ExecutionTest.cpp 395 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716
  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. TEST_METHOD(HelperLaneTestWave);
  280. TEST_METHOD(SignatureResourcesTest)
  281. TEST_METHOD(DynamicResourcesTest)
  282. TEST_METHOD(QuadReadTest)
  283. TEST_METHOD(CBufferTestHalf);
  284. TEST_METHOD(BasicShaderModel61);
  285. TEST_METHOD(BasicShaderModel63);
  286. BEGIN_TEST_METHOD(WaveIntrinsicsActiveIntTest)
  287. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsActiveIntTable")
  288. END_TEST_METHOD()
  289. BEGIN_TEST_METHOD(WaveIntrinsicsActiveUintTest)
  290. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsActiveUintTable")
  291. END_TEST_METHOD()
  292. BEGIN_TEST_METHOD(WaveIntrinsicsPrefixIntTest)
  293. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsPrefixIntTable")
  294. END_TEST_METHOD()
  295. BEGIN_TEST_METHOD(WaveIntrinsicsPrefixUintTest)
  296. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsPrefixUintTable")
  297. END_TEST_METHOD()
  298. BEGIN_TEST_METHOD(WaveIntrinsicsSM65IntTest)
  299. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsMultiPrefixIntTable")
  300. END_TEST_METHOD()
  301. BEGIN_TEST_METHOD(WaveIntrinsicsSM65UintTest)
  302. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsMultiPrefixUintTable")
  303. END_TEST_METHOD()
  304. // TAEF data-driven tests.
  305. BEGIN_TEST_METHOD(UnaryFloatOpTest)
  306. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryFloatOpTable")
  307. END_TEST_METHOD()
  308. BEGIN_TEST_METHOD(BinaryFloatOpTest)
  309. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryFloatOpTable")
  310. END_TEST_METHOD()
  311. BEGIN_TEST_METHOD(TertiaryFloatOpTest)
  312. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryFloatOpTable")
  313. END_TEST_METHOD()
  314. BEGIN_TEST_METHOD(UnaryHalfOpTest)
  315. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryHalfOpTable")
  316. END_TEST_METHOD()
  317. BEGIN_TEST_METHOD(BinaryHalfOpTest)
  318. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryHalfOpTable")
  319. END_TEST_METHOD()
  320. BEGIN_TEST_METHOD(TertiaryHalfOpTest)
  321. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryHalfOpTable")
  322. END_TEST_METHOD()
  323. BEGIN_TEST_METHOD(UnaryIntOpTest)
  324. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryIntOpTable")
  325. END_TEST_METHOD()
  326. BEGIN_TEST_METHOD(BinaryIntOpTest)
  327. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryIntOpTable")
  328. END_TEST_METHOD()
  329. BEGIN_TEST_METHOD(TertiaryIntOpTest)
  330. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryIntOpTable")
  331. END_TEST_METHOD()
  332. BEGIN_TEST_METHOD(UnaryUintOpTest)
  333. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryUintOpTable")
  334. END_TEST_METHOD()
  335. BEGIN_TEST_METHOD(BinaryUintOpTest)
  336. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryUintOpTable")
  337. END_TEST_METHOD()
  338. BEGIN_TEST_METHOD(TertiaryUintOpTest)
  339. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryUintOpTable")
  340. END_TEST_METHOD()
  341. BEGIN_TEST_METHOD(UnaryInt16OpTest)
  342. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryInt16OpTable")
  343. END_TEST_METHOD()
  344. BEGIN_TEST_METHOD(BinaryInt16OpTest)
  345. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryInt16OpTable")
  346. END_TEST_METHOD()
  347. BEGIN_TEST_METHOD(TertiaryInt16OpTest)
  348. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryInt16OpTable")
  349. END_TEST_METHOD()
  350. BEGIN_TEST_METHOD(UnaryUint16OpTest)
  351. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryUint16OpTable")
  352. END_TEST_METHOD()
  353. BEGIN_TEST_METHOD(BinaryUint16OpTest)
  354. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryUint16OpTable")
  355. END_TEST_METHOD()
  356. BEGIN_TEST_METHOD(TertiaryUint16OpTest)
  357. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryUint16OpTable")
  358. END_TEST_METHOD()
  359. BEGIN_TEST_METHOD(DotTest)
  360. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DotOpTable")
  361. END_TEST_METHOD()
  362. BEGIN_TEST_METHOD(Dot2AddHalfTest)
  363. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot2AddHalfOpTable")
  364. END_TEST_METHOD()
  365. BEGIN_TEST_METHOD(Dot4AddI8PackedTest)
  366. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot4AddI8PackedOpTable")
  367. END_TEST_METHOD()
  368. BEGIN_TEST_METHOD(Dot4AddU8PackedTest)
  369. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot4AddU8PackedOpTable")
  370. END_TEST_METHOD()
  371. BEGIN_TEST_METHOD(Msad4Test)
  372. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Msad4Table")
  373. END_TEST_METHOD()
  374. BEGIN_TEST_METHOD(DenormBinaryFloatOpTest)
  375. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DenormBinaryFloatOpTable")
  376. END_TEST_METHOD()
  377. BEGIN_TEST_METHOD(DenormTertiaryFloatOpTest)
  378. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DenormTertiaryFloatOpTable")
  379. END_TEST_METHOD()
  380. TEST_METHOD(BarycentricsTest);
  381. TEST_METHOD(ComputeRawBufferLdStI32);
  382. TEST_METHOD(ComputeRawBufferLdStFloat);
  383. TEST_METHOD(ComputeRawBufferLdStI64);
  384. TEST_METHOD(ComputeRawBufferLdStDouble);
  385. TEST_METHOD(ComputeRawBufferLdStI16);
  386. TEST_METHOD(ComputeRawBufferLdStHalf);
  387. TEST_METHOD(GraphicsRawBufferLdStI32);
  388. TEST_METHOD(GraphicsRawBufferLdStFloat);
  389. TEST_METHOD(GraphicsRawBufferLdStI64);
  390. TEST_METHOD(GraphicsRawBufferLdStDouble);
  391. TEST_METHOD(GraphicsRawBufferLdStI16);
  392. TEST_METHOD(GraphicsRawBufferLdStHalf);
  393. BEGIN_TEST_METHOD(PackUnpackTest)
  394. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#PackUnpackOpTable")
  395. END_TEST_METHOD()
  396. dxc::DxcDllSupport m_support;
  397. VersionSupportInfo m_ver;
  398. bool m_ExperimentalModeEnabled = false;
  399. const float ClearColor[4] = { 0.0f, 0.2f, 0.4f, 1.0f };
  400. // Do not remove the following line - it is used by TranslateExecutionTest.py
  401. // MARKER: ExecutionTest/DxilConf Shared Implementation Start
  402. // This is defined in d3d.h for Windows 10 Anniversary Edition SDK, but we only
  403. // require the Windows 10 SDK.
  404. typedef enum D3D_SHADER_MODEL {
  405. D3D_SHADER_MODEL_5_1 = 0x51,
  406. D3D_SHADER_MODEL_6_0 = 0x60,
  407. D3D_SHADER_MODEL_6_1 = 0x61,
  408. D3D_SHADER_MODEL_6_2 = 0x62,
  409. D3D_SHADER_MODEL_6_3 = 0x63,
  410. D3D_SHADER_MODEL_6_4 = 0x64,
  411. D3D_SHADER_MODEL_6_5 = 0x65,
  412. D3D_SHADER_MODEL_6_6 = 0x66,
  413. } D3D_SHADER_MODEL;
  414. #if WDK_NTDDI_VERSION == NTDDI_WIN10_RS2
  415. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_0;
  416. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS3
  417. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_1;
  418. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS4
  419. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_2;
  420. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS5
  421. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_3;
  422. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_19H1
  423. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_4;
  424. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_VB
  425. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_5;
  426. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_MN
  427. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_5;
  428. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_FE
  429. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  430. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_CO
  431. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  432. #else
  433. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  434. #endif
  435. bool UseDxbc() {
  436. #ifdef _HLK_CONF
  437. return false;
  438. #else
  439. return GetTestParamBool(L"DXBC");
  440. #endif
  441. }
  442. bool UseWarpByDefault() {
  443. #ifdef _HLK_CONF
  444. return false;
  445. #else
  446. return true;
  447. #endif
  448. }
  449. bool UseDebugIfaces() {
  450. return true;
  451. }
  452. bool SaveImages() {
  453. return GetTestParamBool(L"SaveImages");
  454. }
  455. void RunResourceTest(ID3D12Device *pDevice, const char *pShader, const wchar_t *sm, bool isDynamic);
  456. template <class T1, class T2>
  457. void WaveIntrinsicsActivePrefixTest(TableParameter *pParameterList,
  458. size_t numParameter, bool isPrefix);
  459. template <typename T>
  460. void WaveIntrinsicsMultiPrefixOpTest(TableParameter *pParameterList,
  461. size_t numParameters);
  462. void BasicTriangleTestSetup(LPCSTR OpName, LPCWSTR FileName, D3D_SHADER_MODEL testModel);
  463. void RunBasicShaderModelTest(D3D_SHADER_MODEL shaderModel);
  464. enum class RawBufferLdStType {
  465. I32,
  466. Float,
  467. I64,
  468. Double,
  469. I16,
  470. Half
  471. };
  472. template <class Ty>
  473. struct RawBufferLdStTestData {
  474. Ty v1, v2[2], v3[3], v4[4];
  475. };
  476. template <class Ty>
  477. struct RawBufferLdStUavData {
  478. RawBufferLdStTestData<Ty> input, output, srvOut;
  479. };
  480. template <class Ty>
  481. void RunComputeRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  482. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData);
  483. template <class Ty>
  484. void RunGraphicsRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  485. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData);
  486. template <class Ty>
  487. void VerifyRawBufferLdStTestResults(const std::shared_ptr<st::ShaderOpTest> test, const RawBufferLdStTestData<Ty> &testData);
  488. bool SetupRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType, CComPtr<ID3D12Device> &pDevice,
  489. CComPtr<IStream> &pStream, char *&sTy, char *&additionalOptions);
  490. template <class Ty>
  491. void RunBasicShaderModelTest(CComPtr<ID3D12Device> pDevice, const char *pShaderModelStr, const char *pShader, Ty *pInputDataPairs, unsigned inputDataCount);
  492. template <class Ty>
  493. const wchar_t* BasicShaderModelTest_GetFormatString();
  494. void CompileFromText(LPCSTR pText, LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, ID3DBlob **ppBlob, LPCWSTR *pOptions = nullptr, int numOptions = 0) {
  495. VERIFY_SUCCEEDED(m_support.Initialize());
  496. CComPtr<IDxcCompiler> pCompiler;
  497. CComPtr<IDxcLibrary> pLibrary;
  498. CComPtr<IDxcBlobEncoding> pTextBlob;
  499. CComPtr<IDxcOperationResult> pResult;
  500. HRESULT resultCode;
  501. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcCompiler, &pCompiler));
  502. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcLibrary, &pLibrary));
  503. VERIFY_SUCCEEDED(pLibrary->CreateBlobWithEncodingFromPinned(pText, (UINT32)strlen(pText), CP_UTF8, &pTextBlob));
  504. VERIFY_SUCCEEDED(pCompiler->Compile(pTextBlob, L"hlsl.hlsl", pEntryPoint, pTargetProfile, pOptions, numOptions, nullptr, 0, nullptr, &pResult));
  505. VERIFY_SUCCEEDED(pResult->GetStatus(&resultCode));
  506. if (FAILED(resultCode)) {
  507. CComPtr<IDxcBlobEncoding> errors;
  508. VERIFY_SUCCEEDED(pResult->GetErrorBuffer(&errors));
  509. #ifndef _HLK_CONF
  510. LogCommentFmt(L"Failed to compile shader: %s", BlobToUtf16(errors).data());
  511. #endif
  512. }
  513. VERIFY_SUCCEEDED(resultCode);
  514. VERIFY_SUCCEEDED(pResult->GetResult((IDxcBlob **)ppBlob));
  515. }
  516. void CreateCommandQueue(ID3D12Device *pDevice, LPCWSTR pName, ID3D12CommandQueue **ppCommandQueue, D3D12_COMMAND_LIST_TYPE type) {
  517. D3D12_COMMAND_QUEUE_DESC queueDesc = {};
  518. queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
  519. queueDesc.Type = type;
  520. VERIFY_SUCCEEDED(pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(ppCommandQueue)));
  521. VERIFY_SUCCEEDED((*ppCommandQueue)->SetName(pName));
  522. }
  523. void CreateComputeCommandQueue(ID3D12Device *pDevice, LPCWSTR pName, ID3D12CommandQueue **ppCommandQueue) {
  524. CreateCommandQueue(pDevice, pName, ppCommandQueue, D3D12_COMMAND_LIST_TYPE_COMPUTE);
  525. }
  526. void CreateComputePSO(ID3D12Device *pDevice, ID3D12RootSignature *pRootSignature, LPCSTR pShader, LPCWSTR pTargetProfile, ID3D12PipelineState **ppComputeState, LPCWSTR *pOptions = nullptr, int numOptions = 0) {
  527. CComPtr<ID3DBlob> pComputeShader;
  528. // Load and compile shaders.
  529. if (UseDxbc()) {
  530. #ifndef _HLK_CONF
  531. DXBCFromText(pShader, L"main", pTargetProfile, &pComputeShader);
  532. #endif
  533. }
  534. else {
  535. CompileFromText(pShader, L"main", pTargetProfile, &pComputeShader, pOptions, numOptions);
  536. }
  537. // Describe and create the compute pipeline state object (PSO).
  538. D3D12_COMPUTE_PIPELINE_STATE_DESC computePsoDesc = {};
  539. computePsoDesc.pRootSignature = pRootSignature;
  540. computePsoDesc.CS = CD3DX12_SHADER_BYTECODE(pComputeShader);
  541. VERIFY_SUCCEEDED(pDevice->CreateComputePipelineState(&computePsoDesc, IID_PPV_ARGS(ppComputeState)));
  542. }
  543. bool CreateDevice(_COM_Outptr_ ID3D12Device **ppDevice,
  544. D3D_SHADER_MODEL testModel = D3D_SHADER_MODEL_6_0, bool skipUnsupported = true,
  545. bool enableRayTracing = false) {
  546. if (testModel > HIGHEST_SHADER_MODEL) {
  547. UINT minor = (UINT)testModel & 0x0f;
  548. LogCommentFmt(L"Installed SDK does not support "
  549. L"shader model 6.%1u", minor);
  550. if (skipUnsupported) {
  551. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  552. }
  553. return false;
  554. }
  555. const D3D_FEATURE_LEVEL FeatureLevelRequired = enableRayTracing ? D3D_FEATURE_LEVEL_12_0 : D3D_FEATURE_LEVEL_11_0;
  556. CComPtr<IDXGIFactory4> factory;
  557. CComPtr<ID3D12Device> pDevice;
  558. *ppDevice = nullptr;
  559. VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
  560. if (GetTestParamUseWARP(UseWarpByDefault())) {
  561. CComPtr<IDXGIAdapter> warpAdapter;
  562. VERIFY_SUCCEEDED(factory->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter)));
  563. HRESULT createHR = D3D12CreateDevice(warpAdapter, FeatureLevelRequired,
  564. IID_PPV_ARGS(&pDevice));
  565. if (FAILED(createHR)) {
  566. LogCommentFmt(L"The available version of WARP does not support d3d12.");
  567. if (skipUnsupported) {
  568. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  569. }
  570. return false;
  571. }
  572. } else {
  573. CComPtr<IDXGIAdapter1> hardwareAdapter;
  574. WEX::Common::String AdapterValue;
  575. HRESULT hr = WEX::TestExecution::RuntimeParameters::TryGetValue(L"Adapter",
  576. AdapterValue);
  577. if (SUCCEEDED(hr)) {
  578. GetHardwareAdapter(factory, AdapterValue, &hardwareAdapter);
  579. } else {
  580. WEX::Logging::Log::Comment(
  581. L"Using default hardware adapter with D3D12 support.");
  582. }
  583. VERIFY_SUCCEEDED(D3D12CreateDevice(hardwareAdapter, FeatureLevelRequired,
  584. IID_PPV_ARGS(&pDevice)));
  585. }
  586. // retrieve adapter information
  587. LUID adapterID = pDevice->GetAdapterLuid();
  588. CComPtr<IDXGIAdapter> adapter;
  589. factory->EnumAdapterByLuid(adapterID, IID_PPV_ARGS(&adapter));
  590. DXGI_ADAPTER_DESC AdapterDesc;
  591. VERIFY_SUCCEEDED(adapter->GetDesc(&AdapterDesc));
  592. LogCommentFmt(L"Using Adapter:%s", AdapterDesc.Description);
  593. if (pDevice == nullptr)
  594. return false;
  595. if (!UseDxbc()) {
  596. // Check for DXIL support.
  597. typedef struct D3D12_FEATURE_DATA_SHADER_MODEL {
  598. _Inout_ D3D_SHADER_MODEL HighestShaderModel;
  599. } D3D12_FEATURE_DATA_SHADER_MODEL;
  600. const UINT D3D12_FEATURE_SHADER_MODEL = 7;
  601. D3D12_FEATURE_DATA_SHADER_MODEL SMData;
  602. SMData.HighestShaderModel = testModel;
  603. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_SHADER_MODEL,
  604. &SMData, sizeof(SMData))) ||
  605. SMData.HighestShaderModel < testModel) {
  606. UINT minor = (UINT)testModel & 0x0f;
  607. LogCommentFmt(L"The selected device does not support "
  608. L"shader model 6.%1u", minor);
  609. if (skipUnsupported) {
  610. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  611. }
  612. return false;
  613. }
  614. }
  615. if (UseDebugIfaces()) {
  616. CComPtr<ID3D12InfoQueue> pInfoQueue;
  617. if (SUCCEEDED(pDevice->QueryInterface(&pInfoQueue))) {
  618. pInfoQueue->SetMuteDebugOutput(FALSE);
  619. }
  620. }
  621. *ppDevice = pDevice.Detach();
  622. return true;
  623. }
  624. void CreateGraphicsCommandQueue(ID3D12Device *pDevice, ID3D12CommandQueue **ppCommandQueue) {
  625. D3D12_COMMAND_QUEUE_DESC queueDesc = {};
  626. queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
  627. queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;;
  628. VERIFY_SUCCEEDED(pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(ppCommandQueue)));
  629. }
  630. void CreateGraphicsCommandQueueAndList(
  631. ID3D12Device *pDevice, ID3D12CommandQueue **ppCommandQueue,
  632. ID3D12CommandAllocator **ppAllocator,
  633. ID3D12GraphicsCommandList **ppCommandList, ID3D12PipelineState *pPSO) {
  634. CreateGraphicsCommandQueue(pDevice, ppCommandQueue);
  635. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(
  636. D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(ppAllocator)));
  637. VERIFY_SUCCEEDED(pDevice->CreateCommandList(
  638. 0, D3D12_COMMAND_LIST_TYPE_DIRECT, *ppAllocator, pPSO,
  639. IID_PPV_ARGS(ppCommandList)));
  640. }
  641. void CreateGraphicsPSO(ID3D12Device *pDevice,
  642. D3D12_INPUT_LAYOUT_DESC *pInputLayout,
  643. ID3D12RootSignature *pRootSignature, LPCSTR pShaders,
  644. ID3D12PipelineState **ppPSO) {
  645. CComPtr<ID3DBlob> vertexShader;
  646. CComPtr<ID3DBlob> pixelShader;
  647. if (UseDxbc()) {
  648. #ifndef _HLK_CONF
  649. DXBCFromText(pShaders, L"VSMain", L"vs_6_0", &vertexShader);
  650. DXBCFromText(pShaders, L"PSMain", L"ps_6_0", &pixelShader);
  651. #endif
  652. } else {
  653. CompileFromText(pShaders, L"VSMain", L"vs_6_0", &vertexShader);
  654. CompileFromText(pShaders, L"PSMain", L"ps_6_0", &pixelShader);
  655. }
  656. // Describe and create the graphics pipeline state object (PSO).
  657. D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
  658. psoDesc.InputLayout = *pInputLayout;
  659. psoDesc.pRootSignature = pRootSignature;
  660. psoDesc.VS = CD3DX12_SHADER_BYTECODE(vertexShader);
  661. psoDesc.PS = CD3DX12_SHADER_BYTECODE(pixelShader);
  662. psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
  663. psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
  664. psoDesc.DepthStencilState.DepthEnable = FALSE;
  665. psoDesc.DepthStencilState.StencilEnable = FALSE;
  666. psoDesc.SampleMask = UINT_MAX;
  667. psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
  668. psoDesc.NumRenderTargets = 1;
  669. psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
  670. psoDesc.SampleDesc.Count = 1;
  671. VERIFY_SUCCEEDED(
  672. pDevice->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(ppPSO)));
  673. }
  674. void CreateRenderTargetAndReadback(ID3D12Device *pDevice,
  675. ID3D12DescriptorHeap *pHeap, UINT width,
  676. UINT height,
  677. ID3D12Resource **ppRenderTarget,
  678. ID3D12Resource **ppBuffer) {
  679. const DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
  680. const size_t formatElementSize = 4;
  681. CComPtr<ID3D12Resource> pRenderTarget;
  682. CComPtr<ID3D12Resource> pBuffer;
  683. CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(
  684. pHeap->GetCPUDescriptorHandleForHeapStart());
  685. CD3DX12_HEAP_PROPERTIES rtHeap(D3D12_HEAP_TYPE_DEFAULT);
  686. CD3DX12_RESOURCE_DESC rtDesc(
  687. CD3DX12_RESOURCE_DESC::Tex2D(format, width, height));
  688. CD3DX12_CLEAR_VALUE rtClearVal(format, ClearColor);
  689. rtDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
  690. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  691. &rtHeap, D3D12_HEAP_FLAG_NONE, &rtDesc, D3D12_RESOURCE_STATE_COPY_DEST,
  692. &rtClearVal, IID_PPV_ARGS(&pRenderTarget)));
  693. pDevice->CreateRenderTargetView(pRenderTarget, nullptr, rtvHandle);
  694. // rtvHandle.Offset(1, rtvDescriptorSize); // Not needed for a single
  695. // resource.
  696. CD3DX12_HEAP_PROPERTIES readHeap(D3D12_HEAP_TYPE_READBACK);
  697. CD3DX12_RESOURCE_DESC readDesc(
  698. CD3DX12_RESOURCE_DESC::Buffer(width * height * formatElementSize));
  699. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  700. &readHeap, D3D12_HEAP_FLAG_NONE, &readDesc,
  701. D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pBuffer)));
  702. *ppRenderTarget = pRenderTarget.Detach();
  703. *ppBuffer = pBuffer.Detach();
  704. }
  705. void CreateRootSignatureFromDesc(ID3D12Device *pDevice,
  706. const D3D12_ROOT_SIGNATURE_DESC *pDesc,
  707. ID3D12RootSignature **pRootSig) {
  708. CComPtr<ID3DBlob> signature;
  709. CComPtr<ID3DBlob> error;
  710. VERIFY_SUCCEEDED(D3D12SerializeRootSignature(pDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
  711. VERIFY_SUCCEEDED(pDevice->CreateRootSignature(
  712. 0, signature->GetBufferPointer(), signature->GetBufferSize(),
  713. IID_PPV_ARGS(pRootSig)));
  714. }
  715. void CreateRootSignatureFromRanges(ID3D12Device *pDevice, ID3D12RootSignature **pRootSig,
  716. CD3DX12_DESCRIPTOR_RANGE *resRanges, UINT resCt,
  717. CD3DX12_DESCRIPTOR_RANGE *sampRanges = nullptr, UINT sampCt = 0,
  718. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) {
  719. CD3DX12_ROOT_PARAMETER rootParameters[2];
  720. rootParameters[0].InitAsDescriptorTable(resCt, resRanges, D3D12_SHADER_VISIBILITY_ALL);
  721. rootParameters[1].InitAsDescriptorTable(sampCt, sampRanges, D3D12_SHADER_VISIBILITY_ALL);
  722. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  723. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, flags);
  724. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, pRootSig);
  725. }
  726. void CreateRtvDescriptorHeap(ID3D12Device *pDevice, UINT numDescriptors,
  727. ID3D12DescriptorHeap **pRtvHeap, UINT *rtvDescriptorSize) {
  728. D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {};
  729. rtvHeapDesc.NumDescriptors = numDescriptors;
  730. rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
  731. rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
  732. VERIFY_SUCCEEDED(
  733. pDevice->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(pRtvHeap)));
  734. if (rtvDescriptorSize != nullptr) {
  735. *rtvDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(
  736. D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
  737. }
  738. }
  739. void CreateTestResources(ID3D12Device *pDevice,
  740. ID3D12GraphicsCommandList *pCommandList, LPCVOID values,
  741. UINT32 valueSizeInBytes, D3D12_RESOURCE_DESC resDesc,
  742. ID3D12Resource **ppResource,
  743. ID3D12Resource **ppUploadResource,
  744. ID3D12Resource **ppReadBuffer = nullptr) {
  745. CComPtr<ID3D12Resource> pResource;
  746. CComPtr<ID3D12Resource> pReadBuffer;
  747. CComPtr<ID3D12Resource> pUploadResource;
  748. D3D12_SUBRESOURCE_DATA transferData;
  749. D3D12_HEAP_PROPERTIES defaultHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);
  750. D3D12_HEAP_PROPERTIES uploadHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD);
  751. D3D12_RESOURCE_DESC uploadBufferDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes);
  752. CD3DX12_HEAP_PROPERTIES readHeap(D3D12_HEAP_TYPE_READBACK);
  753. CD3DX12_RESOURCE_DESC readDesc(CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes));
  754. pDevice->GetCopyableFootprints(&resDesc, 0, 1/*mipleveles*/, 0, nullptr, nullptr, nullptr, &uploadBufferDesc.Width);
  755. uploadBufferDesc.Height = 1;
  756. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  757. &defaultHeapProperties,
  758. D3D12_HEAP_FLAG_NONE,
  759. &resDesc,
  760. D3D12_RESOURCE_STATE_COPY_DEST,
  761. nullptr,
  762. IID_PPV_ARGS(&pResource)));
  763. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  764. &uploadHeapProperties,
  765. D3D12_HEAP_FLAG_NONE,
  766. &uploadBufferDesc,
  767. D3D12_RESOURCE_STATE_GENERIC_READ,
  768. nullptr,
  769. IID_PPV_ARGS(&pUploadResource)));
  770. if (ppReadBuffer)
  771. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  772. &readHeap, D3D12_HEAP_FLAG_NONE, &readDesc,
  773. D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pReadBuffer)));
  774. transferData.pData = values;
  775. transferData.RowPitch = valueSizeInBytes/resDesc.Height;
  776. transferData.SlicePitch = valueSizeInBytes;
  777. UpdateSubresources<1>(pCommandList, pResource.p, pUploadResource.p, 0, 0, 1, &transferData);
  778. if (resDesc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)
  779. RecordTransitionBarrier(pCommandList, pResource, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
  780. else
  781. RecordTransitionBarrier(pCommandList, pResource, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COMMON);
  782. *ppResource = pResource.Detach();
  783. *ppUploadResource = pUploadResource.Detach();
  784. if (ppReadBuffer)
  785. *ppReadBuffer = pReadBuffer.Detach();
  786. }
  787. void CreateTestUavs(ID3D12Device *pDevice,
  788. ID3D12GraphicsCommandList *pCommandList, LPCVOID values,
  789. UINT32 valueSizeInBytes, ID3D12Resource **ppUavResource,
  790. ID3D12Resource **ppUploadResource = nullptr,
  791. ID3D12Resource **ppReadBuffer = nullptr) {
  792. D3D12_RESOURCE_DESC bufferDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
  793. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, bufferDesc,
  794. ppUavResource, ppUploadResource, ppReadBuffer);
  795. }
  796. // Create and return descriptor heaps for the given device
  797. // with the given number of resources and samples.
  798. // using some reasonable defaults
  799. void CreateDefaultDescHeaps(ID3D12Device *pDevice,
  800. int NumResources, int NumSamplers,
  801. ID3D12DescriptorHeap **ppResHeap, ID3D12DescriptorHeap **ppSampHeap) {
  802. // Describe and create descriptor heaps.
  803. ID3D12DescriptorHeap *pResHeap, *pSampHeap;
  804. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  805. heapDesc.NumDescriptors = NumResources;
  806. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  807. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  808. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pResHeap)));
  809. heapDesc.NumDescriptors = NumSamplers;
  810. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
  811. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pSampHeap)));
  812. *ppResHeap = pResHeap;
  813. *ppSampHeap = pSampHeap;
  814. }
  815. void CreateSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &baseHandle,
  816. DXGI_FORMAT format, D3D12_SRV_DIMENSION viewDimension, UINT numElements, UINT stride,
  817. const CComPtr<ID3D12Resource> pResource) {
  818. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
  819. // Create SRV
  820. D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
  821. srvDesc.Format = format;
  822. srvDesc.ViewDimension = viewDimension;
  823. srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
  824. switch (viewDimension) {
  825. case D3D12_SRV_DIMENSION_BUFFER:
  826. srvDesc.Buffer.FirstElement = 0;
  827. srvDesc.Buffer.NumElements = numElements;
  828. srvDesc.Buffer.StructureByteStride = stride;
  829. if (format == DXGI_FORMAT_R32_TYPELESS && stride == 0)
  830. srvDesc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW;
  831. else
  832. srvDesc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_NONE;
  833. break;
  834. case D3D12_SRV_DIMENSION_TEXTURE1D:
  835. srvDesc.Texture1D.MostDetailedMip = 0;
  836. srvDesc.Texture1D.MipLevels = 1;
  837. srvDesc.Texture1D.ResourceMinLODClamp = 0;
  838. break;
  839. case D3D12_SRV_DIMENSION_TEXTURE2D:
  840. srvDesc.Texture2D.MostDetailedMip = 0;
  841. srvDesc.Texture2D.MipLevels = 1;
  842. srvDesc.Texture2D.PlaneSlice = 0;
  843. srvDesc.Texture2D.ResourceMinLODClamp = 0;
  844. break;
  845. }
  846. pDevice->CreateShaderResourceView(pResource, &srvDesc, baseHandle);
  847. baseHandle.Offset(descriptorSize);
  848. }
  849. void CreateRawSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  850. UINT numElements, const CComPtr<ID3D12Resource> pResource) {
  851. CreateSRV(pDevice, heapStart, DXGI_FORMAT_R32_TYPELESS, D3D12_SRV_DIMENSION_BUFFER, numElements, 0, pResource);
  852. }
  853. void CreateStructSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  854. UINT numElements, UINT stride, const CComPtr<ID3D12Resource> pResource) {
  855. CreateSRV(pDevice, heapStart, DXGI_FORMAT_UNKNOWN, D3D12_SRV_DIMENSION_BUFFER, numElements, stride, pResource);
  856. }
  857. void CreateTypedSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  858. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  859. CreateSRV(pDevice, heapStart, format, D3D12_SRV_DIMENSION_BUFFER, numElements, 0, pResource);
  860. }
  861. void CreateTex1DSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  862. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  863. CreateSRV(pDevice, heapStart, format, D3D12_SRV_DIMENSION_TEXTURE1D, numElements, 0, pResource);
  864. }
  865. void CreateTex2DSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  866. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  867. CreateSRV(pDevice, heapStart, format, D3D12_SRV_DIMENSION_TEXTURE2D, numElements, 0, pResource);
  868. }
  869. void CreateUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &baseHandle,
  870. DXGI_FORMAT format, D3D12_UAV_DIMENSION viewDimension, UINT numElements, UINT stride,
  871. const CComPtr<ID3D12Resource> pResource) {
  872. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
  873. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  874. uavDesc.Format = format;
  875. uavDesc.ViewDimension = viewDimension;
  876. switch (viewDimension) {
  877. case D3D12_UAV_DIMENSION_BUFFER:
  878. uavDesc.Buffer.FirstElement = 0;
  879. uavDesc.Buffer.NumElements = numElements;
  880. uavDesc.Buffer.StructureByteStride = stride;
  881. if (format == DXGI_FORMAT_R32_TYPELESS && stride == 0)
  882. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  883. else
  884. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  885. break;
  886. case D3D12_UAV_DIMENSION_TEXTURE1D:
  887. uavDesc.Texture1D.MipSlice = 0;
  888. break;
  889. case D3D12_UAV_DIMENSION_TEXTURE2D:
  890. uavDesc.Texture2D.MipSlice = 0;
  891. uavDesc.Texture2D.PlaneSlice = 0;
  892. break;
  893. }
  894. pDevice->CreateUnorderedAccessView(pResource, nullptr, &uavDesc, baseHandle);
  895. baseHandle.Offset(descriptorSize);
  896. }
  897. void CreateRawUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  898. UINT numElements, const CComPtr<ID3D12Resource> pResource) {
  899. CreateUAV(pDevice, heapStart, DXGI_FORMAT_R32_TYPELESS, D3D12_UAV_DIMENSION_BUFFER, numElements, 0, pResource);
  900. }
  901. void CreateStructUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  902. UINT numElements, UINT stride, const CComPtr<ID3D12Resource> pResource) {
  903. CreateUAV(pDevice, heapStart, DXGI_FORMAT_UNKNOWN, D3D12_UAV_DIMENSION_BUFFER, numElements, stride, pResource);
  904. }
  905. void CreateTypedUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  906. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  907. CreateUAV(pDevice, heapStart, format, D3D12_UAV_DIMENSION_BUFFER, numElements, 0, pResource);
  908. }
  909. void CreateTex1DUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  910. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  911. CreateUAV(pDevice, heapStart, format, D3D12_UAV_DIMENSION_TEXTURE1D, numElements, 0, pResource);
  912. }
  913. void CreateTex2DUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  914. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  915. CreateUAV(pDevice, heapStart, format, D3D12_UAV_DIMENSION_TEXTURE2D, numElements, 0, pResource);
  916. }
  917. // Create Samplers for <pDevice> given the filter and border color information provided
  918. // using some reasonable defaults
  919. void CreateDefaultSamplers(ID3D12Device *pDevice, D3D12_CPU_DESCRIPTOR_HANDLE heapStart,
  920. D3D12_FILTER filters[], float BorderColors[], int NumSamplers) {
  921. CD3DX12_CPU_DESCRIPTOR_HANDLE sampHandle(heapStart);
  922. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
  923. D3D12_SAMPLER_DESC sampDesc = {};
  924. sampDesc.Filter = D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT;
  925. sampDesc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  926. sampDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  927. sampDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  928. sampDesc.MipLODBias = 0;
  929. sampDesc.MaxAnisotropy = 1;
  930. sampDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_EQUAL;
  931. sampDesc.MinLOD = 0;
  932. sampDesc.MaxLOD = 0;
  933. for (int i = 0; i < NumSamplers; i++) {
  934. sampDesc.Filter = filters[i];
  935. for (int j = 0; j < 4; j++)
  936. sampDesc.BorderColor[j] = BorderColors[i];
  937. pDevice->CreateSampler(&sampDesc, sampHandle);
  938. sampHandle = sampHandle.Offset(descriptorSize);
  939. }
  940. }
  941. template <typename TVertex, int len>
  942. void CreateVertexBuffer(ID3D12Device *pDevice, TVertex(&vertices)[len],
  943. ID3D12Resource **ppVertexBuffer,
  944. D3D12_VERTEX_BUFFER_VIEW *pVertexBufferView) {
  945. size_t vertexBufferSize = sizeof(vertices);
  946. CComPtr<ID3D12Resource> pVertexBuffer;
  947. CD3DX12_HEAP_PROPERTIES heapProps(D3D12_HEAP_TYPE_UPLOAD);
  948. CD3DX12_RESOURCE_DESC bufferDesc(
  949. CD3DX12_RESOURCE_DESC::Buffer(vertexBufferSize));
  950. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  951. &heapProps, D3D12_HEAP_FLAG_NONE, &bufferDesc,
  952. D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
  953. IID_PPV_ARGS(&pVertexBuffer)));
  954. UINT8 *pVertexDataBegin;
  955. CD3DX12_RANGE readRange(0, 0);
  956. VERIFY_SUCCEEDED(pVertexBuffer->Map(
  957. 0, &readRange, reinterpret_cast<void **>(&pVertexDataBegin)));
  958. memcpy(pVertexDataBegin, vertices, vertexBufferSize);
  959. pVertexBuffer->Unmap(0, nullptr);
  960. // Initialize the vertex buffer view.
  961. pVertexBufferView->BufferLocation = pVertexBuffer->GetGPUVirtualAddress();
  962. pVertexBufferView->StrideInBytes = sizeof(TVertex);
  963. pVertexBufferView->SizeInBytes = (UINT)vertexBufferSize;
  964. *ppVertexBuffer = pVertexBuffer.Detach();
  965. }
  966. // Requires Anniversary Edition headers, so simplifying things for current setup.
  967. const UINT D3D12_FEATURE_D3D12_OPTIONS1 = 8;
  968. struct D3D12_FEATURE_DATA_D3D12_OPTIONS1 {
  969. BOOL WaveOps;
  970. UINT WaveLaneCountMin;
  971. UINT WaveLaneCountMax;
  972. UINT TotalLaneCount;
  973. BOOL ExpandedComputeResourceStates;
  974. BOOL Int64ShaderOps;
  975. };
  976. bool IsDeviceBasicAdapter(ID3D12Device *pDevice) {
  977. CComPtr<IDXGIFactory4> factory;
  978. VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
  979. LUID adapterID = pDevice->GetAdapterLuid();
  980. CComPtr<IDXGIAdapter1> adapter;
  981. factory->EnumAdapterByLuid(adapterID, IID_PPV_ARGS(&adapter));
  982. DXGI_ADAPTER_DESC1 AdapterDesc;
  983. VERIFY_SUCCEEDED(adapter->GetDesc1(&AdapterDesc));
  984. return (AdapterDesc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE);
  985. }
  986. bool DoesDeviceSupportInt64(ID3D12Device *pDevice) {
  987. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  988. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  989. return false;
  990. return O.Int64ShaderOps != FALSE;
  991. }
  992. bool DoesDeviceSupportDouble(ID3D12Device *pDevice) {
  993. D3D12_FEATURE_DATA_D3D12_OPTIONS O;
  994. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS, &O, sizeof(O))))
  995. return false;
  996. return O.DoublePrecisionFloatShaderOps != FALSE;
  997. }
  998. bool DoesDeviceSupportWaveOps(ID3D12Device *pDevice) {
  999. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  1000. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  1001. return false;
  1002. return O.WaveOps != FALSE;
  1003. }
  1004. bool DoesDeviceSupportBarycentrics(ID3D12Device *pDevice) {
  1005. D3D12_FEATURE_DATA_D3D12_OPTIONS3 O;
  1006. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS3, &O, sizeof(O))))
  1007. return false;
  1008. return O.BarycentricsSupported != FALSE;
  1009. }
  1010. bool DoesDeviceSupportNative16bitOps(ID3D12Device *pDevice) {
  1011. D3D12_FEATURE_DATA_D3D12_OPTIONS4 O;
  1012. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS4, &O, sizeof(O))))
  1013. return false;
  1014. return O.Native16BitShaderOpsSupported != FALSE;
  1015. }
  1016. bool DoesDeviceSupportMeshShaders(ID3D12Device *pDevice) {
  1017. #if defined(NTDDI_WIN10_VB) && WDK_NTDDI_VERSION >= NTDDI_WIN10_VB
  1018. D3D12_FEATURE_DATA_D3D12_OPTIONS7 O7;
  1019. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS7, &O7, sizeof(O7))))
  1020. return false;
  1021. return O7.MeshShaderTier != D3D12_MESH_SHADER_TIER_NOT_SUPPORTED;
  1022. #else
  1023. UNREFERENCED_PARAMETER(pDevice);
  1024. return false;
  1025. #endif
  1026. }
  1027. bool DoesDeviceSupportRayTracing(ID3D12Device *pDevice) {
  1028. #if WDK_NTDDI_VERSION > NTDDI_WIN10_RS4
  1029. D3D12_FEATURE_DATA_D3D12_OPTIONS5 O5;
  1030. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS5, &O5, sizeof(O5))))
  1031. return false;
  1032. return O5.RaytracingTier != D3D12_RAYTRACING_TIER_NOT_SUPPORTED;
  1033. #else
  1034. UNREFERENCED_PARAMETER(pDevice);
  1035. return false;
  1036. #endif
  1037. }
  1038. bool DoesDeviceSupportMeshAmpDerivatives(ID3D12Device *pDevice) {
  1039. #if defined(NTDDI_WIN10_FE) && WDK_NTDDI_VERSION >= NTDDI_WIN10_FE
  1040. D3D12_FEATURE_DATA_D3D12_OPTIONS7 O7;
  1041. D3D12_FEATURE_DATA_D3D12_OPTIONS9 O9;
  1042. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS7, &O7, sizeof(O7))) ||
  1043. FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS9, &O9, sizeof(O9))))
  1044. return false;
  1045. return O7.MeshShaderTier != D3D12_MESH_SHADER_TIER_NOT_SUPPORTED &&
  1046. O9.DerivativesInMeshAndAmplificationShadersSupported != FALSE;
  1047. #else
  1048. UNREFERENCED_PARAMETER(pDevice);
  1049. return false;
  1050. #endif
  1051. }
  1052. bool DoesDeviceSupportTyped64Atomics(ID3D12Device *pDevice) {
  1053. #if defined(NTDDI_WIN10_FE) && WDK_NTDDI_VERSION >= NTDDI_WIN10_FE
  1054. D3D12_FEATURE_DATA_D3D12_OPTIONS9 O9;
  1055. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS9, &O9, sizeof(O9))))
  1056. return false;
  1057. return O9.AtomicInt64OnTypedResourceSupported != FALSE;
  1058. #else
  1059. UNREFERENCED_PARAMETER(pDevice);
  1060. return false;
  1061. #endif
  1062. }
  1063. bool DoesDeviceSupportHeap64Atomics(ID3D12Device *pDevice) {
  1064. #if defined(NTDDI_WIN10_CO) && WDK_NTDDI_VERSION >= NTDDI_WIN10_CO
  1065. D3D12_FEATURE_DATA_D3D12_OPTIONS11 O11;
  1066. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS11, &O11, sizeof(O11))))
  1067. return false;
  1068. return O11.AtomicInt64OnDescriptorHeapResourceSupported != FALSE;
  1069. #else
  1070. UNREFERENCED_PARAMETER(pDevice);
  1071. return false;
  1072. #endif
  1073. }
  1074. bool DoesDeviceSupportShared64Atomics(ID3D12Device *pDevice) {
  1075. #if defined(NTDDI_WIN10_FE) && WDK_NTDDI_VERSION >= NTDDI_WIN10_FE
  1076. D3D12_FEATURE_DATA_D3D12_OPTIONS9 O9;
  1077. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS9, &O9, sizeof(O9))))
  1078. return false;
  1079. return O9.AtomicInt64OnGroupSharedSupported != FALSE;
  1080. #else
  1081. UNREFERENCED_PARAMETER(pDevice);
  1082. return false;
  1083. #endif
  1084. }
  1085. #ifndef _HLK_CONF
  1086. void DXBCFromText(LPCSTR pText, LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, ID3DBlob **ppBlob) {
  1087. CW2A pEntryPointA(pEntryPoint, CP_UTF8);
  1088. CW2A pTargetProfileA(pTargetProfile, CP_UTF8);
  1089. CComPtr<ID3DBlob> pErrors;
  1090. D3D_SHADER_MACRO d3dMacro[2];
  1091. ZeroMemory(d3dMacro, sizeof(d3dMacro));
  1092. d3dMacro[0].Definition = "1";
  1093. d3dMacro[0].Name = "USING_DXBC";
  1094. HRESULT hr = D3DCompile(pText, strlen(pText), "hlsl.hlsl", d3dMacro, nullptr, pEntryPointA, pTargetProfileA, 0, 0, ppBlob, &pErrors);
  1095. if (pErrors != nullptr) {
  1096. CA2W errors((char *)pErrors->GetBufferPointer(), CP_ACP);
  1097. LogCommentFmt(L"Compilation failure: %s", errors.m_szBuffer);
  1098. }
  1099. VERIFY_SUCCEEDED(hr);
  1100. }
  1101. #endif
  1102. HRESULT EnableDebugLayer() {
  1103. // The debug layer does net yet validate DXIL programs that require rewriting,
  1104. // but basic logging should work properly.
  1105. HRESULT hr = S_FALSE;
  1106. if (UseDebugIfaces()) {
  1107. CComPtr<ID3D12Debug> debugController;
  1108. hr = D3D12GetDebugInterface(IID_PPV_ARGS(&debugController));
  1109. if (SUCCEEDED(hr)) {
  1110. debugController->EnableDebugLayer();
  1111. hr = S_OK;
  1112. }
  1113. }
  1114. return hr;
  1115. }
  1116. #ifndef _HLK_CONF
  1117. HRESULT EnableExperimentalMode() {
  1118. if (m_ExperimentalModeEnabled) {
  1119. return S_OK;
  1120. }
  1121. if (!GetTestParamBool(L"ExperimentalShaders")) {
  1122. return S_FALSE;
  1123. }
  1124. HRESULT hr = EnableExperimentalShaderModels();
  1125. if (SUCCEEDED(hr)) {
  1126. m_ExperimentalModeEnabled = true;
  1127. }
  1128. return hr;
  1129. }
  1130. #endif
  1131. struct FenceObj {
  1132. HANDLE m_fenceEvent = NULL;
  1133. CComPtr<ID3D12Fence> m_fence;
  1134. UINT64 m_fenceValue;
  1135. ~FenceObj() {
  1136. if (m_fenceEvent) CloseHandle(m_fenceEvent);
  1137. }
  1138. };
  1139. void InitFenceObj(ID3D12Device *pDevice, FenceObj *pObj) {
  1140. pObj->m_fenceValue = 1;
  1141. VERIFY_SUCCEEDED(pDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE,
  1142. IID_PPV_ARGS(&pObj->m_fence)));
  1143. // Create an event handle to use for frame synchronization.
  1144. pObj->m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
  1145. if (pObj->m_fenceEvent == nullptr) {
  1146. VERIFY_SUCCEEDED(HRESULT_FROM_WIN32(GetLastError()));
  1147. }
  1148. }
  1149. void ReadHlslDataIntoNewStream(LPCWSTR relativePath, IStream **ppStream) {
  1150. VERIFY_SUCCEEDED(m_support.Initialize());
  1151. CComPtr<IDxcLibrary> pLibrary;
  1152. CComPtr<IDxcBlobEncoding> pBlob;
  1153. CComPtr<IStream> pStream;
  1154. std::wstring path = GetPathToHlslDataFile(relativePath);
  1155. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcLibrary, &pLibrary));
  1156. VERIFY_SUCCEEDED(pLibrary->CreateBlobFromFile(path.c_str(), nullptr, &pBlob));
  1157. VERIFY_SUCCEEDED(pLibrary->CreateStreamFromBlobReadOnly(pBlob, &pStream));
  1158. *ppStream = pStream.Detach();
  1159. }
  1160. void RecordRenderAndReadback(ID3D12GraphicsCommandList *pList,
  1161. ID3D12DescriptorHeap *pRtvHeap,
  1162. UINT rtvDescriptorSize,
  1163. UINT instanceCount,
  1164. D3D12_VERTEX_BUFFER_VIEW *pVertexBufferView,
  1165. ID3D12RootSignature *pRootSig,
  1166. ID3D12Resource *pRenderTarget,
  1167. ID3D12Resource *pReadBuffer) {
  1168. D3D12_RESOURCE_DESC rtDesc = pRenderTarget->GetDesc();
  1169. D3D12_VIEWPORT viewport;
  1170. D3D12_RECT scissorRect;
  1171. memset(&viewport, 0, sizeof(viewport));
  1172. viewport.Height = (float)rtDesc.Height;
  1173. viewport.Width = (float)rtDesc.Width;
  1174. viewport.MaxDepth = 1.0f;
  1175. memset(&scissorRect, 0, sizeof(scissorRect));
  1176. scissorRect.right = (long)rtDesc.Width;
  1177. scissorRect.bottom = rtDesc.Height;
  1178. if (pRootSig != nullptr) {
  1179. pList->SetGraphicsRootSignature(pRootSig);
  1180. }
  1181. pList->RSSetViewports(1, &viewport);
  1182. pList->RSSetScissorRects(1, &scissorRect);
  1183. // Indicate that the buffer will be used as a render target.
  1184. RecordTransitionBarrier(pList, pRenderTarget, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_RENDER_TARGET);
  1185. CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(pRtvHeap->GetCPUDescriptorHandleForHeapStart(), 0, rtvDescriptorSize);
  1186. pList->OMSetRenderTargets(1, &rtvHandle, FALSE, nullptr);
  1187. pList->ClearRenderTargetView(rtvHandle, ClearColor, 0, nullptr);
  1188. pList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
  1189. pList->IASetVertexBuffers(0, 1, pVertexBufferView);
  1190. pList->DrawInstanced(3, instanceCount, 0, 0);
  1191. // Transition to copy source and copy into read-back buffer.
  1192. RecordTransitionBarrier(pList, pRenderTarget, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1193. // Copy into read-back buffer.
  1194. UINT64 rowPitch = rtDesc.Width * 4;
  1195. if (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT)
  1196. rowPitch += D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
  1197. D3D12_PLACED_SUBRESOURCE_FOOTPRINT Footprint;
  1198. Footprint.Offset = 0;
  1199. Footprint.Footprint = CD3DX12_SUBRESOURCE_FOOTPRINT(DXGI_FORMAT_R8G8B8A8_UNORM, (UINT)rtDesc.Width, rtDesc.Height, 1, (UINT)rowPitch);
  1200. CD3DX12_TEXTURE_COPY_LOCATION DstLoc(pReadBuffer, Footprint);
  1201. CD3DX12_TEXTURE_COPY_LOCATION SrcLoc(pRenderTarget, 0);
  1202. pList->CopyTextureRegion(&DstLoc, 0, 0, 0, &SrcLoc, nullptr);
  1203. }
  1204. void RunRWByteBufferComputeTest(ID3D12Device *pDevice, LPCSTR shader, std::vector<uint32_t> &values);
  1205. void RunLifetimeIntrinsicTest(ID3D12Device *pDevice, LPCSTR shader, D3D_SHADER_MODEL shaderModel, bool useLibTarget, llvm::ArrayRef<LPCWSTR> options, std::vector<uint32_t> &values);
  1206. void RunLifetimeIntrinsicComputeTest(ID3D12Device *pDevice, LPCSTR pShader, CComPtr<ID3D12DescriptorHeap>& pUavHeap, CComPtr<ID3D12RootSignature>& pRootSignature,
  1207. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values);
  1208. void RunLifetimeIntrinsicLibTest(ID3D12Device *pDevice0, LPCSTR pShader, CComPtr<ID3D12RootSignature>& pRootSignature,
  1209. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions);
  1210. void SetDescriptorHeap(ID3D12GraphicsCommandList *pCommandList, ID3D12DescriptorHeap *pHeap) {
  1211. ID3D12DescriptorHeap *const pHeaps[1] = { pHeap };
  1212. pCommandList->SetDescriptorHeaps(1, pHeaps);
  1213. }
  1214. void WaitForSignal(ID3D12CommandQueue *pCQ, FenceObj &FO) {
  1215. ::WaitForSignal(pCQ, FO.m_fence, FO.m_fenceEvent, FO.m_fenceValue++);
  1216. }
  1217. };
  1218. #define WAVE_INTRINSIC_DXBC_GUARD \
  1219. "#ifdef USING_DXBC\r\n" \
  1220. "uint WaveGetLaneIndex() { return 1; }\r\n" \
  1221. "uint WaveReadLaneFirst(uint u) { return u; }\r\n" \
  1222. "bool WaveIsFirstLane() { return true; }\r\n" \
  1223. "uint WaveGetLaneCount() { return 1; }\r\n" \
  1224. "uint WaveReadLaneAt(uint n, uint u) { return u; }\r\n" \
  1225. "bool WaveActiveAnyTrue(bool b) { return b; }\r\n" \
  1226. "bool WaveActiveAllTrue(bool b) { return false; }\r\n" \
  1227. "uint WaveActiveAllEqual(uint u) { return u; }\r\n" \
  1228. "uint4 WaveActiveBallot(bool b) { return 1; }\r\n" \
  1229. "uint WaveActiveCountBits(uint u) { return 1; }\r\n" \
  1230. "uint WaveActiveSum(uint u) { return 1; }\r\n" \
  1231. "uint WaveActiveProduct(uint u) { return 1; }\r\n" \
  1232. "uint WaveActiveBitAnd(uint u) { return 1; }\r\n" \
  1233. "uint WaveActiveBitOr(uint u) { return 1; }\r\n" \
  1234. "uint WaveActiveBitXor(uint u) { return 1; }\r\n" \
  1235. "uint WaveActiveMin(uint u) { return 1; }\r\n" \
  1236. "uint WaveActiveMax(uint u) { return 1; }\r\n" \
  1237. "uint WavePrefixCountBits(uint u) { return 1; }\r\n" \
  1238. "uint WavePrefixSum(uint u) { return 1; }\r\n" \
  1239. "uint WavePrefixProduct(uint u) { return 1; }\r\n" \
  1240. "uint QuadReadLaneAt(uint a, uint u) { return 1; }\r\n" \
  1241. "uint QuadReadAcrossX(uint u) { return 1; }\r\n" \
  1242. "uint QuadReadAcrossY(uint u) { return 1; }\r\n" \
  1243. "uint QuadReadAcrossDiagonal(uint u) { return 1; }\r\n" \
  1244. "#endif\r\n"
  1245. static void SetupComputeValuePattern(std::vector<uint32_t> &values,
  1246. size_t count) {
  1247. values.resize(count); // one element per dispatch group, in bytes
  1248. for (size_t i = 0; i < count; ++i) {
  1249. values[i] = (uint32_t)i;
  1250. }
  1251. }
  1252. bool ExecutionTest::ExecutionTestClassSetup() {
  1253. #ifdef _HLK_CONF
  1254. // TODO: Enabling the D3D driver verifier. Check out the logic in the D3DConf_12_Core test.
  1255. VERIFY_SUCCEEDED(m_support.Initialize());
  1256. m_UseWarp = hlsl_test::GetTestParamUseWARP(false);
  1257. m_EnableDebugLayer = hlsl_test::GetTestParamBool(L"DebugLayer");
  1258. if (m_EnableDebugLayer) {
  1259. EnableDebugLayer();
  1260. }
  1261. return true;
  1262. #else
  1263. HRESULT hr = EnableExperimentalMode();
  1264. if (FAILED(hr)) {
  1265. LogCommentFmt(L"Unable to enable shader experimental mode - 0x%08x.", hr);
  1266. }
  1267. else if (hr == S_FALSE) {
  1268. LogCommentFmt(L"Experimental mode not enabled.");
  1269. }
  1270. else {
  1271. LogCommentFmt(L"Experimental mode enabled.");
  1272. }
  1273. hr = EnableDebugLayer();
  1274. if (FAILED(hr)) {
  1275. LogCommentFmt(L"Unable to enable debug layer - 0x%08x.", hr);
  1276. }
  1277. else {
  1278. LogCommentFmt(L"Debug layer enabled.");
  1279. }
  1280. return true;
  1281. #endif
  1282. }
  1283. void ExecutionTest::RunRWByteBufferComputeTest(ID3D12Device *pDevice, LPCSTR pShader, std::vector<uint32_t> &values) {
  1284. static const int DispatchGroupX = 1;
  1285. static const int DispatchGroupY = 1;
  1286. static const int DispatchGroupZ = 1;
  1287. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1288. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1289. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1290. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1291. UINT uavDescriptorSize;
  1292. FenceObj FO;
  1293. const UINT valueSizeInBytes = (UINT)values.size() * sizeof(uint32_t);
  1294. CreateComputeCommandQueue(pDevice, L"RunRWByteBufferComputeTest Command Queue", &pCommandQueue);
  1295. InitFenceObj(pDevice, &FO);
  1296. // Describe and create a UAV descriptor heap.
  1297. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1298. heapDesc.NumDescriptors = 1;
  1299. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1300. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1301. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1302. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  1303. // Create root signature.
  1304. CComPtr<ID3D12RootSignature> pRootSignature;
  1305. {
  1306. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1307. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1308. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1309. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1310. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1311. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  1312. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  1313. }
  1314. // Create pipeline state object.
  1315. CComPtr<ID3D12PipelineState> pComputeState;
  1316. CreateComputePSO(pDevice, pRootSignature, pShader, L"cs_6_0", &pComputeState);
  1317. // Create a command allocator and list for compute.
  1318. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1319. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1320. pCommandList->SetName(L"ExecutionTest::RunRWByteButterComputeTest Command List");
  1321. // Set up UAV resource.
  1322. CComPtr<ID3D12Resource> pUavResource;
  1323. CComPtr<ID3D12Resource> pReadBuffer;
  1324. CComPtr<ID3D12Resource> pUploadResource;
  1325. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  1326. VERIFY_SUCCEEDED(pUavResource->SetName(L"RunRWByteBufferComputeText UAV"));
  1327. VERIFY_SUCCEEDED(pReadBuffer->SetName(L"RunRWByteBufferComputeText UAV Read Buffer"));
  1328. VERIFY_SUCCEEDED(pUploadResource->SetName(L"RunRWByteBufferComputeText UAV Upload Buffer"));
  1329. // Close the command list and execute it to perform the GPU setup.
  1330. pCommandList->Close();
  1331. ExecuteCommandList(pCommandQueue, pCommandList);
  1332. WaitForSignal(pCommandQueue, FO);
  1333. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1334. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1335. // Run the compute shader and copy the results back to readable memory.
  1336. {
  1337. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1338. uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
  1339. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1340. uavDesc.Buffer.FirstElement = 0;
  1341. uavDesc.Buffer.NumElements = (UINT)values.size();
  1342. uavDesc.Buffer.StructureByteStride = 0;
  1343. uavDesc.Buffer.CounterOffsetInBytes = 0;
  1344. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  1345. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  1346. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  1347. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  1348. SetDescriptorHeap(pCommandList, pUavHeap);
  1349. pCommandList->SetComputeRootSignature(pRootSignature);
  1350. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  1351. }
  1352. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  1353. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1354. pCommandList->CopyResource(pReadBuffer, pUavResource);
  1355. pCommandList->Close();
  1356. ExecuteCommandList(pCommandQueue, pCommandList);
  1357. WaitForSignal(pCommandQueue, FO);
  1358. {
  1359. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  1360. uint32_t *pData = (uint32_t *)mappedData.data();
  1361. memcpy(values.data(), pData, (size_t)valueSizeInBytes);
  1362. }
  1363. WaitForSignal(pCommandQueue, FO);
  1364. }
  1365. void ExecutionTest::RunLifetimeIntrinsicComputeTest(ID3D12Device *pDevice, LPCSTR pShader, CComPtr<ID3D12DescriptorHeap>& pUavHeap, CComPtr<ID3D12RootSignature>& pRootSignature,
  1366. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values) {
  1367. // Create command queue.
  1368. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1369. CreateComputeCommandQueue(pDevice, L"RunLifetimeIntrinsicTest Command Queue", &pCommandQueue);
  1370. FenceObj FO;
  1371. InitFenceObj(pDevice, &FO);
  1372. // Compile shader "main" and create pipeline state object.
  1373. CComPtr<ID3D12PipelineState> pComputeState;
  1374. CreateComputePSO(pDevice, pRootSignature, pShader, pTargetProfile, &pComputeState, pOptions, numOptions);
  1375. // Create a command allocator and list for compute.
  1376. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1377. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1378. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1379. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1380. pCommandList->SetName(L"ExecutionTest::RunLifetimeIntrinsicTest Command List");
  1381. // Set up UAV resource.
  1382. const UINT valueSizeInBytes = (UINT)values.size() * sizeof(uint32_t);
  1383. CComPtr<ID3D12Resource> pUavResource;
  1384. CComPtr<ID3D12Resource> pReadBuffer;
  1385. CComPtr<ID3D12Resource> pUploadResource;
  1386. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  1387. VERIFY_SUCCEEDED(pUavResource->SetName(L"RunLifetimeIntrinsicTest UAV"));
  1388. VERIFY_SUCCEEDED(pReadBuffer->SetName(L"RunLifetimeIntrinsicTest UAV Read Buffer"));
  1389. VERIFY_SUCCEEDED(pUploadResource->SetName(L"RunLifetimeIntrinsicTest UAV Upload Buffer"));
  1390. // Close the command list and execute it to perform the GPU setup.
  1391. pCommandList->Close();
  1392. ExecuteCommandList(pCommandQueue, pCommandList);
  1393. WaitForSignal(pCommandQueue, FO);
  1394. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1395. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1396. // Run the compute shader and copy the results back to readable memory.
  1397. {
  1398. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1399. uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
  1400. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1401. uavDesc.Buffer.FirstElement = 0;
  1402. uavDesc.Buffer.NumElements = (UINT)values.size();
  1403. uavDesc.Buffer.StructureByteStride = 0;
  1404. uavDesc.Buffer.CounterOffsetInBytes = 0;
  1405. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  1406. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  1407. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  1408. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  1409. SetDescriptorHeap(pCommandList, pUavHeap);
  1410. pCommandList->SetComputeRootSignature(pRootSignature);
  1411. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  1412. }
  1413. static const int DispatchGroupX = 1;
  1414. static const int DispatchGroupY = 1;
  1415. static const int DispatchGroupZ = 1;
  1416. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  1417. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1418. pCommandList->CopyResource(pReadBuffer, pUavResource);
  1419. pCommandList->Close();
  1420. ExecuteCommandList(pCommandQueue, pCommandList);
  1421. WaitForSignal(pCommandQueue, FO);
  1422. {
  1423. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  1424. uint32_t *pData = (uint32_t *)mappedData.data();
  1425. memcpy(values.data(), pData, (size_t)valueSizeInBytes);
  1426. }
  1427. WaitForSignal(pCommandQueue, FO);
  1428. }
  1429. void ExecutionTest::RunLifetimeIntrinsicLibTest(ID3D12Device *pDevice0, LPCSTR pShader, CComPtr<ID3D12RootSignature>& pRootSignature,
  1430. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions) {
  1431. CComPtr<ID3D12Device5> pDevice;
  1432. VERIFY_SUCCEEDED(pDevice0->QueryInterface(IID_PPV_ARGS(&pDevice)));
  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. llvm::ArrayRef<LPCWSTR> options, 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(pDevice, pShader, pRootSignature, pTargetProfile,
  1505. const_cast<LPCWSTR*>(options.data()), static_cast<int>(options.size()));
  1506. } else {
  1507. RunLifetimeIntrinsicComputeTest(pDevice, pShader, pUavHeap, pRootSignature, pTargetProfile,
  1508. const_cast<LPCWSTR*>(options.data()), static_cast<int>(options.size()), values);
  1509. }
  1510. }
  1511. TEST_F(ExecutionTest, LifetimeIntrinsicTest) {
  1512. // The only thing we test here is that existence of lifetime intrinsics or
  1513. // their fallback replacement (store undef or store zeroinitializer) do not
  1514. // cause any issues in the runtime and driver stack.
  1515. // The easiest way to force placement of intrinsics is to create an array in
  1516. // a local scope that is dynamically indexed. It must not be optimized away,
  1517. // so we do some bogus initialization that prevents this. Since all the code
  1518. // is guarded by a conditional that is dynamically always false, the actual
  1519. // effect of the shader is that the same value that was read is written back.
  1520. static const char* pShader = R"(
  1521. RWByteAddressBuffer g_bab : register(u0);
  1522. void fn(uint GI) {
  1523. const uint addr = GI * 4;
  1524. const int val = g_bab.Load(addr);
  1525. int res = val;
  1526. if (val < 0) { // Never true.
  1527. int arr[200];
  1528. for (int i = 0; i < 200; ++i) {
  1529. arr[i] = arr[val - i];
  1530. }
  1531. res += arr[val];
  1532. }
  1533. g_bab.Store(addr, (uint)res);
  1534. }
  1535. [numthreads(8,8,1)]
  1536. void main(uint GI : SV_GroupIndex) {
  1537. fn(GI);
  1538. }
  1539. [shader("raygeneration")]
  1540. void RayGen() {
  1541. const uint d = DispatchRaysIndex().x;
  1542. const uint g = g > 64 ? 63 : g;
  1543. fn(g);
  1544. }
  1545. )";
  1546. static const int NumThreadsX = 8;
  1547. static const int NumThreadsY = 8;
  1548. static const int NumThreadsZ = 1;
  1549. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1550. static const int DispatchGroupCount = 1;
  1551. CComPtr<ID3D12Device> pDevice;
  1552. bool bSM_6_6_Supported = CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6, false, true);
  1553. bool bSM_6_3_Supported = bSM_6_6_Supported;
  1554. if (!bSM_6_6_Supported) {
  1555. // Try 6.3 for downlevel DXR case
  1556. bSM_6_3_Supported = CreateDevice(&pDevice, D3D_SHADER_MODEL_6_3, false, true);
  1557. }
  1558. if (!bSM_6_3_Supported) {
  1559. // Otherwise, 6.0 better be supported for compute case
  1560. VERIFY_IS_TRUE(CreateDevice(&pDevice, D3D_SHADER_MODEL_6_0, false, false));
  1561. }
  1562. bool bDXRSupported = bSM_6_3_Supported && DoesDeviceSupportRayTracing(pDevice);
  1563. if (GetTestParamUseWARP(UseWarpByDefault()) || IsDeviceBasicAdapter(pDevice)) {
  1564. WEX::Logging::Log::Comment(L"WARP has a known issue with LifetimeIntrinsicTest.");
  1565. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  1566. return;
  1567. }
  1568. if (!bSM_6_6_Supported) {
  1569. WEX::Logging::Log::Comment(L"Native lifetime markers skipped, device does not support SM 6.6");
  1570. }
  1571. if (!bDXRSupported) {
  1572. WEX::Logging::Log::Comment(L"DXR lifetime tests skipped, device does not support DXR");
  1573. }
  1574. std::vector<uint32_t> values;
  1575. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1576. // Run a number of tests for different configurations that will cause
  1577. // lifetime intrinsics to be:
  1578. // - placed directly
  1579. // - translated to an undef store
  1580. // - translated to a zeroinitializer store
  1581. // against compute and DXR targets, downlevel and SM 6.6:
  1582. // - downlevel: cs_6_0, lib_6_3 (DXR)
  1583. // - cs_6_6, lib_6_6 (DXR)
  1584. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1585. WEX::Logging::Log::Comment(L"==== cs_6_0 with default translation");
  1586. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_0, false,
  1587. {L"-enable-lifetime-markers"}, values);
  1588. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1589. if (bDXRSupported) {
  1590. WEX::Logging::Log::Comment(L"==== DXR lib_6_3 with default translation");
  1591. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_3, true,
  1592. {L"-enable-lifetime-markers"}, values);
  1593. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1594. }
  1595. WEX::Logging::Log::Comment(L"==== cs_6_0 with zeroinitializer translation");
  1596. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_0, false,
  1597. {L"-enable-lifetime-markers", L"-force-zero-store-lifetimes"}, values);
  1598. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1599. if (bDXRSupported) {
  1600. WEX::Logging::Log::Comment(L"==== DXR lib_6_3 with zeroinitializer translation");
  1601. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_3, true,
  1602. {L"-enable-lifetime-markers", L"-force-zero-store-lifetimes"}, values);
  1603. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1604. }
  1605. if (bSM_6_6_Supported) {
  1606. WEX::Logging::Log::Comment(L"==== cs_6_6 with zeroinitializer translation");
  1607. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_6, false,
  1608. {L"-enable-lifetime-markers", L"-force-zero-store-lifetimes"}, values);
  1609. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1610. if (bDXRSupported) {
  1611. WEX::Logging::Log::Comment(L"==== DXR lib_6_6 with zeroinitializer translation");
  1612. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_6, true,
  1613. {L"-enable-lifetime-markers", L"-force-zero-store-lifetimes"}, values);
  1614. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1615. }
  1616. WEX::Logging::Log::Comment(L"==== cs_6_6 with native lifetime markers");
  1617. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_6, false,
  1618. {L"-enable-lifetime-markers"}, values);
  1619. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1620. if (bDXRSupported) {
  1621. WEX::Logging::Log::Comment(L"==== DXR lib_6_6 with native lifetime markers");
  1622. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_6, true,
  1623. {L"-enable-lifetime-markers"}, values);
  1624. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1625. }
  1626. }
  1627. }
  1628. TEST_F(ExecutionTest, BasicComputeTest) {
  1629. #ifndef _HLK_CONF
  1630. //
  1631. // BasicComputeTest is a simple compute shader that can be used as the basis
  1632. // for more interesting compute execution tests.
  1633. // The HLSL is compatible with shader models <=5.1 to allow using the DXBC
  1634. // rendering code paths for comparison.
  1635. //
  1636. static const char pShader[] =
  1637. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1638. "[numthreads(8,8,1)]\r\n"
  1639. "void main(uint GI : SV_GroupIndex) {"
  1640. " uint addr = GI * 4;\r\n"
  1641. " uint val = g_bab.Load(addr);\r\n"
  1642. " DeviceMemoryBarrierWithGroupSync();\r\n"
  1643. " g_bab.Store(addr, val + 1);\r\n"
  1644. "}";
  1645. static const int NumThreadsX = 8;
  1646. static const int NumThreadsY = 8;
  1647. static const int NumThreadsZ = 1;
  1648. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1649. static const int DispatchGroupCount = 1;
  1650. CComPtr<ID3D12Device> pDevice;
  1651. if (!CreateDevice(&pDevice))
  1652. return;
  1653. std::vector<uint32_t> values;
  1654. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1655. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1656. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1657. VERIFY_ARE_EQUAL(values[0], (uint32_t)1);
  1658. #endif
  1659. }
  1660. TEST_F(ExecutionTest, BasicTriangleTest) {
  1661. #ifndef _HLK_CONF
  1662. static const UINT FrameCount = 2;
  1663. static const UINT m_width = 320;
  1664. static const UINT m_height = 200;
  1665. static const float m_aspectRatio = static_cast<float>(m_width) / static_cast<float>(m_height);
  1666. struct Vertex {
  1667. XMFLOAT3 position;
  1668. XMFLOAT4 color;
  1669. };
  1670. // Pipeline objects.
  1671. CComPtr<ID3D12Device> pDevice;
  1672. CComPtr<ID3D12Resource> pRenderTarget;
  1673. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1674. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1675. CComPtr<ID3D12RootSignature> pRootSig;
  1676. CComPtr<ID3D12DescriptorHeap> pRtvHeap;
  1677. CComPtr<ID3D12PipelineState> pPipelineState;
  1678. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1679. CComPtr<ID3D12Resource> pReadBuffer;
  1680. UINT rtvDescriptorSize;
  1681. CComPtr<ID3D12Resource> pVertexBuffer;
  1682. D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
  1683. // Synchronization objects.
  1684. FenceObj FO;
  1685. // Shaders.
  1686. static const char pShaders[] =
  1687. "struct PSInput {\r\n"
  1688. " float4 position : SV_POSITION;\r\n"
  1689. " float4 color : COLOR;\r\n"
  1690. "};\r\n\r\n"
  1691. "PSInput VSMain(float4 position : POSITION, float4 color : COLOR) {\r\n"
  1692. " PSInput result;\r\n"
  1693. "\r\n"
  1694. " result.position = position;\r\n"
  1695. " result.color = color;\r\n"
  1696. " return result;\r\n"
  1697. "}\r\n\r\n"
  1698. "float4 PSMain(PSInput input) : SV_TARGET {\r\n"
  1699. " return 1; //input.color;\r\n"
  1700. "};\r\n";
  1701. if (!CreateDevice(&pDevice))
  1702. return;
  1703. struct BasicTestChecker {
  1704. CComPtr<ID3D12Device> m_pDevice;
  1705. CComPtr<ID3D12InfoQueue> m_pInfoQueue;
  1706. bool m_OK = false;
  1707. void SetOK(bool value) { m_OK = value; }
  1708. BasicTestChecker(ID3D12Device *pDevice) : m_pDevice(pDevice) {
  1709. if (FAILED(m_pDevice.QueryInterface(&m_pInfoQueue)))
  1710. return;
  1711. m_pInfoQueue->PushEmptyStorageFilter();
  1712. m_pInfoQueue->PushEmptyRetrievalFilter();
  1713. }
  1714. ~BasicTestChecker() {
  1715. if (!m_OK && m_pInfoQueue != nullptr) {
  1716. UINT64 count = m_pInfoQueue->GetNumStoredMessages();
  1717. bool invalidBytecodeFound = false;
  1718. CAtlArray<BYTE> m_pBytes;
  1719. for (UINT64 i = 0; i < count; ++i) {
  1720. SIZE_T len = 0;
  1721. if (FAILED(m_pInfoQueue->GetMessageA(i, nullptr, &len)))
  1722. continue;
  1723. if (m_pBytes.GetCount() < len && !m_pBytes.SetCount(len))
  1724. continue;
  1725. D3D12_MESSAGE *pMsg = (D3D12_MESSAGE *)m_pBytes.GetData();
  1726. if (FAILED(m_pInfoQueue->GetMessageA(i, pMsg, &len)))
  1727. continue;
  1728. if (pMsg->ID == D3D12_MESSAGE_ID_CREATEVERTEXSHADER_INVALIDSHADERBYTECODE ||
  1729. pMsg->ID == D3D12_MESSAGE_ID_CREATEPIXELSHADER_INVALIDSHADERBYTECODE) {
  1730. invalidBytecodeFound = true;
  1731. break;
  1732. }
  1733. }
  1734. if (invalidBytecodeFound) {
  1735. LogCommentFmt(L"%s", L"Found an invalid bytecode message. This "
  1736. L"typically indicates that experimental mode "
  1737. L"is not set up properly.");
  1738. if (!GetTestParamBool(L"ExperimentalShaders")) {
  1739. LogCommentFmt(L"Note that the ExperimentalShaders test parameter isn't set.");
  1740. }
  1741. }
  1742. else {
  1743. LogCommentFmt(L"Did not find corrupt pixel or vertex shaders in "
  1744. L"queue - dumping complete queue.");
  1745. WriteInfoQueueMessages(nullptr, OutputFn, m_pInfoQueue);
  1746. }
  1747. }
  1748. }
  1749. static void __stdcall OutputFn(void *pCtx, const wchar_t *pMsg) {
  1750. UNREFERENCED_PARAMETER(pCtx);
  1751. LogCommentFmt(L"%s", pMsg);
  1752. }
  1753. };
  1754. BasicTestChecker BTC(pDevice);
  1755. {
  1756. InitFenceObj(pDevice, &FO);
  1757. CreateRtvDescriptorHeap(pDevice, FrameCount, &pRtvHeap, &rtvDescriptorSize);
  1758. CreateRenderTargetAndReadback(pDevice, pRtvHeap, m_width, m_height, &pRenderTarget, &pReadBuffer);
  1759. // Create an empty root signature.
  1760. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1761. rootSignatureDesc.Init(
  1762. 0, nullptr, 0, nullptr,
  1763. D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
  1764. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSig);
  1765. // Create the pipeline state, which includes compiling and loading shaders.
  1766. // Define the vertex input layout.
  1767. D3D12_INPUT_ELEMENT_DESC inputElementDescs[] = {
  1768. {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
  1769. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
  1770. {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12,
  1771. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}};
  1772. D3D12_INPUT_LAYOUT_DESC InputLayout = { inputElementDescs, _countof(inputElementDescs) };
  1773. CreateGraphicsPSO(pDevice, &InputLayout, pRootSig, pShaders, &pPipelineState);
  1774. CreateGraphicsCommandQueueAndList(pDevice, &pCommandQueue,
  1775. &pCommandAllocator, &pCommandList,
  1776. pPipelineState);
  1777. // Define the geometry for a triangle.
  1778. Vertex triangleVertices[] = {
  1779. { { 0.0f, 0.25f * m_aspectRatio, 0.0f },{ 1.0f, 0.0f, 0.0f, 1.0f } },
  1780. { { 0.25f, -0.25f * m_aspectRatio, 0.0f },{ 0.0f, 1.0f, 0.0f, 1.0f } },
  1781. { { -0.25f, -0.25f * m_aspectRatio, 0.0f },{ 0.0f, 0.0f, 1.0f, 1.0f } } };
  1782. CreateVertexBuffer(pDevice, triangleVertices, &pVertexBuffer, &vertexBufferView);
  1783. WaitForSignal(pCommandQueue, FO);
  1784. }
  1785. // Render and execute the command list.
  1786. RecordRenderAndReadback(pCommandList, pRtvHeap, rtvDescriptorSize, 1,
  1787. &vertexBufferView, pRootSig, pRenderTarget,
  1788. pReadBuffer);
  1789. VERIFY_SUCCEEDED(pCommandList->Close());
  1790. ExecuteCommandList(pCommandQueue, pCommandList);
  1791. // Wait for previous frame.
  1792. WaitForSignal(pCommandQueue, FO);
  1793. // At this point, we've verified that execution succeeded with DXIL.
  1794. BTC.SetOK(true);
  1795. // Read back to CPU and examine contents.
  1796. {
  1797. MappedData data(pReadBuffer, m_width * m_height * 4);
  1798. const uint32_t *pPixels = (uint32_t *)data.data();
  1799. if (SaveImages()) {
  1800. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, m_width, m_height, L"basic.bmp");
  1801. }
  1802. uint32_t top = pPixels[m_width / 2]; // Top center.
  1803. uint32_t mid = pPixels[m_width / 2 + m_width * (m_height / 2)]; // Middle center.
  1804. VERIFY_ARE_EQUAL(0xff663300, top); // clear color
  1805. VERIFY_ARE_EQUAL(0xffffffff, mid); // white
  1806. }
  1807. #endif
  1808. }
  1809. TEST_F(ExecutionTest, Int64Test) {
  1810. static const char pShader[] =
  1811. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1812. "[numthreads(8,8,1)]\r\n"
  1813. "void main(uint GI : SV_GroupIndex) {"
  1814. " uint addr = GI * 4;\r\n"
  1815. " uint val = g_bab.Load(addr);\r\n"
  1816. " uint64_t u64 = val;\r\n"
  1817. " u64 *= val;\r\n"
  1818. " g_bab.Store(addr, (uint)(u64 >> 32));\r\n"
  1819. "}";
  1820. static const int NumThreadsX = 8;
  1821. static const int NumThreadsY = 8;
  1822. static const int NumThreadsZ = 1;
  1823. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1824. static const int DispatchGroupCount = 1;
  1825. CComPtr<ID3D12Device> pDevice;
  1826. if (!CreateDevice(&pDevice))
  1827. return;
  1828. if (!DoesDeviceSupportInt64(pDevice)) {
  1829. // Optional feature, so it's correct to not support it if declared as such.
  1830. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  1831. return;
  1832. }
  1833. std::vector<uint32_t> values;
  1834. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1835. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1836. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1837. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1838. }
  1839. TEST_F(ExecutionTest, SignTest) {
  1840. static const char pShader[] =
  1841. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1842. "[numthreads(8,1,1)]\r\n"
  1843. "void main(uint GI : SV_GroupIndex) {"
  1844. " uint addr = GI * 4;\r\n"
  1845. " int val = g_bab.Load(addr);\r\n"
  1846. " g_bab.Store(addr, (uint)(sign(val)));\r\n"
  1847. "}";
  1848. static const int NumThreadsX = 8;
  1849. static const int NumThreadsY = 1;
  1850. static const int NumThreadsZ = 1;
  1851. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1852. static const int DispatchGroupCount = 1;
  1853. CComPtr<ID3D12Device> pDevice;
  1854. if (!CreateDevice(&pDevice))
  1855. return;
  1856. const uint32_t neg1 = (uint32_t)-1;
  1857. uint32_t origValues[] = { (uint32_t)-3, (uint32_t)-2, neg1, 0, 1, 2, 3, 4 };
  1858. std::vector<uint32_t> values(origValues, origValues + _countof(origValues));
  1859. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1860. VERIFY_ARE_EQUAL(values[0], neg1);
  1861. VERIFY_ARE_EQUAL(values[1], neg1);
  1862. VERIFY_ARE_EQUAL(values[2], neg1);
  1863. VERIFY_ARE_EQUAL(values[3], (uint32_t)0);
  1864. VERIFY_ARE_EQUAL(values[4], (uint32_t)1);
  1865. VERIFY_ARE_EQUAL(values[5], (uint32_t)1);
  1866. VERIFY_ARE_EQUAL(values[6], (uint32_t)1);
  1867. VERIFY_ARE_EQUAL(values[7], (uint32_t)1);
  1868. }
  1869. TEST_F(ExecutionTest, WaveIntrinsicsDDITest) {
  1870. #ifndef _HLK_CONF
  1871. CComPtr<ID3D12Device> pDevice;
  1872. if (!CreateDevice(&pDevice))
  1873. return;
  1874. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  1875. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  1876. return;
  1877. bool waveSupported = O.WaveOps;
  1878. UINT laneCountMin = O.WaveLaneCountMin;
  1879. UINT laneCountMax = O.WaveLaneCountMax;
  1880. LogCommentFmt(L"WaveOps %i, WaveLaneCountMin %u, WaveLaneCountMax %u", waveSupported, laneCountMin, laneCountMax);
  1881. VERIFY_IS_TRUE(laneCountMin <= laneCountMax);
  1882. if (waveSupported) {
  1883. VERIFY_IS_TRUE(laneCountMin > 0 && laneCountMax > 0);
  1884. }
  1885. else {
  1886. VERIFY_IS_TRUE(laneCountMin == 0 && laneCountMax == 0);
  1887. }
  1888. #endif
  1889. }
  1890. TEST_F(ExecutionTest, WaveIntrinsicsTest) {
  1891. #ifndef _HLK_CONF
  1892. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  1893. struct PerThreadData {
  1894. uint32_t id, flags, laneIndex, laneCount, firstLaneId, preds, firstlaneX, lane1X;
  1895. uint32_t allBC, allSum, allProd, allAND, allOR, allXOR, allMin, allMax;
  1896. uint32_t pfBC, pfSum, pfProd;
  1897. uint32_t ballot[4];
  1898. uint32_t diver; // divergent value, used in calculation
  1899. int32_t i_diver; // divergent value, used in calculation
  1900. int32_t i_allMax, i_allMin, i_allSum, i_allProd;
  1901. int32_t i_pfSum, i_pfProd;
  1902. };
  1903. static const char pShader[] =
  1904. WAVE_INTRINSIC_DXBC_GUARD
  1905. "struct PerThreadData {\r\n"
  1906. " uint id, flags, laneIndex, laneCount, firstLaneId, preds, firstlaneX, lane1X;\r\n"
  1907. " uint allBC, allSum, allProd, allAND, allOR, allXOR, allMin, allMax;\r\n"
  1908. " uint pfBC, pfSum, pfProd;\r\n"
  1909. " uint4 ballot;\r\n"
  1910. " uint diver;\r\n"
  1911. " int i_diver;\r\n"
  1912. " int i_allMax, i_allMin, i_allSum, i_allProd;\r\n"
  1913. " int i_pfSum, i_pfProd;\r\n"
  1914. "};\r\n"
  1915. "RWStructuredBuffer<PerThreadData> g_sb : register(u0);\r\n"
  1916. "[numthreads(8,8,1)]\r\n"
  1917. "void main(uint GI : SV_GroupIndex, uint3 GTID : SV_GroupThreadID) {"
  1918. " PerThreadData pts = g_sb[GI];\r\n"
  1919. " uint diver = GTID.x + 2;\r\n"
  1920. " pts.diver = diver;\r\n"
  1921. " pts.flags = 0;\r\n"
  1922. " pts.preds = 0;\r\n"
  1923. " if (WaveIsFirstLane()) pts.flags |= 1;\r\n"
  1924. " pts.laneIndex = WaveGetLaneIndex();\r\n"
  1925. " pts.laneCount = WaveGetLaneCount();\r\n"
  1926. " pts.firstLaneId = WaveReadLaneFirst(pts.id);\r\n"
  1927. " pts.preds |= ((WaveActiveAnyTrue(diver == 1) ? 1 : 0) << 0);\r\n"
  1928. " pts.preds |= ((WaveActiveAllTrue(diver == 1) ? 1 : 0) << 1);\r\n"
  1929. " pts.preds |= ((WaveActiveAllEqual(diver) ? 1 : 0) << 2);\r\n"
  1930. " pts.preds |= ((WaveActiveAllEqual(GTID.z) ? 1 : 0) << 3);\r\n"
  1931. " pts.preds |= ((WaveActiveAllEqual(WaveReadLaneFirst(diver)) ? 1 : 0) << 4);\r\n"
  1932. " pts.ballot = WaveActiveBallot(diver > 3);\r\n"
  1933. " pts.firstlaneX = WaveReadLaneFirst(GTID.x);\r\n"
  1934. " pts.lane1X = WaveReadLaneAt(GTID.x, 1);\r\n"
  1935. "\r\n"
  1936. " pts.allBC = WaveActiveCountBits(diver > 3);\r\n"
  1937. " pts.allSum = WaveActiveSum(diver);\r\n"
  1938. " pts.allProd = WaveActiveProduct(diver);\r\n"
  1939. " pts.allAND = WaveActiveBitAnd(diver);\r\n"
  1940. " pts.allOR = WaveActiveBitOr(diver);\r\n"
  1941. " pts.allXOR = WaveActiveBitXor(diver);\r\n"
  1942. " pts.allMin = WaveActiveMin(diver);\r\n"
  1943. " pts.allMax = WaveActiveMax(diver);\r\n"
  1944. "\r\n"
  1945. " pts.pfBC = WavePrefixCountBits(diver > 3);\r\n"
  1946. " pts.pfSum = WavePrefixSum(diver);\r\n"
  1947. " pts.pfProd = WavePrefixProduct(diver);\r\n"
  1948. "\r\n"
  1949. " int i_diver = pts.i_diver;\r\n"
  1950. " pts.i_allMax = WaveActiveMax(i_diver);\r\n"
  1951. " pts.i_allMin = WaveActiveMin(i_diver);\r\n"
  1952. " pts.i_allSum = WaveActiveSum(i_diver);\r\n"
  1953. " pts.i_allProd = WaveActiveProduct(i_diver);\r\n"
  1954. " pts.i_pfSum = WavePrefixSum(i_diver);\r\n"
  1955. " pts.i_pfProd = WavePrefixProduct(i_diver);\r\n"
  1956. "\r\n"
  1957. " g_sb[GI] = pts;\r\n"
  1958. "}";
  1959. static const int NumtheadsX = 8;
  1960. static const int NumtheadsY = 8;
  1961. static const int NumtheadsZ = 1;
  1962. static const int ThreadsPerGroup = NumtheadsX * NumtheadsY * NumtheadsZ;
  1963. static const int DispatchGroupCount = 1;
  1964. CComPtr<ID3D12Device> pDevice;
  1965. if (!CreateDevice(&pDevice))
  1966. return;
  1967. if (!DoesDeviceSupportWaveOps(pDevice)) {
  1968. // Optional feature, so it's correct to not support it if declared as such.
  1969. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  1970. return;
  1971. }
  1972. std::vector<PerThreadData> values;
  1973. values.resize(ThreadsPerGroup * DispatchGroupCount);
  1974. for (size_t i = 0; i < values.size(); ++i) {
  1975. memset(&values[i], 0, sizeof(PerThreadData));
  1976. values[i].id = (uint32_t)i;
  1977. values[i].i_diver = (int)i;
  1978. values[i].i_diver *= (i % 2) ? 1 : -1;
  1979. }
  1980. static const int DispatchGroupX = 1;
  1981. static const int DispatchGroupY = 1;
  1982. static const int DispatchGroupZ = 1;
  1983. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1984. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1985. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1986. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1987. UINT uavDescriptorSize;
  1988. FenceObj FO;
  1989. bool dxbc = UseDxbc();
  1990. const size_t valueSizeInBytes = values.size() * sizeof(PerThreadData);
  1991. CreateComputeCommandQueue(pDevice, L"WaveIntrinsicsTest Command Queue", &pCommandQueue);
  1992. InitFenceObj(pDevice, &FO);
  1993. // Describe and create a UAV descriptor heap.
  1994. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1995. heapDesc.NumDescriptors = 1;
  1996. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1997. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1998. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1999. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  2000. // Create root signature.
  2001. CComPtr<ID3D12RootSignature> pRootSignature;
  2002. {
  2003. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  2004. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  2005. CD3DX12_ROOT_PARAMETER rootParameters[1];
  2006. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  2007. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  2008. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  2009. CComPtr<ID3DBlob> signature;
  2010. CComPtr<ID3DBlob> error;
  2011. VERIFY_SUCCEEDED(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
  2012. VERIFY_SUCCEEDED(pDevice->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&pRootSignature)));
  2013. }
  2014. // Create pipeline state object.
  2015. CComPtr<ID3D12PipelineState> pComputeState;
  2016. CreateComputePSO(pDevice, pRootSignature, pShader, L"cs_6_0", &pComputeState);
  2017. // Create a command allocator and list for compute.
  2018. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  2019. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  2020. // Set up UAV resource.
  2021. CComPtr<ID3D12Resource> pUavResource;
  2022. CComPtr<ID3D12Resource> pReadBuffer;
  2023. CComPtr<ID3D12Resource> pUploadResource;
  2024. CreateTestUavs(pDevice, pCommandList, values.data(), (UINT)valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  2025. // Close the command list and execute it to perform the GPU setup.
  2026. pCommandList->Close();
  2027. ExecuteCommandList(pCommandQueue, pCommandList);
  2028. WaitForSignal(pCommandQueue, FO);
  2029. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  2030. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  2031. // Run the compute shader and copy the results back to readable memory.
  2032. {
  2033. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  2034. uavDesc.Format = DXGI_FORMAT_UNKNOWN;
  2035. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  2036. uavDesc.Buffer.FirstElement = 0;
  2037. uavDesc.Buffer.NumElements = (UINT)values.size();
  2038. uavDesc.Buffer.StructureByteStride = sizeof(PerThreadData);
  2039. uavDesc.Buffer.CounterOffsetInBytes = 0;
  2040. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  2041. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  2042. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  2043. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  2044. SetDescriptorHeap(pCommandList, pUavHeap);
  2045. pCommandList->SetComputeRootSignature(pRootSignature);
  2046. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  2047. }
  2048. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  2049. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2050. pCommandList->CopyResource(pReadBuffer, pUavResource);
  2051. pCommandList->Close();
  2052. ExecuteCommandList(pCommandQueue, pCommandList);
  2053. WaitForSignal(pCommandQueue, FO);
  2054. {
  2055. MappedData mappedData(pReadBuffer, (UINT)valueSizeInBytes);
  2056. PerThreadData *pData = (PerThreadData *)mappedData.data();
  2057. memcpy(values.data(), pData, valueSizeInBytes);
  2058. // Gather some general data.
  2059. // The 'firstLaneId' captures a unique number per first-lane per wave.
  2060. // Counting the number distinct firstLaneIds gives us the number of waves.
  2061. std::vector<uint32_t> firstLaneIds;
  2062. for (size_t i = 0; i < values.size(); ++i) {
  2063. PerThreadData &pts = values[i];
  2064. uint32_t firstLaneId = pts.firstLaneId;
  2065. if (!contains(firstLaneIds, firstLaneId)) {
  2066. firstLaneIds.push_back(firstLaneId);
  2067. }
  2068. }
  2069. // Waves should cover 4 threads or more.
  2070. LogCommentFmt(L"Found %u distinct lane ids: %u", firstLaneIds.size());
  2071. if (!dxbc) {
  2072. VERIFY_IS_GREATER_THAN_OR_EQUAL(values.size() / 4, firstLaneIds.size());
  2073. }
  2074. // Now, group threads into waves.
  2075. std::map<uint32_t, std::unique_ptr<std::vector<PerThreadData *> > > waves;
  2076. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  2077. waves[firstLaneIds[i]] = std::make_unique<std::vector<PerThreadData *> >();
  2078. }
  2079. for (size_t i = 0; i < values.size(); ++i) {
  2080. PerThreadData &pts = values[i];
  2081. std::unique_ptr<std::vector<PerThreadData *> > &wave = waves[pts.firstLaneId];
  2082. wave->push_back(&pts);
  2083. }
  2084. // Verify that all the wave values are coherent across the wave.
  2085. for (size_t i = 0; i < values.size(); ++i) {
  2086. PerThreadData &pts = values[i];
  2087. std::unique_ptr<std::vector<PerThreadData *> > &wave = waves[pts.firstLaneId];
  2088. // Sort the lanes by increasing lane ID.
  2089. struct LaneIdOrderPred {
  2090. bool operator()(PerThreadData *a, PerThreadData *b) {
  2091. return a->laneIndex < b->laneIndex;
  2092. }
  2093. };
  2094. std::sort(wave.get()->begin(), wave.get()->end(), LaneIdOrderPred());
  2095. // Verify some interesting properties of the first lane.
  2096. uint32_t pfBC, pfSum, pfProd;
  2097. int32_t i_pfSum, i_pfProd;
  2098. int32_t i_allMax, i_allMin;
  2099. {
  2100. PerThreadData *ptdFirst = wave->front();
  2101. VERIFY_IS_TRUE(0 != (ptdFirst->flags & 1)); // FirstLane sets this bit.
  2102. VERIFY_IS_TRUE(0 == ptdFirst->pfBC);
  2103. VERIFY_IS_TRUE(0 == ptdFirst->pfSum);
  2104. VERIFY_IS_TRUE(1 == ptdFirst->pfProd);
  2105. VERIFY_IS_TRUE(0 == ptdFirst->i_pfSum);
  2106. VERIFY_IS_TRUE(1 == ptdFirst->i_pfProd);
  2107. pfBC = (ptdFirst->diver > 3) ? 1 : 0;
  2108. pfSum = ptdFirst->diver;
  2109. pfProd = ptdFirst->diver;
  2110. i_pfSum = ptdFirst->i_diver;
  2111. i_pfProd = ptdFirst->i_diver;
  2112. i_allMax = i_allMin = ptdFirst->i_diver;
  2113. }
  2114. // Calculate values which take into consideration all lanes.
  2115. uint32_t preds = 0;
  2116. preds |= 1 << 1; // AllTrue starts true, switches to false if needed.
  2117. preds |= 1 << 2; // AllEqual starts true, switches to false if needed.
  2118. preds |= 1 << 3; // WaveActiveAllEqual(GTID.z) is always true
  2119. preds |= 1 << 4; // (WaveActiveAllEqual(WaveReadLaneFirst(diver)) is always true
  2120. uint32_t ballot[4] = { 0, 0, 0, 0 };
  2121. int32_t i_allSum = 0, i_allProd = 1;
  2122. for (size_t n = 0; n < wave->size(); ++n) {
  2123. std::vector<PerThreadData *> &lanes = *wave.get();
  2124. // pts.preds |= ((WaveActiveAnyTrue(diver == 1) ? 1 : 0) << 0);
  2125. if (lanes[n]->diver == 1) preds |= (1 << 0);
  2126. // pts.preds |= ((WaveActiveAllTrue(diver == 1) ? 1 : 0) << 1);
  2127. if (lanes[n]->diver != 1) preds &= ~(1 << 1);
  2128. // pts.preds |= ((WaveActiveAllEqual(diver) ? 1 : 0) << 2);
  2129. if (lanes[0]->diver != lanes[n]->diver) preds &= ~(1 << 2);
  2130. // pts.ballot = WaveActiveBallot(diver > 3);\r\n"
  2131. if (lanes[n]->diver > 3) {
  2132. // This is the uint4 result layout:
  2133. // .x -> bits 0 .. 31
  2134. // .y -> bits 32 .. 63
  2135. // .z -> bits 64 .. 95
  2136. // .w -> bits 96 ..127
  2137. uint32_t component = lanes[n]->laneIndex / 32;
  2138. uint32_t bit = lanes[n]->laneIndex % 32;
  2139. ballot[component] |= 1 << bit;
  2140. }
  2141. i_allMax = std::max(lanes[n]->i_diver, i_allMax);
  2142. i_allMin = std::min(lanes[n]->i_diver, i_allMin);
  2143. i_allProd *= lanes[n]->i_diver;
  2144. i_allSum += lanes[n]->i_diver;
  2145. }
  2146. for (size_t n = 1; n < wave->size(); ++n) {
  2147. // 'All' operations are uniform across the wave.
  2148. std::vector<PerThreadData *> &lanes = *wave.get();
  2149. VERIFY_IS_TRUE(0 == (lanes[n]->flags & 1)); // non-firstlanes do not set this bit
  2150. VERIFY_ARE_EQUAL(lanes[0]->allBC, lanes[n]->allBC);
  2151. VERIFY_ARE_EQUAL(lanes[0]->allSum, lanes[n]->allSum);
  2152. VERIFY_ARE_EQUAL(lanes[0]->allProd, lanes[n]->allProd);
  2153. VERIFY_ARE_EQUAL(lanes[0]->allAND, lanes[n]->allAND);
  2154. VERIFY_ARE_EQUAL(lanes[0]->allOR, lanes[n]->allOR);
  2155. VERIFY_ARE_EQUAL(lanes[0]->allXOR, lanes[n]->allXOR);
  2156. VERIFY_ARE_EQUAL(lanes[0]->allMin, lanes[n]->allMin);
  2157. VERIFY_ARE_EQUAL(lanes[0]->allMax, lanes[n]->allMax);
  2158. VERIFY_ARE_EQUAL(i_allMax, lanes[n]->i_allMax);
  2159. VERIFY_ARE_EQUAL(i_allMin, lanes[n]->i_allMin);
  2160. VERIFY_ARE_EQUAL(i_allProd, lanes[n]->i_allProd);
  2161. VERIFY_ARE_EQUAL(i_allSum, lanes[n]->i_allSum);
  2162. // first-lane reads and uniform reads are uniform across the wave.
  2163. VERIFY_ARE_EQUAL(lanes[0]->firstlaneX, lanes[n]->firstlaneX);
  2164. VERIFY_ARE_EQUAL(lanes[0]->lane1X, lanes[n]->lane1X);
  2165. // the lane count is uniform across the wave.
  2166. VERIFY_ARE_EQUAL(lanes[0]->laneCount, lanes[n]->laneCount);
  2167. // The predicates are uniform across the wave.
  2168. VERIFY_ARE_EQUAL(lanes[n]->preds, preds);
  2169. // the lane index is distinct per thread.
  2170. for (size_t prior = 0; prior < n; ++prior) {
  2171. VERIFY_ARE_NOT_EQUAL(lanes[prior]->laneIndex, lanes[n]->laneIndex);
  2172. }
  2173. // Ballot results are uniform across the wave.
  2174. VERIFY_ARE_EQUAL(0, memcmp(ballot, lanes[n]->ballot, sizeof(ballot)));
  2175. // Keep running total of prefix calculation. Prefix values are exclusive to
  2176. // the executing lane.
  2177. VERIFY_ARE_EQUAL(pfBC, lanes[n]->pfBC);
  2178. VERIFY_ARE_EQUAL(pfSum, lanes[n]->pfSum);
  2179. VERIFY_ARE_EQUAL(pfProd, lanes[n]->pfProd);
  2180. VERIFY_ARE_EQUAL(i_pfSum, lanes[n]->i_pfSum);
  2181. VERIFY_ARE_EQUAL(i_pfProd, lanes[n]->i_pfProd);
  2182. pfBC += (lanes[n]->diver > 3) ? 1 : 0;
  2183. pfSum += lanes[n]->diver;
  2184. pfProd *= lanes[n]->diver;
  2185. i_pfSum += lanes[n]->i_diver;
  2186. i_pfProd *= lanes[n]->i_diver;
  2187. }
  2188. // TODO: add divergent branching and verify that the otherwise uniform values properly diverge
  2189. }
  2190. // Compare each value of each per-thread element.
  2191. for (size_t i = 0; i < values.size(); ++i) {
  2192. PerThreadData &pts = values[i];
  2193. VERIFY_ARE_EQUAL(i, pts.id); // ID is unchanged.
  2194. }
  2195. }
  2196. #endif
  2197. }
  2198. // This test is assuming that the adapter implements WaveReadLaneFirst correctly
  2199. TEST_F(ExecutionTest, WaveIntrinsicsInPSTest) {
  2200. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2201. struct Vertex {
  2202. XMFLOAT3 position;
  2203. };
  2204. struct PerPixelData {
  2205. XMFLOAT4 position;
  2206. uint32_t id, flags, laneIndex, laneCount, firstLaneId, sum1;
  2207. uint32_t id0, id1, id2, id3;
  2208. uint32_t acrossX, acrossY, acrossDiag, quadActiveCount;
  2209. };
  2210. const UINT RTWidth = 128;
  2211. const UINT RTHeight = 128;
  2212. // Shaders.
  2213. static const char pShaders[] =
  2214. WAVE_INTRINSIC_DXBC_GUARD
  2215. "struct PSInput {\r\n"
  2216. " float4 position : SV_POSITION;\r\n"
  2217. "};\r\n\r\n"
  2218. "PSInput VSMain(float4 position : POSITION) {\r\n"
  2219. " PSInput result;\r\n"
  2220. "\r\n"
  2221. " result.position = position;\r\n"
  2222. " return result;\r\n"
  2223. "}\r\n\r\n"
  2224. "uint pos_to_id(float4 pos) { return pos.x * 128 + pos.y; }\r\n"
  2225. "struct PerPixelData {\r\n"
  2226. " float4 position;\r\n"
  2227. " uint id, flags, laneIndex, laneCount, firstLaneId, sum1;\r\n"
  2228. " uint id0, id1, id2, id3;\r\n"
  2229. " uint acrossX, acrossY, acrossDiag, quadActiveCount;\r\n"
  2230. "};\r\n"
  2231. "AppendStructuredBuffer<PerPixelData> g_sb : register(u1);\r\n"
  2232. "float4 PSMain(PSInput input) : SV_TARGET {\r\n"
  2233. " uint one = 1;\r\n"
  2234. " PerPixelData d;\r\n"
  2235. " d.position = input.position;\r\n"
  2236. " d.id = pos_to_id(input.position);\r\n"
  2237. " d.flags = 0;\r\n"
  2238. " if (WaveIsFirstLane()) d.flags |= 1;\r\n"
  2239. " d.laneIndex = WaveGetLaneIndex();\r\n"
  2240. " d.laneCount = WaveGetLaneCount();\r\n"
  2241. " d.firstLaneId = WaveReadLaneFirst(d.id);\r\n"
  2242. " d.sum1 = WaveActiveSum(one);\r\n"
  2243. " d.id0 = QuadReadLaneAt(d.id, 0);\r\n"
  2244. " d.id1 = QuadReadLaneAt(d.id, 1);\r\n"
  2245. " d.id2 = QuadReadLaneAt(d.id, 2);\r\n"
  2246. " d.id3 = QuadReadLaneAt(d.id, 3);\r\n"
  2247. " d.acrossX = QuadReadAcrossX(d.id);\r\n"
  2248. " d.acrossY = QuadReadAcrossY(d.id);\r\n"
  2249. " d.acrossDiag = QuadReadAcrossDiagonal(d.id);\r\n"
  2250. " d.quadActiveCount = one + QuadReadAcrossX(one) + QuadReadAcrossY(one) + QuadReadAcrossDiagonal(one);\r\n"
  2251. " g_sb.Append(d);\r\n"
  2252. " return 1;\r\n"
  2253. "};\r\n";
  2254. CComPtr<ID3D12Device> pDevice;
  2255. CComPtr<ID3D12CommandQueue> pCommandQueue;
  2256. CComPtr<ID3D12DescriptorHeap> pUavHeap, pRtvHeap;
  2257. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  2258. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  2259. CComPtr<ID3D12PipelineState> pPSO;
  2260. CComPtr<ID3D12Resource> pRenderTarget, pReadBuffer;
  2261. UINT uavDescriptorSize, rtvDescriptorSize;
  2262. CComPtr<ID3D12Resource> pVertexBuffer;
  2263. D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
  2264. if (!CreateDevice(&pDevice))
  2265. return;
  2266. if (!DoesDeviceSupportWaveOps(pDevice)) {
  2267. // Optional feature, so it's correct to not support it if declared as such.
  2268. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  2269. return;
  2270. }
  2271. FenceObj FO;
  2272. InitFenceObj(pDevice, &FO);
  2273. // Describe and create a UAV descriptor heap.
  2274. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  2275. heapDesc.NumDescriptors = 1;
  2276. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  2277. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  2278. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  2279. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  2280. CreateRtvDescriptorHeap(pDevice, 1, &pRtvHeap, &rtvDescriptorSize);
  2281. CreateRenderTargetAndReadback(pDevice, pRtvHeap, RTHeight, RTWidth, &pRenderTarget, &pReadBuffer);
  2282. // Create root signature: one UAV.
  2283. CComPtr<ID3D12RootSignature> pRootSignature;
  2284. {
  2285. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  2286. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 1, 0, 0);
  2287. CD3DX12_ROOT_PARAMETER rootParameters[1];
  2288. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  2289. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  2290. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
  2291. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  2292. }
  2293. D3D12_INPUT_ELEMENT_DESC elementDesc[] = {
  2294. {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
  2295. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}};
  2296. D3D12_INPUT_LAYOUT_DESC InputLayout = {elementDesc, _countof(elementDesc)};
  2297. CreateGraphicsPSO(pDevice, &InputLayout, pRootSignature, pShaders, &pPSO);
  2298. CreateGraphicsCommandQueueAndList(pDevice, &pCommandQueue, &pCommandAllocator,
  2299. &pCommandList, pPSO);
  2300. // Single triangle covering half the target.
  2301. Vertex vertices[] = {
  2302. { { -1.0f, 1.0f, 0.0f } },
  2303. { { 1.0f, 1.0f, 0.0f } },
  2304. { { -1.0f, -1.0f, 0.0f } } };
  2305. const UINT TriangleCount = _countof(vertices) / 3;
  2306. CreateVertexBuffer(pDevice, vertices, &pVertexBuffer, &vertexBufferView);
  2307. bool dxbc = UseDxbc();
  2308. // Set up UAV resource.
  2309. std::vector<PerPixelData> values;
  2310. values.resize(RTWidth * RTHeight * 2);
  2311. UINT valueSizeInBytes = (UINT)values.size() * sizeof(PerPixelData);
  2312. memset(values.data(), 0, valueSizeInBytes);
  2313. CComPtr<ID3D12Resource> pUavResource;
  2314. CComPtr<ID3D12Resource> pUavReadBuffer;
  2315. CComPtr<ID3D12Resource> pUploadResource;
  2316. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pUavReadBuffer);
  2317. // Set up the append counter resource.
  2318. CComPtr<ID3D12Resource> pUavCounterResource;
  2319. CComPtr<ID3D12Resource> pReadCounterBuffer;
  2320. CComPtr<ID3D12Resource> pUploadCounterResource;
  2321. BYTE zero[sizeof(UINT)] = { 0 };
  2322. CreateTestUavs(pDevice, pCommandList, zero, sizeof(zero), &pUavCounterResource, &pUploadCounterResource, &pReadCounterBuffer);
  2323. // Close the command list and execute it to perform the GPU setup.
  2324. pCommandList->Close();
  2325. ExecuteCommandList(pCommandQueue, pCommandList);
  2326. WaitForSignal(pCommandQueue, FO);
  2327. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  2328. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pPSO));
  2329. pCommandList->SetGraphicsRootSignature(pRootSignature);
  2330. SetDescriptorHeap(pCommandList, pUavHeap);
  2331. {
  2332. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  2333. uavDesc.Format = DXGI_FORMAT_UNKNOWN;
  2334. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  2335. uavDesc.Buffer.FirstElement = 0;
  2336. uavDesc.Buffer.NumElements = (UINT)values.size();
  2337. uavDesc.Buffer.StructureByteStride = sizeof(PerPixelData);
  2338. uavDesc.Buffer.CounterOffsetInBytes = 0;
  2339. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  2340. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  2341. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  2342. pDevice->CreateUnorderedAccessView(pUavResource, pUavCounterResource, &uavDesc, uavHandle);
  2343. pCommandList->SetGraphicsRootDescriptorTable(0, uavHandleGpu);
  2344. }
  2345. RecordRenderAndReadback(pCommandList, pRtvHeap, rtvDescriptorSize, TriangleCount, &vertexBufferView, nullptr, pRenderTarget, pReadBuffer);
  2346. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2347. RecordTransitionBarrier(pCommandList, pUavCounterResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2348. pCommandList->CopyResource(pUavReadBuffer, pUavResource);
  2349. pCommandList->CopyResource(pReadCounterBuffer, pUavCounterResource);
  2350. VERIFY_SUCCEEDED(pCommandList->Close());
  2351. LogCommentFmt(L"Rendering to %u by %u", RTWidth, RTHeight);
  2352. ExecuteCommandList(pCommandQueue, pCommandList);
  2353. WaitForSignal(pCommandQueue, FO);
  2354. {
  2355. MappedData data(pReadBuffer, RTWidth * RTHeight * 4);
  2356. const uint32_t *pPixels = (uint32_t *)data.data();
  2357. if (SaveImages()) {
  2358. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, RTWidth, RTHeight, L"psintrin.bmp");
  2359. }
  2360. }
  2361. uint32_t appendCount;
  2362. {
  2363. MappedData mappedData(pReadCounterBuffer, sizeof(uint32_t));
  2364. appendCount = *((uint32_t *)mappedData.data());
  2365. LogCommentFmt(L"%u elements in append buffer", appendCount);
  2366. }
  2367. {
  2368. MappedData mappedData(pUavReadBuffer, (UINT32)values.size());
  2369. PerPixelData *pData = (PerPixelData *)mappedData.data();
  2370. memcpy(values.data(), pData, valueSizeInBytes);
  2371. // DXBC is handy to test pipeline setup, but interesting functions are
  2372. // stubbed out, so there is no point in further validation.
  2373. if (dxbc)
  2374. return;
  2375. uint32_t maxActiveLaneCount = 0;
  2376. uint32_t maxLaneCount = 0;
  2377. for (uint32_t i = 0; i < appendCount; ++i) {
  2378. maxActiveLaneCount = std::max(maxActiveLaneCount, values[i].sum1);
  2379. maxLaneCount = std::max(maxLaneCount, values[i].laneCount);
  2380. }
  2381. uint32_t peerOfHelperLanes = 0;
  2382. for (uint32_t i = 0; i < appendCount; ++i) {
  2383. if (values[i].sum1 != maxActiveLaneCount) {
  2384. ++peerOfHelperLanes;
  2385. }
  2386. }
  2387. LogCommentFmt(
  2388. L"Found: %u threads. Waves reported up to %u total lanes, up "
  2389. L"to %u active lanes, and %u threads had helper/inactive lanes.",
  2390. appendCount, maxLaneCount, maxActiveLaneCount, peerOfHelperLanes);
  2391. // Group threads into quad invocations.
  2392. uint32_t singlePixelCount = 0;
  2393. uint32_t multiPixelCount = 0;
  2394. std::unordered_set<uint32_t> ids;
  2395. std::multimap<uint32_t, PerPixelData *> idGroups;
  2396. std::multimap<uint32_t, PerPixelData *> firstIdGroups;
  2397. for (uint32_t i = 0; i < appendCount; ++i) {
  2398. ids.insert(values[i].id);
  2399. idGroups.insert(std::make_pair(values[i].id, &values[i]));
  2400. firstIdGroups.insert(std::make_pair(values[i].firstLaneId, &values[i]));
  2401. }
  2402. for (uint32_t id : ids) {
  2403. if (idGroups.count(id) == 1)
  2404. ++singlePixelCount;
  2405. else
  2406. ++multiPixelCount;
  2407. }
  2408. LogCommentFmt(L"%u pixels were processed by a single thread. %u invocations were for shared pixels.",
  2409. singlePixelCount, multiPixelCount);
  2410. // Multiple threads may have tried to shade the same pixel. (Is this true even if we have only one triangle?)
  2411. // Where every pixel is distinct, it's very straightforward to validate.
  2412. {
  2413. auto cur = firstIdGroups.begin(), end = firstIdGroups.end();
  2414. while (cur != end) {
  2415. bool simpleWave = true;
  2416. uint32_t firstId = (*cur).first;
  2417. auto groupEnd = cur;
  2418. while (groupEnd != end && (*groupEnd).first == firstId) {
  2419. if (idGroups.count((*groupEnd).second->id) > 1)
  2420. simpleWave = false;
  2421. ++groupEnd;
  2422. }
  2423. if (simpleWave) {
  2424. // Break the wave into quads.
  2425. struct QuadData {
  2426. unsigned count;
  2427. PerPixelData *data[4];
  2428. };
  2429. std::map<uint32_t, QuadData> quads;
  2430. for (auto i = cur; i != groupEnd; ++i) {
  2431. // assuming that it is a simple wave, idGroups has a unique id for each entry.
  2432. uint32_t laneId = (*i).second->id;
  2433. uint32_t laneIds[4] = {(*i).second->id0, (*i).second->id1,
  2434. (*i).second->id2, (*i).second->id3};
  2435. // Since this is a simple wave, each lane has an unique id and
  2436. // therefore should not have any ids in there.
  2437. VERIFY_IS_TRUE(quads.find(laneId) == quads.end());
  2438. // check if QuadReadLaneAt is returning same values in a single quad.
  2439. bool newQuad = true;
  2440. for (unsigned quadIndex = 0; quadIndex < 4; ++quadIndex) {
  2441. auto match = quads.find(laneIds[quadIndex]);
  2442. if (match != quads.end()) {
  2443. (*match).second.data[(*match).second.count++] = (*i).second;
  2444. newQuad = false;
  2445. break;
  2446. }
  2447. auto quadMemberData = idGroups.find(laneIds[quadIndex]);
  2448. if (quadMemberData != idGroups.end()) {
  2449. VERIFY_IS_TRUE((*quadMemberData).second->id0 == laneIds[0]);
  2450. VERIFY_IS_TRUE((*quadMemberData).second->id1 == laneIds[1]);
  2451. VERIFY_IS_TRUE((*quadMemberData).second->id2 == laneIds[2]);
  2452. VERIFY_IS_TRUE((*quadMemberData).second->id3 == laneIds[3]);
  2453. }
  2454. }
  2455. if (newQuad) {
  2456. QuadData qdata;
  2457. qdata.count = 1;
  2458. qdata.data[0] = (*i).second;
  2459. quads.insert(std::make_pair(laneId, qdata));
  2460. }
  2461. }
  2462. for (auto quadPair : quads) {
  2463. unsigned count = quadPair.second.count;
  2464. // There could be only one pixel data on the edge of the triangle
  2465. if (count < 2) continue;
  2466. PerPixelData **data = quadPair.second.data;
  2467. bool isTop[4];
  2468. bool isLeft[4];
  2469. PerPixelData helperData;
  2470. memset(&helperData, sizeof(helperData), 0);
  2471. PerPixelData *layout[4]; // tl,tr,bl,br
  2472. memset(layout, sizeof(layout), 0);
  2473. auto fnToLayout = [&](bool top, bool left) -> PerPixelData ** {
  2474. int idx = top ? 0 : 2;
  2475. idx += left ? 0 : 1;
  2476. return &layout[idx];
  2477. };
  2478. auto fnToLayoutData = [&](bool top, bool left) -> PerPixelData * {
  2479. PerPixelData **pResult = fnToLayout(top, left);
  2480. if (*pResult == nullptr) return &helperData;
  2481. return *pResult;
  2482. };
  2483. VERIFY_IS_TRUE(count <= 4);
  2484. if (count == 2) {
  2485. isTop[0] = data[0]->position.y < data[1]->position.y;
  2486. isTop[1] = (data[0]->position.y == data[1]->position.y) ? isTop[0] : !isTop[0];
  2487. isLeft[0] = data[0]->position.x < data[1]->position.x;
  2488. isLeft[1] = (data[0]->position.x == data[1]->position.x) ? isLeft[0] : !isLeft[0];
  2489. }
  2490. else {
  2491. // with at least three samples, we have distinct x and y coordinates.
  2492. float left = std::min(data[0]->position.x, data[1]->position.x);
  2493. left = std::min(data[2]->position.x, left);
  2494. float top = std::min(data[0]->position.y, data[1]->position.y);
  2495. top = std::min(data[2]->position.y, top);
  2496. for (unsigned i = 0; i < count; ++i) {
  2497. isTop[i] = data[i]->position.y == top;
  2498. isLeft[i] = data[i]->position.x == left;
  2499. }
  2500. }
  2501. for (unsigned i = 0; i < count; ++i) {
  2502. *(fnToLayout(isTop[i], isLeft[i])) = data[i];
  2503. }
  2504. // Finally, we have a proper quad reconstructed. Validate.
  2505. for (unsigned i = 0; i < count; ++i) {
  2506. PerPixelData *d = data[i];
  2507. VERIFY_ARE_EQUAL(d->id0, fnToLayoutData(true, true)->id);
  2508. VERIFY_ARE_EQUAL(d->id1, fnToLayoutData(true, false)->id);
  2509. VERIFY_ARE_EQUAL(d->id2, fnToLayoutData(false, true)->id);
  2510. VERIFY_ARE_EQUAL(d->id3, fnToLayoutData(false, false)->id);
  2511. VERIFY_ARE_EQUAL(d->acrossX, fnToLayoutData(isTop[i], !isLeft[i])->id);
  2512. VERIFY_ARE_EQUAL(d->acrossY, fnToLayoutData(!isTop[i], isLeft[i])->id);
  2513. VERIFY_ARE_EQUAL(d->acrossDiag, fnToLayoutData(!isTop[i], !isLeft[i])->id);
  2514. VERIFY_ARE_EQUAL(d->quadActiveCount, count);
  2515. }
  2516. }
  2517. }
  2518. cur = groupEnd;
  2519. }
  2520. }
  2521. // TODO: provide validation for quads where the same pixel was shaded multiple times
  2522. //
  2523. // Consider: for pixels that were shaded multiple times, check whether
  2524. // some grouping of threads into quads satisfies all value requirements.
  2525. }
  2526. }
  2527. struct ShaderOpTestResult {
  2528. st::ShaderOp *ShaderOp;
  2529. std::shared_ptr<st::ShaderOpSet> ShaderOpSet;
  2530. std::shared_ptr<st::ShaderOpTest> Test;
  2531. };
  2532. struct SPrimitives {
  2533. float f_float;
  2534. float f_float2;
  2535. float f_float_o;
  2536. float f_float2_o;
  2537. };
  2538. std::shared_ptr<ShaderOpTestResult>
  2539. RunShaderOpTestAfterParse(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
  2540. LPCSTR pName,
  2541. st::ShaderOpTest::TInitCallbackFn pInitCallback,
  2542. std::shared_ptr<st::ShaderOpSet> ShaderOpSet) {
  2543. st::ShaderOp *pShaderOp;
  2544. if (pName == nullptr) {
  2545. if (ShaderOpSet->ShaderOps.size() != 1) {
  2546. VERIFY_FAIL(L"Expected a single shader operation.");
  2547. }
  2548. pShaderOp = ShaderOpSet->ShaderOps[0].get();
  2549. }
  2550. else {
  2551. pShaderOp = ShaderOpSet->GetShaderOp(pName);
  2552. }
  2553. if (pShaderOp == nullptr) {
  2554. std::string msg = "Unable to find shader op ";
  2555. msg += pName;
  2556. msg += "; available ops";
  2557. const char sep = ':';
  2558. for (auto &pAvailOp : ShaderOpSet->ShaderOps) {
  2559. msg += sep;
  2560. msg += pAvailOp->Name ? pAvailOp->Name : "[n/a]";
  2561. }
  2562. CA2W msgWide(msg.c_str());
  2563. VERIFY_FAIL(msgWide.m_psz);
  2564. }
  2565. // This won't actually be used since we're supplying the device,
  2566. // but let's make it consistent.
  2567. pShaderOp->UseWarpDevice = GetTestParamUseWARP(true);
  2568. std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
  2569. test->SetDxcSupport(&support);
  2570. test->SetInitCallback(pInitCallback);
  2571. test->SetDevice(pDevice);
  2572. test->RunShaderOp(pShaderOp);
  2573. std::shared_ptr<ShaderOpTestResult> result =
  2574. std::make_shared<ShaderOpTestResult>();
  2575. result->ShaderOpSet = ShaderOpSet;
  2576. result->Test = test;
  2577. result->ShaderOp = pShaderOp;
  2578. return result;
  2579. }
  2580. std::shared_ptr<ShaderOpTestResult>
  2581. RunShaderOpTest(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
  2582. IStream *pStream, LPCSTR pName,
  2583. st::ShaderOpTest::TInitCallbackFn pInitCallback) {
  2584. DXASSERT_NOMSG(pStream != nullptr);
  2585. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2586. std::make_shared<st::ShaderOpSet>();
  2587. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2588. return RunShaderOpTestAfterParse(pDevice, support, pName, pInitCallback, ShaderOpSet);
  2589. }
  2590. TEST_F(ExecutionTest, OutOfBoundsTest) {
  2591. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2592. CComPtr<IStream> pStream;
  2593. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2594. // Single operation test at the moment.
  2595. CComPtr<ID3D12Device> pDevice;
  2596. if (!CreateDevice(&pDevice))
  2597. return;
  2598. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "OOB", nullptr);
  2599. MappedData data;
  2600. // Read back to CPU and examine contents - should get pure red.
  2601. {
  2602. MappedData data;
  2603. test->Test->GetReadBackData("RTarget", &data);
  2604. const uint32_t *pPixels = (uint32_t *)data.data();
  2605. uint32_t first = *pPixels;
  2606. VERIFY_ARE_EQUAL(0xff0000ff, first); // pure red - only first component is read
  2607. }
  2608. }
  2609. TEST_F(ExecutionTest, SaturateTest) {
  2610. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2611. CComPtr<IStream> pStream;
  2612. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2613. // Single operation test at the moment.
  2614. CComPtr<ID3D12Device> pDevice;
  2615. if (!CreateDevice(&pDevice))
  2616. return;
  2617. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "Saturate", nullptr);
  2618. MappedData data;
  2619. test->Test->GetReadBackData("U0", &data);
  2620. const float *pValues = (float *)data.data();
  2621. // Everything is zero except for 1.5f and +Inf, which saturate to 1.0f
  2622. const float ExpectedCases[9] = {
  2623. 0.0f, 0.0f, 0.0f, 0.0f, // -inf, -1.5, -denorm, -0
  2624. 0.0f, 0.0f, 1.0f, 1.0f, // 0, denorm, 1.5f, inf
  2625. 0.0f // nan
  2626. };
  2627. for (size_t i = 0; i < _countof(ExpectedCases); ++i) {
  2628. VERIFY_IS_TRUE(ifdenorm_flushf_eq(*pValues, ExpectedCases[i]));
  2629. ++pValues;
  2630. }
  2631. }
  2632. void ExecutionTest::BasicTriangleTestSetup(LPCSTR ShaderOpName, LPCWSTR FileName, D3D_SHADER_MODEL testModel) {
  2633. #ifdef _HLK_CONF
  2634. UNREFERENCED_PARAMETER(ShaderOpName);
  2635. UNREFERENCED_PARAMETER(FileName);
  2636. UNREFERENCED_PARAMETER(testModel);
  2637. #else
  2638. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2639. CComPtr<IStream> pStream;
  2640. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2641. // Single operation test at the moment.
  2642. CComPtr<ID3D12Device> pDevice;
  2643. if (!CreateDevice(&pDevice, testModel))
  2644. return;
  2645. // As this is used, 6.2 requirement always comes with requiring native 16-bit ops
  2646. if (testModel == D3D_SHADER_MODEL_6_2 && !DoesDeviceSupportNative16bitOps(pDevice)) {
  2647. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  2648. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  2649. return;
  2650. }
  2651. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, ShaderOpName, nullptr);
  2652. MappedData data;
  2653. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  2654. UINT width = (UINT)D.Width;
  2655. UINT height = D.Height;
  2656. test->Test->GetReadBackData("RTarget", &data);
  2657. const uint32_t *pPixels = (uint32_t *)data.data();
  2658. if (SaveImages()) {
  2659. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, 320, 200, FileName);
  2660. }
  2661. uint32_t top = pPixels[width / 2]; // Top center.
  2662. uint32_t mid = pPixels[width / 2 + width * (height / 2)]; // Middle center.
  2663. VERIFY_ARE_EQUAL(0xff663300, top); // clear color
  2664. VERIFY_ARE_EQUAL(0xffffffff, mid); // white
  2665. // This is the basic validation test for shader operations, so it's good to
  2666. // check this here at least for this one test case.
  2667. data.reset();
  2668. test.reset();
  2669. ReportLiveObjects();
  2670. #endif
  2671. }
  2672. TEST_F(ExecutionTest, BasicTriangleOpTest) {
  2673. BasicTriangleTestSetup("Triangle", L"basic-triangle.bmp", D3D_SHADER_MODEL_6_0);
  2674. }
  2675. TEST_F(ExecutionTest, BasicTriangleOpTestHalf) {
  2676. BasicTriangleTestSetup("TriangleHalf", L"basic-triangle-half.bmp", D3D_SHADER_MODEL_6_2);
  2677. }
  2678. void VerifyDerivResults(const float *pPixels, UINT offsetCenter) {
  2679. // pixel at the center
  2680. float CenterDDXFine = pPixels[offsetCenter];
  2681. float CenterDDYFine = pPixels[offsetCenter + 1];
  2682. float CenterDDXCoarse = pPixels[offsetCenter + 2];
  2683. float CenterDDYCoarse = pPixels[offsetCenter + 3];
  2684. LogCommentFmt(
  2685. L"center ddx_fine: %8f, ddy_fine: %8f, ddx_coarse: %8f, ddy_coarse: %8f",
  2686. CenterDDXFine, CenterDDYFine, CenterDDXCoarse, CenterDDYCoarse);
  2687. // The texture for the 9 pixels in the center should look like the following
  2688. // 256 32 64
  2689. // 2048 256 512
  2690. // 1 .125 .25
  2691. // In D3D12 there is no guarantee of how the adapter is grouping 2x2 pixels
  2692. // So for fine derivatives there can be up to two possible results for the center pixel,
  2693. // while for coarse derivatives there can be up to six possible results.
  2694. int ulpTolerance = 1;
  2695. // 512 - 256 or 2048 - 256
  2696. bool left = CompareFloatULP(CenterDDXFine, -1792.0f, ulpTolerance);
  2697. VERIFY_IS_TRUE(left || CompareFloatULP(CenterDDXFine, 256.0f, ulpTolerance));
  2698. // 256 - 32 or 256 - .125
  2699. bool top = CompareFloatULP(CenterDDYFine, 224.0f, ulpTolerance);
  2700. VERIFY_IS_TRUE(top || CompareFloatULP(CenterDDYFine, -255.875, ulpTolerance));
  2701. if (top && left) {
  2702. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, -224.0f, ulpTolerance) ||
  2703. CompareFloatULP(CenterDDXCoarse, -1792.0f, ulpTolerance)) &&
  2704. (CompareFloatULP(CenterDDYCoarse, 224.0f, ulpTolerance) ||
  2705. CompareFloatULP(CenterDDYCoarse, 1792.0f, ulpTolerance)));
  2706. }
  2707. else if (top) { // top right quad
  2708. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, 256.0f, ulpTolerance) ||
  2709. CompareFloatULP(CenterDDXCoarse, 32.0f, ulpTolerance)) &&
  2710. (CompareFloatULP(CenterDDYCoarse, 224.0f, ulpTolerance) ||
  2711. CompareFloatULP(CenterDDYCoarse, 448.0f, ulpTolerance)));
  2712. }
  2713. else if (left) { // bottom left quad
  2714. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, -1792.0f, ulpTolerance) ||
  2715. CompareFloatULP(CenterDDXCoarse, -.875f, ulpTolerance)) &&
  2716. (CompareFloatULP(CenterDDYCoarse, -2047.0f, ulpTolerance) ||
  2717. CompareFloatULP(CenterDDYCoarse, -255.875f, ulpTolerance)));
  2718. }
  2719. else { // bottom right
  2720. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, 256.0f, ulpTolerance) ||
  2721. CompareFloatULP(CenterDDXCoarse, .125f, ulpTolerance)) &&
  2722. (CompareFloatULP(CenterDDYCoarse, -255.875f, ulpTolerance) ||
  2723. CompareFloatULP(CenterDDYCoarse, -511.75f, ulpTolerance)));
  2724. }
  2725. }
  2726. // Rendering two right triangles forming a square and assigning a texture value
  2727. // for each pixel to calculate derivates.
  2728. TEST_F(ExecutionTest, PartialDerivTest) {
  2729. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2730. CComPtr<IStream> pStream;
  2731. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2732. CComPtr<ID3D12Device> pDevice;
  2733. if (!CreateDevice(&pDevice))
  2734. return;
  2735. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "DerivFine", nullptr);
  2736. MappedData data;
  2737. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  2738. UINT width = (UINT)D.Width;
  2739. UINT height = D.Height;
  2740. UINT pixelSize = GetByteSizeForFormat(D.Format) / 4;
  2741. test->Test->GetReadBackData("RTarget", &data);
  2742. const float *pPixels = (float *)data.data();
  2743. UINT centerIndex = (UINT64)width * height / 2 - width / 2;
  2744. UINT offsetCenter = centerIndex * pixelSize;
  2745. VerifyDerivResults(pPixels, offsetCenter);
  2746. }
  2747. struct Dispatch {
  2748. int width, height, depth;
  2749. };
  2750. std::shared_ptr<st::ShaderOpTest>
  2751. RunDispatch(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
  2752. st::ShaderOp *pShaderOp, const Dispatch D) {
  2753. char compilerOptions[256];
  2754. std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
  2755. test->SetDxcSupport(&support);
  2756. test->SetInitCallback(nullptr);
  2757. test->SetDevice(pDevice);
  2758. // format compiler args
  2759. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions),
  2760. "-D DISPATCHX=%d -D DISPATCHY=%d -D DISPATCHZ=%d ",
  2761. D.width, D.height, D.depth));
  2762. for (st::ShaderOpShader &S : pShaderOp->Shaders)
  2763. S.Arguments = compilerOptions;
  2764. pShaderOp->DispatchX = D.width;
  2765. pShaderOp->DispatchY = D.height;
  2766. pShaderOp->DispatchZ = D.depth;
  2767. test->RunShaderOp(pShaderOp);
  2768. return test;
  2769. }
  2770. TEST_F(ExecutionTest, DerivativesTest) {
  2771. const UINT pixelSize = 4; // always float4
  2772. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2773. CComPtr<IStream> pStream;
  2774. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2775. CComPtr<ID3D12Device> pDevice;
  2776. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  2777. return;
  2778. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2779. std::make_shared<st::ShaderOpSet>();
  2780. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2781. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Derivatives");
  2782. std::vector<Dispatch> dispatches =
  2783. {
  2784. {40, 1, 1},
  2785. {1000, 1, 1},
  2786. {32, 32, 1},
  2787. {16, 64, 1},
  2788. {4, 12, 4},
  2789. {4, 64, 1},
  2790. {16, 16, 3},
  2791. {32, 8, 2}
  2792. };
  2793. std::vector<Dispatch> meshDispatches =
  2794. {
  2795. {60, 1, 1},
  2796. {128, 1, 1},
  2797. {8, 8, 1},
  2798. {32, 8, 1},
  2799. {8, 16, 4},
  2800. {8, 64, 1},
  2801. {8, 8, 3},
  2802. };
  2803. std::vector<Dispatch> badDispatches =
  2804. {
  2805. {16, 3, 1},
  2806. {2, 16, 1},
  2807. {33, 1, 1}
  2808. };
  2809. pShaderOp->UseWarpDevice = GetTestParamUseWARP(true);
  2810. LPCSTR CS = pShaderOp->CS;
  2811. MappedData data;
  2812. for (Dispatch &D : dispatches) {
  2813. // Test Compute Shader
  2814. std::shared_ptr<st::ShaderOpTest> test = RunDispatch(pDevice, m_support, pShaderOp, D);
  2815. test->GetReadBackData("U0", &data);
  2816. float *pPixels = (float *)data.data();;
  2817. UINT centerIndex = 0;
  2818. if (D.height == 1) {
  2819. centerIndex = (((UINT64)(D.width * D.height * D.depth) / 2) & ~0xF) + 10;
  2820. } else {
  2821. // To find roughly the center for compute, divide the height and width in half,
  2822. // truncate to the previous multiple of 4 to get to the start of the repeating pattern
  2823. // and then add 2 rows to get to the second row of quads and 2 to get to the first texel
  2824. // of the second row of that quad row
  2825. UINT centerRow = ((D.height/2UL) & ~0x3) + 2;
  2826. UINT centerCol = ((D.width/2UL) & ~0x3) + 2;
  2827. centerIndex = centerRow * D.width + centerCol;
  2828. }
  2829. UINT offsetCenter = centerIndex * pixelSize;
  2830. LogCommentFmt(L"Verifying derivatives in compute shader results");
  2831. VerifyDerivResults(pPixels, offsetCenter);
  2832. }
  2833. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2834. // Disable CS so mesh goes forward
  2835. pShaderOp->CS = nullptr;
  2836. for (Dispatch &D : meshDispatches) {
  2837. std::shared_ptr<st::ShaderOpTest> test = RunDispatch(pDevice, m_support, pShaderOp, D);
  2838. test->GetReadBackData("U1", &data);
  2839. const float *pPixels = (float *)data.data();
  2840. UINT centerIndex = (((UINT64)(D.width * D.height * D.depth)/2) & ~0xF) + 10;
  2841. UINT offsetCenter = centerIndex * pixelSize;
  2842. LogCommentFmt(L"Verifying derivatives in mesh shader results");
  2843. VerifyDerivResults(pPixels, offsetCenter);
  2844. test->GetReadBackData("U2", &data);
  2845. pPixels = (float *)data.data();
  2846. LogCommentFmt(L"Verifying derivatives in amplification shader results");
  2847. VerifyDerivResults(pPixels, offsetCenter);
  2848. }
  2849. }
  2850. // Final tests with invalid dispatch size just to make sure they run
  2851. for (Dispatch &D : badDispatches) {
  2852. // Test Compute Shader
  2853. pShaderOp->CS = CS;
  2854. std::shared_ptr<st::ShaderOpTest> test = RunDispatch(pDevice, m_support, pShaderOp, D);
  2855. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2856. pShaderOp->CS = nullptr;
  2857. test = RunDispatch(pDevice, m_support, pShaderOp, D);
  2858. }
  2859. }
  2860. }
  2861. // Verify the results for the quad starting with the given index
  2862. void VerifyQuadReadResults(const UINT *pPixels, UINT quadIndex) {
  2863. for (UINT i = 0; i < 4; i++) {
  2864. UINT ix = quadIndex + i;
  2865. VERIFY_ARE_EQUAL(pPixels[4*ix + 0], ix); // ReadLaneAt own quad index
  2866. VERIFY_ARE_EQUAL(pPixels[4*ix + 1], (ix^1));// ReadAcrossX
  2867. VERIFY_ARE_EQUAL(pPixels[4*ix + 2], (ix^2));// ReadAcrossY
  2868. VERIFY_ARE_EQUAL(pPixels[4*ix + 3], (ix^3));// ReadAcrossDiagonal
  2869. }
  2870. }
  2871. TEST_F(ExecutionTest, QuadReadTest) {
  2872. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2873. CComPtr<IStream> pStream;
  2874. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2875. CComPtr<ID3D12Device> pDevice;
  2876. if (!CreateDevice(&pDevice))
  2877. return;
  2878. if (GetTestParamUseWARP(UseWarpByDefault()) || IsDeviceBasicAdapter(pDevice)) {
  2879. WEX::Logging::Log::Comment(L"WARP does not support QuadRead in compute shaders.");
  2880. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  2881. return;
  2882. }
  2883. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2884. std::make_shared<st::ShaderOpSet>();
  2885. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2886. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("QuadRead");
  2887. LPCSTR CS = pShaderOp->CS;
  2888. struct Dispatch {
  2889. int x, y, z;
  2890. int mx, my, mz;
  2891. };
  2892. //std::vector<std::tuple<int, int, int, int, int>> dispatches =
  2893. std::vector<Dispatch> dispatches =
  2894. {
  2895. {32, 32, 1, 8, 8, 1},
  2896. {64, 4, 1, 64, 2, 1},
  2897. {1, 4, 64, 1, 4, 32},
  2898. {64, 1, 1, 64, 1, 1},
  2899. {1, 64, 1, 1, 64, 1},
  2900. {1, 1, 64, 1, 1, 64},
  2901. {16, 16, 3, 4, 4, 3},
  2902. {32, 3, 8, 8, 3, 2},
  2903. {3, 1, 64, 3, 1, 32}
  2904. };
  2905. for (Dispatch &D : dispatches) {
  2906. UINT width = D.x;
  2907. UINT height = D.y;
  2908. UINT depth = D.z;
  2909. UINT mwidth = D.mx;
  2910. UINT mheight = D.my;
  2911. UINT mdepth = D.mz;
  2912. // format compiler args
  2913. char compilerOptions[256];
  2914. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions),
  2915. "-D DISPATCHX=%d -D DISPATCHY=%d -D DISPATCHZ=%d "
  2916. "-D MESHDISPATCHX=%d -D MESHDISPATCHY=%d -D MESHDISPATCHZ=%d",
  2917. width, height, depth, mwidth, mheight, mdepth));
  2918. for (st::ShaderOpShader &S : pShaderOp->Shaders)
  2919. S.Arguments = compilerOptions;
  2920. pShaderOp->DispatchX = width;
  2921. pShaderOp->DispatchY = height;
  2922. pShaderOp->DispatchZ = depth;
  2923. // Test Compute Shader
  2924. pShaderOp->CS = CS;
  2925. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "QuadRead", nullptr, ShaderOpSet);
  2926. MappedData data;
  2927. test->Test->GetReadBackData("U0", &data);
  2928. const UINT *pPixels = (UINT *)data.data();
  2929. // To find roughly the center for compute, divide the pixel count in half
  2930. // and truncate to next lowest power of 4 to start at a quad
  2931. UINT offsetCenter = ((UINT64)(width * height * depth)/2) & ~0x3;
  2932. // Test first, second and center quads
  2933. LogCommentFmt(L"Verifying QuadRead* in compute shader results");
  2934. VerifyQuadReadResults(pPixels, 0);
  2935. VerifyQuadReadResults(pPixels, 4);
  2936. VerifyQuadReadResults(pPixels, offsetCenter);
  2937. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2938. offsetCenter = ((UINT64)(mwidth * mheight * mdepth)/2) & ~0x3;
  2939. // Disable CS so mesh goes forward
  2940. pShaderOp->CS = nullptr;
  2941. test = RunShaderOpTestAfterParse(pDevice, m_support, "QuadRead", nullptr, ShaderOpSet);
  2942. test->Test->GetReadBackData("U1", &data);
  2943. pPixels = (UINT *)data.data();
  2944. // Test first, second and center quads
  2945. LogCommentFmt(L"Verifying QuadRead* in mesh shader results");
  2946. VerifyQuadReadResults(pPixels, 0);
  2947. VerifyQuadReadResults(pPixels, 4);
  2948. VerifyQuadReadResults(pPixels, offsetCenter);
  2949. test->Test->GetReadBackData("U2", &data);
  2950. pPixels = (UINT *)data.data();
  2951. // Test first, second and center quads
  2952. LogCommentFmt(L"Verifying QuadRead* in amplification shader results");
  2953. VerifyQuadReadResults(pPixels, 0);
  2954. VerifyQuadReadResults(pPixels, 4);
  2955. VerifyQuadReadResults(pPixels, offsetCenter);
  2956. }
  2957. }
  2958. }
  2959. void VerifySampleResults(const UINT *pPixels, UINT width) {
  2960. UINT xlod = 0;
  2961. UINT ylod = 0;
  2962. // Each pixel contains 4 samples and 4 LOD calculations.
  2963. // 2 of these (called 'left' and 'right') have X values that vary and a constant Y
  2964. // 2 others (called 'top' and 'bot') have Y values that vary and a constant X
  2965. // Only of the X variant sample results and one of the Y variant results
  2966. // are actually reported for the pixel.
  2967. // The other 2 serve as "helpers" to the other pixels in the quad.
  2968. // On the left side of the quad, the 'left' samples are reported.
  2969. // Op the top of the quad, the 'top' samples are reported and so on.
  2970. // The varying coordinate values alternate between zero and a
  2971. // value whose magnitude increases with the index.
  2972. // As a result, the LOD level should steadily increas.
  2973. // Due to vagaries of implementation, the same derivatives
  2974. // in both directions might result in different levels for different locations
  2975. // in the quad. So only comparisons between sample results and LOD calculations
  2976. // and ensuring that the LOD increased and reaches the max can be tested reliably.
  2977. for (unsigned i = 0; i < width; i++) {
  2978. // CalculateLOD and Sample from texture with mip levels containing LOD index should match
  2979. VERIFY_ARE_EQUAL(pPixels[4*i + 0], pPixels[4*i + 1]);
  2980. VERIFY_ARE_EQUAL(pPixels[4*i + 2], pPixels[4*i + 3]);
  2981. // Make sure LODs are ever climbing as magnitudes increase
  2982. VERIFY_IS_TRUE(pPixels[4*i] >= xlod);
  2983. xlod = pPixels[4*i];
  2984. VERIFY_IS_TRUE(pPixels[4*i + 2] >= ylod);
  2985. ylod = pPixels[4*i + 2];
  2986. }
  2987. // Make sure we reached the max lod level for both tracks
  2988. VERIFY_ARE_EQUAL(xlod, 6u);
  2989. VERIFY_ARE_EQUAL(ylod, 6u);
  2990. }
  2991. TEST_F(ExecutionTest, ComputeSampleTest) {
  2992. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2993. CComPtr<IStream> pStream;
  2994. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2995. CComPtr<ID3D12Device> pDevice;
  2996. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  2997. return;
  2998. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2999. std::make_shared<st::ShaderOpSet>();
  3000. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  3001. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("ComputeSample");
  3002. // Initialize texture with the LOD number in each corresponding mip level
  3003. auto SampleInitFn = [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  3004. UNREFERENCED_PARAMETER(pShaderOp);
  3005. VERIFY_ARE_EQUAL(0, _stricmp(Name, "T0"));
  3006. D3D12_RESOURCE_DESC &texDesc = pShaderOp->GetResourceByName("T0")->Desc;
  3007. UINT texWidth = (UINT)texDesc.Width;
  3008. UINT texHeight = (UINT)texDesc.Height;
  3009. size_t size = sizeof(float) * texWidth * texHeight * 2;
  3010. Data.resize(size);
  3011. float *pPrimitives = (float *)Data.data();
  3012. float lod = 0.0;
  3013. int ix = 0;
  3014. while (texHeight > 0 && texWidth > 0) {
  3015. if(!texHeight) texHeight = 1;
  3016. if(!texWidth) texWidth = 1;
  3017. for (size_t j = 0; j < texHeight; ++j) {
  3018. for (size_t i = 0; i < texWidth; ++i) {
  3019. pPrimitives[ix++] = lod;
  3020. }
  3021. }
  3022. lod += 1.0;
  3023. texHeight >>= 1;
  3024. texWidth >>= 1;
  3025. }
  3026. };
  3027. LPCSTR CS2 = nullptr, AS2 = nullptr, MS2 = nullptr;
  3028. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  3029. if (!strcmp(S.Name, "CS2")) CS2 = S.Name;
  3030. if (!strcmp(S.Name, "AS2")) AS2 = S.Name;
  3031. if (!strcmp(S.Name, "MS2")) MS2 = S.Name;
  3032. }
  3033. // Test 1D compute shader
  3034. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  3035. MappedData data;
  3036. test->Test->GetReadBackData("U0", &data);
  3037. const UINT *pPixels = (UINT *)data.data();
  3038. VerifySampleResults(pPixels, 84*4);
  3039. // Test 2D compute shader
  3040. pShaderOp->CS = CS2;
  3041. test.reset();
  3042. test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  3043. test->Test->GetReadBackData("U0", &data);
  3044. pPixels = (UINT *)data.data();
  3045. VerifySampleResults(pPixels, 84*4);
  3046. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  3047. // Disable CS so mesh goes forward
  3048. pShaderOp->CS = nullptr;
  3049. test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  3050. test->Test->GetReadBackData("U1", &data);
  3051. pPixels = (UINT *)data.data();
  3052. VerifySampleResults(pPixels, 116);
  3053. test->Test->GetReadBackData("U2", &data);
  3054. pPixels = (UINT *)data.data();
  3055. VerifySampleResults(pPixels, 84);
  3056. pShaderOp->AS = AS2;
  3057. pShaderOp->MS = MS2;
  3058. test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  3059. test->Test->GetReadBackData("U1", &data);
  3060. pPixels = (UINT *)data.data();
  3061. VerifySampleResults(pPixels, 116);
  3062. test->Test->GetReadBackData("U2", &data);
  3063. pPixels = (UINT *)data.data();
  3064. VerifySampleResults(pPixels, 84);
  3065. }
  3066. }
  3067. // Executing a simple binop to verify shadel model 6.1 support; runs with
  3068. // ShaderModel61.CoreRequirement
  3069. TEST_F(ExecutionTest, BasicShaderModel61) {
  3070. RunBasicShaderModelTest(D3D_SHADER_MODEL_6_1);
  3071. }
  3072. // Executing a simple binop to verify shadel model 6.3 support; runs with
  3073. // ShaderModel63.CoreRequirement
  3074. TEST_F(ExecutionTest, BasicShaderModel63) {
  3075. RunBasicShaderModelTest(D3D_SHADER_MODEL_6_3);
  3076. }
  3077. void ExecutionTest::RunBasicShaderModelTest(D3D_SHADER_MODEL shaderModel) {
  3078. WEX::TestExecution::SetVerifyOutput verifySettings(
  3079. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  3080. CComPtr<ID3D12Device> pDevice;
  3081. if (!CreateDevice(&pDevice, shaderModel)) {
  3082. return;
  3083. }
  3084. char *pShaderModelStr;
  3085. if (shaderModel == D3D_SHADER_MODEL_6_1) {
  3086. pShaderModelStr = "cs_6_1";
  3087. } else if (shaderModel == D3D_SHADER_MODEL_6_3) {
  3088. pShaderModelStr = "cs_6_3";
  3089. } else {
  3090. DXASSERT_NOMSG("Invalid Shader Model Parameter");
  3091. pShaderModelStr = nullptr;
  3092. }
  3093. const char shaderTemplate[] =
  3094. "struct SBinaryOp { %s input1; %s input2; %s output; };"
  3095. "RWStructuredBuffer<SBinaryOp> g_buf : register(u0);"
  3096. "[numthreads(8,8,1)]"
  3097. "void main(uint GI : SV_GroupIndex) {"
  3098. " SBinaryOp l = g_buf[GI];"
  3099. " l.output = l.input1 + l.input2;"
  3100. " g_buf[GI] = l;"
  3101. "}";
  3102. char shader[sizeof(shaderTemplate) + 50];
  3103. // Run simple shader with float data types
  3104. char* sTy = "float";
  3105. float inputFloatPairs[] = { 1.5f, -2.8f, 3.23e-5f, 6.0f, 181.621f, 14.978f };
  3106. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  3107. WEX::Logging::Log::Comment(L"BasicShaderModel float");
  3108. RunBasicShaderModelTest<float>(pDevice, pShaderModelStr, shader, inputFloatPairs, sizeof(inputFloatPairs) / (2 * sizeof(float)));
  3109. // Run simple shader with double data types
  3110. if (DoesDeviceSupportDouble(pDevice)) {
  3111. sTy = "double";
  3112. double inputDoublePairs[] = { 1.5891020, -2.8, 3.23e-5, 1 / 3, 181.91621, 14.654978 };
  3113. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  3114. WEX::Logging::Log::Comment(L"BasicShaderModel double");
  3115. RunBasicShaderModelTest<double>(pDevice, pShaderModelStr, shader, inputDoublePairs, sizeof(inputDoublePairs) / (2 * sizeof(double)));
  3116. }
  3117. else {
  3118. // Optional feature, so it's correct to not support it if declared as such.
  3119. WEX::Logging::Log::Comment(L"Device does not support double operations.");
  3120. }
  3121. // Run simple shader with int64 types
  3122. if (DoesDeviceSupportInt64(pDevice)) {
  3123. sTy = "int64_t";
  3124. int64_t inputInt64Pairs[] = { 1, -100, 6814684, -9814810, 654, 1021248900 };
  3125. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  3126. WEX::Logging::Log::Comment(L"BasicShaderModel int64_t");
  3127. RunBasicShaderModelTest<int64_t>(pDevice, pShaderModelStr, shader, inputInt64Pairs, sizeof(inputInt64Pairs) / (2 * sizeof(int64_t)));
  3128. }
  3129. else {
  3130. // Optional feature, so it's correct to not support it if declared as such.
  3131. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  3132. }
  3133. }
  3134. template <class Ty>
  3135. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString() {
  3136. DXASSERT_NOMSG("Unsupported type");
  3137. return "";
  3138. }
  3139. template <>
  3140. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<float>() {
  3141. return L"element #%u: input1 = %6.8f, input1 = %6.8f, output = %6.8f, expected = %6.8f";
  3142. }
  3143. template <>
  3144. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<double>() {
  3145. return BasicShaderModelTest_GetFormatString<float>();
  3146. }
  3147. template <>
  3148. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<int64_t>() {
  3149. return L"element #%u: input1 = %ld, input1 = %ld, output = %ld, expected = %ld";
  3150. }
  3151. template <class Ty>
  3152. void ExecutionTest::RunBasicShaderModelTest(CComPtr<ID3D12Device> pDevice, const char *pShaderModelStr, const char *pShader,
  3153. Ty *pInputDataPairs, unsigned inputDataCount) {
  3154. struct SBinaryOp {
  3155. Ty input1;
  3156. Ty input2;
  3157. Ty output;
  3158. };
  3159. CComPtr<IStream> pStream;
  3160. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  3161. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  3162. pDevice, m_support, pStream, "BinaryFPOp",
  3163. // this callbacked is called when the test is creating the resource to run the test
  3164. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  3165. UNREFERENCED_PARAMETER(Name);
  3166. pShaderOp->Shaders.at(0).Target = pShaderModelStr;
  3167. pShaderOp->Shaders.at(0).Text = pShader;
  3168. size_t size = sizeof(SBinaryOp) * inputDataCount;
  3169. Data.resize(size);
  3170. SBinaryOp *pPrimitives = (SBinaryOp*)Data.data();
  3171. Ty *pIn = pInputDataPairs;
  3172. for (size_t i = 0; i < inputDataCount; i++, pIn += 2) {
  3173. SBinaryOp *p = &pPrimitives[i];
  3174. p->input1 = pIn[0];
  3175. p->input2 = pIn[1];
  3176. }
  3177. });
  3178. VERIFY_SUCCEEDED(S_OK);
  3179. MappedData data;
  3180. test->Test->GetReadBackData("SBinaryFPOp", &data);
  3181. SBinaryOp *pPrimitives = (SBinaryOp*)data.data();
  3182. const wchar_t* formatStr = BasicShaderModelTest_GetFormatString<Ty>();
  3183. Ty *pIn = pInputDataPairs;
  3184. for (unsigned i = 0; i < inputDataCount; i++, pIn += 2) {
  3185. Ty expValue = pIn[0] + pIn[1];
  3186. SBinaryOp *p = &pPrimitives[i];
  3187. LogCommentFmt(formatStr, i, pIn[0], pIn[1], p->output, expValue);
  3188. VERIFY_ARE_EQUAL(p->output, expValue);
  3189. }
  3190. }
  3191. // Resource structure for data-driven tests.
  3192. struct SUnaryFPOp {
  3193. float input;
  3194. float output;
  3195. };
  3196. struct SBinaryFPOp {
  3197. float input1;
  3198. float input2;
  3199. float output1;
  3200. float output2;
  3201. };
  3202. struct STertiaryFPOp {
  3203. float input1;
  3204. float input2;
  3205. float input3;
  3206. float output;
  3207. };
  3208. struct SUnaryHalfOp {
  3209. uint16_t input;
  3210. uint16_t output;
  3211. };
  3212. struct SBinaryHalfOp {
  3213. uint16_t input1;
  3214. uint16_t input2;
  3215. uint16_t output1;
  3216. uint16_t output2;
  3217. };
  3218. struct STertiaryHalfOp {
  3219. uint16_t input1;
  3220. uint16_t input2;
  3221. uint16_t input3;
  3222. uint16_t output;
  3223. };
  3224. struct SUnaryIntOp {
  3225. int input;
  3226. int output;
  3227. };
  3228. struct SUnaryUintOp {
  3229. unsigned int input;
  3230. unsigned int output;
  3231. };
  3232. struct SBinaryIntOp {
  3233. int input1;
  3234. int input2;
  3235. int output1;
  3236. int output2;
  3237. };
  3238. struct STertiaryIntOp {
  3239. int input1;
  3240. int input2;
  3241. int input3;
  3242. int output;
  3243. };
  3244. struct SBinaryUintOp {
  3245. unsigned int input1;
  3246. unsigned int input2;
  3247. unsigned int output1;
  3248. unsigned int output2;
  3249. };
  3250. struct STertiaryUintOp {
  3251. unsigned int input1;
  3252. unsigned int input2;
  3253. unsigned int input3;
  3254. unsigned int output;
  3255. };
  3256. struct SUnaryInt16Op {
  3257. short input;
  3258. short output;
  3259. };
  3260. struct SUnaryUint16Op {
  3261. unsigned short input;
  3262. unsigned short output;
  3263. };
  3264. struct SBinaryInt16Op {
  3265. short input1;
  3266. short input2;
  3267. short output1;
  3268. short output2;
  3269. };
  3270. struct STertiaryInt16Op {
  3271. short input1;
  3272. short input2;
  3273. short input3;
  3274. short output;
  3275. };
  3276. struct SBinaryUint16Op {
  3277. unsigned short input1;
  3278. unsigned short input2;
  3279. unsigned short output1;
  3280. unsigned short output2;
  3281. };
  3282. struct STertiaryUint16Op {
  3283. unsigned short input1;
  3284. unsigned short input2;
  3285. unsigned short input3;
  3286. unsigned short output;
  3287. };
  3288. // representation for HLSL float vectors
  3289. struct SDotOp {
  3290. XMFLOAT4 input1;
  3291. XMFLOAT4 input2;
  3292. float o_dot2;
  3293. float o_dot3;
  3294. float o_dot4;
  3295. };
  3296. struct Half2
  3297. {
  3298. uint16_t x;
  3299. uint16_t y;
  3300. Half2() = default;
  3301. Half2(const Half2&) = default;
  3302. Half2& operator=(const Half2&) = default;
  3303. Half2(Half2&&) = default;
  3304. Half2& operator=(Half2&&) = default;
  3305. constexpr Half2(uint16_t _x, uint16_t _y) : x(_x), y(_y) {}
  3306. explicit Half2(_In_reads_(2) const uint16_t *pArray) : x(pArray[0]), y(pArray[1]) {}
  3307. };
  3308. struct SDot2AddHalfOp {
  3309. Half2 input1;
  3310. Half2 input2;
  3311. float acc;
  3312. float result;
  3313. };
  3314. struct SDot4AddI8PackedOp {
  3315. uint32_t input1;
  3316. uint32_t input2;
  3317. int32_t acc;
  3318. int32_t result;
  3319. };
  3320. struct SDot4AddU8PackedOp {
  3321. uint32_t input1;
  3322. uint32_t input2;
  3323. uint32_t acc;
  3324. uint32_t result;
  3325. };
  3326. struct SMsad4 {
  3327. unsigned int ref;
  3328. XMUINT2 src;
  3329. XMUINT4 accum;
  3330. XMUINT4 result;
  3331. };
  3332. struct SPackUnpackOpOutPacked
  3333. {
  3334. uint32_t packedUint32;
  3335. uint32_t packedInt32;
  3336. uint32_t packedUint16;
  3337. uint32_t packedInt16;
  3338. uint32_t packedClampedUint32;
  3339. uint32_t packedClampedInt32;
  3340. uint32_t packedClampedUint16;
  3341. uint32_t packedClampedInt16;
  3342. };
  3343. struct SPackUnpackOpOutUnpacked {
  3344. std::array<uint32_t, 4> outputUint32;
  3345. std::array<int32_t, 4> outputInt32;
  3346. std::array<uint16_t, 4> outputUint16;
  3347. std::array<int16_t, 4> outputInt16;
  3348. std::array<uint32_t, 4> outputClampedUint32;
  3349. std::array<int32_t, 4> outputClampedInt32;
  3350. std::array<uint16_t, 4> outputClampedUint16;
  3351. std::array<int16_t, 4> outputClampedInt16;
  3352. };
  3353. // Parameter representation for taef data-driven tests
  3354. struct TableParameter {
  3355. LPCWSTR m_name;
  3356. enum TableParameterType {
  3357. INT8,
  3358. INT16,
  3359. INT32,
  3360. UINT,
  3361. FLOAT,
  3362. HALF,
  3363. DOUBLE,
  3364. STRING,
  3365. BOOL,
  3366. INT8_TABLE,
  3367. INT16_TABLE,
  3368. INT32_TABLE,
  3369. FLOAT_TABLE,
  3370. HALF_TABLE,
  3371. DOUBLE_TABLE,
  3372. STRING_TABLE,
  3373. UINT8_TABLE,
  3374. UINT16_TABLE,
  3375. UINT32_TABLE,
  3376. BOOL_TABLE
  3377. };
  3378. TableParameterType m_type;
  3379. bool m_required; // required parameter
  3380. int8_t m_int8;
  3381. int16_t m_int16;
  3382. int m_int32;
  3383. unsigned int m_uint;
  3384. float m_float;
  3385. uint16_t m_half; // no such thing as half type in c++. Use int16 instead
  3386. double m_double;
  3387. bool m_bool;
  3388. WEX::Common::String m_str;
  3389. std::vector<int8_t> m_int8Table;
  3390. std::vector<int16_t> m_int16Table;
  3391. std::vector<int> m_int32Table;
  3392. std::vector<uint8_t> m_uint8Table;
  3393. std::vector<uint16_t> m_uint16Table;
  3394. std::vector<unsigned int> m_uint32Table;
  3395. std::vector<float> m_floatTable;
  3396. std::vector<uint16_t> m_halfTable; // no such thing as half type in c++
  3397. std::vector<double> m_doubleTable;
  3398. std::vector<bool> m_boolTable;
  3399. std::vector<WEX::Common::String> m_StringTable;
  3400. };
  3401. class TableParameterHandler {
  3402. private:
  3403. HRESULT ParseTableRow();
  3404. public:
  3405. TableParameter* m_table;
  3406. size_t m_tableSize;
  3407. TableParameterHandler(TableParameter *pTable, size_t size) : m_table(pTable), m_tableSize(size) {
  3408. clearTableParameter();
  3409. VERIFY_SUCCEEDED(ParseTableRow());
  3410. }
  3411. TableParameter* GetTableParamByName(LPCWSTR name) {
  3412. for (size_t i = 0; i < m_tableSize; ++i) {
  3413. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3414. return &m_table[i];
  3415. }
  3416. }
  3417. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3418. return nullptr;
  3419. }
  3420. void clearTableParameter() {
  3421. for (size_t i = 0; i < m_tableSize; ++i) {
  3422. m_table[i].m_int32 = 0;
  3423. m_table[i].m_uint = 0;
  3424. m_table[i].m_double = 0;
  3425. m_table[i].m_bool = false;
  3426. m_table[i].m_str = WEX::Common::String();
  3427. }
  3428. }
  3429. template <class T1>
  3430. std::vector<T1> *GetDataArray(LPCWSTR name) {
  3431. return nullptr;
  3432. }
  3433. template <>
  3434. std::vector<int> *GetDataArray(LPCWSTR name) {
  3435. for (size_t i = 0; i < m_tableSize; ++i) {
  3436. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3437. return &(m_table[i].m_int32Table);
  3438. }
  3439. }
  3440. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3441. return nullptr;
  3442. }
  3443. template <>
  3444. std::vector<int8_t> *GetDataArray(LPCWSTR name) {
  3445. for (size_t i = 0; i < m_tableSize; ++i) {
  3446. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3447. return &(m_table[i].m_int8Table);
  3448. }
  3449. }
  3450. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3451. return nullptr;
  3452. }
  3453. template <>
  3454. std::vector<int16_t> *GetDataArray(LPCWSTR name) {
  3455. for (size_t i = 0; i < m_tableSize; ++i) {
  3456. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3457. return &(m_table[i].m_int16Table);
  3458. }
  3459. }
  3460. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3461. return nullptr;
  3462. }
  3463. template <>
  3464. std::vector<unsigned int> *GetDataArray(LPCWSTR name) {
  3465. for (size_t i = 0; i < m_tableSize; ++i) {
  3466. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3467. return &(m_table[i].m_uint32Table);
  3468. }
  3469. }
  3470. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3471. return nullptr;
  3472. }
  3473. template <>
  3474. std::vector<float> *GetDataArray(LPCWSTR name) {
  3475. for (size_t i = 0; i < m_tableSize; ++i) {
  3476. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3477. return &(m_table[i].m_floatTable);
  3478. }
  3479. }
  3480. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3481. return nullptr;
  3482. }
  3483. // TODO: uin16_t may be used to represent two different types when we introduce uint16
  3484. template <>
  3485. std::vector<uint16_t> *GetDataArray(LPCWSTR name) {
  3486. for (size_t i = 0; i < m_tableSize; ++i) {
  3487. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3488. return &(m_table[i].m_halfTable);
  3489. }
  3490. }
  3491. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3492. return nullptr;
  3493. }
  3494. template <>
  3495. std::vector<double> *GetDataArray(LPCWSTR name) {
  3496. for (size_t i = 0; i < m_tableSize; ++i) {
  3497. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3498. return &(m_table[i].m_doubleTable);
  3499. }
  3500. }
  3501. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3502. return nullptr;
  3503. }
  3504. template <>
  3505. std::vector<bool> *GetDataArray(LPCWSTR name) {
  3506. for (size_t i = 0; i < m_tableSize; ++i) {
  3507. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3508. return &(m_table[i].m_boolTable);
  3509. }
  3510. }
  3511. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3512. return nullptr;
  3513. }
  3514. };
  3515. static TableParameter UnaryFPOpParameters[] = {
  3516. { L"ShaderOp.Target", TableParameter::STRING, true },
  3517. { L"ShaderOp.Text", TableParameter::STRING, true },
  3518. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3519. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3520. { L"Validation.Type", TableParameter::STRING, true },
  3521. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3522. { L"Warp.Version", TableParameter::UINT, false }
  3523. };
  3524. static TableParameter BinaryFPOpParameters[] = {
  3525. { L"ShaderOp.Target", TableParameter::STRING, true },
  3526. { L"ShaderOp.Text", TableParameter::STRING, true },
  3527. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3528. { L"Validation.Input2", TableParameter::FLOAT_TABLE, true },
  3529. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3530. { L"Validation.Expected2", TableParameter::FLOAT_TABLE, false },
  3531. { L"Validation.Type", TableParameter::STRING, true },
  3532. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3533. };
  3534. static TableParameter TertiaryFPOpParameters[] = {
  3535. { L"ShaderOp.Target", TableParameter::STRING, true },
  3536. { L"ShaderOp.Text", TableParameter::STRING, true },
  3537. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3538. { L"Validation.Input2", TableParameter::FLOAT_TABLE, true },
  3539. { L"Validation.Input3", TableParameter::FLOAT_TABLE, true },
  3540. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3541. { L"Validation.Type", TableParameter::STRING, true },
  3542. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3543. };
  3544. static TableParameter UnaryHalfOpParameters[] = {
  3545. { L"ShaderOp.Target", TableParameter::STRING, true },
  3546. { L"ShaderOp.Text", TableParameter::STRING, true },
  3547. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3548. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3549. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3550. { L"Validation.Type", TableParameter::STRING, true },
  3551. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3552. { L"Warp.Version", TableParameter::UINT, false }
  3553. };
  3554. static TableParameter BinaryHalfOpParameters[] = {
  3555. { L"ShaderOp.Target", TableParameter::STRING, true },
  3556. { L"ShaderOp.Text", TableParameter::STRING, true },
  3557. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3558. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3559. { L"Validation.Input2", TableParameter::HALF_TABLE, true },
  3560. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3561. { L"Validation.Expected2", TableParameter::HALF_TABLE, false },
  3562. { L"Validation.Type", TableParameter::STRING, true },
  3563. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3564. };
  3565. static TableParameter TertiaryHalfOpParameters[] = {
  3566. { L"ShaderOp.Target", TableParameter::STRING, true },
  3567. { L"ShaderOp.Text", TableParameter::STRING, true },
  3568. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3569. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3570. { L"Validation.Input2", TableParameter::HALF_TABLE, true },
  3571. { L"Validation.Input3", TableParameter::HALF_TABLE, true },
  3572. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3573. { L"Validation.Type", TableParameter::STRING, true },
  3574. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3575. };
  3576. static TableParameter UnaryIntOpParameters[] = {
  3577. { L"ShaderOp.Target", TableParameter::STRING, true },
  3578. { L"ShaderOp.Text", TableParameter::STRING, true },
  3579. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3580. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3581. { L"Validation.Tolerance", TableParameter::INT32, true },
  3582. };
  3583. static TableParameter UnaryUintOpParameters[] = {
  3584. { L"ShaderOp.Target", TableParameter::STRING, true },
  3585. { L"ShaderOp.Text", TableParameter::STRING, true },
  3586. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3587. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3588. { L"Validation.Tolerance", TableParameter::INT32, true },
  3589. };
  3590. static TableParameter BinaryIntOpParameters[] = {
  3591. { L"ShaderOp.Target", TableParameter::STRING, true },
  3592. { L"ShaderOp.Text", TableParameter::STRING, true },
  3593. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3594. { L"Validation.Input2", TableParameter::INT32_TABLE, true },
  3595. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3596. { L"Validation.Expected2", TableParameter::INT32_TABLE, false },
  3597. { L"Validation.Tolerance", TableParameter::INT32, true },
  3598. };
  3599. static TableParameter TertiaryIntOpParameters[] = {
  3600. { L"ShaderOp.Target", TableParameter::STRING, true },
  3601. { L"ShaderOp.Text", TableParameter::STRING, true },
  3602. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3603. { L"Validation.Input2", TableParameter::INT32_TABLE, true },
  3604. { L"Validation.Input3", TableParameter::INT32_TABLE, true },
  3605. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3606. { L"Validation.Tolerance", TableParameter::INT32, true },
  3607. };
  3608. static TableParameter BinaryUintOpParameters[] = {
  3609. { L"ShaderOp.Target", TableParameter::STRING, true },
  3610. { L"ShaderOp.Text", TableParameter::STRING, true },
  3611. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3612. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3613. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3614. { L"Validation.Expected2", TableParameter::UINT32_TABLE, false },
  3615. { L"Validation.Tolerance", TableParameter::INT32, true },
  3616. };
  3617. static TableParameter TertiaryUintOpParameters[] = {
  3618. { L"ShaderOp.Target", TableParameter::STRING, true },
  3619. { L"ShaderOp.Text", TableParameter::STRING, true },
  3620. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3621. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3622. { L"Validation.Input3", TableParameter::UINT32_TABLE, true },
  3623. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3624. { L"Validation.Tolerance", TableParameter::INT32, true },
  3625. };
  3626. static TableParameter UnaryInt16OpParameters[] = {
  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::INT16_TABLE, true },
  3631. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3632. { L"Validation.Tolerance", TableParameter::INT32, true },
  3633. };
  3634. static TableParameter UnaryUint16OpParameters[] = {
  3635. { L"ShaderOp.Target", TableParameter::STRING, true },
  3636. { L"ShaderOp.Text", TableParameter::STRING, true },
  3637. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3638. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3639. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3640. { L"Validation.Tolerance", TableParameter::INT32, true },
  3641. };
  3642. static TableParameter BinaryInt16OpParameters[] = {
  3643. { L"ShaderOp.Target", TableParameter::STRING, true },
  3644. { L"ShaderOp.Text", TableParameter::STRING, true },
  3645. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3646. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  3647. { L"Validation.Input2", TableParameter::INT16_TABLE, true },
  3648. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3649. { L"Validation.Expected2", TableParameter::INT16_TABLE, false },
  3650. { L"Validation.Tolerance", TableParameter::INT32, true },
  3651. };
  3652. static TableParameter TertiaryInt16OpParameters[] = {
  3653. { L"ShaderOp.Target", TableParameter::STRING, true },
  3654. { L"ShaderOp.Text", TableParameter::STRING, true },
  3655. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3656. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  3657. { L"Validation.Input2", TableParameter::INT16_TABLE, true },
  3658. { L"Validation.Input3", TableParameter::INT16_TABLE, true },
  3659. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3660. { L"Validation.Tolerance", TableParameter::INT32, true },
  3661. };
  3662. static TableParameter BinaryUint16OpParameters[] = {
  3663. { L"ShaderOp.Target", TableParameter::STRING, true },
  3664. { L"ShaderOp.Text", TableParameter::STRING, true },
  3665. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3666. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3667. { L"Validation.Input2", TableParameter::UINT16_TABLE, true },
  3668. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3669. { L"Validation.Expected2", TableParameter::UINT16_TABLE, false },
  3670. { L"Validation.Tolerance", TableParameter::INT32, true },
  3671. };
  3672. static TableParameter TertiaryUint16OpParameters[] = {
  3673. { L"ShaderOp.Target", TableParameter::STRING, true },
  3674. { L"ShaderOp.Text", TableParameter::STRING, true },
  3675. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3676. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3677. { L"Validation.Input2", TableParameter::UINT16_TABLE, true },
  3678. { L"Validation.Input3", TableParameter::UINT16_TABLE, true },
  3679. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3680. { L"Validation.Tolerance", TableParameter::INT32, true },
  3681. };
  3682. static TableParameter DotOpParameters[] = {
  3683. { L"ShaderOp.Target", TableParameter::STRING, true },
  3684. { L"ShaderOp.Text", TableParameter::STRING, true },
  3685. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3686. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3687. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3688. { L"Validation.Expected2", TableParameter::STRING_TABLE, true },
  3689. { L"Validation.Expected3", TableParameter::STRING_TABLE, true },
  3690. { L"Validation.Type", TableParameter::STRING, true },
  3691. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3692. };
  3693. static TableParameter Dot2AddHalfOpParameters[] = {
  3694. { L"ShaderOp.Target", TableParameter::STRING, true },
  3695. { L"ShaderOp.Text", TableParameter::STRING, true },
  3696. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3697. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3698. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3699. { L"Validation.Input3", TableParameter::FLOAT_TABLE, true },
  3700. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3701. { L"Validation.Type", TableParameter::STRING, true },
  3702. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3703. };
  3704. static TableParameter Dot4AddI8PackedOpParameters[] = {
  3705. { L"ShaderOp.Target", TableParameter::STRING, true },
  3706. { L"ShaderOp.Text", TableParameter::STRING, true },
  3707. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3708. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3709. { L"Validation.Input3", TableParameter::INT32_TABLE, true },
  3710. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3711. };
  3712. static TableParameter Dot4AddU8PackedOpParameters[] = {
  3713. { L"ShaderOp.Target", TableParameter::STRING, true },
  3714. { L"ShaderOp.Text", TableParameter::STRING, true },
  3715. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3716. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3717. { L"Validation.Input3", TableParameter::UINT32_TABLE, true },
  3718. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3719. };
  3720. static TableParameter Msad4OpParameters[] = {
  3721. { L"ShaderOp.Text", TableParameter::STRING, true },
  3722. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3723. { L"Validation.Input1", TableParameter::UINT32_TABLE, true},
  3724. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3725. { L"Validation.Input3", TableParameter::STRING_TABLE, true },
  3726. { L"Validation.Expected1", TableParameter::STRING_TABLE, true }
  3727. };
  3728. static TableParameter WaveIntrinsicsActiveIntParameters[] = {
  3729. { L"ShaderOp.Name", TableParameter::STRING, true },
  3730. { L"ShaderOp.Text", TableParameter::STRING, true },
  3731. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3732. { L"Validation.InputSet1", TableParameter::INT32_TABLE, true },
  3733. { L"Validation.InputSet2", TableParameter::INT32_TABLE, false },
  3734. { L"Validation.InputSet3", TableParameter::INT32_TABLE, false },
  3735. { L"Validation.InputSet4", TableParameter::INT32_TABLE, false }
  3736. };
  3737. static TableParameter WaveIntrinsicsPrefixIntParameters[] = {
  3738. { L"ShaderOp.Name", TableParameter::STRING, true },
  3739. { L"ShaderOp.Text", TableParameter::STRING, true },
  3740. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3741. { L"Validation.InputSet1", TableParameter::INT32_TABLE, true },
  3742. { L"Validation.InputSet2", TableParameter::INT32_TABLE, false },
  3743. { L"Validation.InputSet3", TableParameter::INT32_TABLE, false },
  3744. { L"Validation.InputSet4", TableParameter::INT32_TABLE, false }
  3745. };
  3746. static TableParameter WaveIntrinsicsActiveUintParameters[] = {
  3747. { L"ShaderOp.Name", TableParameter::STRING, true },
  3748. { L"ShaderOp.Text", TableParameter::STRING, true },
  3749. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3750. { L"Validation.InputSet1", TableParameter::UINT32_TABLE, true },
  3751. { L"Validation.InputSet2", TableParameter::UINT32_TABLE, false },
  3752. { L"Validation.InputSet3", TableParameter::UINT32_TABLE, false },
  3753. { L"Validation.InputSet4", TableParameter::UINT32_TABLE, false }
  3754. };
  3755. static TableParameter WaveIntrinsicsPrefixUintParameters[] = {
  3756. { L"ShaderOp.Name", TableParameter::STRING, true },
  3757. { L"ShaderOp.Text", TableParameter::STRING, true },
  3758. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3759. { L"Validation.InputSet1", TableParameter::UINT32_TABLE, true },
  3760. { L"Validation.InputSet2", TableParameter::UINT32_TABLE, false },
  3761. { L"Validation.InputSet3", TableParameter::UINT32_TABLE, false },
  3762. { L"Validation.InputSet4", TableParameter::UINT32_TABLE, false }
  3763. };
  3764. static TableParameter WaveIntrinsicsMultiPrefixIntParameters[] = {
  3765. { L"ShaderOp.Name", TableParameter::STRING, true },
  3766. { L"ShaderOp.Target", TableParameter::STRING, true },
  3767. { L"ShaderOp.Text", TableParameter::STRING, true },
  3768. { L"Validation.Keys", TableParameter::INT32_TABLE, true },
  3769. { L"Validation.Values", TableParameter::INT32_TABLE, true },
  3770. };
  3771. static TableParameter WaveIntrinsicsMultiPrefixUintParameters[] = {
  3772. { L"ShaderOp.Name", TableParameter::STRING, true },
  3773. { L"ShaderOp.Target", TableParameter::STRING, true },
  3774. { L"ShaderOp.Text", TableParameter::STRING, true },
  3775. { L"Validation.Keys", TableParameter::UINT32_TABLE, true },
  3776. { L"Validation.Values", TableParameter::UINT32_TABLE, true },
  3777. };
  3778. static TableParameter WaveIntrinsicsActiveBoolParameters[] = {
  3779. { L"ShaderOp.Name", TableParameter::STRING, true },
  3780. { L"ShaderOp.Text", TableParameter::STRING, true },
  3781. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3782. { L"Validation.InputSet1", TableParameter::BOOL_TABLE, true },
  3783. { L"Validation.InputSet2", TableParameter::BOOL_TABLE, false },
  3784. { L"Validation.InputSet3", TableParameter::BOOL_TABLE, false },
  3785. };
  3786. static TableParameter CBufferTestHalfParameters[] = {
  3787. { L"Validation.InputSet", TableParameter::HALF_TABLE, true },
  3788. };
  3789. static TableParameter DenormBinaryFPOpParameters[] = {
  3790. { L"ShaderOp.Target", TableParameter::STRING, true },
  3791. { L"ShaderOp.Text", TableParameter::STRING, true },
  3792. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3793. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3794. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3795. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3796. { L"Validation.Expected2", TableParameter::STRING_TABLE, false },
  3797. { L"Validation.Type", TableParameter::STRING, true },
  3798. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3799. };
  3800. static TableParameter DenormTertiaryFPOpParameters[] = {
  3801. { L"ShaderOp.Target", TableParameter::STRING, true },
  3802. { L"ShaderOp.Text", TableParameter::STRING, true },
  3803. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3804. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3805. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3806. { L"Validation.Input3", TableParameter::STRING_TABLE, true },
  3807. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3808. { L"Validation.Expected2", TableParameter::STRING_TABLE, false },
  3809. { L"Validation.Type", TableParameter::STRING, true },
  3810. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3811. };
  3812. static TableParameter PackUnpackOpParameters[] = {
  3813. { L"ShaderOp.Text", TableParameter::STRING, true },
  3814. { L"Validation.Type", TableParameter::STRING, true },
  3815. { L"Validation.Tolerance", TableParameter::UINT, true },
  3816. { L"Validation.Input", TableParameter::UINT32_TABLE, true },
  3817. };
  3818. static bool IsHexString(PCWSTR str, uint16_t *value) {
  3819. std::wstring wString(str);
  3820. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3821. LPCWSTR wstr = wString.c_str();
  3822. if (wcsncmp(wstr, L"0x", 2) == 0 || wcsncmp(wstr, L"0b", 2) == 0) {
  3823. *value = (uint16_t)wcstol(wstr, NULL, 0);
  3824. return true;
  3825. }
  3826. return false;
  3827. }
  3828. static HRESULT ParseDataToFloat(PCWSTR str, float &value) {
  3829. std::wstring wString(str);
  3830. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3831. PCWSTR wstr = wString.data();
  3832. if (_wcsicmp(wstr, L"NaN") == 0) {
  3833. value = NAN;
  3834. } else if (_wcsicmp(wstr, L"-inf") == 0) {
  3835. value = -(INFINITY);
  3836. } else if (_wcsicmp(wstr, L"inf") == 0) {
  3837. value = INFINITY;
  3838. } else if (_wcsicmp(wstr, L"-denorm") == 0) {
  3839. value = -(FLT_MIN / 2);
  3840. } else if (_wcsicmp(wstr, L"denorm") == 0) {
  3841. value = FLT_MIN / 2;
  3842. } else if (_wcsicmp(wstr, L"-0.0f") == 0 || _wcsicmp(wstr, L"-0.0") == 0 ||
  3843. _wcsicmp(wstr, L"-0") == 0) {
  3844. value = -0.0f;
  3845. } else if (_wcsicmp(wstr, L"0.0f") == 0 || _wcsicmp(wstr, L"0.0") == 0 ||
  3846. _wcsicmp(wstr, L"0") == 0) {
  3847. value = 0.0f;
  3848. } else if (_wcsnicmp(wstr, L"0x", 2) == 0) { // For hex values, take values literally
  3849. unsigned temp_i = std::stoul(wstr, nullptr, 16);
  3850. value = (float&)temp_i;
  3851. }
  3852. else {
  3853. // evaluate the expression of wstring
  3854. double val = _wtof(wstr);
  3855. if (val == 0) {
  3856. LogErrorFmt(L"Failed to parse parameter %s to float", wstr);
  3857. return E_FAIL;
  3858. }
  3859. value = (float)val;
  3860. }
  3861. return S_OK;
  3862. }
  3863. static HRESULT ParseDataToInt(PCWSTR str, int &value) {
  3864. std::wstring wString(str);
  3865. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3866. PCWSTR wstr = wString.data();
  3867. // evaluate the expression of string
  3868. if (_wcsicmp(wstr, L"0.0") == 0 || _wcsicmp(wstr, L"0") == 0) {
  3869. value = 0;
  3870. return S_OK;
  3871. }
  3872. int val = _wtoi(wstr);
  3873. if (val == 0) {
  3874. LogErrorFmt(L"Failed to parse parameter %s to int", wstr);
  3875. return E_FAIL;
  3876. }
  3877. value = val;
  3878. return S_OK;
  3879. }
  3880. static HRESULT ParseDataToUint(PCWSTR str, unsigned int &value) {
  3881. std::wstring wString(str);
  3882. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3883. PCWSTR wstr = wString.data();
  3884. // evaluate the expression of string
  3885. if (_wcsicmp(wstr, L"0") == 0 || _wcsicmp(wstr, L"0x00000000") == 0) {
  3886. value = 0;
  3887. return S_OK;
  3888. }
  3889. wchar_t *end;
  3890. unsigned int val = std::wcstoul(wstr, &end, 0);
  3891. if (val == 0) {
  3892. LogErrorFmt(L"Failed to parse parameter %s to int", wstr);
  3893. return E_FAIL;
  3894. }
  3895. value = val;
  3896. return S_OK;
  3897. }
  3898. static HRESULT ParseDataToVectorFloat(PCWSTR str, float *ptr, size_t count) {
  3899. std::wstring wstr(str);
  3900. size_t curPosition = 0;
  3901. // parse a string of dot product separated by commas
  3902. for (size_t i = 0; i < count; ++i) {
  3903. size_t nextPosition = wstr.find(L",", curPosition);
  3904. if (FAILED(ParseDataToFloat(
  3905. wstr.substr(curPosition, nextPosition - curPosition).data(),
  3906. *(ptr + i)))) {
  3907. return E_FAIL;
  3908. }
  3909. curPosition = nextPosition + 1;
  3910. }
  3911. return S_OK;
  3912. }
  3913. static HRESULT ParseDataToVectorHalf(PCWSTR str, uint16_t *ptr, size_t count) {
  3914. std::wstring wstr(str);
  3915. size_t curPosition = 0;
  3916. // parse a string of dot product separated by commas
  3917. for (size_t i = 0; i < count; ++i) {
  3918. size_t nextPosition = wstr.find(L",", curPosition);
  3919. float floatValue;
  3920. if (FAILED(ParseDataToFloat(
  3921. wstr.substr(curPosition, nextPosition - curPosition).data(), floatValue))) {
  3922. return E_FAIL;
  3923. }
  3924. *(ptr + i) = ConvertFloat32ToFloat16(floatValue);
  3925. curPosition = nextPosition + 1;
  3926. }
  3927. return S_OK;
  3928. }
  3929. static HRESULT ParseDataToVectorUint(PCWSTR str, unsigned int *ptr, size_t count) {
  3930. std::wstring wstr(str);
  3931. size_t curPosition = 0;
  3932. // parse a string of dot product separated by commas
  3933. for (size_t i = 0; i < count; ++i) {
  3934. size_t nextPosition = wstr.find(L",", curPosition);
  3935. if (FAILED(ParseDataToUint(
  3936. wstr.substr(curPosition, nextPosition - curPosition).data(),
  3937. *(ptr + i)))) {
  3938. return E_FAIL;
  3939. }
  3940. curPosition = nextPosition + 1;
  3941. }
  3942. return S_OK;
  3943. }
  3944. HRESULT TableParameterHandler::ParseTableRow() {
  3945. TableParameter *table = m_table;
  3946. for (unsigned int i = 0; i < m_tableSize; ++i) {
  3947. switch (table[i].m_type) {
  3948. case TableParameter::INT8:
  3949. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3950. table[i].m_int32)) && table[i].m_required) {
  3951. // TryGetValue does not suppport reading from int16
  3952. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3953. return E_FAIL;
  3954. }
  3955. table[i].m_int8 = (int8_t)(table[i].m_int32);
  3956. break;
  3957. case TableParameter::INT16:
  3958. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3959. table[i].m_int32)) && table[i].m_required) {
  3960. // TryGetValue does not suppport reading from int16
  3961. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3962. return E_FAIL;
  3963. }
  3964. table[i].m_int16 = (short)(table[i].m_int32);
  3965. break;
  3966. case TableParameter::INT32:
  3967. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3968. table[i].m_int32)) && table[i].m_required) {
  3969. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3970. return E_FAIL;
  3971. }
  3972. break;
  3973. case TableParameter::UINT:
  3974. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3975. table[i].m_uint)) && table[i].m_required) {
  3976. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3977. return E_FAIL;
  3978. }
  3979. break;
  3980. case TableParameter::DOUBLE:
  3981. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3982. table[i].m_name, table[i].m_double)) && table[i].m_required) {
  3983. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3984. return E_FAIL;
  3985. }
  3986. break;
  3987. case TableParameter::STRING:
  3988. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3989. table[i].m_str)) && table[i].m_required) {
  3990. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3991. return E_FAIL;
  3992. }
  3993. break;
  3994. case TableParameter::BOOL:
  3995. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3996. table[i].m_str)) && table[i].m_bool) {
  3997. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3998. return E_FAIL;
  3999. }
  4000. break;
  4001. case TableParameter::INT8_TABLE: {
  4002. WEX::TestExecution::TestDataArray<int> tempTable;
  4003. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4004. table[i].m_name, tempTable)) && table[i].m_required) {
  4005. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4006. return E_FAIL;
  4007. }
  4008. // TryGetValue does not suppport reading from int8
  4009. table[i].m_int8Table.resize(tempTable.GetSize());
  4010. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4011. table[i].m_int8Table[j] = (int8_t)tempTable[j];
  4012. }
  4013. break;
  4014. }
  4015. case TableParameter::INT16_TABLE: {
  4016. WEX::TestExecution::TestDataArray<int> tempTable;
  4017. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4018. table[i].m_name, tempTable)) && table[i].m_required) {
  4019. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4020. return E_FAIL;
  4021. }
  4022. // TryGetValue does not suppport reading from int8
  4023. table[i].m_int16Table.resize(tempTable.GetSize());
  4024. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4025. table[i].m_int16Table[j] = (int16_t)tempTable[j];
  4026. }
  4027. break;
  4028. }case TableParameter::INT32_TABLE: {
  4029. WEX::TestExecution::TestDataArray<int> tempTable;
  4030. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4031. table[i].m_name, tempTable)) && table[i].m_required) {
  4032. // TryGetValue does not suppport reading from int8
  4033. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4034. return E_FAIL;
  4035. }
  4036. table[i].m_int32Table.resize(tempTable.GetSize());
  4037. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4038. table[i].m_int32Table[j] = tempTable[j];
  4039. }
  4040. break;
  4041. }
  4042. case TableParameter::UINT8_TABLE: {
  4043. WEX::TestExecution::TestDataArray<int> tempTable;
  4044. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4045. table[i].m_name, tempTable)) && table[i].m_required) {
  4046. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4047. return E_FAIL;
  4048. }
  4049. // TryGetValue does not suppport reading from int8
  4050. table[i].m_int8Table.resize(tempTable.GetSize());
  4051. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4052. table[i].m_int8Table[j] = (uint8_t)tempTable[j];
  4053. }
  4054. break;
  4055. }
  4056. case TableParameter::UINT16_TABLE: {
  4057. WEX::TestExecution::TestDataArray<int> tempTable;
  4058. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4059. table[i].m_name, tempTable)) && table[i].m_required) {
  4060. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4061. return E_FAIL;
  4062. }
  4063. // TryGetValue does not suppport reading from int8
  4064. table[i].m_uint16Table.resize(tempTable.GetSize());
  4065. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4066. table[i].m_uint16Table[j] = (uint16_t)tempTable[j];
  4067. }
  4068. break;
  4069. }
  4070. case TableParameter::UINT32_TABLE: {
  4071. WEX::TestExecution::TestDataArray<unsigned int> tempTable;
  4072. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4073. table[i].m_name, tempTable)) && table[i].m_required) {
  4074. // TryGetValue does not suppport reading from int8
  4075. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4076. return E_FAIL;
  4077. }
  4078. table[i].m_uint32Table.resize(tempTable.GetSize());
  4079. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4080. table[i].m_uint32Table[j] = tempTable[j];
  4081. }
  4082. break;
  4083. }
  4084. case TableParameter::FLOAT_TABLE: {
  4085. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  4086. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4087. table[i].m_name, tempTable)) && table[i].m_required) {
  4088. // TryGetValue does not suppport reading from int8
  4089. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4090. return E_FAIL;
  4091. }
  4092. table[i].m_floatTable.resize(tempTable.GetSize());
  4093. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4094. ParseDataToFloat(tempTable[j], table[i].m_floatTable[j]);
  4095. }
  4096. break;
  4097. }
  4098. case TableParameter::HALF_TABLE: {
  4099. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  4100. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4101. table[i].m_name, tempTable)) && table[i].m_required) {
  4102. // TryGetValue does not suppport reading from int8
  4103. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4104. return E_FAIL;
  4105. }
  4106. table[i].m_halfTable.resize(tempTable.GetSize());
  4107. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4108. uint16_t value = 0;
  4109. if (IsHexString(tempTable[j], &value)) {
  4110. table[i].m_halfTable[j] = value;
  4111. }
  4112. else {
  4113. float val;
  4114. ParseDataToFloat(tempTable[j], val);
  4115. if (isdenorm(val))
  4116. table[i].m_halfTable[j] = signbit(val) ? Float16NegDenorm : Float16PosDenorm;
  4117. else
  4118. table[i].m_halfTable[j] = ConvertFloat32ToFloat16(val);
  4119. }
  4120. }
  4121. break;
  4122. }
  4123. case TableParameter::DOUBLE_TABLE: {
  4124. WEX::TestExecution::TestDataArray<double> tempTable;
  4125. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4126. table[i].m_name, tempTable)) && table[i].m_required) {
  4127. // TryGetValue does not suppport reading from int8
  4128. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4129. return E_FAIL;
  4130. }
  4131. table[i].m_doubleTable.resize(tempTable.GetSize());
  4132. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4133. table[i].m_doubleTable[j] = tempTable[j];
  4134. }
  4135. break;
  4136. }
  4137. case TableParameter::BOOL_TABLE: {
  4138. WEX::TestExecution::TestDataArray<bool> tempTable;
  4139. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4140. table[i].m_name, tempTable)) && table[i].m_required) {
  4141. // TryGetValue does not suppport reading from int8
  4142. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4143. return E_FAIL;
  4144. }
  4145. table[i].m_boolTable.resize(tempTable.GetSize());
  4146. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4147. table[i].m_boolTable[j] = tempTable[j];
  4148. }
  4149. break;
  4150. }
  4151. case TableParameter::STRING_TABLE: {
  4152. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  4153. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4154. table[i].m_name, tempTable)) && table[i].m_required) {
  4155. // TryGetValue does not suppport reading from int8
  4156. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4157. return E_FAIL;
  4158. }
  4159. table[i].m_StringTable.resize(tempTable.GetSize());
  4160. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4161. table[i].m_StringTable[j] = tempTable[j];
  4162. }
  4163. break;
  4164. }
  4165. default:
  4166. DXASSERT_NOMSG("Invalid Parameter Type");
  4167. }
  4168. if (errno == ERANGE) {
  4169. LogErrorFmt(L"got out of range value for table %s", table[i].m_name);
  4170. return E_FAIL;
  4171. }
  4172. }
  4173. return S_OK;
  4174. }
  4175. static void VerifyOutputWithExpectedValueInt(int output, int ref, int tolerance) {
  4176. VERIFY_IS_TRUE(output - ref <= tolerance && ref - output <= tolerance);
  4177. }
  4178. static void VerifyOutputWithExpectedValueUInt(uint32_t output, uint32_t ref, uint32_t tolerance) {
  4179. VERIFY_IS_TRUE(output - ref <= tolerance && ref - output <= tolerance);
  4180. }
  4181. static void VerifyOutputWithExpectedValueUInt4(XMUINT4 output, XMUINT4 ref) {
  4182. VERIFY_ARE_EQUAL(output.x, ref.x);
  4183. VERIFY_ARE_EQUAL(output.y, ref.y);
  4184. VERIFY_ARE_EQUAL(output.z, ref.z);
  4185. VERIFY_ARE_EQUAL(output.w, ref.w);
  4186. }
  4187. static void VerifyOutputWithExpectedValueFloat(
  4188. float output, float ref, LPCWSTR type, double tolerance,
  4189. hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
  4190. if (_wcsicmp(type, L"Relative") == 0) {
  4191. VERIFY_IS_TRUE(CompareFloatRelativeEpsilon(output, ref, (int)tolerance, mode));
  4192. } else if (_wcsicmp(type, L"Epsilon") == 0) {
  4193. VERIFY_IS_TRUE(CompareFloatEpsilon(output, ref, (float)tolerance, mode));
  4194. } else if (_wcsicmp(type, L"ULP") == 0) {
  4195. VERIFY_IS_TRUE(CompareFloatULP(output, ref, (int)tolerance, mode));
  4196. } else {
  4197. LogErrorFmt(L"Failed to read comparison type %S", type);
  4198. }
  4199. }
  4200. static bool CompareOutputWithExpectedValueFloat(
  4201. float output, float ref, LPCWSTR type, double tolerance,
  4202. hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
  4203. if (_wcsicmp(type, L"Relative") == 0) {
  4204. return CompareFloatRelativeEpsilon(output, ref, (int)tolerance, mode);
  4205. } else if (_wcsicmp(type, L"Epsilon") == 0) {
  4206. return CompareFloatEpsilon(output, ref, (float)tolerance, mode);
  4207. } else if (_wcsicmp(type, L"ULP") == 0) {
  4208. return CompareFloatULP(output, ref, (int)tolerance, mode);
  4209. } else {
  4210. LogErrorFmt(L"Failed to read comparison type %S", type);
  4211. return false;
  4212. }
  4213. }
  4214. static void VerifyOutputWithExpectedValueHalf(
  4215. uint16_t output, uint16_t ref, LPCWSTR type, double tolerance) {
  4216. if (_wcsicmp(type, L"Relative") == 0) {
  4217. VERIFY_IS_TRUE(CompareHalfRelativeEpsilon(output, ref, (int)tolerance));
  4218. }
  4219. else if (_wcsicmp(type, L"Epsilon") == 0) {
  4220. VERIFY_IS_TRUE(CompareHalfEpsilon(output, ref, (float)tolerance));
  4221. }
  4222. else if (_wcsicmp(type, L"ULP") == 0) {
  4223. VERIFY_IS_TRUE(CompareHalfULP(output, ref, (float)tolerance));
  4224. }
  4225. else {
  4226. LogErrorFmt(L"Failed to read comparison type %S", type);
  4227. }
  4228. }
  4229. TEST_F(ExecutionTest, UnaryFloatOpTest) {
  4230. WEX::TestExecution::SetVerifyOutput verifySettings(
  4231. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4232. CComPtr<IStream> pStream;
  4233. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4234. CComPtr<ID3D12Device> pDevice;
  4235. if (!CreateDevice(&pDevice)) {
  4236. return;
  4237. }
  4238. // Read data from the table
  4239. int tableSize = sizeof(UnaryFPOpParameters) / sizeof(TableParameter);
  4240. TableParameterHandler handler(UnaryFPOpParameters, tableSize);
  4241. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4242. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4243. unsigned int WarpVersion = handler.GetTableParamByName(L"Warp.Version")->m_uint;
  4244. if (GetTestParamUseWARP(true) && !IsValidWarpDllVersion(WarpVersion)) {
  4245. return;
  4246. }
  4247. std::vector<float> *Validation_Input =
  4248. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4249. std::vector<float> *Validation_Expected =
  4250. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4251. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4252. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4253. size_t count = Validation_Input->size();
  4254. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4255. pDevice, m_support, pStream, "UnaryFPOp",
  4256. // this callbacked is called when the test
  4257. // is creating the resource to run the test
  4258. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4259. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryFPOp"));
  4260. size_t size = sizeof(SUnaryFPOp) * count;
  4261. Data.resize(size);
  4262. SUnaryFPOp *pPrimitives = (SUnaryFPOp *)Data.data();
  4263. for (size_t i = 0; i < count; ++i) {
  4264. SUnaryFPOp *p = &pPrimitives[i];
  4265. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4266. }
  4267. // use shader from data table
  4268. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4269. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4270. });
  4271. MappedData data;
  4272. test->Test->GetReadBackData("SUnaryFPOp", &data);
  4273. SUnaryFPOp *pPrimitives = (SUnaryFPOp*)data.data();
  4274. WEX::TestExecution::DisableVerifyExceptions dve;
  4275. for (unsigned i = 0; i < count; ++i) {
  4276. SUnaryFPOp *p = &pPrimitives[i];
  4277. float val = (*Validation_Expected)[i % Validation_Expected->size()];
  4278. LogCommentFmt(
  4279. L"element #%u, input = %6.8f, output = %6.8f, expected = %6.8f", i,
  4280. p->input, p->output, val);
  4281. VerifyOutputWithExpectedValueFloat(p->output, val, Validation_Type, Validation_Tolerance);
  4282. }
  4283. }
  4284. TEST_F(ExecutionTest, BinaryFloatOpTest) {
  4285. WEX::TestExecution::SetVerifyOutput verifySettings(
  4286. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4287. CComPtr<IStream> pStream;
  4288. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4289. CComPtr<ID3D12Device> pDevice;
  4290. if (!CreateDevice(&pDevice)) {
  4291. return;
  4292. }
  4293. // Read data from the table
  4294. int tableSize = sizeof(BinaryFPOpParameters) / sizeof(TableParameter);
  4295. TableParameterHandler handler(BinaryFPOpParameters, tableSize);
  4296. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4297. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4298. std::vector<float> *Validation_Input1 =
  4299. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4300. std::vector<float> *Validation_Input2 =
  4301. &(handler.GetTableParamByName(L"Validation.Input2")->m_floatTable);
  4302. std::vector<float> *Validation_Expected1 =
  4303. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4304. std::vector<float> *Validation_Expected2 =
  4305. &(handler.GetTableParamByName(L"Validation.Expected2")->m_floatTable);
  4306. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4307. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4308. size_t count = Validation_Input1->size();
  4309. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4310. pDevice, m_support, pStream, "BinaryFPOp",
  4311. // this callbacked is called when the test
  4312. // is creating the resource to run the test
  4313. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4314. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  4315. size_t size = sizeof(SBinaryFPOp) * count;
  4316. Data.resize(size);
  4317. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)Data.data();
  4318. for (size_t i = 0; i < count; ++i) {
  4319. SBinaryFPOp *p = &pPrimitives[i];
  4320. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4321. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4322. }
  4323. // use shader from data table
  4324. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4325. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4326. });
  4327. MappedData data;
  4328. test->Test->GetReadBackData("SBinaryFPOp", &data);
  4329. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)data.data();
  4330. WEX::TestExecution::DisableVerifyExceptions dve;
  4331. unsigned numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4332. if (numExpected == 2) {
  4333. for (unsigned i = 0; i < count; ++i) {
  4334. SBinaryFPOp *p = &pPrimitives[i];
  4335. float val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4336. float val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4337. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output1 = "
  4338. L"%6.8f, expected1 = %6.8f, output2 = %6.8f, expected2 = %6.8f",
  4339. i, p->input1, p->input2, p->output1, val1, p->output2,
  4340. val2);
  4341. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  4342. Validation_Tolerance);
  4343. VerifyOutputWithExpectedValueFloat(p->output2, val2, Validation_Type,
  4344. Validation_Tolerance);
  4345. }
  4346. }
  4347. else if (numExpected == 1) {
  4348. for (unsigned i = 0; i < count; ++i) {
  4349. SBinaryFPOp *p = &pPrimitives[i];
  4350. float val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4351. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output1 = "
  4352. L"%6.8f, expected1 = %6.8f",
  4353. i, p->input1, p->input2, p->output1, val1);
  4354. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  4355. Validation_Tolerance);
  4356. }
  4357. }
  4358. else {
  4359. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4360. }
  4361. }
  4362. TEST_F(ExecutionTest, TertiaryFloatOpTest) {
  4363. WEX::TestExecution::SetVerifyOutput verifySettings(
  4364. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4365. CComPtr<IStream> pStream;
  4366. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4367. CComPtr<ID3D12Device> pDevice;
  4368. if (!CreateDevice(&pDevice)) {
  4369. return;
  4370. }
  4371. // Read data from the table
  4372. int tableSize = sizeof(TertiaryFPOpParameters) / sizeof(TableParameter);
  4373. TableParameterHandler handler(TertiaryFPOpParameters, tableSize);
  4374. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4375. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4376. std::vector<float> *Validation_Input1 =
  4377. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4378. std::vector<float> *Validation_Input2 =
  4379. &(handler.GetTableParamByName(L"Validation.Input2")->m_floatTable);
  4380. std::vector<float> *Validation_Input3 =
  4381. &(handler.GetTableParamByName(L"Validation.Input3")->m_floatTable);
  4382. std::vector<float> *Validation_Expected =
  4383. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4384. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4385. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4386. size_t count = Validation_Input1->size();
  4387. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4388. pDevice, m_support, pStream, "TertiaryFPOp",
  4389. // this callbacked is called when the test
  4390. // is creating the resource to run the test
  4391. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4392. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  4393. size_t size = sizeof(STertiaryFPOp) * count;
  4394. Data.resize(size);
  4395. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)Data.data();
  4396. for (size_t i = 0; i < count; ++i) {
  4397. STertiaryFPOp *p = &pPrimitives[i];
  4398. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4399. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4400. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4401. }
  4402. // use shader from data table
  4403. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4404. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4405. });
  4406. MappedData data;
  4407. test->Test->GetReadBackData("STertiaryFPOp", &data);
  4408. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)data.data();
  4409. WEX::TestExecution::DisableVerifyExceptions dve;
  4410. for (unsigned i = 0; i < count; ++i) {
  4411. STertiaryFPOp *p = &pPrimitives[i];
  4412. float val = (*Validation_Expected)[i % Validation_Expected->size()];
  4413. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output1 = "
  4414. L"%6.8f, expected = %6.8f",
  4415. i, p->input1, p->input2, p->input3, p->output, val);
  4416. VerifyOutputWithExpectedValueFloat(p->output, val, Validation_Type,
  4417. Validation_Tolerance);
  4418. }
  4419. }
  4420. TEST_F(ExecutionTest, UnaryHalfOpTest) {
  4421. WEX::TestExecution::SetVerifyOutput verifySettings(
  4422. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4423. CComPtr<IStream> pStream;
  4424. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4425. CComPtr<ID3D12Device> pDevice;
  4426. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4427. return;
  4428. }
  4429. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4430. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4431. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4432. return;
  4433. }
  4434. // Read data from the table
  4435. int tableSize = sizeof(UnaryHalfOpParameters) / sizeof(TableParameter);
  4436. TableParameterHandler handler(UnaryHalfOpParameters, tableSize);
  4437. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4438. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4439. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4440. unsigned int WarpVersion = handler.GetTableParamByName(L"Warp.Version")->m_uint;
  4441. if (GetTestParamUseWARP(true) && !IsValidWarpDllVersion(WarpVersion)) {
  4442. return;
  4443. }
  4444. std::vector<uint16_t> *Validation_Input =
  4445. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4446. std::vector<uint16_t> *Validation_Expected =
  4447. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4448. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4449. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4450. size_t count = Validation_Input->size();
  4451. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4452. pDevice, m_support, pStream, "UnaryFPOp",
  4453. // this callbacked is called when the test
  4454. // is creating the resource to run the test
  4455. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4456. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryFPOp"));
  4457. size_t size = sizeof(SUnaryHalfOp) * count;
  4458. Data.resize(size);
  4459. SUnaryHalfOp *pPrimitives = (SUnaryHalfOp *)Data.data();
  4460. for (size_t i = 0; i < count; ++i) {
  4461. SUnaryHalfOp *p = &pPrimitives[i];
  4462. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4463. }
  4464. // use shader from data table
  4465. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4466. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4467. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4468. });
  4469. MappedData data;
  4470. test->Test->GetReadBackData("SUnaryFPOp", &data);
  4471. SUnaryHalfOp *pPrimitives = (SUnaryHalfOp*)data.data();
  4472. WEX::TestExecution::DisableVerifyExceptions dve;
  4473. for (unsigned i = 0; i < count; ++i) {
  4474. SUnaryHalfOp *p = &pPrimitives[i];
  4475. uint16_t expected = (*Validation_Expected)[i % Validation_Input->size()];
  4476. LogCommentFmt(L"element #%u, input = %6.8f(0x%04x), output = "
  4477. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4478. i, ConvertFloat16ToFloat32(p->input), p->input,
  4479. ConvertFloat16ToFloat32(p->output), p->output,
  4480. ConvertFloat16ToFloat32(expected), expected);
  4481. VerifyOutputWithExpectedValueHalf(p->output, expected, Validation_Type, Validation_Tolerance);
  4482. }
  4483. }
  4484. TEST_F(ExecutionTest, BinaryHalfOpTest) {
  4485. WEX::TestExecution::SetVerifyOutput verifySettings(
  4486. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4487. CComPtr<IStream> pStream;
  4488. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4489. CComPtr<ID3D12Device> pDevice;
  4490. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4491. return;
  4492. }
  4493. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4494. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4495. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4496. return;
  4497. }
  4498. // Read data from the table
  4499. int tableSize = sizeof(BinaryHalfOpParameters) / sizeof(TableParameter);
  4500. TableParameterHandler handler(BinaryHalfOpParameters, tableSize);
  4501. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4502. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4503. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4504. std::vector<uint16_t> *Validation_Input1 =
  4505. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4506. std::vector<uint16_t> *Validation_Input2 =
  4507. &(handler.GetTableParamByName(L"Validation.Input2")->m_halfTable);
  4508. std::vector<uint16_t> *Validation_Expected1 =
  4509. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4510. std::vector<uint16_t> *Validation_Expected2 =
  4511. &(handler.GetTableParamByName(L"Validation.Expected2")->m_halfTable);
  4512. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4513. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4514. size_t count = Validation_Input1->size();
  4515. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4516. pDevice, m_support, pStream, "BinaryFPOp",
  4517. // this callbacked is called when the test
  4518. // is creating the resource to run the test
  4519. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4520. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  4521. size_t size = sizeof(SBinaryHalfOp) * count;
  4522. Data.resize(size);
  4523. SBinaryHalfOp *pPrimitives = (SBinaryHalfOp *)Data.data();
  4524. for (size_t i = 0; i < count; ++i) {
  4525. SBinaryHalfOp *p = &pPrimitives[i];
  4526. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4527. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4528. }
  4529. // use shader from data table
  4530. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4531. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4532. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4533. });
  4534. MappedData data;
  4535. test->Test->GetReadBackData("SBinaryFPOp", &data);
  4536. SBinaryHalfOp *pPrimitives = (SBinaryHalfOp *)data.data();
  4537. WEX::TestExecution::DisableVerifyExceptions dve;
  4538. unsigned numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4539. if (numExpected == 2) {
  4540. for (unsigned i = 0; i < count; ++i) {
  4541. SBinaryHalfOp *p = &pPrimitives[i];
  4542. uint16_t expected1 = (*Validation_Expected1)[i % Validation_Input1->size()];
  4543. uint16_t expected2 = (*Validation_Expected2)[i % Validation_Input2->size()];
  4544. LogCommentFmt(L"element #%u, input1 = %6.8f(0x%04x), input2 = %6.8f(0x%04x), output1 = "
  4545. L"%6.8f(0x%04x), expected1 = %6.8f(0x%04x), output2 = %6.8f(0x%04x), expected2 = %6.8f(0x%04x)",
  4546. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4547. ConvertFloat16ToFloat32(p->input2), p->input2,
  4548. ConvertFloat16ToFloat32(p->output1), p->output1,
  4549. ConvertFloat16ToFloat32(p->output2), p->output2,
  4550. ConvertFloat16ToFloat32(expected1), expected1,
  4551. ConvertFloat16ToFloat32(expected2), expected2);
  4552. VerifyOutputWithExpectedValueHalf(p->output1, expected1, Validation_Type, Validation_Tolerance);
  4553. VerifyOutputWithExpectedValueHalf(p->output2, expected2, Validation_Type, Validation_Tolerance);
  4554. }
  4555. }
  4556. else if (numExpected == 1) {
  4557. for (unsigned i = 0; i < count; ++i) {
  4558. uint16_t expected = (*Validation_Expected1)[i % Validation_Input1->size()];
  4559. SBinaryHalfOp *p = &pPrimitives[i];
  4560. LogCommentFmt(L"element #%u, input = %6.8f(0x%04x), output = "
  4561. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4562. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4563. ConvertFloat16ToFloat32(p->output1), p->output1,
  4564. ConvertFloat16ToFloat32(expected), expected);
  4565. VerifyOutputWithExpectedValueHalf(p->output1, expected, Validation_Type, Validation_Tolerance);
  4566. }
  4567. }
  4568. else {
  4569. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4570. }
  4571. }
  4572. TEST_F(ExecutionTest, TertiaryHalfOpTest) {
  4573. WEX::TestExecution::SetVerifyOutput verifySettings(
  4574. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4575. CComPtr<IStream> pStream;
  4576. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4577. CComPtr<ID3D12Device> pDevice;
  4578. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4579. return;
  4580. }
  4581. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4582. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4583. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4584. return;
  4585. }
  4586. // Read data from the table
  4587. int tableSize = sizeof(TertiaryHalfOpParameters) / sizeof(TableParameter);
  4588. TableParameterHandler handler(TertiaryHalfOpParameters, tableSize);
  4589. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4590. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4591. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4592. std::vector<uint16_t> *Validation_Input1 =
  4593. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4594. std::vector<uint16_t> *Validation_Input2 =
  4595. &(handler.GetTableParamByName(L"Validation.Input2")->m_halfTable);
  4596. std::vector<uint16_t> *Validation_Input3 =
  4597. &(handler.GetTableParamByName(L"Validation.Input3")->m_halfTable);
  4598. std::vector<uint16_t> *Validation_Expected =
  4599. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4600. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4601. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4602. size_t count = Validation_Input1->size();
  4603. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4604. pDevice, m_support, pStream, "TertiaryFPOp",
  4605. // this callbacked is called when the test
  4606. // is creating the resource to run the test
  4607. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4608. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  4609. size_t size = sizeof(STertiaryHalfOp) * count;
  4610. Data.resize(size);
  4611. STertiaryHalfOp *pPrimitives = (STertiaryHalfOp *)Data.data();
  4612. for (size_t i = 0; i < count; ++i) {
  4613. STertiaryHalfOp *p = &pPrimitives[i];
  4614. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4615. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4616. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4617. }
  4618. // use shader from data table
  4619. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4620. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4621. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4622. });
  4623. MappedData data;
  4624. test->Test->GetReadBackData("STertiaryFPOp", &data);
  4625. STertiaryHalfOp *pPrimitives = (STertiaryHalfOp *)data.data();
  4626. WEX::TestExecution::DisableVerifyExceptions dve;
  4627. for (unsigned i = 0; i < count; ++i) {
  4628. STertiaryHalfOp *p = &pPrimitives[i];
  4629. uint16_t expected = (*Validation_Expected)[i % Validation_Expected->size()];
  4630. LogCommentFmt(L"element #%u, input1 = %6.8f(0x%04x), input2 = %6.8f(0x%04x), input3 = %6.8f(0x%04x), output = "
  4631. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4632. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4633. ConvertFloat16ToFloat32(p->input2), p->input2,
  4634. ConvertFloat16ToFloat32(p->input3), p->input3,
  4635. ConvertFloat16ToFloat32(p->output), p->output,
  4636. ConvertFloat16ToFloat32(expected), expected);
  4637. VerifyOutputWithExpectedValueHalf(p->output, expected, Validation_Type, Validation_Tolerance);
  4638. }
  4639. }
  4640. TEST_F(ExecutionTest, UnaryIntOpTest) {
  4641. WEX::TestExecution::SetVerifyOutput verifySettings(
  4642. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4643. CComPtr<IStream> pStream;
  4644. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4645. CComPtr<ID3D12Device> pDevice;
  4646. if (!CreateDevice(&pDevice)) {
  4647. return;
  4648. }
  4649. // Read data from the table
  4650. int tableSize = sizeof(UnaryIntOpParameters) / sizeof(TableParameter);
  4651. TableParameterHandler handler(UnaryIntOpParameters, tableSize);
  4652. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4653. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4654. std::vector<int> *Validation_Input =
  4655. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4656. std::vector<int> *Validation_Expected =
  4657. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4658. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4659. size_t count = Validation_Input->size();
  4660. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4661. pDevice, m_support, pStream, "UnaryIntOp",
  4662. // this callbacked is called when the test
  4663. // is creating the resource to run the test
  4664. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4665. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryIntOp"));
  4666. size_t size = sizeof(SUnaryIntOp) * count;
  4667. Data.resize(size);
  4668. SUnaryIntOp *pPrimitives = (SUnaryIntOp *)Data.data();
  4669. for (size_t i = 0; i < count; ++i) {
  4670. SUnaryIntOp *p = &pPrimitives[i];
  4671. int val = (*Validation_Input)[i % Validation_Input->size()];
  4672. p->input = val;
  4673. }
  4674. // use shader data table
  4675. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4676. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4677. });
  4678. MappedData data;
  4679. test->Test->GetReadBackData("SUnaryIntOp", &data);
  4680. SUnaryIntOp *pPrimitives = (SUnaryIntOp *)data.data();
  4681. WEX::TestExecution::DisableVerifyExceptions dve;
  4682. for (unsigned i = 0; i < count; ++i) {
  4683. SUnaryIntOp *p = &pPrimitives[i];
  4684. int val = (*Validation_Expected)[i % Validation_Expected->size()];
  4685. LogCommentFmt(L"element #%u, input = %11i(0x%08x), output = %11i(0x%08x), "
  4686. L"expected = %11i(0x%08x)",
  4687. i, p->input, p->input, p->output, p->output, val, val);
  4688. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4689. }
  4690. }
  4691. TEST_F(ExecutionTest, UnaryUintOpTest) {
  4692. WEX::TestExecution::SetVerifyOutput verifySettings(
  4693. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4694. CComPtr<IStream> pStream;
  4695. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4696. CComPtr<ID3D12Device> pDevice;
  4697. if (!CreateDevice(&pDevice)) {
  4698. return;
  4699. }
  4700. // Read data from the table
  4701. int tableSize = sizeof(UnaryUintOpParameters) / sizeof(TableParameter);
  4702. TableParameterHandler handler(UnaryUintOpParameters, tableSize);
  4703. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4704. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4705. std::vector<unsigned int> *Validation_Input =
  4706. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4707. std::vector<unsigned int> *Validation_Expected =
  4708. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4709. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4710. size_t count = Validation_Input->size();
  4711. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4712. pDevice, m_support, pStream, "UnaryUintOp",
  4713. // this callbacked is called when the test
  4714. // is creating the resource to run the test
  4715. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4716. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryUintOp"));
  4717. size_t size = sizeof(SUnaryUintOp) * count;
  4718. Data.resize(size);
  4719. SUnaryUintOp *pPrimitives = (SUnaryUintOp *)Data.data();
  4720. for (size_t i = 0; i < count; ++i) {
  4721. SUnaryUintOp *p = &pPrimitives[i];
  4722. unsigned int val = (*Validation_Input)[i % Validation_Input->size()];
  4723. p->input = val;
  4724. }
  4725. // use shader data table
  4726. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4727. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4728. });
  4729. MappedData data;
  4730. test->Test->GetReadBackData("SUnaryUintOp", &data);
  4731. SUnaryUintOp *pPrimitives = (SUnaryUintOp *)data.data();
  4732. WEX::TestExecution::DisableVerifyExceptions dve;
  4733. for (unsigned i = 0; i < count; ++i) {
  4734. SUnaryUintOp *p = &pPrimitives[i];
  4735. unsigned int val = (*Validation_Expected)[i % Validation_Expected->size()];
  4736. LogCommentFmt(L"element #%u, input = %11u(0x%08x), output = %11u(0x%08x), "
  4737. L"expected = %11u(0x%08x)",
  4738. i, p->input, p->input, p->output, p->output, val, val);
  4739. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4740. }
  4741. }
  4742. TEST_F(ExecutionTest, BinaryIntOpTest) {
  4743. WEX::TestExecution::SetVerifyOutput verifySettings(
  4744. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4745. CComPtr<IStream> pStream;
  4746. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4747. CComPtr<ID3D12Device> pDevice;
  4748. if (!CreateDevice(&pDevice)) {
  4749. return;
  4750. }
  4751. // Read data from the table
  4752. size_t tableSize = sizeof(BinaryIntOpParameters) / sizeof(TableParameter);
  4753. TableParameterHandler handler(BinaryIntOpParameters, tableSize);
  4754. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4755. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4756. std::vector<int> *Validation_Input1 =
  4757. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4758. std::vector<int> *Validation_Input2 =
  4759. &handler.GetTableParamByName(L"Validation.Input2")->m_int32Table;
  4760. std::vector<int> *Validation_Expected1 =
  4761. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4762. std::vector<int> *Validation_Expected2 =
  4763. &handler.GetTableParamByName(L"Validation.Expected2")->m_int32Table;
  4764. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4765. size_t count = Validation_Input1->size();
  4766. size_t numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4767. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4768. pDevice, m_support, pStream, "BinaryIntOp",
  4769. // this callbacked is called when the test
  4770. // is creating the resource to run the test
  4771. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4772. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryIntOp"));
  4773. size_t size = sizeof(SBinaryIntOp) * count;
  4774. Data.resize(size);
  4775. SBinaryIntOp *pPrimitives = (SBinaryIntOp *)Data.data();
  4776. for (size_t i = 0; i < count; ++i) {
  4777. SBinaryIntOp *p = &pPrimitives[i];
  4778. int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4779. int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4780. p->input1 = val1;
  4781. p->input2 = val2;
  4782. }
  4783. // use shader from data table
  4784. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4785. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4786. });
  4787. MappedData data;
  4788. test->Test->GetReadBackData("SBinaryIntOp", &data);
  4789. SBinaryIntOp *pPrimitives = (SBinaryIntOp *)data.data();
  4790. WEX::TestExecution::DisableVerifyExceptions dve;
  4791. if (numExpected == 2) {
  4792. for (unsigned i = 0; i < count; ++i) {
  4793. SBinaryIntOp *p = &pPrimitives[i];
  4794. int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4795. int val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4796. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4797. L"%11i(0x%08x), output1 = "
  4798. L"%11i(0x%08x), expected1 = %11i(0x%08x), output2 = "
  4799. L"%11i(0x%08x), expected2 = %11i(0x%08x)",
  4800. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  4801. p->output1, val1, val1, p->output2, p->output2, val2,
  4802. val2);
  4803. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4804. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  4805. }
  4806. }
  4807. else if (numExpected == 1) {
  4808. for (unsigned i = 0; i < count; ++i) {
  4809. SBinaryIntOp *p = &pPrimitives[i];
  4810. int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4811. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4812. L"%11i(0x%08x), output = "
  4813. L"%11i(0x%08x), expected = %11i(0x%08x)", i,
  4814. p->input1, p->input1, p->input2, p->input2,
  4815. p->output1, p->output1, val1, val1);
  4816. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4817. }
  4818. }
  4819. else {
  4820. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4821. }
  4822. }
  4823. TEST_F(ExecutionTest, TertiaryIntOpTest) {
  4824. WEX::TestExecution::SetVerifyOutput verifySettings(
  4825. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4826. CComPtr<IStream> pStream;
  4827. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4828. CComPtr<ID3D12Device> pDevice;
  4829. if (!CreateDevice(&pDevice)) {
  4830. return;
  4831. }
  4832. // Read data from the table
  4833. size_t tableSize = sizeof(TertiaryIntOpParameters) / sizeof(TableParameter);
  4834. TableParameterHandler handler(TertiaryIntOpParameters, tableSize);
  4835. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4836. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4837. std::vector<int> *Validation_Input1 =
  4838. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4839. std::vector<int> *Validation_Input2 =
  4840. &handler.GetTableParamByName(L"Validation.Input2")->m_int32Table;
  4841. std::vector<int> *Validation_Input3 =
  4842. &handler.GetTableParamByName(L"Validation.Input3")->m_int32Table;
  4843. std::vector<int> *Validation_Expected =
  4844. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4845. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4846. size_t count = Validation_Input1->size();
  4847. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4848. pDevice, m_support, pStream, "TertiaryIntOp",
  4849. // this callbacked is called when the test
  4850. // is creating the resource to run the test
  4851. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4852. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryIntOp"));
  4853. size_t size = sizeof(STertiaryIntOp) * count;
  4854. Data.resize(size);
  4855. STertiaryIntOp *pPrimitives = (STertiaryIntOp *)Data.data();
  4856. for (size_t i = 0; i < count; ++i) {
  4857. STertiaryIntOp *p = &pPrimitives[i];
  4858. int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4859. int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4860. int val3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4861. p->input1 = val1;
  4862. p->input2 = val2;
  4863. p->input3 = val3;
  4864. }
  4865. // use shader from data table
  4866. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4867. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4868. });
  4869. MappedData data;
  4870. test->Test->GetReadBackData("STertiaryIntOp", &data);
  4871. STertiaryIntOp *pPrimitives = (STertiaryIntOp *)data.data();
  4872. WEX::TestExecution::DisableVerifyExceptions dve;
  4873. for (unsigned i = 0; i < count; ++i) {
  4874. STertiaryIntOp *p = &pPrimitives[i];
  4875. int val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  4876. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4877. L"%11i(0x%08x), input3= %11i(0x%08x), output = "
  4878. L"%11i(0x%08x), expected = %11i(0x%08x)",
  4879. i, p->input1, p->input1, p->input2, p->input2,
  4880. p->input3, p->input3, p->output, p->output, val1,
  4881. val1);
  4882. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  4883. }
  4884. }
  4885. TEST_F(ExecutionTest, BinaryUintOpTest) {
  4886. WEX::TestExecution::SetVerifyOutput verifySettings(
  4887. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4888. CComPtr<IStream> pStream;
  4889. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4890. CComPtr<ID3D12Device> pDevice;
  4891. if (!CreateDevice(&pDevice)) {
  4892. return;
  4893. }
  4894. // Read data from the table
  4895. size_t tableSize = sizeof(BinaryUintOpParameters) / sizeof(TableParameter);
  4896. TableParameterHandler handler(BinaryUintOpParameters, tableSize);
  4897. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4898. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4899. std::vector<unsigned int> *Validation_Input1 =
  4900. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4901. std::vector<unsigned int> *Validation_Input2 =
  4902. &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  4903. std::vector<unsigned int> *Validation_Expected1 =
  4904. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4905. std::vector<unsigned int> *Validation_Expected2 =
  4906. &handler.GetTableParamByName(L"Validation.Expected2")->m_uint32Table;
  4907. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4908. size_t count = Validation_Input1->size();
  4909. int numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4910. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4911. pDevice, m_support, pStream, "BinaryUintOp",
  4912. // this callbacked is called when the test
  4913. // is creating the resource to run the test
  4914. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4915. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryUintOp"));
  4916. size_t size = sizeof(SBinaryUintOp) * count;
  4917. Data.resize(size);
  4918. SBinaryUintOp *pPrimitives = (SBinaryUintOp *)Data.data();
  4919. for (size_t i = 0; i < count; ++i) {
  4920. SBinaryUintOp *p = &pPrimitives[i];
  4921. unsigned int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4922. unsigned int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4923. p->input1 = val1;
  4924. p->input2 = val2;
  4925. }
  4926. // use shader from data table
  4927. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4928. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4929. });
  4930. MappedData data;
  4931. test->Test->GetReadBackData("SBinaryUintOp", &data);
  4932. SBinaryUintOp *pPrimitives = (SBinaryUintOp *)data.data();
  4933. WEX::TestExecution::DisableVerifyExceptions dve;
  4934. if (numExpected == 2) {
  4935. for (unsigned i = 0; i < count; ++i) {
  4936. SBinaryUintOp *p = &pPrimitives[i];
  4937. unsigned int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4938. unsigned int val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4939. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4940. L"%11u(0x%08x), output1 = "
  4941. L"%11u(0x%08x), expected1 = %11u(0x%08x), output2 = "
  4942. L"%11u(0x%08x), expected2 = %11u(0x%08x)",
  4943. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  4944. p->output1, val1, val1, p->output2, p->output2, val2,
  4945. val2);
  4946. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4947. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  4948. }
  4949. }
  4950. else if (numExpected == 1) {
  4951. for (unsigned i = 0; i < count; ++i) {
  4952. SBinaryUintOp *p = &pPrimitives[i];
  4953. unsigned int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4954. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4955. L"%11u(0x%08x), output = "
  4956. L"%11u(0x%08x), expected = %11u(0x%08x)", i,
  4957. p->input1, p->input1, p->input2, p->input2,
  4958. p->output1, p->output1, val1, val1);
  4959. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4960. }
  4961. }
  4962. else {
  4963. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4964. }
  4965. }
  4966. TEST_F(ExecutionTest, TertiaryUintOpTest) {
  4967. WEX::TestExecution::SetVerifyOutput verifySettings(
  4968. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4969. CComPtr<IStream> pStream;
  4970. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4971. CComPtr<ID3D12Device> pDevice;
  4972. if (!CreateDevice(&pDevice)) {
  4973. return;
  4974. }
  4975. // Read data from the table
  4976. size_t tableSize = sizeof(TertiaryUintOpParameters) / sizeof(TableParameter);
  4977. TableParameterHandler handler(TertiaryUintOpParameters, tableSize);
  4978. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4979. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4980. std::vector<unsigned int> *Validation_Input1 =
  4981. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4982. std::vector<unsigned int> *Validation_Input2 =
  4983. &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  4984. std::vector<unsigned int> *Validation_Input3 =
  4985. &handler.GetTableParamByName(L"Validation.Input3")->m_uint32Table;
  4986. std::vector<unsigned int> *Validation_Expected =
  4987. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4988. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4989. size_t count = Validation_Input1->size();
  4990. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4991. pDevice, m_support, pStream, "TertiaryUintOp",
  4992. // this callbacked is called when the test
  4993. // is creating the resource to run the test
  4994. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4995. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryUintOp"));
  4996. size_t size = sizeof(STertiaryUintOp) * count;
  4997. Data.resize(size);
  4998. STertiaryUintOp *pPrimitives = (STertiaryUintOp *)Data.data();
  4999. for (size_t i = 0; i < count; ++i) {
  5000. STertiaryUintOp *p = &pPrimitives[i];
  5001. unsigned int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5002. unsigned int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5003. unsigned int val3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5004. p->input1 = val1;
  5005. p->input2 = val2;
  5006. p->input3 = val3;
  5007. }
  5008. // use shader from data table
  5009. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5010. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5011. });
  5012. MappedData data;
  5013. test->Test->GetReadBackData("STertiaryUintOp", &data);
  5014. STertiaryUintOp *pPrimitives = (STertiaryUintOp *)data.data();
  5015. WEX::TestExecution::DisableVerifyExceptions dve;
  5016. for (unsigned i = 0; i < count; ++i) {
  5017. STertiaryUintOp *p = &pPrimitives[i];
  5018. unsigned int val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  5019. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  5020. L"%11u(0x%08x), input3 = %11u(0x%08x), output = "
  5021. L"%11u(0x%08x), expected = %11u(0x%08x)", i,
  5022. p->input1, p->input1, p->input2, p->input2, p->input3, p->input3,
  5023. p->output, p->output, val1, val1);
  5024. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  5025. }
  5026. }
  5027. // 16 bit integer type tests
  5028. TEST_F(ExecutionTest, UnaryInt16OpTest) {
  5029. WEX::TestExecution::SetVerifyOutput verifySettings(
  5030. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5031. CComPtr<IStream> pStream;
  5032. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5033. CComPtr<ID3D12Device> pDevice;
  5034. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5035. return;
  5036. }
  5037. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5038. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5039. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5040. return;
  5041. }
  5042. // Read data from the table
  5043. int tableSize = sizeof(UnaryInt16OpParameters) / sizeof(TableParameter);
  5044. TableParameterHandler handler(UnaryInt16OpParameters, tableSize);
  5045. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5046. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5047. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5048. std::vector<short> *Validation_Input =
  5049. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  5050. std::vector<short> *Validation_Expected =
  5051. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  5052. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5053. size_t count = Validation_Input->size();
  5054. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5055. pDevice, m_support, pStream, "UnaryIntOp",
  5056. // this callbacked is called when the test
  5057. // is creating the resource to run the test
  5058. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5059. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryIntOp"));
  5060. size_t size = sizeof(SUnaryInt16Op) * count;
  5061. Data.resize(size);
  5062. SUnaryInt16Op *pPrimitives = (SUnaryInt16Op *)Data.data();
  5063. for (size_t i = 0; i < count; ++i) {
  5064. SUnaryInt16Op *p = &pPrimitives[i];
  5065. p->input = (*Validation_Input)[i % Validation_Input->size()];
  5066. }
  5067. // use shader data table
  5068. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5069. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5070. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5071. });
  5072. MappedData data;
  5073. test->Test->GetReadBackData("SUnaryIntOp", &data);
  5074. SUnaryInt16Op *pPrimitives = (SUnaryInt16Op *)data.data();
  5075. WEX::TestExecution::DisableVerifyExceptions dve;
  5076. for (unsigned i = 0; i < count; ++i) {
  5077. SUnaryInt16Op *p = &pPrimitives[i];
  5078. short val = (*Validation_Expected)[i % Validation_Expected->size()];
  5079. LogCommentFmt(L"element #%u, input = %5hi(0x%08x), output = %5hi(0x%08x), "
  5080. L"expected = %5hi(0x%08x)",
  5081. i, p->input, p->input, p->output, p->output, val, val);
  5082. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  5083. }
  5084. }
  5085. TEST_F(ExecutionTest, UnaryUint16OpTest) {
  5086. WEX::TestExecution::SetVerifyOutput verifySettings(
  5087. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5088. CComPtr<IStream> pStream;
  5089. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5090. CComPtr<ID3D12Device> pDevice;
  5091. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5092. return;
  5093. }
  5094. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5095. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5096. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5097. return;
  5098. }
  5099. // Read data from the table
  5100. int tableSize = sizeof(UnaryUint16OpParameters) / sizeof(TableParameter);
  5101. TableParameterHandler handler(UnaryUint16OpParameters, tableSize);
  5102. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5103. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5104. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5105. std::vector<unsigned short> *Validation_Input =
  5106. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5107. std::vector<unsigned short> *Validation_Expected =
  5108. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5109. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5110. size_t count = Validation_Input->size();
  5111. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5112. pDevice, m_support, pStream, "UnaryUintOp",
  5113. // this callbacked is called when the test
  5114. // is creating the resource to run the test
  5115. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5116. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryUintOp"));
  5117. size_t size = sizeof(SUnaryUint16Op) * count;
  5118. Data.resize(size);
  5119. SUnaryUint16Op *pPrimitives = (SUnaryUint16Op *)Data.data();
  5120. for (size_t i = 0; i < count; ++i) {
  5121. SUnaryUint16Op *p = &pPrimitives[i];
  5122. p->input = (*Validation_Input)[i % Validation_Input->size()];
  5123. }
  5124. // use shader data table
  5125. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5126. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5127. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5128. });
  5129. MappedData data;
  5130. test->Test->GetReadBackData("SUnaryUintOp", &data);
  5131. SUnaryUint16Op *pPrimitives = (SUnaryUint16Op *)data.data();
  5132. WEX::TestExecution::DisableVerifyExceptions dve;
  5133. for (unsigned i = 0; i < count; ++i) {
  5134. SUnaryUint16Op *p = &pPrimitives[i];
  5135. unsigned short val = (*Validation_Expected)[i % Validation_Expected->size()];
  5136. LogCommentFmt(L"element #%u, input = %5hu(0x%08x), output = %5hu(0x%08x), "
  5137. L"expected = %5hu(0x%08x)",
  5138. i, p->input, p->input, p->output, p->output, val, val);
  5139. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  5140. }
  5141. }
  5142. TEST_F(ExecutionTest, BinaryInt16OpTest) {
  5143. WEX::TestExecution::SetVerifyOutput verifySettings(
  5144. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5145. CComPtr<IStream> pStream;
  5146. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5147. CComPtr<ID3D12Device> pDevice;
  5148. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5149. return;
  5150. }
  5151. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5152. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5153. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5154. return;
  5155. }
  5156. // Read data from the table
  5157. size_t tableSize = sizeof(BinaryInt16OpParameters) / sizeof(TableParameter);
  5158. TableParameterHandler handler(BinaryInt16OpParameters, tableSize);
  5159. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5160. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5161. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5162. std::vector<short> *Validation_Input1 =
  5163. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  5164. std::vector<short> *Validation_Input2 =
  5165. &handler.GetTableParamByName(L"Validation.Input2")->m_int16Table;
  5166. std::vector<short> *Validation_Expected1 =
  5167. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  5168. std::vector<short> *Validation_Expected2 =
  5169. &handler.GetTableParamByName(L"Validation.Expected2")->m_int16Table;
  5170. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5171. size_t count = Validation_Input1->size();
  5172. size_t numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  5173. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5174. pDevice, m_support, pStream, "BinaryIntOp",
  5175. // this callbacked is called when the test
  5176. // is creating the resource to run the test
  5177. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5178. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryIntOp"));
  5179. size_t size = sizeof(SBinaryInt16Op) * count;
  5180. Data.resize(size);
  5181. SBinaryInt16Op *pPrimitives = (SBinaryInt16Op *)Data.data();
  5182. for (size_t i = 0; i < count; ++i) {
  5183. SBinaryInt16Op *p = &pPrimitives[i];
  5184. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5185. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5186. }
  5187. // use shader from data table
  5188. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5189. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5190. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5191. });
  5192. MappedData data;
  5193. test->Test->GetReadBackData("SBinaryIntOp", &data);
  5194. SBinaryInt16Op *pPrimitives = (SBinaryInt16Op *)data.data();
  5195. WEX::TestExecution::DisableVerifyExceptions dve;
  5196. if (numExpected == 2) {
  5197. for (unsigned i = 0; i < count; ++i) {
  5198. SBinaryInt16Op *p = &pPrimitives[i];
  5199. short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5200. short val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5201. LogCommentFmt(L"element #%u, input1 = %5hi(0x%08x), input2 = "
  5202. L"%5hi(0x%08x), output1 = "
  5203. L"%5hi(0x%08x), expected1 = %5hi(0x%08x), output2 = "
  5204. L"%5hi(0x%08x), expected2 = %5hi(0x%08x)",
  5205. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  5206. p->output1, val1, val1, p->output2, p->output2, val2,
  5207. val2);
  5208. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5209. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  5210. }
  5211. }
  5212. else if (numExpected == 1) {
  5213. for (unsigned i = 0; i < count; ++i) {
  5214. SBinaryInt16Op *p = &pPrimitives[i];
  5215. short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5216. LogCommentFmt(L"element #%u, input1 = %5hi(0x%08x), input2 = "
  5217. L"%5hi(0x%08x), output = "
  5218. L"%5hi(0x%08x), expected = %5hi(0x%08x)", i,
  5219. p->input1, p->input1, p->input2, p->input2,
  5220. p->output1, p->output1, val1, val1);
  5221. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5222. }
  5223. }
  5224. else {
  5225. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  5226. }
  5227. }
  5228. TEST_F(ExecutionTest, TertiaryInt16OpTest) {
  5229. WEX::TestExecution::SetVerifyOutput verifySettings(
  5230. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5231. CComPtr<IStream> pStream;
  5232. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5233. CComPtr<ID3D12Device> pDevice;
  5234. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5235. return;
  5236. }
  5237. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5238. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5239. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5240. return;
  5241. }
  5242. // Read data from the table
  5243. size_t tableSize = sizeof(TertiaryInt16OpParameters) / sizeof(TableParameter);
  5244. TableParameterHandler handler(TertiaryInt16OpParameters, tableSize);
  5245. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5246. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5247. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5248. std::vector<short> *Validation_Input1 =
  5249. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  5250. std::vector<short> *Validation_Input2 =
  5251. &handler.GetTableParamByName(L"Validation.Input2")->m_int16Table;
  5252. std::vector<short> *Validation_Input3 =
  5253. &handler.GetTableParamByName(L"Validation.Input3")->m_int16Table;
  5254. std::vector<short> *Validation_Expected =
  5255. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  5256. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5257. size_t count = Validation_Input1->size();
  5258. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5259. pDevice, m_support, pStream, "TertiaryIntOp",
  5260. // this callbacked is called when the test
  5261. // is creating the resource to run the test
  5262. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5263. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryIntOp"));
  5264. size_t size = sizeof(STertiaryInt16Op) * count;
  5265. Data.resize(size);
  5266. STertiaryInt16Op *pPrimitives = (STertiaryInt16Op *)Data.data();
  5267. for (size_t i = 0; i < count; ++i) {
  5268. STertiaryInt16Op *p = &pPrimitives[i];
  5269. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5270. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5271. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5272. }
  5273. // use shader from data table
  5274. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5275. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5276. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5277. });
  5278. MappedData data;
  5279. test->Test->GetReadBackData("STertiaryIntOp", &data);
  5280. STertiaryInt16Op *pPrimitives = (STertiaryInt16Op *)data.data();
  5281. WEX::TestExecution::DisableVerifyExceptions dve;
  5282. for (unsigned i = 0; i < count; ++i) {
  5283. STertiaryInt16Op *p = &pPrimitives[i];
  5284. short val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  5285. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  5286. L"%11i(0x%08x), input3= %11i(0x%08x), output = "
  5287. L"%11i(0x%08x), expected = %11i(0x%08x)",
  5288. i, p->input1, p->input1, p->input2, p->input2,
  5289. p->input3, p->input3, p->output, p->output, val1,
  5290. val1);
  5291. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  5292. }
  5293. }
  5294. TEST_F(ExecutionTest, BinaryUint16OpTest) {
  5295. WEX::TestExecution::SetVerifyOutput verifySettings(
  5296. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5297. CComPtr<IStream> pStream;
  5298. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5299. CComPtr<ID3D12Device> pDevice;
  5300. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5301. return;
  5302. }
  5303. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5304. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5305. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5306. return;
  5307. }
  5308. // Read data from the table
  5309. size_t tableSize = sizeof(BinaryUint16OpParameters) / sizeof(TableParameter);
  5310. TableParameterHandler handler(BinaryUint16OpParameters, tableSize);
  5311. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5312. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5313. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5314. std::vector<unsigned short> *Validation_Input1 =
  5315. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5316. std::vector<unsigned short> *Validation_Input2 =
  5317. &handler.GetTableParamByName(L"Validation.Input2")->m_uint16Table;
  5318. std::vector<unsigned short> *Validation_Expected1 =
  5319. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5320. std::vector<unsigned short> *Validation_Expected2 =
  5321. &handler.GetTableParamByName(L"Validation.Expected2")->m_uint16Table;
  5322. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5323. size_t count = Validation_Input1->size();
  5324. int numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  5325. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5326. pDevice, m_support, pStream, "BinaryUintOp",
  5327. // this callbacked is called when the test
  5328. // is creating the resource to run the test
  5329. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5330. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryUintOp"));
  5331. size_t size = sizeof(SBinaryUint16Op) * count;
  5332. Data.resize(size);
  5333. SBinaryUint16Op *pPrimitives = (SBinaryUint16Op *)Data.data();
  5334. for (size_t i = 0; i < count; ++i) {
  5335. SBinaryUint16Op *p = &pPrimitives[i];
  5336. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5337. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5338. }
  5339. // use shader from data table
  5340. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5341. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5342. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5343. });
  5344. MappedData data;
  5345. test->Test->GetReadBackData("SBinaryUintOp", &data);
  5346. SBinaryUint16Op *pPrimitives = (SBinaryUint16Op *)data.data();
  5347. WEX::TestExecution::DisableVerifyExceptions dve;
  5348. if (numExpected == 2) {
  5349. for (unsigned i = 0; i < count; ++i) {
  5350. SBinaryUint16Op *p = &pPrimitives[i];
  5351. unsigned short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5352. unsigned short val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5353. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5354. L"%5hu(0x%08x), output1 = "
  5355. L"%5hu(0x%08x), expected1 = %5hu(0x%08x), output2 = "
  5356. L"%5hu(0x%08x), expected2 = %5hu(0x%08x)",
  5357. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  5358. p->output1, val1, val1, p->output2, p->output2, val2,
  5359. val2);
  5360. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5361. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  5362. }
  5363. }
  5364. else if (numExpected == 1) {
  5365. for (unsigned i = 0; i < count; ++i) {
  5366. SBinaryUint16Op *p = &pPrimitives[i];
  5367. unsigned short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5368. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5369. L"%5hu(0x%08x), output = "
  5370. L"%5hu(0x%08x), expected = %5hu(0x%08x)", i,
  5371. p->input1, p->input1, p->input2, p->input2,
  5372. p->output1, p->output1, val1, val1);
  5373. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5374. }
  5375. }
  5376. else {
  5377. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  5378. }
  5379. }
  5380. TEST_F(ExecutionTest, TertiaryUint16OpTest) {
  5381. WEX::TestExecution::SetVerifyOutput verifySettings(
  5382. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5383. CComPtr<IStream> pStream;
  5384. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5385. CComPtr<ID3D12Device> pDevice;
  5386. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5387. return;
  5388. }
  5389. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5390. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5391. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5392. return;
  5393. }
  5394. // Read data from the table
  5395. size_t tableSize = sizeof(TertiaryUint16OpParameters) / sizeof(TableParameter);
  5396. TableParameterHandler handler(TertiaryUint16OpParameters, tableSize);
  5397. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5398. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5399. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5400. std::vector<unsigned short> *Validation_Input1 =
  5401. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5402. std::vector<unsigned short> *Validation_Input2 =
  5403. &handler.GetTableParamByName(L"Validation.Input2")->m_uint16Table;
  5404. std::vector<unsigned short> *Validation_Input3 =
  5405. &handler.GetTableParamByName(L"Validation.Input3")->m_uint16Table;
  5406. std::vector<unsigned short> *Validation_Expected =
  5407. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5408. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5409. size_t count = Validation_Input1->size();
  5410. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5411. pDevice, m_support, pStream, "TertiaryUintOp",
  5412. // this callbacked is called when the test
  5413. // is creating the resource to run the test
  5414. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5415. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryUintOp"));
  5416. size_t size = sizeof(STertiaryUint16Op) * count;
  5417. Data.resize(size);
  5418. STertiaryUint16Op *pPrimitives = (STertiaryUint16Op *)Data.data();
  5419. for (size_t i = 0; i < count; ++i) {
  5420. STertiaryUint16Op *p = &pPrimitives[i];
  5421. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5422. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5423. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5424. }
  5425. // use shader from data table
  5426. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5427. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5428. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5429. });
  5430. MappedData data;
  5431. test->Test->GetReadBackData("STertiaryUintOp", &data);
  5432. STertiaryUint16Op *pPrimitives = (STertiaryUint16Op *)data.data();
  5433. WEX::TestExecution::DisableVerifyExceptions dve;
  5434. for (unsigned i = 0; i < count; ++i) {
  5435. STertiaryUint16Op *p = &pPrimitives[i];
  5436. unsigned short val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  5437. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5438. L"%5hu(0x%08x), input3 = %5hu(0x%08x), output = "
  5439. L"%5hu(0x%08x), expected = %5hu(0x%08x)", i,
  5440. p->input1, p->input1, p->input2, p->input2, p->input3, p->input3,
  5441. p->output, p->output, val1, val1);
  5442. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  5443. }
  5444. }
  5445. TEST_F(ExecutionTest, DotTest) {
  5446. WEX::TestExecution::SetVerifyOutput verifySettings(
  5447. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5448. CComPtr<IStream> pStream;
  5449. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5450. CComPtr<ID3D12Device> pDevice;
  5451. if (!CreateDevice(&pDevice)) {
  5452. return;
  5453. }
  5454. int tableSize = sizeof(DotOpParameters) / sizeof(TableParameter);
  5455. TableParameterHandler handler(DotOpParameters, tableSize);
  5456. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5457. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5458. std::vector<WEX::Common::String> *Validation_Input1 =
  5459. &handler.GetTableParamByName(L"Validation.Input1")->m_StringTable;
  5460. std::vector<WEX::Common::String> *Validation_Input2 =
  5461. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5462. std::vector<WEX::Common::String> *Validation_dot2 =
  5463. &handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable;
  5464. std::vector<WEX::Common::String> *Validation_dot3 =
  5465. &handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable;
  5466. std::vector<WEX::Common::String> *Validation_dot4 =
  5467. &handler.GetTableParamByName(L"Validation.Expected3")->m_StringTable;
  5468. PCWSTR Validation_type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5469. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5470. size_t count = Validation_Input1->size();
  5471. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5472. pDevice, m_support, pStream, "DotOp",
  5473. // this callbacked is called when the test
  5474. // is creating the resource to run the test
  5475. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5476. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDotOp"));
  5477. size_t size = sizeof(SDotOp) * count;
  5478. Data.resize(size);
  5479. SDotOp *pPrimitives = (SDotOp*)Data.data();
  5480. for (size_t i = 0; i < count; ++i) {
  5481. SDotOp *p = &pPrimitives[i];
  5482. XMFLOAT4 val1,val2;
  5483. VERIFY_SUCCEEDED(ParseDataToVectorFloat((*Validation_Input1)[i],
  5484. (float *)&val1, 4));
  5485. VERIFY_SUCCEEDED(ParseDataToVectorFloat((*Validation_Input2)[i],
  5486. (float *)&val2, 4));
  5487. p->input1 = val1;
  5488. p->input2 = val2;
  5489. }
  5490. // use shader from data table
  5491. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5492. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5493. });
  5494. MappedData data;
  5495. test->Test->GetReadBackData("SDotOp", &data);
  5496. SDotOp *pPrimitives = (SDotOp*)data.data();
  5497. WEX::TestExecution::DisableVerifyExceptions dve;
  5498. for (size_t i = 0; i < count; ++i) {
  5499. SDotOp *p = &pPrimitives[i];
  5500. float dot2, dot3, dot4;
  5501. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot2)[i], dot2));
  5502. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot3)[i], dot3));
  5503. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot4)[i], dot4));
  5504. LogCommentFmt(
  5505. L"element #%u, input1 = (%f, %f, %f, %f), input2 = (%f, %f, "
  5506. L"%f, %f), \n dot2 = %f, dot2_expected = %f, dot3 = %f, "
  5507. L"dot3_expected = %f, dot4 = %f, dot4_expected = %f",
  5508. i, p->input1.x, p->input1.y, p->input1.z, p->input1.w, p->input2.x,
  5509. p->input2.y, p->input2.z, p->input2.w, p->o_dot2, dot2, p->o_dot3, dot3,
  5510. p->o_dot4, dot4);
  5511. VerifyOutputWithExpectedValueFloat(p->o_dot2, dot2, Validation_type,
  5512. tolerance);
  5513. VerifyOutputWithExpectedValueFloat(p->o_dot3, dot3, Validation_type,
  5514. tolerance);
  5515. VerifyOutputWithExpectedValueFloat(p->o_dot4, dot4, Validation_type,
  5516. tolerance);
  5517. }
  5518. }
  5519. TEST_F(ExecutionTest, Dot2AddHalfTest) {
  5520. WEX::TestExecution::SetVerifyOutput verifySettings(
  5521. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5522. CComPtr<IStream> pStream;
  5523. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5524. CComPtr<ID3D12Device> pDevice;
  5525. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5526. return;
  5527. }
  5528. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5529. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5530. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5531. return;
  5532. }
  5533. int tableSize = sizeof(Dot2AddHalfOpParameters) / sizeof(TableParameter);
  5534. TableParameterHandler handler(Dot2AddHalfOpParameters, tableSize);
  5535. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5536. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5537. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5538. std::vector<WEX::Common::String> *validation_input1 =
  5539. &handler.GetTableParamByName(L"Validation.Input1")->m_StringTable;
  5540. std::vector<WEX::Common::String> *validation_input2 =
  5541. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5542. std::vector<float> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_floatTable;
  5543. std::vector<float> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable;
  5544. PCWSTR Validation_type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5545. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5546. size_t count = validation_input1->size();
  5547. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5548. pDevice, m_support, pStream, "Dot2AddHalfOp",
  5549. // this callback is called when the test
  5550. // is creating the resource to run the test
  5551. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5552. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot2AddHalfOp"));
  5553. size_t size = sizeof(SDot2AddHalfOp) * count;
  5554. Data.resize(size);
  5555. SDot2AddHalfOp *pPrimitives = (SDot2AddHalfOp*)Data.data();
  5556. for (size_t i = 0; i < count; ++i) {
  5557. SDot2AddHalfOp *p = &pPrimitives[i];
  5558. Half2 val1,val2;
  5559. VERIFY_SUCCEEDED(ParseDataToVectorHalf((*validation_input1)[i],
  5560. (uint16_t *)&val1, 2));
  5561. VERIFY_SUCCEEDED(ParseDataToVectorHalf((*validation_input2)[i],
  5562. (uint16_t *)&val2, 2));
  5563. p->input1 = val1;
  5564. p->input2 = val2;
  5565. p->acc = (*validation_acc)[i];
  5566. }
  5567. // use shader from data table
  5568. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5569. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5570. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5571. });
  5572. MappedData data;
  5573. test->Test->GetReadBackData("SDot2AddHalfOp", &data);
  5574. SDot2AddHalfOp *pPrimitives = (SDot2AddHalfOp*)data.data();
  5575. WEX::TestExecution::DisableVerifyExceptions dve;
  5576. for (size_t i = 0; i < count; ++i) {
  5577. SDot2AddHalfOp *p = &pPrimitives[i];
  5578. float expectedResult = (*validation_result)[i];
  5579. float input1x = ConvertFloat16ToFloat32(p->input1.x);
  5580. float input1y = ConvertFloat16ToFloat32(p->input1.y);
  5581. float input2x = ConvertFloat16ToFloat32(p->input2.x);
  5582. float input2y = ConvertFloat16ToFloat32(p->input2.y);
  5583. LogCommentFmt(
  5584. L"element #%u, input1 = (%f, %f), input2 = (%f, %f), acc = %f\n"
  5585. L"result = %f, result_expected = %f",
  5586. i, input1x, input1y, input2x, input2y, p->acc, p->result, expectedResult);
  5587. VerifyOutputWithExpectedValueFloat(p->result, expectedResult, Validation_type, tolerance);
  5588. }
  5589. }
  5590. TEST_F(ExecutionTest, Dot4AddI8PackedTest) {
  5591. WEX::TestExecution::SetVerifyOutput verifySettings(
  5592. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5593. CComPtr<IStream> pStream;
  5594. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5595. CComPtr<ID3D12Device> pDevice;
  5596. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5597. return;
  5598. }
  5599. int tableSize = sizeof(Dot4AddI8PackedOpParameters) / sizeof(TableParameter);
  5600. TableParameterHandler handler(Dot4AddI8PackedOpParameters, tableSize);
  5601. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5602. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5603. std::vector<uint32_t> *validation_input1 = &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5604. std::vector<uint32_t> *validation_input2 = &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  5605. std::vector<int32_t> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_int32Table;
  5606. std::vector<int32_t> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  5607. size_t count = validation_input1->size();
  5608. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5609. pDevice, m_support, pStream, "Dot4AddI8PackedOp",
  5610. // this callback is called when the test
  5611. // is creating the resource to run the test
  5612. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5613. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot4AddI8PackedOp"));
  5614. size_t size = sizeof(SDot4AddI8PackedOp) * count;
  5615. Data.resize(size);
  5616. SDot4AddI8PackedOp *pPrimitives = (SDot4AddI8PackedOp*)Data.data();
  5617. for (size_t i = 0; i < count; ++i) {
  5618. SDot4AddI8PackedOp *p = &pPrimitives[i];
  5619. p->input1 = (*validation_input1)[i];
  5620. p->input2 = (*validation_input2)[i];
  5621. p->acc = (*validation_acc)[i];
  5622. }
  5623. // use shader from data table
  5624. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5625. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5626. });
  5627. MappedData data;
  5628. test->Test->GetReadBackData("SDot4AddI8PackedOp", &data);
  5629. SDot4AddI8PackedOp *pPrimitives = (SDot4AddI8PackedOp*)data.data();
  5630. WEX::TestExecution::DisableVerifyExceptions dve;
  5631. for (size_t i = 0; i < count; ++i) {
  5632. SDot4AddI8PackedOp *p = &pPrimitives[i];
  5633. int32_t expectedResult = (*validation_result)[i];
  5634. LogCommentFmt(
  5635. L"element #%u, input1 = %u, input2 = %u, acc = %d \n"
  5636. L"result = %d, result_expected = %d",
  5637. i, p->input1, p->input2, p->acc, p->result, expectedResult);
  5638. VerifyOutputWithExpectedValueInt(p->result, expectedResult, 0);
  5639. }
  5640. }
  5641. TEST_F(ExecutionTest, Dot4AddU8PackedTest) {
  5642. WEX::TestExecution::SetVerifyOutput verifySettings(
  5643. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5644. CComPtr<IStream> pStream;
  5645. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5646. CComPtr<ID3D12Device> pDevice;
  5647. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5648. return;
  5649. }
  5650. int tableSize = sizeof(Dot4AddU8PackedOpParameters) / sizeof(TableParameter);
  5651. TableParameterHandler handler(Dot4AddU8PackedOpParameters, tableSize);
  5652. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5653. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5654. std::vector<uint32_t> *validation_input1 = &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5655. std::vector<uint32_t> *validation_input2 = &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  5656. std::vector<uint32_t> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_uint32Table;
  5657. std::vector<uint32_t> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  5658. size_t count = validation_input1->size();
  5659. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5660. pDevice, m_support, pStream, "Dot4AddU8PackedOp",
  5661. // this callback is called when the test
  5662. // is creating the resource to run the test
  5663. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5664. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot4AddU8PackedOp"));
  5665. size_t size = sizeof(SDot4AddU8PackedOp) * count;
  5666. Data.resize(size);
  5667. SDot4AddU8PackedOp *pPrimitives = (SDot4AddU8PackedOp*)Data.data();
  5668. for (size_t i = 0; i < count; ++i) {
  5669. SDot4AddU8PackedOp *p = &pPrimitives[i];
  5670. p->input1 = (*validation_input1)[i];
  5671. p->input2 = (*validation_input2)[i];
  5672. p->acc = (*validation_acc)[i];
  5673. }
  5674. // use shader from data table
  5675. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5676. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5677. });
  5678. MappedData data;
  5679. test->Test->GetReadBackData("SDot4AddU8PackedOp", &data);
  5680. SDot4AddU8PackedOp *pPrimitives = (SDot4AddU8PackedOp*)data.data();
  5681. WEX::TestExecution::DisableVerifyExceptions dve;
  5682. for (size_t i = 0; i < count; ++i) {
  5683. SDot4AddU8PackedOp *p = &pPrimitives[i];
  5684. uint32_t expectedResult = (*validation_result)[i];
  5685. LogCommentFmt(
  5686. L"element #%u, input1 = %u, input2 = %u, acc = %u \n"
  5687. L"result = %u, result_expected = %u, ",
  5688. i, p->input1, p->input2, p->acc, p->result, expectedResult);
  5689. VerifyOutputWithExpectedValueUInt(p->result, expectedResult, 0);
  5690. }
  5691. }
  5692. TEST_F(ExecutionTest, Msad4Test) {
  5693. WEX::TestExecution::SetVerifyOutput verifySettings(
  5694. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5695. CComPtr<IStream> pStream;
  5696. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5697. CComPtr<ID3D12Device> pDevice;
  5698. if (!CreateDevice(&pDevice)) {
  5699. return;
  5700. }
  5701. size_t tableSize = sizeof(Msad4OpParameters) / sizeof(TableParameter);
  5702. TableParameterHandler handler(Msad4OpParameters, tableSize);
  5703. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5704. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5705. std::vector<unsigned int> *Validation_Reference =
  5706. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5707. std::vector<WEX::Common::String> *Validation_Source =
  5708. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5709. std::vector<WEX::Common::String> *Validation_Accum =
  5710. &handler.GetTableParamByName(L"Validation.Input3")->m_StringTable;
  5711. std::vector<WEX::Common::String> *Validation_Expected =
  5712. &handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable;
  5713. size_t count = Validation_Expected->size();
  5714. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5715. pDevice, m_support, pStream, "Msad4",
  5716. // this callbacked is called when the test
  5717. // is creating the resource to run the test
  5718. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5719. VERIFY_IS_TRUE(0 == _stricmp(Name, "SMsad4"));
  5720. size_t size = sizeof(SMsad4) * count;
  5721. Data.resize(size);
  5722. SMsad4 *pPrimitives = (SMsad4*)Data.data();
  5723. for (size_t i = 0; i < count; ++i) {
  5724. SMsad4 *p = &pPrimitives[i];
  5725. XMUINT2 src;
  5726. XMUINT4 accum;
  5727. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Source)[i], (unsigned int*)&src, 2));
  5728. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Accum)[i], (unsigned int*)&accum, 4));
  5729. p->ref = (*Validation_Reference)[i];
  5730. p->src = src;
  5731. p->accum = accum;
  5732. }
  5733. // use shader from data table
  5734. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5735. });
  5736. MappedData data;
  5737. test->Test->GetReadBackData("SMsad4", &data);
  5738. SMsad4 *pPrimitives = (SMsad4*)data.data();
  5739. WEX::TestExecution::DisableVerifyExceptions dve;
  5740. for (size_t i = 0; i < count; ++i) {
  5741. SMsad4 *p = &pPrimitives[i];
  5742. XMUINT4 result;
  5743. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Expected)[i],
  5744. (unsigned int *)&result, 4));
  5745. LogCommentFmt(
  5746. L"element #%u, ref = %u(0x%08x), src = %u(0x%08x), %u(0x%08x), "
  5747. L"accum = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x),\n"
  5748. L"result = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x),\n"
  5749. L"expected = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x)", i,
  5750. p->ref, p->ref, p->src.x, p->src.x, p->src.y, p->src.y, p->accum.x,
  5751. p->accum.x, p->accum.y, p->accum.y, p->accum.z, p->accum.z,
  5752. p->accum.w, p->accum.w, p->result.x, p->result.x, p->result.y,
  5753. p->result.y, p->result.z, p->result.z, p->result.w, p->result.w,
  5754. result.x, result.x, result.y, result.y, result.z, result.z,
  5755. result.w, result.w);
  5756. int toleranceInt = (int)tolerance;
  5757. VerifyOutputWithExpectedValueInt(p->result.x, result.x, toleranceInt);
  5758. VerifyOutputWithExpectedValueInt(p->result.y, result.y, toleranceInt);
  5759. VerifyOutputWithExpectedValueInt(p->result.z, result.z, toleranceInt);
  5760. VerifyOutputWithExpectedValueInt(p->result.w, result.w, toleranceInt);
  5761. }
  5762. }
  5763. TEST_F(ExecutionTest, DenormBinaryFloatOpTest) {
  5764. WEX::TestExecution::SetVerifyOutput verifySettings(
  5765. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5766. CComPtr<IStream> pStream;
  5767. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5768. CComPtr<ID3D12Device> pDevice;
  5769. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5770. return;
  5771. }
  5772. // Read data from the table
  5773. int tableSize = sizeof(DenormBinaryFPOpParameters) / sizeof(TableParameter);
  5774. TableParameterHandler handler(DenormBinaryFPOpParameters, tableSize);
  5775. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5776. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5777. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5778. std::vector<WEX::Common::String> *Validation_Input1 =
  5779. &(handler.GetTableParamByName(L"Validation.Input1")->m_StringTable);
  5780. std::vector<WEX::Common::String> *Validation_Input2 =
  5781. &(handler.GetTableParamByName(L"Validation.Input2")->m_StringTable);
  5782. std::vector<WEX::Common::String> *Validation_Expected1 =
  5783. &(handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable);
  5784. // two expected outputs for any mode
  5785. std::vector<WEX::Common::String> *Validation_Expected2 =
  5786. &(handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable);
  5787. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5788. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5789. size_t count = Validation_Input1->size();
  5790. using namespace hlsl::DXIL;
  5791. Float32DenormMode mode = Float32DenormMode::Any;
  5792. if (strcmp(Arguments.m_psz, "-denorm preserve") == 0) {
  5793. mode = Float32DenormMode::Preserve;
  5794. }
  5795. else if (strcmp(Arguments.m_psz, "-denorm ftz") == 0) {
  5796. mode = Float32DenormMode::FTZ;
  5797. }
  5798. if (mode == Float32DenormMode::Any) {
  5799. DXASSERT(Validation_Expected2->size() == Validation_Expected1->size(),
  5800. "must have same number of expected values");
  5801. }
  5802. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5803. pDevice, m_support, pStream, "BinaryFPOp",
  5804. // this callbacked is called when the test
  5805. // is creating the resource to run the test
  5806. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5807. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  5808. size_t size = sizeof(SBinaryFPOp) * count;
  5809. Data.resize(size);
  5810. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)Data.data();
  5811. for (size_t i = 0; i < count; ++i) {
  5812. SBinaryFPOp *p = &pPrimitives[i];
  5813. PCWSTR str1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5814. PCWSTR str2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5815. float val1, val2;
  5816. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5817. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5818. p->input1 = val1;
  5819. p->input2 = val2;
  5820. }
  5821. // use shader from data table
  5822. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5823. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5824. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5825. });
  5826. MappedData data;
  5827. test->Test->GetReadBackData("SBinaryFPOp", &data);
  5828. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)data.data();
  5829. WEX::TestExecution::DisableVerifyExceptions dve;
  5830. for (unsigned i = 0; i < count; ++i) {
  5831. SBinaryFPOp *p = &pPrimitives[i];
  5832. if (mode == Float32DenormMode::Any) {
  5833. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5834. LPCWSTR str2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5835. float val1;
  5836. float val2;
  5837. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5838. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5839. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output = "
  5840. L"%6.8f, expected = %6.8f(%x) or %6.8f(%x)",
  5841. i, p->input1, p->input2, p->output1, val1, *(int *)&val1, val2, *(int *)&val2);
  5842. VERIFY_IS_TRUE(
  5843. CompareOutputWithExpectedValueFloat(
  5844. p->output1, val1, Validation_Type, Validation_Tolerance, mode) ||
  5845. CompareOutputWithExpectedValueFloat(
  5846. p->output1, val2, Validation_Type, Validation_Tolerance, mode));
  5847. }
  5848. else {
  5849. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5850. float val1;
  5851. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5852. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output = "
  5853. L"%6.8f, expected = %6.8f(%a)",
  5854. i, p->input1, p->input2, p->output1, val1, *(int *)&val1);
  5855. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  5856. Validation_Tolerance, mode);
  5857. }
  5858. }
  5859. }
  5860. TEST_F(ExecutionTest, DenormTertiaryFloatOpTest) {
  5861. WEX::TestExecution::SetVerifyOutput verifySettings(
  5862. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5863. CComPtr<IStream> pStream;
  5864. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5865. CComPtr<ID3D12Device> pDevice;
  5866. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5867. return;
  5868. }
  5869. // Read data from the table
  5870. int tableSize = sizeof(DenormTertiaryFPOpParameters) / sizeof(TableParameter);
  5871. TableParameterHandler handler(DenormTertiaryFPOpParameters, tableSize);
  5872. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5873. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5874. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5875. std::vector<WEX::Common::String> *Validation_Input1 =
  5876. &(handler.GetTableParamByName(L"Validation.Input1")->m_StringTable);
  5877. std::vector<WEX::Common::String> *Validation_Input2 =
  5878. &(handler.GetTableParamByName(L"Validation.Input2")->m_StringTable);
  5879. std::vector<WEX::Common::String> *Validation_Input3 =
  5880. &(handler.GetTableParamByName(L"Validation.Input3")->m_StringTable);
  5881. std::vector<WEX::Common::String> *Validation_Expected1 =
  5882. &(handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable);
  5883. // two expected outputs for any mode
  5884. std::vector<WEX::Common::String> *Validation_Expected2 =
  5885. &(handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable);
  5886. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5887. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5888. size_t count = Validation_Input1->size();
  5889. using namespace hlsl::DXIL;
  5890. Float32DenormMode mode = Float32DenormMode::Any;
  5891. if (strcmp(Arguments.m_psz, "-denorm preserve") == 0) {
  5892. mode = Float32DenormMode::Preserve;
  5893. }
  5894. else if (strcmp(Arguments.m_psz, "-denorm ftz") == 0) {
  5895. mode = Float32DenormMode::FTZ;
  5896. }
  5897. if (mode == Float32DenormMode::Any) {
  5898. DXASSERT(Validation_Expected2->size() == Validation_Expected1->size(),
  5899. "must have same number of expected values");
  5900. }
  5901. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5902. pDevice, m_support, pStream, "TertiaryFPOp",
  5903. // this callbacked is called when the test
  5904. // is creating the resource to run the test
  5905. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5906. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  5907. size_t size = sizeof(STertiaryFPOp) * count;
  5908. Data.resize(size);
  5909. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)Data.data();
  5910. for (size_t i = 0; i < count; ++i) {
  5911. STertiaryFPOp *p = &pPrimitives[i];
  5912. PCWSTR str1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5913. PCWSTR str2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5914. PCWSTR str3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5915. float val1, val2, val3;
  5916. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5917. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5918. VERIFY_SUCCEEDED(ParseDataToFloat(str3, val3));
  5919. p->input1 = val1;
  5920. p->input2 = val2;
  5921. p->input3 = val3;
  5922. }
  5923. // use shader from data table
  5924. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5925. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5926. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5927. });
  5928. MappedData data;
  5929. test->Test->GetReadBackData("STertiaryFPOp", &data);
  5930. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)data.data();
  5931. WEX::TestExecution::DisableVerifyExceptions dve;
  5932. for (unsigned i = 0; i < count; ++i) {
  5933. STertiaryFPOp *p = &pPrimitives[i];
  5934. if (mode == Float32DenormMode::Any) {
  5935. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5936. LPCWSTR str2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5937. float val1;
  5938. float val2;
  5939. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5940. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5941. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output = "
  5942. L"%6.8f, expected = %6.8f(%x) or %6.8f(%x)",
  5943. i, p->input1, p->input2, p->input3, p->output, val1, *(int *)&val1, val2, *(int *)&val2);
  5944. VERIFY_IS_TRUE(
  5945. CompareOutputWithExpectedValueFloat(
  5946. p->output, val1, Validation_Type, Validation_Tolerance, mode) ||
  5947. CompareOutputWithExpectedValueFloat(
  5948. p->output, val2, Validation_Type, Validation_Tolerance, mode));
  5949. }
  5950. else {
  5951. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5952. float val1;
  5953. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5954. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output = "
  5955. L"%6.8f, expected = %6.8f(%a)",
  5956. i, p->input1, p->input2, p->input3, p->output, val1, *(int *)&val1);
  5957. VerifyOutputWithExpectedValueFloat(p->output, val1, Validation_Type,
  5958. Validation_Tolerance, mode);
  5959. }
  5960. }
  5961. }
  5962. // Setup for wave intrinsics tests
  5963. enum class ShaderOpKind {
  5964. WaveSum,
  5965. WaveProduct,
  5966. WaveActiveMax,
  5967. WaveActiveMin,
  5968. WaveCountBits,
  5969. WaveActiveAllEqual,
  5970. WaveActiveAnyTrue,
  5971. WaveActiveAllTrue,
  5972. WaveActiveBitOr,
  5973. WaveActiveBitAnd,
  5974. WaveActiveBitXor,
  5975. ShaderOpInvalid
  5976. };
  5977. struct ShaderOpKindPair {
  5978. LPCWSTR name;
  5979. ShaderOpKind kind;
  5980. };
  5981. static ShaderOpKindPair ShaderOpKindTable[] = {
  5982. { L"WaveActiveSum", ShaderOpKind::WaveSum },
  5983. { L"WaveActiveUSum", ShaderOpKind::WaveSum },
  5984. { L"WaveActiveProduct", ShaderOpKind::WaveProduct },
  5985. { L"WaveActiveUProduct", ShaderOpKind::WaveProduct },
  5986. { L"WaveActiveMax", ShaderOpKind::WaveActiveMax },
  5987. { L"WaveActiveUMax", ShaderOpKind::WaveActiveMax },
  5988. { L"WaveActiveMin", ShaderOpKind::WaveActiveMin },
  5989. { L"WaveActiveUMin", ShaderOpKind::WaveActiveMin },
  5990. { L"WaveActiveCountBits", ShaderOpKind::WaveCountBits },
  5991. { L"WaveActiveAllEqual", ShaderOpKind::WaveActiveAllEqual },
  5992. { L"WaveActiveAnyTrue", ShaderOpKind::WaveActiveAnyTrue },
  5993. { L"WaveActiveAllTrue", ShaderOpKind::WaveActiveAllTrue },
  5994. { L"WaveActiveBitOr", ShaderOpKind::WaveActiveBitOr },
  5995. { L"WaveActiveBitAnd", ShaderOpKind::WaveActiveBitAnd },
  5996. { L"WaveActiveBitXor", ShaderOpKind::WaveActiveBitXor },
  5997. { L"WavePrefixSum", ShaderOpKind::WaveSum },
  5998. { L"WavePrefixUSum", ShaderOpKind::WaveSum },
  5999. { L"WavePrefixProduct", ShaderOpKind::WaveProduct },
  6000. { L"WavePrefixUProduct", ShaderOpKind::WaveProduct },
  6001. { L"WavePrefixMax", ShaderOpKind::WaveActiveMax },
  6002. { L"WavePrefixUMax", ShaderOpKind::WaveActiveMax },
  6003. { L"WavePrefixMin", ShaderOpKind::WaveActiveMin },
  6004. { L"WavePrefixUMin", ShaderOpKind::WaveActiveMin },
  6005. { L"WavePrefixCountBits", ShaderOpKind::WaveCountBits }
  6006. };
  6007. ShaderOpKind GetShaderOpKind(LPCWSTR str) {
  6008. for (size_t i = 0; i < sizeof(ShaderOpKindTable)/sizeof(ShaderOpKindPair); ++i) {
  6009. if (_wcsicmp(ShaderOpKindTable[i].name, str) == 0) {
  6010. return ShaderOpKindTable[i].kind;
  6011. }
  6012. }
  6013. DXASSERT_ARGS(false, "Invalid ShaderOp name: %s", str);
  6014. return ShaderOpKind::ShaderOpInvalid;
  6015. }
  6016. template <typename InType, typename OutType, ShaderOpKind kind>
  6017. struct computeExpected {
  6018. OutType operator()(const std::vector<InType> &inputs,
  6019. const std::vector<int> &masks, int maskValue,
  6020. unsigned int index) {
  6021. return 0;
  6022. }
  6023. };
  6024. template <typename InType, typename OutType>
  6025. struct computeExpected<InType, OutType, ShaderOpKind::WaveSum> {
  6026. OutType operator()(const std::vector<InType> &inputs,
  6027. const std::vector<int> &masks, int maskValue,
  6028. unsigned int index) {
  6029. OutType sum = 0;
  6030. for (size_t i = 0; i < index; ++i) {
  6031. if (masks.at(i) == maskValue) {
  6032. sum += inputs.at(i);
  6033. }
  6034. }
  6035. return sum;
  6036. }
  6037. };
  6038. template <typename InType, typename OutType>
  6039. struct computeExpected<InType, OutType, ShaderOpKind::WaveProduct> {
  6040. OutType operator()(const std::vector<InType> &inputs,
  6041. const std::vector<int> &masks, int maskValue,
  6042. unsigned int index) {
  6043. OutType prod = 1;
  6044. for (size_t i = 0; i < index; ++i) {
  6045. if (masks.at(i) == maskValue) {
  6046. prod *= inputs.at(i);
  6047. }
  6048. }
  6049. return prod;
  6050. }
  6051. };
  6052. template <typename InType, typename OutType>
  6053. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveMax> {
  6054. OutType operator()(const std::vector<InType> &inputs,
  6055. const std::vector<int> &masks, int maskValue,
  6056. unsigned int index) {
  6057. OutType maximum = std::numeric_limits<OutType>::min();
  6058. for (size_t i = 0; i < index; ++i) {
  6059. if (masks.at(i) == maskValue && inputs.at(i) > maximum)
  6060. maximum = inputs.at(i);
  6061. }
  6062. return maximum;
  6063. }
  6064. };
  6065. template <typename InType, typename OutType>
  6066. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveMin> {
  6067. OutType operator()(const std::vector<InType> &inputs,
  6068. const std::vector<int> &masks, int maskValue,
  6069. unsigned int index) {
  6070. OutType minimum = std::numeric_limits<OutType>::max();
  6071. for (size_t i = 0; i < index; ++i) {
  6072. if (masks.at(i) == maskValue && inputs.at(i) < minimum)
  6073. minimum = inputs.at(i);
  6074. }
  6075. return minimum;
  6076. }
  6077. };
  6078. template <typename InType, typename OutType>
  6079. struct computeExpected<InType, OutType, ShaderOpKind::WaveCountBits> {
  6080. OutType operator()(const std::vector<InType> &inputs,
  6081. const std::vector<int> &masks, int maskValue,
  6082. unsigned int index) {
  6083. OutType count = 0;
  6084. for (size_t i = 0; i < index; ++i) {
  6085. if (masks.at(i) == maskValue && inputs.at(i) > 3) {
  6086. count++;
  6087. }
  6088. }
  6089. return count;
  6090. }
  6091. };
  6092. // In HLSL, boolean is represented in a 4 byte (uint32) format,
  6093. // So we cannot use c++ bool type to represent bool in HLSL
  6094. // HLSL returns 0 for false and 1 for true
  6095. template <typename InType, typename OutType>
  6096. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAnyTrue> {
  6097. OutType operator()(const std::vector<InType> &inputs,
  6098. const std::vector<int> &masks, int maskValue,
  6099. unsigned int index) {
  6100. for (size_t i = 0; i < index; ++i) {
  6101. if (masks.at(i) == maskValue && inputs.at(i) != 0) {
  6102. return 1;
  6103. }
  6104. }
  6105. return 0;
  6106. }
  6107. };
  6108. template <typename InType, typename OutType>
  6109. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllTrue> {
  6110. OutType operator()(const std::vector<InType> &inputs,
  6111. const std::vector<int> &masks, int maskValue,
  6112. unsigned int index) {
  6113. for (size_t i = 0; i < index; ++i) {
  6114. if (masks.at(i) == maskValue && inputs.at(i) == 0) {
  6115. return 0;
  6116. }
  6117. }
  6118. return 1;
  6119. }
  6120. };
  6121. template <typename InType, typename OutType>
  6122. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllEqual> {
  6123. OutType operator()(const std::vector<InType> &inputs,
  6124. const std::vector<int> &masks, int maskValue,
  6125. unsigned int index) {
  6126. const InType *val = nullptr;
  6127. for (size_t i = 0; i < index; ++i) {
  6128. if (masks.at(i) == maskValue) {
  6129. if (val && *val != inputs.at(i)) {
  6130. return 0;
  6131. }
  6132. val = &inputs.at(i);
  6133. }
  6134. }
  6135. return 1;
  6136. }
  6137. };
  6138. template <typename InType, typename OutType>
  6139. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitOr> {
  6140. OutType operator()(const std::vector<InType> &inputs,
  6141. const std::vector<int> &masks, int maskValue,
  6142. unsigned int index) {
  6143. OutType bits = 0x00000000;
  6144. for (size_t i = 0; i < index; ++i) {
  6145. if (masks.at(i) == maskValue) {
  6146. bits |= inputs.at(i);
  6147. }
  6148. }
  6149. return bits;
  6150. }
  6151. };
  6152. template <typename InType, typename OutType>
  6153. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitAnd> {
  6154. OutType operator()(const std::vector<InType> &inputs,
  6155. const std::vector<int> &masks, int maskValue,
  6156. unsigned int index) {
  6157. OutType bits = 0xffffffff;
  6158. for (size_t i = 0; i < index; ++i) {
  6159. if (masks.at(i) == maskValue) {
  6160. bits &= inputs.at(i);
  6161. }
  6162. }
  6163. return bits;
  6164. }
  6165. };
  6166. template <typename InType, typename OutType>
  6167. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitXor> {
  6168. OutType operator()(const std::vector<InType> &inputs,
  6169. const std::vector<int> &masks, int maskValue,
  6170. unsigned int index) {
  6171. OutType bits = 0x00000000;
  6172. for (size_t i = 0; i < index; ++i) {
  6173. if (masks.at(i) == maskValue) {
  6174. bits ^= inputs.at(i);
  6175. }
  6176. }
  6177. return bits;
  6178. }
  6179. };
  6180. // Mask functions used to control active lanes
  6181. static int MaskAll(int i) {
  6182. UNREFERENCED_PARAMETER(i);
  6183. return 1;
  6184. }
  6185. static int MaskEveryOther(int i) {
  6186. return i % 2 == 0 ? 1 : 0;
  6187. }
  6188. static int MaskEveryThird(int i) {
  6189. return i % 3 == 0 ? 1 : 0;
  6190. }
  6191. typedef int(*MaskFunction)(int);
  6192. static MaskFunction MaskFunctionTable[] = {
  6193. MaskAll, MaskEveryOther, MaskEveryThird
  6194. };
  6195. template <typename InType, typename OutType>
  6196. static OutType computeExpectedWithShaderOp(const std::vector<InType> &inputs,
  6197. const std::vector<int> &masks,
  6198. int maskValue, unsigned int index,
  6199. LPCWSTR str) {
  6200. ShaderOpKind kind = GetShaderOpKind(str);
  6201. switch (kind) {
  6202. case ShaderOpKind::WaveSum:
  6203. return computeExpected<InType, OutType, ShaderOpKind::WaveSum>()(inputs, masks, maskValue, index);
  6204. case ShaderOpKind::WaveProduct:
  6205. return computeExpected<InType, OutType, ShaderOpKind::WaveProduct>()(inputs, masks, maskValue, index);
  6206. case ShaderOpKind::WaveActiveMax:
  6207. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveMax>()(inputs, masks, maskValue, index);
  6208. case ShaderOpKind::WaveActiveMin:
  6209. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveMin>()(inputs, masks, maskValue, index);
  6210. case ShaderOpKind::WaveCountBits:
  6211. return computeExpected<InType, OutType, ShaderOpKind::WaveCountBits>()(inputs, masks, maskValue, index);
  6212. case ShaderOpKind::WaveActiveBitOr:
  6213. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitOr>()(inputs, masks, maskValue, index);
  6214. case ShaderOpKind::WaveActiveBitAnd:
  6215. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitAnd>()(inputs, masks, maskValue, index);
  6216. case ShaderOpKind::WaveActiveBitXor:
  6217. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitXor>()(inputs, masks, maskValue, index);
  6218. case ShaderOpKind::WaveActiveAnyTrue:
  6219. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAnyTrue>()(inputs, masks, maskValue, index);
  6220. case ShaderOpKind::WaveActiveAllTrue:
  6221. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllTrue>()(inputs, masks, maskValue, index);
  6222. case ShaderOpKind::WaveActiveAllEqual:
  6223. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllEqual>()(inputs, masks, maskValue, index);
  6224. default:
  6225. DXASSERT_ARGS(false, "Invalid ShaderOp Name: %s", str);
  6226. return (OutType) 0;
  6227. }
  6228. };
  6229. // A framework for testing individual wave intrinsics tests.
  6230. // This test case is assuming that functions 1) WaveIsFirstLane and 2) WaveGetLaneIndex are correct for all lanes.
  6231. template <class T1, class T2>
  6232. void ExecutionTest::WaveIntrinsicsActivePrefixTest(
  6233. TableParameter *pParameterList, size_t numParameter, bool isPrefix) {
  6234. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6235. // Resource representation for compute shader
  6236. // firstLaneId is used to group different waves
  6237. // laneIndex is used to identify lane within the wave.
  6238. // Lane ids are not necessarily in same order as thread ids.
  6239. struct PerThreadData {
  6240. unsigned firstLaneId;
  6241. unsigned laneIndex;
  6242. int mask;
  6243. T1 input;
  6244. T2 output;
  6245. };
  6246. unsigned int NumThreadsX = 8;
  6247. unsigned int NumThreadsY = 12;
  6248. unsigned int NumThreadsZ = 1;
  6249. static const unsigned int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  6250. static const unsigned int DispatchGroupCount = 1;
  6251. static const unsigned int ThreadCount = ThreadsPerGroup * DispatchGroupCount;
  6252. CComPtr<IStream> pStream;
  6253. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6254. CComPtr<ID3D12Device> pDevice;
  6255. if (!CreateDevice(&pDevice)) {
  6256. return;
  6257. }
  6258. if (!DoesDeviceSupportWaveOps(pDevice)) {
  6259. // Optional feature, so it's correct to not support it if declared as such.
  6260. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  6261. return;
  6262. }
  6263. TableParameterHandler handler(pParameterList, numParameter);
  6264. unsigned int numInputSet = handler.GetTableParamByName(L"Validation.NumInputSet")->m_uint;
  6265. // Obtain the list of input lists
  6266. std::vector<std::vector<T1>*> InputDataList;
  6267. for (unsigned int i = 0;
  6268. i < numInputSet; ++i) {
  6269. std::wstring inputName = L"Validation.InputSet";
  6270. inputName.append(std::to_wstring(i + 1));
  6271. InputDataList.push_back(handler.GetDataArray<T1>(inputName.data()));
  6272. }
  6273. CW2A Text(handler.GetTableParamByName(L"ShaderOp.text")->m_str);
  6274. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  6275. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  6276. // Running compute shader for each input set with different masks
  6277. for (size_t setIndex = 0; setIndex < numInputSet; ++setIndex) {
  6278. for (size_t maskIndex = 0; maskIndex < sizeof(MaskFunctionTable) / sizeof(MaskFunction); ++maskIndex) {
  6279. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(
  6280. pDevice, m_support, "WaveIntrinsicsOp",
  6281. // this callbacked is called when the test
  6282. // is creating the resource to run the test
  6283. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6284. VERIFY_IS_TRUE(0 == _stricmp(Name, "SWaveIntrinsicsOp"));
  6285. size_t size = sizeof(PerThreadData) * ThreadCount;
  6286. Data.resize(size);
  6287. PerThreadData *pPrimitives = (PerThreadData*)Data.data();
  6288. // 4 different inputs for each operation test
  6289. size_t index = 0;
  6290. std::vector<T1> *IntList = InputDataList[setIndex];
  6291. while (index < ThreadCount) {
  6292. PerThreadData *p = &pPrimitives[index];
  6293. p->firstLaneId = 0xFFFFBFFF;
  6294. p->laneIndex = 0xFFFFBFFF;
  6295. p->mask = MaskFunctionTable[maskIndex]((int)index);
  6296. p->input = (*IntList)[index % IntList->size()];
  6297. p->output = 0xFFFFBFFF;
  6298. index++;
  6299. }
  6300. // use shader from data table
  6301. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  6302. }, ShaderOpSet);
  6303. // Check the value
  6304. MappedData data;
  6305. test->Test->GetReadBackData("SWaveIntrinsicsOp", &data);
  6306. PerThreadData *pPrimitives = (PerThreadData*)data.data();
  6307. WEX::TestExecution::DisableVerifyExceptions dve;
  6308. // Grouping data by waves
  6309. std::vector<int> firstLaneIds;
  6310. for (size_t i = 0; i < ThreadCount; ++i) {
  6311. PerThreadData *p = &pPrimitives[i];
  6312. int firstLaneId = p->firstLaneId;
  6313. if (!contains(firstLaneIds, firstLaneId)) {
  6314. firstLaneIds.push_back(firstLaneId);
  6315. }
  6316. }
  6317. std::map<int, std::unique_ptr<std::vector<PerThreadData *>>> waves;
  6318. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  6319. waves[firstLaneIds.at(i)] = std::make_unique<std::vector<PerThreadData*>>();
  6320. }
  6321. for (size_t i = 0; i < ThreadCount; ++i) {
  6322. PerThreadData *p = &pPrimitives[i];
  6323. waves[p->firstLaneId].get()->push_back(p);
  6324. }
  6325. // validate for each wave
  6326. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  6327. // collect inputs and masks for a given wave
  6328. std::vector<PerThreadData *> *waveData = waves[firstLaneIds.at(i)].get();
  6329. std::vector<T1> inputList(waveData->size());
  6330. std::vector<int> maskList(waveData->size(), -1);
  6331. std::vector<T2> outputList(waveData->size());
  6332. // sort inputList and masklist by lane id. input for each lane can be computed for its group index
  6333. for (size_t j = 0, end = waveData->size(); j < end; ++j) {
  6334. unsigned laneID = waveData->at(j)->laneIndex;
  6335. // ensure that each lane ID is unique and within the range
  6336. VERIFY_IS_TRUE(0 <= laneID && laneID < waveData->size());
  6337. VERIFY_IS_TRUE(maskList.at(laneID) == -1);
  6338. maskList.at(laneID) = waveData->at(j)->mask;
  6339. inputList.at(laneID) = waveData->at(j)->input;
  6340. outputList.at(laneID) = waveData->at(j)->output;
  6341. }
  6342. std::wstring inputStr = L"Wave Inputs: ";
  6343. std::wstring maskStr = L"Wave Masks: ";
  6344. std::wstring outputStr = L"Wave Outputs: ";
  6345. // append input string and mask string in lane id order
  6346. for (size_t j = 0, end = waveData->size(); j < end; ++j) {
  6347. maskStr.append(std::to_wstring(maskList.at(j)));
  6348. maskStr.append(L" ");
  6349. inputStr.append(std::to_wstring(inputList.at(j)));
  6350. inputStr.append(L" ");
  6351. outputStr.append(std::to_wstring(outputList.at(j)));
  6352. outputStr.append(L" ");
  6353. }
  6354. LogCommentFmt(inputStr.data());
  6355. LogCommentFmt(maskStr.data());
  6356. LogCommentFmt(outputStr.data());
  6357. LogCommentFmt(L"\n");
  6358. // Compute expected output for a given inputs, masks, and index
  6359. for (size_t laneIndex = 0, laneEnd = inputList.size(); laneIndex < laneEnd; ++laneIndex) {
  6360. T2 expected;
  6361. // WaveActive is equivalent to WavePrefix lane # lane count
  6362. unsigned index = isPrefix ? (unsigned)laneIndex : (unsigned)inputList.size();
  6363. if (maskList.at(laneIndex) == 1) {
  6364. expected = computeExpectedWithShaderOp<T1, T2>(
  6365. inputList, maskList, 1, index,
  6366. handler.GetTableParamByName(L"ShaderOp.Name")->m_str);
  6367. }
  6368. else {
  6369. expected = computeExpectedWithShaderOp<T1, T2>(
  6370. inputList, maskList, 0, index,
  6371. handler.GetTableParamByName(L"ShaderOp.Name")->m_str);
  6372. }
  6373. // TODO: use different comparison for floating point inputs
  6374. bool equal = outputList.at(laneIndex) == expected;
  6375. if (!equal) {
  6376. LogCommentFmt(L"lane%d: %4d, Expected : %4d", laneIndex, outputList.at(laneIndex), expected);
  6377. }
  6378. VERIFY_IS_TRUE(equal);
  6379. }
  6380. }
  6381. }
  6382. }
  6383. }
  6384. static const unsigned int MinWarpVersionForWaveIntrinsics = 16202;
  6385. TEST_F(ExecutionTest, WaveIntrinsicsActiveIntTest) {
  6386. if (GetTestParamUseWARP(true) &&
  6387. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6388. return;
  6389. }
  6390. WaveIntrinsicsActivePrefixTest<int, int>(
  6391. WaveIntrinsicsActiveIntParameters,
  6392. sizeof(WaveIntrinsicsActiveIntParameters) / sizeof(TableParameter),
  6393. /*isPrefix*/ false);
  6394. }
  6395. TEST_F(ExecutionTest, WaveIntrinsicsActiveUintTest) {
  6396. if (GetTestParamUseWARP(true) &&
  6397. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6398. return;
  6399. }
  6400. WaveIntrinsicsActivePrefixTest<unsigned int, unsigned int>(
  6401. WaveIntrinsicsActiveUintParameters,
  6402. sizeof(WaveIntrinsicsActiveUintParameters) / sizeof(TableParameter),
  6403. /*isPrefix*/ false);
  6404. }
  6405. TEST_F(ExecutionTest, WaveIntrinsicsPrefixIntTest) {
  6406. if (GetTestParamUseWARP(true) &&
  6407. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6408. return;
  6409. }
  6410. WaveIntrinsicsActivePrefixTest<int, int>(
  6411. WaveIntrinsicsPrefixIntParameters,
  6412. sizeof(WaveIntrinsicsPrefixIntParameters) / sizeof(TableParameter),
  6413. /*isPrefix*/ true);
  6414. }
  6415. TEST_F(ExecutionTest, WaveIntrinsicsPrefixUintTest) {
  6416. if (GetTestParamUseWARP(true) &&
  6417. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6418. return;
  6419. }
  6420. WaveIntrinsicsActivePrefixTest<unsigned int, unsigned int>(
  6421. WaveIntrinsicsPrefixUintParameters,
  6422. sizeof(WaveIntrinsicsPrefixUintParameters) / sizeof(TableParameter),
  6423. /*isPrefix*/ true);
  6424. }
  6425. template <typename T>
  6426. static T GetWaveMultiPrefixInitialAccumValue(LPCWSTR testName) {
  6427. if (_wcsicmp(testName, L"WaveMultiPrefixProduct") == 0 ||
  6428. _wcsicmp(testName, L"WaveMultiPrefixUProduct") == 0) {
  6429. return static_cast<T>(1);
  6430. } else if (_wcsicmp(testName, L"WaveMultiPrefixSum") == 0 ||
  6431. _wcsicmp(testName, L"WaveMultiPrefixUSum") == 0 ||
  6432. _wcsicmp(testName, L"WaveMultiPrefixBitOr") == 0 ||
  6433. _wcsicmp(testName, L"WaveMultiPrefixUBitOr") == 0 ||
  6434. _wcsicmp(testName, L"WaveMultiPrefixBitXor") == 0 ||
  6435. _wcsicmp(testName, L"WaveMultiPrefixUBitXor") == 0 ||
  6436. _wcsicmp(testName, L"WaveMultiPrefixCountBits") == 0 ||
  6437. _wcsicmp(testName, L"WaveMultiPrefixUCountBits") == 0) {
  6438. return static_cast<T>(0);
  6439. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitAnd") == 0 ||
  6440. _wcsicmp(testName, L"WaveMultiPrefixUBitAnd") == 0) {
  6441. return static_cast<T>(-1);
  6442. } else {
  6443. return static_cast<T>(0);
  6444. }
  6445. }
  6446. template <typename T>
  6447. std::function<T(T, T)> GetWaveMultiPrefixReferenceFunction(LPCWSTR testName) {
  6448. if (_wcsicmp(testName, L"WaveMultiPrefixProduct") == 0 ||
  6449. _wcsicmp(testName, L"WaveMultiPrefixUProduct") == 0) {
  6450. return [] (T lhs, T rhs) -> T { return lhs * rhs; };
  6451. } else if (_wcsicmp(testName, L"WaveMultiPrefixSum") == 0 ||
  6452. _wcsicmp(testName, L"WaveMultiPrefixUSum") == 0) {
  6453. return [] (T lhs, T rhs) -> T { return lhs + rhs; };
  6454. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitAnd") == 0 ||
  6455. _wcsicmp(testName, L"WaveMultiPrefixUBitAnd") == 0) {
  6456. return [] (T lhs, T rhs) -> T { return lhs & rhs; };
  6457. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitOr") == 0 ||
  6458. _wcsicmp(testName, L"WaveMultiPrefixUBitOr") == 0) {
  6459. return [] (T lhs, T rhs) -> T { return lhs | rhs; };
  6460. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitXor") == 0 ||
  6461. _wcsicmp(testName, L"WaveMultiPrefixUBitXor") == 0) {
  6462. return [] (T lhs, T rhs) -> T { return lhs ^ rhs; };
  6463. } else if (_wcsicmp(testName, L"WaveMultiPrefixCountBits") == 0 ||
  6464. _wcsicmp(testName, L"WaveMultiPrefixUCountBits") == 0) {
  6465. // For CountBits, each lane contributes a boolean value. The test input is
  6466. // a zero or non-zero integer. If the input is a non-zero value then the
  6467. // condition is true, thus we contribute one to the bit count.
  6468. return [] (T lhs, T rhs) -> T { return lhs + (rhs ? 1 : 0); };
  6469. } else {
  6470. return [] (T lhs, T rhs) -> T { UNREFERENCED_PARAMETER(lhs); UNREFERENCED_PARAMETER(rhs); return 0; };
  6471. }
  6472. }
  6473. template <class T>
  6474. void
  6475. ExecutionTest::WaveIntrinsicsMultiPrefixOpTest(TableParameter *pParameterList,
  6476. size_t numParameters) {
  6477. WEX::TestExecution::SetVerifyOutput
  6478. verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6479. struct PerThreadData {
  6480. uint32_t key;
  6481. uint32_t firstLaneId;
  6482. uint32_t laneId;
  6483. uint32_t mask;
  6484. T value;
  6485. T result;
  6486. };
  6487. constexpr size_t NumThreadsX = 8;
  6488. constexpr size_t NumThreadsY = 12;
  6489. constexpr size_t NumThreadsZ = 1;
  6490. constexpr size_t ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  6491. constexpr size_t DispatchGroupSize = 1;
  6492. constexpr size_t ThreadCount = ThreadsPerGroup * DispatchGroupSize;
  6493. CComPtr<IStream> pStream;
  6494. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6495. CComPtr<ID3D12Device> pDevice;
  6496. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_5)) {
  6497. return;
  6498. }
  6499. if (!DoesDeviceSupportWaveOps(pDevice)) {
  6500. // Optional feature, so it's correct to not support it if declared as such.
  6501. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  6502. return;
  6503. }
  6504. std::shared_ptr<st::ShaderOpSet>
  6505. ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  6506. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  6507. TableParameterHandler handler(pParameterList, numParameters);
  6508. CW2A shaderSource(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  6509. CW2A shaderProfile(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  6510. auto testName = handler.GetTableParamByName(L"ShaderOp.Name")->m_str;
  6511. std::vector<T> *keys = handler.GetDataArray<T>(L"Validation.Keys");
  6512. std::vector<T> *values = handler.GetDataArray<T>(L"Validation.Values");
  6513. for (size_t maskIndex = 0; maskIndex < _countof(MaskFunctionTable); ++maskIndex) {
  6514. std::shared_ptr<ShaderOpTestResult> test =
  6515. RunShaderOpTestAfterParse(pDevice, m_support, "WaveIntrinsicsOp",
  6516. [&] (LPCSTR name, std::vector<BYTE> &data, st::ShaderOp *pShaderOp) {
  6517. UNREFERENCED_PARAMETER(name);
  6518. const size_t dataSize = sizeof(PerThreadData) * ThreadCount;
  6519. data.resize(dataSize);
  6520. PerThreadData *pThreadData = reinterpret_cast<PerThreadData *>(data.data());
  6521. for (size_t i = 0; i != ThreadCount; ++i) {
  6522. pThreadData[i].key = keys->at(i % keys->size());
  6523. pThreadData[i].value = values->at(i % values->size());
  6524. pThreadData[i].firstLaneId = 0xdeadbeef;
  6525. pThreadData[i].laneId = 0xdeadbeef;
  6526. pThreadData[i].mask = MaskFunctionTable[maskIndex]((int)i);
  6527. pThreadData[i].result = 0xdeadbeef;
  6528. }
  6529. pShaderOp->Shaders.at(0).Text = shaderSource;
  6530. pShaderOp->Shaders.at(0).Target = shaderProfile;
  6531. }, ShaderOpSet);
  6532. MappedData mappedData;
  6533. test->Test->GetReadBackData("SWaveIntrinsicsOp", &mappedData);
  6534. PerThreadData *resultData = reinterpret_cast<PerThreadData *>(mappedData.data());
  6535. // Partition our data into waves
  6536. std::map<uint32_t, std::vector<PerThreadData *>> waves;
  6537. for (size_t i = 0, e = ThreadCount; i != e; ++i) {
  6538. PerThreadData *elt = &resultData[i];
  6539. // Basic sanity checks
  6540. VERIFY_IS_TRUE(elt->firstLaneId != 0xdeadbeef);
  6541. VERIFY_IS_TRUE(elt->laneId != 0xdeadbeef);
  6542. waves[elt->firstLaneId].push_back(elt);
  6543. }
  6544. // Verify each wave
  6545. auto refFn = GetWaveMultiPrefixReferenceFunction<T>(testName);
  6546. for (auto &w : waves) {
  6547. std::vector<PerThreadData *> &waveData = w.second;
  6548. struct {
  6549. bool operator()(PerThreadData *a, PerThreadData *b) const {
  6550. return (a->laneId < b->laneId);
  6551. }
  6552. } compare;
  6553. // Need to sort based on the lane id
  6554. std::sort(waveData.begin(), waveData.end(), compare);
  6555. LogCommentFmt(L"LaneId Mask Key Value Result Expected");
  6556. LogCommentFmt(L"-------- -------- -------- -------- -------- --------");
  6557. for (size_t i = 0, e = waveData.size(); i != e; ++i) {
  6558. PerThreadData *data = waveData[i];
  6559. // Compute prefix operation over each previous lane element that has the
  6560. // same key value, and is part of the same active thread group
  6561. T accum = GetWaveMultiPrefixInitialAccumValue<T>(testName);
  6562. for (unsigned j = 0; j < i; ++j) {
  6563. if (waveData[j]->key == data->key && waveData[j]->mask == data->mask) {
  6564. accum = refFn(accum, waveData[j]->value);
  6565. }
  6566. }
  6567. LogCommentFmt(L"%08X %08X %08X %08X %08X %08X", data->laneId, data->mask, data->key, data->value, data->result, accum);
  6568. VERIFY_IS_TRUE(accum == data->result);
  6569. }
  6570. LogCommentFmt(L"\n");
  6571. }
  6572. }
  6573. }
  6574. TEST_F(ExecutionTest, WaveIntrinsicsSM65IntTest) {
  6575. WaveIntrinsicsMultiPrefixOpTest<int>(WaveIntrinsicsMultiPrefixIntParameters,
  6576. _countof(WaveIntrinsicsMultiPrefixIntParameters));
  6577. }
  6578. TEST_F(ExecutionTest, WaveIntrinsicsSM65UintTest) {
  6579. WaveIntrinsicsMultiPrefixOpTest<unsigned>(WaveIntrinsicsMultiPrefixUintParameters,
  6580. _countof(WaveIntrinsicsMultiPrefixUintParameters));
  6581. }
  6582. TEST_F(ExecutionTest, CBufferTestHalf) {
  6583. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6584. CComPtr<IStream> pStream;
  6585. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6586. // Single operation test at the moment.
  6587. CComPtr<ID3D12Device> pDevice;
  6588. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_2))
  6589. return;
  6590. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  6591. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  6592. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6593. return;
  6594. }
  6595. uint16_t InputData[] = { 0x3F80, 0x3F00, 0x3D80, 0x7BFF };
  6596. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "CBufferTestHalf",
  6597. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6598. UNREFERENCED_PARAMETER(pShaderOp);
  6599. VERIFY_IS_TRUE(0 == _stricmp(Name, "CB0"));
  6600. // use shader from data table.
  6601. Data.resize(sizeof(InputData));
  6602. uint16_t *pData = (uint16_t *)Data.data();
  6603. for (size_t i = 0; i < 4; ++i, ++pData) {
  6604. *pData = InputData[i];
  6605. }
  6606. });
  6607. {
  6608. MappedData data;
  6609. test->Test->GetReadBackData("RTarget", &data);
  6610. const uint16_t *pPixels = (uint16_t *)data.data();
  6611. for (int i = 0; i < 4; ++i) {
  6612. uint16_t output = *(pPixels + i);
  6613. float outputFloat = ConvertFloat16ToFloat32(output);
  6614. float inputFloat = ConvertFloat16ToFloat32(InputData[i]);
  6615. LogCommentFmt(L"element #%u: input = %6.8f(0x%04x), output = %6.8f(0x%04x)",
  6616. i, inputFloat, InputData[i], outputFloat, output);
  6617. VERIFY_ARE_EQUAL(inputFloat, outputFloat);
  6618. }
  6619. }
  6620. }
  6621. TEST_F(ExecutionTest, BarycentricsTest) {
  6622. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6623. CComPtr<IStream> pStream;
  6624. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6625. CComPtr<ID3D12Device> pDevice;
  6626. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_1))
  6627. return;
  6628. if (!DoesDeviceSupportBarycentrics(pDevice)) {
  6629. WEX::Logging::Log::Comment(L"Device does not support barycentrics.");
  6630. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6631. return;
  6632. }
  6633. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "Barycentrics", nullptr);
  6634. MappedData data;
  6635. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  6636. UINT width = (UINT)D.Width;
  6637. UINT height = D.Height;
  6638. UINT pixelSize = GetByteSizeForFormat(D.Format);
  6639. test->Test->GetReadBackData("RTarget", &data);
  6640. //const uint8_t *pPixels = (uint8_t *)data.data();
  6641. const float *pPixels = (float *)data.data();
  6642. // Get the vertex of barycentric coordinate using VBuffer
  6643. MappedData triangleData;
  6644. test->Test->GetReadBackData("VBuffer", &triangleData);
  6645. const float *pTriangleData = (float*)triangleData.data();
  6646. // get the size of the input data
  6647. unsigned triangleVertexSizeInFloat = 0;
  6648. for (auto element : test->ShaderOp->InputElements)
  6649. triangleVertexSizeInFloat += GetByteSizeForFormat(element.Format) / 4;
  6650. XMFLOAT2 p0(pTriangleData[0], pTriangleData[1]);
  6651. XMFLOAT2 p1(pTriangleData[triangleVertexSizeInFloat], pTriangleData[triangleVertexSizeInFloat + 1]);
  6652. XMFLOAT2 p2(pTriangleData[triangleVertexSizeInFloat * 2], pTriangleData[triangleVertexSizeInFloat * 2 + 1]);
  6653. XMFLOAT3 barycentricWeights[4] = {
  6654. XMFLOAT3(0.3333f, 0.3333f, 0.3333f),
  6655. XMFLOAT3(0.5f, 0.25f, 0.25f),
  6656. XMFLOAT3(0.25f, 0.5f, 0.25f),
  6657. XMFLOAT3(0.25f, 0.25f, 0.50f)
  6658. };
  6659. float tolerance = 0.001f;
  6660. for (unsigned i = 0; i < sizeof(barycentricWeights) / sizeof(XMFLOAT3); ++i) {
  6661. float w0 = barycentricWeights[i].x;
  6662. float w1 = barycentricWeights[i].y;
  6663. float w2 = barycentricWeights[i].z;
  6664. float x1 = w0 * p0.x + w1 * p1.x + w2 * p2.x;
  6665. float y1 = w0 * p0.y + w1 * p1.y + w2 * p2.y;
  6666. // map from x1 y1 to rtv pixels
  6667. int pixelX = (int)((x1 + 1) * (width - 1) / 2);
  6668. int pixelY = (int)((1 - y1) * (height - 1) / 2);
  6669. int offset = pixelSize * (pixelX + pixelY * width) / sizeof(pPixels[0]);
  6670. LogCommentFmt(L"location %u %u, value %f, %f, %f", pixelX, pixelY, pPixels[offset], pPixels[offset + 1], pPixels[offset + 2]);
  6671. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset], w0, tolerance));
  6672. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset + 1], w1, tolerance));
  6673. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset + 2], w2, tolerance));
  6674. }
  6675. //SavePixelsToFile(pPixels, DXGI_FORMAT_R32G32B32A32_FLOAT, width, height, L"barycentric.bmp");
  6676. }
  6677. static const char RawBufferTestShaderDeclarations[] =
  6678. "// Note: COMPONENT_TYPE and COMPONENT_SIZE will be defined via compiler option -D\r\n"
  6679. "typedef COMPONENT_TYPE scalar; \r\n"
  6680. "typedef vector<COMPONENT_TYPE, 2> vector2; \r\n"
  6681. "typedef vector<COMPONENT_TYPE, 3> vector3; \r\n"
  6682. "typedef vector<COMPONENT_TYPE, 4> vector4; \r\n"
  6683. "\r\n"
  6684. "struct TestData { \r\n"
  6685. " scalar v1; \r\n"
  6686. " vector2 v2; \r\n"
  6687. " vector3 v3; \r\n"
  6688. " vector4 v4; \r\n"
  6689. "}; \r\n"
  6690. "\r\n"
  6691. "struct UavData {\r\n"
  6692. " TestData input; \r\n"
  6693. " TestData output; \r\n"
  6694. " TestData srvOut; \r\n"
  6695. "}; \r\n"
  6696. "\r\n"
  6697. "ByteAddressBuffer srv0 : register(t0); \r\n"
  6698. "StructuredBuffer<TestData> srv1 : register(t1); \r\n"
  6699. "ByteAddressBuffer srv2 : register(t2); \r\n"
  6700. "StructuredBuffer<TestData> srv3 : register(t3); \r\n"
  6701. "\r\n"
  6702. "RWByteAddressBuffer uav0 : register(u0); \r\n"
  6703. "RWStructuredBuffer<UavData> uav1 : register(u1); \r\n"
  6704. "RWByteAddressBuffer uav2 : register(u2); \r\n"
  6705. "RWStructuredBuffer<UavData> uav3 : register(u3); \r\n";
  6706. static const char RawBufferTestShaderBody[] =
  6707. " // offset of 'out' in 'UavData'\r\n"
  6708. " const int out_offset = COMPONENT_SIZE * 10; \r\n"
  6709. "\r\n"
  6710. " // offset of 'srv_out' in 'UavData'\r\n"
  6711. " const int srv_out_offset = COMPONENT_SIZE * 10 * 2; \r\n"
  6712. "\r\n"
  6713. " // offsets within the 'Data' struct\r\n"
  6714. " const int v1_offset = 0; \r\n"
  6715. " const int v2_offset = COMPONENT_SIZE; \r\n"
  6716. " const int v3_offset = COMPONENT_SIZE * 3; \r\n"
  6717. " const int v4_offset = COMPONENT_SIZE * 6; \r\n"
  6718. "\r\n"
  6719. " uav0.Store(srv_out_offset + v1_offset, srv0.Load<scalar>(v1_offset)); \r\n"
  6720. " uav0.Store(srv_out_offset + v2_offset, srv0.Load<vector2>(v2_offset)); \r\n"
  6721. " uav0.Store(srv_out_offset + v3_offset, srv0.Load<vector3>(v3_offset)); \r\n"
  6722. " uav0.Store(srv_out_offset + v4_offset, srv0.Load<vector4>(v4_offset)); \r\n"
  6723. "\r\n"
  6724. " uav1[0].srvOut.v1 = srv1[0].v1; \r\n"
  6725. " uav1[0].srvOut.v2 = srv1[0].v2; \r\n"
  6726. " uav1[0].srvOut.v3 = srv1[0].v3; \r\n"
  6727. " uav1[0].srvOut.v4 = srv1[0].v4; \r\n"
  6728. "\r\n"
  6729. " uav2.Store(srv_out_offset + v1_offset, srv2.Load<scalar>(v1_offset)); \r\n"
  6730. " uav2.Store(srv_out_offset + v2_offset, srv2.Load<vector2>(v2_offset)); \r\n"
  6731. " uav2.Store(srv_out_offset + v3_offset, srv2.Load<vector3>(v3_offset)); \r\n"
  6732. " uav2.Store(srv_out_offset + v4_offset, srv2.Load<vector4>(v4_offset)); \r\n"
  6733. "\r\n"
  6734. " uav3[0].srvOut.v1 = srv3[0].v1; \r\n"
  6735. " uav3[0].srvOut.v2 = srv3[0].v2; \r\n"
  6736. " uav3[0].srvOut.v3 = srv3[0].v3; \r\n"
  6737. " uav3[0].srvOut.v4 = srv3[0].v4; \r\n"
  6738. "\r\n"
  6739. " uav0.Store(out_offset + v1_offset, uav0.Load<scalar>(v1_offset)); \r\n"
  6740. " uav0.Store(out_offset + v2_offset, uav0.Load<vector2>(v2_offset)); \r\n"
  6741. " uav0.Store(out_offset + v3_offset, uav0.Load<vector3>(v3_offset)); \r\n"
  6742. " uav0.Store(out_offset + v4_offset, uav0.Load<vector4>(v4_offset)); \r\n"
  6743. "\r\n"
  6744. " uav1[0].output.v1 = uav1[0].input.v1; \r\n"
  6745. " uav1[0].output.v2 = uav1[0].input.v2; \r\n"
  6746. " uav1[0].output.v3 = uav1[0].input.v3; \r\n"
  6747. " uav1[0].output.v4 = uav1[0].input.v4; \r\n"
  6748. "\r\n"
  6749. " uav2.Store(out_offset + v1_offset, uav2.Load<scalar>(v1_offset)); \r\n"
  6750. " uav2.Store(out_offset + v2_offset, uav2.Load<vector2>(v2_offset)); \r\n"
  6751. " uav2.Store(out_offset + v3_offset, uav2.Load<vector3>(v3_offset)); \r\n"
  6752. " uav2.Store(out_offset + v4_offset, uav2.Load<vector4>(v4_offset)); \r\n"
  6753. "\r\n"
  6754. " uav3[0].output.v1 = uav3[0].input.v1; \r\n"
  6755. " uav3[0].output.v2 = uav3[0].input.v2; \r\n"
  6756. " uav3[0].output.v3 = uav3[0].input.v3; \r\n"
  6757. " uav3[0].output.v4 = uav3[0].input.v4; \r\n";
  6758. static const char RawBufferTestComputeShaderTemplate[] =
  6759. "%s\r\n" // <- RawBufferTestShaderDeclarations
  6760. "[numthreads(1, 1, 1)]\r\n"
  6761. "void main(uint GI : SV_GroupIndex) {\r\n"
  6762. "%s\r\n" // <- RawBufferTestShaderBody
  6763. "};";
  6764. static const char RawBufferTestGraphicsPixelShaderTemplate[] =
  6765. "%s\r\n" // <- RawBufferTestShaderDeclarations
  6766. "struct PSInput { \r\n"
  6767. " float4 pos : SV_POSITION; \r\n"
  6768. "}; \r\n"
  6769. "uint4 main(PSInput input) : SV_TARGET{ \r\n"
  6770. " if (input.pos.x + input.pos.y == 1.0f) { // pixel { 0.5, 0.5, 0 } \r\n"
  6771. "%s\r\n" // <- RawBufferTestShaderBody
  6772. " } \r\n"
  6773. " return uint4(1, 2, 3, 4); \r\n"
  6774. "};";
  6775. TEST_F(ExecutionTest, ComputeRawBufferLdStI32) {
  6776. RawBufferLdStTestData<int32_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT32 / 2 } };
  6777. RunComputeRawBufferLdStTest<int32_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I32, "ComputeRawBufferLdSt32Bit", data);
  6778. }
  6779. TEST_F(ExecutionTest, ComputeRawBufferLdStFloat) {
  6780. RawBufferLdStTestData<float> data = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, -105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6781. RunComputeRawBufferLdStTest<float>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Float, "ComputeRawBufferLdSt32Bit", data);
  6782. }
  6783. TEST_F(ExecutionTest, ComputeRawBufferLdStI64) {
  6784. RawBufferLdStTestData<int64_t> data = { { 1 }, { 2, -1 }, { 256, -105171532, 980 }, { 465, 13, -89, MAXUINT64 / 2 } };
  6785. RunComputeRawBufferLdStTest<int64_t>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "ComputeRawBufferLdSt64Bit", data);
  6786. }
  6787. TEST_F(ExecutionTest, ComputeRawBufferLdStDouble) {
  6788. RawBufferLdStTestData<double> data = { { 3e-10 }, { 1.5, -1.99988 }, { 256.0, -105.17, 980.0 }, { 465.1652, -1.5694e2, -0.8543e-2, 1333.5 } };
  6789. RunComputeRawBufferLdStTest<double>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "ComputeRawBufferLdSt64Bit", data);
  6790. }
  6791. TEST_F(ExecutionTest, ComputeRawBufferLdStI16) {
  6792. RawBufferLdStTestData<int16_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT16 / 2 } };
  6793. RunComputeRawBufferLdStTest<int16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I16, "ComputeRawBufferLdSt16Bit", data);
  6794. }
  6795. TEST_F(ExecutionTest, ComputeRawBufferLdStHalf) {
  6796. RawBufferLdStTestData<float> floatData = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, 105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6797. RawBufferLdStTestData<uint16_t> halfData;
  6798. for (int i = 0; i < sizeof(floatData)/sizeof(float); i++) {
  6799. ((uint16_t*)&halfData)[i] = ConvertFloat32ToFloat16(((float*)&floatData)[i]);
  6800. }
  6801. RunComputeRawBufferLdStTest<uint16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Half, "ComputeRawBufferLdSt16Bit", halfData);
  6802. }
  6803. TEST_F(ExecutionTest, GraphicsRawBufferLdStI32) {
  6804. RawBufferLdStTestData<int32_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT32 / 2 } };
  6805. RunGraphicsRawBufferLdStTest<int32_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I32, "GraphicsRawBufferLdSt32Bit", data);
  6806. }
  6807. TEST_F(ExecutionTest, GraphicsRawBufferLdStFloat) {
  6808. RawBufferLdStTestData<float> data = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, -105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6809. RunGraphicsRawBufferLdStTest<float>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Float, "GraphicsRawBufferLdSt32Bit", data);
  6810. }
  6811. TEST_F(ExecutionTest, GraphicsRawBufferLdStI64) {
  6812. RawBufferLdStTestData<int64_t> data = { { 1 }, { 2, -1 }, { 256, -105171532, 980 }, { 465, 13, -89, MAXUINT64 / 2 } };
  6813. RunGraphicsRawBufferLdStTest<int64_t>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "GraphicsRawBufferLdSt64Bit", data);
  6814. }
  6815. TEST_F(ExecutionTest, GraphicsRawBufferLdStDouble) {
  6816. RawBufferLdStTestData<double> data = { { 3e-10 }, { 1.5, -1.99988 }, { 256.0, -105.17, 980.0 }, { 465.1652, -1.5694e2, -0.8543e-2, 1333.5 } };
  6817. RunGraphicsRawBufferLdStTest<double>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::Double, "GraphicsRawBufferLdSt64Bit", data);
  6818. }
  6819. TEST_F(ExecutionTest, GraphicsRawBufferLdStI16) {
  6820. RawBufferLdStTestData<int16_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT16 / 2 } };
  6821. RunGraphicsRawBufferLdStTest<int16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I16, "GraphicsRawBufferLdSt16Bit", data);
  6822. }
  6823. TEST_F(ExecutionTest, GraphicsRawBufferLdStHalf) {
  6824. RawBufferLdStTestData<float> floatData = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, 105.17f, 0.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6825. RawBufferLdStTestData<uint16_t> halfData;
  6826. for (int i = 0; i < sizeof(floatData) / sizeof(float); i++) {
  6827. ((uint16_t*)&halfData)[i] = ConvertFloat32ToFloat16(((float*)&floatData)[i]);
  6828. }
  6829. RunGraphicsRawBufferLdStTest<uint16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Half, "GraphicsRawBufferLdSt16Bit", halfData);
  6830. }
  6831. bool ExecutionTest::SetupRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6832. CComPtr<ID3D12Device> &pDevice, CComPtr<IStream> &pStream,
  6833. char *&sTy, char *&additionalOptions) {
  6834. if (!CreateDevice(&pDevice, shaderModel)) {
  6835. return false;
  6836. }
  6837. additionalOptions = "";
  6838. switch (dataType) {
  6839. case RawBufferLdStType::I64:
  6840. if (!DoesDeviceSupportInt64(pDevice)) {
  6841. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  6842. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6843. return false;
  6844. }
  6845. sTy = "int64_t";
  6846. break;
  6847. case RawBufferLdStType::Double:
  6848. if (!DoesDeviceSupportDouble(pDevice)) {
  6849. WEX::Logging::Log::Comment(L"Device does not support double operations.");
  6850. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6851. return false;
  6852. }
  6853. sTy = "double";
  6854. break;
  6855. case RawBufferLdStType::I16:
  6856. case RawBufferLdStType::Half:
  6857. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  6858. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  6859. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6860. return false;
  6861. }
  6862. additionalOptions = "-enable-16bit-types";
  6863. sTy = (dataType == RawBufferLdStType::I16 ? "int16_t" : "half");
  6864. break;
  6865. case RawBufferLdStType::I32:
  6866. sTy = "int32_t";
  6867. break;
  6868. case RawBufferLdStType::Float:
  6869. sTy = "float";
  6870. break;
  6871. default:
  6872. DXASSERT_NOMSG("Invalid RawBufferLdStType");
  6873. }
  6874. // read shader config
  6875. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6876. return true;
  6877. }
  6878. template <class Ty>
  6879. void ExecutionTest::VerifyRawBufferLdStTestResults(const std::shared_ptr<st::ShaderOpTest> test, const RawBufferLdStTestData<Ty> &testData) {
  6880. // read buffers back & verify expected values
  6881. static const int UavBufferCount = 4;
  6882. char bufferName[11] = "UAVBufferX";
  6883. for (unsigned i = 0; i < UavBufferCount; i++) {
  6884. MappedData dataUav;
  6885. RawBufferLdStUavData<Ty> *pOutData;
  6886. bufferName[sizeof(bufferName) - 2] = (char)(i + '0');
  6887. test->GetReadBackData(bufferName, &dataUav);
  6888. VERIFY_ARE_EQUAL(sizeof(RawBufferLdStUavData<Ty>), dataUav.size());
  6889. pOutData = (RawBufferLdStUavData<Ty> *)dataUav.data();
  6890. LogCommentFmt(L"Verifying UAVBuffer%d Load -> UAVBuffer%d Store", i, i);
  6891. // scalar
  6892. VERIFY_ARE_EQUAL(pOutData->output.v1, testData.v1);
  6893. // vector 2
  6894. VERIFY_ARE_EQUAL(pOutData->output.v2[0], testData.v2[0]);
  6895. VERIFY_ARE_EQUAL(pOutData->output.v2[1], testData.v2[1]);
  6896. // vector 3
  6897. VERIFY_ARE_EQUAL(pOutData->output.v3[0], testData.v3[0]);
  6898. VERIFY_ARE_EQUAL(pOutData->output.v3[1], testData.v3[1]);
  6899. VERIFY_ARE_EQUAL(pOutData->output.v3[2], testData.v3[2]);
  6900. // vector 4
  6901. VERIFY_ARE_EQUAL(pOutData->output.v4[0], testData.v4[0]);
  6902. VERIFY_ARE_EQUAL(pOutData->output.v4[1], testData.v4[1]);
  6903. VERIFY_ARE_EQUAL(pOutData->output.v4[2], testData.v4[2]);
  6904. VERIFY_ARE_EQUAL(pOutData->output.v4[3], testData.v4[3]);
  6905. // verify SRV Store
  6906. LogCommentFmt(L"Verifying SRVBuffer%d Load -> UAVBuffer%d Store", i, i);
  6907. // scalar
  6908. VERIFY_ARE_EQUAL(pOutData->srvOut.v1, testData.v1);
  6909. // vector 2
  6910. VERIFY_ARE_EQUAL(pOutData->srvOut.v2[0], testData.v2[0]);
  6911. VERIFY_ARE_EQUAL(pOutData->srvOut.v2[1], testData.v2[1]);
  6912. // vector 3
  6913. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[0], testData.v3[0]);
  6914. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[1], testData.v3[1]);
  6915. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[2], testData.v3[2]);
  6916. // vector 4
  6917. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[0], testData.v4[0]);
  6918. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[1], testData.v4[1]);
  6919. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[2], testData.v4[2]);
  6920. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[3], testData.v4[3]);
  6921. }
  6922. }
  6923. template <class Ty>
  6924. void ExecutionTest::RunComputeRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6925. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData) {
  6926. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6927. CComPtr<ID3D12Device> pDevice;
  6928. CComPtr<IStream> pStream;
  6929. char *sTy = nullptr, *additionalOptions = nullptr;
  6930. if (!SetupRawBufferLdStTest(shaderModel, dataType, pDevice, pStream, sTy, additionalOptions)) {
  6931. return;
  6932. }
  6933. // format shader source
  6934. char rawBufferTestShaderText[sizeof(RawBufferTestComputeShaderTemplate) + sizeof(RawBufferTestShaderDeclarations) + sizeof(RawBufferTestShaderBody)];
  6935. VERIFY_IS_TRUE(sprintf_s(rawBufferTestShaderText, sizeof(rawBufferTestShaderText),
  6936. RawBufferTestComputeShaderTemplate, RawBufferTestShaderDeclarations, RawBufferTestShaderBody) != -1);
  6937. // format compiler args
  6938. char compilerOptions[256];
  6939. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D COMPONENT_TYPE=%s -D COMPONENT_SIZE=%d %s", sTy, (int)sizeof(Ty), additionalOptions) != -1);
  6940. // run the shader
  6941. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, shaderOpName,
  6942. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6943. VERIFY_IS_TRUE(((0 == strncmp(Name, "SRVBuffer", 9)) || (0 == strncmp(Name, "UAVBuffer", 9))) &&
  6944. (Name[9] >= '0' && Name[9] <= '3'));
  6945. pShaderOp->Shaders.at(0).Arguments = compilerOptions;
  6946. pShaderOp->Shaders.at(0).Text = rawBufferTestShaderText;
  6947. VERIFY_IS_TRUE(sizeof(RawBufferLdStTestData<Ty>) <= Data.size());
  6948. RawBufferLdStTestData<Ty> *pInData = (RawBufferLdStTestData<Ty>*)Data.data();
  6949. memcpy(pInData, &testData, sizeof(RawBufferLdStTestData<Ty>));
  6950. });
  6951. // verify expected values
  6952. VerifyRawBufferLdStTestResults<Ty>(test->Test, testData);
  6953. }
  6954. template <class Ty>
  6955. void ExecutionTest::RunGraphicsRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6956. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData) {
  6957. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6958. CComPtr<ID3D12Device> pDevice;
  6959. CComPtr<IStream> pStream;
  6960. char *sTy = nullptr, *additionalOptions = nullptr;
  6961. if (!SetupRawBufferLdStTest(shaderModel, dataType, pDevice, pStream, sTy, additionalOptions)) {
  6962. return;
  6963. }
  6964. // format shader source
  6965. char rawBufferTestPixelShaderText[sizeof(RawBufferTestGraphicsPixelShaderTemplate) + sizeof(RawBufferTestShaderDeclarations) + sizeof(RawBufferTestShaderBody)];
  6966. VERIFY_IS_TRUE(sprintf_s(rawBufferTestPixelShaderText, sizeof(rawBufferTestPixelShaderText),
  6967. RawBufferTestGraphicsPixelShaderTemplate, RawBufferTestShaderDeclarations, RawBufferTestShaderBody) != -1);
  6968. // format compiler args
  6969. char compilerOptions[256];
  6970. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D COMPONENT_TYPE=%s -D COMPONENT_SIZE=%d %s", sTy, (int)sizeof(Ty), additionalOptions) != -1);
  6971. // run the shader
  6972. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, shaderOpName,
  6973. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6974. VERIFY_IS_TRUE(((0 == strncmp(Name, "SRVBuffer", 9)) || (0 == strncmp(Name, "UAVBuffer", 9))) &&
  6975. (Name[9] >= '0' && Name[9] <= '3'));
  6976. // pixel shader is at index 1, vertex shader at index 0
  6977. pShaderOp->Shaders.at(1).Arguments = compilerOptions;
  6978. pShaderOp->Shaders.at(1).Text = rawBufferTestPixelShaderText;
  6979. VERIFY_IS_TRUE(sizeof(RawBufferLdStTestData<Ty>) <= Data.size());
  6980. RawBufferLdStTestData<Ty> *pInData = (RawBufferLdStTestData<Ty>*)Data.data();
  6981. memcpy(pInData, &testData, sizeof(RawBufferLdStTestData<Ty>));
  6982. });
  6983. // verify expected values
  6984. VerifyRawBufferLdStTestResults<Ty>(test->Test, testData);
  6985. }
  6986. template<typename T>
  6987. uint32_t pack(std::array<T, 4> unpackedVals)
  6988. {
  6989. uint32_t dst = 0;
  6990. constexpr uint32_t bitMask = 0xFF;
  6991. for (uint32_t i = 0U; i < 4U; ++i)
  6992. {
  6993. dst |= (unpackedVals[i] & bitMask) << (i * 8);
  6994. }
  6995. return dst;
  6996. }
  6997. template <typename T>
  6998. uint32_t pack_clamp_u8(std::array<T, 4> unpackedVals)
  6999. {
  7000. int32_t clamp_min = std::numeric_limits<uint8_t>::min();
  7001. int32_t clamp_max = std::numeric_limits<uint8_t>::max();
  7002. uint32_t dst = 0;
  7003. for (uint32_t i = 0U; i < 4U; ++i)
  7004. {
  7005. int32_t clamped = std::min(std::max((int32_t)unpackedVals[i], clamp_min), clamp_max);
  7006. dst |= ((uint8_t)clamped) << (i * 8);
  7007. }
  7008. return dst;
  7009. }
  7010. template <typename T>
  7011. uint32_t pack_clamp_s8(std::array<T, 4> unpackedVals)
  7012. {
  7013. int32_t clamp_min = std::numeric_limits<int8_t>::min();
  7014. int32_t clamp_max = std::numeric_limits<int8_t>::max();
  7015. uint32_t dst = 0;
  7016. for (uint32_t i = 0U; i < 4U; ++i)
  7017. {
  7018. int32_t clamped = std::min(std::max((int32_t)unpackedVals[i], clamp_min), clamp_max);
  7019. dst |= ((uint8_t)clamped) << (i * 8);
  7020. }
  7021. return dst;
  7022. }
  7023. template<typename T>
  7024. std::array<T, 4> unpack_u(uint32_t packedVal)
  7025. {
  7026. std::array<T, 4> ret;
  7027. ret[0] = (uint8_t)((packedVal & 0x000000FF) >> 0 );
  7028. ret[1] = (uint8_t)((packedVal & 0x0000FF00) >> 8 );
  7029. ret[2] = (uint8_t)((packedVal & 0x00FF0000) >> 16);
  7030. ret[3] = (uint8_t)((packedVal & 0xFF000000) >> 24);
  7031. return ret;
  7032. }
  7033. template<typename T>
  7034. std::array<T, 4> unpack_s(uint32_t packedVal)
  7035. {
  7036. std::array<T, 4> ret;
  7037. ret[0] = (int8_t)((packedVal & 0x000000FF) >> 0 );
  7038. ret[1] = (int8_t)((packedVal & 0x0000FF00) >> 8 );
  7039. ret[2] = (int8_t)((packedVal & 0x00FF0000) >> 16);
  7040. ret[3] = (int8_t)((packedVal & 0xFF000000) >> 24);
  7041. return ret;
  7042. }
  7043. TEST_F(ExecutionTest, PackUnpackTest) {
  7044. WEX::TestExecution::SetVerifyOutput verifySettings(
  7045. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7046. CComPtr<IStream> pStream;
  7047. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7048. CComPtr<ID3D12Device> pDevice;
  7049. #ifdef PACKUNPACK_PLACEHOLDER
  7050. string args = "-enable-16bit-types -DPACKUNPACK_PLACEHOLDER";
  7051. string target = "cs_6_2";
  7052. if (!CreateDevice(&pDevice)) {
  7053. return;
  7054. }
  7055. #else
  7056. string args = "-enable-16bit-types";
  7057. string target = "cs_6_6";
  7058. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6)) {
  7059. return;
  7060. }
  7061. #endif
  7062. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  7063. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  7064. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7065. return;
  7066. }
  7067. int tableSize = sizeof(PackUnpackOpParameters) / sizeof(TableParameter);
  7068. TableParameterHandler handler(PackUnpackOpParameters, tableSize);
  7069. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  7070. std::vector<uint32_t> *validation_input = &handler.GetTableParamByName(L"Validation.Input")->m_uint32Table;
  7071. uint32_t validation_tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_uint;
  7072. size_t count = validation_input->size();
  7073. std::vector<SPackUnpackOpOutPacked> expectedPacked(count / 4);
  7074. std::vector<SPackUnpackOpOutUnpacked> expectedUnpacked(count / 4);
  7075. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  7076. pDevice, m_support, pStream, "PackUnpackOp",
  7077. // this callback is called when the test
  7078. // is creating the resource to run the test
  7079. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  7080. if (0 == _stricmp(Name, "g_bufIn"))
  7081. {
  7082. size_t size = sizeof(uint32_t) * 4 * count;
  7083. Data.resize(size);
  7084. uint32_t *pPrimitives = (uint32_t*)Data.data();
  7085. for (size_t i = 0; i < count / 4; ++i) {
  7086. uint32_t *p = &pPrimitives[i * 4];
  7087. uint32_t x = (*validation_input)[i * 4 + 0];
  7088. uint32_t y = (*validation_input)[i * 4 + 1];
  7089. uint32_t z = (*validation_input)[i * 4 + 2];
  7090. uint32_t w = (*validation_input)[i * 4 + 3];
  7091. p[0] = x;
  7092. p[1] = y;
  7093. p[2] = z;
  7094. p[3] = w;
  7095. std::array<uint32_t, 4> inputUint32 = { x, y, z, w };
  7096. std::array<int32_t, 4> inputInt32 = { (int32_t)x, (int32_t)y, (int32_t)z, (int32_t)w };
  7097. std::array<uint16_t, 4> inputUint16 = { (uint16_t)x, (uint16_t)y, (uint16_t)z, (uint16_t)w };
  7098. std::array<int16_t, 4> inputInt16 = { (int16_t)x, (int16_t)y, (int16_t)z, (int16_t)w };
  7099. // Pack unclamped
  7100. expectedPacked[i].packedUint32 = pack(inputUint32);
  7101. expectedPacked[i].packedInt32 = pack(inputInt32);
  7102. expectedPacked[i].packedUint16 = pack(inputUint16);
  7103. expectedPacked[i].packedInt16 = pack(inputInt16);
  7104. // pack clamped
  7105. expectedPacked[i].packedClampedUint32 = pack_clamp_u8(inputInt32);
  7106. expectedPacked[i].packedClampedInt32 = pack_clamp_s8(inputInt32);
  7107. expectedPacked[i].packedClampedUint16 = pack_clamp_u8(inputInt16);
  7108. expectedPacked[i].packedClampedInt16 = pack_clamp_s8(inputInt16);
  7109. // unpack
  7110. expectedUnpacked[i].outputUint32 = unpack_u<uint32_t>(expectedPacked[i].packedUint32);
  7111. expectedUnpacked[i].outputInt32 = unpack_s<int32_t >(expectedPacked[i].packedInt32 );
  7112. expectedUnpacked[i].outputUint16 = unpack_u<uint16_t>(expectedPacked[i].packedUint16);
  7113. expectedUnpacked[i].outputInt16 = unpack_s<int16_t >(expectedPacked[i].packedInt16 );
  7114. expectedUnpacked[i].outputClampedUint32 = unpack_u<uint32_t>(expectedPacked[i].packedClampedUint32);
  7115. expectedUnpacked[i].outputClampedInt32 = unpack_s<int32_t >(expectedPacked[i].packedClampedInt32 );
  7116. expectedUnpacked[i].outputClampedUint16 = unpack_u<uint16_t>(expectedPacked[i].packedClampedUint16);
  7117. expectedUnpacked[i].outputClampedInt16 = unpack_s<int16_t >(expectedPacked[i].packedClampedInt16 );
  7118. }
  7119. }
  7120. else
  7121. {
  7122. std::fill(Data.begin(), Data.end(), (BYTE)0);
  7123. }
  7124. // use shader from data table
  7125. pShaderOp->Shaders.at(0).Target = target.c_str();
  7126. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  7127. pShaderOp->Shaders.at(0).Arguments = args.c_str();
  7128. });
  7129. MappedData packedData;
  7130. test->Test->GetReadBackData("g_bufOutPacked", &packedData);
  7131. SPackUnpackOpOutPacked *readBackPacked = (SPackUnpackOpOutPacked *)packedData.data();
  7132. MappedData unpackedData;
  7133. test->Test->GetReadBackData("g_bufOutPackedUnpacked", &unpackedData);
  7134. SPackUnpackOpOutUnpacked *readBackUnpacked = (SPackUnpackOpOutUnpacked *)unpackedData.data();
  7135. for (size_t i = 0; i < count / 4; ++i)
  7136. {
  7137. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedUint32, expectedPacked[i].packedUint32, validation_tolerance);
  7138. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedInt32 , expectedPacked[i].packedInt32 , validation_tolerance);
  7139. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedUint16, expectedPacked[i].packedUint16, validation_tolerance);
  7140. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedInt16 , expectedPacked[i].packedInt16 , validation_tolerance);
  7141. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedClampedUint32, expectedPacked[i].packedClampedUint32, validation_tolerance);
  7142. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedClampedInt32 , expectedPacked[i].packedClampedInt32 , validation_tolerance);
  7143. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedClampedUint16, expectedPacked[i].packedClampedUint16, validation_tolerance);
  7144. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedClampedInt16 , expectedPacked[i].packedClampedInt16 , validation_tolerance);
  7145. for (uint32_t j = 0; j < 4; ++j)
  7146. {
  7147. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputUint32[j], expectedUnpacked[i].outputUint32[j], validation_tolerance);
  7148. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputInt32 [j], expectedUnpacked[i].outputInt32 [j], validation_tolerance);
  7149. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputUint16[j], expectedUnpacked[i].outputUint16[j], validation_tolerance);
  7150. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputInt16 [j], expectedUnpacked[i].outputInt16 [j], validation_tolerance);
  7151. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputClampedUint32[j], expectedUnpacked[i].outputClampedUint32[j], validation_tolerance);
  7152. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputClampedInt32 [j], expectedUnpacked[i].outputClampedInt32 [j], validation_tolerance);
  7153. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputClampedUint16[j], expectedUnpacked[i].outputClampedUint16[j], validation_tolerance);
  7154. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputClampedInt16 [j], expectedUnpacked[i].outputClampedInt16 [j], validation_tolerance);
  7155. }
  7156. }
  7157. }
  7158. // This test expects a <pShader> that retrieves a signal value from each of a few
  7159. // resources that are initialized here. <isDynamic> determines if it uses the
  7160. // 6.6 Dynamic Resources feature.
  7161. // Values are read back from the result UAV and compared to the expected signals
  7162. void ExecutionTest::RunResourceTest(ID3D12Device *pDevice, const char *pShader,
  7163. const wchar_t *sm, bool isDynamic) {
  7164. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7165. const int NumSRVs = 3;
  7166. const int NumUAVs = 4;
  7167. const int NumResources = NumSRVs + NumUAVs;
  7168. const int NumSamplers = 2;
  7169. const int valueSize = 16;
  7170. static const int DispatchGroupX = 1;
  7171. static const int DispatchGroupY = 1;
  7172. static const int DispatchGroupZ = 1;
  7173. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  7174. CComPtr<ID3D12CommandQueue> pCommandQueue;
  7175. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  7176. FenceObj FO;
  7177. UINT valueSizeInBytes = valueSize * sizeof(float);
  7178. CreateComputeCommandQueue(pDevice, L"DynamicResourcesTest Command Queue", &pCommandQueue);
  7179. InitFenceObj(pDevice, &FO);
  7180. // Create root signature.
  7181. CComPtr<ID3D12RootSignature> pRootSignature;
  7182. if (!isDynamic) {
  7183. // Not dynamic, create a range for each resource and from them, the root signature
  7184. CD3DX12_DESCRIPTOR_RANGE ranges[NumResources];
  7185. CD3DX12_DESCRIPTOR_RANGE srange[NumSamplers];
  7186. for (int i = 0; i < NumSRVs; i++)
  7187. ranges[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, i, 0);
  7188. for (int i = NumSRVs; i < NumResources; i++)
  7189. ranges[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, i - NumSRVs, 0);
  7190. for (int i = 0; i < NumSamplers; i++)
  7191. srange[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, i, 0);
  7192. CreateRootSignatureFromRanges(pDevice, &pRootSignature, ranges, NumResources, srange, NumSamplers);
  7193. } else {
  7194. // Dynamic just requires the flags indicating that the builtin arrays should be accessible
  7195. #if !defined(D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED)
  7196. #define D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED (D3D12_ROOT_SIGNATURE_FLAGS)0x400
  7197. #define D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED (D3D12_ROOT_SIGNATURE_FLAGS)0x800
  7198. #endif
  7199. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  7200. rootSignatureDesc.Init(0, nullptr, 0, nullptr,
  7201. D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED |
  7202. D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED);
  7203. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  7204. }
  7205. // Create pipeline state object.
  7206. CComPtr<ID3D12PipelineState> pComputeState;
  7207. CreateComputePSO(pDevice, pRootSignature, pShader, sm, &pComputeState);
  7208. // Create a command allocator and list for compute.
  7209. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  7210. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  7211. // Set up SRV resources
  7212. CComPtr<ID3D12Resource> pSRVResources[NumSRVs];
  7213. CComPtr<ID3D12Resource> pUAVResources[NumUAVs];
  7214. CComPtr<ID3D12Resource> pUploadResources[NumResources];
  7215. {
  7216. D3D12_RESOURCE_DESC bufDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes);
  7217. float values[valueSize];
  7218. for (int i = 0; i < NumSRVs - 1; i++) {
  7219. for (int j = 0; j < valueSize; j++)
  7220. values[j] = 10.0f + i;
  7221. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, bufDesc,
  7222. &pSRVResources[i], &pUploadResources[i]);
  7223. }
  7224. D3D12_RESOURCE_DESC tex2dDesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R32_FLOAT, 4, 4);
  7225. for (int j = 0; j < valueSize; j++)
  7226. values[j] = 10.0 + (NumSRVs - 1);
  7227. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, tex2dDesc,
  7228. &pSRVResources[NumSRVs - 1], &pUploadResources[NumSRVs - 1]);
  7229. }
  7230. // Set up UAV resources
  7231. CComPtr<ID3D12Resource> pReadBuffer;
  7232. float values[valueSize];
  7233. for (int i = 0; i < NumUAVs - 2; i++) {
  7234. for (int j = 0; j < valueSize; j++)
  7235. values[j] = 20.0f + i;
  7236. CreateTestUavs(pDevice, pCommandList, values, valueSizeInBytes,
  7237. &pUAVResources[i], &pUploadResources[NumSRVs + i]);
  7238. }
  7239. for (int j = 0; j < valueSize; j++)
  7240. values[j] = 20.0 + (NumUAVs - 1);
  7241. CreateTestUavs(pDevice, pCommandList, values, valueSizeInBytes,
  7242. &pUAVResources[NumUAVs - 2], &pUploadResources[NumResources - 2], &pReadBuffer);
  7243. for (int j = 0; j < valueSize; j++)
  7244. values[j] = 20.0 + (NumUAVs - 2);
  7245. D3D12_RESOURCE_DESC tex1dDesc = CD3DX12_RESOURCE_DESC::Tex1D(DXGI_FORMAT_R32_FLOAT, valueSize, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
  7246. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, tex1dDesc,
  7247. &pUAVResources[NumUAVs - 1], &pUploadResources[NumResources - 1]);
  7248. // Close the command list and execute it to perform the GPU setup.
  7249. pCommandList->Close();
  7250. ExecuteCommandList(pCommandQueue, pCommandList);
  7251. WaitForSignal(pCommandQueue, FO);
  7252. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  7253. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  7254. CComPtr<ID3D12DescriptorHeap> pResHeap;
  7255. CComPtr<ID3D12DescriptorHeap> pSampHeap;
  7256. CreateDefaultDescHeaps(pDevice, NumSRVs + NumUAVs, NumSamplers, &pResHeap, &pSampHeap);
  7257. // Create Rootsignature and descriptor tables
  7258. {
  7259. ID3D12DescriptorHeap *descHeaps[2] = {pResHeap, pSampHeap};
  7260. pCommandList->SetDescriptorHeaps(2, descHeaps);
  7261. pCommandList->SetComputeRootSignature(pRootSignature);
  7262. if (!isDynamic) {
  7263. // Only non-dynamic resources require descriptortables
  7264. pCommandList->SetComputeRootDescriptorTable(0, pResHeap->GetGPUDescriptorHandleForHeapStart());
  7265. pCommandList->SetComputeRootDescriptorTable(1, pSampHeap->GetGPUDescriptorHandleForHeapStart());
  7266. }
  7267. }
  7268. CD3DX12_CPU_DESCRIPTOR_HANDLE baseHandle(pResHeap->GetCPUDescriptorHandleForHeapStart());
  7269. // Create SRVs
  7270. CreateRawSRV(pDevice, baseHandle, valueSize, pSRVResources[0]);
  7271. CreateStructSRV(pDevice, baseHandle, valueSize, sizeof(float), pSRVResources[1]);
  7272. CreateTex2DSRV(pDevice, baseHandle, valueSize, DXGI_FORMAT_R32_FLOAT, pSRVResources[2]);
  7273. // Create UAVs
  7274. CreateRawUAV(pDevice, baseHandle, valueSize, pUAVResources[0]);
  7275. CreateStructUAV(pDevice, baseHandle, valueSize, sizeof(float), pUAVResources[1]);
  7276. CreateTypedUAV(pDevice, baseHandle, valueSize, DXGI_FORMAT_R32_FLOAT, pUAVResources[2]);
  7277. CreateTex1DUAV(pDevice, baseHandle, valueSize, DXGI_FORMAT_R32_FLOAT, pUAVResources[3]);
  7278. D3D12_FILTER filters[] = {D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D12_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT};
  7279. float borderColors[] = {30.0, 31.0};
  7280. CreateDefaultSamplers(pDevice, pSampHeap->GetCPUDescriptorHandleForHeapStart(),
  7281. filters, borderColors, NumSamplers);
  7282. // Run the compute shader and copy the results back to readable memory.
  7283. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  7284. RecordTransitionBarrier(pCommandList, pUAVResources[NumUAVs - 2], D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  7285. pCommandList->CopyResource(pReadBuffer, pUAVResources[NumUAVs - 2]);
  7286. pCommandList->Close();
  7287. ExecuteCommandList(pCommandQueue, pCommandList);
  7288. WaitForSignal(pCommandQueue, FO);
  7289. MappedData data(pReadBuffer, valueSize*sizeof(float));
  7290. const float *pData = (float*)data.data();
  7291. LogCommentFmt(L"Verify bound resources are properly selected");
  7292. VERIFY_ARE_EQUAL(pData[0], 10);
  7293. VERIFY_ARE_EQUAL(pData[1], 11);
  7294. VERIFY_ARE_EQUAL(pData[2], 12);
  7295. VERIFY_ARE_EQUAL(pData[3], 20);
  7296. VERIFY_ARE_EQUAL(pData[4], 21);
  7297. VERIFY_ARE_EQUAL(pData[5], 22);
  7298. VERIFY_ARE_EQUAL(pData[6], 30);
  7299. VERIFY_ARE_EQUAL(pData[7], 1); // samplecmp 1 means it matched 31
  7300. }
  7301. TEST_F(ExecutionTest, SignatureResourcesTest) {
  7302. std::string pShader =
  7303. "ByteAddressBuffer g_rawBuf : register(t0);\n"
  7304. "StructuredBuffer<float> g_structBuf : register(t1);\n"
  7305. "Texture2D<float> g_tex : register(t2);\n"
  7306. "RWByteAddressBuffer g_rwRawBuf : register(u0);\n"
  7307. "RWStructuredBuffer<float> g_rwStructBuf : register(u1);\n"
  7308. "RWBuffer<float> g_result : register(u2);\n"
  7309. "RWTexture1D<float> g_rwTex : register(u3);\n"
  7310. "SamplerState g_samp : register(s0);\n"
  7311. "SamplerComparisonState g_sampCmp : register(s1);\n"
  7312. "[NumThreads(1, 1, 1)]\n"
  7313. "void main(uint ix : SV_GroupIndex) {\n"
  7314. " g_result[0] = g_rawBuf.Load<float>(0);\n"
  7315. " g_result[1] = g_structBuf.Load(0);\n"
  7316. " g_result[2] = g_tex.Load(0);\n"
  7317. " g_result[3] = g_rwRawBuf.Load<float>(0);\n"
  7318. " g_result[4] = g_rwStructBuf.Load(0);\n"
  7319. " g_result[5] = g_rwTex.Load(0);\n"
  7320. " g_result[6] = g_tex.SampleLevel(g_samp, -0.5, 0);\n"
  7321. " g_result[7] = g_tex.SampleCmpLevelZero(g_sampCmp, -0.5, 31.0);\n"
  7322. "}\n";
  7323. CComPtr<ID3D12Device> pDevice;
  7324. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7325. return;
  7326. RunResourceTest(pDevice, pShader.c_str(), L"cs_6_6", /*isDynamic*/false);
  7327. }
  7328. TEST_F(ExecutionTest, DynamicResourcesTest) {
  7329. static const char pShader[] =
  7330. "static ByteAddressBuffer g_rawBuf = ResourceDescriptorHeap[0];\n"
  7331. "static StructuredBuffer<float> g_structBuf = ResourceDescriptorHeap[1];\n"
  7332. "static Texture2D<float> g_tex = ResourceDescriptorHeap[2];\n"
  7333. "static RWByteAddressBuffer g_rwRawBuf = ResourceDescriptorHeap[3];\n"
  7334. "static RWStructuredBuffer<float> g_rwStructBuf = ResourceDescriptorHeap[4];\n"
  7335. "static RWBuffer<float> g_result = ResourceDescriptorHeap[5];\n"
  7336. "static RWTexture1D<float> g_rwTex = ResourceDescriptorHeap[6];\n"
  7337. "static SamplerState g_samp = SamplerDescriptorHeap[0];\n"
  7338. "static SamplerComparisonState g_sampCmp = SamplerDescriptorHeap[1];\n"
  7339. "[NumThreads(1, 1, 1)]\n"
  7340. "void main(uint ix : SV_GroupIndex) {\n"
  7341. " g_result[0] = g_rawBuf.Load<float>(0);\n"
  7342. " g_result[1] = g_structBuf.Load(0);\n"
  7343. " g_result[2] = g_tex.Load(0);\n"
  7344. " g_result[3] = g_rwRawBuf.Load<float>(0);\n"
  7345. " g_result[4] = g_rwStructBuf.Load(0);\n"
  7346. " g_result[5] = g_rwTex.Load(0);\n"
  7347. " g_result[6] = g_tex.SampleLevel(g_samp, -0.5, 0);\n"
  7348. " g_result[7] = g_tex.SampleCmpLevelZero(g_sampCmp, -0.5, 31.0);\n"
  7349. "}\n";
  7350. CComPtr<ID3D12Device> pDevice;
  7351. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7352. return;
  7353. // ResourceDescriptorHeap/SamplerDescriptorHeap requires Resource Binding Tier 3
  7354. D3D12_FEATURE_DATA_D3D12_OPTIONS devOptions;
  7355. VERIFY_SUCCEEDED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS, &devOptions, sizeof(devOptions)));
  7356. if (devOptions.ResourceBindingTier < D3D12_RESOURCE_BINDING_TIER_3) {
  7357. WEX::Logging::Log::Comment(L"Device does not support Resource Binding Tier 3");
  7358. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7359. return;
  7360. }
  7361. RunResourceTest(pDevice, pShader, L"cs_6_6", /*isDynamic*/true);
  7362. }
  7363. #define MAX_WAVESIZE 128
  7364. #define strinfigy2(arg) #arg
  7365. #define strinfigy(arg) strinfigy2(arg)
  7366. void ExecutionTest::WaveSizeTest() {
  7367. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7368. CComPtr<ID3D12Device> pDevice;
  7369. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6)) {
  7370. return;
  7371. }
  7372. // Check Wave support
  7373. if (!DoesDeviceSupportWaveOps(pDevice)) {
  7374. // Optional feature, so it's correct to not support it if declared as such.
  7375. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  7376. return;
  7377. }
  7378. // Get supported wave sizes
  7379. D3D12_FEATURE_DATA_D3D12_OPTIONS1 waveOpts;
  7380. VERIFY_SUCCEEDED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &waveOpts, sizeof(waveOpts)));
  7381. UINT minWaveSize = waveOpts.WaveLaneCountMin;
  7382. UINT maxWaveSize = waveOpts.WaveLaneCountMax;
  7383. DXASSERT_NOMSG(minWaveSize <= maxWaveSize);
  7384. DXASSERT((minWaveSize & (minWaveSize - 1)) == 0, "must be a power of 2");
  7385. DXASSERT((maxWaveSize & (maxWaveSize - 1)) == 0, "must be a power of 2");
  7386. // read shader config
  7387. CComPtr<IStream> pStream;
  7388. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  7389. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7390. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7391. // format shader source
  7392. const char waveSizeTestShader[] =
  7393. "struct TestData { \r\n"
  7394. " uint count; \r\n"
  7395. "}; \r\n"
  7396. "RWStructuredBuffer<TestData> data : register(u0); \r\n"
  7397. "\r\n"
  7398. "// Note: WAVESIZE will be defined via compiler option -D\r\n"
  7399. "[wavesize(WAVESIZE)]\r\n"
  7400. "[numthreads(" strinfigy(MAX_WAVESIZE) "*2,1,1)]\r\n"
  7401. "void main(uint3 tid : SV_DispatchThreadID ) { \r\n"
  7402. " data[tid.x].count = WaveActiveSum(1); \r\n"
  7403. "}\r\n";
  7404. struct WaveSizeTestData {
  7405. uint32_t count;
  7406. };
  7407. for (UINT waveSize = minWaveSize; waveSize <= maxWaveSize; waveSize *= 2) {
  7408. // format compiler args
  7409. char compilerOptions[32];
  7410. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D WAVESIZE=%d", waveSize) != -1);
  7411. // run the shader
  7412. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "WaveSizeTest",
  7413. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  7414. VERIFY_IS_TRUE((0 == strncmp(Name, "UAVBuffer0", 10)));
  7415. pShaderOp->Shaders.at(0).Arguments = compilerOptions;
  7416. pShaderOp->Shaders.at(0).Text = waveSizeTestShader;
  7417. VERIFY_IS_TRUE(sizeof(WaveSizeTestData)*MAX_WAVESIZE <= Data.size());
  7418. WaveSizeTestData *pInData = (WaveSizeTestData *)Data.data();
  7419. memset(&pInData, sizeof(WaveSizeTestData)*MAX_WAVESIZE, 0);
  7420. }, ShaderOpSet);
  7421. // verify expected values
  7422. MappedData dataUav;
  7423. WaveSizeTestData *pOutData;
  7424. test->Test->GetReadBackData("UAVBuffer0", &dataUav);
  7425. VERIFY_ARE_EQUAL(sizeof(WaveSizeTestData)*MAX_WAVESIZE, dataUav.size());
  7426. pOutData = (WaveSizeTestData*)dataUav.data();
  7427. LogCommentFmt(L"Verifying test result for wave size %d", waveSize);
  7428. for (unsigned i = 0; i < MAX_WAVESIZE; i++) {
  7429. if (!VERIFY_ARE_EQUAL(pOutData[i].count, waveSize))
  7430. break;
  7431. }
  7432. }
  7433. }
  7434. // Atomic operation testing
  7435. // Atomic tests take a single integer index as input and contort it into some
  7436. // kind of interesting contributor to the operation in question.
  7437. // So each vertex, pixel, thread, or other will have a unique index that produces
  7438. // a contributing value to the calculation which is stored in a small resource
  7439. // For arithmetic or bitwise operations, each contributor accumulates to the same
  7440. // location in the resource indexed by the operation type. Addition is in index 0
  7441. // umin/umax are in 1 and 2 and so on.
  7442. // To make sure that the most significant bits are involved in the calculation,
  7443. // particularly in the case of 64-bit values, each contributing value is duplicated
  7444. // to the lower and upper halves of the value. There is an exception to this when
  7445. // addition exceeds the available size and also for compare and exchange explained below.
  7446. // For compare and exchange operations, 64 output locations are shared by the various lanes.
  7447. // Each lane attempts to write to a location that is shared with several others.
  7448. // The first one to write to it determines its contents, which will be the lane index <ix>
  7449. // in the upper bits and the output location index in the lower bits.
  7450. // This ensures that the compare operations consider the upper bits in the comparison.
  7451. // The initial compare store is followed by a compare exchange that compares for the
  7452. // value the current lane would have assigned there. Finally, the output of the cmpxchg
  7453. // is used to determine if the current lane should perform the final unconditional exchange.
  7454. // The values are verified by checking the lower bits for the matching location index
  7455. // and ensuring that the upper bits undergoing the same transformation result in the location index.
  7456. // For lane index <ix> the location is calculated and final result assigned as if by this code:
  7457. // g_outputBuf[(ix/3)%64] = (ix << shBits) | ((ix/3)%64);
  7458. bool AtomicResultMatches(const BYTE *uResults, uint64_t gold, size_t size) {
  7459. if (memcmp(uResults, &gold, size)) {
  7460. if (size == 4)
  7461. LogCommentFmt(L" value %d is not %d", ((uint32_t*)uResults)[0], (uint32_t)gold);
  7462. else
  7463. LogCommentFmt(L" value %lld is not %lld", ((uint64_t*)uResults)[0], gold);
  7464. return false;
  7465. }
  7466. return true;
  7467. }
  7468. // Used to duplicate the lower half bits into the upper half bits of an integer
  7469. // To verify that the full value is being considered, many tests duplicate the results into the upper half
  7470. #define SHIFT(val, bits) (((val)&((1ULL<<(bits))-1ULL)) | ((uint64_t)(val) << (bits)))
  7471. // Symbolic constants for the results
  7472. #define ADD_IDX 0
  7473. #define UMIN_IDX 1
  7474. #define UMAX_IDX 2
  7475. #define AND_IDX 3
  7476. #define OR_IDX 4
  7477. #define XOR_IDX 5
  7478. #define SMIN_IDX 0
  7479. #define SMAX_IDX 1
  7480. // Verify results for atomic operations. <uResults> and <sResults> are pointers to
  7481. // the readback resource sections containing unsigned and signed integers respectively.
  7482. // <pXchg> is a poiner to the readback resource containing the results of the compare
  7483. // and exchange operations tests. <stride> is the number of bytes between results for
  7484. // all of the results pointers. <maxIdx> is the number of indices that went into the results
  7485. // which is used to determine what the results should be. <bitSize> is the size in bits of
  7486. // the produced results, either 32 or 64.
  7487. void VerifyAtomicResults(const BYTE *uResults, const BYTE *sResults,
  7488. const BYTE *pXchg, size_t stride, uint64_t maxIdx, size_t bitSize) {
  7489. // Each atomic test performs the test on the value in the lower half
  7490. // and also duplicated in the upper half of the value. The SHIFT macros account for this.
  7491. // This is to verify that the upper bits are considered
  7492. uint64_t shBits = bitSize/2;
  7493. size_t byteSize = bitSize/8;
  7494. // Test ADD Operation
  7495. // ADD just sums all the indices. The result should the sum of the highest and lowest indices
  7496. // multiplied by half the number of sums.
  7497. uint64_t addResult = (maxIdx)*(maxIdx-1)/2;
  7498. LogCommentFmt(L"Verifying %d-bit integer atomic add", bitSize);
  7499. // For 32-bit values, the sum exceeds the 16 bit limit, so we can't duplicate
  7500. // That's fine, the duplication is really for 64-bit values.
  7501. if (bitSize < 64)
  7502. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*ADD_IDX, addResult, byteSize));
  7503. else
  7504. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*ADD_IDX, SHIFT(addResult, shBits), byteSize));
  7505. // Test MIN and MAX Operations
  7506. // The result of a simple min and max of any sequence of indices would be fairly uninteresting
  7507. // and certain erroneous behavior might mistakenly produce the correct results.
  7508. // To make it interesting, the contributing values will change depending on the evenness of the index.
  7509. // On an even index, min and max operate on the bitflipped index. For signed compares, this is
  7510. // interpretted as a negative value and for unsigned, a very high value.
  7511. // For unsigned min/max, index 0 will be bitflipped to ~0, which is interpretted as the maximum
  7512. // Because zero is manipulated, this leaves 1 as the lowest value.
  7513. LogCommentFmt(L"Verifying %d-bit integer atomic umin", bitSize);
  7514. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*UMIN_IDX, SHIFT(1ULL, shBits), byteSize)); // UMin
  7515. LogCommentFmt(L"Verifying %d-bit integer atomic umax", bitSize);
  7516. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*UMAX_IDX, ~0ULL, byteSize)); // UMax
  7517. // For signed min/max, the index just before the last will be bitflipped (maxIndex is always even).
  7518. // This is interpretted as -(maxIndex-1) and will be the lowest
  7519. // The maxIndex will be unaltered and interpretted as the highest.
  7520. LogCommentFmt(L"Verifying %d-bit integer atomic smin", bitSize);
  7521. VERIFY_IS_TRUE(AtomicResultMatches(sResults + stride*SMIN_IDX, SHIFT(-((int64_t)maxIdx-1), shBits), byteSize)); // SMin
  7522. LogCommentFmt(L"Verifying %d-bit integer atomic smax", bitSize);
  7523. VERIFY_IS_TRUE(AtomicResultMatches(sResults + stride*SMAX_IDX, SHIFT(maxIdx-1, shBits), byteSize)); // SMax
  7524. // Test AND and OR operations.
  7525. // For AND operations, all indices are bitflipped and ANDed to the previous result.
  7526. // This means that the highest bits, which are never set by the contributing indices will be set
  7527. // for all the indices, so they will be set in the final result.
  7528. // For OR operations, the indices are ORed to the previous result unaltered
  7529. // This means that any bit that is set in any index will be set in the final OR result.
  7530. // In practice, this means that the cumulative result of the AND and OR operations
  7531. // are bitflipped versions of each other.
  7532. // Finding the most significant set bit by the max index or next power of two (pot)
  7533. // gives us the pivot point for these results
  7534. uint64_t nextPot = 1ULL << (bitSize - 1);
  7535. for (;nextPot && !((maxIdx-1) & (nextPot)); nextPot >>= 1) {}
  7536. nextPot <<= 1;
  7537. LogCommentFmt(L"Verifying %d-bit integer atomic and", bitSize);
  7538. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*AND_IDX, ~SHIFT(nextPot-1, shBits), byteSize)); // And
  7539. LogCommentFmt(L"Verifying %d-bit integer atomic or", bitSize);
  7540. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*OR_IDX, SHIFT(nextPot-1, shBits), byteSize)); // Or
  7541. // Test XOR operation
  7542. // For XOR operations, a 1 is shifted by the number of spaces equal to the index and XORed
  7543. // to the previous result. Because this would rapidely shift off the end of the value,
  7544. // giving undefined and uninteresting results, the index is moduloed to a value that will
  7545. // fit within the type size.
  7546. // Because many of the tests use total numbers of lanes that can be evenly divisible by 32 or 64,
  7547. // these values aren't used for the modulo since the expected result might be zero,
  7548. // which could be encountered through erroneous behavior.
  7549. // Instead, one less than the type size in bits is used for the modulo.
  7550. // Even though we don't know the actual order these operations are performed,
  7551. // indices that make up a contiguous sequence of 31 or 63 values can be thought of as one of a series of "passes".
  7552. // Each "pass" sets or clears the bits depending on what's already there.
  7553. // if the number of the pass is odd, the bits are being unset and all above the mod position should be set.
  7554. // If even, the bits are in the process of being set and bits below the mod position should be set.
  7555. uint64_t xorResult = ((1ULL<<((maxIdx)%(bitSize-1))) -1);
  7556. if (((maxIdx/(bitSize-1))&1)) {
  7557. xorResult ^= ~0ULL;
  7558. // The XOR above may set uninvolved upper bits, messing up the compare. So AND off the uninvolved bits.
  7559. xorResult &= ((1ULL<<(bitSize-1)) - 1);
  7560. }
  7561. LogCommentFmt(L"Verifying %d-bit integer atomic xor", bitSize);
  7562. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*XOR_IDX, xorResult, byteSize));
  7563. // Test CMP/XCHG Operations
  7564. // This tests CompareStore, CompareExchange, and Exchange operations.
  7565. // Unlike above, every lane isn't contributing to the same resource location
  7566. // Instead, every lane competes with a few others to update the same resource location.
  7567. // The first lane to find the contents of their location uninitialized will
  7568. // update it. To verify that upper bits are considered in the comparison and
  7569. // in the assignment, the value stored in the lowest bits is the location index.
  7570. // This ensures that part will be the same for each of the competing lanes.
  7571. // The uppermost bits are updated with the index of the lane that got there first.
  7572. // Subsequent calls to CompareExchange will verify this value matches and alter
  7573. // the content slightly. Finally, a simple check of the output value to what
  7574. // the current lane would expect and a call to exchange will update the value once more
  7575. // To verify this has gone through properly, the upper portion is converted as
  7576. // if to calculate the location index and compared with the location index.
  7577. // It could be the index of any of several lanes that assign to that location,
  7578. // but this ensures that it is not any lane outside of that group.
  7579. // The lower bits are compared to the location index as well.
  7580. LogCommentFmt(L"Verifying %d-bit integer atomic cmp/xchg results", bitSize);
  7581. for (size_t i = 0; i < 64; i++) {
  7582. uint64_t val = *((uint64_t*)(pXchg + i*stride));
  7583. // Verify lower bits match location index exactly
  7584. VERIFY_ARE_EQUAL(i, val & ((1ULL << shBits) - 1ULL));
  7585. // Verify that upper bits contain original index that transforms to location index
  7586. VERIFY_ARE_EQUAL(((val >> shBits)/3)%64, i);
  7587. }
  7588. }
  7589. void VerifyAtomicsRawTest(std::shared_ptr<ShaderOpTestResult> test,
  7590. uint64_t maxIdx, size_t bitSize) {
  7591. size_t stride = 8;
  7592. // struct mirroring that in the shader
  7593. struct AtomicStuff {
  7594. float prepad[2][3];
  7595. UINT uintEl[4];
  7596. int sintEl[4];
  7597. struct useless {
  7598. uint32_t unused[3];
  7599. } postpad;
  7600. float last;
  7601. };
  7602. MappedData uintData, xchgData;
  7603. test->Test->GetReadBackData("U0", &uintData);
  7604. test->Test->GetReadBackData("U1", &xchgData);
  7605. const AtomicStuff *pStruct = (AtomicStuff *)uintData.data();
  7606. const AtomicStuff *pStrXchg = (AtomicStuff *)xchgData.data();
  7607. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWStructuredBuffer resource", bitSize);
  7608. VerifyAtomicResults((const BYTE*)&(pStruct[0].uintEl[2]), (const BYTE*)&(pStruct[1].sintEl[2]),
  7609. (const BYTE*)&(pStrXchg[0].uintEl[2]), sizeof(AtomicStuff), maxIdx, bitSize);
  7610. const BYTE *pUint = nullptr;
  7611. const BYTE *pXchg = nullptr;
  7612. test->Test->GetReadBackData("U2", &uintData);
  7613. test->Test->GetReadBackData("U3", &xchgData);
  7614. pUint = (BYTE *)uintData.data();
  7615. pXchg = (BYTE *)xchgData.data();
  7616. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWByteAddressBuffer resource", bitSize);
  7617. VerifyAtomicResults(pUint, pUint + stride*6,
  7618. pXchg, stride, maxIdx, bitSize);
  7619. }
  7620. void VerifyAtomicsTypedTest(std::shared_ptr<ShaderOpTestResult> test,
  7621. uint64_t maxIdx, size_t bitSize) {
  7622. size_t stride = 8;
  7623. MappedData uintData, sintData, xchgData;
  7624. const BYTE *pUint = nullptr;
  7625. const BYTE *pSint = nullptr;
  7626. const BYTE *pXchg = nullptr;
  7627. // Typed resources can't share between 32 and 64 bits
  7628. if (bitSize == 32) {
  7629. test->Test->GetReadBackData("U6", &uintData);
  7630. test->Test->GetReadBackData("U7", &sintData);
  7631. test->Test->GetReadBackData("U8", &xchgData);
  7632. } else {
  7633. test->Test->GetReadBackData("U12", &uintData);
  7634. test->Test->GetReadBackData("U13", &sintData);
  7635. test->Test->GetReadBackData("U14", &xchgData);
  7636. }
  7637. pUint = (BYTE *)uintData.data();
  7638. pSint = (BYTE *)sintData.data();
  7639. pXchg = (BYTE *)xchgData.data();
  7640. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWBuffer resource", bitSize);
  7641. VerifyAtomicResults(pUint, pSint + stride, pXchg, stride, maxIdx, bitSize);
  7642. // Typed resources can't share between 32 and 64 bits
  7643. if (bitSize == 32) {
  7644. test->Test->GetReadBackData("U9", &uintData);
  7645. test->Test->GetReadBackData("U10", &sintData);
  7646. test->Test->GetReadBackData("U11", &xchgData);
  7647. } else {
  7648. test->Test->GetReadBackData("U15", &uintData);
  7649. test->Test->GetReadBackData("U16", &sintData);
  7650. test->Test->GetReadBackData("U17", &xchgData);
  7651. }
  7652. pUint = (BYTE *)uintData.data();
  7653. pSint = (BYTE *)sintData.data();
  7654. pXchg = (BYTE *)xchgData.data();
  7655. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWTexture resource", bitSize);
  7656. VerifyAtomicResults(pUint, pSint + stride, pXchg, stride, maxIdx, bitSize);
  7657. }
  7658. void VerifyAtomicsSharedTest(std::shared_ptr<ShaderOpTestResult> test,
  7659. uint64_t maxIdx, size_t bitSize) {
  7660. size_t stride = 8;
  7661. MappedData uintData, xchgData;
  7662. const BYTE *pUint = nullptr;
  7663. const BYTE *pXchg = nullptr;
  7664. test->Test->GetReadBackData("U4", &uintData);
  7665. test->Test->GetReadBackData("U5", &xchgData);
  7666. pUint = (BYTE *)uintData.data();
  7667. pXchg = (BYTE *)xchgData.data();
  7668. LogCommentFmt(L"Verifying %d-bit integer atomic operations on groupshared variables", bitSize);
  7669. VerifyAtomicResults(pUint, pUint + stride*6,
  7670. pXchg, stride, maxIdx, bitSize);
  7671. }
  7672. void VerifyAtomicsTest(std::shared_ptr<ShaderOpTestResult> test,
  7673. uint64_t maxIdx, size_t bitSize) {
  7674. VerifyAtomicsRawTest(test, maxIdx, bitSize);
  7675. VerifyAtomicsTypedTest(test, maxIdx, bitSize);
  7676. }
  7677. TEST_F(ExecutionTest, AtomicsTest) {
  7678. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7679. CComPtr<IStream> pStream;
  7680. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7681. CComPtr<ID3D12Device> pDevice;
  7682. if (!CreateDevice(&pDevice))
  7683. return;
  7684. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7685. std::make_shared<st::ShaderOpSet>();
  7686. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7687. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("AtomicsHeap");
  7688. // Test compute shader
  7689. LogCommentFmt(L"Verifying 32-bit integer atomic operations in compute shader");
  7690. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsHeap", nullptr, ShaderOpSet);
  7691. VerifyAtomicsTest(test, 32*32, 32);
  7692. VerifyAtomicsSharedTest(test, 32*32, 32);
  7693. // Test mesh shader if available
  7694. pShaderOp->CS = nullptr;
  7695. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7696. LogCommentFmt(L"Verifying 32-bit integer atomic operations in amp/mesh/pixel shaders");
  7697. test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsHeap", nullptr, ShaderOpSet);
  7698. VerifyAtomicsTest(test, 8*8*2 + 8*8*2 + 64*64, 32);
  7699. VerifyAtomicsSharedTest(test, 8*8*2 + 8*8*2, 32);
  7700. }
  7701. // Test Vertex + Pixel shader
  7702. pShaderOp->MS = nullptr;
  7703. LogCommentFmt(L"Verifying 32-bit integer atomic operations in vert/pixel shaders");
  7704. test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsHeap", nullptr, ShaderOpSet);
  7705. VerifyAtomicsTest(test, 64*64+6, 32);
  7706. }
  7707. TEST_F(ExecutionTest, Atomics64Test) {
  7708. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7709. CComPtr<IStream> pStream;
  7710. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7711. CComPtr<ID3D12Device> pDevice;
  7712. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7713. return;
  7714. if (!DoesDeviceSupportInt64(pDevice)) {
  7715. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  7716. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7717. return;
  7718. }
  7719. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7720. std::make_shared<st::ShaderOpSet>();
  7721. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7722. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("AtomicsRoot");
  7723. // Reassign shader stages to 64-bit versions
  7724. // Collect 64-bit shaders
  7725. LPCSTR CS64 = nullptr, VS64 = nullptr, PS64 = nullptr;
  7726. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7727. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7728. if (!strcmp(S.Name, "CS")) CS64 = S.Name;
  7729. if (!strcmp(S.Name, "VS")) VS64 = S.Name;
  7730. if (!strcmp(S.Name, "PS")) PS64 = S.Name;
  7731. if (!strcmp(S.Name, "AS")) AS64 = S.Name;
  7732. if (!strcmp(S.Name, "MS")) MS64 = S.Name;
  7733. }
  7734. pShaderOp->CS = CS64;
  7735. pShaderOp->VS = VS64;
  7736. pShaderOp->PS = PS64;
  7737. pShaderOp->AS = AS64;
  7738. pShaderOp->MS = MS64;
  7739. // Test compute shader
  7740. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in compute shader");
  7741. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsRoot", nullptr, ShaderOpSet);
  7742. VerifyAtomicsRawTest(test, 32*32, 64);
  7743. // Test mesh shader if available
  7744. pShaderOp->CS = nullptr;
  7745. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7746. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in amp/mesh/pixel shader");
  7747. test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsRoot", nullptr, ShaderOpSet);
  7748. VerifyAtomicsRawTest(test, 8*8*2 + 8*8*2 + 64*64, 64);
  7749. }
  7750. // Test Vertex + Pixel shader
  7751. pShaderOp->MS = nullptr;
  7752. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in vert/pixel shader");
  7753. test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsRoot", nullptr, ShaderOpSet);
  7754. VerifyAtomicsRawTest(test, 64*64+6, 64);
  7755. }
  7756. TEST_F(ExecutionTest, AtomicsRawHeap64Test) {
  7757. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7758. CComPtr<IStream> pStream;
  7759. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7760. CComPtr<ID3D12Device> pDevice;
  7761. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7762. return;
  7763. if (!DoesDeviceSupportInt64(pDevice)) {
  7764. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  7765. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7766. return;
  7767. }
  7768. if (!DoesDeviceSupportHeap64Atomics(pDevice)) {
  7769. WEX::Logging::Log::Comment(L"Device does not support 64-bit atomic operations on heap resources.");
  7770. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7771. return;
  7772. }
  7773. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7774. std::make_shared<st::ShaderOpSet>();
  7775. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7776. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("AtomicsHeap");
  7777. // Reassign shader stages to 64-bit versions
  7778. // Collect 64-bit shaders
  7779. LPCSTR CS64 = nullptr, VS64 = nullptr, PS64 = nullptr;
  7780. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7781. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7782. if (!strcmp(S.Name, "CS64")) CS64 = S.Name;
  7783. if (!strcmp(S.Name, "VS64")) VS64 = S.Name;
  7784. if (!strcmp(S.Name, "PS64")) PS64 = S.Name;
  7785. if (!strcmp(S.Name, "AS64")) AS64 = S.Name;
  7786. if (!strcmp(S.Name, "MS64")) MS64 = S.Name;
  7787. }
  7788. pShaderOp->CS = CS64;
  7789. pShaderOp->VS = VS64;
  7790. pShaderOp->PS = PS64;
  7791. pShaderOp->AS = AS64;
  7792. pShaderOp->MS = MS64;
  7793. // Test compute shader
  7794. LogCommentFmt(L"Verifying 64-bit integer atomic operations on heap raw buffers in compute shader");
  7795. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsHeap", nullptr, ShaderOpSet);
  7796. VerifyAtomicsRawTest(test, 32*32, 64);
  7797. // Test mesh shader if available
  7798. pShaderOp->CS = nullptr;
  7799. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7800. LogCommentFmt(L"Verifying 64-bit integer atomic operations on heap raw buffers in amp/mesh/pixel shader");
  7801. test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsHeap", nullptr, ShaderOpSet);
  7802. VerifyAtomicsRawTest(test, 8*8*2 + 8*8*2 + 64*64, 64);
  7803. }
  7804. // Test Vertex + Pixel shader
  7805. pShaderOp->MS = nullptr;
  7806. LogCommentFmt(L"Verifying 64-bit integer atomic operations on heap raw buffers in vert/pixel shader");
  7807. test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsHeap", nullptr, ShaderOpSet);
  7808. VerifyAtomicsRawTest(test, 64*64+6, 64);
  7809. }
  7810. TEST_F(ExecutionTest, AtomicsTyped64Test) {
  7811. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7812. CComPtr<IStream> pStream;
  7813. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7814. CComPtr<ID3D12Device> pDevice;
  7815. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7816. return;
  7817. if (!DoesDeviceSupportInt64(pDevice)) {
  7818. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  7819. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7820. return;
  7821. }
  7822. if (!DoesDeviceSupportTyped64Atomics(pDevice)) {
  7823. WEX::Logging::Log::Comment(L"Device does not support int64 atomic operations on typed resources.");
  7824. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7825. return;
  7826. }
  7827. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7828. std::make_shared<st::ShaderOpSet>();
  7829. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7830. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("AtomicsHeap");
  7831. // Reassign shader stages to 64-bit versions
  7832. // Collect 64-bit shaders
  7833. LPCSTR CS64 = nullptr, VS64 = nullptr, PS64 = nullptr;
  7834. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7835. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7836. if (!strcmp(S.Name, "CSTY64")) CS64 = S.Name;
  7837. if (!strcmp(S.Name, "VSTY64")) VS64 = S.Name;
  7838. if (!strcmp(S.Name, "PSTY64")) PS64 = S.Name;
  7839. if (!strcmp(S.Name, "ASTY64")) AS64 = S.Name;
  7840. if (!strcmp(S.Name, "MSTY64")) MS64 = S.Name;
  7841. }
  7842. pShaderOp->CS = CS64;
  7843. pShaderOp->VS = VS64;
  7844. pShaderOp->PS = PS64;
  7845. pShaderOp->AS = AS64;
  7846. pShaderOp->MS = MS64;
  7847. // Test compute shader
  7848. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in compute shader");
  7849. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsHeap", nullptr, ShaderOpSet);
  7850. VerifyAtomicsTypedTest(test, 32*32, 64);
  7851. // Test mesh shader if available
  7852. pShaderOp->CS = nullptr;
  7853. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7854. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in amp/mesh/pixel shader");
  7855. test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsHeap", nullptr, ShaderOpSet);
  7856. VerifyAtomicsTypedTest(test, 8*8*2 + 8*8*2 + 64*64, 64);
  7857. }
  7858. // Test Vertex + Pixel shader
  7859. pShaderOp->MS = nullptr;
  7860. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in vert/pixel shader");
  7861. test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsHeap", nullptr, ShaderOpSet);
  7862. VerifyAtomicsTypedTest(test, 64*64+6, 64);
  7863. }
  7864. TEST_F(ExecutionTest, AtomicsShared64Test) {
  7865. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7866. CComPtr<IStream> pStream;
  7867. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7868. CComPtr<ID3D12Device> pDevice;
  7869. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7870. return;
  7871. if (!DoesDeviceSupportInt64(pDevice)) {
  7872. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  7873. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7874. return;
  7875. }
  7876. if (!DoesDeviceSupportShared64Atomics(pDevice)) {
  7877. WEX::Logging::Log::Comment(L"Device does not support int64 atomic operations on groupshared variables.");
  7878. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7879. return;
  7880. }
  7881. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7882. std::make_shared<st::ShaderOpSet>();
  7883. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7884. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("AtomicsRoot");
  7885. // Reassign shader stages to 64-bit versions
  7886. // Collect 64-bit shaders
  7887. LPCSTR CS64 = nullptr, PS64 = nullptr;
  7888. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7889. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7890. if (!strcmp(S.Name, "CSSH64")) CS64 = S.Name;
  7891. if (!strcmp(S.Name, "CSSH64")) CS64 = S.Name;
  7892. if (!strcmp(S.Name, "PS64")) PS64 = S.Name;
  7893. if (!strcmp(S.Name, "ASSH64")) AS64 = S.Name;
  7894. if (!strcmp(S.Name, "MSSH64")) MS64 = S.Name;
  7895. }
  7896. pShaderOp->CS = CS64;
  7897. pShaderOp->PS = PS64;
  7898. pShaderOp->AS = AS64;
  7899. pShaderOp->MS = MS64;
  7900. LogCommentFmt(L"Verifying 64-bit integer atomic operations on groupshared variables in compute shader");
  7901. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsRoot", nullptr, ShaderOpSet);
  7902. VerifyAtomicsSharedTest(test, 32*32, 64);
  7903. // Test mesh shader if available
  7904. pShaderOp->CS = nullptr;
  7905. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7906. LogCommentFmt(L"Verifying 64-bit integer atomic operations on groupshared variables in amp/mesh/pixel shader");
  7907. test = RunShaderOpTestAfterParse(pDevice, m_support, "AtomicsRoot", nullptr, ShaderOpSet);
  7908. VerifyAtomicsSharedTest(test, 8*8*2 + 8*8*2, 64);
  7909. }
  7910. }
  7911. // Float Atomics
  7912. // These operations are almost the same as for the 32-bit and 64-bit integer tests
  7913. // The difference is that there is no need to verify the upper bits.
  7914. // So there is no storing of different parts in upper and lower halves.
  7915. // Additionally, the only operations that are supported on floats
  7916. // are compare and exchange operations. So that's all that is tested here.
  7917. // Just as above, a number of lanes are assigned the same output value.
  7918. // Unlike above, one location is needed for the result of the special NaN test
  7919. // For this reason, the conversion is reduced by one and shifted by one to leave
  7920. // the zero-indexed location available.
  7921. // Verify results for a particular set of atomics results
  7922. void VerifyAtomicFloatResults(const float *results) {
  7923. // The first entry is for NaN to ensure that compares between NaNs succeed
  7924. // The sentinal value is 0.123, for which this compare is sufficient.
  7925. VERIFY_IS_TRUE(results[0] >= 0.120 && results[0] < 0.125);
  7926. // Start at 1 because 0 is just for NaN tests
  7927. for (int i = 1; i < 64; i++) {
  7928. VERIFY_ARE_EQUAL((int(results[i])/3)%63 + 1, i);
  7929. }
  7930. }
  7931. void VerifyAtomicsFloatSharedTest(std::shared_ptr<ShaderOpTestResult> test) {
  7932. MappedData Data;
  7933. const float *pData = nullptr;
  7934. test->Test->GetReadBackData("U4", &Data);
  7935. pData = (float *)Data.data();
  7936. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on groupshared variables");
  7937. VerifyAtomicFloatResults(pData);
  7938. }
  7939. void VerifyAtomicsFloatTest(std::shared_ptr<ShaderOpTestResult> test) {
  7940. // struct mirroring that in the shader
  7941. struct AtomicStuff {
  7942. float prepad[2][3];
  7943. float fltEl[2];
  7944. struct useless {
  7945. uint32_t unused[3];
  7946. } postpad;
  7947. };
  7948. // Test Compute Shader
  7949. MappedData Data;
  7950. const float *pData = nullptr;
  7951. test->Test->GetReadBackData("U0", &Data);
  7952. const AtomicStuff *pStructData = (AtomicStuff *)Data.data();
  7953. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWStructuredBuffer resources");
  7954. VERIFY_IS_TRUE(pStructData[0].fltEl[1] >= 0.120 && pStructData[0].fltEl[1] < 0.125);
  7955. for (int i = 1; i < 64; i++) {
  7956. VERIFY_ARE_EQUAL((int(pStructData[i].fltEl[1])/3)%63 + 1, i);
  7957. }
  7958. test->Test->GetReadBackData("U1", &Data);
  7959. pData = (float *)Data.data();
  7960. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWByteAddressBuffer resources");
  7961. VerifyAtomicFloatResults(pData);
  7962. test->Test->GetReadBackData("U2", &Data);
  7963. pData = (float *)Data.data();
  7964. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWBuffer resources");
  7965. VerifyAtomicFloatResults(pData);
  7966. test->Test->GetReadBackData("U3", &Data);
  7967. pData = (float *)Data.data();
  7968. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWTexture resources");
  7969. VerifyAtomicFloatResults(pData);
  7970. }
  7971. TEST_F(ExecutionTest, AtomicsFloatTest) {
  7972. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7973. CComPtr<IStream> pStream;
  7974. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7975. CComPtr<ID3D12Device> pDevice;
  7976. if (!CreateDevice(&pDevice))
  7977. return;
  7978. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7979. std::make_shared<st::ShaderOpSet>();
  7980. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7981. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("FloatAtomics");
  7982. // Test compute shader
  7983. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in compute shader");
  7984. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7985. VerifyAtomicsFloatTest(test);
  7986. VerifyAtomicsFloatSharedTest(test);
  7987. // Test mesh shader if available
  7988. pShaderOp->CS = nullptr;
  7989. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7990. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in amp/mesh/pixel shaders");
  7991. test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7992. VerifyAtomicsFloatTest(test);
  7993. VerifyAtomicsFloatSharedTest(test);
  7994. }
  7995. // Test Vertex + Pixel shader
  7996. pShaderOp->MS = nullptr;
  7997. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in vert/pixel shaders");
  7998. test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7999. VerifyAtomicsFloatTest(test);
  8000. }
  8001. // The IsHelperLane test renders 3-pixel triangle into 16x16 render target restricted
  8002. // to 2x2 viewport alligned at (0,0) which guarantees it will run in a single quad.
  8003. //
  8004. // Pixels to be rendered*
  8005. // (0,0)* (0,1)*
  8006. // (1,0) (1,1)*
  8007. //
  8008. // Pixel (1,0) is not rendered and is in helper lane.
  8009. //
  8010. // Each thread will use ddx_fine and ddy_fine to read the IsHelperLane() values from other threads.
  8011. // The bottom right pixel will write the results into the UAV buffer.
  8012. //
  8013. // Then the top level pixel (0,0) is discarded and the process above is repeated.
  8014. //
  8015. // Runs with shader models 6.0 and 6.6 to test both the HLSL built-in IsHelperLane fallback
  8016. // function (sm <= 6.5) and the IsHelperLane intrisics (sm >= 6.6).
  8017. //
  8018. TEST_F(ExecutionTest, HelperLaneTest) {
  8019. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  8020. CComPtr<IStream> pStream;
  8021. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  8022. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  8023. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  8024. #ifdef ISHELPERLANE_PLACEHOLDER
  8025. string args = "-DISHELPERLANE_PLACEHOLDER";
  8026. #else
  8027. string args = "";
  8028. #endif
  8029. D3D_SHADER_MODEL TestShaderModels[] = { D3D_SHADER_MODEL_6_0, D3D_SHADER_MODEL_6_6 };
  8030. for (unsigned i = 0; i < _countof(TestShaderModels); i++) {
  8031. D3D_SHADER_MODEL sm = TestShaderModels[i];
  8032. LogCommentFmt(L"Verifying IsHelperLane in shader model 6.%1u", ((UINT)sm & 0x0f));
  8033. CComPtr<ID3D12Device> pDevice;
  8034. if (!CreateDevice(&pDevice, sm, false /* skipUnsupported */))
  8035. continue;
  8036. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "HelperLaneTestNoWave",
  8037. // this callbacked is called when the test is creating the resource to run the test
  8038. [&](LPCSTR Name, std::vector<BYTE>& Data, st::ShaderOp* pShaderOp) {
  8039. VERIFY_IS_TRUE(0 == _stricmp(Name, "UAVBuffer0"));
  8040. std::fill(Data.begin(), Data.end(), (BYTE)0xCC);
  8041. pShaderOp->Shaders.at(0).Arguments = args.c_str();
  8042. pShaderOp->Shaders.at(1).Arguments = args.c_str();
  8043. }, ShaderOpSet);
  8044. struct HelperLaneTestResult {
  8045. int32_t is_helper_00;
  8046. int32_t is_helper_10;
  8047. int32_t is_helper_01;
  8048. int32_t is_helper_11;
  8049. };
  8050. MappedData uavData;
  8051. test->Test->GetReadBackData("UAVBuffer0", &uavData);
  8052. HelperLaneTestResult* pTestResults = (HelperLaneTestResult*)uavData.data();
  8053. MappedData renderData;
  8054. test->Test->GetReadBackData("RTarget", &renderData);
  8055. const uint32_t* pPixels = (uint32_t*)renderData.data();
  8056. // before discard
  8057. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_00, 0);
  8058. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_10, 0);
  8059. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_01, 1);
  8060. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_11, 0);
  8061. // after discard
  8062. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_00, 1);
  8063. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_10, 0);
  8064. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_01, 1);
  8065. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_11, 0);
  8066. UNREFERENCED_PARAMETER(pPixels);
  8067. }
  8068. }
  8069. struct HelperLaneWaveTestResult60 {
  8070. // 6.0 wave ops
  8071. int32_t anyTrue;
  8072. int32_t allTrue;
  8073. XMUINT4 ballot;
  8074. int32_t waterfallLoopCount;
  8075. int32_t allEqual;
  8076. int32_t countBits;
  8077. int32_t sum;
  8078. int32_t product;
  8079. int32_t bitAnd;
  8080. int32_t bitOr;
  8081. int32_t bitXor;
  8082. int32_t min;
  8083. int32_t max;
  8084. int32_t prefixCountBits;
  8085. int32_t prefixProduct;
  8086. int32_t prefixSum;
  8087. };
  8088. struct HelperLaneQuadTestResult {
  8089. int32_t is_helper_this;
  8090. int32_t is_helper_across_X;
  8091. int32_t is_helper_across_Y;
  8092. int32_t is_helper_across_Diag;
  8093. };
  8094. struct HelperLaneWaveTestResult65 {
  8095. // 6.5 wave ops
  8096. XMUINT4 match;
  8097. int32_t mpCountBits;
  8098. int32_t mpSum;
  8099. int32_t mpProduct;
  8100. int32_t mpBitAnd;
  8101. int32_t mpBitOr;
  8102. int32_t mpBitXor;
  8103. };
  8104. struct HelperLaneWaveTestResult {
  8105. HelperLaneWaveTestResult60 sm60;
  8106. HelperLaneQuadTestResult sm60_quad;
  8107. HelperLaneWaveTestResult65 sm65;
  8108. };
  8109. struct foo { int32_t a; int32_t b; int32_t c; };
  8110. struct bar { foo f; int32_t d; XMUINT4 g; };
  8111. foo f = {1, 2, 3};
  8112. bar b = { { 1, 2, 3 }, 0, { 1, 2, 3, 4 } };
  8113. HelperLaneWaveTestResult HelperLane_CS_ExpectedResults = {
  8114. // HelperLaneWaveTestResult60
  8115. { 0, 1, { 0x7, 0, 0, 0 }, 3, 1, 3, 12, 64, 1, 0, 0, 10, 1, 2, 16, 4 },
  8116. // HelperLaneQuadTestResult
  8117. { 0, 0, 0, 0 },
  8118. // HelperLaneWaveTestResult65
  8119. { {0x7, 0, 0, 0}, 2, 4, 16, 1, 0, 0 }
  8120. };
  8121. HelperLaneWaveTestResult HelperLane_VS_ExpectedResults = HelperLane_CS_ExpectedResults;
  8122. HelperLaneWaveTestResult HelperLane_PS_ExpectedResults = {
  8123. // HelperLaneWaveTestResult60
  8124. { 0, 1, { 0xB, 0, 0, 0 }, 3, 1, 3, 12, 64, 1, 0, 0, 10, 1, 2, 16, 4 },
  8125. // HelperLaneQuadTestResult
  8126. { 0, 1, 0, 0 },
  8127. // HelperLaneWaveTestResult65
  8128. { {0xB, 0, 0, 0}, 2, 4, 16, 1, 0, 0 }
  8129. };
  8130. HelperLaneWaveTestResult HelperLane_PSAfterDiscard_ExpectedResults = {
  8131. // HelperLaneWaveTestResult60
  8132. { 0, 1, { 0xA, 0, 0, 0 }, 2, 1, 2, 8, 16, 1, 0, 0, 10, 1, 1, 4, 2 },
  8133. // HelperLaneQuadTestResult
  8134. { 0, 1, 0, 1 },
  8135. // HelperLaneWaveTestResult65
  8136. { {0xA, 0, 0, 0}, 1, 2, 4, 1, 0, 0 }
  8137. };
  8138. bool HelperLaneResultLogAndVerify(const wchar_t* testDesc, uint32_t expectedValue, uint32_t actualValue) {
  8139. bool matches = (expectedValue == actualValue);
  8140. LogCommentFmt(L"%s%s, expected = %u, actual = %u", matches ? L" - " : L"FAILED: ", testDesc, expectedValue, actualValue);
  8141. return matches;
  8142. }
  8143. bool HelperLaneResultLogAndVerify(const wchar_t* testDesc, XMUINT4 expectedValue, XMUINT4 actualValue) {
  8144. bool matches = (expectedValue.x == actualValue.x && expectedValue.y == actualValue.y &&
  8145. expectedValue.z == actualValue.z && expectedValue.w == actualValue.w);
  8146. 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,
  8147. expectedValue.x, expectedValue.y, expectedValue.z, expectedValue.w, actualValue.x, actualValue.y, actualValue.z, actualValue.w);
  8148. return matches;
  8149. }
  8150. bool VerifyHelperLaneWaveResults(ExecutionTest::D3D_SHADER_MODEL sm, HelperLaneWaveTestResult& testResults, HelperLaneWaveTestResult& expectedResults, bool verifyQuads) {
  8151. bool passed = true;
  8152. {
  8153. HelperLaneWaveTestResult60& tr60 = testResults.sm60;
  8154. HelperLaneWaveTestResult60& tr60exp = expectedResults.sm60;
  8155. passed &= HelperLaneResultLogAndVerify(L"WaveActiveAnyTrue(IsHelperLane())", tr60exp.anyTrue, tr60.anyTrue);
  8156. passed &= HelperLaneResultLogAndVerify(L"WaveActiveAllTrue(!IsHelperLane())", tr60exp.allTrue, tr60.allTrue);
  8157. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBallot(true) has exactly 3 bits set", tr60exp.ballot, tr60.ballot);
  8158. passed &= HelperLaneResultLogAndVerify(L"!WaveReadLaneFirst(IsHelperLane()) && WaveIsFirstLane() in a waterfall loop", tr60exp.waterfallLoopCount, tr60.waterfallLoopCount);
  8159. passed &= HelperLaneResultLogAndVerify(L"WaveActiveAllEqual(IsHelperLane())", tr60exp.allEqual, tr60.allEqual);
  8160. passed &= HelperLaneResultLogAndVerify(L"WaveActiveCountBits(true)", tr60exp.countBits, tr60.countBits);
  8161. passed &= HelperLaneResultLogAndVerify(L"WaveActiveSum(4)", tr60exp.sum, tr60.sum);
  8162. passed &= HelperLaneResultLogAndVerify(L"WaveActiveProduct(4)", tr60exp.product, tr60.product);
  8163. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBitAnd(!IsHelperLane())", tr60exp.bitAnd, tr60.bitAnd);
  8164. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBitOr(IsHelperLane())", tr60exp.bitOr, tr60.bitOr);
  8165. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBitXor(IsHelperLane())", tr60exp.bitXor, tr60.bitXor);
  8166. passed &= HelperLaneResultLogAndVerify(L"WaveActiveMin(IsHelperLane() ? 1 : 10)", tr60exp.min, tr60.min);
  8167. passed &= HelperLaneResultLogAndVerify(L"WaveActiveMax(IsHelperLane() ? 10 : 1)", tr60exp.max, tr60.max);
  8168. passed &= HelperLaneResultLogAndVerify(L"WavePrefixCountBits(1)", tr60exp.prefixCountBits, tr60.prefixCountBits);
  8169. passed &= HelperLaneResultLogAndVerify(L"WavePrefixProduct(4)", tr60exp.prefixProduct, tr60.prefixProduct);
  8170. passed &= HelperLaneResultLogAndVerify(L"WavePrefixSum(2)", tr60exp.prefixSum, tr60.prefixSum);
  8171. }
  8172. if (verifyQuads) {
  8173. HelperLaneQuadTestResult& quad_tr = testResults.sm60_quad;
  8174. HelperLaneQuadTestResult& quad_tr_exp = expectedResults.sm60_quad;
  8175. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 3 / pixel (1,1) - IsHelperLane()", quad_tr_exp.is_helper_this, quad_tr.is_helper_this);
  8176. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 2 / pixel (0,1) - IsHelperLane()", quad_tr_exp.is_helper_across_X, quad_tr.is_helper_across_X);
  8177. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 1 / pixel (1,0) - IsHelperLane()", quad_tr_exp.is_helper_across_Y, quad_tr.is_helper_across_Y);
  8178. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 0 / pixel (0,0) - IsHelperLane()", quad_tr_exp.is_helper_across_Diag, quad_tr.is_helper_across_Diag);
  8179. }
  8180. if (sm >= D3D_SHADER_MODEL_6_5) {
  8181. HelperLaneWaveTestResult65& tr65 = testResults.sm65;
  8182. HelperLaneWaveTestResult65& tr65exp = expectedResults.sm65;
  8183. passed &= HelperLaneResultLogAndVerify(L"WaveMatch(true) has exactly 3 bits set", tr65exp.match, tr65.match);
  8184. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixCountBits(1, no_masked_bits)", tr65exp.mpCountBits, tr65.mpCountBits);
  8185. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixSum(2, no_masked_bits)", tr65exp.mpSum, tr65.mpSum);
  8186. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixProduct(4, no_masked_bits)", tr65exp.mpProduct, tr65.mpProduct);
  8187. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixAnd(IsHelperLane() ? 0 : 1, no_masked_bits)", tr65exp.mpBitAnd, tr65.mpBitAnd);
  8188. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixOr(IsHelperLane() ? 1 : 0, no_masked_bits)", tr65exp.mpBitOr, tr65.mpBitOr);
  8189. passed &= HelperLaneResultLogAndVerify(L"verify WaveMultiPrefixXor(IsHelperLane() ? 1 : 0, no_masked_bits)", tr65exp.mpBitXor, tr65.mpBitXor);
  8190. }
  8191. return passed;
  8192. }
  8193. void CleanUAVBuffer0Buffer(LPCSTR BufferName, std::vector<BYTE>& Data, st::ShaderOp* pShaderOp) {
  8194. UNREFERENCED_PARAMETER(pShaderOp);
  8195. VERIFY_IS_TRUE(0 == _stricmp(BufferName, "UAVBuffer0"));
  8196. std::fill(Data.begin(), Data.end(), (BYTE)0xCC);
  8197. }
  8198. //
  8199. // The IsHelperLane test that use Wave intrinsics to verify IsHelperLane() and Wave operations on active lanes.
  8200. //
  8201. // Runs with shader models 6.0, 6.5 and 6.6 to test both the HLSL built-in IsHelperLane fallback
  8202. // function (sm <= 6.5) and the IsHelperLane intrisics (sm >= 6.6) and the shader model 6.5 wave intrinsics (sm >= 6.5).
  8203. //
  8204. // For compute and vertex shaders IsHelperLane() always returns false and might be optimized away in the front end.
  8205. // However it can be exposed to the driver in CS/VS through an exported function in a library so drivers need
  8206. // to be prepared to handle it. For this reason the test is compiled with disabled optimizations (/Od).
  8207. // The tests are also validating that wave intrinsics operate correctly with 3 threads in a CS or 3 vertices
  8208. // in a VS where the rest of the lanes in the wave are not active (dead lanes).
  8209. //
  8210. TEST_F(ExecutionTest, HelperLaneTestWave) {
  8211. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  8212. CComPtr<IStream> pStream;
  8213. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  8214. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  8215. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  8216. st::ShaderOp* pShaderOp = ShaderOpSet->GetShaderOp("HelperLaneTestWave");
  8217. #ifdef ISHELPERLANE_PLACEHOLDER
  8218. LPCSTR args = "/Od -DISHELPERLANE_PLACEHOLDER";
  8219. #else
  8220. LPCSTR args = "/Od";
  8221. #endif
  8222. if (args[0]) {
  8223. for (st::ShaderOpShader& S : pShaderOp->Shaders)
  8224. S.Arguments = args;
  8225. }
  8226. bool testPassed = true;
  8227. D3D_SHADER_MODEL TestShaderModels[] = { D3D_SHADER_MODEL_6_0, D3D_SHADER_MODEL_6_5, D3D_SHADER_MODEL_6_6 };
  8228. for (unsigned i = 0; i < _countof(TestShaderModels); i++) {
  8229. D3D_SHADER_MODEL sm = TestShaderModels[i];
  8230. LogCommentFmt(L"\r\nVerifying IsHelperLane using Wave intrinsics in shader model 6.%1u", ((UINT)sm & 0x0f));
  8231. bool smPassed = true;
  8232. CComPtr<ID3D12Device> pDevice;
  8233. if (!CreateDevice(&pDevice, sm, false /* skipUnsupported */)) {
  8234. continue;
  8235. }
  8236. if (GetTestParamUseWARP(UseWarpByDefault()) || IsDeviceBasicAdapter(pDevice)) {
  8237. WEX::Logging::Log::Comment(L"WARP has a known issue with HelperLaneTestWave.");
  8238. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  8239. return;
  8240. }
  8241. if (!DoesDeviceSupportWaveOps(pDevice)) {
  8242. LogCommentFmt(L"Device does not support wave operations in shader model 6.%1u", ((UINT)sm & 0x0f));
  8243. continue;
  8244. }
  8245. if (sm == D3D_SHADER_MODEL_6_5) {
  8246. // Reassign shader stages to 6.5 versions
  8247. LPCSTR CS65 = nullptr, VS65 = nullptr, PS65 = nullptr;
  8248. for (st::ShaderOpShader& S : pShaderOp->Shaders) {
  8249. if (!strcmp(S.Name, "CS65")) CS65 = S.Name;
  8250. if (!strcmp(S.Name, "VS65")) VS65 = S.Name;
  8251. if (!strcmp(S.Name, "PS65")) PS65 = S.Name;
  8252. }
  8253. pShaderOp->CS = CS65;
  8254. pShaderOp->VS = VS65;
  8255. pShaderOp->PS = PS65;
  8256. } else if (sm == D3D_SHADER_MODEL_6_6) {
  8257. // Reassign shader stages to 6.6 versions
  8258. LPCSTR CS66 = nullptr, VS66 = nullptr, PS66 = nullptr;
  8259. for (st::ShaderOpShader& S : pShaderOp->Shaders) {
  8260. if (!strcmp(S.Name, "CS66")) CS66 = S.Name;
  8261. if (!strcmp(S.Name, "VS66")) VS66 = S.Name;
  8262. if (!strcmp(S.Name, "PS66")) PS66 = S.Name;
  8263. }
  8264. pShaderOp->CS = CS66;
  8265. pShaderOp->VS = VS66;
  8266. pShaderOp->PS = PS66;
  8267. }
  8268. const unsigned CS_INDEX = 0, VS_INDEX = 0, PS_INDEX = 1, PS_INDEX_AFTER_DISCARD = 2;
  8269. // Test Compute shader
  8270. {
  8271. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "HelperLaneTestWave",
  8272. CleanUAVBuffer0Buffer, ShaderOpSet);
  8273. MappedData uavData;
  8274. test->Test->GetReadBackData("UAVBuffer0", &uavData);
  8275. HelperLaneWaveTestResult* pTestResults = (HelperLaneWaveTestResult*)uavData.data();
  8276. LogCommentFmt(L"\r\nCompute shader");
  8277. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[CS_INDEX], HelperLane_CS_ExpectedResults, true);
  8278. }
  8279. // Test Vertex + Pixel shader
  8280. {
  8281. pShaderOp->CS = nullptr;
  8282. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "HelperLaneTestWave", CleanUAVBuffer0Buffer, ShaderOpSet);
  8283. MappedData uavData;
  8284. test->Test->GetReadBackData("UAVBuffer0", &uavData);
  8285. HelperLaneWaveTestResult* pTestResults = (HelperLaneWaveTestResult*)uavData.data();
  8286. LogCommentFmt(L"\r\nVertex shader");
  8287. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[VS_INDEX], HelperLane_VS_ExpectedResults, false);
  8288. LogCommentFmt(L"\r\nPixel shader");
  8289. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[PS_INDEX], HelperLane_PS_ExpectedResults, true);
  8290. LogCommentFmt(L"\r\nPixel shader with discarded pixel");
  8291. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[PS_INDEX_AFTER_DISCARD], HelperLane_PSAfterDiscard_ExpectedResults, true);
  8292. MappedData renderData;
  8293. test->Test->GetReadBackData("RTarget", &renderData);
  8294. const uint32_t* pPixels = (uint32_t*)renderData.data();
  8295. UNREFERENCED_PARAMETER(pPixels);
  8296. }
  8297. testPassed &= smPassed;
  8298. }
  8299. VERIFY_ARE_EQUAL(testPassed, true);
  8300. }
  8301. #ifndef _HLK_CONF
  8302. static void WriteReadBackDump(st::ShaderOp *pShaderOp, st::ShaderOpTest *pTest,
  8303. char **pReadBackDump) {
  8304. std::stringstream str;
  8305. unsigned count = 0;
  8306. for (auto &R : pShaderOp->Resources) {
  8307. if (!R.ReadBack)
  8308. continue;
  8309. ++count;
  8310. str << "Resource: " << R.Name << "\r\n";
  8311. // Find a descriptor that can tell us how to dump this resource.
  8312. bool found = false;
  8313. for (auto &Heaps : pShaderOp->DescriptorHeaps) {
  8314. for (auto &D : Heaps.Descriptors) {
  8315. if (_stricmp(D.ResName, R.Name) != 0) {
  8316. continue;
  8317. }
  8318. found = true;
  8319. if (_stricmp(D.Kind, "UAV") != 0) {
  8320. str << "Resource dump for kind " << D.Kind << " not implemented yet.\r\n";
  8321. break;
  8322. }
  8323. if (D.UavDesc.ViewDimension != D3D12_UAV_DIMENSION_BUFFER) {
  8324. str << "Resource dump for this kind of view dimension not implemented yet.\r\n";
  8325. break;
  8326. }
  8327. // We can map back to the structure if a structured buffer via the shader, but
  8328. // we'll keep this simple and simply dump out 32-bit uint/float representations.
  8329. MappedData data;
  8330. pTest->GetReadBackData(R.Name, &data);
  8331. uint32_t *pData = (uint32_t *)data.data();
  8332. size_t u32_count = ((size_t)R.Desc.Width) / sizeof(uint32_t);
  8333. for (size_t i = 0; i < u32_count; ++i) {
  8334. float f = *(float *)pData;
  8335. str << i << ": 0n" << *pData << " 0x" << std::hex << *pData
  8336. << std::dec << " " << f << "\r\n";
  8337. ++pData;
  8338. }
  8339. break;
  8340. }
  8341. if (found) break;
  8342. }
  8343. if (!found) {
  8344. str << "Unable to find a view for the resource.\r\n";
  8345. }
  8346. }
  8347. str << "Resources read back: " << count << "\r\n";
  8348. std::string s(str.str());
  8349. CComHeapPtr<char> pDump;
  8350. if (!pDump.Allocate(s.size() + 1))
  8351. throw std::bad_alloc();
  8352. memcpy(pDump.m_pData, s.data(), s.size());
  8353. pDump.m_pData[s.size()] = '\0';
  8354. *pReadBackDump = pDump.Detach();
  8355. }
  8356. // This is the exported interface by use from HLSLHost.exe.
  8357. // It's exclusive with the use of the DLL as a TAEF target.
  8358. extern "C" {
  8359. __declspec(dllexport) HRESULT WINAPI InitializeOpTests(void *pStrCtx, st::OutputStringFn pOutputStrFn) {
  8360. HRESULT hr = EnableExperimentalShaderModels();
  8361. if (FAILED(hr)) {
  8362. pOutputStrFn(pStrCtx, L"Unable to enable experimental shader models.\r\n.");
  8363. }
  8364. return S_OK;
  8365. }
  8366. __declspec(dllexport) HRESULT WINAPI
  8367. RunOpTest(void *pStrCtx, st::OutputStringFn pOutputStrFn, LPCSTR pText,
  8368. ID3D12Device *pDevice, ID3D12CommandQueue *pCommandQueue,
  8369. ID3D12Resource *pRenderTarget, char **pReadBackDump) {
  8370. HRESULT hr;
  8371. if (pReadBackDump) *pReadBackDump = nullptr;
  8372. st::SetOutputFn(pStrCtx, pOutputStrFn);
  8373. CComPtr<ID3D12InfoQueue> pInfoQueue;
  8374. CComHeapPtr<char> pDump;
  8375. bool FilterCreation = false;
  8376. if (SUCCEEDED(pDevice->QueryInterface(&pInfoQueue))) {
  8377. // Creation is largely driven by inputs, so don't log create/destroy messages.
  8378. pInfoQueue->PushEmptyStorageFilter();
  8379. pInfoQueue->PushEmptyRetrievalFilter();
  8380. if (FilterCreation) {
  8381. D3D12_INFO_QUEUE_FILTER filter;
  8382. D3D12_MESSAGE_CATEGORY denyCategories[] = { D3D12_MESSAGE_CATEGORY_STATE_CREATION };
  8383. ZeroMemory(&filter, sizeof(filter));
  8384. filter.DenyList.NumCategories = _countof(denyCategories);
  8385. filter.DenyList.pCategoryList = denyCategories;
  8386. pInfoQueue->PushStorageFilter(&filter);
  8387. }
  8388. }
  8389. else {
  8390. pOutputStrFn(pStrCtx, L"Unable to enable info queue for D3D.\r\n.");
  8391. }
  8392. try {
  8393. dxc::DxcDllSupport m_support;
  8394. m_support.Initialize();
  8395. const char *pName = nullptr;
  8396. CComPtr<IStream> pStream = SHCreateMemStream((BYTE *)pText, (UINT)strlen(pText));
  8397. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  8398. std::make_shared<st::ShaderOpSet>();
  8399. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  8400. st::ShaderOp *pShaderOp;
  8401. if (pName == nullptr) {
  8402. if (ShaderOpSet->ShaderOps.size() != 1) {
  8403. pOutputStrFn(pStrCtx, L"Expected a single shader operation.\r\n");
  8404. return E_FAIL;
  8405. }
  8406. pShaderOp = ShaderOpSet->ShaderOps[0].get();
  8407. }
  8408. else {
  8409. pShaderOp = ShaderOpSet->GetShaderOp(pName);
  8410. }
  8411. if (pShaderOp == nullptr) {
  8412. std::string msg = "Unable to find shader op ";
  8413. msg += pName;
  8414. msg += "; available ops";
  8415. const char sep = ':';
  8416. for (auto &pAvailOp : ShaderOpSet->ShaderOps) {
  8417. msg += sep;
  8418. msg += pAvailOp->Name ? pAvailOp->Name : "[n/a]";
  8419. }
  8420. CA2W msgWide(msg.c_str());
  8421. pOutputStrFn(pStrCtx, msgWide);
  8422. return E_FAIL;
  8423. }
  8424. std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
  8425. test->SetupRenderTarget(pShaderOp, pDevice, pCommandQueue, pRenderTarget);
  8426. test->SetDxcSupport(&m_support);
  8427. test->RunShaderOp(pShaderOp);
  8428. test->PresentRenderTarget(pShaderOp, pCommandQueue, pRenderTarget);
  8429. pOutputStrFn(pStrCtx, L"Rendering complete.\r\n");
  8430. if (!pShaderOp->IsCompute()) {
  8431. D3D12_QUERY_DATA_PIPELINE_STATISTICS stats;
  8432. test->GetPipelineStats(&stats);
  8433. wchar_t statsText[400];
  8434. StringCchPrintfW(statsText, _countof(statsText),
  8435. L"Vertices/primitives read by input assembler: %I64u/%I64u\r\n"
  8436. L"Vertex shader invocations: %I64u\r\n"
  8437. L"Geometry shader invocations/output primitive: %I64u/%I64u\r\n"
  8438. L"Primitives sent to rasterizer/rendered: %I64u/%I64u\r\n"
  8439. L"PS/HS/DS/CS invocations: %I64u/%I64u/%I64u/%I64u\r\n",
  8440. stats.IAVertices, stats.IAPrimitives, stats.VSInvocations,
  8441. stats.GSInvocations, stats.GSPrimitives, stats.CInvocations,
  8442. stats.CPrimitives, stats.PSInvocations, stats.HSInvocations,
  8443. stats.DSInvocations, stats.CSInvocations);
  8444. pOutputStrFn(pStrCtx, statsText);
  8445. }
  8446. if (pReadBackDump) {
  8447. WriteReadBackDump(pShaderOp, test.get(), &pDump);
  8448. }
  8449. hr = S_OK;
  8450. }
  8451. catch (const CAtlException &E)
  8452. {
  8453. hr = E.m_hr;
  8454. }
  8455. catch (const std::bad_alloc &)
  8456. {
  8457. hr = E_OUTOFMEMORY;
  8458. }
  8459. catch (const std::exception &)
  8460. {
  8461. hr = E_FAIL;
  8462. }
  8463. // Drain the device message queue if available.
  8464. if (pInfoQueue != nullptr) {
  8465. wchar_t buf[200];
  8466. StringCchPrintfW(buf, _countof(buf),
  8467. L"NumStoredMessages=%u limit/discarded by limit=%u/%u "
  8468. L"allowed/denied by storage filter=%u/%u "
  8469. L"NumStoredMessagesAllowedByRetrievalFilter=%u\r\n",
  8470. (unsigned)pInfoQueue->GetNumStoredMessages(),
  8471. (unsigned)pInfoQueue->GetMessageCountLimit(),
  8472. (unsigned)pInfoQueue->GetNumMessagesDiscardedByMessageCountLimit(),
  8473. (unsigned)pInfoQueue->GetNumMessagesAllowedByStorageFilter(),
  8474. (unsigned)pInfoQueue->GetNumMessagesDeniedByStorageFilter(),
  8475. (unsigned)pInfoQueue->GetNumStoredMessagesAllowedByRetrievalFilter());
  8476. pOutputStrFn(pStrCtx, buf);
  8477. WriteInfoQueueMessages(pStrCtx, pOutputStrFn, pInfoQueue);
  8478. pInfoQueue->ClearStoredMessages();
  8479. pInfoQueue->PopRetrievalFilter();
  8480. pInfoQueue->PopStorageFilter();
  8481. if (FilterCreation) {
  8482. pInfoQueue->PopStorageFilter();
  8483. }
  8484. }
  8485. if (pReadBackDump) *pReadBackDump = pDump.Detach();
  8486. return hr;
  8487. }
  8488. }
  8489. #endif
  8490. // MARKER: ExecutionTest/DxilConf Shared Implementation End
  8491. // Do not remove the line above - it is used by TranslateExecutionTest.py