ExecutionTest.cpp 393 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671
  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(AtomicsRawHeap64Test);
  275. TEST_METHOD(AtomicsTyped64Test);
  276. TEST_METHOD(AtomicsShared64Test);
  277. TEST_METHOD(AtomicsFloatTest);
  278. TEST_METHOD(HelperLaneTest);
  279. BEGIN_TEST_METHOD(HelperLaneTestWave)
  280. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp handles this
  281. END_TEST_METHOD()
  282. TEST_METHOD(SignatureResourcesTest)
  283. TEST_METHOD(DynamicResourcesTest)
  284. TEST_METHOD(QuadReadTest)
  285. TEST_METHOD(CBufferTestHalf);
  286. TEST_METHOD(BasicShaderModel61);
  287. TEST_METHOD(BasicShaderModel63);
  288. BEGIN_TEST_METHOD(WaveIntrinsicsActiveIntTest)
  289. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsActiveIntTable")
  290. END_TEST_METHOD()
  291. BEGIN_TEST_METHOD(WaveIntrinsicsActiveUintTest)
  292. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsActiveUintTable")
  293. END_TEST_METHOD()
  294. BEGIN_TEST_METHOD(WaveIntrinsicsPrefixIntTest)
  295. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsPrefixIntTable")
  296. END_TEST_METHOD()
  297. BEGIN_TEST_METHOD(WaveIntrinsicsPrefixUintTest)
  298. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsPrefixUintTable")
  299. END_TEST_METHOD()
  300. BEGIN_TEST_METHOD(WaveIntrinsicsSM65IntTest)
  301. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsMultiPrefixIntTable")
  302. END_TEST_METHOD()
  303. BEGIN_TEST_METHOD(WaveIntrinsicsSM65UintTest)
  304. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsMultiPrefixUintTable")
  305. END_TEST_METHOD()
  306. // TAEF data-driven tests.
  307. BEGIN_TEST_METHOD(UnaryFloatOpTest)
  308. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryFloatOpTable")
  309. END_TEST_METHOD()
  310. BEGIN_TEST_METHOD(BinaryFloatOpTest)
  311. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryFloatOpTable")
  312. END_TEST_METHOD()
  313. BEGIN_TEST_METHOD(TertiaryFloatOpTest)
  314. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryFloatOpTable")
  315. END_TEST_METHOD()
  316. BEGIN_TEST_METHOD(UnaryHalfOpTest)
  317. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryHalfOpTable")
  318. END_TEST_METHOD()
  319. BEGIN_TEST_METHOD(BinaryHalfOpTest)
  320. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryHalfOpTable")
  321. END_TEST_METHOD()
  322. BEGIN_TEST_METHOD(TertiaryHalfOpTest)
  323. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryHalfOpTable")
  324. END_TEST_METHOD()
  325. BEGIN_TEST_METHOD(UnaryIntOpTest)
  326. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryIntOpTable")
  327. END_TEST_METHOD()
  328. BEGIN_TEST_METHOD(BinaryIntOpTest)
  329. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryIntOpTable")
  330. END_TEST_METHOD()
  331. BEGIN_TEST_METHOD(TertiaryIntOpTest)
  332. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryIntOpTable")
  333. END_TEST_METHOD()
  334. BEGIN_TEST_METHOD(UnaryUintOpTest)
  335. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryUintOpTable")
  336. END_TEST_METHOD()
  337. BEGIN_TEST_METHOD(BinaryUintOpTest)
  338. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryUintOpTable")
  339. END_TEST_METHOD()
  340. BEGIN_TEST_METHOD(TertiaryUintOpTest)
  341. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryUintOpTable")
  342. END_TEST_METHOD()
  343. BEGIN_TEST_METHOD(UnaryInt16OpTest)
  344. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryInt16OpTable")
  345. END_TEST_METHOD()
  346. BEGIN_TEST_METHOD(BinaryInt16OpTest)
  347. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryInt16OpTable")
  348. END_TEST_METHOD()
  349. BEGIN_TEST_METHOD(TertiaryInt16OpTest)
  350. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryInt16OpTable")
  351. END_TEST_METHOD()
  352. BEGIN_TEST_METHOD(UnaryUint16OpTest)
  353. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryUint16OpTable")
  354. END_TEST_METHOD()
  355. BEGIN_TEST_METHOD(BinaryUint16OpTest)
  356. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryUint16OpTable")
  357. END_TEST_METHOD()
  358. BEGIN_TEST_METHOD(TertiaryUint16OpTest)
  359. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryUint16OpTable")
  360. END_TEST_METHOD()
  361. BEGIN_TEST_METHOD(DotTest)
  362. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DotOpTable")
  363. END_TEST_METHOD()
  364. BEGIN_TEST_METHOD(Dot2AddHalfTest)
  365. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot2AddHalfOpTable")
  366. END_TEST_METHOD()
  367. BEGIN_TEST_METHOD(Dot4AddI8PackedTest)
  368. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot4AddI8PackedOpTable")
  369. END_TEST_METHOD()
  370. BEGIN_TEST_METHOD(Dot4AddU8PackedTest)
  371. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot4AddU8PackedOpTable")
  372. END_TEST_METHOD()
  373. BEGIN_TEST_METHOD(Msad4Test)
  374. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Msad4Table")
  375. END_TEST_METHOD()
  376. BEGIN_TEST_METHOD(DenormBinaryFloatOpTest)
  377. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DenormBinaryFloatOpTable")
  378. END_TEST_METHOD()
  379. BEGIN_TEST_METHOD(DenormTertiaryFloatOpTest)
  380. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DenormTertiaryFloatOpTable")
  381. END_TEST_METHOD()
  382. TEST_METHOD(BarycentricsTest);
  383. TEST_METHOD(ComputeRawBufferLdStI32);
  384. TEST_METHOD(ComputeRawBufferLdStFloat);
  385. TEST_METHOD(ComputeRawBufferLdStI64);
  386. TEST_METHOD(ComputeRawBufferLdStDouble);
  387. TEST_METHOD(ComputeRawBufferLdStI16);
  388. TEST_METHOD(ComputeRawBufferLdStHalf);
  389. TEST_METHOD(GraphicsRawBufferLdStI32);
  390. TEST_METHOD(GraphicsRawBufferLdStFloat);
  391. TEST_METHOD(GraphicsRawBufferLdStI64);
  392. TEST_METHOD(GraphicsRawBufferLdStDouble);
  393. TEST_METHOD(GraphicsRawBufferLdStI16);
  394. TEST_METHOD(GraphicsRawBufferLdStHalf);
  395. BEGIN_TEST_METHOD(PackUnpackTest)
  396. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#PackUnpackOpTable")
  397. END_TEST_METHOD()
  398. dxc::DxcDllSupport m_support;
  399. VersionSupportInfo m_ver;
  400. bool m_ExperimentalModeEnabled = false;
  401. const float ClearColor[4] = { 0.0f, 0.2f, 0.4f, 1.0f };
  402. // Do not remove the following line - it is used by TranslateExecutionTest.py
  403. // MARKER: ExecutionTest/DxilConf Shared Implementation Start
  404. // This is defined in d3d.h for Windows 10 Anniversary Edition SDK, but we only
  405. // require the Windows 10 SDK.
  406. typedef enum D3D_SHADER_MODEL {
  407. D3D_SHADER_MODEL_5_1 = 0x51,
  408. D3D_SHADER_MODEL_6_0 = 0x60,
  409. D3D_SHADER_MODEL_6_1 = 0x61,
  410. D3D_SHADER_MODEL_6_2 = 0x62,
  411. D3D_SHADER_MODEL_6_3 = 0x63,
  412. D3D_SHADER_MODEL_6_4 = 0x64,
  413. D3D_SHADER_MODEL_6_5 = 0x65,
  414. D3D_SHADER_MODEL_6_6 = 0x66,
  415. } D3D_SHADER_MODEL;
  416. #if WDK_NTDDI_VERSION == NTDDI_WIN10_RS2
  417. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_0;
  418. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS3
  419. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_1;
  420. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS4
  421. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_2;
  422. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS5
  423. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_3;
  424. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_19H1
  425. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_4;
  426. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_VB
  427. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_5;
  428. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_MN
  429. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_5;
  430. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_FE
  431. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  432. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_CO
  433. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  434. #else
  435. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  436. #endif
  437. bool UseDxbc() {
  438. #ifdef _HLK_CONF
  439. return false;
  440. #else
  441. return GetTestParamBool(L"DXBC");
  442. #endif
  443. }
  444. bool UseWarpByDefault() {
  445. #ifdef _HLK_CONF
  446. return false;
  447. #else
  448. return true;
  449. #endif
  450. }
  451. bool UseDebugIfaces() {
  452. return true;
  453. }
  454. bool SaveImages() {
  455. return GetTestParamBool(L"SaveImages");
  456. }
  457. void RunResourceTest(ID3D12Device *pDevice, const char *pShader, const wchar_t *sm, bool isDynamic);
  458. template <class T1, class T2>
  459. void WaveIntrinsicsActivePrefixTest(TableParameter *pParameterList,
  460. size_t numParameter, bool isPrefix);
  461. template <typename T>
  462. void WaveIntrinsicsMultiPrefixOpTest(TableParameter *pParameterList,
  463. size_t numParameters);
  464. void BasicTriangleTestSetup(LPCSTR OpName, LPCWSTR FileName, D3D_SHADER_MODEL testModel);
  465. void RunBasicShaderModelTest(D3D_SHADER_MODEL shaderModel);
  466. enum class RawBufferLdStType {
  467. I32,
  468. Float,
  469. I64,
  470. Double,
  471. I16,
  472. Half
  473. };
  474. template <class Ty>
  475. struct RawBufferLdStTestData {
  476. Ty v1, v2[2], v3[3], v4[4];
  477. };
  478. template <class Ty>
  479. struct RawBufferLdStUavData {
  480. RawBufferLdStTestData<Ty> input, output, srvOut;
  481. };
  482. template <class Ty>
  483. void RunComputeRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  484. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData);
  485. template <class Ty>
  486. void RunGraphicsRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  487. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData);
  488. template <class Ty>
  489. void VerifyRawBufferLdStTestResults(const std::shared_ptr<st::ShaderOpTest> test, const RawBufferLdStTestData<Ty> &testData);
  490. bool SetupRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType, CComPtr<ID3D12Device> &pDevice,
  491. CComPtr<IStream> &pStream, char *&sTy, char *&additionalOptions);
  492. template <class Ty>
  493. void RunBasicShaderModelTest(CComPtr<ID3D12Device> pDevice, const char *pShaderModelStr, const char *pShader, Ty *pInputDataPairs, unsigned inputDataCount);
  494. template <class Ty>
  495. const wchar_t* BasicShaderModelTest_GetFormatString();
  496. void CompileFromText(LPCSTR pText, LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, ID3DBlob **ppBlob, LPCWSTR *pOptions = nullptr, int numOptions = 0) {
  497. VERIFY_SUCCEEDED(m_support.Initialize());
  498. CComPtr<IDxcCompiler> pCompiler;
  499. CComPtr<IDxcLibrary> pLibrary;
  500. CComPtr<IDxcBlobEncoding> pTextBlob;
  501. CComPtr<IDxcOperationResult> pResult;
  502. HRESULT resultCode;
  503. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcCompiler, &pCompiler));
  504. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcLibrary, &pLibrary));
  505. VERIFY_SUCCEEDED(pLibrary->CreateBlobWithEncodingFromPinned(pText, (UINT32)strlen(pText), CP_UTF8, &pTextBlob));
  506. VERIFY_SUCCEEDED(pCompiler->Compile(pTextBlob, L"hlsl.hlsl", pEntryPoint, pTargetProfile, pOptions, numOptions, nullptr, 0, nullptr, &pResult));
  507. VERIFY_SUCCEEDED(pResult->GetStatus(&resultCode));
  508. if (FAILED(resultCode)) {
  509. CComPtr<IDxcBlobEncoding> errors;
  510. VERIFY_SUCCEEDED(pResult->GetErrorBuffer(&errors));
  511. #ifndef _HLK_CONF
  512. LogCommentFmt(L"Failed to compile shader: %s", BlobToUtf16(errors).data());
  513. #endif
  514. }
  515. VERIFY_SUCCEEDED(resultCode);
  516. VERIFY_SUCCEEDED(pResult->GetResult((IDxcBlob **)ppBlob));
  517. }
  518. void CreateCommandQueue(ID3D12Device *pDevice, LPCWSTR pName, ID3D12CommandQueue **ppCommandQueue, D3D12_COMMAND_LIST_TYPE type) {
  519. D3D12_COMMAND_QUEUE_DESC queueDesc = {};
  520. queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
  521. queueDesc.Type = type;
  522. VERIFY_SUCCEEDED(pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(ppCommandQueue)));
  523. VERIFY_SUCCEEDED((*ppCommandQueue)->SetName(pName));
  524. }
  525. void CreateComputeCommandQueue(ID3D12Device *pDevice, LPCWSTR pName, ID3D12CommandQueue **ppCommandQueue) {
  526. CreateCommandQueue(pDevice, pName, ppCommandQueue, D3D12_COMMAND_LIST_TYPE_COMPUTE);
  527. }
  528. void CreateComputePSO(ID3D12Device *pDevice, ID3D12RootSignature *pRootSignature, LPCSTR pShader, LPCWSTR pTargetProfile, ID3D12PipelineState **ppComputeState, LPCWSTR *pOptions = nullptr, int numOptions = 0) {
  529. CComPtr<ID3DBlob> pComputeShader;
  530. // Load and compile shaders.
  531. if (UseDxbc()) {
  532. #ifndef _HLK_CONF
  533. DXBCFromText(pShader, L"main", pTargetProfile, &pComputeShader);
  534. #endif
  535. }
  536. else {
  537. CompileFromText(pShader, L"main", pTargetProfile, &pComputeShader, pOptions, numOptions);
  538. }
  539. // Describe and create the compute pipeline state object (PSO).
  540. D3D12_COMPUTE_PIPELINE_STATE_DESC computePsoDesc = {};
  541. computePsoDesc.pRootSignature = pRootSignature;
  542. computePsoDesc.CS = CD3DX12_SHADER_BYTECODE(pComputeShader);
  543. VERIFY_SUCCEEDED(pDevice->CreateComputePipelineState(&computePsoDesc, IID_PPV_ARGS(ppComputeState)));
  544. }
  545. bool CreateDevice(_COM_Outptr_ ID3D12Device **ppDevice,
  546. D3D_SHADER_MODEL testModel = D3D_SHADER_MODEL_6_0, bool skipUnsupported = true,
  547. bool enableRayTracing = false) {
  548. if (testModel > HIGHEST_SHADER_MODEL) {
  549. UINT minor = (UINT)testModel & 0x0f;
  550. LogCommentFmt(L"Installed SDK does not support "
  551. L"shader model 6.%1u", minor);
  552. if (skipUnsupported) {
  553. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  554. }
  555. return false;
  556. }
  557. const D3D_FEATURE_LEVEL FeatureLevelRequired = enableRayTracing ? D3D_FEATURE_LEVEL_12_0 : D3D_FEATURE_LEVEL_11_0;
  558. CComPtr<IDXGIFactory4> factory;
  559. CComPtr<ID3D12Device> pDevice;
  560. *ppDevice = nullptr;
  561. VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
  562. if (GetTestParamUseWARP(UseWarpByDefault())) {
  563. CComPtr<IDXGIAdapter> warpAdapter;
  564. VERIFY_SUCCEEDED(factory->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter)));
  565. HRESULT createHR = D3D12CreateDevice(warpAdapter, FeatureLevelRequired,
  566. IID_PPV_ARGS(&pDevice));
  567. if (FAILED(createHR)) {
  568. LogCommentFmt(L"The available version of WARP does not support d3d12.");
  569. if (skipUnsupported) {
  570. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  571. }
  572. return false;
  573. }
  574. } else {
  575. CComPtr<IDXGIAdapter1> hardwareAdapter;
  576. WEX::Common::String AdapterValue;
  577. HRESULT hr = WEX::TestExecution::RuntimeParameters::TryGetValue(L"Adapter",
  578. AdapterValue);
  579. if (SUCCEEDED(hr)) {
  580. GetHardwareAdapter(factory, AdapterValue, &hardwareAdapter);
  581. } else {
  582. WEX::Logging::Log::Comment(
  583. L"Using default hardware adapter with D3D12 support.");
  584. }
  585. VERIFY_SUCCEEDED(D3D12CreateDevice(hardwareAdapter, FeatureLevelRequired,
  586. IID_PPV_ARGS(&pDevice)));
  587. }
  588. // retrieve adapter information
  589. LUID adapterID = pDevice->GetAdapterLuid();
  590. CComPtr<IDXGIAdapter> adapter;
  591. factory->EnumAdapterByLuid(adapterID, IID_PPV_ARGS(&adapter));
  592. DXGI_ADAPTER_DESC AdapterDesc;
  593. VERIFY_SUCCEEDED(adapter->GetDesc(&AdapterDesc));
  594. LogCommentFmt(L"Using Adapter:%s", AdapterDesc.Description);
  595. if (pDevice == nullptr)
  596. return false;
  597. if (!UseDxbc()) {
  598. // Check for DXIL support.
  599. typedef struct D3D12_FEATURE_DATA_SHADER_MODEL {
  600. _Inout_ D3D_SHADER_MODEL HighestShaderModel;
  601. } D3D12_FEATURE_DATA_SHADER_MODEL;
  602. const UINT D3D12_FEATURE_SHADER_MODEL = 7;
  603. D3D12_FEATURE_DATA_SHADER_MODEL SMData;
  604. SMData.HighestShaderModel = testModel;
  605. VERIFY_SUCCEEDED(pDevice->CheckFeatureSupport(
  606. (D3D12_FEATURE)D3D12_FEATURE_SHADER_MODEL, &SMData, sizeof(SMData)));
  607. if (SMData.HighestShaderModel < testModel) {
  608. UINT minor = (UINT)testModel & 0x0f;
  609. LogCommentFmt(L"The selected device does not support "
  610. L"shader model 6.%1u", minor);
  611. if (skipUnsupported) {
  612. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  613. }
  614. return false;
  615. }
  616. }
  617. if (UseDebugIfaces()) {
  618. CComPtr<ID3D12InfoQueue> pInfoQueue;
  619. if (SUCCEEDED(pDevice->QueryInterface(&pInfoQueue))) {
  620. pInfoQueue->SetMuteDebugOutput(FALSE);
  621. }
  622. }
  623. *ppDevice = pDevice.Detach();
  624. return true;
  625. }
  626. void CreateGraphicsCommandQueue(ID3D12Device *pDevice, ID3D12CommandQueue **ppCommandQueue) {
  627. D3D12_COMMAND_QUEUE_DESC queueDesc = {};
  628. queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
  629. queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;;
  630. VERIFY_SUCCEEDED(pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(ppCommandQueue)));
  631. }
  632. void CreateGraphicsCommandQueueAndList(
  633. ID3D12Device *pDevice, ID3D12CommandQueue **ppCommandQueue,
  634. ID3D12CommandAllocator **ppAllocator,
  635. ID3D12GraphicsCommandList **ppCommandList, ID3D12PipelineState *pPSO) {
  636. CreateGraphicsCommandQueue(pDevice, ppCommandQueue);
  637. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(
  638. D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(ppAllocator)));
  639. VERIFY_SUCCEEDED(pDevice->CreateCommandList(
  640. 0, D3D12_COMMAND_LIST_TYPE_DIRECT, *ppAllocator, pPSO,
  641. IID_PPV_ARGS(ppCommandList)));
  642. }
  643. void CreateGraphicsPSO(ID3D12Device *pDevice,
  644. D3D12_INPUT_LAYOUT_DESC *pInputLayout,
  645. ID3D12RootSignature *pRootSignature, LPCSTR pShaders,
  646. ID3D12PipelineState **ppPSO) {
  647. CComPtr<ID3DBlob> vertexShader;
  648. CComPtr<ID3DBlob> pixelShader;
  649. if (UseDxbc()) {
  650. #ifndef _HLK_CONF
  651. DXBCFromText(pShaders, L"VSMain", L"vs_6_0", &vertexShader);
  652. DXBCFromText(pShaders, L"PSMain", L"ps_6_0", &pixelShader);
  653. #endif
  654. } else {
  655. CompileFromText(pShaders, L"VSMain", L"vs_6_0", &vertexShader);
  656. CompileFromText(pShaders, L"PSMain", L"ps_6_0", &pixelShader);
  657. }
  658. // Describe and create the graphics pipeline state object (PSO).
  659. D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
  660. psoDesc.InputLayout = *pInputLayout;
  661. psoDesc.pRootSignature = pRootSignature;
  662. psoDesc.VS = CD3DX12_SHADER_BYTECODE(vertexShader);
  663. psoDesc.PS = CD3DX12_SHADER_BYTECODE(pixelShader);
  664. psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
  665. psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
  666. psoDesc.DepthStencilState.DepthEnable = FALSE;
  667. psoDesc.DepthStencilState.StencilEnable = FALSE;
  668. psoDesc.SampleMask = UINT_MAX;
  669. psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
  670. psoDesc.NumRenderTargets = 1;
  671. psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
  672. psoDesc.SampleDesc.Count = 1;
  673. VERIFY_SUCCEEDED(
  674. pDevice->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(ppPSO)));
  675. }
  676. void CreateRenderTargetAndReadback(ID3D12Device *pDevice,
  677. ID3D12DescriptorHeap *pHeap, UINT width,
  678. UINT height,
  679. ID3D12Resource **ppRenderTarget,
  680. ID3D12Resource **ppBuffer) {
  681. const DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
  682. const size_t formatElementSize = 4;
  683. CComPtr<ID3D12Resource> pRenderTarget;
  684. CComPtr<ID3D12Resource> pBuffer;
  685. CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(
  686. pHeap->GetCPUDescriptorHandleForHeapStart());
  687. CD3DX12_HEAP_PROPERTIES rtHeap(D3D12_HEAP_TYPE_DEFAULT);
  688. CD3DX12_RESOURCE_DESC rtDesc(
  689. CD3DX12_RESOURCE_DESC::Tex2D(format, width, height));
  690. CD3DX12_CLEAR_VALUE rtClearVal(format, ClearColor);
  691. rtDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
  692. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  693. &rtHeap, D3D12_HEAP_FLAG_NONE, &rtDesc, D3D12_RESOURCE_STATE_COPY_DEST,
  694. &rtClearVal, IID_PPV_ARGS(&pRenderTarget)));
  695. pDevice->CreateRenderTargetView(pRenderTarget, nullptr, rtvHandle);
  696. // rtvHandle.Offset(1, rtvDescriptorSize); // Not needed for a single
  697. // resource.
  698. CD3DX12_HEAP_PROPERTIES readHeap(D3D12_HEAP_TYPE_READBACK);
  699. CD3DX12_RESOURCE_DESC readDesc(
  700. CD3DX12_RESOURCE_DESC::Buffer(width * height * formatElementSize));
  701. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  702. &readHeap, D3D12_HEAP_FLAG_NONE, &readDesc,
  703. D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pBuffer)));
  704. *ppRenderTarget = pRenderTarget.Detach();
  705. *ppBuffer = pBuffer.Detach();
  706. }
  707. void CreateRootSignatureFromDesc(ID3D12Device *pDevice,
  708. const D3D12_ROOT_SIGNATURE_DESC *pDesc,
  709. ID3D12RootSignature **pRootSig) {
  710. CComPtr<ID3DBlob> signature;
  711. CComPtr<ID3DBlob> error;
  712. VERIFY_SUCCEEDED(D3D12SerializeRootSignature(pDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
  713. VERIFY_SUCCEEDED(pDevice->CreateRootSignature(
  714. 0, signature->GetBufferPointer(), signature->GetBufferSize(),
  715. IID_PPV_ARGS(pRootSig)));
  716. }
  717. void CreateRootSignatureFromRanges(ID3D12Device *pDevice, ID3D12RootSignature **pRootSig,
  718. CD3DX12_DESCRIPTOR_RANGE *resRanges, UINT resCt,
  719. CD3DX12_DESCRIPTOR_RANGE *sampRanges = nullptr, UINT sampCt = 0,
  720. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) {
  721. CD3DX12_ROOT_PARAMETER rootParameters[2];
  722. rootParameters[0].InitAsDescriptorTable(resCt, resRanges, D3D12_SHADER_VISIBILITY_ALL);
  723. rootParameters[1].InitAsDescriptorTable(sampCt, sampRanges, D3D12_SHADER_VISIBILITY_ALL);
  724. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  725. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, flags);
  726. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, pRootSig);
  727. }
  728. void CreateRtvDescriptorHeap(ID3D12Device *pDevice, UINT numDescriptors,
  729. ID3D12DescriptorHeap **pRtvHeap, UINT *rtvDescriptorSize) {
  730. D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {};
  731. rtvHeapDesc.NumDescriptors = numDescriptors;
  732. rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
  733. rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
  734. VERIFY_SUCCEEDED(
  735. pDevice->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(pRtvHeap)));
  736. if (rtvDescriptorSize != nullptr) {
  737. *rtvDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(
  738. D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
  739. }
  740. }
  741. void CreateTestResources(ID3D12Device *pDevice,
  742. ID3D12GraphicsCommandList *pCommandList, LPCVOID values,
  743. UINT32 valueSizeInBytes, D3D12_RESOURCE_DESC resDesc,
  744. ID3D12Resource **ppResource,
  745. ID3D12Resource **ppUploadResource,
  746. ID3D12Resource **ppReadBuffer = nullptr) {
  747. CComPtr<ID3D12Resource> pResource;
  748. CComPtr<ID3D12Resource> pReadBuffer;
  749. CComPtr<ID3D12Resource> pUploadResource;
  750. D3D12_SUBRESOURCE_DATA transferData;
  751. D3D12_HEAP_PROPERTIES defaultHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);
  752. D3D12_HEAP_PROPERTIES uploadHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD);
  753. D3D12_RESOURCE_DESC uploadBufferDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes);
  754. CD3DX12_HEAP_PROPERTIES readHeap(D3D12_HEAP_TYPE_READBACK);
  755. CD3DX12_RESOURCE_DESC readDesc(CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes));
  756. pDevice->GetCopyableFootprints(&resDesc, 0, 1/*mipleveles*/, 0, nullptr, nullptr, nullptr, &uploadBufferDesc.Width);
  757. uploadBufferDesc.Height = 1;
  758. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  759. &defaultHeapProperties,
  760. D3D12_HEAP_FLAG_NONE,
  761. &resDesc,
  762. D3D12_RESOURCE_STATE_COPY_DEST,
  763. nullptr,
  764. IID_PPV_ARGS(&pResource)));
  765. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  766. &uploadHeapProperties,
  767. D3D12_HEAP_FLAG_NONE,
  768. &uploadBufferDesc,
  769. D3D12_RESOURCE_STATE_GENERIC_READ,
  770. nullptr,
  771. IID_PPV_ARGS(&pUploadResource)));
  772. if (ppReadBuffer)
  773. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  774. &readHeap, D3D12_HEAP_FLAG_NONE, &readDesc,
  775. D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pReadBuffer)));
  776. transferData.pData = values;
  777. transferData.RowPitch = valueSizeInBytes/resDesc.Height;
  778. transferData.SlicePitch = valueSizeInBytes;
  779. UpdateSubresources<1>(pCommandList, pResource.p, pUploadResource.p, 0, 0, 1, &transferData);
  780. if (resDesc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)
  781. RecordTransitionBarrier(pCommandList, pResource, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
  782. else
  783. RecordTransitionBarrier(pCommandList, pResource, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COMMON);
  784. *ppResource = pResource.Detach();
  785. *ppUploadResource = pUploadResource.Detach();
  786. if (ppReadBuffer)
  787. *ppReadBuffer = pReadBuffer.Detach();
  788. }
  789. void CreateTestUavs(ID3D12Device *pDevice,
  790. ID3D12GraphicsCommandList *pCommandList, LPCVOID values,
  791. UINT32 valueSizeInBytes, ID3D12Resource **ppUavResource,
  792. ID3D12Resource **ppUploadResource = nullptr,
  793. ID3D12Resource **ppReadBuffer = nullptr) {
  794. D3D12_RESOURCE_DESC bufferDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
  795. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, bufferDesc,
  796. ppUavResource, ppUploadResource, ppReadBuffer);
  797. }
  798. // Create and return descriptor heaps for the given device
  799. // with the given number of resources and samples.
  800. // using some reasonable defaults
  801. void CreateDefaultDescHeaps(ID3D12Device *pDevice,
  802. int NumResources, int NumSamplers,
  803. ID3D12DescriptorHeap **ppResHeap, ID3D12DescriptorHeap **ppSampHeap) {
  804. // Describe and create descriptor heaps.
  805. ID3D12DescriptorHeap *pResHeap, *pSampHeap;
  806. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  807. heapDesc.NumDescriptors = NumResources;
  808. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  809. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  810. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pResHeap)));
  811. heapDesc.NumDescriptors = NumSamplers;
  812. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
  813. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pSampHeap)));
  814. *ppResHeap = pResHeap;
  815. *ppSampHeap = pSampHeap;
  816. }
  817. void CreateSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &baseHandle,
  818. DXGI_FORMAT format, D3D12_SRV_DIMENSION viewDimension, UINT numElements, UINT stride,
  819. const CComPtr<ID3D12Resource> pResource) {
  820. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
  821. // Create SRV
  822. D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
  823. srvDesc.Format = format;
  824. srvDesc.ViewDimension = viewDimension;
  825. srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
  826. switch (viewDimension) {
  827. case D3D12_SRV_DIMENSION_BUFFER:
  828. srvDesc.Buffer.FirstElement = 0;
  829. srvDesc.Buffer.NumElements = numElements;
  830. srvDesc.Buffer.StructureByteStride = stride;
  831. if (format == DXGI_FORMAT_R32_TYPELESS && stride == 0)
  832. srvDesc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW;
  833. else
  834. srvDesc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_NONE;
  835. break;
  836. case D3D12_SRV_DIMENSION_TEXTURE1D:
  837. srvDesc.Texture1D.MostDetailedMip = 0;
  838. srvDesc.Texture1D.MipLevels = 1;
  839. srvDesc.Texture1D.ResourceMinLODClamp = 0;
  840. break;
  841. case D3D12_SRV_DIMENSION_TEXTURE2D:
  842. srvDesc.Texture2D.MostDetailedMip = 0;
  843. srvDesc.Texture2D.MipLevels = 1;
  844. srvDesc.Texture2D.PlaneSlice = 0;
  845. srvDesc.Texture2D.ResourceMinLODClamp = 0;
  846. break;
  847. }
  848. pDevice->CreateShaderResourceView(pResource, &srvDesc, baseHandle);
  849. baseHandle.Offset(descriptorSize);
  850. }
  851. void CreateRawSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  852. UINT numElements, const CComPtr<ID3D12Resource> pResource) {
  853. CreateSRV(pDevice, heapStart, DXGI_FORMAT_R32_TYPELESS, D3D12_SRV_DIMENSION_BUFFER, numElements, 0, pResource);
  854. }
  855. void CreateStructSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  856. UINT numElements, UINT stride, const CComPtr<ID3D12Resource> pResource) {
  857. CreateSRV(pDevice, heapStart, DXGI_FORMAT_UNKNOWN, D3D12_SRV_DIMENSION_BUFFER, numElements, stride, pResource);
  858. }
  859. void CreateTypedSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  860. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  861. CreateSRV(pDevice, heapStart, format, D3D12_SRV_DIMENSION_BUFFER, numElements, 0, pResource);
  862. }
  863. void CreateTex1DSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  864. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  865. CreateSRV(pDevice, heapStart, format, D3D12_SRV_DIMENSION_TEXTURE1D, numElements, 0, pResource);
  866. }
  867. void CreateTex2DSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  868. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  869. CreateSRV(pDevice, heapStart, format, D3D12_SRV_DIMENSION_TEXTURE2D, numElements, 0, pResource);
  870. }
  871. void CreateUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &baseHandle,
  872. DXGI_FORMAT format, D3D12_UAV_DIMENSION viewDimension, UINT numElements, UINT stride,
  873. const CComPtr<ID3D12Resource> pResource) {
  874. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
  875. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  876. uavDesc.Format = format;
  877. uavDesc.ViewDimension = viewDimension;
  878. switch (viewDimension) {
  879. case D3D12_UAV_DIMENSION_BUFFER:
  880. uavDesc.Buffer.FirstElement = 0;
  881. uavDesc.Buffer.NumElements = numElements;
  882. uavDesc.Buffer.StructureByteStride = stride;
  883. if (format == DXGI_FORMAT_R32_TYPELESS && stride == 0)
  884. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  885. else
  886. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  887. break;
  888. case D3D12_UAV_DIMENSION_TEXTURE1D:
  889. uavDesc.Texture1D.MipSlice = 0;
  890. break;
  891. case D3D12_UAV_DIMENSION_TEXTURE2D:
  892. uavDesc.Texture2D.MipSlice = 0;
  893. uavDesc.Texture2D.PlaneSlice = 0;
  894. break;
  895. }
  896. pDevice->CreateUnorderedAccessView(pResource, nullptr, &uavDesc, baseHandle);
  897. baseHandle.Offset(descriptorSize);
  898. }
  899. void CreateRawUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  900. UINT numElements, const CComPtr<ID3D12Resource> pResource) {
  901. CreateUAV(pDevice, heapStart, DXGI_FORMAT_R32_TYPELESS, D3D12_UAV_DIMENSION_BUFFER, numElements, 0, pResource);
  902. }
  903. void CreateStructUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  904. UINT numElements, UINT stride, const CComPtr<ID3D12Resource> pResource) {
  905. CreateUAV(pDevice, heapStart, DXGI_FORMAT_UNKNOWN, D3D12_UAV_DIMENSION_BUFFER, numElements, stride, pResource);
  906. }
  907. void CreateTypedUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  908. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  909. CreateUAV(pDevice, heapStart, format, D3D12_UAV_DIMENSION_BUFFER, numElements, 0, pResource);
  910. }
  911. void CreateTex1DUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  912. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  913. CreateUAV(pDevice, heapStart, format, D3D12_UAV_DIMENSION_TEXTURE1D, numElements, 0, pResource);
  914. }
  915. void CreateTex2DUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  916. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  917. CreateUAV(pDevice, heapStart, format, D3D12_UAV_DIMENSION_TEXTURE2D, numElements, 0, pResource);
  918. }
  919. // Create Samplers for <pDevice> given the filter and border color information provided
  920. // using some reasonable defaults
  921. void CreateDefaultSamplers(ID3D12Device *pDevice, D3D12_CPU_DESCRIPTOR_HANDLE heapStart,
  922. D3D12_FILTER filters[], float BorderColors[], int NumSamplers) {
  923. CD3DX12_CPU_DESCRIPTOR_HANDLE sampHandle(heapStart);
  924. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
  925. D3D12_SAMPLER_DESC sampDesc = {};
  926. sampDesc.Filter = D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT;
  927. sampDesc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  928. sampDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  929. sampDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  930. sampDesc.MipLODBias = 0;
  931. sampDesc.MaxAnisotropy = 1;
  932. sampDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_EQUAL;
  933. sampDesc.MinLOD = 0;
  934. sampDesc.MaxLOD = 0;
  935. for (int i = 0; i < NumSamplers; i++) {
  936. sampDesc.Filter = filters[i];
  937. for (int j = 0; j < 4; j++)
  938. sampDesc.BorderColor[j] = BorderColors[i];
  939. pDevice->CreateSampler(&sampDesc, sampHandle);
  940. sampHandle = sampHandle.Offset(descriptorSize);
  941. }
  942. }
  943. template <typename TVertex, int len>
  944. void CreateVertexBuffer(ID3D12Device *pDevice, TVertex(&vertices)[len],
  945. ID3D12Resource **ppVertexBuffer,
  946. D3D12_VERTEX_BUFFER_VIEW *pVertexBufferView) {
  947. size_t vertexBufferSize = sizeof(vertices);
  948. CComPtr<ID3D12Resource> pVertexBuffer;
  949. CD3DX12_HEAP_PROPERTIES heapProps(D3D12_HEAP_TYPE_UPLOAD);
  950. CD3DX12_RESOURCE_DESC bufferDesc(
  951. CD3DX12_RESOURCE_DESC::Buffer(vertexBufferSize));
  952. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  953. &heapProps, D3D12_HEAP_FLAG_NONE, &bufferDesc,
  954. D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
  955. IID_PPV_ARGS(&pVertexBuffer)));
  956. UINT8 *pVertexDataBegin;
  957. CD3DX12_RANGE readRange(0, 0);
  958. VERIFY_SUCCEEDED(pVertexBuffer->Map(
  959. 0, &readRange, reinterpret_cast<void **>(&pVertexDataBegin)));
  960. memcpy(pVertexDataBegin, vertices, vertexBufferSize);
  961. pVertexBuffer->Unmap(0, nullptr);
  962. // Initialize the vertex buffer view.
  963. pVertexBufferView->BufferLocation = pVertexBuffer->GetGPUVirtualAddress();
  964. pVertexBufferView->StrideInBytes = sizeof(TVertex);
  965. pVertexBufferView->SizeInBytes = (UINT)vertexBufferSize;
  966. *ppVertexBuffer = pVertexBuffer.Detach();
  967. }
  968. // Requires Anniversary Edition headers, so simplifying things for current setup.
  969. const UINT D3D12_FEATURE_D3D12_OPTIONS1 = 8;
  970. struct D3D12_FEATURE_DATA_D3D12_OPTIONS1 {
  971. BOOL WaveOps;
  972. UINT WaveLaneCountMin;
  973. UINT WaveLaneCountMax;
  974. UINT TotalLaneCount;
  975. BOOL ExpandedComputeResourceStates;
  976. BOOL Int64ShaderOps;
  977. };
  978. bool IsDeviceBasicAdapter(ID3D12Device *pDevice) {
  979. CComPtr<IDXGIFactory4> factory;
  980. VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
  981. LUID adapterID = pDevice->GetAdapterLuid();
  982. CComPtr<IDXGIAdapter1> adapter;
  983. factory->EnumAdapterByLuid(adapterID, IID_PPV_ARGS(&adapter));
  984. DXGI_ADAPTER_DESC1 AdapterDesc;
  985. VERIFY_SUCCEEDED(adapter->GetDesc1(&AdapterDesc));
  986. return (AdapterDesc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE);
  987. }
  988. bool DoesDeviceSupportInt64(ID3D12Device *pDevice) {
  989. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  990. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  991. return false;
  992. return O.Int64ShaderOps != FALSE;
  993. }
  994. bool DoesDeviceSupportDouble(ID3D12Device *pDevice) {
  995. D3D12_FEATURE_DATA_D3D12_OPTIONS O;
  996. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS, &O, sizeof(O))))
  997. return false;
  998. return O.DoublePrecisionFloatShaderOps != FALSE;
  999. }
  1000. bool DoesDeviceSupportWaveOps(ID3D12Device *pDevice) {
  1001. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  1002. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  1003. return false;
  1004. return O.WaveOps != FALSE;
  1005. }
  1006. bool DoesDeviceSupportBarycentrics(ID3D12Device *pDevice) {
  1007. D3D12_FEATURE_DATA_D3D12_OPTIONS3 O;
  1008. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS3, &O, sizeof(O))))
  1009. return false;
  1010. return O.BarycentricsSupported != FALSE;
  1011. }
  1012. bool DoesDeviceSupportNative16bitOps(ID3D12Device *pDevice) {
  1013. D3D12_FEATURE_DATA_D3D12_OPTIONS4 O;
  1014. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS4, &O, sizeof(O))))
  1015. return false;
  1016. return O.Native16BitShaderOpsSupported != FALSE;
  1017. }
  1018. bool DoesDeviceSupportMeshShaders(ID3D12Device *pDevice) {
  1019. #if defined(NTDDI_WIN10_VB) && WDK_NTDDI_VERSION >= NTDDI_WIN10_VB
  1020. D3D12_FEATURE_DATA_D3D12_OPTIONS7 O7;
  1021. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS7, &O7, sizeof(O7))))
  1022. return false;
  1023. return O7.MeshShaderTier != D3D12_MESH_SHADER_TIER_NOT_SUPPORTED;
  1024. #else
  1025. UNREFERENCED_PARAMETER(pDevice);
  1026. return false;
  1027. #endif
  1028. }
  1029. bool DoesDeviceSupportRayTracing(ID3D12Device *pDevice) {
  1030. #if WDK_NTDDI_VERSION > NTDDI_WIN10_RS4
  1031. D3D12_FEATURE_DATA_D3D12_OPTIONS5 O5;
  1032. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS5, &O5, sizeof(O5))))
  1033. return false;
  1034. return O5.RaytracingTier != D3D12_RAYTRACING_TIER_NOT_SUPPORTED;
  1035. #else
  1036. UNREFERENCED_PARAMETER(pDevice);
  1037. return false;
  1038. #endif
  1039. }
  1040. bool DoesDeviceSupportMeshAmpDerivatives(ID3D12Device *pDevice) {
  1041. #if defined(NTDDI_WIN10_FE) && WDK_NTDDI_VERSION >= NTDDI_WIN10_FE
  1042. D3D12_FEATURE_DATA_D3D12_OPTIONS7 O7;
  1043. D3D12_FEATURE_DATA_D3D12_OPTIONS9 O9;
  1044. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS7, &O7, sizeof(O7))) ||
  1045. FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS9, &O9, sizeof(O9))))
  1046. return false;
  1047. return O7.MeshShaderTier != D3D12_MESH_SHADER_TIER_NOT_SUPPORTED &&
  1048. O9.DerivativesInMeshAndAmplificationShadersSupported != FALSE;
  1049. #else
  1050. UNREFERENCED_PARAMETER(pDevice);
  1051. return false;
  1052. #endif
  1053. }
  1054. bool DoesDeviceSupportTyped64Atomics(ID3D12Device *pDevice) {
  1055. #if defined(NTDDI_WIN10_FE) && WDK_NTDDI_VERSION >= NTDDI_WIN10_FE
  1056. D3D12_FEATURE_DATA_D3D12_OPTIONS9 O9;
  1057. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS9, &O9, sizeof(O9))))
  1058. return false;
  1059. return O9.AtomicInt64OnTypedResourceSupported != FALSE;
  1060. #else
  1061. UNREFERENCED_PARAMETER(pDevice);
  1062. return false;
  1063. #endif
  1064. }
  1065. bool DoesDeviceSupportHeap64Atomics(ID3D12Device *pDevice) {
  1066. #if defined(NTDDI_WIN10_CO) && WDK_NTDDI_VERSION >= NTDDI_WIN10_CO
  1067. D3D12_FEATURE_DATA_D3D12_OPTIONS11 O11;
  1068. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS11, &O11, sizeof(O11))))
  1069. return false;
  1070. return O11.AtomicInt64OnDescriptorHeapResourceSupported != FALSE;
  1071. #else
  1072. UNREFERENCED_PARAMETER(pDevice);
  1073. return false;
  1074. #endif
  1075. }
  1076. bool DoesDeviceSupportShared64Atomics(ID3D12Device *pDevice) {
  1077. #if defined(NTDDI_WIN10_FE) && WDK_NTDDI_VERSION >= NTDDI_WIN10_FE
  1078. D3D12_FEATURE_DATA_D3D12_OPTIONS9 O9;
  1079. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS9, &O9, sizeof(O9))))
  1080. return false;
  1081. return O9.AtomicInt64OnGroupSharedSupported != FALSE;
  1082. #else
  1083. UNREFERENCED_PARAMETER(pDevice);
  1084. return false;
  1085. #endif
  1086. }
  1087. #ifndef _HLK_CONF
  1088. void DXBCFromText(LPCSTR pText, LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, ID3DBlob **ppBlob) {
  1089. CW2A pEntryPointA(pEntryPoint, CP_UTF8);
  1090. CW2A pTargetProfileA(pTargetProfile, CP_UTF8);
  1091. CComPtr<ID3DBlob> pErrors;
  1092. D3D_SHADER_MACRO d3dMacro[2];
  1093. ZeroMemory(d3dMacro, sizeof(d3dMacro));
  1094. d3dMacro[0].Definition = "1";
  1095. d3dMacro[0].Name = "USING_DXBC";
  1096. HRESULT hr = D3DCompile(pText, strlen(pText), "hlsl.hlsl", d3dMacro, nullptr, pEntryPointA, pTargetProfileA, 0, 0, ppBlob, &pErrors);
  1097. if (pErrors != nullptr) {
  1098. CA2W errors((char *)pErrors->GetBufferPointer(), CP_ACP);
  1099. LogCommentFmt(L"Compilation failure: %s", errors.m_szBuffer);
  1100. }
  1101. VERIFY_SUCCEEDED(hr);
  1102. }
  1103. #endif
  1104. HRESULT EnableDebugLayer() {
  1105. // The debug layer does net yet validate DXIL programs that require rewriting,
  1106. // but basic logging should work properly.
  1107. HRESULT hr = S_FALSE;
  1108. if (UseDebugIfaces()) {
  1109. CComPtr<ID3D12Debug> debugController;
  1110. hr = D3D12GetDebugInterface(IID_PPV_ARGS(&debugController));
  1111. if (SUCCEEDED(hr)) {
  1112. debugController->EnableDebugLayer();
  1113. hr = S_OK;
  1114. }
  1115. }
  1116. return hr;
  1117. }
  1118. #ifndef _HLK_CONF
  1119. HRESULT EnableExperimentalMode() {
  1120. if (m_ExperimentalModeEnabled) {
  1121. return S_OK;
  1122. }
  1123. if (!GetTestParamBool(L"ExperimentalShaders")) {
  1124. return S_FALSE;
  1125. }
  1126. HRESULT hr = EnableExperimentalShaderModels();
  1127. if (SUCCEEDED(hr)) {
  1128. m_ExperimentalModeEnabled = true;
  1129. }
  1130. return hr;
  1131. }
  1132. #endif
  1133. struct FenceObj {
  1134. HANDLE m_fenceEvent = NULL;
  1135. CComPtr<ID3D12Fence> m_fence;
  1136. UINT64 m_fenceValue;
  1137. ~FenceObj() {
  1138. if (m_fenceEvent) CloseHandle(m_fenceEvent);
  1139. }
  1140. };
  1141. void InitFenceObj(ID3D12Device *pDevice, FenceObj *pObj) {
  1142. pObj->m_fenceValue = 1;
  1143. VERIFY_SUCCEEDED(pDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE,
  1144. IID_PPV_ARGS(&pObj->m_fence)));
  1145. // Create an event handle to use for frame synchronization.
  1146. pObj->m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
  1147. if (pObj->m_fenceEvent == nullptr) {
  1148. VERIFY_SUCCEEDED(HRESULT_FROM_WIN32(GetLastError()));
  1149. }
  1150. }
  1151. void ReadHlslDataIntoNewStream(LPCWSTR relativePath, IStream **ppStream) {
  1152. VERIFY_SUCCEEDED(m_support.Initialize());
  1153. CComPtr<IDxcLibrary> pLibrary;
  1154. CComPtr<IDxcBlobEncoding> pBlob;
  1155. CComPtr<IStream> pStream;
  1156. std::wstring path = GetPathToHlslDataFile(relativePath);
  1157. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcLibrary, &pLibrary));
  1158. VERIFY_SUCCEEDED(pLibrary->CreateBlobFromFile(path.c_str(), nullptr, &pBlob));
  1159. VERIFY_SUCCEEDED(pLibrary->CreateStreamFromBlobReadOnly(pBlob, &pStream));
  1160. *ppStream = pStream.Detach();
  1161. }
  1162. void RecordRenderAndReadback(ID3D12GraphicsCommandList *pList,
  1163. ID3D12DescriptorHeap *pRtvHeap,
  1164. UINT rtvDescriptorSize,
  1165. UINT instanceCount,
  1166. D3D12_VERTEX_BUFFER_VIEW *pVertexBufferView,
  1167. ID3D12RootSignature *pRootSig,
  1168. ID3D12Resource *pRenderTarget,
  1169. ID3D12Resource *pReadBuffer) {
  1170. D3D12_RESOURCE_DESC rtDesc = pRenderTarget->GetDesc();
  1171. D3D12_VIEWPORT viewport;
  1172. D3D12_RECT scissorRect;
  1173. memset(&viewport, 0, sizeof(viewport));
  1174. viewport.Height = (float)rtDesc.Height;
  1175. viewport.Width = (float)rtDesc.Width;
  1176. viewport.MaxDepth = 1.0f;
  1177. memset(&scissorRect, 0, sizeof(scissorRect));
  1178. scissorRect.right = (long)rtDesc.Width;
  1179. scissorRect.bottom = rtDesc.Height;
  1180. if (pRootSig != nullptr) {
  1181. pList->SetGraphicsRootSignature(pRootSig);
  1182. }
  1183. pList->RSSetViewports(1, &viewport);
  1184. pList->RSSetScissorRects(1, &scissorRect);
  1185. // Indicate that the buffer will be used as a render target.
  1186. RecordTransitionBarrier(pList, pRenderTarget, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_RENDER_TARGET);
  1187. CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(pRtvHeap->GetCPUDescriptorHandleForHeapStart(), 0, rtvDescriptorSize);
  1188. pList->OMSetRenderTargets(1, &rtvHandle, FALSE, nullptr);
  1189. pList->ClearRenderTargetView(rtvHandle, ClearColor, 0, nullptr);
  1190. pList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
  1191. pList->IASetVertexBuffers(0, 1, pVertexBufferView);
  1192. pList->DrawInstanced(3, instanceCount, 0, 0);
  1193. // Transition to copy source and copy into read-back buffer.
  1194. RecordTransitionBarrier(pList, pRenderTarget, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1195. // Copy into read-back buffer.
  1196. UINT64 rowPitch = rtDesc.Width * 4;
  1197. if (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT)
  1198. rowPitch += D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
  1199. D3D12_PLACED_SUBRESOURCE_FOOTPRINT Footprint;
  1200. Footprint.Offset = 0;
  1201. Footprint.Footprint = CD3DX12_SUBRESOURCE_FOOTPRINT(DXGI_FORMAT_R8G8B8A8_UNORM, (UINT)rtDesc.Width, rtDesc.Height, 1, (UINT)rowPitch);
  1202. CD3DX12_TEXTURE_COPY_LOCATION DstLoc(pReadBuffer, Footprint);
  1203. CD3DX12_TEXTURE_COPY_LOCATION SrcLoc(pRenderTarget, 0);
  1204. pList->CopyTextureRegion(&DstLoc, 0, 0, 0, &SrcLoc, nullptr);
  1205. }
  1206. void RunRWByteBufferComputeTest(ID3D12Device *pDevice, LPCSTR shader, std::vector<uint32_t> &values);
  1207. void RunLifetimeIntrinsicTest(ID3D12Device *pDevice, LPCSTR shader, D3D_SHADER_MODEL shaderModel, bool useLibTarget, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values);
  1208. void RunLifetimeIntrinsicComputeTest(ID3D12Device *pDevice, LPCSTR pShader, CComPtr<ID3D12DescriptorHeap>& pUavHeap, CComPtr<ID3D12RootSignature>& pRootSignature,
  1209. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values);
  1210. void RunLifetimeIntrinsicLibTest(ID3D12Device5 *pDevice, LPCSTR pShader, CComPtr<ID3D12RootSignature>& pRootSignature,
  1211. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions);
  1212. void SetDescriptorHeap(ID3D12GraphicsCommandList *pCommandList, ID3D12DescriptorHeap *pHeap) {
  1213. ID3D12DescriptorHeap *const pHeaps[1] = { pHeap };
  1214. pCommandList->SetDescriptorHeaps(1, pHeaps);
  1215. }
  1216. void WaitForSignal(ID3D12CommandQueue *pCQ, FenceObj &FO) {
  1217. ::WaitForSignal(pCQ, FO.m_fence, FO.m_fenceEvent, FO.m_fenceValue++);
  1218. }
  1219. };
  1220. #define WAVE_INTRINSIC_DXBC_GUARD \
  1221. "#ifdef USING_DXBC\r\n" \
  1222. "uint WaveGetLaneIndex() { return 1; }\r\n" \
  1223. "uint WaveReadLaneFirst(uint u) { return u; }\r\n" \
  1224. "bool WaveIsFirstLane() { return true; }\r\n" \
  1225. "uint WaveGetLaneCount() { return 1; }\r\n" \
  1226. "uint WaveReadLaneAt(uint n, uint u) { return u; }\r\n" \
  1227. "bool WaveActiveAnyTrue(bool b) { return b; }\r\n" \
  1228. "bool WaveActiveAllTrue(bool b) { return false; }\r\n" \
  1229. "uint WaveActiveAllEqual(uint u) { return u; }\r\n" \
  1230. "uint4 WaveActiveBallot(bool b) { return 1; }\r\n" \
  1231. "uint WaveActiveCountBits(uint u) { return 1; }\r\n" \
  1232. "uint WaveActiveSum(uint u) { return 1; }\r\n" \
  1233. "uint WaveActiveProduct(uint u) { return 1; }\r\n" \
  1234. "uint WaveActiveBitAnd(uint u) { return 1; }\r\n" \
  1235. "uint WaveActiveBitOr(uint u) { return 1; }\r\n" \
  1236. "uint WaveActiveBitXor(uint u) { return 1; }\r\n" \
  1237. "uint WaveActiveMin(uint u) { return 1; }\r\n" \
  1238. "uint WaveActiveMax(uint u) { return 1; }\r\n" \
  1239. "uint WavePrefixCountBits(uint u) { return 1; }\r\n" \
  1240. "uint WavePrefixSum(uint u) { return 1; }\r\n" \
  1241. "uint WavePrefixProduct(uint u) { return 1; }\r\n" \
  1242. "uint QuadReadLaneAt(uint a, uint u) { return 1; }\r\n" \
  1243. "uint QuadReadAcrossX(uint u) { return 1; }\r\n" \
  1244. "uint QuadReadAcrossY(uint u) { return 1; }\r\n" \
  1245. "uint QuadReadAcrossDiagonal(uint u) { return 1; }\r\n" \
  1246. "#endif\r\n"
  1247. static void SetupComputeValuePattern(std::vector<uint32_t> &values,
  1248. size_t count) {
  1249. values.resize(count); // one element per dispatch group, in bytes
  1250. for (size_t i = 0; i < count; ++i) {
  1251. values[i] = (uint32_t)i;
  1252. }
  1253. }
  1254. bool ExecutionTest::ExecutionTestClassSetup() {
  1255. #ifdef _HLK_CONF
  1256. // TODO: Enabling the D3D driver verifier. Check out the logic in the D3DConf_12_Core test.
  1257. VERIFY_SUCCEEDED(m_support.Initialize());
  1258. m_UseWarp = hlsl_test::GetTestParamUseWARP(false);
  1259. m_EnableDebugLayer = hlsl_test::GetTestParamBool(L"DebugLayer");
  1260. if (m_EnableDebugLayer) {
  1261. EnableDebugLayer();
  1262. }
  1263. return true;
  1264. #else
  1265. HRESULT hr = EnableExperimentalMode();
  1266. if (FAILED(hr)) {
  1267. LogCommentFmt(L"Unable to enable shader experimental mode - 0x%08x.", hr);
  1268. }
  1269. else if (hr == S_FALSE) {
  1270. LogCommentFmt(L"Experimental mode not enabled.");
  1271. }
  1272. else {
  1273. LogCommentFmt(L"Experimental mode enabled.");
  1274. }
  1275. hr = EnableDebugLayer();
  1276. if (FAILED(hr)) {
  1277. LogCommentFmt(L"Unable to enable debug layer - 0x%08x.", hr);
  1278. }
  1279. else {
  1280. LogCommentFmt(L"Debug layer enabled.");
  1281. }
  1282. return true;
  1283. #endif
  1284. }
  1285. void ExecutionTest::RunRWByteBufferComputeTest(ID3D12Device *pDevice, LPCSTR pShader, std::vector<uint32_t> &values) {
  1286. static const int DispatchGroupX = 1;
  1287. static const int DispatchGroupY = 1;
  1288. static const int DispatchGroupZ = 1;
  1289. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1290. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1291. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1292. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1293. UINT uavDescriptorSize;
  1294. FenceObj FO;
  1295. const UINT valueSizeInBytes = (UINT)values.size() * sizeof(uint32_t);
  1296. CreateComputeCommandQueue(pDevice, L"RunRWByteBufferComputeTest Command Queue", &pCommandQueue);
  1297. InitFenceObj(pDevice, &FO);
  1298. // Describe and create a UAV descriptor heap.
  1299. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1300. heapDesc.NumDescriptors = 1;
  1301. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1302. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1303. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1304. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  1305. // Create root signature.
  1306. CComPtr<ID3D12RootSignature> pRootSignature;
  1307. {
  1308. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1309. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1310. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1311. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1312. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1313. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  1314. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  1315. }
  1316. // Create pipeline state object.
  1317. CComPtr<ID3D12PipelineState> pComputeState;
  1318. CreateComputePSO(pDevice, pRootSignature, pShader, L"cs_6_0", &pComputeState);
  1319. // Create a command allocator and list for compute.
  1320. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1321. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1322. pCommandList->SetName(L"ExecutionTest::RunRWByteButterComputeTest Command List");
  1323. // Set up UAV resource.
  1324. CComPtr<ID3D12Resource> pUavResource;
  1325. CComPtr<ID3D12Resource> pReadBuffer;
  1326. CComPtr<ID3D12Resource> pUploadResource;
  1327. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  1328. VERIFY_SUCCEEDED(pUavResource->SetName(L"RunRWByteBufferComputeText UAV"));
  1329. VERIFY_SUCCEEDED(pReadBuffer->SetName(L"RunRWByteBufferComputeText UAV Read Buffer"));
  1330. VERIFY_SUCCEEDED(pUploadResource->SetName(L"RunRWByteBufferComputeText UAV Upload Buffer"));
  1331. // Close the command list and execute it to perform the GPU setup.
  1332. pCommandList->Close();
  1333. ExecuteCommandList(pCommandQueue, pCommandList);
  1334. WaitForSignal(pCommandQueue, FO);
  1335. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1336. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1337. // Run the compute shader and copy the results back to readable memory.
  1338. {
  1339. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1340. uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
  1341. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1342. uavDesc.Buffer.FirstElement = 0;
  1343. uavDesc.Buffer.NumElements = (UINT)values.size();
  1344. uavDesc.Buffer.StructureByteStride = 0;
  1345. uavDesc.Buffer.CounterOffsetInBytes = 0;
  1346. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  1347. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  1348. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  1349. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  1350. SetDescriptorHeap(pCommandList, pUavHeap);
  1351. pCommandList->SetComputeRootSignature(pRootSignature);
  1352. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  1353. }
  1354. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  1355. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1356. pCommandList->CopyResource(pReadBuffer, pUavResource);
  1357. pCommandList->Close();
  1358. ExecuteCommandList(pCommandQueue, pCommandList);
  1359. WaitForSignal(pCommandQueue, FO);
  1360. {
  1361. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  1362. uint32_t *pData = (uint32_t *)mappedData.data();
  1363. memcpy(values.data(), pData, (size_t)valueSizeInBytes);
  1364. }
  1365. WaitForSignal(pCommandQueue, FO);
  1366. }
  1367. void ExecutionTest::RunLifetimeIntrinsicComputeTest(ID3D12Device *pDevice, LPCSTR pShader, CComPtr<ID3D12DescriptorHeap>& pUavHeap, CComPtr<ID3D12RootSignature>& pRootSignature,
  1368. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values) {
  1369. // Create command queue.
  1370. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1371. CreateComputeCommandQueue(pDevice, L"RunLifetimeIntrinsicTest Command Queue", &pCommandQueue);
  1372. FenceObj FO;
  1373. InitFenceObj(pDevice, &FO);
  1374. // Compile shader "main" and create pipeline state object.
  1375. CComPtr<ID3D12PipelineState> pComputeState;
  1376. CreateComputePSO(pDevice, pRootSignature, pShader, pTargetProfile, &pComputeState, pOptions, numOptions);
  1377. // Create a command allocator and list for compute.
  1378. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1379. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1380. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1381. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1382. pCommandList->SetName(L"ExecutionTest::RunLifetimeIntrinsicTest Command List");
  1383. // Set up UAV resource.
  1384. const UINT valueSizeInBytes = (UINT)values.size() * sizeof(uint32_t);
  1385. CComPtr<ID3D12Resource> pUavResource;
  1386. CComPtr<ID3D12Resource> pReadBuffer;
  1387. CComPtr<ID3D12Resource> pUploadResource;
  1388. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  1389. VERIFY_SUCCEEDED(pUavResource->SetName(L"RunLifetimeIntrinsicTest UAV"));
  1390. VERIFY_SUCCEEDED(pReadBuffer->SetName(L"RunLifetimeIntrinsicTest UAV Read Buffer"));
  1391. VERIFY_SUCCEEDED(pUploadResource->SetName(L"RunLifetimeIntrinsicTest UAV Upload Buffer"));
  1392. // Close the command list and execute it to perform the GPU setup.
  1393. pCommandList->Close();
  1394. ExecuteCommandList(pCommandQueue, pCommandList);
  1395. WaitForSignal(pCommandQueue, FO);
  1396. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1397. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1398. // Run the compute shader and copy the results back to readable memory.
  1399. {
  1400. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1401. uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
  1402. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1403. uavDesc.Buffer.FirstElement = 0;
  1404. uavDesc.Buffer.NumElements = (UINT)values.size();
  1405. uavDesc.Buffer.StructureByteStride = 0;
  1406. uavDesc.Buffer.CounterOffsetInBytes = 0;
  1407. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  1408. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  1409. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  1410. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  1411. SetDescriptorHeap(pCommandList, pUavHeap);
  1412. pCommandList->SetComputeRootSignature(pRootSignature);
  1413. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  1414. }
  1415. static const int DispatchGroupX = 1;
  1416. static const int DispatchGroupY = 1;
  1417. static const int DispatchGroupZ = 1;
  1418. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  1419. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1420. pCommandList->CopyResource(pReadBuffer, pUavResource);
  1421. pCommandList->Close();
  1422. ExecuteCommandList(pCommandQueue, pCommandList);
  1423. WaitForSignal(pCommandQueue, FO);
  1424. {
  1425. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  1426. uint32_t *pData = (uint32_t *)mappedData.data();
  1427. memcpy(values.data(), pData, (size_t)valueSizeInBytes);
  1428. }
  1429. WaitForSignal(pCommandQueue, FO);
  1430. }
  1431. void ExecutionTest::RunLifetimeIntrinsicLibTest(ID3D12Device5 *pDevice, LPCSTR pShader, CComPtr<ID3D12RootSignature>& pRootSignature,
  1432. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions) {
  1433. // Create command queue.
  1434. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1435. CreateCommandQueue(pDevice, L"RunLifetimeIntrinsicTest Command Queue", &pCommandQueue, D3D12_COMMAND_LIST_TYPE_DIRECT);
  1436. FenceObj FO;
  1437. InitFenceObj(pDevice, &FO);
  1438. // Compile raygen shader.
  1439. CComPtr<ID3DBlob> pShaderLib;
  1440. CompileFromText(pShader, L"RayGen", pTargetProfile, &pShaderLib, pOptions, numOptions);
  1441. // Describe and create the RT pipeline state object (RTPSO).
  1442. CD3DX12_STATE_OBJECT_DESC stateObjectDesc(D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE);
  1443. auto lib = stateObjectDesc.CreateSubobject<CD3DX12_DXIL_LIBRARY_SUBOBJECT>();
  1444. CD3DX12_SHADER_BYTECODE byteCode(pShaderLib);
  1445. lib->SetDXILLibrary(&byteCode);
  1446. lib->DefineExport(L"RayGen");
  1447. const int payloadCount = 4;
  1448. const int attributeCount = 2;
  1449. const int maxRecursion = 2;
  1450. stateObjectDesc.CreateSubobject<CD3DX12_RAYTRACING_SHADER_CONFIG_SUBOBJECT>()->Config(payloadCount * sizeof(float), attributeCount * sizeof(float));
  1451. stateObjectDesc.CreateSubobject<CD3DX12_RAYTRACING_PIPELINE_CONFIG_SUBOBJECT>()->Config(maxRecursion);
  1452. // Create (local!) root sig subobject and associate with shader.
  1453. auto localRootSigSubObj = stateObjectDesc.CreateSubobject<CD3DX12_LOCAL_ROOT_SIGNATURE_SUBOBJECT>();
  1454. localRootSigSubObj->SetRootSignature(pRootSignature);
  1455. auto x = stateObjectDesc.CreateSubobject<CD3DX12_SUBOBJECT_TO_EXPORTS_ASSOCIATION_SUBOBJECT>();
  1456. x->SetSubobjectToAssociate(*localRootSigSubObj);
  1457. x->AddExport(L"RayGen");
  1458. CComPtr<ID3D12StateObject> pStateObject;
  1459. VERIFY_SUCCEEDED(pDevice->CreateStateObject(stateObjectDesc, IID_PPV_ARGS(&pStateObject)));
  1460. // Create a command allocator and list.
  1461. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1462. CComPtr<ID3D12GraphicsCommandList4> pCommandList;
  1463. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&pCommandAllocator)));
  1464. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, pCommandAllocator, nullptr, IID_PPV_ARGS(&pCommandList)));
  1465. pCommandList->SetPipelineState1(pStateObject);
  1466. pCommandList->SetName(L"ExecutionTest::RunLifetimeIntrinsicTest Command List");
  1467. // Close the command list and execute it to kick-off compilation in the driver.
  1468. // NOTE: We don't care about anything else, so we're not setting up any resources and don't actually execute the shader.
  1469. pCommandList->Close();
  1470. ExecuteCommandList(pCommandQueue, pCommandList);
  1471. WaitForSignal(pCommandQueue, FO);
  1472. }
  1473. void ExecutionTest::RunLifetimeIntrinsicTest(ID3D12Device *pDevice, LPCSTR pShader, D3D_SHADER_MODEL shaderModel, bool useLibTarget,
  1474. LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values) {
  1475. LPCWSTR pTargetProfile;
  1476. switch (shaderModel) {
  1477. default: pTargetProfile = useLibTarget ? L"lib_6_3" : L"cs_6_0"; break; // Default to 6.3 for lib, 6.0 otherwise.
  1478. case D3D_SHADER_MODEL_6_0: pTargetProfile = useLibTarget ? L"lib_6_0" : L"cs_6_0"; break;
  1479. case D3D_SHADER_MODEL_6_3: pTargetProfile = useLibTarget ? L"lib_6_3" : L"cs_6_3"; break;
  1480. case D3D_SHADER_MODEL_6_5: pTargetProfile = useLibTarget ? L"lib_6_5" : L"cs_6_5"; break;
  1481. case D3D_SHADER_MODEL_6_6: pTargetProfile = useLibTarget ? L"lib_6_6" : L"cs_6_6"; break;
  1482. }
  1483. // Describe a UAV descriptor heap.
  1484. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1485. heapDesc.NumDescriptors = 1;
  1486. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1487. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1488. // Create the UAV descriptor heap.
  1489. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1490. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1491. // Create root signature.
  1492. CComPtr<ID3D12RootSignature> pRootSignature;
  1493. {
  1494. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1495. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1496. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1497. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1498. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1499. D3D12_ROOT_SIGNATURE_FLAGS rootSigFlag = useLibTarget ? D3D12_ROOT_SIGNATURE_FLAG_LOCAL_ROOT_SIGNATURE : D3D12_ROOT_SIGNATURE_FLAG_NONE;
  1500. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, rootSigFlag);
  1501. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  1502. }
  1503. if (useLibTarget)
  1504. RunLifetimeIntrinsicLibTest(reinterpret_cast<ID3D12Device5*>(pDevice), pShader, pRootSignature, pTargetProfile, pOptions, numOptions);
  1505. else
  1506. RunLifetimeIntrinsicComputeTest(pDevice, pShader, pUavHeap, pRootSignature, pTargetProfile, pOptions, numOptions, values);
  1507. }
  1508. TEST_F(ExecutionTest, LifetimeIntrinsicTest) {
  1509. // The only thing we test here is that existence of lifetime intrinsics or
  1510. // their fallback replacement (store undef or store zeroinitializer) do not
  1511. // cause any issues in the runtime and driver stack.
  1512. // The easiest way to force placement of intrinsics is to create an array in
  1513. // a local scope that is dynamically indexed. It must not be optimized away,
  1514. // so we do some bogus initialization that prevents this. Since all the code
  1515. // is guarded by a conditional that is dynamically always false, the actual
  1516. // effect of the shader is that the same value that was read is written back.
  1517. static const char* pShader = R"(
  1518. RWByteAddressBuffer g_bab : register(u0);
  1519. void fn(uint GI) {
  1520. const uint addr = GI * 4;
  1521. const int val = g_bab.Load(addr);
  1522. int res = val;
  1523. if (val < 0) { // Never true.
  1524. int arr[200];
  1525. for (int i = 0; i < 200; ++i) {
  1526. arr[i] = arr[val - i];
  1527. }
  1528. res += arr[val];
  1529. }
  1530. g_bab.Store(addr, (uint)res);
  1531. }
  1532. [numthreads(8,8,1)]
  1533. void main(uint GI : SV_GroupIndex) {
  1534. fn(GI);
  1535. }
  1536. [shader("raygeneration")]
  1537. void RayGen() {
  1538. const uint d = DispatchRaysIndex().x;
  1539. const uint g = g > 64 ? 63 : g;
  1540. fn(g);
  1541. }
  1542. )";
  1543. static const int NumThreadsX = 8;
  1544. static const int NumThreadsY = 8;
  1545. static const int NumThreadsZ = 1;
  1546. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1547. static const int DispatchGroupCount = 1;
  1548. // TODO: There's probably a lot of things in the rest of this test that could be stripped away.
  1549. CComPtr<ID3D12Device5> pDevice;
  1550. if (!CreateDevice(reinterpret_cast<ID3D12Device**>(&pDevice), D3D_SHADER_MODEL_6_6, true, true)) {
  1551. WEX::Logging::Log::Comment(L"Lifetime test not run pre 6.6");
  1552. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  1553. return;
  1554. }
  1555. std::vector<uint32_t> values;
  1556. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1557. // Run a number of tests for different configurations that will cause
  1558. // lifetime intrinsics to be placed directly, be replaced by a zeroinitializer
  1559. // store, or be replaced by an undef store.
  1560. LPCWSTR pOptions15[] = {L"/validator-version 1.5"};
  1561. LPCWSTR pOptions16[] = {L"/validator-version 1.6", L"/Vd"};
  1562. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1563. // Test regular shader with zeroinitializer store.
  1564. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_0, false, pOptions15, _countof(pOptions15), values);
  1565. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1566. if (DoesDeviceSupportRayTracing(pDevice)) {
  1567. // Test library with zeroinitializer store.
  1568. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_3, true, pOptions15, _countof(pOptions15), values);
  1569. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1570. }
  1571. // Testing SM 6.6 and validator version 1.6 requires experimental shaders
  1572. // being turned on.
  1573. if (!m_ExperimentalModeEnabled)
  1574. return;
  1575. // Test regular shader with undef store.
  1576. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_0, false, pOptions16, _countof(pOptions16), values);
  1577. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1578. if (DoesDeviceSupportRayTracing(pDevice)) {
  1579. // Test library with undef store.
  1580. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_3, true, pOptions16, _countof(pOptions16), values);
  1581. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1582. }
  1583. // Test regular shader with lifetime intrinsics.
  1584. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_5, false, pOptions16, _countof(pOptions16), values); // TODO: Test 6.6 here!
  1585. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1586. if (DoesDeviceSupportRayTracing(pDevice)) {
  1587. // Test library with lifetime intrinsics.
  1588. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_5, true, pOptions16, _countof(pOptions16), values); // TODO: Test 6.6 here!
  1589. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1590. }
  1591. }
  1592. TEST_F(ExecutionTest, BasicComputeTest) {
  1593. #ifndef _HLK_CONF
  1594. //
  1595. // BasicComputeTest is a simple compute shader that can be used as the basis
  1596. // for more interesting compute execution tests.
  1597. // The HLSL is compatible with shader models <=5.1 to allow using the DXBC
  1598. // rendering code paths for comparison.
  1599. //
  1600. static const char pShader[] =
  1601. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1602. "[numthreads(8,8,1)]\r\n"
  1603. "void main(uint GI : SV_GroupIndex) {"
  1604. " uint addr = GI * 4;\r\n"
  1605. " uint val = g_bab.Load(addr);\r\n"
  1606. " DeviceMemoryBarrierWithGroupSync();\r\n"
  1607. " g_bab.Store(addr, val + 1);\r\n"
  1608. "}";
  1609. static const int NumThreadsX = 8;
  1610. static const int NumThreadsY = 8;
  1611. static const int NumThreadsZ = 1;
  1612. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1613. static const int DispatchGroupCount = 1;
  1614. CComPtr<ID3D12Device> pDevice;
  1615. if (!CreateDevice(&pDevice))
  1616. return;
  1617. std::vector<uint32_t> values;
  1618. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1619. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1620. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1621. VERIFY_ARE_EQUAL(values[0], (uint32_t)1);
  1622. #endif
  1623. }
  1624. TEST_F(ExecutionTest, BasicTriangleTest) {
  1625. #ifndef _HLK_CONF
  1626. static const UINT FrameCount = 2;
  1627. static const UINT m_width = 320;
  1628. static const UINT m_height = 200;
  1629. static const float m_aspectRatio = static_cast<float>(m_width) / static_cast<float>(m_height);
  1630. struct Vertex {
  1631. XMFLOAT3 position;
  1632. XMFLOAT4 color;
  1633. };
  1634. // Pipeline objects.
  1635. CComPtr<ID3D12Device> pDevice;
  1636. CComPtr<ID3D12Resource> pRenderTarget;
  1637. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1638. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1639. CComPtr<ID3D12RootSignature> pRootSig;
  1640. CComPtr<ID3D12DescriptorHeap> pRtvHeap;
  1641. CComPtr<ID3D12PipelineState> pPipelineState;
  1642. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1643. CComPtr<ID3D12Resource> pReadBuffer;
  1644. UINT rtvDescriptorSize;
  1645. CComPtr<ID3D12Resource> pVertexBuffer;
  1646. D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
  1647. // Synchronization objects.
  1648. FenceObj FO;
  1649. // Shaders.
  1650. static const char pShaders[] =
  1651. "struct PSInput {\r\n"
  1652. " float4 position : SV_POSITION;\r\n"
  1653. " float4 color : COLOR;\r\n"
  1654. "};\r\n\r\n"
  1655. "PSInput VSMain(float4 position : POSITION, float4 color : COLOR) {\r\n"
  1656. " PSInput result;\r\n"
  1657. "\r\n"
  1658. " result.position = position;\r\n"
  1659. " result.color = color;\r\n"
  1660. " return result;\r\n"
  1661. "}\r\n\r\n"
  1662. "float4 PSMain(PSInput input) : SV_TARGET {\r\n"
  1663. " return 1; //input.color;\r\n"
  1664. "};\r\n";
  1665. if (!CreateDevice(&pDevice))
  1666. return;
  1667. struct BasicTestChecker {
  1668. CComPtr<ID3D12Device> m_pDevice;
  1669. CComPtr<ID3D12InfoQueue> m_pInfoQueue;
  1670. bool m_OK = false;
  1671. void SetOK(bool value) { m_OK = value; }
  1672. BasicTestChecker(ID3D12Device *pDevice) : m_pDevice(pDevice) {
  1673. if (FAILED(m_pDevice.QueryInterface(&m_pInfoQueue)))
  1674. return;
  1675. m_pInfoQueue->PushEmptyStorageFilter();
  1676. m_pInfoQueue->PushEmptyRetrievalFilter();
  1677. }
  1678. ~BasicTestChecker() {
  1679. if (!m_OK && m_pInfoQueue != nullptr) {
  1680. UINT64 count = m_pInfoQueue->GetNumStoredMessages();
  1681. bool invalidBytecodeFound = false;
  1682. CAtlArray<BYTE> m_pBytes;
  1683. for (UINT64 i = 0; i < count; ++i) {
  1684. SIZE_T len = 0;
  1685. if (FAILED(m_pInfoQueue->GetMessageA(i, nullptr, &len)))
  1686. continue;
  1687. if (m_pBytes.GetCount() < len && !m_pBytes.SetCount(len))
  1688. continue;
  1689. D3D12_MESSAGE *pMsg = (D3D12_MESSAGE *)m_pBytes.GetData();
  1690. if (FAILED(m_pInfoQueue->GetMessageA(i, pMsg, &len)))
  1691. continue;
  1692. if (pMsg->ID == D3D12_MESSAGE_ID_CREATEVERTEXSHADER_INVALIDSHADERBYTECODE ||
  1693. pMsg->ID == D3D12_MESSAGE_ID_CREATEPIXELSHADER_INVALIDSHADERBYTECODE) {
  1694. invalidBytecodeFound = true;
  1695. break;
  1696. }
  1697. }
  1698. if (invalidBytecodeFound) {
  1699. LogCommentFmt(L"%s", L"Found an invalid bytecode message. This "
  1700. L"typically indicates that experimental mode "
  1701. L"is not set up properly.");
  1702. if (!GetTestParamBool(L"ExperimentalShaders")) {
  1703. LogCommentFmt(L"Note that the ExperimentalShaders test parameter isn't set.");
  1704. }
  1705. }
  1706. else {
  1707. LogCommentFmt(L"Did not find corrupt pixel or vertex shaders in "
  1708. L"queue - dumping complete queue.");
  1709. WriteInfoQueueMessages(nullptr, OutputFn, m_pInfoQueue);
  1710. }
  1711. }
  1712. }
  1713. static void __stdcall OutputFn(void *pCtx, const wchar_t *pMsg) {
  1714. UNREFERENCED_PARAMETER(pCtx);
  1715. LogCommentFmt(L"%s", pMsg);
  1716. }
  1717. };
  1718. BasicTestChecker BTC(pDevice);
  1719. {
  1720. InitFenceObj(pDevice, &FO);
  1721. CreateRtvDescriptorHeap(pDevice, FrameCount, &pRtvHeap, &rtvDescriptorSize);
  1722. CreateRenderTargetAndReadback(pDevice, pRtvHeap, m_width, m_height, &pRenderTarget, &pReadBuffer);
  1723. // Create an empty root signature.
  1724. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1725. rootSignatureDesc.Init(
  1726. 0, nullptr, 0, nullptr,
  1727. D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
  1728. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSig);
  1729. // Create the pipeline state, which includes compiling and loading shaders.
  1730. // Define the vertex input layout.
  1731. D3D12_INPUT_ELEMENT_DESC inputElementDescs[] = {
  1732. {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
  1733. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
  1734. {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12,
  1735. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}};
  1736. D3D12_INPUT_LAYOUT_DESC InputLayout = { inputElementDescs, _countof(inputElementDescs) };
  1737. CreateGraphicsPSO(pDevice, &InputLayout, pRootSig, pShaders, &pPipelineState);
  1738. CreateGraphicsCommandQueueAndList(pDevice, &pCommandQueue,
  1739. &pCommandAllocator, &pCommandList,
  1740. pPipelineState);
  1741. // Define the geometry for a triangle.
  1742. Vertex triangleVertices[] = {
  1743. { { 0.0f, 0.25f * m_aspectRatio, 0.0f },{ 1.0f, 0.0f, 0.0f, 1.0f } },
  1744. { { 0.25f, -0.25f * m_aspectRatio, 0.0f },{ 0.0f, 1.0f, 0.0f, 1.0f } },
  1745. { { -0.25f, -0.25f * m_aspectRatio, 0.0f },{ 0.0f, 0.0f, 1.0f, 1.0f } } };
  1746. CreateVertexBuffer(pDevice, triangleVertices, &pVertexBuffer, &vertexBufferView);
  1747. WaitForSignal(pCommandQueue, FO);
  1748. }
  1749. // Render and execute the command list.
  1750. RecordRenderAndReadback(pCommandList, pRtvHeap, rtvDescriptorSize, 1,
  1751. &vertexBufferView, pRootSig, pRenderTarget,
  1752. pReadBuffer);
  1753. VERIFY_SUCCEEDED(pCommandList->Close());
  1754. ExecuteCommandList(pCommandQueue, pCommandList);
  1755. // Wait for previous frame.
  1756. WaitForSignal(pCommandQueue, FO);
  1757. // At this point, we've verified that execution succeeded with DXIL.
  1758. BTC.SetOK(true);
  1759. // Read back to CPU and examine contents.
  1760. {
  1761. MappedData data(pReadBuffer, m_width * m_height * 4);
  1762. const uint32_t *pPixels = (uint32_t *)data.data();
  1763. if (SaveImages()) {
  1764. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, m_width, m_height, L"basic.bmp");
  1765. }
  1766. uint32_t top = pPixels[m_width / 2]; // Top center.
  1767. uint32_t mid = pPixels[m_width / 2 + m_width * (m_height / 2)]; // Middle center.
  1768. VERIFY_ARE_EQUAL(0xff663300, top); // clear color
  1769. VERIFY_ARE_EQUAL(0xffffffff, mid); // white
  1770. }
  1771. #endif
  1772. }
  1773. TEST_F(ExecutionTest, Int64Test) {
  1774. static const char pShader[] =
  1775. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1776. "[numthreads(8,8,1)]\r\n"
  1777. "void main(uint GI : SV_GroupIndex) {"
  1778. " uint addr = GI * 4;\r\n"
  1779. " uint val = g_bab.Load(addr);\r\n"
  1780. " uint64_t u64 = val;\r\n"
  1781. " u64 *= val;\r\n"
  1782. " g_bab.Store(addr, (uint)(u64 >> 32));\r\n"
  1783. "}";
  1784. static const int NumThreadsX = 8;
  1785. static const int NumThreadsY = 8;
  1786. static const int NumThreadsZ = 1;
  1787. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1788. static const int DispatchGroupCount = 1;
  1789. CComPtr<ID3D12Device> pDevice;
  1790. if (!CreateDevice(&pDevice))
  1791. return;
  1792. if (!DoesDeviceSupportInt64(pDevice)) {
  1793. // Optional feature, so it's correct to not support it if declared as such.
  1794. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  1795. return;
  1796. }
  1797. std::vector<uint32_t> values;
  1798. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1799. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1800. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1801. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1802. }
  1803. TEST_F(ExecutionTest, SignTest) {
  1804. static const char pShader[] =
  1805. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1806. "[numthreads(8,1,1)]\r\n"
  1807. "void main(uint GI : SV_GroupIndex) {"
  1808. " uint addr = GI * 4;\r\n"
  1809. " int val = g_bab.Load(addr);\r\n"
  1810. " g_bab.Store(addr, (uint)(sign(val)));\r\n"
  1811. "}";
  1812. static const int NumThreadsX = 8;
  1813. static const int NumThreadsY = 1;
  1814. static const int NumThreadsZ = 1;
  1815. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1816. static const int DispatchGroupCount = 1;
  1817. CComPtr<ID3D12Device> pDevice;
  1818. if (!CreateDevice(&pDevice))
  1819. return;
  1820. const uint32_t neg1 = (uint32_t)-1;
  1821. uint32_t origValues[] = { (uint32_t)-3, (uint32_t)-2, neg1, 0, 1, 2, 3, 4 };
  1822. std::vector<uint32_t> values(origValues, origValues + _countof(origValues));
  1823. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1824. VERIFY_ARE_EQUAL(values[0], neg1);
  1825. VERIFY_ARE_EQUAL(values[1], neg1);
  1826. VERIFY_ARE_EQUAL(values[2], neg1);
  1827. VERIFY_ARE_EQUAL(values[3], (uint32_t)0);
  1828. VERIFY_ARE_EQUAL(values[4], (uint32_t)1);
  1829. VERIFY_ARE_EQUAL(values[5], (uint32_t)1);
  1830. VERIFY_ARE_EQUAL(values[6], (uint32_t)1);
  1831. VERIFY_ARE_EQUAL(values[7], (uint32_t)1);
  1832. }
  1833. TEST_F(ExecutionTest, WaveIntrinsicsDDITest) {
  1834. #ifndef _HLK_CONF
  1835. CComPtr<ID3D12Device> pDevice;
  1836. if (!CreateDevice(&pDevice))
  1837. return;
  1838. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  1839. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  1840. return;
  1841. bool waveSupported = O.WaveOps;
  1842. UINT laneCountMin = O.WaveLaneCountMin;
  1843. UINT laneCountMax = O.WaveLaneCountMax;
  1844. LogCommentFmt(L"WaveOps %i, WaveLaneCountMin %u, WaveLaneCountMax %u", waveSupported, laneCountMin, laneCountMax);
  1845. VERIFY_IS_TRUE(laneCountMin <= laneCountMax);
  1846. if (waveSupported) {
  1847. VERIFY_IS_TRUE(laneCountMin > 0 && laneCountMax > 0);
  1848. }
  1849. else {
  1850. VERIFY_IS_TRUE(laneCountMin == 0 && laneCountMax == 0);
  1851. }
  1852. #endif
  1853. }
  1854. TEST_F(ExecutionTest, WaveIntrinsicsTest) {
  1855. #ifndef _HLK_CONF
  1856. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  1857. struct PerThreadData {
  1858. uint32_t id, flags, laneIndex, laneCount, firstLaneId, preds, firstlaneX, lane1X;
  1859. uint32_t allBC, allSum, allProd, allAND, allOR, allXOR, allMin, allMax;
  1860. uint32_t pfBC, pfSum, pfProd;
  1861. uint32_t ballot[4];
  1862. uint32_t diver; // divergent value, used in calculation
  1863. int32_t i_diver; // divergent value, used in calculation
  1864. int32_t i_allMax, i_allMin, i_allSum, i_allProd;
  1865. int32_t i_pfSum, i_pfProd;
  1866. };
  1867. static const char pShader[] =
  1868. WAVE_INTRINSIC_DXBC_GUARD
  1869. "struct PerThreadData {\r\n"
  1870. " uint id, flags, laneIndex, laneCount, firstLaneId, preds, firstlaneX, lane1X;\r\n"
  1871. " uint allBC, allSum, allProd, allAND, allOR, allXOR, allMin, allMax;\r\n"
  1872. " uint pfBC, pfSum, pfProd;\r\n"
  1873. " uint4 ballot;\r\n"
  1874. " uint diver;\r\n"
  1875. " int i_diver;\r\n"
  1876. " int i_allMax, i_allMin, i_allSum, i_allProd;\r\n"
  1877. " int i_pfSum, i_pfProd;\r\n"
  1878. "};\r\n"
  1879. "RWStructuredBuffer<PerThreadData> g_sb : register(u0);\r\n"
  1880. "[numthreads(8,8,1)]\r\n"
  1881. "void main(uint GI : SV_GroupIndex, uint3 GTID : SV_GroupThreadID) {"
  1882. " PerThreadData pts = g_sb[GI];\r\n"
  1883. " uint diver = GTID.x + 2;\r\n"
  1884. " pts.diver = diver;\r\n"
  1885. " pts.flags = 0;\r\n"
  1886. " pts.preds = 0;\r\n"
  1887. " if (WaveIsFirstLane()) pts.flags |= 1;\r\n"
  1888. " pts.laneIndex = WaveGetLaneIndex();\r\n"
  1889. " pts.laneCount = WaveGetLaneCount();\r\n"
  1890. " pts.firstLaneId = WaveReadLaneFirst(pts.id);\r\n"
  1891. " pts.preds |= ((WaveActiveAnyTrue(diver == 1) ? 1 : 0) << 0);\r\n"
  1892. " pts.preds |= ((WaveActiveAllTrue(diver == 1) ? 1 : 0) << 1);\r\n"
  1893. " pts.preds |= ((WaveActiveAllEqual(diver) ? 1 : 0) << 2);\r\n"
  1894. " pts.preds |= ((WaveActiveAllEqual(GTID.z) ? 1 : 0) << 3);\r\n"
  1895. " pts.preds |= ((WaveActiveAllEqual(WaveReadLaneFirst(diver)) ? 1 : 0) << 4);\r\n"
  1896. " pts.ballot = WaveActiveBallot(diver > 3);\r\n"
  1897. " pts.firstlaneX = WaveReadLaneFirst(GTID.x);\r\n"
  1898. " pts.lane1X = WaveReadLaneAt(GTID.x, 1);\r\n"
  1899. "\r\n"
  1900. " pts.allBC = WaveActiveCountBits(diver > 3);\r\n"
  1901. " pts.allSum = WaveActiveSum(diver);\r\n"
  1902. " pts.allProd = WaveActiveProduct(diver);\r\n"
  1903. " pts.allAND = WaveActiveBitAnd(diver);\r\n"
  1904. " pts.allOR = WaveActiveBitOr(diver);\r\n"
  1905. " pts.allXOR = WaveActiveBitXor(diver);\r\n"
  1906. " pts.allMin = WaveActiveMin(diver);\r\n"
  1907. " pts.allMax = WaveActiveMax(diver);\r\n"
  1908. "\r\n"
  1909. " pts.pfBC = WavePrefixCountBits(diver > 3);\r\n"
  1910. " pts.pfSum = WavePrefixSum(diver);\r\n"
  1911. " pts.pfProd = WavePrefixProduct(diver);\r\n"
  1912. "\r\n"
  1913. " int i_diver = pts.i_diver;\r\n"
  1914. " pts.i_allMax = WaveActiveMax(i_diver);\r\n"
  1915. " pts.i_allMin = WaveActiveMin(i_diver);\r\n"
  1916. " pts.i_allSum = WaveActiveSum(i_diver);\r\n"
  1917. " pts.i_allProd = WaveActiveProduct(i_diver);\r\n"
  1918. " pts.i_pfSum = WavePrefixSum(i_diver);\r\n"
  1919. " pts.i_pfProd = WavePrefixProduct(i_diver);\r\n"
  1920. "\r\n"
  1921. " g_sb[GI] = pts;\r\n"
  1922. "}";
  1923. static const int NumtheadsX = 8;
  1924. static const int NumtheadsY = 8;
  1925. static const int NumtheadsZ = 1;
  1926. static const int ThreadsPerGroup = NumtheadsX * NumtheadsY * NumtheadsZ;
  1927. static const int DispatchGroupCount = 1;
  1928. CComPtr<ID3D12Device> pDevice;
  1929. if (!CreateDevice(&pDevice))
  1930. return;
  1931. if (!DoesDeviceSupportWaveOps(pDevice)) {
  1932. // Optional feature, so it's correct to not support it if declared as such.
  1933. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  1934. return;
  1935. }
  1936. std::vector<PerThreadData> values;
  1937. values.resize(ThreadsPerGroup * DispatchGroupCount);
  1938. for (size_t i = 0; i < values.size(); ++i) {
  1939. memset(&values[i], 0, sizeof(PerThreadData));
  1940. values[i].id = (uint32_t)i;
  1941. values[i].i_diver = (int)i;
  1942. values[i].i_diver *= (i % 2) ? 1 : -1;
  1943. }
  1944. static const int DispatchGroupX = 1;
  1945. static const int DispatchGroupY = 1;
  1946. static const int DispatchGroupZ = 1;
  1947. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1948. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1949. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1950. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1951. UINT uavDescriptorSize;
  1952. FenceObj FO;
  1953. bool dxbc = UseDxbc();
  1954. const size_t valueSizeInBytes = values.size() * sizeof(PerThreadData);
  1955. CreateComputeCommandQueue(pDevice, L"WaveIntrinsicsTest Command Queue", &pCommandQueue);
  1956. InitFenceObj(pDevice, &FO);
  1957. // Describe and create a UAV descriptor heap.
  1958. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1959. heapDesc.NumDescriptors = 1;
  1960. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1961. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1962. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1963. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  1964. // Create root signature.
  1965. CComPtr<ID3D12RootSignature> pRootSignature;
  1966. {
  1967. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1968. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1969. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1970. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1971. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1972. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  1973. CComPtr<ID3DBlob> signature;
  1974. CComPtr<ID3DBlob> error;
  1975. VERIFY_SUCCEEDED(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
  1976. VERIFY_SUCCEEDED(pDevice->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&pRootSignature)));
  1977. }
  1978. // Create pipeline state object.
  1979. CComPtr<ID3D12PipelineState> pComputeState;
  1980. CreateComputePSO(pDevice, pRootSignature, pShader, L"cs_6_0", &pComputeState);
  1981. // Create a command allocator and list for compute.
  1982. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1983. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1984. // Set up UAV resource.
  1985. CComPtr<ID3D12Resource> pUavResource;
  1986. CComPtr<ID3D12Resource> pReadBuffer;
  1987. CComPtr<ID3D12Resource> pUploadResource;
  1988. CreateTestUavs(pDevice, pCommandList, values.data(), (UINT)valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  1989. // Close the command list and execute it to perform the GPU setup.
  1990. pCommandList->Close();
  1991. ExecuteCommandList(pCommandQueue, pCommandList);
  1992. WaitForSignal(pCommandQueue, FO);
  1993. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1994. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1995. // Run the compute shader and copy the results back to readable memory.
  1996. {
  1997. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1998. uavDesc.Format = DXGI_FORMAT_UNKNOWN;
  1999. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  2000. uavDesc.Buffer.FirstElement = 0;
  2001. uavDesc.Buffer.NumElements = (UINT)values.size();
  2002. uavDesc.Buffer.StructureByteStride = sizeof(PerThreadData);
  2003. uavDesc.Buffer.CounterOffsetInBytes = 0;
  2004. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  2005. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  2006. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  2007. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  2008. SetDescriptorHeap(pCommandList, pUavHeap);
  2009. pCommandList->SetComputeRootSignature(pRootSignature);
  2010. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  2011. }
  2012. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  2013. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2014. pCommandList->CopyResource(pReadBuffer, pUavResource);
  2015. pCommandList->Close();
  2016. ExecuteCommandList(pCommandQueue, pCommandList);
  2017. WaitForSignal(pCommandQueue, FO);
  2018. {
  2019. MappedData mappedData(pReadBuffer, (UINT)valueSizeInBytes);
  2020. PerThreadData *pData = (PerThreadData *)mappedData.data();
  2021. memcpy(values.data(), pData, valueSizeInBytes);
  2022. // Gather some general data.
  2023. // The 'firstLaneId' captures a unique number per first-lane per wave.
  2024. // Counting the number distinct firstLaneIds gives us the number of waves.
  2025. std::vector<uint32_t> firstLaneIds;
  2026. for (size_t i = 0; i < values.size(); ++i) {
  2027. PerThreadData &pts = values[i];
  2028. uint32_t firstLaneId = pts.firstLaneId;
  2029. if (!contains(firstLaneIds, firstLaneId)) {
  2030. firstLaneIds.push_back(firstLaneId);
  2031. }
  2032. }
  2033. // Waves should cover 4 threads or more.
  2034. LogCommentFmt(L"Found %u distinct lane ids: %u", firstLaneIds.size());
  2035. if (!dxbc) {
  2036. VERIFY_IS_GREATER_THAN_OR_EQUAL(values.size() / 4, firstLaneIds.size());
  2037. }
  2038. // Now, group threads into waves.
  2039. std::map<uint32_t, std::unique_ptr<std::vector<PerThreadData *> > > waves;
  2040. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  2041. waves[firstLaneIds[i]] = std::make_unique<std::vector<PerThreadData *> >();
  2042. }
  2043. for (size_t i = 0; i < values.size(); ++i) {
  2044. PerThreadData &pts = values[i];
  2045. std::unique_ptr<std::vector<PerThreadData *> > &wave = waves[pts.firstLaneId];
  2046. wave->push_back(&pts);
  2047. }
  2048. // Verify that all the wave values are coherent across the wave.
  2049. for (size_t i = 0; i < values.size(); ++i) {
  2050. PerThreadData &pts = values[i];
  2051. std::unique_ptr<std::vector<PerThreadData *> > &wave = waves[pts.firstLaneId];
  2052. // Sort the lanes by increasing lane ID.
  2053. struct LaneIdOrderPred {
  2054. bool operator()(PerThreadData *a, PerThreadData *b) {
  2055. return a->laneIndex < b->laneIndex;
  2056. }
  2057. };
  2058. std::sort(wave.get()->begin(), wave.get()->end(), LaneIdOrderPred());
  2059. // Verify some interesting properties of the first lane.
  2060. uint32_t pfBC, pfSum, pfProd;
  2061. int32_t i_pfSum, i_pfProd;
  2062. int32_t i_allMax, i_allMin;
  2063. {
  2064. PerThreadData *ptdFirst = wave->front();
  2065. VERIFY_IS_TRUE(0 != (ptdFirst->flags & 1)); // FirstLane sets this bit.
  2066. VERIFY_IS_TRUE(0 == ptdFirst->pfBC);
  2067. VERIFY_IS_TRUE(0 == ptdFirst->pfSum);
  2068. VERIFY_IS_TRUE(1 == ptdFirst->pfProd);
  2069. VERIFY_IS_TRUE(0 == ptdFirst->i_pfSum);
  2070. VERIFY_IS_TRUE(1 == ptdFirst->i_pfProd);
  2071. pfBC = (ptdFirst->diver > 3) ? 1 : 0;
  2072. pfSum = ptdFirst->diver;
  2073. pfProd = ptdFirst->diver;
  2074. i_pfSum = ptdFirst->i_diver;
  2075. i_pfProd = ptdFirst->i_diver;
  2076. i_allMax = i_allMin = ptdFirst->i_diver;
  2077. }
  2078. // Calculate values which take into consideration all lanes.
  2079. uint32_t preds = 0;
  2080. preds |= 1 << 1; // AllTrue starts true, switches to false if needed.
  2081. preds |= 1 << 2; // AllEqual starts true, switches to false if needed.
  2082. preds |= 1 << 3; // WaveActiveAllEqual(GTID.z) is always true
  2083. preds |= 1 << 4; // (WaveActiveAllEqual(WaveReadLaneFirst(diver)) is always true
  2084. uint32_t ballot[4] = { 0, 0, 0, 0 };
  2085. int32_t i_allSum = 0, i_allProd = 1;
  2086. for (size_t n = 0; n < wave->size(); ++n) {
  2087. std::vector<PerThreadData *> &lanes = *wave.get();
  2088. // pts.preds |= ((WaveActiveAnyTrue(diver == 1) ? 1 : 0) << 0);
  2089. if (lanes[n]->diver == 1) preds |= (1 << 0);
  2090. // pts.preds |= ((WaveActiveAllTrue(diver == 1) ? 1 : 0) << 1);
  2091. if (lanes[n]->diver != 1) preds &= ~(1 << 1);
  2092. // pts.preds |= ((WaveActiveAllEqual(diver) ? 1 : 0) << 2);
  2093. if (lanes[0]->diver != lanes[n]->diver) preds &= ~(1 << 2);
  2094. // pts.ballot = WaveActiveBallot(diver > 3);\r\n"
  2095. if (lanes[n]->diver > 3) {
  2096. // This is the uint4 result layout:
  2097. // .x -> bits 0 .. 31
  2098. // .y -> bits 32 .. 63
  2099. // .z -> bits 64 .. 95
  2100. // .w -> bits 96 ..127
  2101. uint32_t component = lanes[n]->laneIndex / 32;
  2102. uint32_t bit = lanes[n]->laneIndex % 32;
  2103. ballot[component] |= 1 << bit;
  2104. }
  2105. i_allMax = std::max(lanes[n]->i_diver, i_allMax);
  2106. i_allMin = std::min(lanes[n]->i_diver, i_allMin);
  2107. i_allProd *= lanes[n]->i_diver;
  2108. i_allSum += lanes[n]->i_diver;
  2109. }
  2110. for (size_t n = 1; n < wave->size(); ++n) {
  2111. // 'All' operations are uniform across the wave.
  2112. std::vector<PerThreadData *> &lanes = *wave.get();
  2113. VERIFY_IS_TRUE(0 == (lanes[n]->flags & 1)); // non-firstlanes do not set this bit
  2114. VERIFY_ARE_EQUAL(lanes[0]->allBC, lanes[n]->allBC);
  2115. VERIFY_ARE_EQUAL(lanes[0]->allSum, lanes[n]->allSum);
  2116. VERIFY_ARE_EQUAL(lanes[0]->allProd, lanes[n]->allProd);
  2117. VERIFY_ARE_EQUAL(lanes[0]->allAND, lanes[n]->allAND);
  2118. VERIFY_ARE_EQUAL(lanes[0]->allOR, lanes[n]->allOR);
  2119. VERIFY_ARE_EQUAL(lanes[0]->allXOR, lanes[n]->allXOR);
  2120. VERIFY_ARE_EQUAL(lanes[0]->allMin, lanes[n]->allMin);
  2121. VERIFY_ARE_EQUAL(lanes[0]->allMax, lanes[n]->allMax);
  2122. VERIFY_ARE_EQUAL(i_allMax, lanes[n]->i_allMax);
  2123. VERIFY_ARE_EQUAL(i_allMin, lanes[n]->i_allMin);
  2124. VERIFY_ARE_EQUAL(i_allProd, lanes[n]->i_allProd);
  2125. VERIFY_ARE_EQUAL(i_allSum, lanes[n]->i_allSum);
  2126. // first-lane reads and uniform reads are uniform across the wave.
  2127. VERIFY_ARE_EQUAL(lanes[0]->firstlaneX, lanes[n]->firstlaneX);
  2128. VERIFY_ARE_EQUAL(lanes[0]->lane1X, lanes[n]->lane1X);
  2129. // the lane count is uniform across the wave.
  2130. VERIFY_ARE_EQUAL(lanes[0]->laneCount, lanes[n]->laneCount);
  2131. // The predicates are uniform across the wave.
  2132. VERIFY_ARE_EQUAL(lanes[n]->preds, preds);
  2133. // the lane index is distinct per thread.
  2134. for (size_t prior = 0; prior < n; ++prior) {
  2135. VERIFY_ARE_NOT_EQUAL(lanes[prior]->laneIndex, lanes[n]->laneIndex);
  2136. }
  2137. // Ballot results are uniform across the wave.
  2138. VERIFY_ARE_EQUAL(0, memcmp(ballot, lanes[n]->ballot, sizeof(ballot)));
  2139. // Keep running total of prefix calculation. Prefix values are exclusive to
  2140. // the executing lane.
  2141. VERIFY_ARE_EQUAL(pfBC, lanes[n]->pfBC);
  2142. VERIFY_ARE_EQUAL(pfSum, lanes[n]->pfSum);
  2143. VERIFY_ARE_EQUAL(pfProd, lanes[n]->pfProd);
  2144. VERIFY_ARE_EQUAL(i_pfSum, lanes[n]->i_pfSum);
  2145. VERIFY_ARE_EQUAL(i_pfProd, lanes[n]->i_pfProd);
  2146. pfBC += (lanes[n]->diver > 3) ? 1 : 0;
  2147. pfSum += lanes[n]->diver;
  2148. pfProd *= lanes[n]->diver;
  2149. i_pfSum += lanes[n]->i_diver;
  2150. i_pfProd *= lanes[n]->i_diver;
  2151. }
  2152. // TODO: add divergent branching and verify that the otherwise uniform values properly diverge
  2153. }
  2154. // Compare each value of each per-thread element.
  2155. for (size_t i = 0; i < values.size(); ++i) {
  2156. PerThreadData &pts = values[i];
  2157. VERIFY_ARE_EQUAL(i, pts.id); // ID is unchanged.
  2158. }
  2159. }
  2160. #endif
  2161. }
  2162. // This test is assuming that the adapter implements WaveReadLaneFirst correctly
  2163. TEST_F(ExecutionTest, WaveIntrinsicsInPSTest) {
  2164. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2165. struct Vertex {
  2166. XMFLOAT3 position;
  2167. };
  2168. struct PerPixelData {
  2169. XMFLOAT4 position;
  2170. uint32_t id, flags, laneIndex, laneCount, firstLaneId, sum1;
  2171. uint32_t id0, id1, id2, id3;
  2172. uint32_t acrossX, acrossY, acrossDiag, quadActiveCount;
  2173. };
  2174. const UINT RTWidth = 128;
  2175. const UINT RTHeight = 128;
  2176. // Shaders.
  2177. static const char pShaders[] =
  2178. WAVE_INTRINSIC_DXBC_GUARD
  2179. "struct PSInput {\r\n"
  2180. " float4 position : SV_POSITION;\r\n"
  2181. "};\r\n\r\n"
  2182. "PSInput VSMain(float4 position : POSITION) {\r\n"
  2183. " PSInput result;\r\n"
  2184. "\r\n"
  2185. " result.position = position;\r\n"
  2186. " return result;\r\n"
  2187. "}\r\n\r\n"
  2188. "uint pos_to_id(float4 pos) { return pos.x * 128 + pos.y; }\r\n"
  2189. "struct PerPixelData {\r\n"
  2190. " float4 position;\r\n"
  2191. " uint id, flags, laneIndex, laneCount, firstLaneId, sum1;\r\n"
  2192. " uint id0, id1, id2, id3;\r\n"
  2193. " uint acrossX, acrossY, acrossDiag, quadActiveCount;\r\n"
  2194. "};\r\n"
  2195. "AppendStructuredBuffer<PerPixelData> g_sb : register(u1);\r\n"
  2196. "float4 PSMain(PSInput input) : SV_TARGET {\r\n"
  2197. " uint one = 1;\r\n"
  2198. " PerPixelData d;\r\n"
  2199. " d.position = input.position;\r\n"
  2200. " d.id = pos_to_id(input.position);\r\n"
  2201. " d.flags = 0;\r\n"
  2202. " if (WaveIsFirstLane()) d.flags |= 1;\r\n"
  2203. " d.laneIndex = WaveGetLaneIndex();\r\n"
  2204. " d.laneCount = WaveGetLaneCount();\r\n"
  2205. " d.firstLaneId = WaveReadLaneFirst(d.id);\r\n"
  2206. " d.sum1 = WaveActiveSum(one);\r\n"
  2207. " d.id0 = QuadReadLaneAt(d.id, 0);\r\n"
  2208. " d.id1 = QuadReadLaneAt(d.id, 1);\r\n"
  2209. " d.id2 = QuadReadLaneAt(d.id, 2);\r\n"
  2210. " d.id3 = QuadReadLaneAt(d.id, 3);\r\n"
  2211. " d.acrossX = QuadReadAcrossX(d.id);\r\n"
  2212. " d.acrossY = QuadReadAcrossY(d.id);\r\n"
  2213. " d.acrossDiag = QuadReadAcrossDiagonal(d.id);\r\n"
  2214. " d.quadActiveCount = one + QuadReadAcrossX(one) + QuadReadAcrossY(one) + QuadReadAcrossDiagonal(one);\r\n"
  2215. " g_sb.Append(d);\r\n"
  2216. " return 1;\r\n"
  2217. "};\r\n";
  2218. CComPtr<ID3D12Device> pDevice;
  2219. CComPtr<ID3D12CommandQueue> pCommandQueue;
  2220. CComPtr<ID3D12DescriptorHeap> pUavHeap, pRtvHeap;
  2221. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  2222. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  2223. CComPtr<ID3D12PipelineState> pPSO;
  2224. CComPtr<ID3D12Resource> pRenderTarget, pReadBuffer;
  2225. UINT uavDescriptorSize, rtvDescriptorSize;
  2226. CComPtr<ID3D12Resource> pVertexBuffer;
  2227. D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
  2228. if (!CreateDevice(&pDevice))
  2229. return;
  2230. if (!DoesDeviceSupportWaveOps(pDevice)) {
  2231. // Optional feature, so it's correct to not support it if declared as such.
  2232. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  2233. return;
  2234. }
  2235. FenceObj FO;
  2236. InitFenceObj(pDevice, &FO);
  2237. // Describe and create a UAV descriptor heap.
  2238. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  2239. heapDesc.NumDescriptors = 1;
  2240. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  2241. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  2242. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  2243. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  2244. CreateRtvDescriptorHeap(pDevice, 1, &pRtvHeap, &rtvDescriptorSize);
  2245. CreateRenderTargetAndReadback(pDevice, pRtvHeap, RTHeight, RTWidth, &pRenderTarget, &pReadBuffer);
  2246. // Create root signature: one UAV.
  2247. CComPtr<ID3D12RootSignature> pRootSignature;
  2248. {
  2249. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  2250. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 1, 0, 0);
  2251. CD3DX12_ROOT_PARAMETER rootParameters[1];
  2252. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  2253. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  2254. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
  2255. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  2256. }
  2257. D3D12_INPUT_ELEMENT_DESC elementDesc[] = {
  2258. {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
  2259. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}};
  2260. D3D12_INPUT_LAYOUT_DESC InputLayout = {elementDesc, _countof(elementDesc)};
  2261. CreateGraphicsPSO(pDevice, &InputLayout, pRootSignature, pShaders, &pPSO);
  2262. CreateGraphicsCommandQueueAndList(pDevice, &pCommandQueue, &pCommandAllocator,
  2263. &pCommandList, pPSO);
  2264. // Single triangle covering half the target.
  2265. Vertex vertices[] = {
  2266. { { -1.0f, 1.0f, 0.0f } },
  2267. { { 1.0f, 1.0f, 0.0f } },
  2268. { { -1.0f, -1.0f, 0.0f } } };
  2269. const UINT TriangleCount = _countof(vertices) / 3;
  2270. CreateVertexBuffer(pDevice, vertices, &pVertexBuffer, &vertexBufferView);
  2271. bool dxbc = UseDxbc();
  2272. // Set up UAV resource.
  2273. std::vector<PerPixelData> values;
  2274. values.resize(RTWidth * RTHeight * 2);
  2275. UINT valueSizeInBytes = (UINT)values.size() * sizeof(PerPixelData);
  2276. memset(values.data(), 0, valueSizeInBytes);
  2277. CComPtr<ID3D12Resource> pUavResource;
  2278. CComPtr<ID3D12Resource> pUavReadBuffer;
  2279. CComPtr<ID3D12Resource> pUploadResource;
  2280. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pUavReadBuffer);
  2281. // Set up the append counter resource.
  2282. CComPtr<ID3D12Resource> pUavCounterResource;
  2283. CComPtr<ID3D12Resource> pReadCounterBuffer;
  2284. CComPtr<ID3D12Resource> pUploadCounterResource;
  2285. BYTE zero[sizeof(UINT)] = { 0 };
  2286. CreateTestUavs(pDevice, pCommandList, zero, sizeof(zero), &pUavCounterResource, &pUploadCounterResource, &pReadCounterBuffer);
  2287. // Close the command list and execute it to perform the GPU setup.
  2288. pCommandList->Close();
  2289. ExecuteCommandList(pCommandQueue, pCommandList);
  2290. WaitForSignal(pCommandQueue, FO);
  2291. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  2292. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pPSO));
  2293. pCommandList->SetGraphicsRootSignature(pRootSignature);
  2294. SetDescriptorHeap(pCommandList, pUavHeap);
  2295. {
  2296. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  2297. uavDesc.Format = DXGI_FORMAT_UNKNOWN;
  2298. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  2299. uavDesc.Buffer.FirstElement = 0;
  2300. uavDesc.Buffer.NumElements = (UINT)values.size();
  2301. uavDesc.Buffer.StructureByteStride = sizeof(PerPixelData);
  2302. uavDesc.Buffer.CounterOffsetInBytes = 0;
  2303. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  2304. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  2305. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  2306. pDevice->CreateUnorderedAccessView(pUavResource, pUavCounterResource, &uavDesc, uavHandle);
  2307. pCommandList->SetGraphicsRootDescriptorTable(0, uavHandleGpu);
  2308. }
  2309. RecordRenderAndReadback(pCommandList, pRtvHeap, rtvDescriptorSize, TriangleCount, &vertexBufferView, nullptr, pRenderTarget, pReadBuffer);
  2310. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2311. RecordTransitionBarrier(pCommandList, pUavCounterResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2312. pCommandList->CopyResource(pUavReadBuffer, pUavResource);
  2313. pCommandList->CopyResource(pReadCounterBuffer, pUavCounterResource);
  2314. VERIFY_SUCCEEDED(pCommandList->Close());
  2315. LogCommentFmt(L"Rendering to %u by %u", RTWidth, RTHeight);
  2316. ExecuteCommandList(pCommandQueue, pCommandList);
  2317. WaitForSignal(pCommandQueue, FO);
  2318. {
  2319. MappedData data(pReadBuffer, RTWidth * RTHeight * 4);
  2320. const uint32_t *pPixels = (uint32_t *)data.data();
  2321. if (SaveImages()) {
  2322. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, RTWidth, RTHeight, L"psintrin.bmp");
  2323. }
  2324. }
  2325. uint32_t appendCount;
  2326. {
  2327. MappedData mappedData(pReadCounterBuffer, sizeof(uint32_t));
  2328. appendCount = *((uint32_t *)mappedData.data());
  2329. LogCommentFmt(L"%u elements in append buffer", appendCount);
  2330. }
  2331. {
  2332. MappedData mappedData(pUavReadBuffer, (UINT32)values.size());
  2333. PerPixelData *pData = (PerPixelData *)mappedData.data();
  2334. memcpy(values.data(), pData, valueSizeInBytes);
  2335. // DXBC is handy to test pipeline setup, but interesting functions are
  2336. // stubbed out, so there is no point in further validation.
  2337. if (dxbc)
  2338. return;
  2339. uint32_t maxActiveLaneCount = 0;
  2340. uint32_t maxLaneCount = 0;
  2341. for (uint32_t i = 0; i < appendCount; ++i) {
  2342. maxActiveLaneCount = std::max(maxActiveLaneCount, values[i].sum1);
  2343. maxLaneCount = std::max(maxLaneCount, values[i].laneCount);
  2344. }
  2345. uint32_t peerOfHelperLanes = 0;
  2346. for (uint32_t i = 0; i < appendCount; ++i) {
  2347. if (values[i].sum1 != maxActiveLaneCount) {
  2348. ++peerOfHelperLanes;
  2349. }
  2350. }
  2351. LogCommentFmt(
  2352. L"Found: %u threads. Waves reported up to %u total lanes, up "
  2353. L"to %u active lanes, and %u threads had helper/inactive lanes.",
  2354. appendCount, maxLaneCount, maxActiveLaneCount, peerOfHelperLanes);
  2355. // Group threads into quad invocations.
  2356. uint32_t singlePixelCount = 0;
  2357. uint32_t multiPixelCount = 0;
  2358. std::unordered_set<uint32_t> ids;
  2359. std::multimap<uint32_t, PerPixelData *> idGroups;
  2360. std::multimap<uint32_t, PerPixelData *> firstIdGroups;
  2361. for (uint32_t i = 0; i < appendCount; ++i) {
  2362. ids.insert(values[i].id);
  2363. idGroups.insert(std::make_pair(values[i].id, &values[i]));
  2364. firstIdGroups.insert(std::make_pair(values[i].firstLaneId, &values[i]));
  2365. }
  2366. for (uint32_t id : ids) {
  2367. if (idGroups.count(id) == 1)
  2368. ++singlePixelCount;
  2369. else
  2370. ++multiPixelCount;
  2371. }
  2372. LogCommentFmt(L"%u pixels were processed by a single thread. %u invocations were for shared pixels.",
  2373. singlePixelCount, multiPixelCount);
  2374. // Multiple threads may have tried to shade the same pixel. (Is this true even if we have only one triangle?)
  2375. // Where every pixel is distinct, it's very straightforward to validate.
  2376. {
  2377. auto cur = firstIdGroups.begin(), end = firstIdGroups.end();
  2378. while (cur != end) {
  2379. bool simpleWave = true;
  2380. uint32_t firstId = (*cur).first;
  2381. auto groupEnd = cur;
  2382. while (groupEnd != end && (*groupEnd).first == firstId) {
  2383. if (idGroups.count((*groupEnd).second->id) > 1)
  2384. simpleWave = false;
  2385. ++groupEnd;
  2386. }
  2387. if (simpleWave) {
  2388. // Break the wave into quads.
  2389. struct QuadData {
  2390. unsigned count;
  2391. PerPixelData *data[4];
  2392. };
  2393. std::map<uint32_t, QuadData> quads;
  2394. for (auto i = cur; i != groupEnd; ++i) {
  2395. // assuming that it is a simple wave, idGroups has a unique id for each entry.
  2396. uint32_t laneId = (*i).second->id;
  2397. uint32_t laneIds[4] = {(*i).second->id0, (*i).second->id1,
  2398. (*i).second->id2, (*i).second->id3};
  2399. // Since this is a simple wave, each lane has an unique id and
  2400. // therefore should not have any ids in there.
  2401. VERIFY_IS_TRUE(quads.find(laneId) == quads.end());
  2402. // check if QuadReadLaneAt is returning same values in a single quad.
  2403. bool newQuad = true;
  2404. for (unsigned quadIndex = 0; quadIndex < 4; ++quadIndex) {
  2405. auto match = quads.find(laneIds[quadIndex]);
  2406. if (match != quads.end()) {
  2407. (*match).second.data[(*match).second.count++] = (*i).second;
  2408. newQuad = false;
  2409. break;
  2410. }
  2411. auto quadMemberData = idGroups.find(laneIds[quadIndex]);
  2412. if (quadMemberData != idGroups.end()) {
  2413. VERIFY_IS_TRUE((*quadMemberData).second->id0 == laneIds[0]);
  2414. VERIFY_IS_TRUE((*quadMemberData).second->id1 == laneIds[1]);
  2415. VERIFY_IS_TRUE((*quadMemberData).second->id2 == laneIds[2]);
  2416. VERIFY_IS_TRUE((*quadMemberData).second->id3 == laneIds[3]);
  2417. }
  2418. }
  2419. if (newQuad) {
  2420. QuadData qdata;
  2421. qdata.count = 1;
  2422. qdata.data[0] = (*i).second;
  2423. quads.insert(std::make_pair(laneId, qdata));
  2424. }
  2425. }
  2426. for (auto quadPair : quads) {
  2427. unsigned count = quadPair.second.count;
  2428. // There could be only one pixel data on the edge of the triangle
  2429. if (count < 2) continue;
  2430. PerPixelData **data = quadPair.second.data;
  2431. bool isTop[4];
  2432. bool isLeft[4];
  2433. PerPixelData helperData;
  2434. memset(&helperData, sizeof(helperData), 0);
  2435. PerPixelData *layout[4]; // tl,tr,bl,br
  2436. memset(layout, sizeof(layout), 0);
  2437. auto fnToLayout = [&](bool top, bool left) -> PerPixelData ** {
  2438. int idx = top ? 0 : 2;
  2439. idx += left ? 0 : 1;
  2440. return &layout[idx];
  2441. };
  2442. auto fnToLayoutData = [&](bool top, bool left) -> PerPixelData * {
  2443. PerPixelData **pResult = fnToLayout(top, left);
  2444. if (*pResult == nullptr) return &helperData;
  2445. return *pResult;
  2446. };
  2447. VERIFY_IS_TRUE(count <= 4);
  2448. if (count == 2) {
  2449. isTop[0] = data[0]->position.y < data[1]->position.y;
  2450. isTop[1] = (data[0]->position.y == data[1]->position.y) ? isTop[0] : !isTop[0];
  2451. isLeft[0] = data[0]->position.x < data[1]->position.x;
  2452. isLeft[1] = (data[0]->position.x == data[1]->position.x) ? isLeft[0] : !isLeft[0];
  2453. }
  2454. else {
  2455. // with at least three samples, we have distinct x and y coordinates.
  2456. float left = std::min(data[0]->position.x, data[1]->position.x);
  2457. left = std::min(data[2]->position.x, left);
  2458. float top = std::min(data[0]->position.y, data[1]->position.y);
  2459. top = std::min(data[2]->position.y, top);
  2460. for (unsigned i = 0; i < count; ++i) {
  2461. isTop[i] = data[i]->position.y == top;
  2462. isLeft[i] = data[i]->position.x == left;
  2463. }
  2464. }
  2465. for (unsigned i = 0; i < count; ++i) {
  2466. *(fnToLayout(isTop[i], isLeft[i])) = data[i];
  2467. }
  2468. // Finally, we have a proper quad reconstructed. Validate.
  2469. for (unsigned i = 0; i < count; ++i) {
  2470. PerPixelData *d = data[i];
  2471. VERIFY_ARE_EQUAL(d->id0, fnToLayoutData(true, true)->id);
  2472. VERIFY_ARE_EQUAL(d->id1, fnToLayoutData(true, false)->id);
  2473. VERIFY_ARE_EQUAL(d->id2, fnToLayoutData(false, true)->id);
  2474. VERIFY_ARE_EQUAL(d->id3, fnToLayoutData(false, false)->id);
  2475. VERIFY_ARE_EQUAL(d->acrossX, fnToLayoutData(isTop[i], !isLeft[i])->id);
  2476. VERIFY_ARE_EQUAL(d->acrossY, fnToLayoutData(!isTop[i], isLeft[i])->id);
  2477. VERIFY_ARE_EQUAL(d->acrossDiag, fnToLayoutData(!isTop[i], !isLeft[i])->id);
  2478. VERIFY_ARE_EQUAL(d->quadActiveCount, count);
  2479. }
  2480. }
  2481. }
  2482. cur = groupEnd;
  2483. }
  2484. }
  2485. // TODO: provide validation for quads where the same pixel was shaded multiple times
  2486. //
  2487. // Consider: for pixels that were shaded multiple times, check whether
  2488. // some grouping of threads into quads satisfies all value requirements.
  2489. }
  2490. }
  2491. struct ShaderOpTestResult {
  2492. st::ShaderOp *ShaderOp;
  2493. std::shared_ptr<st::ShaderOpSet> ShaderOpSet;
  2494. std::shared_ptr<st::ShaderOpTest> Test;
  2495. };
  2496. struct SPrimitives {
  2497. float f_float;
  2498. float f_float2;
  2499. float f_float_o;
  2500. float f_float2_o;
  2501. };
  2502. std::shared_ptr<ShaderOpTestResult>
  2503. RunShaderOpTestAfterParse(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
  2504. LPCSTR pName,
  2505. st::ShaderOpTest::TInitCallbackFn pInitCallback,
  2506. std::shared_ptr<st::ShaderOpSet> ShaderOpSet) {
  2507. st::ShaderOp *pShaderOp;
  2508. if (pName == nullptr) {
  2509. if (ShaderOpSet->ShaderOps.size() != 1) {
  2510. VERIFY_FAIL(L"Expected a single shader operation.");
  2511. }
  2512. pShaderOp = ShaderOpSet->ShaderOps[0].get();
  2513. }
  2514. else {
  2515. pShaderOp = ShaderOpSet->GetShaderOp(pName);
  2516. }
  2517. if (pShaderOp == nullptr) {
  2518. std::string msg = "Unable to find shader op ";
  2519. msg += pName;
  2520. msg += "; available ops";
  2521. const char sep = ':';
  2522. for (auto &pAvailOp : ShaderOpSet->ShaderOps) {
  2523. msg += sep;
  2524. msg += pAvailOp->Name ? pAvailOp->Name : "[n/a]";
  2525. }
  2526. CA2W msgWide(msg.c_str());
  2527. VERIFY_FAIL(msgWide.m_psz);
  2528. }
  2529. // This won't actually be used since we're supplying the device,
  2530. // but let's make it consistent.
  2531. pShaderOp->UseWarpDevice = GetTestParamUseWARP(true);
  2532. std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
  2533. test->SetDxcSupport(&support);
  2534. test->SetInitCallback(pInitCallback);
  2535. test->SetDevice(pDevice);
  2536. test->RunShaderOp(pShaderOp);
  2537. std::shared_ptr<ShaderOpTestResult> result =
  2538. std::make_shared<ShaderOpTestResult>();
  2539. result->ShaderOpSet = ShaderOpSet;
  2540. result->Test = test;
  2541. result->ShaderOp = pShaderOp;
  2542. return result;
  2543. }
  2544. std::shared_ptr<ShaderOpTestResult>
  2545. RunShaderOpTest(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
  2546. IStream *pStream, LPCSTR pName,
  2547. st::ShaderOpTest::TInitCallbackFn pInitCallback) {
  2548. DXASSERT_NOMSG(pStream != nullptr);
  2549. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2550. std::make_shared<st::ShaderOpSet>();
  2551. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2552. return RunShaderOpTestAfterParse(pDevice, support, pName, pInitCallback, ShaderOpSet);
  2553. }
  2554. TEST_F(ExecutionTest, OutOfBoundsTest) {
  2555. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2556. CComPtr<IStream> pStream;
  2557. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2558. // Single operation test at the moment.
  2559. CComPtr<ID3D12Device> pDevice;
  2560. if (!CreateDevice(&pDevice))
  2561. return;
  2562. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "OOB", nullptr);
  2563. MappedData data;
  2564. // Read back to CPU and examine contents - should get pure red.
  2565. {
  2566. MappedData data;
  2567. test->Test->GetReadBackData("RTarget", &data);
  2568. const uint32_t *pPixels = (uint32_t *)data.data();
  2569. uint32_t first = *pPixels;
  2570. VERIFY_ARE_EQUAL(0xff0000ff, first); // pure red - only first component is read
  2571. }
  2572. }
  2573. TEST_F(ExecutionTest, SaturateTest) {
  2574. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2575. CComPtr<IStream> pStream;
  2576. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2577. // Single operation test at the moment.
  2578. CComPtr<ID3D12Device> pDevice;
  2579. if (!CreateDevice(&pDevice))
  2580. return;
  2581. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "Saturate", nullptr);
  2582. MappedData data;
  2583. test->Test->GetReadBackData("U0", &data);
  2584. const float *pValues = (float *)data.data();
  2585. // Everything is zero except for 1.5f and +Inf, which saturate to 1.0f
  2586. const float ExpectedCases[9] = {
  2587. 0.0f, 0.0f, 0.0f, 0.0f, // -inf, -1.5, -denorm, -0
  2588. 0.0f, 0.0f, 1.0f, 1.0f, // 0, denorm, 1.5f, inf
  2589. 0.0f // nan
  2590. };
  2591. for (size_t i = 0; i < _countof(ExpectedCases); ++i) {
  2592. VERIFY_IS_TRUE(ifdenorm_flushf_eq(*pValues, ExpectedCases[i]));
  2593. ++pValues;
  2594. }
  2595. }
  2596. void ExecutionTest::BasicTriangleTestSetup(LPCSTR ShaderOpName, LPCWSTR FileName, D3D_SHADER_MODEL testModel) {
  2597. #ifdef _HLK_CONF
  2598. UNREFERENCED_PARAMETER(ShaderOpName);
  2599. UNREFERENCED_PARAMETER(FileName);
  2600. UNREFERENCED_PARAMETER(testModel);
  2601. #else
  2602. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2603. CComPtr<IStream> pStream;
  2604. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2605. // Single operation test at the moment.
  2606. CComPtr<ID3D12Device> pDevice;
  2607. if (!CreateDevice(&pDevice, testModel))
  2608. return;
  2609. // As this is used, 6.2 requirement always comes with requiring native 16-bit ops
  2610. if (testModel == D3D_SHADER_MODEL_6_2 && !DoesDeviceSupportNative16bitOps(pDevice)) {
  2611. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  2612. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  2613. return;
  2614. }
  2615. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, ShaderOpName, nullptr);
  2616. MappedData data;
  2617. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  2618. UINT width = (UINT)D.Width;
  2619. UINT height = D.Height;
  2620. test->Test->GetReadBackData("RTarget", &data);
  2621. const uint32_t *pPixels = (uint32_t *)data.data();
  2622. if (SaveImages()) {
  2623. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, 320, 200, FileName);
  2624. }
  2625. uint32_t top = pPixels[width / 2]; // Top center.
  2626. uint32_t mid = pPixels[width / 2 + width * (height / 2)]; // Middle center.
  2627. VERIFY_ARE_EQUAL(0xff663300, top); // clear color
  2628. VERIFY_ARE_EQUAL(0xffffffff, mid); // white
  2629. // This is the basic validation test for shader operations, so it's good to
  2630. // check this here at least for this one test case.
  2631. data.reset();
  2632. test.reset();
  2633. ReportLiveObjects();
  2634. #endif
  2635. }
  2636. TEST_F(ExecutionTest, BasicTriangleOpTest) {
  2637. BasicTriangleTestSetup("Triangle", L"basic-triangle.bmp", D3D_SHADER_MODEL_6_0);
  2638. }
  2639. TEST_F(ExecutionTest, BasicTriangleOpTestHalf) {
  2640. BasicTriangleTestSetup("TriangleHalf", L"basic-triangle-half.bmp", D3D_SHADER_MODEL_6_2);
  2641. }
  2642. void VerifyDerivResults(const float *pPixels, UINT offsetCenter) {
  2643. // pixel at the center
  2644. float CenterDDXFine = pPixels[offsetCenter];
  2645. float CenterDDYFine = pPixels[offsetCenter + 1];
  2646. float CenterDDXCoarse = pPixels[offsetCenter + 2];
  2647. float CenterDDYCoarse = pPixels[offsetCenter + 3];
  2648. LogCommentFmt(
  2649. L"center ddx_fine: %8f, ddy_fine: %8f, ddx_coarse: %8f, ddy_coarse: %8f",
  2650. CenterDDXFine, CenterDDYFine, CenterDDXCoarse, CenterDDYCoarse);
  2651. // The texture for the 9 pixels in the center should look like the following
  2652. // 256 32 64
  2653. // 2048 256 512
  2654. // 1 .125 .25
  2655. // In D3D12 there is no guarantee of how the adapter is grouping 2x2 pixels
  2656. // So for fine derivatives there can be up to two possible results for the center pixel,
  2657. // while for coarse derivatives there can be up to six possible results.
  2658. int ulpTolerance = 1;
  2659. // 512 - 256 or 2048 - 256
  2660. bool left = CompareFloatULP(CenterDDXFine, -1792.0f, ulpTolerance);
  2661. VERIFY_IS_TRUE(left || CompareFloatULP(CenterDDXFine, 256.0f, ulpTolerance));
  2662. // 256 - 32 or 256 - .125
  2663. bool top = CompareFloatULP(CenterDDYFine, 224.0f, ulpTolerance);
  2664. VERIFY_IS_TRUE(top || CompareFloatULP(CenterDDYFine, -255.875, ulpTolerance));
  2665. if (top && left) {
  2666. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, -224.0f, ulpTolerance) ||
  2667. CompareFloatULP(CenterDDXCoarse, -1792.0f, ulpTolerance)) &&
  2668. (CompareFloatULP(CenterDDYCoarse, 224.0f, ulpTolerance) ||
  2669. CompareFloatULP(CenterDDYCoarse, 1792.0f, ulpTolerance)));
  2670. }
  2671. else if (top) { // top right quad
  2672. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, 256.0f, ulpTolerance) ||
  2673. CompareFloatULP(CenterDDXCoarse, 32.0f, ulpTolerance)) &&
  2674. (CompareFloatULP(CenterDDYCoarse, 224.0f, ulpTolerance) ||
  2675. CompareFloatULP(CenterDDYCoarse, 448.0f, ulpTolerance)));
  2676. }
  2677. else if (left) { // bottom left quad
  2678. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, -1792.0f, ulpTolerance) ||
  2679. CompareFloatULP(CenterDDXCoarse, -.875f, ulpTolerance)) &&
  2680. (CompareFloatULP(CenterDDYCoarse, -2047.0f, ulpTolerance) ||
  2681. CompareFloatULP(CenterDDYCoarse, -255.875f, ulpTolerance)));
  2682. }
  2683. else { // bottom right
  2684. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, 256.0f, ulpTolerance) ||
  2685. CompareFloatULP(CenterDDXCoarse, .125f, ulpTolerance)) &&
  2686. (CompareFloatULP(CenterDDYCoarse, -255.875f, ulpTolerance) ||
  2687. CompareFloatULP(CenterDDYCoarse, -511.75f, ulpTolerance)));
  2688. }
  2689. }
  2690. // Rendering two right triangles forming a square and assigning a texture value
  2691. // for each pixel to calculate derivates.
  2692. TEST_F(ExecutionTest, PartialDerivTest) {
  2693. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2694. CComPtr<IStream> pStream;
  2695. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2696. CComPtr<ID3D12Device> pDevice;
  2697. if (!CreateDevice(&pDevice))
  2698. return;
  2699. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "DerivFine", nullptr);
  2700. MappedData data;
  2701. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  2702. UINT width = (UINT)D.Width;
  2703. UINT height = D.Height;
  2704. UINT pixelSize = GetByteSizeForFormat(D.Format) / 4;
  2705. test->Test->GetReadBackData("RTarget", &data);
  2706. const float *pPixels = (float *)data.data();
  2707. UINT centerIndex = (UINT64)width * height / 2 - width / 2;
  2708. UINT offsetCenter = centerIndex * pixelSize;
  2709. VerifyDerivResults(pPixels, offsetCenter);
  2710. }
  2711. struct Dispatch {
  2712. int width, height, depth;
  2713. };
  2714. std::shared_ptr<st::ShaderOpTest>
  2715. RunDispatch(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
  2716. st::ShaderOp *pShaderOp, const Dispatch D) {
  2717. char compilerOptions[256];
  2718. std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
  2719. test->SetDxcSupport(&support);
  2720. test->SetInitCallback(nullptr);
  2721. test->SetDevice(pDevice);
  2722. // format compiler args
  2723. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions),
  2724. "-D DISPATCHX=%d -D DISPATCHY=%d -D DISPATCHZ=%d ",
  2725. D.width, D.height, D.depth));
  2726. for (st::ShaderOpShader &S : pShaderOp->Shaders)
  2727. S.Arguments = compilerOptions;
  2728. pShaderOp->DispatchX = D.width;
  2729. pShaderOp->DispatchY = D.height;
  2730. pShaderOp->DispatchZ = D.depth;
  2731. test->RunShaderOp(pShaderOp);
  2732. return test;
  2733. }
  2734. TEST_F(ExecutionTest, DerivativesTest) {
  2735. const UINT pixelSize = 4; // always float4
  2736. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2737. CComPtr<IStream> pStream;
  2738. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2739. CComPtr<ID3D12Device> pDevice;
  2740. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  2741. return;
  2742. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2743. std::make_shared<st::ShaderOpSet>();
  2744. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2745. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Derivatives");
  2746. std::vector<Dispatch> dispatches =
  2747. {
  2748. {40, 1, 1},
  2749. {1000, 1, 1},
  2750. {32, 32, 1},
  2751. {16, 64, 1},
  2752. {4, 12, 4},
  2753. {4, 64, 1},
  2754. {16, 16, 3},
  2755. {32, 8, 2}
  2756. };
  2757. std::vector<Dispatch> meshDispatches =
  2758. {
  2759. {60, 1, 1},
  2760. {128, 1, 1},
  2761. {8, 8, 1},
  2762. {32, 8, 1},
  2763. {8, 16, 4},
  2764. {8, 64, 1},
  2765. {8, 8, 3},
  2766. };
  2767. std::vector<Dispatch> badDispatches =
  2768. {
  2769. {16, 3, 1},
  2770. {2, 16, 1},
  2771. {33, 1, 1}
  2772. };
  2773. pShaderOp->UseWarpDevice = GetTestParamUseWARP(true);
  2774. LPCSTR CS = pShaderOp->CS;
  2775. MappedData data;
  2776. for (Dispatch &D : dispatches) {
  2777. // Test Compute Shader
  2778. std::shared_ptr<st::ShaderOpTest> test = RunDispatch(pDevice, m_support, pShaderOp, D);
  2779. test->GetReadBackData("U0", &data);
  2780. float *pPixels = (float *)data.data();;
  2781. UINT centerIndex = 0;
  2782. if (D.height == 1) {
  2783. centerIndex = (((UINT64)(D.width * D.height * D.depth) / 2) & ~0xF) + 10;
  2784. } else {
  2785. // To find roughly the center for compute, divide the height and width in half,
  2786. // truncate to the previous multiple of 4 to get to the start of the repeating pattern
  2787. // and then add 2 rows to get to the second row of quads and 2 to get to the first texel
  2788. // of the second row of that quad row
  2789. UINT centerRow = ((D.height/2UL) & ~0x3) + 2;
  2790. UINT centerCol = ((D.width/2UL) & ~0x3) + 2;
  2791. centerIndex = centerRow * D.width + centerCol;
  2792. }
  2793. UINT offsetCenter = centerIndex * pixelSize;
  2794. LogCommentFmt(L"Verifying derivatives in compute shader results");
  2795. VerifyDerivResults(pPixels, offsetCenter);
  2796. }
  2797. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2798. // Disable CS so mesh goes forward
  2799. pShaderOp->CS = nullptr;
  2800. for (Dispatch &D : meshDispatches) {
  2801. std::shared_ptr<st::ShaderOpTest> test = RunDispatch(pDevice, m_support, pShaderOp, D);
  2802. test->GetReadBackData("U1", &data);
  2803. const float *pPixels = (float *)data.data();
  2804. UINT centerIndex = (((UINT64)(D.width * D.height * D.depth)/2) & ~0xF) + 10;
  2805. UINT offsetCenter = centerIndex * pixelSize;
  2806. LogCommentFmt(L"Verifying derivatives in mesh shader results");
  2807. VerifyDerivResults(pPixels, offsetCenter);
  2808. test->GetReadBackData("U2", &data);
  2809. pPixels = (float *)data.data();
  2810. LogCommentFmt(L"Verifying derivatives in amplification shader results");
  2811. VerifyDerivResults(pPixels, offsetCenter);
  2812. }
  2813. }
  2814. // Final tests with invalid dispatch size just to make sure they run
  2815. for (Dispatch &D : badDispatches) {
  2816. // Test Compute Shader
  2817. pShaderOp->CS = CS;
  2818. std::shared_ptr<st::ShaderOpTest> test = RunDispatch(pDevice, m_support, pShaderOp, D);
  2819. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2820. pShaderOp->CS = nullptr;
  2821. test = RunDispatch(pDevice, m_support, pShaderOp, D);
  2822. }
  2823. }
  2824. }
  2825. // Verify the results for the quad starting with the given index
  2826. void VerifyQuadReadResults(const UINT *pPixels, UINT quadIndex) {
  2827. for (UINT i = 0; i < 4; i++) {
  2828. UINT ix = quadIndex + i;
  2829. VERIFY_ARE_EQUAL(pPixels[4*ix + 0], ix); // ReadLaneAt own quad index
  2830. VERIFY_ARE_EQUAL(pPixels[4*ix + 1], (ix^1));// ReadAcrossX
  2831. VERIFY_ARE_EQUAL(pPixels[4*ix + 2], (ix^2));// ReadAcrossY
  2832. VERIFY_ARE_EQUAL(pPixels[4*ix + 3], (ix^3));// ReadAcrossDiagonal
  2833. }
  2834. }
  2835. TEST_F(ExecutionTest, QuadReadTest) {
  2836. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2837. CComPtr<IStream> pStream;
  2838. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2839. CComPtr<ID3D12Device> pDevice;
  2840. if (!CreateDevice(&pDevice))
  2841. return;
  2842. if (GetTestParamUseWARP(UseWarpByDefault()) || IsDeviceBasicAdapter(pDevice)) {
  2843. WEX::Logging::Log::Comment(L"WARP does not support QuadRead in compute shaders.");
  2844. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  2845. return;
  2846. }
  2847. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2848. std::make_shared<st::ShaderOpSet>();
  2849. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2850. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("QuadRead");
  2851. LPCSTR CS = pShaderOp->CS;
  2852. struct Dispatch {
  2853. int x, y, z;
  2854. int mx, my, mz;
  2855. };
  2856. //std::vector<std::tuple<int, int, int, int, int>> dispatches =
  2857. std::vector<Dispatch> dispatches =
  2858. {
  2859. {32, 32, 1, 8, 8, 1},
  2860. {64, 4, 1, 64, 2, 1},
  2861. {1, 4, 64, 1, 4, 32},
  2862. {64, 1, 1, 64, 1, 1},
  2863. {1, 64, 1, 1, 64, 1},
  2864. {1, 1, 64, 1, 1, 64},
  2865. {16, 16, 3, 4, 4, 3},
  2866. {32, 3, 8, 8, 3, 2},
  2867. {3, 1, 64, 3, 1, 32}
  2868. };
  2869. for (Dispatch &D : dispatches) {
  2870. UINT width = D.x;
  2871. UINT height = D.y;
  2872. UINT depth = D.z;
  2873. UINT mwidth = D.mx;
  2874. UINT mheight = D.my;
  2875. UINT mdepth = D.mz;
  2876. // format compiler args
  2877. char compilerOptions[256];
  2878. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions),
  2879. "-D DISPATCHX=%d -D DISPATCHY=%d -D DISPATCHZ=%d "
  2880. "-D MESHDISPATCHX=%d -D MESHDISPATCHY=%d -D MESHDISPATCHZ=%d",
  2881. width, height, depth, mwidth, mheight, mdepth));
  2882. for (st::ShaderOpShader &S : pShaderOp->Shaders)
  2883. S.Arguments = compilerOptions;
  2884. pShaderOp->DispatchX = width;
  2885. pShaderOp->DispatchY = height;
  2886. pShaderOp->DispatchZ = depth;
  2887. // Test Compute Shader
  2888. pShaderOp->CS = CS;
  2889. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "QuadRead", nullptr, ShaderOpSet);
  2890. MappedData data;
  2891. test->Test->GetReadBackData("U0", &data);
  2892. const UINT *pPixels = (UINT *)data.data();
  2893. // To find roughly the center for compute, divide the pixel count in half
  2894. // and truncate to next lowest power of 4 to start at a quad
  2895. UINT offsetCenter = ((UINT64)(width * height * depth)/2) & ~0x3;
  2896. // Test first, second and center quads
  2897. LogCommentFmt(L"Verifying QuadRead* in compute shader results");
  2898. VerifyQuadReadResults(pPixels, 0);
  2899. VerifyQuadReadResults(pPixels, 4);
  2900. VerifyQuadReadResults(pPixels, offsetCenter);
  2901. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2902. offsetCenter = ((UINT64)(mwidth * mheight * mdepth)/2) & ~0x3;
  2903. // Disable CS so mesh goes forward
  2904. pShaderOp->CS = nullptr;
  2905. test = RunShaderOpTestAfterParse(pDevice, m_support, "QuadRead", nullptr, ShaderOpSet);
  2906. test->Test->GetReadBackData("U1", &data);
  2907. pPixels = (UINT *)data.data();
  2908. // Test first, second and center quads
  2909. LogCommentFmt(L"Verifying QuadRead* in mesh shader results");
  2910. VerifyQuadReadResults(pPixels, 0);
  2911. VerifyQuadReadResults(pPixels, 4);
  2912. VerifyQuadReadResults(pPixels, offsetCenter);
  2913. test->Test->GetReadBackData("U2", &data);
  2914. pPixels = (UINT *)data.data();
  2915. // Test first, second and center quads
  2916. LogCommentFmt(L"Verifying QuadRead* in amplification shader results");
  2917. VerifyQuadReadResults(pPixels, 0);
  2918. VerifyQuadReadResults(pPixels, 4);
  2919. VerifyQuadReadResults(pPixels, offsetCenter);
  2920. }
  2921. }
  2922. }
  2923. void VerifySampleResults(const UINT *pPixels, UINT width) {
  2924. UINT xlod = 0;
  2925. UINT ylod = 0;
  2926. // Each pixel contains 4 samples and 4 LOD calculations.
  2927. // 2 of these (called 'left' and 'right') have X values that vary and a constant Y
  2928. // 2 others (called 'top' and 'bot') have Y values that vary and a constant X
  2929. // Only of the X variant sample results and one of the Y variant results
  2930. // are actually reported for the pixel.
  2931. // The other 2 serve as "helpers" to the other pixels in the quad.
  2932. // On the left side of the quad, the 'left' samples are reported.
  2933. // Op the top of the quad, the 'top' samples are reported and so on.
  2934. // The varying coordinate values alternate between zero and a
  2935. // value whose magnitude increases with the index.
  2936. // As a result, the LOD level should steadily increas.
  2937. // Due to vagaries of implementation, the same derivatives
  2938. // in both directions might result in different levels for different locations
  2939. // in the quad. So only comparisons between sample results and LOD calculations
  2940. // and ensuring that the LOD increased and reaches the max can be tested reliably.
  2941. for (unsigned i = 0; i < width; i++) {
  2942. // CalculateLOD and Sample from texture with mip levels containing LOD index should match
  2943. VERIFY_ARE_EQUAL(pPixels[4*i + 0], pPixels[4*i + 1]);
  2944. VERIFY_ARE_EQUAL(pPixels[4*i + 2], pPixels[4*i + 3]);
  2945. // Make sure LODs are ever climbing as magnitudes increase
  2946. VERIFY_IS_TRUE(pPixels[4*i] >= xlod);
  2947. xlod = pPixels[4*i];
  2948. VERIFY_IS_TRUE(pPixels[4*i + 2] >= ylod);
  2949. ylod = pPixels[4*i + 2];
  2950. }
  2951. // Make sure we reached the max lod level for both tracks
  2952. VERIFY_ARE_EQUAL(xlod, 6u);
  2953. VERIFY_ARE_EQUAL(ylod, 6u);
  2954. }
  2955. TEST_F(ExecutionTest, ComputeSampleTest) {
  2956. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2957. CComPtr<IStream> pStream;
  2958. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2959. CComPtr<ID3D12Device> pDevice;
  2960. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  2961. return;
  2962. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2963. std::make_shared<st::ShaderOpSet>();
  2964. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2965. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("ComputeSample");
  2966. // Initialize texture with the LOD number in each corresponding mip level
  2967. auto SampleInitFn = [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  2968. UNREFERENCED_PARAMETER(pShaderOp);
  2969. VERIFY_ARE_EQUAL(0, _stricmp(Name, "T0"));
  2970. D3D12_RESOURCE_DESC &texDesc = pShaderOp->GetResourceByName("T0")->Desc;
  2971. UINT texWidth = (UINT)texDesc.Width;
  2972. UINT texHeight = (UINT)texDesc.Height;
  2973. size_t size = sizeof(float) * texWidth * texHeight * 2;
  2974. Data.resize(size);
  2975. float *pPrimitives = (float *)Data.data();
  2976. float lod = 0.0;
  2977. int ix = 0;
  2978. while (texHeight > 0 && texWidth > 0) {
  2979. if(!texHeight) texHeight = 1;
  2980. if(!texWidth) texWidth = 1;
  2981. for (size_t j = 0; j < texHeight; ++j) {
  2982. for (size_t i = 0; i < texWidth; ++i) {
  2983. pPrimitives[ix++] = lod;
  2984. }
  2985. }
  2986. lod += 1.0;
  2987. texHeight >>= 1;
  2988. texWidth >>= 1;
  2989. }
  2990. };
  2991. LPCSTR CS2 = nullptr, AS2 = nullptr, MS2 = nullptr;
  2992. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  2993. if (!strcmp(S.Name, "CS2")) CS2 = S.Name;
  2994. if (!strcmp(S.Name, "AS2")) AS2 = S.Name;
  2995. if (!strcmp(S.Name, "MS2")) MS2 = S.Name;
  2996. }
  2997. // Test 1D compute shader
  2998. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  2999. MappedData data;
  3000. test->Test->GetReadBackData("U0", &data);
  3001. const UINT *pPixels = (UINT *)data.data();
  3002. VerifySampleResults(pPixels, 84*4);
  3003. // Test 2D compute shader
  3004. pShaderOp->CS = CS2;
  3005. test.reset();
  3006. test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  3007. test->Test->GetReadBackData("U0", &data);
  3008. pPixels = (UINT *)data.data();
  3009. VerifySampleResults(pPixels, 84*4);
  3010. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  3011. // Disable CS so mesh goes forward
  3012. pShaderOp->CS = nullptr;
  3013. test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  3014. test->Test->GetReadBackData("U1", &data);
  3015. pPixels = (UINT *)data.data();
  3016. VerifySampleResults(pPixels, 116);
  3017. test->Test->GetReadBackData("U2", &data);
  3018. pPixels = (UINT *)data.data();
  3019. VerifySampleResults(pPixels, 84);
  3020. pShaderOp->AS = AS2;
  3021. pShaderOp->MS = MS2;
  3022. test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  3023. test->Test->GetReadBackData("U1", &data);
  3024. pPixels = (UINT *)data.data();
  3025. VerifySampleResults(pPixels, 116);
  3026. test->Test->GetReadBackData("U2", &data);
  3027. pPixels = (UINT *)data.data();
  3028. VerifySampleResults(pPixels, 84);
  3029. }
  3030. }
  3031. // Executing a simple binop to verify shadel model 6.1 support; runs with
  3032. // ShaderModel61.CoreRequirement
  3033. TEST_F(ExecutionTest, BasicShaderModel61) {
  3034. RunBasicShaderModelTest(D3D_SHADER_MODEL_6_1);
  3035. }
  3036. // Executing a simple binop to verify shadel model 6.3 support; runs with
  3037. // ShaderModel63.CoreRequirement
  3038. TEST_F(ExecutionTest, BasicShaderModel63) {
  3039. RunBasicShaderModelTest(D3D_SHADER_MODEL_6_3);
  3040. }
  3041. void ExecutionTest::RunBasicShaderModelTest(D3D_SHADER_MODEL shaderModel) {
  3042. WEX::TestExecution::SetVerifyOutput verifySettings(
  3043. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  3044. CComPtr<ID3D12Device> pDevice;
  3045. if (!CreateDevice(&pDevice, shaderModel)) {
  3046. return;
  3047. }
  3048. char *pShaderModelStr;
  3049. if (shaderModel == D3D_SHADER_MODEL_6_1) {
  3050. pShaderModelStr = "cs_6_1";
  3051. } else if (shaderModel == D3D_SHADER_MODEL_6_3) {
  3052. pShaderModelStr = "cs_6_3";
  3053. } else {
  3054. DXASSERT_NOMSG("Invalid Shader Model Parameter");
  3055. pShaderModelStr = nullptr;
  3056. }
  3057. const char shaderTemplate[] =
  3058. "struct SBinaryOp { %s input1; %s input2; %s output; };"
  3059. "RWStructuredBuffer<SBinaryOp> g_buf : register(u0);"
  3060. "[numthreads(8,8,1)]"
  3061. "void main(uint GI : SV_GroupIndex) {"
  3062. " SBinaryOp l = g_buf[GI];"
  3063. " l.output = l.input1 + l.input2;"
  3064. " g_buf[GI] = l;"
  3065. "}";
  3066. char shader[sizeof(shaderTemplate) + 50];
  3067. // Run simple shader with float data types
  3068. char* sTy = "float";
  3069. float inputFloatPairs[] = { 1.5f, -2.8f, 3.23e-5f, 6.0f, 181.621f, 14.978f };
  3070. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  3071. WEX::Logging::Log::Comment(L"BasicShaderModel float");
  3072. RunBasicShaderModelTest<float>(pDevice, pShaderModelStr, shader, inputFloatPairs, sizeof(inputFloatPairs) / (2 * sizeof(float)));
  3073. // Run simple shader with double data types
  3074. if (DoesDeviceSupportDouble(pDevice)) {
  3075. sTy = "double";
  3076. double inputDoublePairs[] = { 1.5891020, -2.8, 3.23e-5, 1 / 3, 181.91621, 14.654978 };
  3077. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  3078. WEX::Logging::Log::Comment(L"BasicShaderModel double");
  3079. RunBasicShaderModelTest<double>(pDevice, pShaderModelStr, shader, inputDoublePairs, sizeof(inputDoublePairs) / (2 * sizeof(double)));
  3080. }
  3081. else {
  3082. // Optional feature, so it's correct to not support it if declared as such.
  3083. WEX::Logging::Log::Comment(L"Device does not support double operations.");
  3084. }
  3085. // Run simple shader with int64 types
  3086. if (DoesDeviceSupportInt64(pDevice)) {
  3087. sTy = "int64_t";
  3088. int64_t inputInt64Pairs[] = { 1, -100, 6814684, -9814810, 654, 1021248900 };
  3089. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  3090. WEX::Logging::Log::Comment(L"BasicShaderModel int64_t");
  3091. RunBasicShaderModelTest<int64_t>(pDevice, pShaderModelStr, shader, inputInt64Pairs, sizeof(inputInt64Pairs) / (2 * sizeof(int64_t)));
  3092. }
  3093. else {
  3094. // Optional feature, so it's correct to not support it if declared as such.
  3095. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  3096. }
  3097. }
  3098. template <class Ty>
  3099. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString() {
  3100. DXASSERT_NOMSG("Unsupported type");
  3101. return "";
  3102. }
  3103. template <>
  3104. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<float>() {
  3105. return L"element #%u: input1 = %6.8f, input1 = %6.8f, output = %6.8f, expected = %6.8f";
  3106. }
  3107. template <>
  3108. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<double>() {
  3109. return BasicShaderModelTest_GetFormatString<float>();
  3110. }
  3111. template <>
  3112. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<int64_t>() {
  3113. return L"element #%u: input1 = %ld, input1 = %ld, output = %ld, expected = %ld";
  3114. }
  3115. template <class Ty>
  3116. void ExecutionTest::RunBasicShaderModelTest(CComPtr<ID3D12Device> pDevice, const char *pShaderModelStr, const char *pShader,
  3117. Ty *pInputDataPairs, unsigned inputDataCount) {
  3118. struct SBinaryOp {
  3119. Ty input1;
  3120. Ty input2;
  3121. Ty output;
  3122. };
  3123. CComPtr<IStream> pStream;
  3124. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  3125. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  3126. pDevice, m_support, pStream, "BinaryFPOp",
  3127. // this callbacked is called when the test is creating the resource to run the test
  3128. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  3129. UNREFERENCED_PARAMETER(Name);
  3130. pShaderOp->Shaders.at(0).Target = pShaderModelStr;
  3131. pShaderOp->Shaders.at(0).Text = pShader;
  3132. size_t size = sizeof(SBinaryOp) * inputDataCount;
  3133. Data.resize(size);
  3134. SBinaryOp *pPrimitives = (SBinaryOp*)Data.data();
  3135. Ty *pIn = pInputDataPairs;
  3136. for (size_t i = 0; i < inputDataCount; i++, pIn += 2) {
  3137. SBinaryOp *p = &pPrimitives[i];
  3138. p->input1 = pIn[0];
  3139. p->input2 = pIn[1];
  3140. }
  3141. });
  3142. VERIFY_SUCCEEDED(S_OK);
  3143. MappedData data;
  3144. test->Test->GetReadBackData("SBinaryFPOp", &data);
  3145. SBinaryOp *pPrimitives = (SBinaryOp*)data.data();
  3146. const wchar_t* formatStr = BasicShaderModelTest_GetFormatString<Ty>();
  3147. Ty *pIn = pInputDataPairs;
  3148. for (unsigned i = 0; i < inputDataCount; i++, pIn += 2) {
  3149. Ty expValue = pIn[0] + pIn[1];
  3150. SBinaryOp *p = &pPrimitives[i];
  3151. LogCommentFmt(formatStr, i, pIn[0], pIn[1], p->output, expValue);
  3152. VERIFY_ARE_EQUAL(p->output, expValue);
  3153. }
  3154. }
  3155. // Resource structure for data-driven tests.
  3156. struct SUnaryFPOp {
  3157. float input;
  3158. float output;
  3159. };
  3160. struct SBinaryFPOp {
  3161. float input1;
  3162. float input2;
  3163. float output1;
  3164. float output2;
  3165. };
  3166. struct STertiaryFPOp {
  3167. float input1;
  3168. float input2;
  3169. float input3;
  3170. float output;
  3171. };
  3172. struct SUnaryHalfOp {
  3173. uint16_t input;
  3174. uint16_t output;
  3175. };
  3176. struct SBinaryHalfOp {
  3177. uint16_t input1;
  3178. uint16_t input2;
  3179. uint16_t output1;
  3180. uint16_t output2;
  3181. };
  3182. struct STertiaryHalfOp {
  3183. uint16_t input1;
  3184. uint16_t input2;
  3185. uint16_t input3;
  3186. uint16_t output;
  3187. };
  3188. struct SUnaryIntOp {
  3189. int input;
  3190. int output;
  3191. };
  3192. struct SUnaryUintOp {
  3193. unsigned int input;
  3194. unsigned int output;
  3195. };
  3196. struct SBinaryIntOp {
  3197. int input1;
  3198. int input2;
  3199. int output1;
  3200. int output2;
  3201. };
  3202. struct STertiaryIntOp {
  3203. int input1;
  3204. int input2;
  3205. int input3;
  3206. int output;
  3207. };
  3208. struct SBinaryUintOp {
  3209. unsigned int input1;
  3210. unsigned int input2;
  3211. unsigned int output1;
  3212. unsigned int output2;
  3213. };
  3214. struct STertiaryUintOp {
  3215. unsigned int input1;
  3216. unsigned int input2;
  3217. unsigned int input3;
  3218. unsigned int output;
  3219. };
  3220. struct SUnaryInt16Op {
  3221. short input;
  3222. short output;
  3223. };
  3224. struct SUnaryUint16Op {
  3225. unsigned short input;
  3226. unsigned short output;
  3227. };
  3228. struct SBinaryInt16Op {
  3229. short input1;
  3230. short input2;
  3231. short output1;
  3232. short output2;
  3233. };
  3234. struct STertiaryInt16Op {
  3235. short input1;
  3236. short input2;
  3237. short input3;
  3238. short output;
  3239. };
  3240. struct SBinaryUint16Op {
  3241. unsigned short input1;
  3242. unsigned short input2;
  3243. unsigned short output1;
  3244. unsigned short output2;
  3245. };
  3246. struct STertiaryUint16Op {
  3247. unsigned short input1;
  3248. unsigned short input2;
  3249. unsigned short input3;
  3250. unsigned short output;
  3251. };
  3252. // representation for HLSL float vectors
  3253. struct SDotOp {
  3254. XMFLOAT4 input1;
  3255. XMFLOAT4 input2;
  3256. float o_dot2;
  3257. float o_dot3;
  3258. float o_dot4;
  3259. };
  3260. struct Half2
  3261. {
  3262. uint16_t x;
  3263. uint16_t y;
  3264. Half2() = default;
  3265. Half2(const Half2&) = default;
  3266. Half2& operator=(const Half2&) = default;
  3267. Half2(Half2&&) = default;
  3268. Half2& operator=(Half2&&) = default;
  3269. constexpr Half2(uint16_t _x, uint16_t _y) : x(_x), y(_y) {}
  3270. explicit Half2(_In_reads_(2) const uint16_t *pArray) : x(pArray[0]), y(pArray[1]) {}
  3271. };
  3272. struct SDot2AddHalfOp {
  3273. Half2 input1;
  3274. Half2 input2;
  3275. float acc;
  3276. float result;
  3277. };
  3278. struct SDot4AddI8PackedOp {
  3279. uint32_t input1;
  3280. uint32_t input2;
  3281. int32_t acc;
  3282. int32_t result;
  3283. };
  3284. struct SDot4AddU8PackedOp {
  3285. uint32_t input1;
  3286. uint32_t input2;
  3287. uint32_t acc;
  3288. uint32_t result;
  3289. };
  3290. struct SMsad4 {
  3291. unsigned int ref;
  3292. XMUINT2 src;
  3293. XMUINT4 accum;
  3294. XMUINT4 result;
  3295. };
  3296. struct SPackUnpackOpOutPacked
  3297. {
  3298. uint32_t packedUint32;
  3299. uint32_t packedInt32;
  3300. uint32_t packedUint16;
  3301. uint32_t packedInt16;
  3302. uint32_t packedClampedUint32;
  3303. uint32_t packedClampedInt32;
  3304. uint32_t packedClampedUint16;
  3305. uint32_t packedClampedInt16;
  3306. };
  3307. struct SPackUnpackOpOutUnpacked {
  3308. std::array<uint32_t, 4> outputUint32;
  3309. std::array<int32_t, 4> outputInt32;
  3310. std::array<uint16_t, 4> outputUint16;
  3311. std::array<int16_t, 4> outputInt16;
  3312. std::array<uint32_t, 4> outputClampedUint32;
  3313. std::array<int32_t, 4> outputClampedInt32;
  3314. std::array<uint16_t, 4> outputClampedUint16;
  3315. std::array<int16_t, 4> outputClampedInt16;
  3316. };
  3317. // Parameter representation for taef data-driven tests
  3318. struct TableParameter {
  3319. LPCWSTR m_name;
  3320. enum TableParameterType {
  3321. INT8,
  3322. INT16,
  3323. INT32,
  3324. UINT,
  3325. FLOAT,
  3326. HALF,
  3327. DOUBLE,
  3328. STRING,
  3329. BOOL,
  3330. INT8_TABLE,
  3331. INT16_TABLE,
  3332. INT32_TABLE,
  3333. FLOAT_TABLE,
  3334. HALF_TABLE,
  3335. DOUBLE_TABLE,
  3336. STRING_TABLE,
  3337. UINT8_TABLE,
  3338. UINT16_TABLE,
  3339. UINT32_TABLE,
  3340. BOOL_TABLE
  3341. };
  3342. TableParameterType m_type;
  3343. bool m_required; // required parameter
  3344. int8_t m_int8;
  3345. int16_t m_int16;
  3346. int m_int32;
  3347. unsigned int m_uint;
  3348. float m_float;
  3349. uint16_t m_half; // no such thing as half type in c++. Use int16 instead
  3350. double m_double;
  3351. bool m_bool;
  3352. WEX::Common::String m_str;
  3353. std::vector<int8_t> m_int8Table;
  3354. std::vector<int16_t> m_int16Table;
  3355. std::vector<int> m_int32Table;
  3356. std::vector<uint8_t> m_uint8Table;
  3357. std::vector<uint16_t> m_uint16Table;
  3358. std::vector<unsigned int> m_uint32Table;
  3359. std::vector<float> m_floatTable;
  3360. std::vector<uint16_t> m_halfTable; // no such thing as half type in c++
  3361. std::vector<double> m_doubleTable;
  3362. std::vector<bool> m_boolTable;
  3363. std::vector<WEX::Common::String> m_StringTable;
  3364. };
  3365. class TableParameterHandler {
  3366. private:
  3367. HRESULT ParseTableRow();
  3368. public:
  3369. TableParameter* m_table;
  3370. size_t m_tableSize;
  3371. TableParameterHandler(TableParameter *pTable, size_t size) : m_table(pTable), m_tableSize(size) {
  3372. clearTableParameter();
  3373. VERIFY_SUCCEEDED(ParseTableRow());
  3374. }
  3375. TableParameter* GetTableParamByName(LPCWSTR name) {
  3376. for (size_t i = 0; i < m_tableSize; ++i) {
  3377. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3378. return &m_table[i];
  3379. }
  3380. }
  3381. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3382. return nullptr;
  3383. }
  3384. void clearTableParameter() {
  3385. for (size_t i = 0; i < m_tableSize; ++i) {
  3386. m_table[i].m_int32 = 0;
  3387. m_table[i].m_uint = 0;
  3388. m_table[i].m_double = 0;
  3389. m_table[i].m_bool = false;
  3390. m_table[i].m_str = WEX::Common::String();
  3391. }
  3392. }
  3393. template <class T1>
  3394. std::vector<T1> *GetDataArray(LPCWSTR name) {
  3395. return nullptr;
  3396. }
  3397. template <>
  3398. std::vector<int> *GetDataArray(LPCWSTR name) {
  3399. for (size_t i = 0; i < m_tableSize; ++i) {
  3400. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3401. return &(m_table[i].m_int32Table);
  3402. }
  3403. }
  3404. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3405. return nullptr;
  3406. }
  3407. template <>
  3408. std::vector<int8_t> *GetDataArray(LPCWSTR name) {
  3409. for (size_t i = 0; i < m_tableSize; ++i) {
  3410. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3411. return &(m_table[i].m_int8Table);
  3412. }
  3413. }
  3414. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3415. return nullptr;
  3416. }
  3417. template <>
  3418. std::vector<int16_t> *GetDataArray(LPCWSTR name) {
  3419. for (size_t i = 0; i < m_tableSize; ++i) {
  3420. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3421. return &(m_table[i].m_int16Table);
  3422. }
  3423. }
  3424. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3425. return nullptr;
  3426. }
  3427. template <>
  3428. std::vector<unsigned int> *GetDataArray(LPCWSTR name) {
  3429. for (size_t i = 0; i < m_tableSize; ++i) {
  3430. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3431. return &(m_table[i].m_uint32Table);
  3432. }
  3433. }
  3434. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3435. return nullptr;
  3436. }
  3437. template <>
  3438. std::vector<float> *GetDataArray(LPCWSTR name) {
  3439. for (size_t i = 0; i < m_tableSize; ++i) {
  3440. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3441. return &(m_table[i].m_floatTable);
  3442. }
  3443. }
  3444. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3445. return nullptr;
  3446. }
  3447. // TODO: uin16_t may be used to represent two different types when we introduce uint16
  3448. template <>
  3449. std::vector<uint16_t> *GetDataArray(LPCWSTR name) {
  3450. for (size_t i = 0; i < m_tableSize; ++i) {
  3451. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3452. return &(m_table[i].m_halfTable);
  3453. }
  3454. }
  3455. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3456. return nullptr;
  3457. }
  3458. template <>
  3459. std::vector<double> *GetDataArray(LPCWSTR name) {
  3460. for (size_t i = 0; i < m_tableSize; ++i) {
  3461. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3462. return &(m_table[i].m_doubleTable);
  3463. }
  3464. }
  3465. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3466. return nullptr;
  3467. }
  3468. template <>
  3469. std::vector<bool> *GetDataArray(LPCWSTR name) {
  3470. for (size_t i = 0; i < m_tableSize; ++i) {
  3471. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3472. return &(m_table[i].m_boolTable);
  3473. }
  3474. }
  3475. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3476. return nullptr;
  3477. }
  3478. };
  3479. static TableParameter UnaryFPOpParameters[] = {
  3480. { L"ShaderOp.Target", TableParameter::STRING, true },
  3481. { L"ShaderOp.Text", TableParameter::STRING, true },
  3482. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3483. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3484. { L"Validation.Type", TableParameter::STRING, true },
  3485. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3486. { L"Warp.Version", TableParameter::UINT, false }
  3487. };
  3488. static TableParameter BinaryFPOpParameters[] = {
  3489. { L"ShaderOp.Target", TableParameter::STRING, true },
  3490. { L"ShaderOp.Text", TableParameter::STRING, true },
  3491. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3492. { L"Validation.Input2", TableParameter::FLOAT_TABLE, true },
  3493. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3494. { L"Validation.Expected2", TableParameter::FLOAT_TABLE, false },
  3495. { L"Validation.Type", TableParameter::STRING, true },
  3496. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3497. };
  3498. static TableParameter TertiaryFPOpParameters[] = {
  3499. { L"ShaderOp.Target", TableParameter::STRING, true },
  3500. { L"ShaderOp.Text", TableParameter::STRING, true },
  3501. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3502. { L"Validation.Input2", TableParameter::FLOAT_TABLE, true },
  3503. { L"Validation.Input3", TableParameter::FLOAT_TABLE, true },
  3504. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3505. { L"Validation.Type", TableParameter::STRING, true },
  3506. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3507. };
  3508. static TableParameter UnaryHalfOpParameters[] = {
  3509. { L"ShaderOp.Target", TableParameter::STRING, true },
  3510. { L"ShaderOp.Text", TableParameter::STRING, true },
  3511. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3512. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3513. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3514. { L"Validation.Type", TableParameter::STRING, true },
  3515. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3516. { L"Warp.Version", TableParameter::UINT, false }
  3517. };
  3518. static TableParameter BinaryHalfOpParameters[] = {
  3519. { L"ShaderOp.Target", TableParameter::STRING, true },
  3520. { L"ShaderOp.Text", TableParameter::STRING, true },
  3521. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3522. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3523. { L"Validation.Input2", TableParameter::HALF_TABLE, true },
  3524. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3525. { L"Validation.Expected2", TableParameter::HALF_TABLE, false },
  3526. { L"Validation.Type", TableParameter::STRING, true },
  3527. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3528. };
  3529. static TableParameter TertiaryHalfOpParameters[] = {
  3530. { L"ShaderOp.Target", TableParameter::STRING, true },
  3531. { L"ShaderOp.Text", TableParameter::STRING, true },
  3532. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3533. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3534. { L"Validation.Input2", TableParameter::HALF_TABLE, true },
  3535. { L"Validation.Input3", TableParameter::HALF_TABLE, true },
  3536. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3537. { L"Validation.Type", TableParameter::STRING, true },
  3538. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3539. };
  3540. static TableParameter UnaryIntOpParameters[] = {
  3541. { L"ShaderOp.Target", TableParameter::STRING, true },
  3542. { L"ShaderOp.Text", TableParameter::STRING, true },
  3543. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3544. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3545. { L"Validation.Tolerance", TableParameter::INT32, true },
  3546. };
  3547. static TableParameter UnaryUintOpParameters[] = {
  3548. { L"ShaderOp.Target", TableParameter::STRING, true },
  3549. { L"ShaderOp.Text", TableParameter::STRING, true },
  3550. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3551. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3552. { L"Validation.Tolerance", TableParameter::INT32, true },
  3553. };
  3554. static TableParameter BinaryIntOpParameters[] = {
  3555. { L"ShaderOp.Target", TableParameter::STRING, true },
  3556. { L"ShaderOp.Text", TableParameter::STRING, true },
  3557. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3558. { L"Validation.Input2", TableParameter::INT32_TABLE, true },
  3559. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3560. { L"Validation.Expected2", TableParameter::INT32_TABLE, false },
  3561. { L"Validation.Tolerance", TableParameter::INT32, true },
  3562. };
  3563. static TableParameter TertiaryIntOpParameters[] = {
  3564. { L"ShaderOp.Target", TableParameter::STRING, true },
  3565. { L"ShaderOp.Text", TableParameter::STRING, true },
  3566. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3567. { L"Validation.Input2", TableParameter::INT32_TABLE, true },
  3568. { L"Validation.Input3", TableParameter::INT32_TABLE, true },
  3569. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3570. { L"Validation.Tolerance", TableParameter::INT32, true },
  3571. };
  3572. static TableParameter BinaryUintOpParameters[] = {
  3573. { L"ShaderOp.Target", TableParameter::STRING, true },
  3574. { L"ShaderOp.Text", TableParameter::STRING, true },
  3575. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3576. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3577. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3578. { L"Validation.Expected2", TableParameter::UINT32_TABLE, false },
  3579. { L"Validation.Tolerance", TableParameter::INT32, true },
  3580. };
  3581. static TableParameter TertiaryUintOpParameters[] = {
  3582. { L"ShaderOp.Target", TableParameter::STRING, true },
  3583. { L"ShaderOp.Text", TableParameter::STRING, true },
  3584. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3585. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3586. { L"Validation.Input3", TableParameter::UINT32_TABLE, true },
  3587. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3588. { L"Validation.Tolerance", TableParameter::INT32, true },
  3589. };
  3590. static TableParameter UnaryInt16OpParameters[] = {
  3591. { L"ShaderOp.Target", TableParameter::STRING, true },
  3592. { L"ShaderOp.Text", TableParameter::STRING, true },
  3593. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3594. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  3595. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3596. { L"Validation.Tolerance", TableParameter::INT32, true },
  3597. };
  3598. static TableParameter UnaryUint16OpParameters[] = {
  3599. { L"ShaderOp.Target", TableParameter::STRING, true },
  3600. { L"ShaderOp.Text", TableParameter::STRING, true },
  3601. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3602. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3603. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3604. { L"Validation.Tolerance", TableParameter::INT32, true },
  3605. };
  3606. static TableParameter BinaryInt16OpParameters[] = {
  3607. { L"ShaderOp.Target", TableParameter::STRING, true },
  3608. { L"ShaderOp.Text", TableParameter::STRING, true },
  3609. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3610. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  3611. { L"Validation.Input2", TableParameter::INT16_TABLE, true },
  3612. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3613. { L"Validation.Expected2", TableParameter::INT16_TABLE, false },
  3614. { L"Validation.Tolerance", TableParameter::INT32, true },
  3615. };
  3616. static TableParameter TertiaryInt16OpParameters[] = {
  3617. { L"ShaderOp.Target", TableParameter::STRING, true },
  3618. { L"ShaderOp.Text", TableParameter::STRING, true },
  3619. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3620. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  3621. { L"Validation.Input2", TableParameter::INT16_TABLE, true },
  3622. { L"Validation.Input3", TableParameter::INT16_TABLE, true },
  3623. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3624. { L"Validation.Tolerance", TableParameter::INT32, true },
  3625. };
  3626. static TableParameter BinaryUint16OpParameters[] = {
  3627. { L"ShaderOp.Target", TableParameter::STRING, true },
  3628. { L"ShaderOp.Text", TableParameter::STRING, true },
  3629. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3630. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3631. { L"Validation.Input2", TableParameter::UINT16_TABLE, true },
  3632. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3633. { L"Validation.Expected2", TableParameter::UINT16_TABLE, false },
  3634. { L"Validation.Tolerance", TableParameter::INT32, true },
  3635. };
  3636. static TableParameter TertiaryUint16OpParameters[] = {
  3637. { L"ShaderOp.Target", TableParameter::STRING, true },
  3638. { L"ShaderOp.Text", TableParameter::STRING, true },
  3639. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3640. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3641. { L"Validation.Input2", TableParameter::UINT16_TABLE, true },
  3642. { L"Validation.Input3", TableParameter::UINT16_TABLE, true },
  3643. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3644. { L"Validation.Tolerance", TableParameter::INT32, true },
  3645. };
  3646. static TableParameter DotOpParameters[] = {
  3647. { L"ShaderOp.Target", TableParameter::STRING, true },
  3648. { L"ShaderOp.Text", TableParameter::STRING, true },
  3649. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3650. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3651. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3652. { L"Validation.Expected2", TableParameter::STRING_TABLE, true },
  3653. { L"Validation.Expected3", TableParameter::STRING_TABLE, true },
  3654. { L"Validation.Type", TableParameter::STRING, true },
  3655. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3656. };
  3657. static TableParameter Dot2AddHalfOpParameters[] = {
  3658. { L"ShaderOp.Target", TableParameter::STRING, true },
  3659. { L"ShaderOp.Text", TableParameter::STRING, true },
  3660. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3661. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3662. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3663. { L"Validation.Input3", TableParameter::FLOAT_TABLE, true },
  3664. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3665. { L"Validation.Type", TableParameter::STRING, true },
  3666. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3667. };
  3668. static TableParameter Dot4AddI8PackedOpParameters[] = {
  3669. { L"ShaderOp.Target", TableParameter::STRING, true },
  3670. { L"ShaderOp.Text", TableParameter::STRING, true },
  3671. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3672. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3673. { L"Validation.Input3", TableParameter::INT32_TABLE, true },
  3674. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3675. };
  3676. static TableParameter Dot4AddU8PackedOpParameters[] = {
  3677. { L"ShaderOp.Target", TableParameter::STRING, true },
  3678. { L"ShaderOp.Text", TableParameter::STRING, true },
  3679. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3680. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3681. { L"Validation.Input3", TableParameter::UINT32_TABLE, true },
  3682. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3683. };
  3684. static TableParameter Msad4OpParameters[] = {
  3685. { L"ShaderOp.Text", TableParameter::STRING, true },
  3686. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3687. { L"Validation.Input1", TableParameter::UINT32_TABLE, true},
  3688. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3689. { L"Validation.Input3", TableParameter::STRING_TABLE, true },
  3690. { L"Validation.Expected1", TableParameter::STRING_TABLE, true }
  3691. };
  3692. static TableParameter WaveIntrinsicsActiveIntParameters[] = {
  3693. { L"ShaderOp.Name", TableParameter::STRING, true },
  3694. { L"ShaderOp.Text", TableParameter::STRING, true },
  3695. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3696. { L"Validation.InputSet1", TableParameter::INT32_TABLE, true },
  3697. { L"Validation.InputSet2", TableParameter::INT32_TABLE, false },
  3698. { L"Validation.InputSet3", TableParameter::INT32_TABLE, false },
  3699. { L"Validation.InputSet4", TableParameter::INT32_TABLE, false }
  3700. };
  3701. static TableParameter WaveIntrinsicsPrefixIntParameters[] = {
  3702. { L"ShaderOp.Name", TableParameter::STRING, true },
  3703. { L"ShaderOp.Text", TableParameter::STRING, true },
  3704. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3705. { L"Validation.InputSet1", TableParameter::INT32_TABLE, true },
  3706. { L"Validation.InputSet2", TableParameter::INT32_TABLE, false },
  3707. { L"Validation.InputSet3", TableParameter::INT32_TABLE, false },
  3708. { L"Validation.InputSet4", TableParameter::INT32_TABLE, false }
  3709. };
  3710. static TableParameter WaveIntrinsicsActiveUintParameters[] = {
  3711. { L"ShaderOp.Name", TableParameter::STRING, true },
  3712. { L"ShaderOp.Text", TableParameter::STRING, true },
  3713. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3714. { L"Validation.InputSet1", TableParameter::UINT32_TABLE, true },
  3715. { L"Validation.InputSet2", TableParameter::UINT32_TABLE, false },
  3716. { L"Validation.InputSet3", TableParameter::UINT32_TABLE, false },
  3717. { L"Validation.InputSet4", TableParameter::UINT32_TABLE, false }
  3718. };
  3719. static TableParameter WaveIntrinsicsPrefixUintParameters[] = {
  3720. { L"ShaderOp.Name", TableParameter::STRING, true },
  3721. { L"ShaderOp.Text", TableParameter::STRING, true },
  3722. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3723. { L"Validation.InputSet1", TableParameter::UINT32_TABLE, true },
  3724. { L"Validation.InputSet2", TableParameter::UINT32_TABLE, false },
  3725. { L"Validation.InputSet3", TableParameter::UINT32_TABLE, false },
  3726. { L"Validation.InputSet4", TableParameter::UINT32_TABLE, false }
  3727. };
  3728. static TableParameter WaveIntrinsicsMultiPrefixIntParameters[] = {
  3729. { L"ShaderOp.Name", TableParameter::STRING, true },
  3730. { L"ShaderOp.Target", TableParameter::STRING, true },
  3731. { L"ShaderOp.Text", TableParameter::STRING, true },
  3732. { L"Validation.Keys", TableParameter::INT32_TABLE, true },
  3733. { L"Validation.Values", TableParameter::INT32_TABLE, true },
  3734. };
  3735. static TableParameter WaveIntrinsicsMultiPrefixUintParameters[] = {
  3736. { L"ShaderOp.Name", TableParameter::STRING, true },
  3737. { L"ShaderOp.Target", TableParameter::STRING, true },
  3738. { L"ShaderOp.Text", TableParameter::STRING, true },
  3739. { L"Validation.Keys", TableParameter::UINT32_TABLE, true },
  3740. { L"Validation.Values", TableParameter::UINT32_TABLE, true },
  3741. };
  3742. static TableParameter WaveIntrinsicsActiveBoolParameters[] = {
  3743. { L"ShaderOp.Name", TableParameter::STRING, true },
  3744. { L"ShaderOp.Text", TableParameter::STRING, true },
  3745. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3746. { L"Validation.InputSet1", TableParameter::BOOL_TABLE, true },
  3747. { L"Validation.InputSet2", TableParameter::BOOL_TABLE, false },
  3748. { L"Validation.InputSet3", TableParameter::BOOL_TABLE, false },
  3749. };
  3750. static TableParameter CBufferTestHalfParameters[] = {
  3751. { L"Validation.InputSet", TableParameter::HALF_TABLE, true },
  3752. };
  3753. static TableParameter DenormBinaryFPOpParameters[] = {
  3754. { L"ShaderOp.Target", TableParameter::STRING, true },
  3755. { L"ShaderOp.Text", TableParameter::STRING, true },
  3756. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3757. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3758. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3759. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3760. { L"Validation.Expected2", TableParameter::STRING_TABLE, false },
  3761. { L"Validation.Type", TableParameter::STRING, true },
  3762. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3763. };
  3764. static TableParameter DenormTertiaryFPOpParameters[] = {
  3765. { L"ShaderOp.Target", TableParameter::STRING, true },
  3766. { L"ShaderOp.Text", TableParameter::STRING, true },
  3767. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3768. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3769. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3770. { L"Validation.Input3", TableParameter::STRING_TABLE, true },
  3771. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3772. { L"Validation.Expected2", TableParameter::STRING_TABLE, false },
  3773. { L"Validation.Type", TableParameter::STRING, true },
  3774. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3775. };
  3776. static TableParameter PackUnpackOpParameters[] = {
  3777. { L"ShaderOp.Text", TableParameter::STRING, true },
  3778. { L"Validation.Type", TableParameter::STRING, true },
  3779. { L"Validation.Tolerance", TableParameter::UINT, true },
  3780. { L"Validation.Input", TableParameter::UINT32_TABLE, true },
  3781. };
  3782. static bool IsHexString(PCWSTR str, uint16_t *value) {
  3783. std::wstring wString(str);
  3784. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3785. LPCWSTR wstr = wString.c_str();
  3786. if (wcsncmp(wstr, L"0x", 2) == 0 || wcsncmp(wstr, L"0b", 2) == 0) {
  3787. *value = (uint16_t)wcstol(wstr, NULL, 0);
  3788. return true;
  3789. }
  3790. return false;
  3791. }
  3792. static HRESULT ParseDataToFloat(PCWSTR str, float &value) {
  3793. std::wstring wString(str);
  3794. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3795. PCWSTR wstr = wString.data();
  3796. if (_wcsicmp(wstr, L"NaN") == 0) {
  3797. value = NAN;
  3798. } else if (_wcsicmp(wstr, L"-inf") == 0) {
  3799. value = -(INFINITY);
  3800. } else if (_wcsicmp(wstr, L"inf") == 0) {
  3801. value = INFINITY;
  3802. } else if (_wcsicmp(wstr, L"-denorm") == 0) {
  3803. value = -(FLT_MIN / 2);
  3804. } else if (_wcsicmp(wstr, L"denorm") == 0) {
  3805. value = FLT_MIN / 2;
  3806. } else if (_wcsicmp(wstr, L"-0.0f") == 0 || _wcsicmp(wstr, L"-0.0") == 0 ||
  3807. _wcsicmp(wstr, L"-0") == 0) {
  3808. value = -0.0f;
  3809. } else if (_wcsicmp(wstr, L"0.0f") == 0 || _wcsicmp(wstr, L"0.0") == 0 ||
  3810. _wcsicmp(wstr, L"0") == 0) {
  3811. value = 0.0f;
  3812. } else if (_wcsnicmp(wstr, L"0x", 2) == 0) { // For hex values, take values literally
  3813. unsigned temp_i = std::stoul(wstr, nullptr, 16);
  3814. value = (float&)temp_i;
  3815. }
  3816. else {
  3817. // evaluate the expression of wstring
  3818. double val = _wtof(wstr);
  3819. if (val == 0) {
  3820. LogErrorFmt(L"Failed to parse parameter %s to float", wstr);
  3821. return E_FAIL;
  3822. }
  3823. value = (float)val;
  3824. }
  3825. return S_OK;
  3826. }
  3827. static HRESULT ParseDataToInt(PCWSTR str, int &value) {
  3828. std::wstring wString(str);
  3829. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3830. PCWSTR wstr = wString.data();
  3831. // evaluate the expression of string
  3832. if (_wcsicmp(wstr, L"0.0") == 0 || _wcsicmp(wstr, L"0") == 0) {
  3833. value = 0;
  3834. return S_OK;
  3835. }
  3836. int val = _wtoi(wstr);
  3837. if (val == 0) {
  3838. LogErrorFmt(L"Failed to parse parameter %s to int", wstr);
  3839. return E_FAIL;
  3840. }
  3841. value = val;
  3842. return S_OK;
  3843. }
  3844. static HRESULT ParseDataToUint(PCWSTR str, unsigned int &value) {
  3845. std::wstring wString(str);
  3846. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3847. PCWSTR wstr = wString.data();
  3848. // evaluate the expression of string
  3849. if (_wcsicmp(wstr, L"0") == 0 || _wcsicmp(wstr, L"0x00000000") == 0) {
  3850. value = 0;
  3851. return S_OK;
  3852. }
  3853. wchar_t *end;
  3854. unsigned int val = std::wcstoul(wstr, &end, 0);
  3855. if (val == 0) {
  3856. LogErrorFmt(L"Failed to parse parameter %s to int", wstr);
  3857. return E_FAIL;
  3858. }
  3859. value = val;
  3860. return S_OK;
  3861. }
  3862. static HRESULT ParseDataToVectorFloat(PCWSTR str, float *ptr, size_t count) {
  3863. std::wstring wstr(str);
  3864. size_t curPosition = 0;
  3865. // parse a string of dot product separated by commas
  3866. for (size_t i = 0; i < count; ++i) {
  3867. size_t nextPosition = wstr.find(L",", curPosition);
  3868. if (FAILED(ParseDataToFloat(
  3869. wstr.substr(curPosition, nextPosition - curPosition).data(),
  3870. *(ptr + i)))) {
  3871. return E_FAIL;
  3872. }
  3873. curPosition = nextPosition + 1;
  3874. }
  3875. return S_OK;
  3876. }
  3877. static HRESULT ParseDataToVectorHalf(PCWSTR str, uint16_t *ptr, size_t count) {
  3878. std::wstring wstr(str);
  3879. size_t curPosition = 0;
  3880. // parse a string of dot product separated by commas
  3881. for (size_t i = 0; i < count; ++i) {
  3882. size_t nextPosition = wstr.find(L",", curPosition);
  3883. float floatValue;
  3884. if (FAILED(ParseDataToFloat(
  3885. wstr.substr(curPosition, nextPosition - curPosition).data(), floatValue))) {
  3886. return E_FAIL;
  3887. }
  3888. *(ptr + i) = ConvertFloat32ToFloat16(floatValue);
  3889. curPosition = nextPosition + 1;
  3890. }
  3891. return S_OK;
  3892. }
  3893. static HRESULT ParseDataToVectorUint(PCWSTR str, unsigned int *ptr, size_t count) {
  3894. std::wstring wstr(str);
  3895. size_t curPosition = 0;
  3896. // parse a string of dot product separated by commas
  3897. for (size_t i = 0; i < count; ++i) {
  3898. size_t nextPosition = wstr.find(L",", curPosition);
  3899. if (FAILED(ParseDataToUint(
  3900. wstr.substr(curPosition, nextPosition - curPosition).data(),
  3901. *(ptr + i)))) {
  3902. return E_FAIL;
  3903. }
  3904. curPosition = nextPosition + 1;
  3905. }
  3906. return S_OK;
  3907. }
  3908. HRESULT TableParameterHandler::ParseTableRow() {
  3909. TableParameter *table = m_table;
  3910. for (unsigned int i = 0; i < m_tableSize; ++i) {
  3911. switch (table[i].m_type) {
  3912. case TableParameter::INT8:
  3913. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3914. table[i].m_int32)) && table[i].m_required) {
  3915. // TryGetValue does not suppport reading from int16
  3916. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3917. return E_FAIL;
  3918. }
  3919. table[i].m_int8 = (int8_t)(table[i].m_int32);
  3920. break;
  3921. case TableParameter::INT16:
  3922. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3923. table[i].m_int32)) && table[i].m_required) {
  3924. // TryGetValue does not suppport reading from int16
  3925. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3926. return E_FAIL;
  3927. }
  3928. table[i].m_int16 = (short)(table[i].m_int32);
  3929. break;
  3930. case TableParameter::INT32:
  3931. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3932. table[i].m_int32)) && table[i].m_required) {
  3933. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3934. return E_FAIL;
  3935. }
  3936. break;
  3937. case TableParameter::UINT:
  3938. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3939. table[i].m_uint)) && table[i].m_required) {
  3940. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3941. return E_FAIL;
  3942. }
  3943. break;
  3944. case TableParameter::DOUBLE:
  3945. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3946. table[i].m_name, table[i].m_double)) && table[i].m_required) {
  3947. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3948. return E_FAIL;
  3949. }
  3950. break;
  3951. case TableParameter::STRING:
  3952. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3953. table[i].m_str)) && table[i].m_required) {
  3954. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3955. return E_FAIL;
  3956. }
  3957. break;
  3958. case TableParameter::BOOL:
  3959. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3960. table[i].m_str)) && table[i].m_bool) {
  3961. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3962. return E_FAIL;
  3963. }
  3964. break;
  3965. case TableParameter::INT8_TABLE: {
  3966. WEX::TestExecution::TestDataArray<int> tempTable;
  3967. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3968. table[i].m_name, tempTable)) && table[i].m_required) {
  3969. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3970. return E_FAIL;
  3971. }
  3972. // TryGetValue does not suppport reading from int8
  3973. table[i].m_int8Table.resize(tempTable.GetSize());
  3974. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3975. table[i].m_int8Table[j] = (int8_t)tempTable[j];
  3976. }
  3977. break;
  3978. }
  3979. case TableParameter::INT16_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. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3984. return E_FAIL;
  3985. }
  3986. // TryGetValue does not suppport reading from int8
  3987. table[i].m_int16Table.resize(tempTable.GetSize());
  3988. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3989. table[i].m_int16Table[j] = (int16_t)tempTable[j];
  3990. }
  3991. break;
  3992. }case TableParameter::INT32_TABLE: {
  3993. WEX::TestExecution::TestDataArray<int> tempTable;
  3994. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3995. table[i].m_name, tempTable)) && table[i].m_required) {
  3996. // TryGetValue does not suppport reading from int8
  3997. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3998. return E_FAIL;
  3999. }
  4000. table[i].m_int32Table.resize(tempTable.GetSize());
  4001. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4002. table[i].m_int32Table[j] = tempTable[j];
  4003. }
  4004. break;
  4005. }
  4006. case TableParameter::UINT8_TABLE: {
  4007. WEX::TestExecution::TestDataArray<int> tempTable;
  4008. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4009. table[i].m_name, tempTable)) && table[i].m_required) {
  4010. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4011. return E_FAIL;
  4012. }
  4013. // TryGetValue does not suppport reading from int8
  4014. table[i].m_int8Table.resize(tempTable.GetSize());
  4015. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4016. table[i].m_int8Table[j] = (uint8_t)tempTable[j];
  4017. }
  4018. break;
  4019. }
  4020. case TableParameter::UINT16_TABLE: {
  4021. WEX::TestExecution::TestDataArray<int> tempTable;
  4022. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4023. table[i].m_name, tempTable)) && table[i].m_required) {
  4024. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4025. return E_FAIL;
  4026. }
  4027. // TryGetValue does not suppport reading from int8
  4028. table[i].m_uint16Table.resize(tempTable.GetSize());
  4029. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4030. table[i].m_uint16Table[j] = (uint16_t)tempTable[j];
  4031. }
  4032. break;
  4033. }
  4034. case TableParameter::UINT32_TABLE: {
  4035. WEX::TestExecution::TestDataArray<unsigned int> tempTable;
  4036. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4037. table[i].m_name, tempTable)) && table[i].m_required) {
  4038. // TryGetValue does not suppport reading from int8
  4039. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4040. return E_FAIL;
  4041. }
  4042. table[i].m_uint32Table.resize(tempTable.GetSize());
  4043. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4044. table[i].m_uint32Table[j] = tempTable[j];
  4045. }
  4046. break;
  4047. }
  4048. case TableParameter::FLOAT_TABLE: {
  4049. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  4050. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4051. table[i].m_name, tempTable)) && table[i].m_required) {
  4052. // TryGetValue does not suppport reading from int8
  4053. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4054. return E_FAIL;
  4055. }
  4056. table[i].m_floatTable.resize(tempTable.GetSize());
  4057. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4058. ParseDataToFloat(tempTable[j], table[i].m_floatTable[j]);
  4059. }
  4060. break;
  4061. }
  4062. case TableParameter::HALF_TABLE: {
  4063. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  4064. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4065. table[i].m_name, tempTable)) && table[i].m_required) {
  4066. // TryGetValue does not suppport reading from int8
  4067. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4068. return E_FAIL;
  4069. }
  4070. table[i].m_halfTable.resize(tempTable.GetSize());
  4071. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4072. uint16_t value = 0;
  4073. if (IsHexString(tempTable[j], &value)) {
  4074. table[i].m_halfTable[j] = value;
  4075. }
  4076. else {
  4077. float val;
  4078. ParseDataToFloat(tempTable[j], val);
  4079. if (isdenorm(val))
  4080. table[i].m_halfTable[j] = signbit(val) ? Float16NegDenorm : Float16PosDenorm;
  4081. else
  4082. table[i].m_halfTable[j] = ConvertFloat32ToFloat16(val);
  4083. }
  4084. }
  4085. break;
  4086. }
  4087. case TableParameter::DOUBLE_TABLE: {
  4088. WEX::TestExecution::TestDataArray<double> tempTable;
  4089. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4090. table[i].m_name, tempTable)) && table[i].m_required) {
  4091. // TryGetValue does not suppport reading from int8
  4092. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4093. return E_FAIL;
  4094. }
  4095. table[i].m_doubleTable.resize(tempTable.GetSize());
  4096. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4097. table[i].m_doubleTable[j] = tempTable[j];
  4098. }
  4099. break;
  4100. }
  4101. case TableParameter::BOOL_TABLE: {
  4102. WEX::TestExecution::TestDataArray<bool> tempTable;
  4103. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4104. table[i].m_name, tempTable)) && table[i].m_required) {
  4105. // TryGetValue does not suppport reading from int8
  4106. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4107. return E_FAIL;
  4108. }
  4109. table[i].m_boolTable.resize(tempTable.GetSize());
  4110. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4111. table[i].m_boolTable[j] = tempTable[j];
  4112. }
  4113. break;
  4114. }
  4115. case TableParameter::STRING_TABLE: {
  4116. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  4117. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4118. table[i].m_name, tempTable)) && table[i].m_required) {
  4119. // TryGetValue does not suppport reading from int8
  4120. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4121. return E_FAIL;
  4122. }
  4123. table[i].m_StringTable.resize(tempTable.GetSize());
  4124. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4125. table[i].m_StringTable[j] = tempTable[j];
  4126. }
  4127. break;
  4128. }
  4129. default:
  4130. DXASSERT_NOMSG("Invalid Parameter Type");
  4131. }
  4132. if (errno == ERANGE) {
  4133. LogErrorFmt(L"got out of range value for table %s", table[i].m_name);
  4134. return E_FAIL;
  4135. }
  4136. }
  4137. return S_OK;
  4138. }
  4139. static void VerifyOutputWithExpectedValueInt(int output, int ref, int tolerance) {
  4140. VERIFY_IS_TRUE(output - ref <= tolerance && ref - output <= tolerance);
  4141. }
  4142. static void VerifyOutputWithExpectedValueUInt(uint32_t output, uint32_t ref, uint32_t tolerance) {
  4143. VERIFY_IS_TRUE(output - ref <= tolerance && ref - output <= tolerance);
  4144. }
  4145. static void VerifyOutputWithExpectedValueUInt4(XMUINT4 output, XMUINT4 ref) {
  4146. VERIFY_ARE_EQUAL(output.x, ref.x);
  4147. VERIFY_ARE_EQUAL(output.y, ref.y);
  4148. VERIFY_ARE_EQUAL(output.z, ref.z);
  4149. VERIFY_ARE_EQUAL(output.w, ref.w);
  4150. }
  4151. static void VerifyOutputWithExpectedValueFloat(
  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. VERIFY_IS_TRUE(CompareFloatRelativeEpsilon(output, ref, (int)tolerance, mode));
  4156. } else if (_wcsicmp(type, L"Epsilon") == 0) {
  4157. VERIFY_IS_TRUE(CompareFloatEpsilon(output, ref, (float)tolerance, mode));
  4158. } else if (_wcsicmp(type, L"ULP") == 0) {
  4159. VERIFY_IS_TRUE(CompareFloatULP(output, ref, (int)tolerance, mode));
  4160. } else {
  4161. LogErrorFmt(L"Failed to read comparison type %S", type);
  4162. }
  4163. }
  4164. static bool CompareOutputWithExpectedValueFloat(
  4165. float output, float ref, LPCWSTR type, double tolerance,
  4166. hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
  4167. if (_wcsicmp(type, L"Relative") == 0) {
  4168. return CompareFloatRelativeEpsilon(output, ref, (int)tolerance, mode);
  4169. } else if (_wcsicmp(type, L"Epsilon") == 0) {
  4170. return CompareFloatEpsilon(output, ref, (float)tolerance, mode);
  4171. } else if (_wcsicmp(type, L"ULP") == 0) {
  4172. return CompareFloatULP(output, ref, (int)tolerance, mode);
  4173. } else {
  4174. LogErrorFmt(L"Failed to read comparison type %S", type);
  4175. return false;
  4176. }
  4177. }
  4178. static void VerifyOutputWithExpectedValueHalf(
  4179. uint16_t output, uint16_t ref, LPCWSTR type, double tolerance) {
  4180. if (_wcsicmp(type, L"Relative") == 0) {
  4181. VERIFY_IS_TRUE(CompareHalfRelativeEpsilon(output, ref, (int)tolerance));
  4182. }
  4183. else if (_wcsicmp(type, L"Epsilon") == 0) {
  4184. VERIFY_IS_TRUE(CompareHalfEpsilon(output, ref, (float)tolerance));
  4185. }
  4186. else if (_wcsicmp(type, L"ULP") == 0) {
  4187. VERIFY_IS_TRUE(CompareHalfULP(output, ref, (float)tolerance));
  4188. }
  4189. else {
  4190. LogErrorFmt(L"Failed to read comparison type %S", type);
  4191. }
  4192. }
  4193. TEST_F(ExecutionTest, UnaryFloatOpTest) {
  4194. WEX::TestExecution::SetVerifyOutput verifySettings(
  4195. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4196. CComPtr<IStream> pStream;
  4197. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4198. CComPtr<ID3D12Device> pDevice;
  4199. if (!CreateDevice(&pDevice)) {
  4200. return;
  4201. }
  4202. // Read data from the table
  4203. int tableSize = sizeof(UnaryFPOpParameters) / sizeof(TableParameter);
  4204. TableParameterHandler handler(UnaryFPOpParameters, tableSize);
  4205. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4206. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4207. unsigned int WarpVersion = handler.GetTableParamByName(L"Warp.Version")->m_uint;
  4208. if (GetTestParamUseWARP(true) && !IsValidWarpDllVersion(WarpVersion)) {
  4209. return;
  4210. }
  4211. std::vector<float> *Validation_Input =
  4212. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4213. std::vector<float> *Validation_Expected =
  4214. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4215. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4216. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4217. size_t count = Validation_Input->size();
  4218. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4219. pDevice, m_support, pStream, "UnaryFPOp",
  4220. // this callbacked is called when the test
  4221. // is creating the resource to run the test
  4222. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4223. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryFPOp"));
  4224. size_t size = sizeof(SUnaryFPOp) * count;
  4225. Data.resize(size);
  4226. SUnaryFPOp *pPrimitives = (SUnaryFPOp *)Data.data();
  4227. for (size_t i = 0; i < count; ++i) {
  4228. SUnaryFPOp *p = &pPrimitives[i];
  4229. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4230. }
  4231. // use shader from data table
  4232. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4233. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4234. });
  4235. MappedData data;
  4236. test->Test->GetReadBackData("SUnaryFPOp", &data);
  4237. SUnaryFPOp *pPrimitives = (SUnaryFPOp*)data.data();
  4238. WEX::TestExecution::DisableVerifyExceptions dve;
  4239. for (unsigned i = 0; i < count; ++i) {
  4240. SUnaryFPOp *p = &pPrimitives[i];
  4241. float val = (*Validation_Expected)[i % Validation_Expected->size()];
  4242. LogCommentFmt(
  4243. L"element #%u, input = %6.8f, output = %6.8f, expected = %6.8f", i,
  4244. p->input, p->output, val);
  4245. VerifyOutputWithExpectedValueFloat(p->output, val, Validation_Type, Validation_Tolerance);
  4246. }
  4247. }
  4248. TEST_F(ExecutionTest, BinaryFloatOpTest) {
  4249. WEX::TestExecution::SetVerifyOutput verifySettings(
  4250. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4251. CComPtr<IStream> pStream;
  4252. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4253. CComPtr<ID3D12Device> pDevice;
  4254. if (!CreateDevice(&pDevice)) {
  4255. return;
  4256. }
  4257. // Read data from the table
  4258. int tableSize = sizeof(BinaryFPOpParameters) / sizeof(TableParameter);
  4259. TableParameterHandler handler(BinaryFPOpParameters, tableSize);
  4260. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4261. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4262. std::vector<float> *Validation_Input1 =
  4263. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4264. std::vector<float> *Validation_Input2 =
  4265. &(handler.GetTableParamByName(L"Validation.Input2")->m_floatTable);
  4266. std::vector<float> *Validation_Expected1 =
  4267. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4268. std::vector<float> *Validation_Expected2 =
  4269. &(handler.GetTableParamByName(L"Validation.Expected2")->m_floatTable);
  4270. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4271. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4272. size_t count = Validation_Input1->size();
  4273. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4274. pDevice, m_support, pStream, "BinaryFPOp",
  4275. // this callbacked is called when the test
  4276. // is creating the resource to run the test
  4277. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4278. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  4279. size_t size = sizeof(SBinaryFPOp) * count;
  4280. Data.resize(size);
  4281. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)Data.data();
  4282. for (size_t i = 0; i < count; ++i) {
  4283. SBinaryFPOp *p = &pPrimitives[i];
  4284. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4285. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4286. }
  4287. // use shader from data table
  4288. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4289. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4290. });
  4291. MappedData data;
  4292. test->Test->GetReadBackData("SBinaryFPOp", &data);
  4293. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)data.data();
  4294. WEX::TestExecution::DisableVerifyExceptions dve;
  4295. unsigned numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4296. if (numExpected == 2) {
  4297. for (unsigned i = 0; i < count; ++i) {
  4298. SBinaryFPOp *p = &pPrimitives[i];
  4299. float val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4300. float val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4301. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output1 = "
  4302. L"%6.8f, expected1 = %6.8f, output2 = %6.8f, expected2 = %6.8f",
  4303. i, p->input1, p->input2, p->output1, val1, p->output2,
  4304. val2);
  4305. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  4306. Validation_Tolerance);
  4307. VerifyOutputWithExpectedValueFloat(p->output2, val2, Validation_Type,
  4308. Validation_Tolerance);
  4309. }
  4310. }
  4311. else if (numExpected == 1) {
  4312. for (unsigned i = 0; i < count; ++i) {
  4313. SBinaryFPOp *p = &pPrimitives[i];
  4314. float val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4315. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output1 = "
  4316. L"%6.8f, expected1 = %6.8f",
  4317. i, p->input1, p->input2, p->output1, val1);
  4318. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  4319. Validation_Tolerance);
  4320. }
  4321. }
  4322. else {
  4323. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4324. }
  4325. }
  4326. TEST_F(ExecutionTest, TertiaryFloatOpTest) {
  4327. WEX::TestExecution::SetVerifyOutput verifySettings(
  4328. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4329. CComPtr<IStream> pStream;
  4330. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4331. CComPtr<ID3D12Device> pDevice;
  4332. if (!CreateDevice(&pDevice)) {
  4333. return;
  4334. }
  4335. // Read data from the table
  4336. int tableSize = sizeof(TertiaryFPOpParameters) / sizeof(TableParameter);
  4337. TableParameterHandler handler(TertiaryFPOpParameters, tableSize);
  4338. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4339. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4340. std::vector<float> *Validation_Input1 =
  4341. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4342. std::vector<float> *Validation_Input2 =
  4343. &(handler.GetTableParamByName(L"Validation.Input2")->m_floatTable);
  4344. std::vector<float> *Validation_Input3 =
  4345. &(handler.GetTableParamByName(L"Validation.Input3")->m_floatTable);
  4346. std::vector<float> *Validation_Expected =
  4347. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4348. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4349. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4350. size_t count = Validation_Input1->size();
  4351. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4352. pDevice, m_support, pStream, "TertiaryFPOp",
  4353. // this callbacked is called when the test
  4354. // is creating the resource to run the test
  4355. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4356. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  4357. size_t size = sizeof(STertiaryFPOp) * count;
  4358. Data.resize(size);
  4359. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)Data.data();
  4360. for (size_t i = 0; i < count; ++i) {
  4361. STertiaryFPOp *p = &pPrimitives[i];
  4362. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4363. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4364. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4365. }
  4366. // use shader from data table
  4367. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4368. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4369. });
  4370. MappedData data;
  4371. test->Test->GetReadBackData("STertiaryFPOp", &data);
  4372. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)data.data();
  4373. WEX::TestExecution::DisableVerifyExceptions dve;
  4374. for (unsigned i = 0; i < count; ++i) {
  4375. STertiaryFPOp *p = &pPrimitives[i];
  4376. float val = (*Validation_Expected)[i % Validation_Expected->size()];
  4377. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output1 = "
  4378. L"%6.8f, expected = %6.8f",
  4379. i, p->input1, p->input2, p->input3, p->output, val);
  4380. VerifyOutputWithExpectedValueFloat(p->output, val, Validation_Type,
  4381. Validation_Tolerance);
  4382. }
  4383. }
  4384. TEST_F(ExecutionTest, UnaryHalfOpTest) {
  4385. WEX::TestExecution::SetVerifyOutput verifySettings(
  4386. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4387. CComPtr<IStream> pStream;
  4388. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4389. CComPtr<ID3D12Device> pDevice;
  4390. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4391. return;
  4392. }
  4393. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4394. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4395. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4396. return;
  4397. }
  4398. // Read data from the table
  4399. int tableSize = sizeof(UnaryHalfOpParameters) / sizeof(TableParameter);
  4400. TableParameterHandler handler(UnaryHalfOpParameters, tableSize);
  4401. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4402. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4403. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4404. unsigned int WarpVersion = handler.GetTableParamByName(L"Warp.Version")->m_uint;
  4405. if (GetTestParamUseWARP(true) && !IsValidWarpDllVersion(WarpVersion)) {
  4406. return;
  4407. }
  4408. std::vector<uint16_t> *Validation_Input =
  4409. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4410. std::vector<uint16_t> *Validation_Expected =
  4411. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4412. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4413. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4414. size_t count = Validation_Input->size();
  4415. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4416. pDevice, m_support, pStream, "UnaryFPOp",
  4417. // this callbacked is called when the test
  4418. // is creating the resource to run the test
  4419. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4420. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryFPOp"));
  4421. size_t size = sizeof(SUnaryHalfOp) * count;
  4422. Data.resize(size);
  4423. SUnaryHalfOp *pPrimitives = (SUnaryHalfOp *)Data.data();
  4424. for (size_t i = 0; i < count; ++i) {
  4425. SUnaryHalfOp *p = &pPrimitives[i];
  4426. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4427. }
  4428. // use shader from data table
  4429. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4430. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4431. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4432. });
  4433. MappedData data;
  4434. test->Test->GetReadBackData("SUnaryFPOp", &data);
  4435. SUnaryHalfOp *pPrimitives = (SUnaryHalfOp*)data.data();
  4436. WEX::TestExecution::DisableVerifyExceptions dve;
  4437. for (unsigned i = 0; i < count; ++i) {
  4438. SUnaryHalfOp *p = &pPrimitives[i];
  4439. uint16_t expected = (*Validation_Expected)[i % Validation_Input->size()];
  4440. LogCommentFmt(L"element #%u, input = %6.8f(0x%04x), output = "
  4441. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4442. i, ConvertFloat16ToFloat32(p->input), p->input,
  4443. ConvertFloat16ToFloat32(p->output), p->output,
  4444. ConvertFloat16ToFloat32(expected), expected);
  4445. VerifyOutputWithExpectedValueHalf(p->output, expected, Validation_Type, Validation_Tolerance);
  4446. }
  4447. }
  4448. TEST_F(ExecutionTest, BinaryHalfOpTest) {
  4449. WEX::TestExecution::SetVerifyOutput verifySettings(
  4450. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4451. CComPtr<IStream> pStream;
  4452. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4453. CComPtr<ID3D12Device> pDevice;
  4454. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4455. return;
  4456. }
  4457. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4458. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4459. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4460. return;
  4461. }
  4462. // Read data from the table
  4463. int tableSize = sizeof(BinaryHalfOpParameters) / sizeof(TableParameter);
  4464. TableParameterHandler handler(BinaryHalfOpParameters, tableSize);
  4465. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4466. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4467. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4468. std::vector<uint16_t> *Validation_Input1 =
  4469. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4470. std::vector<uint16_t> *Validation_Input2 =
  4471. &(handler.GetTableParamByName(L"Validation.Input2")->m_halfTable);
  4472. std::vector<uint16_t> *Validation_Expected1 =
  4473. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4474. std::vector<uint16_t> *Validation_Expected2 =
  4475. &(handler.GetTableParamByName(L"Validation.Expected2")->m_halfTable);
  4476. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4477. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4478. size_t count = Validation_Input1->size();
  4479. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4480. pDevice, m_support, pStream, "BinaryFPOp",
  4481. // this callbacked is called when the test
  4482. // is creating the resource to run the test
  4483. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4484. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  4485. size_t size = sizeof(SBinaryHalfOp) * count;
  4486. Data.resize(size);
  4487. SBinaryHalfOp *pPrimitives = (SBinaryHalfOp *)Data.data();
  4488. for (size_t i = 0; i < count; ++i) {
  4489. SBinaryHalfOp *p = &pPrimitives[i];
  4490. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4491. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4492. }
  4493. // use shader from data table
  4494. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4495. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4496. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4497. });
  4498. MappedData data;
  4499. test->Test->GetReadBackData("SBinaryFPOp", &data);
  4500. SBinaryHalfOp *pPrimitives = (SBinaryHalfOp *)data.data();
  4501. WEX::TestExecution::DisableVerifyExceptions dve;
  4502. unsigned numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4503. if (numExpected == 2) {
  4504. for (unsigned i = 0; i < count; ++i) {
  4505. SBinaryHalfOp *p = &pPrimitives[i];
  4506. uint16_t expected1 = (*Validation_Expected1)[i % Validation_Input1->size()];
  4507. uint16_t expected2 = (*Validation_Expected2)[i % Validation_Input2->size()];
  4508. LogCommentFmt(L"element #%u, input1 = %6.8f(0x%04x), input2 = %6.8f(0x%04x), output1 = "
  4509. L"%6.8f(0x%04x), expected1 = %6.8f(0x%04x), output2 = %6.8f(0x%04x), expected2 = %6.8f(0x%04x)",
  4510. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4511. ConvertFloat16ToFloat32(p->input2), p->input2,
  4512. ConvertFloat16ToFloat32(p->output1), p->output1,
  4513. ConvertFloat16ToFloat32(p->output2), p->output2,
  4514. ConvertFloat16ToFloat32(expected1), expected1,
  4515. ConvertFloat16ToFloat32(expected2), expected2);
  4516. VerifyOutputWithExpectedValueHalf(p->output1, expected1, Validation_Type, Validation_Tolerance);
  4517. VerifyOutputWithExpectedValueHalf(p->output2, expected2, Validation_Type, Validation_Tolerance);
  4518. }
  4519. }
  4520. else if (numExpected == 1) {
  4521. for (unsigned i = 0; i < count; ++i) {
  4522. uint16_t expected = (*Validation_Expected1)[i % Validation_Input1->size()];
  4523. SBinaryHalfOp *p = &pPrimitives[i];
  4524. LogCommentFmt(L"element #%u, input = %6.8f(0x%04x), output = "
  4525. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4526. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4527. ConvertFloat16ToFloat32(p->output1), p->output1,
  4528. ConvertFloat16ToFloat32(expected), expected);
  4529. VerifyOutputWithExpectedValueHalf(p->output1, expected, Validation_Type, Validation_Tolerance);
  4530. }
  4531. }
  4532. else {
  4533. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4534. }
  4535. }
  4536. TEST_F(ExecutionTest, TertiaryHalfOpTest) {
  4537. WEX::TestExecution::SetVerifyOutput verifySettings(
  4538. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4539. CComPtr<IStream> pStream;
  4540. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4541. CComPtr<ID3D12Device> pDevice;
  4542. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4543. return;
  4544. }
  4545. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4546. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4547. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4548. return;
  4549. }
  4550. // Read data from the table
  4551. int tableSize = sizeof(TertiaryHalfOpParameters) / sizeof(TableParameter);
  4552. TableParameterHandler handler(TertiaryHalfOpParameters, tableSize);
  4553. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4554. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4555. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4556. std::vector<uint16_t> *Validation_Input1 =
  4557. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4558. std::vector<uint16_t> *Validation_Input2 =
  4559. &(handler.GetTableParamByName(L"Validation.Input2")->m_halfTable);
  4560. std::vector<uint16_t> *Validation_Input3 =
  4561. &(handler.GetTableParamByName(L"Validation.Input3")->m_halfTable);
  4562. std::vector<uint16_t> *Validation_Expected =
  4563. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4564. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4565. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4566. size_t count = Validation_Input1->size();
  4567. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4568. pDevice, m_support, pStream, "TertiaryFPOp",
  4569. // this callbacked is called when the test
  4570. // is creating the resource to run the test
  4571. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4572. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  4573. size_t size = sizeof(STertiaryHalfOp) * count;
  4574. Data.resize(size);
  4575. STertiaryHalfOp *pPrimitives = (STertiaryHalfOp *)Data.data();
  4576. for (size_t i = 0; i < count; ++i) {
  4577. STertiaryHalfOp *p = &pPrimitives[i];
  4578. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4579. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4580. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4581. }
  4582. // use shader from data table
  4583. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4584. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4585. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4586. });
  4587. MappedData data;
  4588. test->Test->GetReadBackData("STertiaryFPOp", &data);
  4589. STertiaryHalfOp *pPrimitives = (STertiaryHalfOp *)data.data();
  4590. WEX::TestExecution::DisableVerifyExceptions dve;
  4591. for (unsigned i = 0; i < count; ++i) {
  4592. STertiaryHalfOp *p = &pPrimitives[i];
  4593. uint16_t expected = (*Validation_Expected)[i % Validation_Expected->size()];
  4594. LogCommentFmt(L"element #%u, input1 = %6.8f(0x%04x), input2 = %6.8f(0x%04x), input3 = %6.8f(0x%04x), output = "
  4595. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4596. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4597. ConvertFloat16ToFloat32(p->input2), p->input2,
  4598. ConvertFloat16ToFloat32(p->input3), p->input3,
  4599. ConvertFloat16ToFloat32(p->output), p->output,
  4600. ConvertFloat16ToFloat32(expected), expected);
  4601. VerifyOutputWithExpectedValueHalf(p->output, expected, Validation_Type, Validation_Tolerance);
  4602. }
  4603. }
  4604. TEST_F(ExecutionTest, UnaryIntOpTest) {
  4605. WEX::TestExecution::SetVerifyOutput verifySettings(
  4606. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4607. CComPtr<IStream> pStream;
  4608. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4609. CComPtr<ID3D12Device> pDevice;
  4610. if (!CreateDevice(&pDevice)) {
  4611. return;
  4612. }
  4613. // Read data from the table
  4614. int tableSize = sizeof(UnaryIntOpParameters) / sizeof(TableParameter);
  4615. TableParameterHandler handler(UnaryIntOpParameters, tableSize);
  4616. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4617. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4618. std::vector<int> *Validation_Input =
  4619. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4620. std::vector<int> *Validation_Expected =
  4621. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4622. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4623. size_t count = Validation_Input->size();
  4624. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4625. pDevice, m_support, pStream, "UnaryIntOp",
  4626. // this callbacked is called when the test
  4627. // is creating the resource to run the test
  4628. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4629. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryIntOp"));
  4630. size_t size = sizeof(SUnaryIntOp) * count;
  4631. Data.resize(size);
  4632. SUnaryIntOp *pPrimitives = (SUnaryIntOp *)Data.data();
  4633. for (size_t i = 0; i < count; ++i) {
  4634. SUnaryIntOp *p = &pPrimitives[i];
  4635. int val = (*Validation_Input)[i % Validation_Input->size()];
  4636. p->input = val;
  4637. }
  4638. // use shader data table
  4639. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4640. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4641. });
  4642. MappedData data;
  4643. test->Test->GetReadBackData("SUnaryIntOp", &data);
  4644. SUnaryIntOp *pPrimitives = (SUnaryIntOp *)data.data();
  4645. WEX::TestExecution::DisableVerifyExceptions dve;
  4646. for (unsigned i = 0; i < count; ++i) {
  4647. SUnaryIntOp *p = &pPrimitives[i];
  4648. int val = (*Validation_Expected)[i % Validation_Expected->size()];
  4649. LogCommentFmt(L"element #%u, input = %11i(0x%08x), output = %11i(0x%08x), "
  4650. L"expected = %11i(0x%08x)",
  4651. i, p->input, p->input, p->output, p->output, val, val);
  4652. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4653. }
  4654. }
  4655. TEST_F(ExecutionTest, UnaryUintOpTest) {
  4656. WEX::TestExecution::SetVerifyOutput verifySettings(
  4657. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4658. CComPtr<IStream> pStream;
  4659. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4660. CComPtr<ID3D12Device> pDevice;
  4661. if (!CreateDevice(&pDevice)) {
  4662. return;
  4663. }
  4664. // Read data from the table
  4665. int tableSize = sizeof(UnaryUintOpParameters) / sizeof(TableParameter);
  4666. TableParameterHandler handler(UnaryUintOpParameters, tableSize);
  4667. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4668. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4669. std::vector<unsigned int> *Validation_Input =
  4670. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4671. std::vector<unsigned int> *Validation_Expected =
  4672. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4673. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4674. size_t count = Validation_Input->size();
  4675. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4676. pDevice, m_support, pStream, "UnaryUintOp",
  4677. // this callbacked is called when the test
  4678. // is creating the resource to run the test
  4679. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4680. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryUintOp"));
  4681. size_t size = sizeof(SUnaryUintOp) * count;
  4682. Data.resize(size);
  4683. SUnaryUintOp *pPrimitives = (SUnaryUintOp *)Data.data();
  4684. for (size_t i = 0; i < count; ++i) {
  4685. SUnaryUintOp *p = &pPrimitives[i];
  4686. unsigned int val = (*Validation_Input)[i % Validation_Input->size()];
  4687. p->input = val;
  4688. }
  4689. // use shader data table
  4690. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4691. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4692. });
  4693. MappedData data;
  4694. test->Test->GetReadBackData("SUnaryUintOp", &data);
  4695. SUnaryUintOp *pPrimitives = (SUnaryUintOp *)data.data();
  4696. WEX::TestExecution::DisableVerifyExceptions dve;
  4697. for (unsigned i = 0; i < count; ++i) {
  4698. SUnaryUintOp *p = &pPrimitives[i];
  4699. unsigned int val = (*Validation_Expected)[i % Validation_Expected->size()];
  4700. LogCommentFmt(L"element #%u, input = %11u(0x%08x), output = %11u(0x%08x), "
  4701. L"expected = %11u(0x%08x)",
  4702. i, p->input, p->input, p->output, p->output, val, val);
  4703. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4704. }
  4705. }
  4706. TEST_F(ExecutionTest, BinaryIntOpTest) {
  4707. WEX::TestExecution::SetVerifyOutput verifySettings(
  4708. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4709. CComPtr<IStream> pStream;
  4710. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4711. CComPtr<ID3D12Device> pDevice;
  4712. if (!CreateDevice(&pDevice)) {
  4713. return;
  4714. }
  4715. // Read data from the table
  4716. size_t tableSize = sizeof(BinaryIntOpParameters) / sizeof(TableParameter);
  4717. TableParameterHandler handler(BinaryIntOpParameters, tableSize);
  4718. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4719. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4720. std::vector<int> *Validation_Input1 =
  4721. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4722. std::vector<int> *Validation_Input2 =
  4723. &handler.GetTableParamByName(L"Validation.Input2")->m_int32Table;
  4724. std::vector<int> *Validation_Expected1 =
  4725. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4726. std::vector<int> *Validation_Expected2 =
  4727. &handler.GetTableParamByName(L"Validation.Expected2")->m_int32Table;
  4728. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4729. size_t count = Validation_Input1->size();
  4730. size_t numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4731. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4732. pDevice, m_support, pStream, "BinaryIntOp",
  4733. // this callbacked is called when the test
  4734. // is creating the resource to run the test
  4735. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4736. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryIntOp"));
  4737. size_t size = sizeof(SBinaryIntOp) * count;
  4738. Data.resize(size);
  4739. SBinaryIntOp *pPrimitives = (SBinaryIntOp *)Data.data();
  4740. for (size_t i = 0; i < count; ++i) {
  4741. SBinaryIntOp *p = &pPrimitives[i];
  4742. int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4743. int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4744. p->input1 = val1;
  4745. p->input2 = val2;
  4746. }
  4747. // use shader from data table
  4748. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4749. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4750. });
  4751. MappedData data;
  4752. test->Test->GetReadBackData("SBinaryIntOp", &data);
  4753. SBinaryIntOp *pPrimitives = (SBinaryIntOp *)data.data();
  4754. WEX::TestExecution::DisableVerifyExceptions dve;
  4755. if (numExpected == 2) {
  4756. for (unsigned i = 0; i < count; ++i) {
  4757. SBinaryIntOp *p = &pPrimitives[i];
  4758. int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4759. int val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4760. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4761. L"%11i(0x%08x), output1 = "
  4762. L"%11i(0x%08x), expected1 = %11i(0x%08x), output2 = "
  4763. L"%11i(0x%08x), expected2 = %11i(0x%08x)",
  4764. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  4765. p->output1, val1, val1, p->output2, p->output2, val2,
  4766. val2);
  4767. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4768. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  4769. }
  4770. }
  4771. else if (numExpected == 1) {
  4772. for (unsigned i = 0; i < count; ++i) {
  4773. SBinaryIntOp *p = &pPrimitives[i];
  4774. int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4775. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4776. L"%11i(0x%08x), output = "
  4777. L"%11i(0x%08x), expected = %11i(0x%08x)", i,
  4778. p->input1, p->input1, p->input2, p->input2,
  4779. p->output1, p->output1, val1, val1);
  4780. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4781. }
  4782. }
  4783. else {
  4784. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4785. }
  4786. }
  4787. TEST_F(ExecutionTest, TertiaryIntOpTest) {
  4788. WEX::TestExecution::SetVerifyOutput verifySettings(
  4789. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4790. CComPtr<IStream> pStream;
  4791. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4792. CComPtr<ID3D12Device> pDevice;
  4793. if (!CreateDevice(&pDevice)) {
  4794. return;
  4795. }
  4796. // Read data from the table
  4797. size_t tableSize = sizeof(TertiaryIntOpParameters) / sizeof(TableParameter);
  4798. TableParameterHandler handler(TertiaryIntOpParameters, tableSize);
  4799. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4800. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4801. std::vector<int> *Validation_Input1 =
  4802. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4803. std::vector<int> *Validation_Input2 =
  4804. &handler.GetTableParamByName(L"Validation.Input2")->m_int32Table;
  4805. std::vector<int> *Validation_Input3 =
  4806. &handler.GetTableParamByName(L"Validation.Input3")->m_int32Table;
  4807. std::vector<int> *Validation_Expected =
  4808. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4809. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4810. size_t count = Validation_Input1->size();
  4811. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4812. pDevice, m_support, pStream, "TertiaryIntOp",
  4813. // this callbacked is called when the test
  4814. // is creating the resource to run the test
  4815. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4816. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryIntOp"));
  4817. size_t size = sizeof(STertiaryIntOp) * count;
  4818. Data.resize(size);
  4819. STertiaryIntOp *pPrimitives = (STertiaryIntOp *)Data.data();
  4820. for (size_t i = 0; i < count; ++i) {
  4821. STertiaryIntOp *p = &pPrimitives[i];
  4822. int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4823. int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4824. int val3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4825. p->input1 = val1;
  4826. p->input2 = val2;
  4827. p->input3 = val3;
  4828. }
  4829. // use shader from data table
  4830. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4831. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4832. });
  4833. MappedData data;
  4834. test->Test->GetReadBackData("STertiaryIntOp", &data);
  4835. STertiaryIntOp *pPrimitives = (STertiaryIntOp *)data.data();
  4836. WEX::TestExecution::DisableVerifyExceptions dve;
  4837. for (unsigned i = 0; i < count; ++i) {
  4838. STertiaryIntOp *p = &pPrimitives[i];
  4839. int val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  4840. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4841. L"%11i(0x%08x), input3= %11i(0x%08x), output = "
  4842. L"%11i(0x%08x), expected = %11i(0x%08x)",
  4843. i, p->input1, p->input1, p->input2, p->input2,
  4844. p->input3, p->input3, p->output, p->output, val1,
  4845. val1);
  4846. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  4847. }
  4848. }
  4849. TEST_F(ExecutionTest, BinaryUintOpTest) {
  4850. WEX::TestExecution::SetVerifyOutput verifySettings(
  4851. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4852. CComPtr<IStream> pStream;
  4853. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4854. CComPtr<ID3D12Device> pDevice;
  4855. if (!CreateDevice(&pDevice)) {
  4856. return;
  4857. }
  4858. // Read data from the table
  4859. size_t tableSize = sizeof(BinaryUintOpParameters) / sizeof(TableParameter);
  4860. TableParameterHandler handler(BinaryUintOpParameters, tableSize);
  4861. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4862. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4863. std::vector<unsigned int> *Validation_Input1 =
  4864. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4865. std::vector<unsigned int> *Validation_Input2 =
  4866. &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  4867. std::vector<unsigned int> *Validation_Expected1 =
  4868. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4869. std::vector<unsigned int> *Validation_Expected2 =
  4870. &handler.GetTableParamByName(L"Validation.Expected2")->m_uint32Table;
  4871. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4872. size_t count = Validation_Input1->size();
  4873. int numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4874. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4875. pDevice, m_support, pStream, "BinaryUintOp",
  4876. // this callbacked is called when the test
  4877. // is creating the resource to run the test
  4878. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4879. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryUintOp"));
  4880. size_t size = sizeof(SBinaryUintOp) * count;
  4881. Data.resize(size);
  4882. SBinaryUintOp *pPrimitives = (SBinaryUintOp *)Data.data();
  4883. for (size_t i = 0; i < count; ++i) {
  4884. SBinaryUintOp *p = &pPrimitives[i];
  4885. unsigned int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4886. unsigned int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4887. p->input1 = val1;
  4888. p->input2 = val2;
  4889. }
  4890. // use shader from data table
  4891. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4892. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4893. });
  4894. MappedData data;
  4895. test->Test->GetReadBackData("SBinaryUintOp", &data);
  4896. SBinaryUintOp *pPrimitives = (SBinaryUintOp *)data.data();
  4897. WEX::TestExecution::DisableVerifyExceptions dve;
  4898. if (numExpected == 2) {
  4899. for (unsigned i = 0; i < count; ++i) {
  4900. SBinaryUintOp *p = &pPrimitives[i];
  4901. unsigned int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4902. unsigned int val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4903. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4904. L"%11u(0x%08x), output1 = "
  4905. L"%11u(0x%08x), expected1 = %11u(0x%08x), output2 = "
  4906. L"%11u(0x%08x), expected2 = %11u(0x%08x)",
  4907. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  4908. p->output1, val1, val1, p->output2, p->output2, val2,
  4909. val2);
  4910. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4911. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  4912. }
  4913. }
  4914. else if (numExpected == 1) {
  4915. for (unsigned i = 0; i < count; ++i) {
  4916. SBinaryUintOp *p = &pPrimitives[i];
  4917. unsigned int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4918. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4919. L"%11u(0x%08x), output = "
  4920. L"%11u(0x%08x), expected = %11u(0x%08x)", i,
  4921. p->input1, p->input1, p->input2, p->input2,
  4922. p->output1, p->output1, val1, val1);
  4923. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4924. }
  4925. }
  4926. else {
  4927. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4928. }
  4929. }
  4930. TEST_F(ExecutionTest, TertiaryUintOpTest) {
  4931. WEX::TestExecution::SetVerifyOutput verifySettings(
  4932. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4933. CComPtr<IStream> pStream;
  4934. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4935. CComPtr<ID3D12Device> pDevice;
  4936. if (!CreateDevice(&pDevice)) {
  4937. return;
  4938. }
  4939. // Read data from the table
  4940. size_t tableSize = sizeof(TertiaryUintOpParameters) / sizeof(TableParameter);
  4941. TableParameterHandler handler(TertiaryUintOpParameters, tableSize);
  4942. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4943. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4944. std::vector<unsigned int> *Validation_Input1 =
  4945. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4946. std::vector<unsigned int> *Validation_Input2 =
  4947. &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  4948. std::vector<unsigned int> *Validation_Input3 =
  4949. &handler.GetTableParamByName(L"Validation.Input3")->m_uint32Table;
  4950. std::vector<unsigned int> *Validation_Expected =
  4951. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4952. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4953. size_t count = Validation_Input1->size();
  4954. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4955. pDevice, m_support, pStream, "TertiaryUintOp",
  4956. // this callbacked is called when the test
  4957. // is creating the resource to run the test
  4958. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4959. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryUintOp"));
  4960. size_t size = sizeof(STertiaryUintOp) * count;
  4961. Data.resize(size);
  4962. STertiaryUintOp *pPrimitives = (STertiaryUintOp *)Data.data();
  4963. for (size_t i = 0; i < count; ++i) {
  4964. STertiaryUintOp *p = &pPrimitives[i];
  4965. unsigned int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4966. unsigned int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4967. unsigned int val3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4968. p->input1 = val1;
  4969. p->input2 = val2;
  4970. p->input3 = val3;
  4971. }
  4972. // use shader from data table
  4973. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4974. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4975. });
  4976. MappedData data;
  4977. test->Test->GetReadBackData("STertiaryUintOp", &data);
  4978. STertiaryUintOp *pPrimitives = (STertiaryUintOp *)data.data();
  4979. WEX::TestExecution::DisableVerifyExceptions dve;
  4980. for (unsigned i = 0; i < count; ++i) {
  4981. STertiaryUintOp *p = &pPrimitives[i];
  4982. unsigned int val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  4983. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4984. L"%11u(0x%08x), input3 = %11u(0x%08x), output = "
  4985. L"%11u(0x%08x), expected = %11u(0x%08x)", i,
  4986. p->input1, p->input1, p->input2, p->input2, p->input3, p->input3,
  4987. p->output, p->output, val1, val1);
  4988. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  4989. }
  4990. }
  4991. // 16 bit integer type tests
  4992. TEST_F(ExecutionTest, UnaryInt16OpTest) {
  4993. WEX::TestExecution::SetVerifyOutput verifySettings(
  4994. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4995. CComPtr<IStream> pStream;
  4996. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4997. CComPtr<ID3D12Device> pDevice;
  4998. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4999. return;
  5000. }
  5001. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5002. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5003. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5004. return;
  5005. }
  5006. // Read data from the table
  5007. int tableSize = sizeof(UnaryInt16OpParameters) / sizeof(TableParameter);
  5008. TableParameterHandler handler(UnaryInt16OpParameters, tableSize);
  5009. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5010. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5011. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5012. std::vector<short> *Validation_Input =
  5013. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  5014. std::vector<short> *Validation_Expected =
  5015. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  5016. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5017. size_t count = Validation_Input->size();
  5018. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5019. pDevice, m_support, pStream, "UnaryIntOp",
  5020. // this callbacked is called when the test
  5021. // is creating the resource to run the test
  5022. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5023. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryIntOp"));
  5024. size_t size = sizeof(SUnaryInt16Op) * count;
  5025. Data.resize(size);
  5026. SUnaryInt16Op *pPrimitives = (SUnaryInt16Op *)Data.data();
  5027. for (size_t i = 0; i < count; ++i) {
  5028. SUnaryInt16Op *p = &pPrimitives[i];
  5029. p->input = (*Validation_Input)[i % Validation_Input->size()];
  5030. }
  5031. // use shader data table
  5032. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5033. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5034. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5035. });
  5036. MappedData data;
  5037. test->Test->GetReadBackData("SUnaryIntOp", &data);
  5038. SUnaryInt16Op *pPrimitives = (SUnaryInt16Op *)data.data();
  5039. WEX::TestExecution::DisableVerifyExceptions dve;
  5040. for (unsigned i = 0; i < count; ++i) {
  5041. SUnaryInt16Op *p = &pPrimitives[i];
  5042. short val = (*Validation_Expected)[i % Validation_Expected->size()];
  5043. LogCommentFmt(L"element #%u, input = %5hi(0x%08x), output = %5hi(0x%08x), "
  5044. L"expected = %5hi(0x%08x)",
  5045. i, p->input, p->input, p->output, p->output, val, val);
  5046. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  5047. }
  5048. }
  5049. TEST_F(ExecutionTest, UnaryUint16OpTest) {
  5050. WEX::TestExecution::SetVerifyOutput verifySettings(
  5051. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5052. CComPtr<IStream> pStream;
  5053. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5054. CComPtr<ID3D12Device> pDevice;
  5055. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5056. return;
  5057. }
  5058. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5059. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5060. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5061. return;
  5062. }
  5063. // Read data from the table
  5064. int tableSize = sizeof(UnaryUint16OpParameters) / sizeof(TableParameter);
  5065. TableParameterHandler handler(UnaryUint16OpParameters, tableSize);
  5066. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5067. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5068. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5069. std::vector<unsigned short> *Validation_Input =
  5070. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5071. std::vector<unsigned short> *Validation_Expected =
  5072. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5073. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5074. size_t count = Validation_Input->size();
  5075. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5076. pDevice, m_support, pStream, "UnaryUintOp",
  5077. // this callbacked is called when the test
  5078. // is creating the resource to run the test
  5079. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5080. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryUintOp"));
  5081. size_t size = sizeof(SUnaryUint16Op) * count;
  5082. Data.resize(size);
  5083. SUnaryUint16Op *pPrimitives = (SUnaryUint16Op *)Data.data();
  5084. for (size_t i = 0; i < count; ++i) {
  5085. SUnaryUint16Op *p = &pPrimitives[i];
  5086. p->input = (*Validation_Input)[i % Validation_Input->size()];
  5087. }
  5088. // use shader data table
  5089. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5090. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5091. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5092. });
  5093. MappedData data;
  5094. test->Test->GetReadBackData("SUnaryUintOp", &data);
  5095. SUnaryUint16Op *pPrimitives = (SUnaryUint16Op *)data.data();
  5096. WEX::TestExecution::DisableVerifyExceptions dve;
  5097. for (unsigned i = 0; i < count; ++i) {
  5098. SUnaryUint16Op *p = &pPrimitives[i];
  5099. unsigned short val = (*Validation_Expected)[i % Validation_Expected->size()];
  5100. LogCommentFmt(L"element #%u, input = %5hu(0x%08x), output = %5hu(0x%08x), "
  5101. L"expected = %5hu(0x%08x)",
  5102. i, p->input, p->input, p->output, p->output, val, val);
  5103. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  5104. }
  5105. }
  5106. TEST_F(ExecutionTest, BinaryInt16OpTest) {
  5107. WEX::TestExecution::SetVerifyOutput verifySettings(
  5108. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5109. CComPtr<IStream> pStream;
  5110. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5111. CComPtr<ID3D12Device> pDevice;
  5112. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5113. return;
  5114. }
  5115. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5116. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5117. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5118. return;
  5119. }
  5120. // Read data from the table
  5121. size_t tableSize = sizeof(BinaryInt16OpParameters) / sizeof(TableParameter);
  5122. TableParameterHandler handler(BinaryInt16OpParameters, tableSize);
  5123. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5124. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5125. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5126. std::vector<short> *Validation_Input1 =
  5127. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  5128. std::vector<short> *Validation_Input2 =
  5129. &handler.GetTableParamByName(L"Validation.Input2")->m_int16Table;
  5130. std::vector<short> *Validation_Expected1 =
  5131. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  5132. std::vector<short> *Validation_Expected2 =
  5133. &handler.GetTableParamByName(L"Validation.Expected2")->m_int16Table;
  5134. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5135. size_t count = Validation_Input1->size();
  5136. size_t numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  5137. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5138. pDevice, m_support, pStream, "BinaryIntOp",
  5139. // this callbacked is called when the test
  5140. // is creating the resource to run the test
  5141. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5142. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryIntOp"));
  5143. size_t size = sizeof(SBinaryInt16Op) * count;
  5144. Data.resize(size);
  5145. SBinaryInt16Op *pPrimitives = (SBinaryInt16Op *)Data.data();
  5146. for (size_t i = 0; i < count; ++i) {
  5147. SBinaryInt16Op *p = &pPrimitives[i];
  5148. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5149. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5150. }
  5151. // use shader from data table
  5152. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5153. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5154. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5155. });
  5156. MappedData data;
  5157. test->Test->GetReadBackData("SBinaryIntOp", &data);
  5158. SBinaryInt16Op *pPrimitives = (SBinaryInt16Op *)data.data();
  5159. WEX::TestExecution::DisableVerifyExceptions dve;
  5160. if (numExpected == 2) {
  5161. for (unsigned i = 0; i < count; ++i) {
  5162. SBinaryInt16Op *p = &pPrimitives[i];
  5163. short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5164. short val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5165. LogCommentFmt(L"element #%u, input1 = %5hi(0x%08x), input2 = "
  5166. L"%5hi(0x%08x), output1 = "
  5167. L"%5hi(0x%08x), expected1 = %5hi(0x%08x), output2 = "
  5168. L"%5hi(0x%08x), expected2 = %5hi(0x%08x)",
  5169. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  5170. p->output1, val1, val1, p->output2, p->output2, val2,
  5171. val2);
  5172. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5173. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  5174. }
  5175. }
  5176. else if (numExpected == 1) {
  5177. for (unsigned i = 0; i < count; ++i) {
  5178. SBinaryInt16Op *p = &pPrimitives[i];
  5179. short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5180. LogCommentFmt(L"element #%u, input1 = %5hi(0x%08x), input2 = "
  5181. L"%5hi(0x%08x), output = "
  5182. L"%5hi(0x%08x), expected = %5hi(0x%08x)", i,
  5183. p->input1, p->input1, p->input2, p->input2,
  5184. p->output1, p->output1, val1, val1);
  5185. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5186. }
  5187. }
  5188. else {
  5189. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  5190. }
  5191. }
  5192. TEST_F(ExecutionTest, TertiaryInt16OpTest) {
  5193. WEX::TestExecution::SetVerifyOutput verifySettings(
  5194. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5195. CComPtr<IStream> pStream;
  5196. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5197. CComPtr<ID3D12Device> pDevice;
  5198. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5199. return;
  5200. }
  5201. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5202. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5203. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5204. return;
  5205. }
  5206. // Read data from the table
  5207. size_t tableSize = sizeof(TertiaryInt16OpParameters) / sizeof(TableParameter);
  5208. TableParameterHandler handler(TertiaryInt16OpParameters, tableSize);
  5209. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5210. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5211. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5212. std::vector<short> *Validation_Input1 =
  5213. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  5214. std::vector<short> *Validation_Input2 =
  5215. &handler.GetTableParamByName(L"Validation.Input2")->m_int16Table;
  5216. std::vector<short> *Validation_Input3 =
  5217. &handler.GetTableParamByName(L"Validation.Input3")->m_int16Table;
  5218. std::vector<short> *Validation_Expected =
  5219. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  5220. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5221. size_t count = Validation_Input1->size();
  5222. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5223. pDevice, m_support, pStream, "TertiaryIntOp",
  5224. // this callbacked is called when the test
  5225. // is creating the resource to run the test
  5226. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5227. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryIntOp"));
  5228. size_t size = sizeof(STertiaryInt16Op) * count;
  5229. Data.resize(size);
  5230. STertiaryInt16Op *pPrimitives = (STertiaryInt16Op *)Data.data();
  5231. for (size_t i = 0; i < count; ++i) {
  5232. STertiaryInt16Op *p = &pPrimitives[i];
  5233. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5234. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5235. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5236. }
  5237. // use shader from data table
  5238. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5239. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5240. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5241. });
  5242. MappedData data;
  5243. test->Test->GetReadBackData("STertiaryIntOp", &data);
  5244. STertiaryInt16Op *pPrimitives = (STertiaryInt16Op *)data.data();
  5245. WEX::TestExecution::DisableVerifyExceptions dve;
  5246. for (unsigned i = 0; i < count; ++i) {
  5247. STertiaryInt16Op *p = &pPrimitives[i];
  5248. short val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  5249. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  5250. L"%11i(0x%08x), input3= %11i(0x%08x), output = "
  5251. L"%11i(0x%08x), expected = %11i(0x%08x)",
  5252. i, p->input1, p->input1, p->input2, p->input2,
  5253. p->input3, p->input3, p->output, p->output, val1,
  5254. val1);
  5255. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  5256. }
  5257. }
  5258. TEST_F(ExecutionTest, BinaryUint16OpTest) {
  5259. WEX::TestExecution::SetVerifyOutput verifySettings(
  5260. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5261. CComPtr<IStream> pStream;
  5262. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5263. CComPtr<ID3D12Device> pDevice;
  5264. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5265. return;
  5266. }
  5267. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5268. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5269. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5270. return;
  5271. }
  5272. // Read data from the table
  5273. size_t tableSize = sizeof(BinaryUint16OpParameters) / sizeof(TableParameter);
  5274. TableParameterHandler handler(BinaryUint16OpParameters, tableSize);
  5275. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5276. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5277. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5278. std::vector<unsigned short> *Validation_Input1 =
  5279. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5280. std::vector<unsigned short> *Validation_Input2 =
  5281. &handler.GetTableParamByName(L"Validation.Input2")->m_uint16Table;
  5282. std::vector<unsigned short> *Validation_Expected1 =
  5283. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5284. std::vector<unsigned short> *Validation_Expected2 =
  5285. &handler.GetTableParamByName(L"Validation.Expected2")->m_uint16Table;
  5286. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5287. size_t count = Validation_Input1->size();
  5288. int numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  5289. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5290. pDevice, m_support, pStream, "BinaryUintOp",
  5291. // this callbacked is called when the test
  5292. // is creating the resource to run the test
  5293. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5294. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryUintOp"));
  5295. size_t size = sizeof(SBinaryUint16Op) * count;
  5296. Data.resize(size);
  5297. SBinaryUint16Op *pPrimitives = (SBinaryUint16Op *)Data.data();
  5298. for (size_t i = 0; i < count; ++i) {
  5299. SBinaryUint16Op *p = &pPrimitives[i];
  5300. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5301. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5302. }
  5303. // use shader from data table
  5304. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5305. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5306. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5307. });
  5308. MappedData data;
  5309. test->Test->GetReadBackData("SBinaryUintOp", &data);
  5310. SBinaryUint16Op *pPrimitives = (SBinaryUint16Op *)data.data();
  5311. WEX::TestExecution::DisableVerifyExceptions dve;
  5312. if (numExpected == 2) {
  5313. for (unsigned i = 0; i < count; ++i) {
  5314. SBinaryUint16Op *p = &pPrimitives[i];
  5315. unsigned short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5316. unsigned short val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5317. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5318. L"%5hu(0x%08x), output1 = "
  5319. L"%5hu(0x%08x), expected1 = %5hu(0x%08x), output2 = "
  5320. L"%5hu(0x%08x), expected2 = %5hu(0x%08x)",
  5321. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  5322. p->output1, val1, val1, p->output2, p->output2, val2,
  5323. val2);
  5324. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5325. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  5326. }
  5327. }
  5328. else if (numExpected == 1) {
  5329. for (unsigned i = 0; i < count; ++i) {
  5330. SBinaryUint16Op *p = &pPrimitives[i];
  5331. unsigned short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5332. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5333. L"%5hu(0x%08x), output = "
  5334. L"%5hu(0x%08x), expected = %5hu(0x%08x)", i,
  5335. p->input1, p->input1, p->input2, p->input2,
  5336. p->output1, p->output1, val1, val1);
  5337. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5338. }
  5339. }
  5340. else {
  5341. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  5342. }
  5343. }
  5344. TEST_F(ExecutionTest, TertiaryUint16OpTest) {
  5345. WEX::TestExecution::SetVerifyOutput verifySettings(
  5346. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5347. CComPtr<IStream> pStream;
  5348. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5349. CComPtr<ID3D12Device> pDevice;
  5350. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5351. return;
  5352. }
  5353. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5354. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5355. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5356. return;
  5357. }
  5358. // Read data from the table
  5359. size_t tableSize = sizeof(TertiaryUint16OpParameters) / sizeof(TableParameter);
  5360. TableParameterHandler handler(TertiaryUint16OpParameters, tableSize);
  5361. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5362. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5363. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5364. std::vector<unsigned short> *Validation_Input1 =
  5365. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5366. std::vector<unsigned short> *Validation_Input2 =
  5367. &handler.GetTableParamByName(L"Validation.Input2")->m_uint16Table;
  5368. std::vector<unsigned short> *Validation_Input3 =
  5369. &handler.GetTableParamByName(L"Validation.Input3")->m_uint16Table;
  5370. std::vector<unsigned short> *Validation_Expected =
  5371. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5372. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5373. size_t count = Validation_Input1->size();
  5374. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5375. pDevice, m_support, pStream, "TertiaryUintOp",
  5376. // this callbacked is called when the test
  5377. // is creating the resource to run the test
  5378. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5379. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryUintOp"));
  5380. size_t size = sizeof(STertiaryUint16Op) * count;
  5381. Data.resize(size);
  5382. STertiaryUint16Op *pPrimitives = (STertiaryUint16Op *)Data.data();
  5383. for (size_t i = 0; i < count; ++i) {
  5384. STertiaryUint16Op *p = &pPrimitives[i];
  5385. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5386. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5387. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5388. }
  5389. // use shader from data table
  5390. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5391. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5392. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5393. });
  5394. MappedData data;
  5395. test->Test->GetReadBackData("STertiaryUintOp", &data);
  5396. STertiaryUint16Op *pPrimitives = (STertiaryUint16Op *)data.data();
  5397. WEX::TestExecution::DisableVerifyExceptions dve;
  5398. for (unsigned i = 0; i < count; ++i) {
  5399. STertiaryUint16Op *p = &pPrimitives[i];
  5400. unsigned short val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  5401. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5402. L"%5hu(0x%08x), input3 = %5hu(0x%08x), output = "
  5403. L"%5hu(0x%08x), expected = %5hu(0x%08x)", i,
  5404. p->input1, p->input1, p->input2, p->input2, p->input3, p->input3,
  5405. p->output, p->output, val1, val1);
  5406. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  5407. }
  5408. }
  5409. TEST_F(ExecutionTest, DotTest) {
  5410. WEX::TestExecution::SetVerifyOutput verifySettings(
  5411. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5412. CComPtr<IStream> pStream;
  5413. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5414. CComPtr<ID3D12Device> pDevice;
  5415. if (!CreateDevice(&pDevice)) {
  5416. return;
  5417. }
  5418. int tableSize = sizeof(DotOpParameters) / sizeof(TableParameter);
  5419. TableParameterHandler handler(DotOpParameters, tableSize);
  5420. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5421. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5422. std::vector<WEX::Common::String> *Validation_Input1 =
  5423. &handler.GetTableParamByName(L"Validation.Input1")->m_StringTable;
  5424. std::vector<WEX::Common::String> *Validation_Input2 =
  5425. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5426. std::vector<WEX::Common::String> *Validation_dot2 =
  5427. &handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable;
  5428. std::vector<WEX::Common::String> *Validation_dot3 =
  5429. &handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable;
  5430. std::vector<WEX::Common::String> *Validation_dot4 =
  5431. &handler.GetTableParamByName(L"Validation.Expected3")->m_StringTable;
  5432. PCWSTR Validation_type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5433. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5434. size_t count = Validation_Input1->size();
  5435. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5436. pDevice, m_support, pStream, "DotOp",
  5437. // this callbacked is called when the test
  5438. // is creating the resource to run the test
  5439. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5440. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDotOp"));
  5441. size_t size = sizeof(SDotOp) * count;
  5442. Data.resize(size);
  5443. SDotOp *pPrimitives = (SDotOp*)Data.data();
  5444. for (size_t i = 0; i < count; ++i) {
  5445. SDotOp *p = &pPrimitives[i];
  5446. XMFLOAT4 val1,val2;
  5447. VERIFY_SUCCEEDED(ParseDataToVectorFloat((*Validation_Input1)[i],
  5448. (float *)&val1, 4));
  5449. VERIFY_SUCCEEDED(ParseDataToVectorFloat((*Validation_Input2)[i],
  5450. (float *)&val2, 4));
  5451. p->input1 = val1;
  5452. p->input2 = val2;
  5453. }
  5454. // use shader from data table
  5455. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5456. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5457. });
  5458. MappedData data;
  5459. test->Test->GetReadBackData("SDotOp", &data);
  5460. SDotOp *pPrimitives = (SDotOp*)data.data();
  5461. WEX::TestExecution::DisableVerifyExceptions dve;
  5462. for (size_t i = 0; i < count; ++i) {
  5463. SDotOp *p = &pPrimitives[i];
  5464. float dot2, dot3, dot4;
  5465. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot2)[i], dot2));
  5466. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot3)[i], dot3));
  5467. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot4)[i], dot4));
  5468. LogCommentFmt(
  5469. L"element #%u, input1 = (%f, %f, %f, %f), input2 = (%f, %f, "
  5470. L"%f, %f), \n dot2 = %f, dot2_expected = %f, dot3 = %f, "
  5471. L"dot3_expected = %f, dot4 = %f, dot4_expected = %f",
  5472. i, p->input1.x, p->input1.y, p->input1.z, p->input1.w, p->input2.x,
  5473. p->input2.y, p->input2.z, p->input2.w, p->o_dot2, dot2, p->o_dot3, dot3,
  5474. p->o_dot4, dot4);
  5475. VerifyOutputWithExpectedValueFloat(p->o_dot2, dot2, Validation_type,
  5476. tolerance);
  5477. VerifyOutputWithExpectedValueFloat(p->o_dot3, dot3, Validation_type,
  5478. tolerance);
  5479. VerifyOutputWithExpectedValueFloat(p->o_dot4, dot4, Validation_type,
  5480. tolerance);
  5481. }
  5482. }
  5483. TEST_F(ExecutionTest, Dot2AddHalfTest) {
  5484. WEX::TestExecution::SetVerifyOutput verifySettings(
  5485. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5486. CComPtr<IStream> pStream;
  5487. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5488. CComPtr<ID3D12Device> pDevice;
  5489. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5490. return;
  5491. }
  5492. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5493. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5494. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5495. return;
  5496. }
  5497. int tableSize = sizeof(Dot2AddHalfOpParameters) / sizeof(TableParameter);
  5498. TableParameterHandler handler(Dot2AddHalfOpParameters, tableSize);
  5499. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5500. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5501. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5502. std::vector<WEX::Common::String> *validation_input1 =
  5503. &handler.GetTableParamByName(L"Validation.Input1")->m_StringTable;
  5504. std::vector<WEX::Common::String> *validation_input2 =
  5505. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5506. std::vector<float> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_floatTable;
  5507. std::vector<float> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable;
  5508. PCWSTR Validation_type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5509. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5510. size_t count = validation_input1->size();
  5511. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5512. pDevice, m_support, pStream, "Dot2AddHalfOp",
  5513. // this callback is called when the test
  5514. // is creating the resource to run the test
  5515. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5516. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot2AddHalfOp"));
  5517. size_t size = sizeof(SDot2AddHalfOp) * count;
  5518. Data.resize(size);
  5519. SDot2AddHalfOp *pPrimitives = (SDot2AddHalfOp*)Data.data();
  5520. for (size_t i = 0; i < count; ++i) {
  5521. SDot2AddHalfOp *p = &pPrimitives[i];
  5522. Half2 val1,val2;
  5523. VERIFY_SUCCEEDED(ParseDataToVectorHalf((*validation_input1)[i],
  5524. (uint16_t *)&val1, 2));
  5525. VERIFY_SUCCEEDED(ParseDataToVectorHalf((*validation_input2)[i],
  5526. (uint16_t *)&val2, 2));
  5527. p->input1 = val1;
  5528. p->input2 = val2;
  5529. p->acc = (*validation_acc)[i];
  5530. }
  5531. // use shader from data table
  5532. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5533. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5534. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5535. });
  5536. MappedData data;
  5537. test->Test->GetReadBackData("SDot2AddHalfOp", &data);
  5538. SDot2AddHalfOp *pPrimitives = (SDot2AddHalfOp*)data.data();
  5539. WEX::TestExecution::DisableVerifyExceptions dve;
  5540. for (size_t i = 0; i < count; ++i) {
  5541. SDot2AddHalfOp *p = &pPrimitives[i];
  5542. float expectedResult = (*validation_result)[i];
  5543. float input1x = ConvertFloat16ToFloat32(p->input1.x);
  5544. float input1y = ConvertFloat16ToFloat32(p->input1.y);
  5545. float input2x = ConvertFloat16ToFloat32(p->input2.x);
  5546. float input2y = ConvertFloat16ToFloat32(p->input2.y);
  5547. LogCommentFmt(
  5548. L"element #%u, input1 = (%f, %f), input2 = (%f, %f), acc = %f\n"
  5549. L"result = %f, result_expected = %f",
  5550. i, input1x, input1y, input2x, input2y, p->acc, p->result, expectedResult);
  5551. VerifyOutputWithExpectedValueFloat(p->result, expectedResult, Validation_type, tolerance);
  5552. }
  5553. }
  5554. TEST_F(ExecutionTest, Dot4AddI8PackedTest) {
  5555. WEX::TestExecution::SetVerifyOutput verifySettings(
  5556. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5557. CComPtr<IStream> pStream;
  5558. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5559. CComPtr<ID3D12Device> pDevice;
  5560. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5561. return;
  5562. }
  5563. int tableSize = sizeof(Dot4AddI8PackedOpParameters) / sizeof(TableParameter);
  5564. TableParameterHandler handler(Dot4AddI8PackedOpParameters, tableSize);
  5565. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5566. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5567. std::vector<uint32_t> *validation_input1 = &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5568. std::vector<uint32_t> *validation_input2 = &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  5569. std::vector<int32_t> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_int32Table;
  5570. std::vector<int32_t> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  5571. size_t count = validation_input1->size();
  5572. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5573. pDevice, m_support, pStream, "Dot4AddI8PackedOp",
  5574. // this callback is called when the test
  5575. // is creating the resource to run the test
  5576. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5577. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot4AddI8PackedOp"));
  5578. size_t size = sizeof(SDot4AddI8PackedOp) * count;
  5579. Data.resize(size);
  5580. SDot4AddI8PackedOp *pPrimitives = (SDot4AddI8PackedOp*)Data.data();
  5581. for (size_t i = 0; i < count; ++i) {
  5582. SDot4AddI8PackedOp *p = &pPrimitives[i];
  5583. p->input1 = (*validation_input1)[i];
  5584. p->input2 = (*validation_input2)[i];
  5585. p->acc = (*validation_acc)[i];
  5586. }
  5587. // use shader from data table
  5588. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5589. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5590. });
  5591. MappedData data;
  5592. test->Test->GetReadBackData("SDot4AddI8PackedOp", &data);
  5593. SDot4AddI8PackedOp *pPrimitives = (SDot4AddI8PackedOp*)data.data();
  5594. WEX::TestExecution::DisableVerifyExceptions dve;
  5595. for (size_t i = 0; i < count; ++i) {
  5596. SDot4AddI8PackedOp *p = &pPrimitives[i];
  5597. int32_t expectedResult = (*validation_result)[i];
  5598. LogCommentFmt(
  5599. L"element #%u, input1 = %u, input2 = %u, acc = %d \n"
  5600. L"result = %d, result_expected = %d",
  5601. i, p->input1, p->input2, p->acc, p->result, expectedResult);
  5602. VerifyOutputWithExpectedValueInt(p->result, expectedResult, 0);
  5603. }
  5604. }
  5605. TEST_F(ExecutionTest, Dot4AddU8PackedTest) {
  5606. WEX::TestExecution::SetVerifyOutput verifySettings(
  5607. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5608. CComPtr<IStream> pStream;
  5609. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5610. CComPtr<ID3D12Device> pDevice;
  5611. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5612. return;
  5613. }
  5614. int tableSize = sizeof(Dot4AddU8PackedOpParameters) / sizeof(TableParameter);
  5615. TableParameterHandler handler(Dot4AddU8PackedOpParameters, tableSize);
  5616. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5617. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5618. std::vector<uint32_t> *validation_input1 = &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5619. std::vector<uint32_t> *validation_input2 = &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  5620. std::vector<uint32_t> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_uint32Table;
  5621. std::vector<uint32_t> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  5622. size_t count = validation_input1->size();
  5623. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5624. pDevice, m_support, pStream, "Dot4AddU8PackedOp",
  5625. // this callback is called when the test
  5626. // is creating the resource to run the test
  5627. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5628. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot4AddU8PackedOp"));
  5629. size_t size = sizeof(SDot4AddU8PackedOp) * count;
  5630. Data.resize(size);
  5631. SDot4AddU8PackedOp *pPrimitives = (SDot4AddU8PackedOp*)Data.data();
  5632. for (size_t i = 0; i < count; ++i) {
  5633. SDot4AddU8PackedOp *p = &pPrimitives[i];
  5634. p->input1 = (*validation_input1)[i];
  5635. p->input2 = (*validation_input2)[i];
  5636. p->acc = (*validation_acc)[i];
  5637. }
  5638. // use shader from data table
  5639. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5640. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5641. });
  5642. MappedData data;
  5643. test->Test->GetReadBackData("SDot4AddU8PackedOp", &data);
  5644. SDot4AddU8PackedOp *pPrimitives = (SDot4AddU8PackedOp*)data.data();
  5645. WEX::TestExecution::DisableVerifyExceptions dve;
  5646. for (size_t i = 0; i < count; ++i) {
  5647. SDot4AddU8PackedOp *p = &pPrimitives[i];
  5648. uint32_t expectedResult = (*validation_result)[i];
  5649. LogCommentFmt(
  5650. L"element #%u, input1 = %u, input2 = %u, acc = %u \n"
  5651. L"result = %u, result_expected = %u, ",
  5652. i, p->input1, p->input2, p->acc, p->result, expectedResult);
  5653. VerifyOutputWithExpectedValueUInt(p->result, expectedResult, 0);
  5654. }
  5655. }
  5656. TEST_F(ExecutionTest, Msad4Test) {
  5657. WEX::TestExecution::SetVerifyOutput verifySettings(
  5658. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5659. CComPtr<IStream> pStream;
  5660. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5661. CComPtr<ID3D12Device> pDevice;
  5662. if (!CreateDevice(&pDevice)) {
  5663. return;
  5664. }
  5665. size_t tableSize = sizeof(Msad4OpParameters) / sizeof(TableParameter);
  5666. TableParameterHandler handler(Msad4OpParameters, tableSize);
  5667. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5668. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5669. std::vector<unsigned int> *Validation_Reference =
  5670. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5671. std::vector<WEX::Common::String> *Validation_Source =
  5672. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5673. std::vector<WEX::Common::String> *Validation_Accum =
  5674. &handler.GetTableParamByName(L"Validation.Input3")->m_StringTable;
  5675. std::vector<WEX::Common::String> *Validation_Expected =
  5676. &handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable;
  5677. size_t count = Validation_Expected->size();
  5678. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5679. pDevice, m_support, pStream, "Msad4",
  5680. // this callbacked is called when the test
  5681. // is creating the resource to run the test
  5682. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5683. VERIFY_IS_TRUE(0 == _stricmp(Name, "SMsad4"));
  5684. size_t size = sizeof(SMsad4) * count;
  5685. Data.resize(size);
  5686. SMsad4 *pPrimitives = (SMsad4*)Data.data();
  5687. for (size_t i = 0; i < count; ++i) {
  5688. SMsad4 *p = &pPrimitives[i];
  5689. XMUINT2 src;
  5690. XMUINT4 accum;
  5691. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Source)[i], (unsigned int*)&src, 2));
  5692. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Accum)[i], (unsigned int*)&accum, 4));
  5693. p->ref = (*Validation_Reference)[i];
  5694. p->src = src;
  5695. p->accum = accum;
  5696. }
  5697. // use shader from data table
  5698. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5699. });
  5700. MappedData data;
  5701. test->Test->GetReadBackData("SMsad4", &data);
  5702. SMsad4 *pPrimitives = (SMsad4*)data.data();
  5703. WEX::TestExecution::DisableVerifyExceptions dve;
  5704. for (size_t i = 0; i < count; ++i) {
  5705. SMsad4 *p = &pPrimitives[i];
  5706. XMUINT4 result;
  5707. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Expected)[i],
  5708. (unsigned int *)&result, 4));
  5709. LogCommentFmt(
  5710. L"element #%u, ref = %u(0x%08x), src = %u(0x%08x), %u(0x%08x), "
  5711. L"accum = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x),\n"
  5712. L"result = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x),\n"
  5713. L"expected = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x)", i,
  5714. p->ref, p->ref, p->src.x, p->src.x, p->src.y, p->src.y, p->accum.x,
  5715. p->accum.x, p->accum.y, p->accum.y, p->accum.z, p->accum.z,
  5716. p->accum.w, p->accum.w, p->result.x, p->result.x, p->result.y,
  5717. p->result.y, p->result.z, p->result.z, p->result.w, p->result.w,
  5718. result.x, result.x, result.y, result.y, result.z, result.z,
  5719. result.w, result.w);
  5720. int toleranceInt = (int)tolerance;
  5721. VerifyOutputWithExpectedValueInt(p->result.x, result.x, toleranceInt);
  5722. VerifyOutputWithExpectedValueInt(p->result.y, result.y, toleranceInt);
  5723. VerifyOutputWithExpectedValueInt(p->result.z, result.z, toleranceInt);
  5724. VerifyOutputWithExpectedValueInt(p->result.w, result.w, toleranceInt);
  5725. }
  5726. }
  5727. TEST_F(ExecutionTest, DenormBinaryFloatOpTest) {
  5728. WEX::TestExecution::SetVerifyOutput verifySettings(
  5729. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5730. CComPtr<IStream> pStream;
  5731. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5732. CComPtr<ID3D12Device> pDevice;
  5733. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5734. return;
  5735. }
  5736. // Read data from the table
  5737. int tableSize = sizeof(DenormBinaryFPOpParameters) / sizeof(TableParameter);
  5738. TableParameterHandler handler(DenormBinaryFPOpParameters, tableSize);
  5739. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5740. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5741. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5742. std::vector<WEX::Common::String> *Validation_Input1 =
  5743. &(handler.GetTableParamByName(L"Validation.Input1")->m_StringTable);
  5744. std::vector<WEX::Common::String> *Validation_Input2 =
  5745. &(handler.GetTableParamByName(L"Validation.Input2")->m_StringTable);
  5746. std::vector<WEX::Common::String> *Validation_Expected1 =
  5747. &(handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable);
  5748. // two expected outputs for any mode
  5749. std::vector<WEX::Common::String> *Validation_Expected2 =
  5750. &(handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable);
  5751. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5752. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5753. size_t count = Validation_Input1->size();
  5754. using namespace hlsl::DXIL;
  5755. Float32DenormMode mode = Float32DenormMode::Any;
  5756. if (strcmp(Arguments.m_psz, "-denorm preserve") == 0) {
  5757. mode = Float32DenormMode::Preserve;
  5758. }
  5759. else if (strcmp(Arguments.m_psz, "-denorm ftz") == 0) {
  5760. mode = Float32DenormMode::FTZ;
  5761. }
  5762. if (mode == Float32DenormMode::Any) {
  5763. DXASSERT(Validation_Expected2->size() == Validation_Expected1->size(),
  5764. "must have same number of expected values");
  5765. }
  5766. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5767. pDevice, m_support, pStream, "BinaryFPOp",
  5768. // this callbacked is called when the test
  5769. // is creating the resource to run the test
  5770. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5771. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  5772. size_t size = sizeof(SBinaryFPOp) * count;
  5773. Data.resize(size);
  5774. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)Data.data();
  5775. for (size_t i = 0; i < count; ++i) {
  5776. SBinaryFPOp *p = &pPrimitives[i];
  5777. PCWSTR str1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5778. PCWSTR str2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5779. float val1, val2;
  5780. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5781. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5782. p->input1 = val1;
  5783. p->input2 = val2;
  5784. }
  5785. // use shader from data table
  5786. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5787. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5788. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5789. });
  5790. MappedData data;
  5791. test->Test->GetReadBackData("SBinaryFPOp", &data);
  5792. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)data.data();
  5793. WEX::TestExecution::DisableVerifyExceptions dve;
  5794. for (unsigned i = 0; i < count; ++i) {
  5795. SBinaryFPOp *p = &pPrimitives[i];
  5796. if (mode == Float32DenormMode::Any) {
  5797. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5798. LPCWSTR str2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5799. float val1;
  5800. float val2;
  5801. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5802. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5803. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output = "
  5804. L"%6.8f, expected = %6.8f(%x) or %6.8f(%x)",
  5805. i, p->input1, p->input2, p->output1, val1, *(int *)&val1, val2, *(int *)&val2);
  5806. VERIFY_IS_TRUE(
  5807. CompareOutputWithExpectedValueFloat(
  5808. p->output1, val1, Validation_Type, Validation_Tolerance, mode) ||
  5809. CompareOutputWithExpectedValueFloat(
  5810. p->output1, val2, Validation_Type, Validation_Tolerance, mode));
  5811. }
  5812. else {
  5813. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5814. float val1;
  5815. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5816. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output = "
  5817. L"%6.8f, expected = %6.8f(%a)",
  5818. i, p->input1, p->input2, p->output1, val1, *(int *)&val1);
  5819. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  5820. Validation_Tolerance, mode);
  5821. }
  5822. }
  5823. }
  5824. TEST_F(ExecutionTest, DenormTertiaryFloatOpTest) {
  5825. WEX::TestExecution::SetVerifyOutput verifySettings(
  5826. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5827. CComPtr<IStream> pStream;
  5828. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5829. CComPtr<ID3D12Device> pDevice;
  5830. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5831. return;
  5832. }
  5833. // Read data from the table
  5834. int tableSize = sizeof(DenormTertiaryFPOpParameters) / sizeof(TableParameter);
  5835. TableParameterHandler handler(DenormTertiaryFPOpParameters, tableSize);
  5836. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5837. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5838. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5839. std::vector<WEX::Common::String> *Validation_Input1 =
  5840. &(handler.GetTableParamByName(L"Validation.Input1")->m_StringTable);
  5841. std::vector<WEX::Common::String> *Validation_Input2 =
  5842. &(handler.GetTableParamByName(L"Validation.Input2")->m_StringTable);
  5843. std::vector<WEX::Common::String> *Validation_Input3 =
  5844. &(handler.GetTableParamByName(L"Validation.Input3")->m_StringTable);
  5845. std::vector<WEX::Common::String> *Validation_Expected1 =
  5846. &(handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable);
  5847. // two expected outputs for any mode
  5848. std::vector<WEX::Common::String> *Validation_Expected2 =
  5849. &(handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable);
  5850. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5851. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5852. size_t count = Validation_Input1->size();
  5853. using namespace hlsl::DXIL;
  5854. Float32DenormMode mode = Float32DenormMode::Any;
  5855. if (strcmp(Arguments.m_psz, "-denorm preserve") == 0) {
  5856. mode = Float32DenormMode::Preserve;
  5857. }
  5858. else if (strcmp(Arguments.m_psz, "-denorm ftz") == 0) {
  5859. mode = Float32DenormMode::FTZ;
  5860. }
  5861. if (mode == Float32DenormMode::Any) {
  5862. DXASSERT(Validation_Expected2->size() == Validation_Expected1->size(),
  5863. "must have same number of expected values");
  5864. }
  5865. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5866. pDevice, m_support, pStream, "TertiaryFPOp",
  5867. // this callbacked is called when the test
  5868. // is creating the resource to run the test
  5869. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5870. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  5871. size_t size = sizeof(STertiaryFPOp) * count;
  5872. Data.resize(size);
  5873. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)Data.data();
  5874. for (size_t i = 0; i < count; ++i) {
  5875. STertiaryFPOp *p = &pPrimitives[i];
  5876. PCWSTR str1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5877. PCWSTR str2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5878. PCWSTR str3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5879. float val1, val2, val3;
  5880. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5881. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5882. VERIFY_SUCCEEDED(ParseDataToFloat(str3, val3));
  5883. p->input1 = val1;
  5884. p->input2 = val2;
  5885. p->input3 = val3;
  5886. }
  5887. // use shader from data table
  5888. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5889. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5890. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5891. });
  5892. MappedData data;
  5893. test->Test->GetReadBackData("STertiaryFPOp", &data);
  5894. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)data.data();
  5895. WEX::TestExecution::DisableVerifyExceptions dve;
  5896. for (unsigned i = 0; i < count; ++i) {
  5897. STertiaryFPOp *p = &pPrimitives[i];
  5898. if (mode == Float32DenormMode::Any) {
  5899. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5900. LPCWSTR str2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5901. float val1;
  5902. float val2;
  5903. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5904. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5905. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output = "
  5906. L"%6.8f, expected = %6.8f(%x) or %6.8f(%x)",
  5907. i, p->input1, p->input2, p->input3, p->output, val1, *(int *)&val1, val2, *(int *)&val2);
  5908. VERIFY_IS_TRUE(
  5909. CompareOutputWithExpectedValueFloat(
  5910. p->output, val1, Validation_Type, Validation_Tolerance, mode) ||
  5911. CompareOutputWithExpectedValueFloat(
  5912. p->output, val2, Validation_Type, Validation_Tolerance, mode));
  5913. }
  5914. else {
  5915. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5916. float val1;
  5917. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5918. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output = "
  5919. L"%6.8f, expected = %6.8f(%a)",
  5920. i, p->input1, p->input2, p->input3, p->output, val1, *(int *)&val1);
  5921. VerifyOutputWithExpectedValueFloat(p->output, val1, Validation_Type,
  5922. Validation_Tolerance, mode);
  5923. }
  5924. }
  5925. }
  5926. // Setup for wave intrinsics tests
  5927. enum class ShaderOpKind {
  5928. WaveSum,
  5929. WaveProduct,
  5930. WaveActiveMax,
  5931. WaveActiveMin,
  5932. WaveCountBits,
  5933. WaveActiveAllEqual,
  5934. WaveActiveAnyTrue,
  5935. WaveActiveAllTrue,
  5936. WaveActiveBitOr,
  5937. WaveActiveBitAnd,
  5938. WaveActiveBitXor,
  5939. ShaderOpInvalid
  5940. };
  5941. struct ShaderOpKindPair {
  5942. LPCWSTR name;
  5943. ShaderOpKind kind;
  5944. };
  5945. static ShaderOpKindPair ShaderOpKindTable[] = {
  5946. { L"WaveActiveSum", ShaderOpKind::WaveSum },
  5947. { L"WaveActiveUSum", ShaderOpKind::WaveSum },
  5948. { L"WaveActiveProduct", ShaderOpKind::WaveProduct },
  5949. { L"WaveActiveUProduct", ShaderOpKind::WaveProduct },
  5950. { L"WaveActiveMax", ShaderOpKind::WaveActiveMax },
  5951. { L"WaveActiveUMax", ShaderOpKind::WaveActiveMax },
  5952. { L"WaveActiveMin", ShaderOpKind::WaveActiveMin },
  5953. { L"WaveActiveUMin", ShaderOpKind::WaveActiveMin },
  5954. { L"WaveActiveCountBits", ShaderOpKind::WaveCountBits },
  5955. { L"WaveActiveAllEqual", ShaderOpKind::WaveActiveAllEqual },
  5956. { L"WaveActiveAnyTrue", ShaderOpKind::WaveActiveAnyTrue },
  5957. { L"WaveActiveAllTrue", ShaderOpKind::WaveActiveAllTrue },
  5958. { L"WaveActiveBitOr", ShaderOpKind::WaveActiveBitOr },
  5959. { L"WaveActiveBitAnd", ShaderOpKind::WaveActiveBitAnd },
  5960. { L"WaveActiveBitXor", ShaderOpKind::WaveActiveBitXor },
  5961. { L"WavePrefixSum", ShaderOpKind::WaveSum },
  5962. { L"WavePrefixUSum", ShaderOpKind::WaveSum },
  5963. { L"WavePrefixProduct", ShaderOpKind::WaveProduct },
  5964. { L"WavePrefixUProduct", ShaderOpKind::WaveProduct },
  5965. { L"WavePrefixMax", ShaderOpKind::WaveActiveMax },
  5966. { L"WavePrefixUMax", ShaderOpKind::WaveActiveMax },
  5967. { L"WavePrefixMin", ShaderOpKind::WaveActiveMin },
  5968. { L"WavePrefixUMin", ShaderOpKind::WaveActiveMin },
  5969. { L"WavePrefixCountBits", ShaderOpKind::WaveCountBits }
  5970. };
  5971. ShaderOpKind GetShaderOpKind(LPCWSTR str) {
  5972. for (size_t i = 0; i < sizeof(ShaderOpKindTable)/sizeof(ShaderOpKindPair); ++i) {
  5973. if (_wcsicmp(ShaderOpKindTable[i].name, str) == 0) {
  5974. return ShaderOpKindTable[i].kind;
  5975. }
  5976. }
  5977. DXASSERT_ARGS(false, "Invalid ShaderOp name: %s", str);
  5978. return ShaderOpKind::ShaderOpInvalid;
  5979. }
  5980. template <typename InType, typename OutType, ShaderOpKind kind>
  5981. struct computeExpected {
  5982. OutType operator()(const std::vector<InType> &inputs,
  5983. const std::vector<int> &masks, int maskValue,
  5984. unsigned int index) {
  5985. return 0;
  5986. }
  5987. };
  5988. template <typename InType, typename OutType>
  5989. struct computeExpected<InType, OutType, ShaderOpKind::WaveSum> {
  5990. OutType operator()(const std::vector<InType> &inputs,
  5991. const std::vector<int> &masks, int maskValue,
  5992. unsigned int index) {
  5993. OutType sum = 0;
  5994. for (size_t i = 0; i < index; ++i) {
  5995. if (masks.at(i) == maskValue) {
  5996. sum += inputs.at(i);
  5997. }
  5998. }
  5999. return sum;
  6000. }
  6001. };
  6002. template <typename InType, typename OutType>
  6003. struct computeExpected<InType, OutType, ShaderOpKind::WaveProduct> {
  6004. OutType operator()(const std::vector<InType> &inputs,
  6005. const std::vector<int> &masks, int maskValue,
  6006. unsigned int index) {
  6007. OutType prod = 1;
  6008. for (size_t i = 0; i < index; ++i) {
  6009. if (masks.at(i) == maskValue) {
  6010. prod *= inputs.at(i);
  6011. }
  6012. }
  6013. return prod;
  6014. }
  6015. };
  6016. template <typename InType, typename OutType>
  6017. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveMax> {
  6018. OutType operator()(const std::vector<InType> &inputs,
  6019. const std::vector<int> &masks, int maskValue,
  6020. unsigned int index) {
  6021. OutType maximum = std::numeric_limits<OutType>::min();
  6022. for (size_t i = 0; i < index; ++i) {
  6023. if (masks.at(i) == maskValue && inputs.at(i) > maximum)
  6024. maximum = inputs.at(i);
  6025. }
  6026. return maximum;
  6027. }
  6028. };
  6029. template <typename InType, typename OutType>
  6030. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveMin> {
  6031. OutType operator()(const std::vector<InType> &inputs,
  6032. const std::vector<int> &masks, int maskValue,
  6033. unsigned int index) {
  6034. OutType minimum = std::numeric_limits<OutType>::max();
  6035. for (size_t i = 0; i < index; ++i) {
  6036. if (masks.at(i) == maskValue && inputs.at(i) < minimum)
  6037. minimum = inputs.at(i);
  6038. }
  6039. return minimum;
  6040. }
  6041. };
  6042. template <typename InType, typename OutType>
  6043. struct computeExpected<InType, OutType, ShaderOpKind::WaveCountBits> {
  6044. OutType operator()(const std::vector<InType> &inputs,
  6045. const std::vector<int> &masks, int maskValue,
  6046. unsigned int index) {
  6047. OutType count = 0;
  6048. for (size_t i = 0; i < index; ++i) {
  6049. if (masks.at(i) == maskValue && inputs.at(i) > 3) {
  6050. count++;
  6051. }
  6052. }
  6053. return count;
  6054. }
  6055. };
  6056. // In HLSL, boolean is represented in a 4 byte (uint32) format,
  6057. // So we cannot use c++ bool type to represent bool in HLSL
  6058. // HLSL returns 0 for false and 1 for true
  6059. template <typename InType, typename OutType>
  6060. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAnyTrue> {
  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 1;
  6067. }
  6068. }
  6069. return 0;
  6070. }
  6071. };
  6072. template <typename InType, typename OutType>
  6073. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllTrue> {
  6074. OutType operator()(const std::vector<InType> &inputs,
  6075. const std::vector<int> &masks, int maskValue,
  6076. unsigned int index) {
  6077. for (size_t i = 0; i < index; ++i) {
  6078. if (masks.at(i) == maskValue && inputs.at(i) == 0) {
  6079. return 0;
  6080. }
  6081. }
  6082. return 1;
  6083. }
  6084. };
  6085. template <typename InType, typename OutType>
  6086. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllEqual> {
  6087. OutType operator()(const std::vector<InType> &inputs,
  6088. const std::vector<int> &masks, int maskValue,
  6089. unsigned int index) {
  6090. const InType *val = nullptr;
  6091. for (size_t i = 0; i < index; ++i) {
  6092. if (masks.at(i) == maskValue) {
  6093. if (val && *val != inputs.at(i)) {
  6094. return 0;
  6095. }
  6096. val = &inputs.at(i);
  6097. }
  6098. }
  6099. return 1;
  6100. }
  6101. };
  6102. template <typename InType, typename OutType>
  6103. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitOr> {
  6104. OutType operator()(const std::vector<InType> &inputs,
  6105. const std::vector<int> &masks, int maskValue,
  6106. unsigned int index) {
  6107. OutType bits = 0x00000000;
  6108. for (size_t i = 0; i < index; ++i) {
  6109. if (masks.at(i) == maskValue) {
  6110. bits |= inputs.at(i);
  6111. }
  6112. }
  6113. return bits;
  6114. }
  6115. };
  6116. template <typename InType, typename OutType>
  6117. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitAnd> {
  6118. OutType operator()(const std::vector<InType> &inputs,
  6119. const std::vector<int> &masks, int maskValue,
  6120. unsigned int index) {
  6121. OutType bits = 0xffffffff;
  6122. for (size_t i = 0; i < index; ++i) {
  6123. if (masks.at(i) == maskValue) {
  6124. bits &= inputs.at(i);
  6125. }
  6126. }
  6127. return bits;
  6128. }
  6129. };
  6130. template <typename InType, typename OutType>
  6131. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitXor> {
  6132. OutType operator()(const std::vector<InType> &inputs,
  6133. const std::vector<int> &masks, int maskValue,
  6134. unsigned int index) {
  6135. OutType bits = 0x00000000;
  6136. for (size_t i = 0; i < index; ++i) {
  6137. if (masks.at(i) == maskValue) {
  6138. bits ^= inputs.at(i);
  6139. }
  6140. }
  6141. return bits;
  6142. }
  6143. };
  6144. // Mask functions used to control active lanes
  6145. static int MaskAll(int i) {
  6146. UNREFERENCED_PARAMETER(i);
  6147. return 1;
  6148. }
  6149. static int MaskEveryOther(int i) {
  6150. return i % 2 == 0 ? 1 : 0;
  6151. }
  6152. static int MaskEveryThird(int i) {
  6153. return i % 3 == 0 ? 1 : 0;
  6154. }
  6155. typedef int(*MaskFunction)(int);
  6156. static MaskFunction MaskFunctionTable[] = {
  6157. MaskAll, MaskEveryOther, MaskEveryThird
  6158. };
  6159. template <typename InType, typename OutType>
  6160. static OutType computeExpectedWithShaderOp(const std::vector<InType> &inputs,
  6161. const std::vector<int> &masks,
  6162. int maskValue, unsigned int index,
  6163. LPCWSTR str) {
  6164. ShaderOpKind kind = GetShaderOpKind(str);
  6165. switch (kind) {
  6166. case ShaderOpKind::WaveSum:
  6167. return computeExpected<InType, OutType, ShaderOpKind::WaveSum>()(inputs, masks, maskValue, index);
  6168. case ShaderOpKind::WaveProduct:
  6169. return computeExpected<InType, OutType, ShaderOpKind::WaveProduct>()(inputs, masks, maskValue, index);
  6170. case ShaderOpKind::WaveActiveMax:
  6171. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveMax>()(inputs, masks, maskValue, index);
  6172. case ShaderOpKind::WaveActiveMin:
  6173. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveMin>()(inputs, masks, maskValue, index);
  6174. case ShaderOpKind::WaveCountBits:
  6175. return computeExpected<InType, OutType, ShaderOpKind::WaveCountBits>()(inputs, masks, maskValue, index);
  6176. case ShaderOpKind::WaveActiveBitOr:
  6177. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitOr>()(inputs, masks, maskValue, index);
  6178. case ShaderOpKind::WaveActiveBitAnd:
  6179. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitAnd>()(inputs, masks, maskValue, index);
  6180. case ShaderOpKind::WaveActiveBitXor:
  6181. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitXor>()(inputs, masks, maskValue, index);
  6182. case ShaderOpKind::WaveActiveAnyTrue:
  6183. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAnyTrue>()(inputs, masks, maskValue, index);
  6184. case ShaderOpKind::WaveActiveAllTrue:
  6185. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllTrue>()(inputs, masks, maskValue, index);
  6186. case ShaderOpKind::WaveActiveAllEqual:
  6187. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllEqual>()(inputs, masks, maskValue, index);
  6188. default:
  6189. DXASSERT_ARGS(false, "Invalid ShaderOp Name: %s", str);
  6190. return (OutType) 0;
  6191. }
  6192. };
  6193. // A framework for testing individual wave intrinsics tests.
  6194. // This test case is assuming that functions 1) WaveIsFirstLane and 2) WaveGetLaneIndex are correct for all lanes.
  6195. template <class T1, class T2>
  6196. void ExecutionTest::WaveIntrinsicsActivePrefixTest(
  6197. TableParameter *pParameterList, size_t numParameter, bool isPrefix) {
  6198. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6199. // Resource representation for compute shader
  6200. // firstLaneId is used to group different waves
  6201. // laneIndex is used to identify lane within the wave.
  6202. // Lane ids are not necessarily in same order as thread ids.
  6203. struct PerThreadData {
  6204. unsigned firstLaneId;
  6205. unsigned laneIndex;
  6206. int mask;
  6207. T1 input;
  6208. T2 output;
  6209. };
  6210. unsigned int NumThreadsX = 8;
  6211. unsigned int NumThreadsY = 12;
  6212. unsigned int NumThreadsZ = 1;
  6213. static const unsigned int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  6214. static const unsigned int DispatchGroupCount = 1;
  6215. static const unsigned int ThreadCount = ThreadsPerGroup * DispatchGroupCount;
  6216. CComPtr<IStream> pStream;
  6217. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6218. CComPtr<ID3D12Device> pDevice;
  6219. if (!CreateDevice(&pDevice)) {
  6220. return;
  6221. }
  6222. if (!DoesDeviceSupportWaveOps(pDevice)) {
  6223. // Optional feature, so it's correct to not support it if declared as such.
  6224. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  6225. return;
  6226. }
  6227. TableParameterHandler handler(pParameterList, numParameter);
  6228. unsigned int numInputSet = handler.GetTableParamByName(L"Validation.NumInputSet")->m_uint;
  6229. // Obtain the list of input lists
  6230. std::vector<std::vector<T1>*> InputDataList;
  6231. for (unsigned int i = 0;
  6232. i < numInputSet; ++i) {
  6233. std::wstring inputName = L"Validation.InputSet";
  6234. inputName.append(std::to_wstring(i + 1));
  6235. InputDataList.push_back(handler.GetDataArray<T1>(inputName.data()));
  6236. }
  6237. CW2A Text(handler.GetTableParamByName(L"ShaderOp.text")->m_str);
  6238. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  6239. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  6240. // Running compute shader for each input set with different masks
  6241. for (size_t setIndex = 0; setIndex < numInputSet; ++setIndex) {
  6242. for (size_t maskIndex = 0; maskIndex < sizeof(MaskFunctionTable) / sizeof(MaskFunction); ++maskIndex) {
  6243. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(
  6244. pDevice, m_support, "WaveIntrinsicsOp",
  6245. // this callbacked is called when the test
  6246. // is creating the resource to run the test
  6247. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6248. VERIFY_IS_TRUE(0 == _stricmp(Name, "SWaveIntrinsicsOp"));
  6249. size_t size = sizeof(PerThreadData) * ThreadCount;
  6250. Data.resize(size);
  6251. PerThreadData *pPrimitives = (PerThreadData*)Data.data();
  6252. // 4 different inputs for each operation test
  6253. size_t index = 0;
  6254. std::vector<T1> *IntList = InputDataList[setIndex];
  6255. while (index < ThreadCount) {
  6256. PerThreadData *p = &pPrimitives[index];
  6257. p->firstLaneId = 0xFFFFBFFF;
  6258. p->laneIndex = 0xFFFFBFFF;
  6259. p->mask = MaskFunctionTable[maskIndex]((int)index);
  6260. p->input = (*IntList)[index % IntList->size()];
  6261. p->output = 0xFFFFBFFF;
  6262. index++;
  6263. }
  6264. // use shader from data table
  6265. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  6266. }, ShaderOpSet);
  6267. // Check the value
  6268. MappedData data;
  6269. test->Test->GetReadBackData("SWaveIntrinsicsOp", &data);
  6270. PerThreadData *pPrimitives = (PerThreadData*)data.data();
  6271. WEX::TestExecution::DisableVerifyExceptions dve;
  6272. // Grouping data by waves
  6273. std::vector<int> firstLaneIds;
  6274. for (size_t i = 0; i < ThreadCount; ++i) {
  6275. PerThreadData *p = &pPrimitives[i];
  6276. int firstLaneId = p->firstLaneId;
  6277. if (!contains(firstLaneIds, firstLaneId)) {
  6278. firstLaneIds.push_back(firstLaneId);
  6279. }
  6280. }
  6281. std::map<int, std::unique_ptr<std::vector<PerThreadData *>>> waves;
  6282. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  6283. waves[firstLaneIds.at(i)] = std::make_unique<std::vector<PerThreadData*>>();
  6284. }
  6285. for (size_t i = 0; i < ThreadCount; ++i) {
  6286. PerThreadData *p = &pPrimitives[i];
  6287. waves[p->firstLaneId].get()->push_back(p);
  6288. }
  6289. // validate for each wave
  6290. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  6291. // collect inputs and masks for a given wave
  6292. std::vector<PerThreadData *> *waveData = waves[firstLaneIds.at(i)].get();
  6293. std::vector<T1> inputList(waveData->size());
  6294. std::vector<int> maskList(waveData->size(), -1);
  6295. std::vector<T2> outputList(waveData->size());
  6296. // sort inputList and masklist by lane id. input for each lane can be computed for its group index
  6297. for (size_t j = 0, end = waveData->size(); j < end; ++j) {
  6298. unsigned laneID = waveData->at(j)->laneIndex;
  6299. // ensure that each lane ID is unique and within the range
  6300. VERIFY_IS_TRUE(0 <= laneID && laneID < waveData->size());
  6301. VERIFY_IS_TRUE(maskList.at(laneID) == -1);
  6302. maskList.at(laneID) = waveData->at(j)->mask;
  6303. inputList.at(laneID) = waveData->at(j)->input;
  6304. outputList.at(laneID) = waveData->at(j)->output;
  6305. }
  6306. std::wstring inputStr = L"Wave Inputs: ";
  6307. std::wstring maskStr = L"Wave Masks: ";
  6308. std::wstring outputStr = L"Wave Outputs: ";
  6309. // append input string and mask string in lane id order
  6310. for (size_t j = 0, end = waveData->size(); j < end; ++j) {
  6311. maskStr.append(std::to_wstring(maskList.at(j)));
  6312. maskStr.append(L" ");
  6313. inputStr.append(std::to_wstring(inputList.at(j)));
  6314. inputStr.append(L" ");
  6315. outputStr.append(std::to_wstring(outputList.at(j)));
  6316. outputStr.append(L" ");
  6317. }
  6318. LogCommentFmt(inputStr.data());
  6319. LogCommentFmt(maskStr.data());
  6320. LogCommentFmt(outputStr.data());
  6321. LogCommentFmt(L"\n");
  6322. // Compute expected output for a given inputs, masks, and index
  6323. for (size_t laneIndex = 0, laneEnd = inputList.size(); laneIndex < laneEnd; ++laneIndex) {
  6324. T2 expected;
  6325. // WaveActive is equivalent to WavePrefix lane # lane count
  6326. unsigned index = isPrefix ? (unsigned)laneIndex : (unsigned)inputList.size();
  6327. if (maskList.at(laneIndex) == 1) {
  6328. expected = computeExpectedWithShaderOp<T1, T2>(
  6329. inputList, maskList, 1, index,
  6330. handler.GetTableParamByName(L"ShaderOp.Name")->m_str);
  6331. }
  6332. else {
  6333. expected = computeExpectedWithShaderOp<T1, T2>(
  6334. inputList, maskList, 0, index,
  6335. handler.GetTableParamByName(L"ShaderOp.Name")->m_str);
  6336. }
  6337. // TODO: use different comparison for floating point inputs
  6338. bool equal = outputList.at(laneIndex) == expected;
  6339. if (!equal) {
  6340. LogCommentFmt(L"lane%d: %4d, Expected : %4d", laneIndex, outputList.at(laneIndex), expected);
  6341. }
  6342. VERIFY_IS_TRUE(equal);
  6343. }
  6344. }
  6345. }
  6346. }
  6347. }
  6348. static const unsigned int MinWarpVersionForWaveIntrinsics = 16202;
  6349. TEST_F(ExecutionTest, WaveIntrinsicsActiveIntTest) {
  6350. if (GetTestParamUseWARP(true) &&
  6351. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6352. return;
  6353. }
  6354. WaveIntrinsicsActivePrefixTest<int, int>(
  6355. WaveIntrinsicsActiveIntParameters,
  6356. sizeof(WaveIntrinsicsActiveIntParameters) / sizeof(TableParameter),
  6357. /*isPrefix*/ false);
  6358. }
  6359. TEST_F(ExecutionTest, WaveIntrinsicsActiveUintTest) {
  6360. if (GetTestParamUseWARP(true) &&
  6361. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6362. return;
  6363. }
  6364. WaveIntrinsicsActivePrefixTest<unsigned int, unsigned int>(
  6365. WaveIntrinsicsActiveUintParameters,
  6366. sizeof(WaveIntrinsicsActiveUintParameters) / sizeof(TableParameter),
  6367. /*isPrefix*/ false);
  6368. }
  6369. TEST_F(ExecutionTest, WaveIntrinsicsPrefixIntTest) {
  6370. if (GetTestParamUseWARP(true) &&
  6371. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6372. return;
  6373. }
  6374. WaveIntrinsicsActivePrefixTest<int, int>(
  6375. WaveIntrinsicsPrefixIntParameters,
  6376. sizeof(WaveIntrinsicsPrefixIntParameters) / sizeof(TableParameter),
  6377. /*isPrefix*/ true);
  6378. }
  6379. TEST_F(ExecutionTest, WaveIntrinsicsPrefixUintTest) {
  6380. if (GetTestParamUseWARP(true) &&
  6381. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6382. return;
  6383. }
  6384. WaveIntrinsicsActivePrefixTest<unsigned int, unsigned int>(
  6385. WaveIntrinsicsPrefixUintParameters,
  6386. sizeof(WaveIntrinsicsPrefixUintParameters) / sizeof(TableParameter),
  6387. /*isPrefix*/ true);
  6388. }
  6389. template <typename T>
  6390. static T GetWaveMultiPrefixInitialAccumValue(LPCWSTR testName) {
  6391. if (_wcsicmp(testName, L"WaveMultiPrefixProduct") == 0 ||
  6392. _wcsicmp(testName, L"WaveMultiPrefixUProduct") == 0) {
  6393. return static_cast<T>(1);
  6394. } else if (_wcsicmp(testName, L"WaveMultiPrefixSum") == 0 ||
  6395. _wcsicmp(testName, L"WaveMultiPrefixUSum") == 0 ||
  6396. _wcsicmp(testName, L"WaveMultiPrefixBitOr") == 0 ||
  6397. _wcsicmp(testName, L"WaveMultiPrefixUBitOr") == 0 ||
  6398. _wcsicmp(testName, L"WaveMultiPrefixBitXor") == 0 ||
  6399. _wcsicmp(testName, L"WaveMultiPrefixUBitXor") == 0 ||
  6400. _wcsicmp(testName, L"WaveMultiPrefixCountBits") == 0 ||
  6401. _wcsicmp(testName, L"WaveMultiPrefixUCountBits") == 0) {
  6402. return static_cast<T>(0);
  6403. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitAnd") == 0 ||
  6404. _wcsicmp(testName, L"WaveMultiPrefixUBitAnd") == 0) {
  6405. return static_cast<T>(-1);
  6406. } else {
  6407. return static_cast<T>(0);
  6408. }
  6409. }
  6410. template <typename T>
  6411. std::function<T(T, T)> GetWaveMultiPrefixReferenceFunction(LPCWSTR testName) {
  6412. if (_wcsicmp(testName, L"WaveMultiPrefixProduct") == 0 ||
  6413. _wcsicmp(testName, L"WaveMultiPrefixUProduct") == 0) {
  6414. return [] (T lhs, T rhs) -> T { return lhs * rhs; };
  6415. } else if (_wcsicmp(testName, L"WaveMultiPrefixSum") == 0 ||
  6416. _wcsicmp(testName, L"WaveMultiPrefixUSum") == 0) {
  6417. return [] (T lhs, T rhs) -> T { return lhs + rhs; };
  6418. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitAnd") == 0 ||
  6419. _wcsicmp(testName, L"WaveMultiPrefixUBitAnd") == 0) {
  6420. return [] (T lhs, T rhs) -> T { return lhs & rhs; };
  6421. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitOr") == 0 ||
  6422. _wcsicmp(testName, L"WaveMultiPrefixUBitOr") == 0) {
  6423. return [] (T lhs, T rhs) -> T { return lhs | rhs; };
  6424. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitXor") == 0 ||
  6425. _wcsicmp(testName, L"WaveMultiPrefixUBitXor") == 0) {
  6426. return [] (T lhs, T rhs) -> T { return lhs ^ rhs; };
  6427. } else if (_wcsicmp(testName, L"WaveMultiPrefixCountBits") == 0 ||
  6428. _wcsicmp(testName, L"WaveMultiPrefixUCountBits") == 0) {
  6429. // For CountBits, each lane contributes a boolean value. The test input is
  6430. // a zero or non-zero integer. If the input is a non-zero value then the
  6431. // condition is true, thus we contribute one to the bit count.
  6432. return [] (T lhs, T rhs) -> T { return lhs + (rhs ? 1 : 0); };
  6433. } else {
  6434. return [] (T lhs, T rhs) -> T { UNREFERENCED_PARAMETER(lhs); UNREFERENCED_PARAMETER(rhs); return 0; };
  6435. }
  6436. }
  6437. template <class T>
  6438. void
  6439. ExecutionTest::WaveIntrinsicsMultiPrefixOpTest(TableParameter *pParameterList,
  6440. size_t numParameters) {
  6441. WEX::TestExecution::SetVerifyOutput
  6442. verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6443. struct PerThreadData {
  6444. uint32_t key;
  6445. uint32_t firstLaneId;
  6446. uint32_t laneId;
  6447. uint32_t mask;
  6448. T value;
  6449. T result;
  6450. };
  6451. constexpr size_t NumThreadsX = 8;
  6452. constexpr size_t NumThreadsY = 12;
  6453. constexpr size_t NumThreadsZ = 1;
  6454. constexpr size_t ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  6455. constexpr size_t DispatchGroupSize = 1;
  6456. constexpr size_t ThreadCount = ThreadsPerGroup * DispatchGroupSize;
  6457. CComPtr<IStream> pStream;
  6458. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6459. CComPtr<ID3D12Device> pDevice;
  6460. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_5)) {
  6461. return;
  6462. }
  6463. if (!DoesDeviceSupportWaveOps(pDevice)) {
  6464. // Optional feature, so it's correct to not support it if declared as such.
  6465. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  6466. return;
  6467. }
  6468. std::shared_ptr<st::ShaderOpSet>
  6469. ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  6470. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  6471. TableParameterHandler handler(pParameterList, numParameters);
  6472. CW2A shaderSource(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  6473. CW2A shaderProfile(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  6474. auto testName = handler.GetTableParamByName(L"ShaderOp.Name")->m_str;
  6475. std::vector<T> *keys = handler.GetDataArray<T>(L"Validation.Keys");
  6476. std::vector<T> *values = handler.GetDataArray<T>(L"Validation.Values");
  6477. for (size_t maskIndex = 0; maskIndex < _countof(MaskFunctionTable); ++maskIndex) {
  6478. std::shared_ptr<ShaderOpTestResult> test =
  6479. RunShaderOpTestAfterParse(pDevice, m_support, "WaveIntrinsicsOp",
  6480. [&] (LPCSTR name, std::vector<BYTE> &data, st::ShaderOp *pShaderOp) {
  6481. UNREFERENCED_PARAMETER(name);
  6482. const size_t dataSize = sizeof(PerThreadData) * ThreadCount;
  6483. data.resize(dataSize);
  6484. PerThreadData *pThreadData = reinterpret_cast<PerThreadData *>(data.data());
  6485. for (size_t i = 0; i != ThreadCount; ++i) {
  6486. pThreadData[i].key = keys->at(i % keys->size());
  6487. pThreadData[i].value = values->at(i % values->size());
  6488. pThreadData[i].firstLaneId = 0xdeadbeef;
  6489. pThreadData[i].laneId = 0xdeadbeef;
  6490. pThreadData[i].mask = MaskFunctionTable[maskIndex]((int)i);
  6491. pThreadData[i].result = 0xdeadbeef;
  6492. }
  6493. pShaderOp->Shaders.at(0).Text = shaderSource;
  6494. pShaderOp->Shaders.at(0).Target = shaderProfile;
  6495. }, ShaderOpSet);
  6496. MappedData mappedData;
  6497. test->Test->GetReadBackData("SWaveIntrinsicsOp", &mappedData);
  6498. PerThreadData *resultData = reinterpret_cast<PerThreadData *>(mappedData.data());
  6499. // Partition our data into waves
  6500. std::map<uint32_t, std::vector<PerThreadData *>> waves;
  6501. for (size_t i = 0, e = ThreadCount; i != e; ++i) {
  6502. PerThreadData *elt = &resultData[i];
  6503. // Basic sanity checks
  6504. VERIFY_IS_TRUE(elt->firstLaneId != 0xdeadbeef);
  6505. VERIFY_IS_TRUE(elt->laneId != 0xdeadbeef);
  6506. waves[elt->firstLaneId].push_back(elt);
  6507. }
  6508. // Verify each wave
  6509. auto refFn = GetWaveMultiPrefixReferenceFunction<T>(testName);
  6510. for (auto &w : waves) {
  6511. std::vector<PerThreadData *> &waveData = w.second;
  6512. struct {
  6513. bool operator()(PerThreadData *a, PerThreadData *b) const {
  6514. return (a->laneId < b->laneId);
  6515. }
  6516. } compare;
  6517. // Need to sort based on the lane id
  6518. std::sort(waveData.begin(), waveData.end(), compare);
  6519. LogCommentFmt(L"LaneId Mask Key Value Result Expected");
  6520. LogCommentFmt(L"-------- -------- -------- -------- -------- --------");
  6521. for (size_t i = 0, e = waveData.size(); i != e; ++i) {
  6522. PerThreadData *data = waveData[i];
  6523. // Compute prefix operation over each previous lane element that has the
  6524. // same key value, and is part of the same active thread group
  6525. T accum = GetWaveMultiPrefixInitialAccumValue<T>(testName);
  6526. for (unsigned j = 0; j < i; ++j) {
  6527. if (waveData[j]->key == data->key && waveData[j]->mask == data->mask) {
  6528. accum = refFn(accum, waveData[j]->value);
  6529. }
  6530. }
  6531. LogCommentFmt(L"%08X %08X %08X %08X %08X %08X", data->laneId, data->mask, data->key, data->value, data->result, accum);
  6532. VERIFY_IS_TRUE(accum == data->result);
  6533. }
  6534. LogCommentFmt(L"\n");
  6535. }
  6536. }
  6537. }
  6538. TEST_F(ExecutionTest, WaveIntrinsicsSM65IntTest) {
  6539. WaveIntrinsicsMultiPrefixOpTest<int>(WaveIntrinsicsMultiPrefixIntParameters,
  6540. _countof(WaveIntrinsicsMultiPrefixIntParameters));
  6541. }
  6542. TEST_F(ExecutionTest, WaveIntrinsicsSM65UintTest) {
  6543. WaveIntrinsicsMultiPrefixOpTest<unsigned>(WaveIntrinsicsMultiPrefixUintParameters,
  6544. _countof(WaveIntrinsicsMultiPrefixUintParameters));
  6545. }
  6546. TEST_F(ExecutionTest, CBufferTestHalf) {
  6547. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6548. CComPtr<IStream> pStream;
  6549. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6550. // Single operation test at the moment.
  6551. CComPtr<ID3D12Device> pDevice;
  6552. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_2))
  6553. return;
  6554. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  6555. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  6556. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6557. return;
  6558. }
  6559. uint16_t InputData[] = { 0x3F80, 0x3F00, 0x3D80, 0x7BFF };
  6560. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "CBufferTestHalf",
  6561. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6562. UNREFERENCED_PARAMETER(pShaderOp);
  6563. VERIFY_IS_TRUE(0 == _stricmp(Name, "CB0"));
  6564. // use shader from data table.
  6565. Data.resize(sizeof(InputData));
  6566. uint16_t *pData = (uint16_t *)Data.data();
  6567. for (size_t i = 0; i < 4; ++i, ++pData) {
  6568. *pData = InputData[i];
  6569. }
  6570. });
  6571. {
  6572. MappedData data;
  6573. test->Test->GetReadBackData("RTarget", &data);
  6574. const uint16_t *pPixels = (uint16_t *)data.data();
  6575. for (int i = 0; i < 4; ++i) {
  6576. uint16_t output = *(pPixels + i);
  6577. float outputFloat = ConvertFloat16ToFloat32(output);
  6578. float inputFloat = ConvertFloat16ToFloat32(InputData[i]);
  6579. LogCommentFmt(L"element #%u: input = %6.8f(0x%04x), output = %6.8f(0x%04x)",
  6580. i, inputFloat, InputData[i], outputFloat, output);
  6581. VERIFY_ARE_EQUAL(inputFloat, outputFloat);
  6582. }
  6583. }
  6584. }
  6585. TEST_F(ExecutionTest, BarycentricsTest) {
  6586. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6587. CComPtr<IStream> pStream;
  6588. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6589. CComPtr<ID3D12Device> pDevice;
  6590. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_1))
  6591. return;
  6592. if (!DoesDeviceSupportBarycentrics(pDevice)) {
  6593. WEX::Logging::Log::Comment(L"Device does not support barycentrics.");
  6594. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6595. return;
  6596. }
  6597. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "Barycentrics", nullptr);
  6598. MappedData data;
  6599. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  6600. UINT width = (UINT)D.Width;
  6601. UINT height = D.Height;
  6602. UINT pixelSize = GetByteSizeForFormat(D.Format);
  6603. test->Test->GetReadBackData("RTarget", &data);
  6604. //const uint8_t *pPixels = (uint8_t *)data.data();
  6605. const float *pPixels = (float *)data.data();
  6606. // Get the vertex of barycentric coordinate using VBuffer
  6607. MappedData triangleData;
  6608. test->Test->GetReadBackData("VBuffer", &triangleData);
  6609. const float *pTriangleData = (float*)triangleData.data();
  6610. // get the size of the input data
  6611. unsigned triangleVertexSizeInFloat = 0;
  6612. for (auto element : test->ShaderOp->InputElements)
  6613. triangleVertexSizeInFloat += GetByteSizeForFormat(element.Format) / 4;
  6614. XMFLOAT2 p0(pTriangleData[0], pTriangleData[1]);
  6615. XMFLOAT2 p1(pTriangleData[triangleVertexSizeInFloat], pTriangleData[triangleVertexSizeInFloat + 1]);
  6616. XMFLOAT2 p2(pTriangleData[triangleVertexSizeInFloat * 2], pTriangleData[triangleVertexSizeInFloat * 2 + 1]);
  6617. XMFLOAT3 barycentricWeights[4] = {
  6618. XMFLOAT3(0.3333f, 0.3333f, 0.3333f),
  6619. XMFLOAT3(0.5f, 0.25f, 0.25f),
  6620. XMFLOAT3(0.25f, 0.5f, 0.25f),
  6621. XMFLOAT3(0.25f, 0.25f, 0.50f)
  6622. };
  6623. float tolerance = 0.001f;
  6624. for (unsigned i = 0; i < sizeof(barycentricWeights) / sizeof(XMFLOAT3); ++i) {
  6625. float w0 = barycentricWeights[i].x;
  6626. float w1 = barycentricWeights[i].y;
  6627. float w2 = barycentricWeights[i].z;
  6628. float x1 = w0 * p0.x + w1 * p1.x + w2 * p2.x;
  6629. float y1 = w0 * p0.y + w1 * p1.y + w2 * p2.y;
  6630. // map from x1 y1 to rtv pixels
  6631. int pixelX = (int)((x1 + 1) * (width - 1) / 2);
  6632. int pixelY = (int)((1 - y1) * (height - 1) / 2);
  6633. int offset = pixelSize * (pixelX + pixelY * width) / sizeof(pPixels[0]);
  6634. LogCommentFmt(L"location %u %u, value %f, %f, %f", pixelX, pixelY, pPixels[offset], pPixels[offset + 1], pPixels[offset + 2]);
  6635. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset], w0, tolerance));
  6636. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset + 1], w1, tolerance));
  6637. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset + 2], w2, tolerance));
  6638. }
  6639. //SavePixelsToFile(pPixels, DXGI_FORMAT_R32G32B32A32_FLOAT, width, height, L"barycentric.bmp");
  6640. }
  6641. static const char RawBufferTestShaderDeclarations[] =
  6642. "// Note: COMPONENT_TYPE and COMPONENT_SIZE will be defined via compiler option -D\r\n"
  6643. "typedef COMPONENT_TYPE scalar; \r\n"
  6644. "typedef vector<COMPONENT_TYPE, 2> vector2; \r\n"
  6645. "typedef vector<COMPONENT_TYPE, 3> vector3; \r\n"
  6646. "typedef vector<COMPONENT_TYPE, 4> vector4; \r\n"
  6647. "\r\n"
  6648. "struct TestData { \r\n"
  6649. " scalar v1; \r\n"
  6650. " vector2 v2; \r\n"
  6651. " vector3 v3; \r\n"
  6652. " vector4 v4; \r\n"
  6653. "}; \r\n"
  6654. "\r\n"
  6655. "struct UavData {\r\n"
  6656. " TestData input; \r\n"
  6657. " TestData output; \r\n"
  6658. " TestData srvOut; \r\n"
  6659. "}; \r\n"
  6660. "\r\n"
  6661. "ByteAddressBuffer srv0 : register(t0); \r\n"
  6662. "StructuredBuffer<TestData> srv1 : register(t1); \r\n"
  6663. "ByteAddressBuffer srv2 : register(t2); \r\n"
  6664. "StructuredBuffer<TestData> srv3 : register(t3); \r\n"
  6665. "\r\n"
  6666. "RWByteAddressBuffer uav0 : register(u0); \r\n"
  6667. "RWStructuredBuffer<UavData> uav1 : register(u1); \r\n"
  6668. "RWByteAddressBuffer uav2 : register(u2); \r\n"
  6669. "RWStructuredBuffer<UavData> uav3 : register(u3); \r\n";
  6670. static const char RawBufferTestShaderBody[] =
  6671. " // offset of 'out' in 'UavData'\r\n"
  6672. " const int out_offset = COMPONENT_SIZE * 10; \r\n"
  6673. "\r\n"
  6674. " // offset of 'srv_out' in 'UavData'\r\n"
  6675. " const int srv_out_offset = COMPONENT_SIZE * 10 * 2; \r\n"
  6676. "\r\n"
  6677. " // offsets within the 'Data' struct\r\n"
  6678. " const int v1_offset = 0; \r\n"
  6679. " const int v2_offset = COMPONENT_SIZE; \r\n"
  6680. " const int v3_offset = COMPONENT_SIZE * 3; \r\n"
  6681. " const int v4_offset = COMPONENT_SIZE * 6; \r\n"
  6682. "\r\n"
  6683. " uav0.Store(srv_out_offset + v1_offset, srv0.Load<scalar>(v1_offset)); \r\n"
  6684. " uav0.Store(srv_out_offset + v2_offset, srv0.Load<vector2>(v2_offset)); \r\n"
  6685. " uav0.Store(srv_out_offset + v3_offset, srv0.Load<vector3>(v3_offset)); \r\n"
  6686. " uav0.Store(srv_out_offset + v4_offset, srv0.Load<vector4>(v4_offset)); \r\n"
  6687. "\r\n"
  6688. " uav1[0].srvOut.v1 = srv1[0].v1; \r\n"
  6689. " uav1[0].srvOut.v2 = srv1[0].v2; \r\n"
  6690. " uav1[0].srvOut.v3 = srv1[0].v3; \r\n"
  6691. " uav1[0].srvOut.v4 = srv1[0].v4; \r\n"
  6692. "\r\n"
  6693. " uav2.Store(srv_out_offset + v1_offset, srv2.Load<scalar>(v1_offset)); \r\n"
  6694. " uav2.Store(srv_out_offset + v2_offset, srv2.Load<vector2>(v2_offset)); \r\n"
  6695. " uav2.Store(srv_out_offset + v3_offset, srv2.Load<vector3>(v3_offset)); \r\n"
  6696. " uav2.Store(srv_out_offset + v4_offset, srv2.Load<vector4>(v4_offset)); \r\n"
  6697. "\r\n"
  6698. " uav3[0].srvOut.v1 = srv3[0].v1; \r\n"
  6699. " uav3[0].srvOut.v2 = srv3[0].v2; \r\n"
  6700. " uav3[0].srvOut.v3 = srv3[0].v3; \r\n"
  6701. " uav3[0].srvOut.v4 = srv3[0].v4; \r\n"
  6702. "\r\n"
  6703. " uav0.Store(out_offset + v1_offset, uav0.Load<scalar>(v1_offset)); \r\n"
  6704. " uav0.Store(out_offset + v2_offset, uav0.Load<vector2>(v2_offset)); \r\n"
  6705. " uav0.Store(out_offset + v3_offset, uav0.Load<vector3>(v3_offset)); \r\n"
  6706. " uav0.Store(out_offset + v4_offset, uav0.Load<vector4>(v4_offset)); \r\n"
  6707. "\r\n"
  6708. " uav1[0].output.v1 = uav1[0].input.v1; \r\n"
  6709. " uav1[0].output.v2 = uav1[0].input.v2; \r\n"
  6710. " uav1[0].output.v3 = uav1[0].input.v3; \r\n"
  6711. " uav1[0].output.v4 = uav1[0].input.v4; \r\n"
  6712. "\r\n"
  6713. " uav2.Store(out_offset + v1_offset, uav2.Load<scalar>(v1_offset)); \r\n"
  6714. " uav2.Store(out_offset + v2_offset, uav2.Load<vector2>(v2_offset)); \r\n"
  6715. " uav2.Store(out_offset + v3_offset, uav2.Load<vector3>(v3_offset)); \r\n"
  6716. " uav2.Store(out_offset + v4_offset, uav2.Load<vector4>(v4_offset)); \r\n"
  6717. "\r\n"
  6718. " uav3[0].output.v1 = uav3[0].input.v1; \r\n"
  6719. " uav3[0].output.v2 = uav3[0].input.v2; \r\n"
  6720. " uav3[0].output.v3 = uav3[0].input.v3; \r\n"
  6721. " uav3[0].output.v4 = uav3[0].input.v4; \r\n";
  6722. static const char RawBufferTestComputeShaderTemplate[] =
  6723. "%s\r\n" // <- RawBufferTestShaderDeclarations
  6724. "[numthreads(1, 1, 1)]\r\n"
  6725. "void main(uint GI : SV_GroupIndex) {\r\n"
  6726. "%s\r\n" // <- RawBufferTestShaderBody
  6727. "};";
  6728. static const char RawBufferTestGraphicsPixelShaderTemplate[] =
  6729. "%s\r\n" // <- RawBufferTestShaderDeclarations
  6730. "struct PSInput { \r\n"
  6731. " float4 pos : SV_POSITION; \r\n"
  6732. "}; \r\n"
  6733. "uint4 main(PSInput input) : SV_TARGET{ \r\n"
  6734. " if (input.pos.x + input.pos.y == 1.0f) { // pixel { 0.5, 0.5, 0 } \r\n"
  6735. "%s\r\n" // <- RawBufferTestShaderBody
  6736. " } \r\n"
  6737. " return uint4(1, 2, 3, 4); \r\n"
  6738. "};";
  6739. TEST_F(ExecutionTest, ComputeRawBufferLdStI32) {
  6740. RawBufferLdStTestData<int32_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT32 / 2 } };
  6741. RunComputeRawBufferLdStTest<int32_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I32, "ComputeRawBufferLdSt32Bit", data);
  6742. }
  6743. TEST_F(ExecutionTest, ComputeRawBufferLdStFloat) {
  6744. RawBufferLdStTestData<float> data = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, -105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6745. RunComputeRawBufferLdStTest<float>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Float, "ComputeRawBufferLdSt32Bit", data);
  6746. }
  6747. TEST_F(ExecutionTest, ComputeRawBufferLdStI64) {
  6748. RawBufferLdStTestData<int64_t> data = { { 1 }, { 2, -1 }, { 256, -105171532, 980 }, { 465, 13, -89, MAXUINT64 / 2 } };
  6749. RunComputeRawBufferLdStTest<int64_t>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "ComputeRawBufferLdSt64Bit", data);
  6750. }
  6751. TEST_F(ExecutionTest, ComputeRawBufferLdStDouble) {
  6752. RawBufferLdStTestData<double> data = { { 3e-10 }, { 1.5, -1.99988 }, { 256.0, -105.17, 980.0 }, { 465.1652, -1.5694e2, -0.8543e-2, 1333.5 } };
  6753. RunComputeRawBufferLdStTest<double>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "ComputeRawBufferLdSt64Bit", data);
  6754. }
  6755. TEST_F(ExecutionTest, ComputeRawBufferLdStI16) {
  6756. RawBufferLdStTestData<int16_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT16 / 2 } };
  6757. RunComputeRawBufferLdStTest<int16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I16, "ComputeRawBufferLdSt16Bit", data);
  6758. }
  6759. TEST_F(ExecutionTest, ComputeRawBufferLdStHalf) {
  6760. RawBufferLdStTestData<float> floatData = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, 105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6761. RawBufferLdStTestData<uint16_t> halfData;
  6762. for (int i = 0; i < sizeof(floatData)/sizeof(float); i++) {
  6763. ((uint16_t*)&halfData)[i] = ConvertFloat32ToFloat16(((float*)&floatData)[i]);
  6764. }
  6765. RunComputeRawBufferLdStTest<uint16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Half, "ComputeRawBufferLdSt16Bit", halfData);
  6766. }
  6767. TEST_F(ExecutionTest, GraphicsRawBufferLdStI32) {
  6768. RawBufferLdStTestData<int32_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT32 / 2 } };
  6769. RunGraphicsRawBufferLdStTest<int32_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I32, "GraphicsRawBufferLdSt32Bit", data);
  6770. }
  6771. TEST_F(ExecutionTest, GraphicsRawBufferLdStFloat) {
  6772. RawBufferLdStTestData<float> data = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, -105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6773. RunGraphicsRawBufferLdStTest<float>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Float, "GraphicsRawBufferLdSt32Bit", data);
  6774. }
  6775. TEST_F(ExecutionTest, GraphicsRawBufferLdStI64) {
  6776. RawBufferLdStTestData<int64_t> data = { { 1 }, { 2, -1 }, { 256, -105171532, 980 }, { 465, 13, -89, MAXUINT64 / 2 } };
  6777. RunGraphicsRawBufferLdStTest<int64_t>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "GraphicsRawBufferLdSt64Bit", data);
  6778. }
  6779. TEST_F(ExecutionTest, GraphicsRawBufferLdStDouble) {
  6780. RawBufferLdStTestData<double> data = { { 3e-10 }, { 1.5, -1.99988 }, { 256.0, -105.17, 980.0 }, { 465.1652, -1.5694e2, -0.8543e-2, 1333.5 } };
  6781. RunGraphicsRawBufferLdStTest<double>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::Double, "GraphicsRawBufferLdSt64Bit", data);
  6782. }
  6783. TEST_F(ExecutionTest, GraphicsRawBufferLdStI16) {
  6784. RawBufferLdStTestData<int16_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT16 / 2 } };
  6785. RunGraphicsRawBufferLdStTest<int16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I16, "GraphicsRawBufferLdSt16Bit", data);
  6786. }
  6787. TEST_F(ExecutionTest, GraphicsRawBufferLdStHalf) {
  6788. RawBufferLdStTestData<float> floatData = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, 105.17f, 0.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6789. RawBufferLdStTestData<uint16_t> halfData;
  6790. for (int i = 0; i < sizeof(floatData) / sizeof(float); i++) {
  6791. ((uint16_t*)&halfData)[i] = ConvertFloat32ToFloat16(((float*)&floatData)[i]);
  6792. }
  6793. RunGraphicsRawBufferLdStTest<uint16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Half, "GraphicsRawBufferLdSt16Bit", halfData);
  6794. }
  6795. bool ExecutionTest::SetupRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6796. CComPtr<ID3D12Device> &pDevice, CComPtr<IStream> &pStream,
  6797. char *&sTy, char *&additionalOptions) {
  6798. if (!CreateDevice(&pDevice, shaderModel)) {
  6799. return false;
  6800. }
  6801. additionalOptions = "";
  6802. switch (dataType) {
  6803. case RawBufferLdStType::I64:
  6804. if (!DoesDeviceSupportInt64(pDevice)) {
  6805. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  6806. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6807. return false;
  6808. }
  6809. sTy = "int64_t";
  6810. break;
  6811. case RawBufferLdStType::Double:
  6812. if (!DoesDeviceSupportDouble(pDevice)) {
  6813. WEX::Logging::Log::Comment(L"Device does not support double operations.");
  6814. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6815. return false;
  6816. }
  6817. sTy = "double";
  6818. break;
  6819. case RawBufferLdStType::I16:
  6820. case RawBufferLdStType::Half:
  6821. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  6822. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  6823. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6824. return false;
  6825. }
  6826. additionalOptions = "-enable-16bit-types";
  6827. sTy = (dataType == RawBufferLdStType::I16 ? "int16_t" : "half");
  6828. break;
  6829. case RawBufferLdStType::I32:
  6830. sTy = "int32_t";
  6831. break;
  6832. case RawBufferLdStType::Float:
  6833. sTy = "float";
  6834. break;
  6835. default:
  6836. DXASSERT_NOMSG("Invalid RawBufferLdStType");
  6837. }
  6838. // read shader config
  6839. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6840. return true;
  6841. }
  6842. template <class Ty>
  6843. void ExecutionTest::VerifyRawBufferLdStTestResults(const std::shared_ptr<st::ShaderOpTest> test, const RawBufferLdStTestData<Ty> &testData) {
  6844. // read buffers back & verify expected values
  6845. static const int UavBufferCount = 4;
  6846. char bufferName[11] = "UAVBufferX";
  6847. for (unsigned i = 0; i < UavBufferCount; i++) {
  6848. MappedData dataUav;
  6849. RawBufferLdStUavData<Ty> *pOutData;
  6850. bufferName[sizeof(bufferName) - 2] = (char)(i + '0');
  6851. test->GetReadBackData(bufferName, &dataUav);
  6852. VERIFY_ARE_EQUAL(sizeof(RawBufferLdStUavData<Ty>), dataUav.size());
  6853. pOutData = (RawBufferLdStUavData<Ty> *)dataUav.data();
  6854. LogCommentFmt(L"Verifying UAVBuffer%d Load -> UAVBuffer%d Store", i, i);
  6855. // scalar
  6856. VERIFY_ARE_EQUAL(pOutData->output.v1, testData.v1);
  6857. // vector 2
  6858. VERIFY_ARE_EQUAL(pOutData->output.v2[0], testData.v2[0]);
  6859. VERIFY_ARE_EQUAL(pOutData->output.v2[1], testData.v2[1]);
  6860. // vector 3
  6861. VERIFY_ARE_EQUAL(pOutData->output.v3[0], testData.v3[0]);
  6862. VERIFY_ARE_EQUAL(pOutData->output.v3[1], testData.v3[1]);
  6863. VERIFY_ARE_EQUAL(pOutData->output.v3[2], testData.v3[2]);
  6864. // vector 4
  6865. VERIFY_ARE_EQUAL(pOutData->output.v4[0], testData.v4[0]);
  6866. VERIFY_ARE_EQUAL(pOutData->output.v4[1], testData.v4[1]);
  6867. VERIFY_ARE_EQUAL(pOutData->output.v4[2], testData.v4[2]);
  6868. VERIFY_ARE_EQUAL(pOutData->output.v4[3], testData.v4[3]);
  6869. // verify SRV Store
  6870. LogCommentFmt(L"Verifying SRVBuffer%d Load -> UAVBuffer%d Store", i, i);
  6871. // scalar
  6872. VERIFY_ARE_EQUAL(pOutData->srvOut.v1, testData.v1);
  6873. // vector 2
  6874. VERIFY_ARE_EQUAL(pOutData->srvOut.v2[0], testData.v2[0]);
  6875. VERIFY_ARE_EQUAL(pOutData->srvOut.v2[1], testData.v2[1]);
  6876. // vector 3
  6877. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[0], testData.v3[0]);
  6878. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[1], testData.v3[1]);
  6879. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[2], testData.v3[2]);
  6880. // vector 4
  6881. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[0], testData.v4[0]);
  6882. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[1], testData.v4[1]);
  6883. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[2], testData.v4[2]);
  6884. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[3], testData.v4[3]);
  6885. }
  6886. }
  6887. template <class Ty>
  6888. void ExecutionTest::RunComputeRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6889. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData) {
  6890. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6891. CComPtr<ID3D12Device> pDevice;
  6892. CComPtr<IStream> pStream;
  6893. char *sTy = nullptr, *additionalOptions = nullptr;
  6894. if (!SetupRawBufferLdStTest(shaderModel, dataType, pDevice, pStream, sTy, additionalOptions)) {
  6895. return;
  6896. }
  6897. // format shader source
  6898. char rawBufferTestShaderText[sizeof(RawBufferTestComputeShaderTemplate) + sizeof(RawBufferTestShaderDeclarations) + sizeof(RawBufferTestShaderBody)];
  6899. VERIFY_IS_TRUE(sprintf_s(rawBufferTestShaderText, sizeof(rawBufferTestShaderText),
  6900. RawBufferTestComputeShaderTemplate, RawBufferTestShaderDeclarations, RawBufferTestShaderBody) != -1);
  6901. // format compiler args
  6902. char compilerOptions[256];
  6903. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D COMPONENT_TYPE=%s -D COMPONENT_SIZE=%d %s", sTy, (int)sizeof(Ty), additionalOptions) != -1);
  6904. // run the shader
  6905. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, shaderOpName,
  6906. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6907. VERIFY_IS_TRUE(((0 == strncmp(Name, "SRVBuffer", 9)) || (0 == strncmp(Name, "UAVBuffer", 9))) &&
  6908. (Name[9] >= '0' && Name[9] <= '3'));
  6909. pShaderOp->Shaders.at(0).Arguments = compilerOptions;
  6910. pShaderOp->Shaders.at(0).Text = rawBufferTestShaderText;
  6911. VERIFY_IS_TRUE(sizeof(RawBufferLdStTestData<Ty>) <= Data.size());
  6912. RawBufferLdStTestData<Ty> *pInData = (RawBufferLdStTestData<Ty>*)Data.data();
  6913. memcpy(pInData, &testData, sizeof(RawBufferLdStTestData<Ty>));
  6914. });
  6915. // verify expected values
  6916. VerifyRawBufferLdStTestResults<Ty>(test->Test, testData);
  6917. }
  6918. template <class Ty>
  6919. void ExecutionTest::RunGraphicsRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6920. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData) {
  6921. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6922. CComPtr<ID3D12Device> pDevice;
  6923. CComPtr<IStream> pStream;
  6924. char *sTy = nullptr, *additionalOptions = nullptr;
  6925. if (!SetupRawBufferLdStTest(shaderModel, dataType, pDevice, pStream, sTy, additionalOptions)) {
  6926. return;
  6927. }
  6928. // format shader source
  6929. char rawBufferTestPixelShaderText[sizeof(RawBufferTestGraphicsPixelShaderTemplate) + sizeof(RawBufferTestShaderDeclarations) + sizeof(RawBufferTestShaderBody)];
  6930. VERIFY_IS_TRUE(sprintf_s(rawBufferTestPixelShaderText, sizeof(rawBufferTestPixelShaderText),
  6931. RawBufferTestGraphicsPixelShaderTemplate, RawBufferTestShaderDeclarations, RawBufferTestShaderBody) != -1);
  6932. // format compiler args
  6933. char compilerOptions[256];
  6934. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D COMPONENT_TYPE=%s -D COMPONENT_SIZE=%d %s", sTy, (int)sizeof(Ty), additionalOptions) != -1);
  6935. // run the shader
  6936. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, shaderOpName,
  6937. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6938. VERIFY_IS_TRUE(((0 == strncmp(Name, "SRVBuffer", 9)) || (0 == strncmp(Name, "UAVBuffer", 9))) &&
  6939. (Name[9] >= '0' && Name[9] <= '3'));
  6940. // pixel shader is at index 1, vertex shader at index 0
  6941. pShaderOp->Shaders.at(1).Arguments = compilerOptions;
  6942. pShaderOp->Shaders.at(1).Text = rawBufferTestPixelShaderText;
  6943. VERIFY_IS_TRUE(sizeof(RawBufferLdStTestData<Ty>) <= Data.size());
  6944. RawBufferLdStTestData<Ty> *pInData = (RawBufferLdStTestData<Ty>*)Data.data();
  6945. memcpy(pInData, &testData, sizeof(RawBufferLdStTestData<Ty>));
  6946. });
  6947. // verify expected values
  6948. VerifyRawBufferLdStTestResults<Ty>(test->Test, testData);
  6949. }
  6950. template<typename T>
  6951. uint32_t pack(std::array<T, 4> unpackedVals)
  6952. {
  6953. uint32_t dst = 0;
  6954. constexpr uint32_t bitMask = 0xFF;
  6955. for (uint32_t i = 0U; i < 4U; ++i)
  6956. {
  6957. dst |= (unpackedVals[i] & bitMask) << (i * 8);
  6958. }
  6959. return dst;
  6960. }
  6961. template <typename T>
  6962. uint32_t pack_clamp_u8(std::array<T, 4> unpackedVals)
  6963. {
  6964. int32_t clamp_min = std::numeric_limits<uint8_t>::min();
  6965. int32_t clamp_max = std::numeric_limits<uint8_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. uint32_t pack_clamp_s8(std::array<T, 4> unpackedVals)
  6976. {
  6977. int32_t clamp_min = std::numeric_limits<int8_t>::min();
  6978. int32_t clamp_max = std::numeric_limits<int8_t>::max();
  6979. uint32_t dst = 0;
  6980. for (uint32_t i = 0U; i < 4U; ++i)
  6981. {
  6982. int32_t clamped = std::min(std::max((int32_t)unpackedVals[i], clamp_min), clamp_max);
  6983. dst |= ((uint8_t)clamped) << (i * 8);
  6984. }
  6985. return dst;
  6986. }
  6987. template<typename T>
  6988. std::array<T, 4> unpack_u(uint32_t packedVal)
  6989. {
  6990. std::array<T, 4> ret;
  6991. ret[0] = (uint8_t)((packedVal & 0x000000FF) >> 0 );
  6992. ret[1] = (uint8_t)((packedVal & 0x0000FF00) >> 8 );
  6993. ret[2] = (uint8_t)((packedVal & 0x00FF0000) >> 16);
  6994. ret[3] = (uint8_t)((packedVal & 0xFF000000) >> 24);
  6995. return ret;
  6996. }
  6997. template<typename T>
  6998. std::array<T, 4> unpack_s(uint32_t packedVal)
  6999. {
  7000. std::array<T, 4> ret;
  7001. ret[0] = (int8_t)((packedVal & 0x000000FF) >> 0 );
  7002. ret[1] = (int8_t)((packedVal & 0x0000FF00) >> 8 );
  7003. ret[2] = (int8_t)((packedVal & 0x00FF0000) >> 16);
  7004. ret[3] = (int8_t)((packedVal & 0xFF000000) >> 24);
  7005. return ret;
  7006. }
  7007. TEST_F(ExecutionTest, PackUnpackTest) {
  7008. WEX::TestExecution::SetVerifyOutput verifySettings(
  7009. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7010. CComPtr<IStream> pStream;
  7011. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7012. CComPtr<ID3D12Device> pDevice;
  7013. #ifdef PACKUNPACK_PLACEHOLDER
  7014. string args = "-enable-16bit-types -DPACKUNPACK_PLACEHOLDER";
  7015. string target = "cs_6_2";
  7016. if (!CreateDevice(&pDevice)) {
  7017. return;
  7018. }
  7019. #else
  7020. string args = "-enable-16bit-types";
  7021. string target = "cs_6_6";
  7022. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6)) {
  7023. return;
  7024. }
  7025. #endif
  7026. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  7027. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  7028. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7029. return;
  7030. }
  7031. int tableSize = sizeof(PackUnpackOpParameters) / sizeof(TableParameter);
  7032. TableParameterHandler handler(PackUnpackOpParameters, tableSize);
  7033. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  7034. std::vector<uint32_t> *validation_input = &handler.GetTableParamByName(L"Validation.Input")->m_uint32Table;
  7035. uint32_t validation_tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_uint;
  7036. size_t count = validation_input->size();
  7037. std::vector<SPackUnpackOpOutPacked> expectedPacked(count / 4);
  7038. std::vector<SPackUnpackOpOutUnpacked> expectedUnpacked(count / 4);
  7039. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  7040. pDevice, m_support, pStream, "PackUnpackOp",
  7041. // this callback is called when the test
  7042. // is creating the resource to run the test
  7043. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  7044. if (0 == _stricmp(Name, "g_bufIn"))
  7045. {
  7046. size_t size = sizeof(uint32_t) * 4 * count;
  7047. Data.resize(size);
  7048. uint32_t *pPrimitives = (uint32_t*)Data.data();
  7049. for (size_t i = 0; i < count / 4; ++i) {
  7050. uint32_t *p = &pPrimitives[i * 4];
  7051. uint32_t x = (*validation_input)[i * 4 + 0];
  7052. uint32_t y = (*validation_input)[i * 4 + 1];
  7053. uint32_t z = (*validation_input)[i * 4 + 2];
  7054. uint32_t w = (*validation_input)[i * 4 + 3];
  7055. p[0] = x;
  7056. p[1] = y;
  7057. p[2] = z;
  7058. p[3] = w;
  7059. std::array<uint32_t, 4> inputUint32 = { x, y, z, w };
  7060. std::array<int32_t, 4> inputInt32 = { (int32_t)x, (int32_t)y, (int32_t)z, (int32_t)w };
  7061. std::array<uint16_t, 4> inputUint16 = { (uint16_t)x, (uint16_t)y, (uint16_t)z, (uint16_t)w };
  7062. std::array<int16_t, 4> inputInt16 = { (int16_t)x, (int16_t)y, (int16_t)z, (int16_t)w };
  7063. // Pack unclamped
  7064. expectedPacked[i].packedUint32 = pack(inputUint32);
  7065. expectedPacked[i].packedInt32 = pack(inputInt32);
  7066. expectedPacked[i].packedUint16 = pack(inputUint16);
  7067. expectedPacked[i].packedInt16 = pack(inputInt16);
  7068. // pack clamped
  7069. expectedPacked[i].packedClampedUint32 = pack_clamp_u8(inputInt32);
  7070. expectedPacked[i].packedClampedInt32 = pack_clamp_s8(inputInt32);
  7071. expectedPacked[i].packedClampedUint16 = pack_clamp_u8(inputInt16);
  7072. expectedPacked[i].packedClampedInt16 = pack_clamp_s8(inputInt16);
  7073. // unpack
  7074. expectedUnpacked[i].outputUint32 = unpack_u<uint32_t>(expectedPacked[i].packedUint32);
  7075. expectedUnpacked[i].outputInt32 = unpack_s<int32_t >(expectedPacked[i].packedInt32 );
  7076. expectedUnpacked[i].outputUint16 = unpack_u<uint16_t>(expectedPacked[i].packedUint16);
  7077. expectedUnpacked[i].outputInt16 = unpack_s<int16_t >(expectedPacked[i].packedInt16 );
  7078. expectedUnpacked[i].outputClampedUint32 = unpack_u<uint32_t>(expectedPacked[i].packedClampedUint32);
  7079. expectedUnpacked[i].outputClampedInt32 = unpack_s<int32_t >(expectedPacked[i].packedClampedInt32 );
  7080. expectedUnpacked[i].outputClampedUint16 = unpack_u<uint16_t>(expectedPacked[i].packedClampedUint16);
  7081. expectedUnpacked[i].outputClampedInt16 = unpack_s<int16_t >(expectedPacked[i].packedClampedInt16 );
  7082. }
  7083. }
  7084. else
  7085. {
  7086. std::fill(Data.begin(), Data.end(), (BYTE)0);
  7087. }
  7088. // use shader from data table
  7089. pShaderOp->Shaders.at(0).Target = target.c_str();
  7090. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  7091. pShaderOp->Shaders.at(0).Arguments = args.c_str();
  7092. });
  7093. MappedData packedData;
  7094. test->Test->GetReadBackData("g_bufOutPacked", &packedData);
  7095. SPackUnpackOpOutPacked *readBackPacked = (SPackUnpackOpOutPacked *)packedData.data();
  7096. MappedData unpackedData;
  7097. test->Test->GetReadBackData("g_bufOutPackedUnpacked", &unpackedData);
  7098. SPackUnpackOpOutUnpacked *readBackUnpacked = (SPackUnpackOpOutUnpacked *)unpackedData.data();
  7099. for (size_t i = 0; i < count / 4; ++i)
  7100. {
  7101. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedUint32, expectedPacked[i].packedUint32, validation_tolerance);
  7102. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedInt32 , expectedPacked[i].packedInt32 , validation_tolerance);
  7103. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedUint16, expectedPacked[i].packedUint16, validation_tolerance);
  7104. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedInt16 , expectedPacked[i].packedInt16 , validation_tolerance);
  7105. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedClampedUint32, expectedPacked[i].packedClampedUint32, validation_tolerance);
  7106. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedClampedInt32 , expectedPacked[i].packedClampedInt32 , validation_tolerance);
  7107. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedClampedUint16, expectedPacked[i].packedClampedUint16, validation_tolerance);
  7108. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedClampedInt16 , expectedPacked[i].packedClampedInt16 , validation_tolerance);
  7109. for (uint32_t j = 0; j < 4; ++j)
  7110. {
  7111. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputUint32[j], expectedUnpacked[i].outputUint32[j], validation_tolerance);
  7112. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputInt32 [j], expectedUnpacked[i].outputInt32 [j], validation_tolerance);
  7113. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputUint16[j], expectedUnpacked[i].outputUint16[j], validation_tolerance);
  7114. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputInt16 [j], expectedUnpacked[i].outputInt16 [j], validation_tolerance);
  7115. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputClampedUint32[j], expectedUnpacked[i].outputClampedUint32[j], validation_tolerance);
  7116. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputClampedInt32 [j], expectedUnpacked[i].outputClampedInt32 [j], validation_tolerance);
  7117. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputClampedUint16[j], expectedUnpacked[i].outputClampedUint16[j], validation_tolerance);
  7118. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputClampedInt16 [j], expectedUnpacked[i].outputClampedInt16 [j], validation_tolerance);
  7119. }
  7120. }
  7121. }
  7122. // This test expects a <pShader> that retrieves a signal value from each of a few
  7123. // resources that are initialized here. <isDynamic> determines if it uses the
  7124. // 6.6 Dynamic Resources feature.
  7125. // Values are read back from the result UAV and compared to the expected signals
  7126. void ExecutionTest::RunResourceTest(ID3D12Device *pDevice, const char *pShader,
  7127. const wchar_t *sm, bool isDynamic) {
  7128. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7129. const int NumSRVs = 3;
  7130. const int NumUAVs = 4;
  7131. const int NumResources = NumSRVs + NumUAVs;
  7132. const int NumSamplers = 2;
  7133. const int valueSize = 16;
  7134. static const int DispatchGroupX = 1;
  7135. static const int DispatchGroupY = 1;
  7136. static const int DispatchGroupZ = 1;
  7137. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  7138. CComPtr<ID3D12CommandQueue> pCommandQueue;
  7139. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  7140. FenceObj FO;
  7141. UINT valueSizeInBytes = valueSize * sizeof(float);
  7142. CreateComputeCommandQueue(pDevice, L"DynamicResourcesTest Command Queue", &pCommandQueue);
  7143. InitFenceObj(pDevice, &FO);
  7144. // Create root signature.
  7145. CComPtr<ID3D12RootSignature> pRootSignature;
  7146. if (!isDynamic) {
  7147. // Not dynamic, create a range for each resource and from them, the root signature
  7148. CD3DX12_DESCRIPTOR_RANGE ranges[NumResources];
  7149. CD3DX12_DESCRIPTOR_RANGE srange[NumSamplers];
  7150. for (int i = 0; i < NumSRVs; i++)
  7151. ranges[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, i, 0);
  7152. for (int i = NumSRVs; i < NumResources; i++)
  7153. ranges[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, i - NumSRVs, 0);
  7154. for (int i = 0; i < NumSamplers; i++)
  7155. srange[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, i, 0);
  7156. CreateRootSignatureFromRanges(pDevice, &pRootSignature, ranges, NumResources, srange, NumSamplers);
  7157. } else {
  7158. // Dynamic just requires the flags indicating that the builtin arrays should be accessible
  7159. #if !defined(D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED)
  7160. #define D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED (D3D12_ROOT_SIGNATURE_FLAGS)0x400
  7161. #define D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED (D3D12_ROOT_SIGNATURE_FLAGS)0x800
  7162. #endif
  7163. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  7164. rootSignatureDesc.Init(0, nullptr, 0, nullptr,
  7165. D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED |
  7166. D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED);
  7167. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  7168. }
  7169. // Create pipeline state object.
  7170. CComPtr<ID3D12PipelineState> pComputeState;
  7171. CreateComputePSO(pDevice, pRootSignature, pShader, sm, &pComputeState);
  7172. // Create a command allocator and list for compute.
  7173. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  7174. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  7175. // Set up SRV resources
  7176. CComPtr<ID3D12Resource> pSRVResources[NumSRVs];
  7177. CComPtr<ID3D12Resource> pUAVResources[NumUAVs];
  7178. CComPtr<ID3D12Resource> pUploadResources[NumResources];
  7179. {
  7180. D3D12_RESOURCE_DESC bufDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes);
  7181. float values[valueSize];
  7182. for (int i = 0; i < NumSRVs - 1; i++) {
  7183. for (int j = 0; j < valueSize; j++)
  7184. values[j] = 10.0f + i;
  7185. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, bufDesc,
  7186. &pSRVResources[i], &pUploadResources[i]);
  7187. }
  7188. D3D12_RESOURCE_DESC tex2dDesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R32_FLOAT, 4, 4);
  7189. for (int j = 0; j < valueSize; j++)
  7190. values[j] = 10.0 + (NumSRVs - 1);
  7191. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, tex2dDesc,
  7192. &pSRVResources[NumSRVs - 1], &pUploadResources[NumSRVs - 1]);
  7193. }
  7194. // Set up UAV resources
  7195. CComPtr<ID3D12Resource> pReadBuffer;
  7196. float values[valueSize];
  7197. for (int i = 0; i < NumUAVs - 2; i++) {
  7198. for (int j = 0; j < valueSize; j++)
  7199. values[j] = 20.0f + i;
  7200. CreateTestUavs(pDevice, pCommandList, values, valueSizeInBytes,
  7201. &pUAVResources[i], &pUploadResources[NumSRVs + i]);
  7202. }
  7203. for (int j = 0; j < valueSize; j++)
  7204. values[j] = 20.0 + (NumUAVs - 1);
  7205. CreateTestUavs(pDevice, pCommandList, values, valueSizeInBytes,
  7206. &pUAVResources[NumUAVs - 2], &pUploadResources[NumResources - 2], &pReadBuffer);
  7207. for (int j = 0; j < valueSize; j++)
  7208. values[j] = 20.0 + (NumUAVs - 2);
  7209. D3D12_RESOURCE_DESC tex1dDesc = CD3DX12_RESOURCE_DESC::Tex1D(DXGI_FORMAT_R32_FLOAT, valueSize, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
  7210. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, tex1dDesc,
  7211. &pUAVResources[NumUAVs - 1], &pUploadResources[NumResources - 1]);
  7212. // Close the command list and execute it to perform the GPU setup.
  7213. pCommandList->Close();
  7214. ExecuteCommandList(pCommandQueue, pCommandList);
  7215. WaitForSignal(pCommandQueue, FO);
  7216. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  7217. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  7218. CComPtr<ID3D12DescriptorHeap> pResHeap;
  7219. CComPtr<ID3D12DescriptorHeap> pSampHeap;
  7220. CreateDefaultDescHeaps(pDevice, NumSRVs + NumUAVs, NumSamplers, &pResHeap, &pSampHeap);
  7221. // Create Rootsignature and descriptor tables
  7222. {
  7223. ID3D12DescriptorHeap *descHeaps[2] = {pResHeap, pSampHeap};
  7224. pCommandList->SetDescriptorHeaps(2, descHeaps);
  7225. pCommandList->SetComputeRootSignature(pRootSignature);
  7226. if (!isDynamic) {
  7227. // Only non-dynamic resources require descriptortables
  7228. pCommandList->SetComputeRootDescriptorTable(0, pResHeap->GetGPUDescriptorHandleForHeapStart());
  7229. pCommandList->SetComputeRootDescriptorTable(1, pSampHeap->GetGPUDescriptorHandleForHeapStart());
  7230. }
  7231. }
  7232. CD3DX12_CPU_DESCRIPTOR_HANDLE baseHandle(pResHeap->GetCPUDescriptorHandleForHeapStart());
  7233. // Create SRVs
  7234. CreateRawSRV(pDevice, baseHandle, valueSize, pSRVResources[0]);
  7235. CreateStructSRV(pDevice, baseHandle, valueSize, sizeof(float), pSRVResources[1]);
  7236. CreateTex2DSRV(pDevice, baseHandle, valueSize, DXGI_FORMAT_R32_FLOAT, pSRVResources[2]);
  7237. // Create UAVs
  7238. CreateRawUAV(pDevice, baseHandle, valueSize, pUAVResources[0]);
  7239. CreateStructUAV(pDevice, baseHandle, valueSize, sizeof(float), pUAVResources[1]);
  7240. CreateTypedUAV(pDevice, baseHandle, valueSize, DXGI_FORMAT_R32_FLOAT, pUAVResources[2]);
  7241. CreateTex1DUAV(pDevice, baseHandle, valueSize, DXGI_FORMAT_R32_FLOAT, pUAVResources[3]);
  7242. D3D12_FILTER filters[] = {D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D12_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT};
  7243. float borderColors[] = {30.0, 31.0};
  7244. CreateDefaultSamplers(pDevice, pSampHeap->GetCPUDescriptorHandleForHeapStart(),
  7245. filters, borderColors, NumSamplers);
  7246. // Run the compute shader and copy the results back to readable memory.
  7247. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  7248. RecordTransitionBarrier(pCommandList, pUAVResources[NumUAVs - 2], D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  7249. pCommandList->CopyResource(pReadBuffer, pUAVResources[NumUAVs - 2]);
  7250. pCommandList->Close();
  7251. ExecuteCommandList(pCommandQueue, pCommandList);
  7252. WaitForSignal(pCommandQueue, FO);
  7253. MappedData data(pReadBuffer, valueSize*sizeof(float));
  7254. const float *pData = (float*)data.data();
  7255. LogCommentFmt(L"Verify bound resources are properly selected");
  7256. VERIFY_ARE_EQUAL(pData[0], 10);
  7257. VERIFY_ARE_EQUAL(pData[1], 11);
  7258. VERIFY_ARE_EQUAL(pData[2], 12);
  7259. VERIFY_ARE_EQUAL(pData[3], 20);
  7260. VERIFY_ARE_EQUAL(pData[4], 21);
  7261. VERIFY_ARE_EQUAL(pData[5], 22);
  7262. VERIFY_ARE_EQUAL(pData[6], 30);
  7263. VERIFY_ARE_EQUAL(pData[7], 1); // samplecmp 1 means it matched 31
  7264. }
  7265. TEST_F(ExecutionTest, SignatureResourcesTest) {
  7266. std::string pShader =
  7267. "ByteAddressBuffer g_rawBuf : register(t0);\n"
  7268. "StructuredBuffer<float> g_structBuf : register(t1);\n"
  7269. "Texture2D<float> g_tex : register(t2);\n"
  7270. "RWByteAddressBuffer g_rwRawBuf : register(u0);\n"
  7271. "RWStructuredBuffer<float> g_rwStructBuf : register(u1);\n"
  7272. "RWBuffer<float> g_result : register(u2);\n"
  7273. "RWTexture1D<float> g_rwTex : register(u3);\n"
  7274. "SamplerState g_samp : register(s0);\n"
  7275. "SamplerComparisonState g_sampCmp : register(s1);\n"
  7276. "[NumThreads(1, 1, 1)]\n"
  7277. "void main(uint ix : SV_GroupIndex) {\n"
  7278. " g_result[0] = g_rawBuf.Load<float>(0);\n"
  7279. " g_result[1] = g_structBuf.Load(0);\n"
  7280. " g_result[2] = g_tex.Load(0);\n"
  7281. " g_result[3] = g_rwRawBuf.Load<float>(0);\n"
  7282. " g_result[4] = g_rwStructBuf.Load(0);\n"
  7283. " g_result[5] = g_rwTex.Load(0);\n"
  7284. " g_result[6] = g_tex.SampleLevel(g_samp, -0.5, 0);\n"
  7285. " g_result[7] = g_tex.SampleCmpLevelZero(g_sampCmp, -0.5, 31.0);\n"
  7286. "}\n";
  7287. CComPtr<ID3D12Device> pDevice;
  7288. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7289. return;
  7290. RunResourceTest(pDevice, pShader.c_str(), L"cs_6_6", /*isDynamic*/false);
  7291. }
  7292. TEST_F(ExecutionTest, DynamicResourcesTest) {
  7293. static const char pShader[] =
  7294. "static ByteAddressBuffer g_rawBuf = ResourceDescriptorHeap[0];\n"
  7295. "static StructuredBuffer<float> g_structBuf = ResourceDescriptorHeap[1];\n"
  7296. "static Texture2D<float> g_tex = ResourceDescriptorHeap[2];\n"
  7297. "static RWByteAddressBuffer g_rwRawBuf = ResourceDescriptorHeap[3];\n"
  7298. "static RWStructuredBuffer<float> g_rwStructBuf = ResourceDescriptorHeap[4];\n"
  7299. "static RWBuffer<float> g_result = ResourceDescriptorHeap[5];\n"
  7300. "static RWTexture1D<float> g_rwTex = ResourceDescriptorHeap[6];\n"
  7301. "static SamplerState g_samp = SamplerDescriptorHeap[0];\n"
  7302. "static SamplerComparisonState g_sampCmp = SamplerDescriptorHeap[1];\n"
  7303. "[NumThreads(1, 1, 1)]\n"
  7304. "void main(uint ix : SV_GroupIndex) {\n"
  7305. " g_result[0] = g_rawBuf.Load<float>(0);\n"
  7306. " g_result[1] = g_structBuf.Load(0);\n"
  7307. " g_result[2] = g_tex.Load(0);\n"
  7308. " g_result[3] = g_rwRawBuf.Load<float>(0);\n"
  7309. " g_result[4] = g_rwStructBuf.Load(0);\n"
  7310. " g_result[5] = g_rwTex.Load(0);\n"
  7311. " g_result[6] = g_tex.SampleLevel(g_samp, -0.5, 0);\n"
  7312. " g_result[7] = g_tex.SampleCmpLevelZero(g_sampCmp, -0.5, 31.0);\n"
  7313. "}\n";
  7314. CComPtr<ID3D12Device> pDevice;
  7315. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7316. return;
  7317. // ResourceDescriptorHeap/SamplerDescriptorHeap requires Resource Binding Tier 3
  7318. D3D12_FEATURE_DATA_D3D12_OPTIONS devOptions;
  7319. VERIFY_SUCCEEDED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS, &devOptions, sizeof(devOptions)));
  7320. if (devOptions.ResourceBindingTier < D3D12_RESOURCE_BINDING_TIER_3) {
  7321. WEX::Logging::Log::Comment(L"Device does not support Resource Binding Tier 3");
  7322. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7323. return;
  7324. }
  7325. RunResourceTest(pDevice, pShader, L"cs_6_6", /*isDynamic*/true);
  7326. }
  7327. #define MAX_WAVESIZE 128
  7328. #define strinfigy2(arg) #arg
  7329. #define strinfigy(arg) strinfigy2(arg)
  7330. void ExecutionTest::WaveSizeTest() {
  7331. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7332. CComPtr<ID3D12Device> pDevice;
  7333. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6)) {
  7334. return;
  7335. }
  7336. // Check Wave support
  7337. if (!DoesDeviceSupportWaveOps(pDevice)) {
  7338. // Optional feature, so it's correct to not support it if declared as such.
  7339. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  7340. return;
  7341. }
  7342. // Get supported wave sizes
  7343. D3D12_FEATURE_DATA_D3D12_OPTIONS1 waveOpts;
  7344. VERIFY_SUCCEEDED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &waveOpts, sizeof(waveOpts)));
  7345. UINT minWaveSize = waveOpts.WaveLaneCountMin;
  7346. UINT maxWaveSize = waveOpts.WaveLaneCountMax;
  7347. DXASSERT_NOMSG(minWaveSize <= maxWaveSize);
  7348. DXASSERT((minWaveSize & (minWaveSize - 1)) == 0, "must be a power of 2");
  7349. DXASSERT((maxWaveSize & (maxWaveSize - 1)) == 0, "must be a power of 2");
  7350. // read shader config
  7351. CComPtr<IStream> pStream;
  7352. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  7353. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7354. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7355. // format shader source
  7356. const char waveSizeTestShader[] =
  7357. "struct TestData { \r\n"
  7358. " uint count; \r\n"
  7359. "}; \r\n"
  7360. "RWStructuredBuffer<TestData> data : register(u0); \r\n"
  7361. "\r\n"
  7362. "// Note: WAVESIZE will be defined via compiler option -D\r\n"
  7363. "[wavesize(WAVESIZE)]\r\n"
  7364. "[numthreads(" strinfigy(MAX_WAVESIZE) "*2,1,1)]\r\n"
  7365. "void main(uint3 tid : SV_DispatchThreadID ) { \r\n"
  7366. " data[tid.x].count = WaveActiveSum(1); \r\n"
  7367. "}\r\n";
  7368. struct WaveSizeTestData {
  7369. uint32_t count;
  7370. };
  7371. for (UINT waveSize = minWaveSize; waveSize <= maxWaveSize; waveSize *= 2) {
  7372. // format compiler args
  7373. char compilerOptions[32];
  7374. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D WAVESIZE=%d", waveSize) != -1);
  7375. // run the shader
  7376. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "WaveSizeTest",
  7377. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  7378. VERIFY_IS_TRUE((0 == strncmp(Name, "UAVBuffer0", 10)));
  7379. pShaderOp->Shaders.at(0).Arguments = compilerOptions;
  7380. pShaderOp->Shaders.at(0).Text = waveSizeTestShader;
  7381. VERIFY_IS_TRUE(sizeof(WaveSizeTestData)*MAX_WAVESIZE <= Data.size());
  7382. WaveSizeTestData *pInData = (WaveSizeTestData *)Data.data();
  7383. memset(&pInData, sizeof(WaveSizeTestData)*MAX_WAVESIZE, 0);
  7384. }, ShaderOpSet);
  7385. // verify expected values
  7386. MappedData dataUav;
  7387. WaveSizeTestData *pOutData;
  7388. test->Test->GetReadBackData("UAVBuffer0", &dataUav);
  7389. VERIFY_ARE_EQUAL(sizeof(WaveSizeTestData)*MAX_WAVESIZE, dataUav.size());
  7390. pOutData = (WaveSizeTestData*)dataUav.data();
  7391. LogCommentFmt(L"Verifying test result for wave size %d", waveSize);
  7392. for (unsigned i = 0; i < MAX_WAVESIZE; i++) {
  7393. if (!VERIFY_ARE_EQUAL(pOutData[i].count, waveSize))
  7394. break;
  7395. }
  7396. }
  7397. }
  7398. // Atomic operation testing
  7399. // Atomic tests take a single integer index as input and contort it into some
  7400. // kind of interesting contributor to the operation in question.
  7401. // So each vertex, pixel, thread, or other will have a unique index that produces
  7402. // a contributing value to the calculation which is stored in a small resource
  7403. // For arithmetic or bitwise operations, each contributor accumulates to the same
  7404. // location in the resource indexed by the operation type. Addition is in index 0
  7405. // umin/umax are in 1 and 2 and so on.
  7406. // To make sure that the most significant bits are involved in the calculation,
  7407. // particularly in the case of 64-bit values, each contributing value is duplicated
  7408. // to the lower and upper halves of the value. There is an exception to this when
  7409. // addition exceeds the available size and also for compare and exchange explained below.
  7410. // For compare and exchange operations, 64 output locations are shared by the various lanes.
  7411. // Each lane attempts to write to a location that is shared with several others.
  7412. // The first one to write to it determines its contents, which will be the lane index <ix>
  7413. // in the upper bits and the output location index in the lower bits.
  7414. // This ensures that the compare operations consider the upper bits in the comparison.
  7415. // The initial compare store is followed by a compare exchange that compares for the
  7416. // value the current lane would have assigned there. Finally, the output of the cmpxchg
  7417. // is used to determine if the current lane should perform the final unconditional exchange.
  7418. // The values are verified by checking the lower bits for the matching location index
  7419. // and ensuring that the upper bits undergoing the same transformation result in the location index.
  7420. // For lane index <ix> the location is calculated and final result assigned as if by this code:
  7421. // g_outputBuf[(ix/3)%64] = (ix << shBits) | ((ix/3)%64);
  7422. bool AtomicResultMatches(const BYTE *uResults, uint64_t gold, size_t size) {
  7423. if (memcmp(uResults, &gold, size)) {
  7424. if (size == 4)
  7425. LogCommentFmt(L" value %d is not %d", ((uint32_t*)uResults)[0], (uint32_t)gold);
  7426. else
  7427. LogCommentFmt(L" value %lld is not %lld", ((uint64_t*)uResults)[0], gold);
  7428. return false;
  7429. }
  7430. return true;
  7431. }
  7432. // Used to duplicate the lower half bits into the upper half bits of an integer
  7433. // To verify that the full value is being considered, many tests duplicate the results into the upper half
  7434. #define SHIFT(val, bits) (((val)&((1ULL<<(bits))-1ULL)) | ((uint64_t)(val) << (bits)))
  7435. // Symbolic constants for the results
  7436. #define ADD_IDX 0
  7437. #define UMIN_IDX 1
  7438. #define UMAX_IDX 2
  7439. #define AND_IDX 3
  7440. #define OR_IDX 4
  7441. #define XOR_IDX 5
  7442. #define SMIN_IDX 0
  7443. #define SMAX_IDX 1
  7444. // Verify results for atomic operations. <uResults> and <sResults> are pointers to
  7445. // the readback resource sections containing unsigned and signed integers respectively.
  7446. // <pXchg> is a poiner to the readback resource containing the results of the compare
  7447. // and exchange operations tests. <stride> is the number of bytes between results for
  7448. // all of the results pointers. <maxIdx> is the number of indices that went into the results
  7449. // which is used to determine what the results should be. <bitSize> is the size in bits of
  7450. // the produced results, either 32 or 64.
  7451. void VerifyAtomicResults(const BYTE *uResults, const BYTE *sResults,
  7452. const BYTE *pXchg, size_t stride, uint64_t maxIdx, size_t bitSize) {
  7453. // Each atomic test performs the test on the value in the lower half
  7454. // and also duplicated in the upper half of the value. The SHIFT macros account for this.
  7455. // This is to verify that the upper bits are considered
  7456. uint64_t shBits = bitSize/2;
  7457. size_t byteSize = bitSize/8;
  7458. // Test ADD Operation
  7459. // ADD just sums all the indices. The result should the sum of the highest and lowest indices
  7460. // multiplied by half the number of sums.
  7461. uint64_t addResult = (maxIdx)*(maxIdx-1)/2;
  7462. LogCommentFmt(L"Verifying %d-bit integer atomic add", bitSize);
  7463. // For 32-bit values, the sum exceeds the 16 bit limit, so we can't duplicate
  7464. // That's fine, the duplication is really for 64-bit values.
  7465. if (bitSize < 64)
  7466. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*ADD_IDX, addResult, byteSize));
  7467. else
  7468. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*ADD_IDX, SHIFT(addResult, shBits), byteSize));
  7469. // Test MIN and MAX Operations
  7470. // The result of a simple min and max of any sequence of indices would be fairly uninteresting
  7471. // and certain erroneous behavior might mistakenly produce the correct results.
  7472. // To make it interesting, the contributing values will change depending on the evenness of the index.
  7473. // On an even index, min and max operate on the bitflipped index. For signed compares, this is
  7474. // interpretted as a negative value and for unsigned, a very high value.
  7475. // For unsigned min/max, index 0 will be bitflipped to ~0, which is interpretted as the maximum
  7476. // Because zero is manipulated, this leaves 1 as the lowest value.
  7477. LogCommentFmt(L"Verifying %d-bit integer atomic umin", bitSize);
  7478. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*UMIN_IDX, SHIFT(1ULL, shBits), byteSize)); // UMin
  7479. LogCommentFmt(L"Verifying %d-bit integer atomic umax", bitSize);
  7480. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*UMAX_IDX, ~0ULL, byteSize)); // UMax
  7481. // For signed min/max, the index just before the last will be bitflipped (maxIndex is always even).
  7482. // This is interpretted as -(maxIndex-1) and will be the lowest
  7483. // The maxIndex will be unaltered and interpretted as the highest.
  7484. LogCommentFmt(L"Verifying %d-bit integer atomic smin", bitSize);
  7485. VERIFY_IS_TRUE(AtomicResultMatches(sResults + stride*SMIN_IDX, SHIFT(-((int64_t)maxIdx-1), shBits), byteSize)); // SMin
  7486. LogCommentFmt(L"Verifying %d-bit integer atomic smax", bitSize);
  7487. VERIFY_IS_TRUE(AtomicResultMatches(sResults + stride*SMAX_IDX, SHIFT(maxIdx-1, shBits), byteSize)); // SMax
  7488. // Test AND and OR operations.
  7489. // For AND operations, all indices are bitflipped and ANDed to the previous result.
  7490. // This means that the highest bits, which are never set by the contributing indices will be set
  7491. // for all the indices, so they will be set in the final result.
  7492. // For OR operations, the indices are ORed to the previous result unaltered
  7493. // This means that any bit that is set in any index will be set in the final OR result.
  7494. // In practice, this means that the cumulative result of the AND and OR operations
  7495. // are bitflipped versions of each other.
  7496. // Finding the most significant set bit by the max index or next power of two (pot)
  7497. // gives us the pivot point for these results
  7498. uint64_t nextPot = 1ULL << (bitSize - 1);
  7499. for (;nextPot && !((maxIdx-1) & (nextPot)); nextPot >>= 1) {}
  7500. nextPot <<= 1;
  7501. LogCommentFmt(L"Verifying %d-bit integer atomic and", bitSize);
  7502. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*AND_IDX, ~SHIFT(nextPot-1, shBits), byteSize)); // And
  7503. LogCommentFmt(L"Verifying %d-bit integer atomic or", bitSize);
  7504. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*OR_IDX, SHIFT(nextPot-1, shBits), byteSize)); // Or
  7505. // Test XOR operation
  7506. // For XOR operations, a 1 is shifted by the number of spaces equal to the index and XORed
  7507. // to the previous result. Because this would rapidely shift off the end of the value,
  7508. // giving undefined and uninteresting results, the index is moduloed to a value that will
  7509. // fit within the type size.
  7510. // Because many of the tests use total numbers of lanes that can be evenly divisible by 32 or 64,
  7511. // these values aren't used for the modulo since the expected result might be zero,
  7512. // which could be encountered through erroneous behavior.
  7513. // Instead, one less than the type size in bits is used for the modulo.
  7514. // Even though we don't know the actual order these operations are performed,
  7515. // indices that make up a contiguous sequence of 31 or 63 values can be thought of as one of a series of "passes".
  7516. // Each "pass" sets or clears the bits depending on what's already there.
  7517. // if the number of the pass is odd, the bits are being unset and all above the mod position should be set.
  7518. // If even, the bits are in the process of being set and bits below the mod position should be set.
  7519. uint64_t xorResult = ((1ULL<<((maxIdx)%(bitSize-1))) -1);
  7520. if (((maxIdx/(bitSize-1))&1)) {
  7521. xorResult ^= ~0ULL;
  7522. // The XOR above may set uninvolved upper bits, messing up the compare. So AND off the uninvolved bits.
  7523. xorResult &= ((1ULL<<(bitSize-1)) - 1);
  7524. }
  7525. LogCommentFmt(L"Verifying %d-bit integer atomic xor", bitSize);
  7526. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*XOR_IDX, xorResult, byteSize));
  7527. // Test CMP/XCHG Operations
  7528. // This tests CompareStore, CompareExchange, and Exchange operations.
  7529. // Unlike above, every lane isn't contributing to the same resource location
  7530. // Instead, every lane competes with a few others to update the same resource location.
  7531. // The first lane to find the contents of their location uninitialized will
  7532. // update it. To verify that upper bits are considered in the comparison and
  7533. // in the assignment, the value stored in the lowest bits is the location index.
  7534. // This ensures that part will be the same for each of the competing lanes.
  7535. // The uppermost bits are updated with the index of the lane that got there first.
  7536. // Subsequent calls to CompareExchange will verify this value matches and alter
  7537. // the content slightly. Finally, a simple check of the output value to what
  7538. // the current lane would expect and a call to exchange will update the value once more
  7539. // To verify this has gone through properly, the upper portion is converted as
  7540. // if to calculate the location index and compared with the location index.
  7541. // It could be the index of any of several lanes that assign to that location,
  7542. // but this ensures that it is not any lane outside of that group.
  7543. // The lower bits are compared to the location index as well.
  7544. LogCommentFmt(L"Verifying %d-bit integer atomic cmp/xchg results", bitSize);
  7545. for (size_t i = 0; i < 64; i++) {
  7546. uint64_t val = *((uint64_t*)(pXchg + i*stride));
  7547. // Verify lower bits match location index exactly
  7548. VERIFY_ARE_EQUAL(i, val & ((1ULL << shBits) - 1ULL));
  7549. // Verify that upper bits contain original index that transforms to location index
  7550. VERIFY_ARE_EQUAL(((val >> shBits)/3)%64, i);
  7551. }
  7552. }
  7553. void VerifyAtomicsRawTest(std::shared_ptr<ShaderOpTestResult> test,
  7554. uint64_t maxIdx, size_t bitSize) {
  7555. size_t stride = 8;
  7556. // struct mirroring that in the shader
  7557. struct AtomicStuff {
  7558. float prepad[2][3];
  7559. UINT uintEl[4];
  7560. int sintEl[4];
  7561. struct useless {
  7562. uint32_t unused[3];
  7563. } postpad;
  7564. float last;
  7565. };
  7566. MappedData uintData, xchgData;
  7567. test->Test->GetReadBackData("U0", &uintData);
  7568. test->Test->GetReadBackData("U1", &xchgData);
  7569. const AtomicStuff *pStruct = (AtomicStuff *)uintData.data();
  7570. const AtomicStuff *pStrXchg = (AtomicStuff *)xchgData.data();
  7571. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWStructuredBuffer resource", bitSize);
  7572. VerifyAtomicResults((const BYTE*)&(pStruct[0].uintEl[2]), (const BYTE*)&(pStruct[1].sintEl[2]),
  7573. (const BYTE*)&(pStrXchg[0].uintEl[2]), sizeof(AtomicStuff), maxIdx, bitSize);
  7574. const BYTE *pUint = nullptr;
  7575. const BYTE *pXchg = nullptr;
  7576. test->Test->GetReadBackData("U2", &uintData);
  7577. test->Test->GetReadBackData("U3", &xchgData);
  7578. pUint = (BYTE *)uintData.data();
  7579. pXchg = (BYTE *)xchgData.data();
  7580. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWByteAddressBuffer resource", bitSize);
  7581. VerifyAtomicResults(pUint, pUint + stride*6,
  7582. pXchg, stride, maxIdx, bitSize);
  7583. }
  7584. void VerifyAtomicsTypedTest(std::shared_ptr<ShaderOpTestResult> test,
  7585. uint64_t maxIdx, size_t bitSize) {
  7586. size_t stride = 8;
  7587. MappedData uintData, sintData, xchgData;
  7588. const BYTE *pUint = nullptr;
  7589. const BYTE *pSint = nullptr;
  7590. const BYTE *pXchg = nullptr;
  7591. // Typed resources can't share between 32 and 64 bits
  7592. if (bitSize == 32) {
  7593. test->Test->GetReadBackData("U6", &uintData);
  7594. test->Test->GetReadBackData("U7", &sintData);
  7595. test->Test->GetReadBackData("U8", &xchgData);
  7596. } else {
  7597. test->Test->GetReadBackData("U12", &uintData);
  7598. test->Test->GetReadBackData("U13", &sintData);
  7599. test->Test->GetReadBackData("U14", &xchgData);
  7600. }
  7601. pUint = (BYTE *)uintData.data();
  7602. pSint = (BYTE *)sintData.data();
  7603. pXchg = (BYTE *)xchgData.data();
  7604. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWBuffer resource", bitSize);
  7605. VerifyAtomicResults(pUint, pSint + stride, pXchg, stride, maxIdx, bitSize);
  7606. // Typed resources can't share between 32 and 64 bits
  7607. if (bitSize == 32) {
  7608. test->Test->GetReadBackData("U9", &uintData);
  7609. test->Test->GetReadBackData("U10", &sintData);
  7610. test->Test->GetReadBackData("U11", &xchgData);
  7611. } else {
  7612. test->Test->GetReadBackData("U15", &uintData);
  7613. test->Test->GetReadBackData("U16", &sintData);
  7614. test->Test->GetReadBackData("U17", &xchgData);
  7615. }
  7616. pUint = (BYTE *)uintData.data();
  7617. pSint = (BYTE *)sintData.data();
  7618. pXchg = (BYTE *)xchgData.data();
  7619. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWTexture resource", bitSize);
  7620. VerifyAtomicResults(pUint, pSint + stride, pXchg, stride, maxIdx, bitSize);
  7621. }
  7622. void VerifyAtomicsSharedTest(std::shared_ptr<ShaderOpTestResult> test,
  7623. uint64_t maxIdx, size_t bitSize) {
  7624. size_t stride = 8;
  7625. MappedData uintData, xchgData;
  7626. const BYTE *pUint = nullptr;
  7627. const BYTE *pXchg = nullptr;
  7628. test->Test->GetReadBackData("U4", &uintData);
  7629. test->Test->GetReadBackData("U5", &xchgData);
  7630. pUint = (BYTE *)uintData.data();
  7631. pXchg = (BYTE *)xchgData.data();
  7632. LogCommentFmt(L"Verifying %d-bit integer atomic operations on groupshared variables", bitSize);
  7633. VerifyAtomicResults(pUint, pUint + stride*6,
  7634. pXchg, stride, maxIdx, bitSize);
  7635. }
  7636. void VerifyAtomicsTest(std::shared_ptr<ShaderOpTestResult> test,
  7637. uint64_t maxIdx, size_t bitSize) {
  7638. VerifyAtomicsRawTest(test, maxIdx, bitSize);
  7639. VerifyAtomicsTypedTest(test, maxIdx, bitSize);
  7640. }
  7641. TEST_F(ExecutionTest, AtomicsTest) {
  7642. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7643. CComPtr<IStream> pStream;
  7644. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7645. CComPtr<ID3D12Device> pDevice;
  7646. if (!CreateDevice(&pDevice))
  7647. return;
  7648. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7649. std::make_shared<st::ShaderOpSet>();
  7650. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7651. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("AtomicsHeap");
  7652. // Test compute shader
  7653. LogCommentFmt(L"Verifying 32-bit integer atomic operations in compute shader");
  7654. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsHeap", nullptr, ShaderOpSet);
  7655. VerifyAtomicsTest(test, 32*32, 32);
  7656. VerifyAtomicsSharedTest(test, 32*32, 32);
  7657. // Test mesh shader if available
  7658. pShaderOp->CS = nullptr;
  7659. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7660. LogCommentFmt(L"Verifying 32-bit integer atomic operations in amp/mesh/pixel shaders");
  7661. test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsHeap", nullptr, ShaderOpSet);
  7662. VerifyAtomicsTest(test, 8*8*2 + 8*8*2 + 64*64, 32);
  7663. VerifyAtomicsSharedTest(test, 8*8*2 + 8*8*2, 32);
  7664. }
  7665. // Test Vertex + Pixel shader
  7666. pShaderOp->MS = nullptr;
  7667. LogCommentFmt(L"Verifying 32-bit integer atomic operations in vert/pixel shaders");
  7668. test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsHeap", nullptr, ShaderOpSet);
  7669. VerifyAtomicsTest(test, 64*64+6, 32);
  7670. }
  7671. TEST_F(ExecutionTest, Atomics64Test) {
  7672. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7673. CComPtr<IStream> pStream;
  7674. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7675. CComPtr<ID3D12Device> pDevice;
  7676. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7677. return;
  7678. if (!DoesDeviceSupportInt64(pDevice)) {
  7679. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  7680. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7681. return;
  7682. }
  7683. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7684. std::make_shared<st::ShaderOpSet>();
  7685. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7686. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("AtomicsRoot");
  7687. // Reassign shader stages to 64-bit versions
  7688. // Collect 64-bit shaders
  7689. LPCSTR CS64 = nullptr, VS64 = nullptr, PS64 = nullptr;
  7690. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7691. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7692. if (!strcmp(S.Name, "CS")) CS64 = S.Name;
  7693. if (!strcmp(S.Name, "VS")) VS64 = S.Name;
  7694. if (!strcmp(S.Name, "PS")) PS64 = S.Name;
  7695. if (!strcmp(S.Name, "AS")) AS64 = S.Name;
  7696. if (!strcmp(S.Name, "MS")) MS64 = S.Name;
  7697. }
  7698. pShaderOp->CS = CS64;
  7699. pShaderOp->VS = VS64;
  7700. pShaderOp->PS = PS64;
  7701. pShaderOp->AS = AS64;
  7702. pShaderOp->MS = MS64;
  7703. // Test compute shader
  7704. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in compute shader");
  7705. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsRoot", nullptr, ShaderOpSet);
  7706. VerifyAtomicsRawTest(test, 32*32, 64);
  7707. // Test mesh shader if available
  7708. pShaderOp->CS = nullptr;
  7709. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7710. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in amp/mesh/pixel shader");
  7711. test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsRoot", nullptr, ShaderOpSet);
  7712. VerifyAtomicsRawTest(test, 8*8*2 + 8*8*2 + 64*64, 64);
  7713. }
  7714. // Test Vertex + Pixel shader
  7715. pShaderOp->MS = nullptr;
  7716. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in vert/pixel shader");
  7717. test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsRoot", nullptr, ShaderOpSet);
  7718. VerifyAtomicsRawTest(test, 64*64+6, 64);
  7719. }
  7720. TEST_F(ExecutionTest, AtomicsRawHeap64Test) {
  7721. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7722. CComPtr<IStream> pStream;
  7723. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7724. CComPtr<ID3D12Device> pDevice;
  7725. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7726. return;
  7727. if (!DoesDeviceSupportInt64(pDevice)) {
  7728. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  7729. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7730. return;
  7731. }
  7732. if (!DoesDeviceSupportHeap64Atomics(pDevice)) {
  7733. WEX::Logging::Log::Comment(L"Device does not support 64-bit atomic operations on heap resources.");
  7734. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7735. return;
  7736. }
  7737. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7738. std::make_shared<st::ShaderOpSet>();
  7739. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7740. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("AtomicsHeap");
  7741. // Reassign shader stages to 64-bit versions
  7742. // Collect 64-bit shaders
  7743. LPCSTR CS64 = nullptr, VS64 = nullptr, PS64 = nullptr;
  7744. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7745. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7746. if (!strcmp(S.Name, "CS64")) CS64 = S.Name;
  7747. if (!strcmp(S.Name, "VS64")) VS64 = S.Name;
  7748. if (!strcmp(S.Name, "PS64")) PS64 = S.Name;
  7749. if (!strcmp(S.Name, "AS64")) AS64 = S.Name;
  7750. if (!strcmp(S.Name, "MS64")) MS64 = S.Name;
  7751. }
  7752. pShaderOp->CS = CS64;
  7753. pShaderOp->VS = VS64;
  7754. pShaderOp->PS = PS64;
  7755. pShaderOp->AS = AS64;
  7756. pShaderOp->MS = MS64;
  7757. // Test compute shader
  7758. LogCommentFmt(L"Verifying 64-bit integer atomic operations on heap raw buffers in compute shader");
  7759. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsHeap", nullptr, ShaderOpSet);
  7760. VerifyAtomicsRawTest(test, 32*32, 64);
  7761. // Test mesh shader if available
  7762. pShaderOp->CS = nullptr;
  7763. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7764. LogCommentFmt(L"Verifying 64-bit integer atomic operations on heap raw buffers in amp/mesh/pixel shader");
  7765. test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsHeap", nullptr, ShaderOpSet);
  7766. VerifyAtomicsRawTest(test, 8*8*2 + 8*8*2 + 64*64, 64);
  7767. }
  7768. // Test Vertex + Pixel shader
  7769. pShaderOp->MS = nullptr;
  7770. LogCommentFmt(L"Verifying 64-bit integer atomic operations on heap raw buffers in vert/pixel shader");
  7771. test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsHeap", nullptr, ShaderOpSet);
  7772. VerifyAtomicsRawTest(test, 64*64+6, 64);
  7773. }
  7774. TEST_F(ExecutionTest, AtomicsTyped64Test) {
  7775. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7776. CComPtr<IStream> pStream;
  7777. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7778. CComPtr<ID3D12Device> pDevice;
  7779. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7780. return;
  7781. if (!DoesDeviceSupportInt64(pDevice)) {
  7782. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  7783. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7784. return;
  7785. }
  7786. if (!DoesDeviceSupportTyped64Atomics(pDevice)) {
  7787. WEX::Logging::Log::Comment(L"Device does not support int64 atomic operations on typed resources.");
  7788. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7789. return;
  7790. }
  7791. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7792. std::make_shared<st::ShaderOpSet>();
  7793. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7794. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("AtomicsHeap");
  7795. // Reassign shader stages to 64-bit versions
  7796. // Collect 64-bit shaders
  7797. LPCSTR CS64 = nullptr, VS64 = nullptr, PS64 = nullptr;
  7798. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7799. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7800. if (!strcmp(S.Name, "CSTY64")) CS64 = S.Name;
  7801. if (!strcmp(S.Name, "VSTY64")) VS64 = S.Name;
  7802. if (!strcmp(S.Name, "PSTY64")) PS64 = S.Name;
  7803. if (!strcmp(S.Name, "ASTY64")) AS64 = S.Name;
  7804. if (!strcmp(S.Name, "MSTY64")) MS64 = S.Name;
  7805. }
  7806. pShaderOp->CS = CS64;
  7807. pShaderOp->VS = VS64;
  7808. pShaderOp->PS = PS64;
  7809. pShaderOp->AS = AS64;
  7810. pShaderOp->MS = MS64;
  7811. // Test compute shader
  7812. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in compute shader");
  7813. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsHeap", nullptr, ShaderOpSet);
  7814. VerifyAtomicsTypedTest(test, 32*32, 64);
  7815. // Test mesh shader if available
  7816. pShaderOp->CS = nullptr;
  7817. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7818. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in amp/mesh/pixel shader");
  7819. test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsHeap", nullptr, ShaderOpSet);
  7820. VerifyAtomicsTypedTest(test, 8*8*2 + 8*8*2 + 64*64, 64);
  7821. }
  7822. // Test Vertex + Pixel shader
  7823. pShaderOp->MS = nullptr;
  7824. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in vert/pixel shader");
  7825. test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsHeap", nullptr, ShaderOpSet);
  7826. VerifyAtomicsTypedTest(test, 64*64+6, 64);
  7827. }
  7828. TEST_F(ExecutionTest, AtomicsShared64Test) {
  7829. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7830. CComPtr<IStream> pStream;
  7831. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7832. CComPtr<ID3D12Device> pDevice;
  7833. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7834. return;
  7835. if (!DoesDeviceSupportInt64(pDevice)) {
  7836. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  7837. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7838. return;
  7839. }
  7840. if (!DoesDeviceSupportShared64Atomics(pDevice)) {
  7841. WEX::Logging::Log::Comment(L"Device does not support int64 atomic operations on groupshared variables.");
  7842. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7843. return;
  7844. }
  7845. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7846. std::make_shared<st::ShaderOpSet>();
  7847. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7848. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("AtomicsRoot");
  7849. // Reassign shader stages to 64-bit versions
  7850. // Collect 64-bit shaders
  7851. LPCSTR CS64 = nullptr, PS64 = nullptr;
  7852. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7853. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7854. if (!strcmp(S.Name, "CSSH64")) CS64 = S.Name;
  7855. if (!strcmp(S.Name, "CSSH64")) CS64 = S.Name;
  7856. if (!strcmp(S.Name, "PS64")) PS64 = S.Name;
  7857. if (!strcmp(S.Name, "ASSH64")) AS64 = S.Name;
  7858. if (!strcmp(S.Name, "MSSH64")) MS64 = S.Name;
  7859. }
  7860. pShaderOp->CS = CS64;
  7861. pShaderOp->PS = PS64;
  7862. pShaderOp->AS = AS64;
  7863. pShaderOp->MS = MS64;
  7864. LogCommentFmt(L"Verifying 64-bit integer atomic operations on groupshared variables in compute shader");
  7865. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsRoot", nullptr, ShaderOpSet);
  7866. VerifyAtomicsSharedTest(test, 32*32, 64);
  7867. // Test mesh shader if available
  7868. pShaderOp->CS = nullptr;
  7869. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7870. LogCommentFmt(L"Verifying 64-bit integer atomic operations on groupshared variables in amp/mesh/pixel shader");
  7871. test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsRoot", nullptr, ShaderOpSet);
  7872. VerifyAtomicsSharedTest(test, 8*8*2 + 8*8*2, 64);
  7873. }
  7874. }
  7875. // Float Atomics
  7876. // These operations are almost the same as for the 32-bit and 64-bit integer tests
  7877. // The difference is that there is no need to verify the upper bits.
  7878. // So there is no storing of different parts in upper and lower halves.
  7879. // Additionally, the only operations that are supported on floats
  7880. // are compare and exchange operations. So that's all that is tested here.
  7881. // Just as above, a number of lanes are assigned the same output value.
  7882. // Unlike above, one location is needed for the result of the special NaN test
  7883. // For this reason, the conversion is reduced by one and shifted by one to leave
  7884. // the zero-indexed location available.
  7885. // Verify results for a particular set of atomics results
  7886. void VerifyAtomicFloatResults(const float *results) {
  7887. // The first entry is for NaN to ensure that compares between NaNs succeed
  7888. // The sentinal value is 0.123, for which this compare is sufficient.
  7889. VERIFY_IS_TRUE(results[0] >= 0.120 && results[0] < 0.125);
  7890. // Start at 1 because 0 is just for NaN tests
  7891. for (int i = 1; i < 64; i++) {
  7892. VERIFY_ARE_EQUAL((int(results[i])/3)%63 + 1, i);
  7893. }
  7894. }
  7895. void VerifyAtomicsFloatSharedTest(std::shared_ptr<ShaderOpTestResult> test) {
  7896. MappedData Data;
  7897. const float *pData = nullptr;
  7898. test->Test->GetReadBackData("U4", &Data);
  7899. pData = (float *)Data.data();
  7900. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on groupshared variables");
  7901. VerifyAtomicFloatResults(pData);
  7902. }
  7903. void VerifyAtomicsFloatTest(std::shared_ptr<ShaderOpTestResult> test) {
  7904. // struct mirroring that in the shader
  7905. struct AtomicStuff {
  7906. float prepad[2][3];
  7907. float fltEl[2];
  7908. struct useless {
  7909. uint32_t unused[3];
  7910. } postpad;
  7911. };
  7912. // Test Compute Shader
  7913. MappedData Data;
  7914. const float *pData = nullptr;
  7915. test->Test->GetReadBackData("U0", &Data);
  7916. const AtomicStuff *pStructData = (AtomicStuff *)Data.data();
  7917. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWStructuredBuffer resources");
  7918. VERIFY_IS_TRUE(pStructData[0].fltEl[1] >= 0.120 && pStructData[0].fltEl[1] < 0.125);
  7919. for (int i = 1; i < 64; i++) {
  7920. VERIFY_ARE_EQUAL((int(pStructData[i].fltEl[1])/3)%63 + 1, i);
  7921. }
  7922. test->Test->GetReadBackData("U1", &Data);
  7923. pData = (float *)Data.data();
  7924. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWByteAddressBuffer resources");
  7925. VerifyAtomicFloatResults(pData);
  7926. test->Test->GetReadBackData("U2", &Data);
  7927. pData = (float *)Data.data();
  7928. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWBuffer resources");
  7929. VerifyAtomicFloatResults(pData);
  7930. test->Test->GetReadBackData("U3", &Data);
  7931. pData = (float *)Data.data();
  7932. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWTexture resources");
  7933. VerifyAtomicFloatResults(pData);
  7934. }
  7935. TEST_F(ExecutionTest, AtomicsFloatTest) {
  7936. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7937. CComPtr<IStream> pStream;
  7938. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7939. CComPtr<ID3D12Device> pDevice;
  7940. if (!CreateDevice(&pDevice))
  7941. return;
  7942. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7943. std::make_shared<st::ShaderOpSet>();
  7944. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7945. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("FloatAtomics");
  7946. // Test compute shader
  7947. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in compute shader");
  7948. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7949. VerifyAtomicsFloatTest(test);
  7950. VerifyAtomicsFloatSharedTest(test);
  7951. // Test mesh shader if available
  7952. pShaderOp->CS = nullptr;
  7953. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7954. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in amp/mesh/pixel shaders");
  7955. test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7956. VerifyAtomicsFloatTest(test);
  7957. VerifyAtomicsFloatSharedTest(test);
  7958. }
  7959. // Test Vertex + Pixel shader
  7960. pShaderOp->MS = nullptr;
  7961. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in vert/pixel shaders");
  7962. test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7963. VerifyAtomicsFloatTest(test);
  7964. }
  7965. // The IsHelperLane test renders 3-pixel triangle into 16x16 render target restricted
  7966. // to 2x2 viewport alligned at (0,0) which guarantees it will run in a single quad.
  7967. //
  7968. // Pixels to be rendered*
  7969. // (0,0)* (0,1)*
  7970. // (1,0) (1,1)*
  7971. //
  7972. // Pixel (1,0) is not rendered and is in helper lane.
  7973. //
  7974. // Each thread will use ddx_fine and ddy_fine to read the IsHelperLane() values from other threads.
  7975. // The bottom right pixel will write the results into the UAV buffer.
  7976. //
  7977. // Then the top level pixel (0,0) is discarded and the process above is repeated.
  7978. //
  7979. // Runs with shader models 6.0 and 6.6 to test both the HLSL built-in IsHelperLane fallback
  7980. // function (sm <= 6.5) and the IsHelperLane intrisics (sm >= 6.6).
  7981. //
  7982. TEST_F(ExecutionTest, HelperLaneTest) {
  7983. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7984. CComPtr<IStream> pStream;
  7985. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7986. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  7987. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7988. #ifdef ISHELPERLANE_PLACEHOLDER
  7989. string args = "-DISHELPERLANE_PLACEHOLDER";
  7990. #else
  7991. string args = "";
  7992. #endif
  7993. D3D_SHADER_MODEL TestShaderModels[] = { D3D_SHADER_MODEL_6_0, D3D_SHADER_MODEL_6_6 };
  7994. for (unsigned i = 0; i < _countof(TestShaderModels); i++) {
  7995. D3D_SHADER_MODEL sm = TestShaderModels[i];
  7996. LogCommentFmt(L"Verifying IsHelperLane in shader model 6.%1u", ((UINT)sm & 0x0f));
  7997. CComPtr<ID3D12Device> pDevice;
  7998. if (!CreateDevice(&pDevice, sm, false /* skipUnsupported */))
  7999. continue;
  8000. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "HelperLaneTestNoWave",
  8001. // this callbacked is called when the test is creating the resource to run the test
  8002. [&](LPCSTR Name, std::vector<BYTE>& Data, st::ShaderOp* pShaderOp) {
  8003. VERIFY_IS_TRUE(0 == _stricmp(Name, "UAVBuffer0"));
  8004. std::fill(Data.begin(), Data.end(), (BYTE)0xCC);
  8005. pShaderOp->Shaders.at(0).Arguments = args.c_str();
  8006. pShaderOp->Shaders.at(1).Arguments = args.c_str();
  8007. }, ShaderOpSet);
  8008. struct HelperLaneTestResult {
  8009. int32_t is_helper_00;
  8010. int32_t is_helper_10;
  8011. int32_t is_helper_01;
  8012. int32_t is_helper_11;
  8013. };
  8014. MappedData uavData;
  8015. test->Test->GetReadBackData("UAVBuffer0", &uavData);
  8016. HelperLaneTestResult* pTestResults = (HelperLaneTestResult*)uavData.data();
  8017. MappedData renderData;
  8018. test->Test->GetReadBackData("RTarget", &renderData);
  8019. const uint32_t* pPixels = (uint32_t*)renderData.data();
  8020. // before discard
  8021. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_00, 0);
  8022. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_10, 0);
  8023. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_01, 1);
  8024. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_11, 0);
  8025. // after discard
  8026. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_00, 1);
  8027. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_10, 0);
  8028. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_01, 1);
  8029. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_11, 0);
  8030. UNREFERENCED_PARAMETER(pPixels);
  8031. }
  8032. }
  8033. struct HelperLaneWaveTestResult60 {
  8034. // 6.0 wave ops
  8035. int32_t anyTrue;
  8036. int32_t allTrue;
  8037. XMUINT4 ballot;
  8038. int32_t waterfallLoopCount;
  8039. int32_t allEqual;
  8040. int32_t countBits;
  8041. int32_t sum;
  8042. int32_t product;
  8043. int32_t bitAnd;
  8044. int32_t bitOr;
  8045. int32_t bitXor;
  8046. int32_t min;
  8047. int32_t max;
  8048. int32_t prefixCountBits;
  8049. int32_t prefixProduct;
  8050. int32_t prefixSum;
  8051. };
  8052. struct HelperLaneQuadTestResult {
  8053. int32_t is_helper_this;
  8054. int32_t is_helper_across_X;
  8055. int32_t is_helper_across_Y;
  8056. int32_t is_helper_across_Diag;
  8057. };
  8058. struct HelperLaneWaveTestResult65 {
  8059. // 6.5 wave ops
  8060. XMUINT4 match;
  8061. int32_t mpCountBits;
  8062. int32_t mpSum;
  8063. int32_t mpProduct;
  8064. int32_t mpBitAnd;
  8065. int32_t mpBitOr;
  8066. int32_t mpBitXor;
  8067. };
  8068. struct HelperLaneWaveTestResult {
  8069. HelperLaneWaveTestResult60 sm60;
  8070. HelperLaneQuadTestResult sm60_quad;
  8071. HelperLaneWaveTestResult65 sm65;
  8072. };
  8073. struct foo { int32_t a; int32_t b; int32_t c; };
  8074. struct bar { foo f; int32_t d; XMUINT4 g; };
  8075. foo f = {1, 2, 3};
  8076. bar b = { { 1, 2, 3 }, 0, { 1, 2, 3, 4 } };
  8077. HelperLaneWaveTestResult HelperLane_CS_ExpectedResults = {
  8078. // HelperLaneWaveTestResult60
  8079. { 0, 1, { 0x7, 0, 0, 0 }, 3, 1, 3, 12, 64, 1, 0, 0, 10, 1, 2, 16, 4 },
  8080. // HelperLaneQuadTestResult
  8081. { 0, 0, 0, 0 },
  8082. // HelperLaneWaveTestResult65
  8083. { {0x7, 0, 0, 0}, 2, 4, 16, 1, 0, 0 }
  8084. };
  8085. HelperLaneWaveTestResult HelperLane_VS_ExpectedResults = HelperLane_CS_ExpectedResults;
  8086. HelperLaneWaveTestResult HelperLane_PS_ExpectedResults = {
  8087. // HelperLaneWaveTestResult60
  8088. { 0, 1, { 0xB, 0, 0, 0 }, 3, 1, 3, 12, 64, 1, 0, 0, 10, 1, 2, 16, 4 },
  8089. // HelperLaneQuadTestResult
  8090. { 0, 1, 0, 0 },
  8091. // HelperLaneWaveTestResult65
  8092. { {0xB, 0, 0, 0}, 2, 4, 16, 1, 0, 0 }
  8093. };
  8094. HelperLaneWaveTestResult HelperLane_PSAfterDiscard_ExpectedResults = {
  8095. // HelperLaneWaveTestResult60
  8096. { 0, 1, { 0xA, 0, 0, 0 }, 2, 1, 2, 8, 16, 1, 0, 0, 10, 1, 1, 4, 2 },
  8097. // HelperLaneQuadTestResult
  8098. { 0, 1, 0, 1 },
  8099. // HelperLaneWaveTestResult65
  8100. { {0xA, 0, 0, 0}, 1, 2, 4, 1, 0, 0 }
  8101. };
  8102. bool HelperLaneResultLogAndVerify(const wchar_t* testDesc, uint32_t expectedValue, uint32_t actualValue) {
  8103. bool matches = (expectedValue == actualValue);
  8104. LogCommentFmt(L"%s%s, expected = %u, actual = %u", matches ? L" - " : L"FAILED: ", testDesc, expectedValue, actualValue);
  8105. return matches;
  8106. }
  8107. bool HelperLaneResultLogAndVerify(const wchar_t* testDesc, XMUINT4 expectedValue, XMUINT4 actualValue) {
  8108. bool matches = (expectedValue.x == actualValue.x && expectedValue.y == actualValue.y &&
  8109. expectedValue.z == actualValue.z && expectedValue.w == actualValue.w);
  8110. 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,
  8111. expectedValue.x, expectedValue.y, expectedValue.z, expectedValue.w, actualValue.x, actualValue.y, actualValue.z, actualValue.w);
  8112. return matches;
  8113. }
  8114. bool VerifyHelperLaneWaveResults(ExecutionTest::D3D_SHADER_MODEL sm, HelperLaneWaveTestResult& testResults, HelperLaneWaveTestResult& expectedResults, bool verifyQuads) {
  8115. bool passed = true;
  8116. {
  8117. HelperLaneWaveTestResult60& tr60 = testResults.sm60;
  8118. HelperLaneWaveTestResult60& tr60exp = expectedResults.sm60;
  8119. passed &= HelperLaneResultLogAndVerify(L"WaveActiveAnyTrue(IsHelperLane())", tr60exp.anyTrue, tr60.anyTrue);
  8120. passed &= HelperLaneResultLogAndVerify(L"WaveActiveAllTrue(!IsHelperLane())", tr60exp.allTrue, tr60.allTrue);
  8121. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBallot(true) has exactly 3 bits set", tr60exp.ballot, tr60.ballot);
  8122. passed &= HelperLaneResultLogAndVerify(L"!WaveReadLaneFirst(IsHelperLane()) && WaveIsFirstLane() in a waterfall loop", tr60exp.waterfallLoopCount, tr60.waterfallLoopCount);
  8123. passed &= HelperLaneResultLogAndVerify(L"WaveActiveAllEqual(IsHelperLane())", tr60exp.allEqual, tr60.allEqual);
  8124. passed &= HelperLaneResultLogAndVerify(L"WaveActiveCountBits(true)", tr60exp.countBits, tr60.countBits);
  8125. passed &= HelperLaneResultLogAndVerify(L"WaveActiveSum(4)", tr60exp.sum, tr60.sum);
  8126. passed &= HelperLaneResultLogAndVerify(L"WaveActiveProduct(4)", tr60exp.product, tr60.product);
  8127. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBitAnd(!IsHelperLane())", tr60exp.bitAnd, tr60.bitAnd);
  8128. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBitOr(IsHelperLane())", tr60exp.bitOr, tr60.bitOr);
  8129. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBitXor(IsHelperLane())", tr60exp.bitXor, tr60.bitXor);
  8130. passed &= HelperLaneResultLogAndVerify(L"WaveActiveMin(IsHelperLane() ? 1 : 10)", tr60exp.min, tr60.min);
  8131. passed &= HelperLaneResultLogAndVerify(L"WaveActiveMax(IsHelperLane() ? 10 : 1)", tr60exp.max, tr60.max);
  8132. passed &= HelperLaneResultLogAndVerify(L"WavePrefixCountBits(1)", tr60exp.prefixCountBits, tr60.prefixCountBits);
  8133. passed &= HelperLaneResultLogAndVerify(L"WavePrefixProduct(4)", tr60exp.prefixProduct, tr60.prefixProduct);
  8134. passed &= HelperLaneResultLogAndVerify(L"WavePrefixSum(2)", tr60exp.prefixSum, tr60.prefixSum);
  8135. }
  8136. if (verifyQuads) {
  8137. HelperLaneQuadTestResult& quad_tr = testResults.sm60_quad;
  8138. HelperLaneQuadTestResult& quad_tr_exp = expectedResults.sm60_quad;
  8139. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 3 / pixel (1,1) - IsHelperLane()", quad_tr_exp.is_helper_this, quad_tr.is_helper_this);
  8140. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 2 / pixel (0,1) - IsHelperLane()", quad_tr_exp.is_helper_across_X, quad_tr.is_helper_across_X);
  8141. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 1 / pixel (1,0) - IsHelperLane()", quad_tr_exp.is_helper_across_Y, quad_tr.is_helper_across_Y);
  8142. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 0 / pixel (0,0) - IsHelperLane()", quad_tr_exp.is_helper_across_Diag, quad_tr.is_helper_across_Diag);
  8143. }
  8144. if (sm >= D3D_SHADER_MODEL_6_5) {
  8145. HelperLaneWaveTestResult65& tr65 = testResults.sm65;
  8146. HelperLaneWaveTestResult65& tr65exp = expectedResults.sm65;
  8147. passed &= HelperLaneResultLogAndVerify(L"WaveMatch(true) has exactly 3 bits set", tr65exp.match, tr65.match);
  8148. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixCountBits(1, no_masked_bits)", tr65exp.mpCountBits, tr65.mpCountBits);
  8149. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixSum(2, no_masked_bits)", tr65exp.mpSum, tr65.mpSum);
  8150. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixProduct(4, no_masked_bits)", tr65exp.mpProduct, tr65.mpProduct);
  8151. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixAnd(IsHelperLane() ? 0 : 1, no_masked_bits)", tr65exp.mpBitAnd, tr65.mpBitAnd);
  8152. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixOr(IsHelperLane() ? 1 : 0, no_masked_bits)", tr65exp.mpBitOr, tr65.mpBitOr);
  8153. passed &= HelperLaneResultLogAndVerify(L"verify WaveMultiPrefixXor(IsHelperLane() ? 1 : 0, no_masked_bits)", tr65exp.mpBitXor, tr65.mpBitXor);
  8154. }
  8155. return passed;
  8156. }
  8157. void CleanUAVBuffer0Buffer(LPCSTR BufferName, std::vector<BYTE>& Data, st::ShaderOp* pShaderOp) {
  8158. UNREFERENCED_PARAMETER(pShaderOp);
  8159. VERIFY_IS_TRUE(0 == _stricmp(BufferName, "UAVBuffer0"));
  8160. std::fill(Data.begin(), Data.end(), (BYTE)0xCC);
  8161. }
  8162. //
  8163. // The IsHelperLane test that use Wave intrinsics to verify IsHelperLane() and Wave operations on active lanes.
  8164. //
  8165. // Runs with shader models 6.0, 6.5 and 6.6 to test both the HLSL built-in IsHelperLane fallback
  8166. // function (sm <= 6.5) and the IsHelperLane intrisics (sm >= 6.6) and the shader model 6.5 wave intrinsics (sm >= 6.5).
  8167. //
  8168. // For compute and vertex shaders IsHelperLane() always returns false and might be optimized away in the front end.
  8169. // However it can be exposed to the driver in CS/VS through an exported function in a library so drivers need
  8170. // to be prepared to handle it. For this reason the test is compiled with disabled optimizations (/Od).
  8171. // The tests are also validating that wave intrinsics operate correctly with 3 threads in a CS or 3 vertices
  8172. // in a VS where the rest of the lanes in the wave are not active (dead lanes).
  8173. //
  8174. TEST_F(ExecutionTest, HelperLaneTestWave) {
  8175. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  8176. CComPtr<IStream> pStream;
  8177. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  8178. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  8179. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  8180. st::ShaderOp* pShaderOp = ShaderOpSet->GetShaderOp("HelperLaneTestWave");
  8181. #ifdef ISHELPERLANE_PLACEHOLDER
  8182. LPCSTR args = "/Od -DISHELPERLANE_PLACEHOLDER";
  8183. #else
  8184. LPCSTR args = "/Od";
  8185. #endif
  8186. if (args[0]) {
  8187. for (st::ShaderOpShader& S : pShaderOp->Shaders)
  8188. S.Arguments = args;
  8189. }
  8190. bool testPassed = true;
  8191. D3D_SHADER_MODEL TestShaderModels[] = { D3D_SHADER_MODEL_6_0, D3D_SHADER_MODEL_6_5, D3D_SHADER_MODEL_6_6 };
  8192. for (unsigned i = 0; i < _countof(TestShaderModels); i++) {
  8193. D3D_SHADER_MODEL sm = TestShaderModels[i];
  8194. LogCommentFmt(L"\r\nVerifying IsHelperLane using Wave intrinsics in shader model 6.%1u", ((UINT)sm & 0x0f));
  8195. bool smPassed = true;
  8196. CComPtr<ID3D12Device> pDevice;
  8197. if (!CreateDevice(&pDevice, sm, false /* skipUnsupported */)) {
  8198. continue;
  8199. }
  8200. if (!DoesDeviceSupportWaveOps(pDevice)) {
  8201. LogCommentFmt(L"Device does not support wave operations in shader model 6.%1u", ((UINT)sm & 0x0f));
  8202. continue;
  8203. }
  8204. if (sm == D3D_SHADER_MODEL_6_5) {
  8205. // Reassign shader stages to 6.5 versions
  8206. LPCSTR CS65 = nullptr, VS65 = nullptr, PS65 = nullptr;
  8207. for (st::ShaderOpShader& S : pShaderOp->Shaders) {
  8208. if (!strcmp(S.Name, "CS65")) CS65 = S.Name;
  8209. if (!strcmp(S.Name, "VS65")) VS65 = S.Name;
  8210. if (!strcmp(S.Name, "PS65")) PS65 = S.Name;
  8211. }
  8212. pShaderOp->CS = CS65;
  8213. pShaderOp->VS = VS65;
  8214. pShaderOp->PS = PS65;
  8215. } else if (sm == D3D_SHADER_MODEL_6_6) {
  8216. // Reassign shader stages to 6.6 versions
  8217. LPCSTR CS66 = nullptr, VS66 = nullptr, PS66 = nullptr;
  8218. for (st::ShaderOpShader& S : pShaderOp->Shaders) {
  8219. if (!strcmp(S.Name, "CS66")) CS66 = S.Name;
  8220. if (!strcmp(S.Name, "VS66")) VS66 = S.Name;
  8221. if (!strcmp(S.Name, "PS66")) PS66 = S.Name;
  8222. }
  8223. pShaderOp->CS = CS66;
  8224. pShaderOp->VS = VS66;
  8225. pShaderOp->PS = PS66;
  8226. }
  8227. const unsigned CS_INDEX = 0, VS_INDEX = 0, PS_INDEX = 1, PS_INDEX_AFTER_DISCARD = 2;
  8228. // Test Compute shader
  8229. {
  8230. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "HelperLaneTestWave",
  8231. CleanUAVBuffer0Buffer, ShaderOpSet);
  8232. MappedData uavData;
  8233. test->Test->GetReadBackData("UAVBuffer0", &uavData);
  8234. HelperLaneWaveTestResult* pTestResults = (HelperLaneWaveTestResult*)uavData.data();
  8235. LogCommentFmt(L"\r\nCompute shader");
  8236. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[CS_INDEX], HelperLane_CS_ExpectedResults, true);
  8237. }
  8238. // Test Vertex + Pixel shader
  8239. {
  8240. pShaderOp->CS = nullptr;
  8241. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "HelperLaneTestWave", CleanUAVBuffer0Buffer, ShaderOpSet);
  8242. MappedData uavData;
  8243. test->Test->GetReadBackData("UAVBuffer0", &uavData);
  8244. HelperLaneWaveTestResult* pTestResults = (HelperLaneWaveTestResult*)uavData.data();
  8245. LogCommentFmt(L"\r\nVertex shader");
  8246. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[VS_INDEX], HelperLane_VS_ExpectedResults, false);
  8247. LogCommentFmt(L"\r\nPixel shader");
  8248. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[PS_INDEX], HelperLane_PS_ExpectedResults, true);
  8249. LogCommentFmt(L"\r\nPixel shader with discarded pixel");
  8250. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[PS_INDEX_AFTER_DISCARD], HelperLane_PSAfterDiscard_ExpectedResults, true);
  8251. MappedData renderData;
  8252. test->Test->GetReadBackData("RTarget", &renderData);
  8253. const uint32_t* pPixels = (uint32_t*)renderData.data();
  8254. UNREFERENCED_PARAMETER(pPixels);
  8255. }
  8256. testPassed &= smPassed;
  8257. }
  8258. VERIFY_ARE_EQUAL(testPassed, true);
  8259. }
  8260. #ifndef _HLK_CONF
  8261. static void WriteReadBackDump(st::ShaderOp *pShaderOp, st::ShaderOpTest *pTest,
  8262. char **pReadBackDump) {
  8263. std::stringstream str;
  8264. unsigned count = 0;
  8265. for (auto &R : pShaderOp->Resources) {
  8266. if (!R.ReadBack)
  8267. continue;
  8268. ++count;
  8269. str << "Resource: " << R.Name << "\r\n";
  8270. // Find a descriptor that can tell us how to dump this resource.
  8271. bool found = false;
  8272. for (auto &Heaps : pShaderOp->DescriptorHeaps) {
  8273. for (auto &D : Heaps.Descriptors) {
  8274. if (_stricmp(D.ResName, R.Name) != 0) {
  8275. continue;
  8276. }
  8277. found = true;
  8278. if (_stricmp(D.Kind, "UAV") != 0) {
  8279. str << "Resource dump for kind " << D.Kind << " not implemented yet.\r\n";
  8280. break;
  8281. }
  8282. if (D.UavDesc.ViewDimension != D3D12_UAV_DIMENSION_BUFFER) {
  8283. str << "Resource dump for this kind of view dimension not implemented yet.\r\n";
  8284. break;
  8285. }
  8286. // We can map back to the structure if a structured buffer via the shader, but
  8287. // we'll keep this simple and simply dump out 32-bit uint/float representations.
  8288. MappedData data;
  8289. pTest->GetReadBackData(R.Name, &data);
  8290. uint32_t *pData = (uint32_t *)data.data();
  8291. size_t u32_count = ((size_t)R.Desc.Width) / sizeof(uint32_t);
  8292. for (size_t i = 0; i < u32_count; ++i) {
  8293. float f = *(float *)pData;
  8294. str << i << ": 0n" << *pData << " 0x" << std::hex << *pData
  8295. << std::dec << " " << f << "\r\n";
  8296. ++pData;
  8297. }
  8298. break;
  8299. }
  8300. if (found) break;
  8301. }
  8302. if (!found) {
  8303. str << "Unable to find a view for the resource.\r\n";
  8304. }
  8305. }
  8306. str << "Resources read back: " << count << "\r\n";
  8307. std::string s(str.str());
  8308. CComHeapPtr<char> pDump;
  8309. if (!pDump.Allocate(s.size() + 1))
  8310. throw std::bad_alloc();
  8311. memcpy(pDump.m_pData, s.data(), s.size());
  8312. pDump.m_pData[s.size()] = '\0';
  8313. *pReadBackDump = pDump.Detach();
  8314. }
  8315. // This is the exported interface by use from HLSLHost.exe.
  8316. // It's exclusive with the use of the DLL as a TAEF target.
  8317. extern "C" {
  8318. __declspec(dllexport) HRESULT WINAPI InitializeOpTests(void *pStrCtx, st::OutputStringFn pOutputStrFn) {
  8319. HRESULT hr = EnableExperimentalShaderModels();
  8320. if (FAILED(hr)) {
  8321. pOutputStrFn(pStrCtx, L"Unable to enable experimental shader models.\r\n.");
  8322. }
  8323. return S_OK;
  8324. }
  8325. __declspec(dllexport) HRESULT WINAPI
  8326. RunOpTest(void *pStrCtx, st::OutputStringFn pOutputStrFn, LPCSTR pText,
  8327. ID3D12Device *pDevice, ID3D12CommandQueue *pCommandQueue,
  8328. ID3D12Resource *pRenderTarget, char **pReadBackDump) {
  8329. HRESULT hr;
  8330. if (pReadBackDump) *pReadBackDump = nullptr;
  8331. st::SetOutputFn(pStrCtx, pOutputStrFn);
  8332. CComPtr<ID3D12InfoQueue> pInfoQueue;
  8333. CComHeapPtr<char> pDump;
  8334. bool FilterCreation = false;
  8335. if (SUCCEEDED(pDevice->QueryInterface(&pInfoQueue))) {
  8336. // Creation is largely driven by inputs, so don't log create/destroy messages.
  8337. pInfoQueue->PushEmptyStorageFilter();
  8338. pInfoQueue->PushEmptyRetrievalFilter();
  8339. if (FilterCreation) {
  8340. D3D12_INFO_QUEUE_FILTER filter;
  8341. D3D12_MESSAGE_CATEGORY denyCategories[] = { D3D12_MESSAGE_CATEGORY_STATE_CREATION };
  8342. ZeroMemory(&filter, sizeof(filter));
  8343. filter.DenyList.NumCategories = _countof(denyCategories);
  8344. filter.DenyList.pCategoryList = denyCategories;
  8345. pInfoQueue->PushStorageFilter(&filter);
  8346. }
  8347. }
  8348. else {
  8349. pOutputStrFn(pStrCtx, L"Unable to enable info queue for D3D.\r\n.");
  8350. }
  8351. try {
  8352. dxc::DxcDllSupport m_support;
  8353. m_support.Initialize();
  8354. const char *pName = nullptr;
  8355. CComPtr<IStream> pStream = SHCreateMemStream((BYTE *)pText, (UINT)strlen(pText));
  8356. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  8357. std::make_shared<st::ShaderOpSet>();
  8358. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  8359. st::ShaderOp *pShaderOp;
  8360. if (pName == nullptr) {
  8361. if (ShaderOpSet->ShaderOps.size() != 1) {
  8362. pOutputStrFn(pStrCtx, L"Expected a single shader operation.\r\n");
  8363. return E_FAIL;
  8364. }
  8365. pShaderOp = ShaderOpSet->ShaderOps[0].get();
  8366. }
  8367. else {
  8368. pShaderOp = ShaderOpSet->GetShaderOp(pName);
  8369. }
  8370. if (pShaderOp == nullptr) {
  8371. std::string msg = "Unable to find shader op ";
  8372. msg += pName;
  8373. msg += "; available ops";
  8374. const char sep = ':';
  8375. for (auto &pAvailOp : ShaderOpSet->ShaderOps) {
  8376. msg += sep;
  8377. msg += pAvailOp->Name ? pAvailOp->Name : "[n/a]";
  8378. }
  8379. CA2W msgWide(msg.c_str());
  8380. pOutputStrFn(pStrCtx, msgWide);
  8381. return E_FAIL;
  8382. }
  8383. std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
  8384. test->SetupRenderTarget(pShaderOp, pDevice, pCommandQueue, pRenderTarget);
  8385. test->SetDxcSupport(&m_support);
  8386. test->RunShaderOp(pShaderOp);
  8387. test->PresentRenderTarget(pShaderOp, pCommandQueue, pRenderTarget);
  8388. pOutputStrFn(pStrCtx, L"Rendering complete.\r\n");
  8389. if (!pShaderOp->IsCompute()) {
  8390. D3D12_QUERY_DATA_PIPELINE_STATISTICS stats;
  8391. test->GetPipelineStats(&stats);
  8392. wchar_t statsText[400];
  8393. StringCchPrintfW(statsText, _countof(statsText),
  8394. L"Vertices/primitives read by input assembler: %I64u/%I64u\r\n"
  8395. L"Vertex shader invocations: %I64u\r\n"
  8396. L"Geometry shader invocations/output primitive: %I64u/%I64u\r\n"
  8397. L"Primitives sent to rasterizer/rendered: %I64u/%I64u\r\n"
  8398. L"PS/HS/DS/CS invocations: %I64u/%I64u/%I64u/%I64u\r\n",
  8399. stats.IAVertices, stats.IAPrimitives, stats.VSInvocations,
  8400. stats.GSInvocations, stats.GSPrimitives, stats.CInvocations,
  8401. stats.CPrimitives, stats.PSInvocations, stats.HSInvocations,
  8402. stats.DSInvocations, stats.CSInvocations);
  8403. pOutputStrFn(pStrCtx, statsText);
  8404. }
  8405. if (pReadBackDump) {
  8406. WriteReadBackDump(pShaderOp, test.get(), &pDump);
  8407. }
  8408. hr = S_OK;
  8409. }
  8410. catch (const CAtlException &E)
  8411. {
  8412. hr = E.m_hr;
  8413. }
  8414. catch (const std::bad_alloc &)
  8415. {
  8416. hr = E_OUTOFMEMORY;
  8417. }
  8418. catch (const std::exception &)
  8419. {
  8420. hr = E_FAIL;
  8421. }
  8422. // Drain the device message queue if available.
  8423. if (pInfoQueue != nullptr) {
  8424. wchar_t buf[200];
  8425. StringCchPrintfW(buf, _countof(buf),
  8426. L"NumStoredMessages=%u limit/discarded by limit=%u/%u "
  8427. L"allowed/denied by storage filter=%u/%u "
  8428. L"NumStoredMessagesAllowedByRetrievalFilter=%u\r\n",
  8429. (unsigned)pInfoQueue->GetNumStoredMessages(),
  8430. (unsigned)pInfoQueue->GetMessageCountLimit(),
  8431. (unsigned)pInfoQueue->GetNumMessagesDiscardedByMessageCountLimit(),
  8432. (unsigned)pInfoQueue->GetNumMessagesAllowedByStorageFilter(),
  8433. (unsigned)pInfoQueue->GetNumMessagesDeniedByStorageFilter(),
  8434. (unsigned)pInfoQueue->GetNumStoredMessagesAllowedByRetrievalFilter());
  8435. pOutputStrFn(pStrCtx, buf);
  8436. WriteInfoQueueMessages(pStrCtx, pOutputStrFn, pInfoQueue);
  8437. pInfoQueue->ClearStoredMessages();
  8438. pInfoQueue->PopRetrievalFilter();
  8439. pInfoQueue->PopStorageFilter();
  8440. if (FilterCreation) {
  8441. pInfoQueue->PopStorageFilter();
  8442. }
  8443. }
  8444. if (pReadBackDump) *pReadBackDump = pDump.Detach();
  8445. return hr;
  8446. }
  8447. }
  8448. #endif
  8449. // MARKER: ExecutionTest/DxilConf Shared Implementation End
  8450. // Do not remove the line above - it is used by TranslateExecutionTest.py