d3dx12.h 180 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511
  1. //*********************************************************
  2. //
  3. // Copyright (c) Microsoft. All rights reserved.
  4. // This code is licensed under the MIT License (MIT).
  5. // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
  6. // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
  7. // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
  8. // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
  9. //
  10. //*********************************************************
  11. // changes made for dynamic linking of dx12.dll
  12. // - all occurrences of "IID_ID3D12Device" were replaced by "__uuidof(*pDevice)"
  13. // - the function D3DX12SerializeVersionedRootSignature has two additional
  14. // functionpointer arguments pointing to the dynamically loaded fuctions of type
  15. // PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE and
  16. // PFN_D3D12_SERIALIZE_ROOT_SIGNATURE
  17. #ifndef __D3DX12_H__
  18. #define __D3DX12_H__
  19. #include "d3d12.h"
  20. #if defined(__cplusplus)
  21. struct CD3DX12_DEFAULT
  22. {};
  23. extern const DECLSPEC_SELECTANY CD3DX12_DEFAULT D3D12_DEFAULT;
  24. //------------------------------------------------------------------------------------------------
  25. inline bool operator==(
  26. const D3D12_VIEWPORT& l, const D3D12_VIEWPORT& r) noexcept
  27. {
  28. return l.TopLeftX == r.TopLeftX && l.TopLeftY == r.TopLeftY
  29. && l.Width == r.Width && l.Height == r.Height
  30. && l.MinDepth == r.MinDepth && l.MaxDepth == r.MaxDepth;
  31. }
  32. //------------------------------------------------------------------------------------------------
  33. inline bool operator!=(
  34. const D3D12_VIEWPORT& l, const D3D12_VIEWPORT& r) noexcept
  35. {
  36. return !(l == r);
  37. }
  38. //------------------------------------------------------------------------------------------------
  39. struct CD3DX12_RECT : public D3D12_RECT
  40. {
  41. CD3DX12_RECT() = default;
  42. explicit CD3DX12_RECT(const D3D12_RECT& o) noexcept
  43. : D3D12_RECT(o)
  44. {}
  45. explicit CD3DX12_RECT(LONG Left, LONG Top, LONG Right, LONG Bottom) noexcept
  46. {
  47. left = Left;
  48. top = Top;
  49. right = Right;
  50. bottom = Bottom;
  51. }
  52. };
  53. //------------------------------------------------------------------------------------------------
  54. struct CD3DX12_VIEWPORT : public D3D12_VIEWPORT
  55. {
  56. CD3DX12_VIEWPORT() = default;
  57. explicit CD3DX12_VIEWPORT(const D3D12_VIEWPORT& o) noexcept
  58. : D3D12_VIEWPORT(o)
  59. {}
  60. explicit CD3DX12_VIEWPORT(FLOAT topLeftX,
  61. FLOAT topLeftY,
  62. FLOAT width,
  63. FLOAT height,
  64. FLOAT minDepth = D3D12_MIN_DEPTH,
  65. FLOAT maxDepth = D3D12_MAX_DEPTH) noexcept
  66. {
  67. TopLeftX = topLeftX;
  68. TopLeftY = topLeftY;
  69. Width = width;
  70. Height = height;
  71. MinDepth = minDepth;
  72. MaxDepth = maxDepth;
  73. }
  74. explicit CD3DX12_VIEWPORT(_In_ ID3D12Resource* pResource,
  75. UINT mipSlice = 0,
  76. FLOAT topLeftX = 0.0f,
  77. FLOAT topLeftY = 0.0f,
  78. FLOAT minDepth = D3D12_MIN_DEPTH,
  79. FLOAT maxDepth = D3D12_MAX_DEPTH) noexcept
  80. {
  81. auto Desc = pResource->GetDesc();
  82. const UINT64 SubresourceWidth = Desc.Width >> mipSlice;
  83. const UINT64 SubresourceHeight = Desc.Height >> mipSlice;
  84. switch (Desc.Dimension)
  85. {
  86. case D3D12_RESOURCE_DIMENSION_BUFFER:
  87. TopLeftX = topLeftX;
  88. TopLeftY = 0.0f;
  89. Width = float(Desc.Width) - topLeftX;
  90. Height = 1.0f;
  91. break;
  92. case D3D12_RESOURCE_DIMENSION_TEXTURE1D:
  93. TopLeftX = topLeftX;
  94. TopLeftY = 0.0f;
  95. Width = (SubresourceWidth ? float(SubresourceWidth) : 1.0f)
  96. - topLeftX;
  97. Height = 1.0f;
  98. break;
  99. case D3D12_RESOURCE_DIMENSION_TEXTURE2D:
  100. case D3D12_RESOURCE_DIMENSION_TEXTURE3D:
  101. TopLeftX = topLeftX;
  102. TopLeftY = topLeftY;
  103. Width = (SubresourceWidth ? float(SubresourceWidth) : 1.0f)
  104. - topLeftX;
  105. Height = (SubresourceHeight ? float(SubresourceHeight) : 1.0f)
  106. - topLeftY;
  107. break;
  108. default:
  109. break;
  110. }
  111. MinDepth = minDepth;
  112. MaxDepth = maxDepth;
  113. }
  114. };
  115. //------------------------------------------------------------------------------------------------
  116. struct CD3DX12_BOX : public D3D12_BOX
  117. {
  118. CD3DX12_BOX() = default;
  119. explicit CD3DX12_BOX(const D3D12_BOX& o) noexcept
  120. : D3D12_BOX(o)
  121. {}
  122. explicit CD3DX12_BOX(LONG Left, LONG Right) noexcept
  123. {
  124. left = static_cast<UINT>(Left);
  125. top = 0;
  126. front = 0;
  127. right = static_cast<UINT>(Right);
  128. bottom = 1;
  129. back = 1;
  130. }
  131. explicit CD3DX12_BOX(LONG Left, LONG Top, LONG Right, LONG Bottom) noexcept
  132. {
  133. left = static_cast<UINT>(Left);
  134. top = static_cast<UINT>(Top);
  135. front = 0;
  136. right = static_cast<UINT>(Right);
  137. bottom = static_cast<UINT>(Bottom);
  138. back = 1;
  139. }
  140. explicit CD3DX12_BOX(LONG Left,
  141. LONG Top,
  142. LONG Front,
  143. LONG Right,
  144. LONG Bottom,
  145. LONG Back) noexcept
  146. {
  147. left = static_cast<UINT>(Left);
  148. top = static_cast<UINT>(Top);
  149. front = static_cast<UINT>(Front);
  150. right = static_cast<UINT>(Right);
  151. bottom = static_cast<UINT>(Bottom);
  152. back = static_cast<UINT>(Back);
  153. }
  154. };
  155. inline bool operator==(const D3D12_BOX& l, const D3D12_BOX& r) noexcept
  156. {
  157. return l.left == r.left && l.top == r.top && l.front == r.front
  158. && l.right == r.right && l.bottom == r.bottom && l.back == r.back;
  159. }
  160. inline bool operator!=(const D3D12_BOX& l, const D3D12_BOX& r) noexcept
  161. {
  162. return !(l == r);
  163. }
  164. //------------------------------------------------------------------------------------------------
  165. struct CD3DX12_DEPTH_STENCIL_DESC : public D3D12_DEPTH_STENCIL_DESC
  166. {
  167. CD3DX12_DEPTH_STENCIL_DESC() = default;
  168. explicit CD3DX12_DEPTH_STENCIL_DESC(
  169. const D3D12_DEPTH_STENCIL_DESC& o) noexcept
  170. : D3D12_DEPTH_STENCIL_DESC(o)
  171. {}
  172. explicit CD3DX12_DEPTH_STENCIL_DESC(CD3DX12_DEFAULT) noexcept
  173. {
  174. DepthEnable = TRUE;
  175. DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
  176. DepthFunc = D3D12_COMPARISON_FUNC_LESS;
  177. StencilEnable = FALSE;
  178. StencilReadMask = D3D12_DEFAULT_STENCIL_READ_MASK;
  179. StencilWriteMask = D3D12_DEFAULT_STENCIL_WRITE_MASK;
  180. const D3D12_DEPTH_STENCILOP_DESC defaultStencilOp
  181. = {D3D12_STENCIL_OP_KEEP,
  182. D3D12_STENCIL_OP_KEEP,
  183. D3D12_STENCIL_OP_KEEP,
  184. D3D12_COMPARISON_FUNC_ALWAYS};
  185. FrontFace = defaultStencilOp;
  186. BackFace = defaultStencilOp;
  187. }
  188. explicit CD3DX12_DEPTH_STENCIL_DESC(BOOL depthEnable,
  189. D3D12_DEPTH_WRITE_MASK depthWriteMask,
  190. D3D12_COMPARISON_FUNC depthFunc,
  191. BOOL stencilEnable,
  192. UINT8 stencilReadMask,
  193. UINT8 stencilWriteMask,
  194. D3D12_STENCIL_OP frontStencilFailOp,
  195. D3D12_STENCIL_OP frontStencilDepthFailOp,
  196. D3D12_STENCIL_OP frontStencilPassOp,
  197. D3D12_COMPARISON_FUNC frontStencilFunc,
  198. D3D12_STENCIL_OP backStencilFailOp,
  199. D3D12_STENCIL_OP backStencilDepthFailOp,
  200. D3D12_STENCIL_OP backStencilPassOp,
  201. D3D12_COMPARISON_FUNC backStencilFunc) noexcept
  202. {
  203. DepthEnable = depthEnable;
  204. DepthWriteMask = depthWriteMask;
  205. DepthFunc = depthFunc;
  206. StencilEnable = stencilEnable;
  207. StencilReadMask = stencilReadMask;
  208. StencilWriteMask = stencilWriteMask;
  209. FrontFace.StencilFailOp = frontStencilFailOp;
  210. FrontFace.StencilDepthFailOp = frontStencilDepthFailOp;
  211. FrontFace.StencilPassOp = frontStencilPassOp;
  212. FrontFace.StencilFunc = frontStencilFunc;
  213. BackFace.StencilFailOp = backStencilFailOp;
  214. BackFace.StencilDepthFailOp = backStencilDepthFailOp;
  215. BackFace.StencilPassOp = backStencilPassOp;
  216. BackFace.StencilFunc = backStencilFunc;
  217. }
  218. };
  219. //------------------------------------------------------------------------------------------------
  220. struct CD3DX12_DEPTH_STENCIL_DESC1 : public D3D12_DEPTH_STENCIL_DESC1
  221. {
  222. CD3DX12_DEPTH_STENCIL_DESC1() = default;
  223. explicit CD3DX12_DEPTH_STENCIL_DESC1(
  224. const D3D12_DEPTH_STENCIL_DESC1& o) noexcept
  225. : D3D12_DEPTH_STENCIL_DESC1(o)
  226. {}
  227. explicit CD3DX12_DEPTH_STENCIL_DESC1(
  228. const D3D12_DEPTH_STENCIL_DESC& o) noexcept
  229. {
  230. DepthEnable = o.DepthEnable;
  231. DepthWriteMask = o.DepthWriteMask;
  232. DepthFunc = o.DepthFunc;
  233. StencilEnable = o.StencilEnable;
  234. StencilReadMask = o.StencilReadMask;
  235. StencilWriteMask = o.StencilWriteMask;
  236. FrontFace.StencilFailOp = o.FrontFace.StencilFailOp;
  237. FrontFace.StencilDepthFailOp = o.FrontFace.StencilDepthFailOp;
  238. FrontFace.StencilPassOp = o.FrontFace.StencilPassOp;
  239. FrontFace.StencilFunc = o.FrontFace.StencilFunc;
  240. BackFace.StencilFailOp = o.BackFace.StencilFailOp;
  241. BackFace.StencilDepthFailOp = o.BackFace.StencilDepthFailOp;
  242. BackFace.StencilPassOp = o.BackFace.StencilPassOp;
  243. BackFace.StencilFunc = o.BackFace.StencilFunc;
  244. DepthBoundsTestEnable = FALSE;
  245. }
  246. explicit CD3DX12_DEPTH_STENCIL_DESC1(CD3DX12_DEFAULT) noexcept
  247. {
  248. DepthEnable = TRUE;
  249. DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
  250. DepthFunc = D3D12_COMPARISON_FUNC_LESS;
  251. StencilEnable = FALSE;
  252. StencilReadMask = D3D12_DEFAULT_STENCIL_READ_MASK;
  253. StencilWriteMask = D3D12_DEFAULT_STENCIL_WRITE_MASK;
  254. const D3D12_DEPTH_STENCILOP_DESC defaultStencilOp
  255. = {D3D12_STENCIL_OP_KEEP,
  256. D3D12_STENCIL_OP_KEEP,
  257. D3D12_STENCIL_OP_KEEP,
  258. D3D12_COMPARISON_FUNC_ALWAYS};
  259. FrontFace = defaultStencilOp;
  260. BackFace = defaultStencilOp;
  261. DepthBoundsTestEnable = FALSE;
  262. }
  263. explicit CD3DX12_DEPTH_STENCIL_DESC1(BOOL depthEnable,
  264. D3D12_DEPTH_WRITE_MASK depthWriteMask,
  265. D3D12_COMPARISON_FUNC depthFunc,
  266. BOOL stencilEnable,
  267. UINT8 stencilReadMask,
  268. UINT8 stencilWriteMask,
  269. D3D12_STENCIL_OP frontStencilFailOp,
  270. D3D12_STENCIL_OP frontStencilDepthFailOp,
  271. D3D12_STENCIL_OP frontStencilPassOp,
  272. D3D12_COMPARISON_FUNC frontStencilFunc,
  273. D3D12_STENCIL_OP backStencilFailOp,
  274. D3D12_STENCIL_OP backStencilDepthFailOp,
  275. D3D12_STENCIL_OP backStencilPassOp,
  276. D3D12_COMPARISON_FUNC backStencilFunc,
  277. BOOL depthBoundsTestEnable) noexcept
  278. {
  279. DepthEnable = depthEnable;
  280. DepthWriteMask = depthWriteMask;
  281. DepthFunc = depthFunc;
  282. StencilEnable = stencilEnable;
  283. StencilReadMask = stencilReadMask;
  284. StencilWriteMask = stencilWriteMask;
  285. FrontFace.StencilFailOp = frontStencilFailOp;
  286. FrontFace.StencilDepthFailOp = frontStencilDepthFailOp;
  287. FrontFace.StencilPassOp = frontStencilPassOp;
  288. FrontFace.StencilFunc = frontStencilFunc;
  289. BackFace.StencilFailOp = backStencilFailOp;
  290. BackFace.StencilDepthFailOp = backStencilDepthFailOp;
  291. BackFace.StencilPassOp = backStencilPassOp;
  292. BackFace.StencilFunc = backStencilFunc;
  293. DepthBoundsTestEnable = depthBoundsTestEnable;
  294. }
  295. operator D3D12_DEPTH_STENCIL_DESC() const noexcept
  296. {
  297. D3D12_DEPTH_STENCIL_DESC D;
  298. D.DepthEnable = DepthEnable;
  299. D.DepthWriteMask = DepthWriteMask;
  300. D.DepthFunc = DepthFunc;
  301. D.StencilEnable = StencilEnable;
  302. D.StencilReadMask = StencilReadMask;
  303. D.StencilWriteMask = StencilWriteMask;
  304. D.FrontFace.StencilFailOp = FrontFace.StencilFailOp;
  305. D.FrontFace.StencilDepthFailOp = FrontFace.StencilDepthFailOp;
  306. D.FrontFace.StencilPassOp = FrontFace.StencilPassOp;
  307. D.FrontFace.StencilFunc = FrontFace.StencilFunc;
  308. D.BackFace.StencilFailOp = BackFace.StencilFailOp;
  309. D.BackFace.StencilDepthFailOp = BackFace.StencilDepthFailOp;
  310. D.BackFace.StencilPassOp = BackFace.StencilPassOp;
  311. D.BackFace.StencilFunc = BackFace.StencilFunc;
  312. return D;
  313. }
  314. };
  315. //------------------------------------------------------------------------------------------------
  316. struct CD3DX12_BLEND_DESC : public D3D12_BLEND_DESC
  317. {
  318. CD3DX12_BLEND_DESC() = default;
  319. explicit CD3DX12_BLEND_DESC(const D3D12_BLEND_DESC& o) noexcept
  320. : D3D12_BLEND_DESC(o)
  321. {}
  322. explicit CD3DX12_BLEND_DESC(CD3DX12_DEFAULT) noexcept
  323. {
  324. AlphaToCoverageEnable = FALSE;
  325. IndependentBlendEnable = FALSE;
  326. const D3D12_RENDER_TARGET_BLEND_DESC defaultRenderTargetBlendDesc = {
  327. FALSE,
  328. FALSE,
  329. D3D12_BLEND_ONE,
  330. D3D12_BLEND_ZERO,
  331. D3D12_BLEND_OP_ADD,
  332. D3D12_BLEND_ONE,
  333. D3D12_BLEND_ZERO,
  334. D3D12_BLEND_OP_ADD,
  335. D3D12_LOGIC_OP_NOOP,
  336. D3D12_COLOR_WRITE_ENABLE_ALL,
  337. };
  338. for (UINT i = 0; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
  339. RenderTarget[i] = defaultRenderTargetBlendDesc;
  340. }
  341. };
  342. //------------------------------------------------------------------------------------------------
  343. struct CD3DX12_RASTERIZER_DESC : public D3D12_RASTERIZER_DESC
  344. {
  345. CD3DX12_RASTERIZER_DESC() = default;
  346. explicit CD3DX12_RASTERIZER_DESC(const D3D12_RASTERIZER_DESC& o) noexcept
  347. : D3D12_RASTERIZER_DESC(o)
  348. {}
  349. explicit CD3DX12_RASTERIZER_DESC(CD3DX12_DEFAULT) noexcept
  350. {
  351. FillMode = D3D12_FILL_MODE_SOLID;
  352. CullMode = D3D12_CULL_MODE_BACK;
  353. FrontCounterClockwise = FALSE;
  354. DepthBias = D3D12_DEFAULT_DEPTH_BIAS;
  355. DepthBiasClamp = D3D12_DEFAULT_DEPTH_BIAS_CLAMP;
  356. SlopeScaledDepthBias = D3D12_DEFAULT_SLOPE_SCALED_DEPTH_BIAS;
  357. DepthClipEnable = TRUE;
  358. MultisampleEnable = FALSE;
  359. AntialiasedLineEnable = FALSE;
  360. ForcedSampleCount = 0;
  361. ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF;
  362. }
  363. explicit CD3DX12_RASTERIZER_DESC(D3D12_FILL_MODE fillMode,
  364. D3D12_CULL_MODE cullMode,
  365. BOOL frontCounterClockwise,
  366. INT depthBias,
  367. FLOAT depthBiasClamp,
  368. FLOAT slopeScaledDepthBias,
  369. BOOL depthClipEnable,
  370. BOOL multisampleEnable,
  371. BOOL antialiasedLineEnable,
  372. UINT forcedSampleCount,
  373. D3D12_CONSERVATIVE_RASTERIZATION_MODE conservativeRaster) noexcept
  374. {
  375. FillMode = fillMode;
  376. CullMode = cullMode;
  377. FrontCounterClockwise = frontCounterClockwise;
  378. DepthBias = depthBias;
  379. DepthBiasClamp = depthBiasClamp;
  380. SlopeScaledDepthBias = slopeScaledDepthBias;
  381. DepthClipEnable = depthClipEnable;
  382. MultisampleEnable = multisampleEnable;
  383. AntialiasedLineEnable = antialiasedLineEnable;
  384. ForcedSampleCount = forcedSampleCount;
  385. ConservativeRaster = conservativeRaster;
  386. }
  387. };
  388. //------------------------------------------------------------------------------------------------
  389. struct CD3DX12_RESOURCE_ALLOCATION_INFO : public D3D12_RESOURCE_ALLOCATION_INFO
  390. {
  391. CD3DX12_RESOURCE_ALLOCATION_INFO() = default;
  392. explicit CD3DX12_RESOURCE_ALLOCATION_INFO(
  393. const D3D12_RESOURCE_ALLOCATION_INFO& o) noexcept
  394. : D3D12_RESOURCE_ALLOCATION_INFO(o)
  395. {}
  396. CD3DX12_RESOURCE_ALLOCATION_INFO(UINT64 size, UINT64 alignment) noexcept
  397. {
  398. SizeInBytes = size;
  399. Alignment = alignment;
  400. }
  401. };
  402. //------------------------------------------------------------------------------------------------
  403. struct CD3DX12_HEAP_PROPERTIES : public D3D12_HEAP_PROPERTIES
  404. {
  405. CD3DX12_HEAP_PROPERTIES() = default;
  406. explicit CD3DX12_HEAP_PROPERTIES(const D3D12_HEAP_PROPERTIES& o) noexcept
  407. : D3D12_HEAP_PROPERTIES(o)
  408. {}
  409. CD3DX12_HEAP_PROPERTIES(D3D12_CPU_PAGE_PROPERTY cpuPageProperty,
  410. D3D12_MEMORY_POOL memoryPoolPreference,
  411. UINT creationNodeMask = 1,
  412. UINT nodeMask = 1)
  413. noexcept
  414. {
  415. Type = D3D12_HEAP_TYPE_CUSTOM;
  416. CPUPageProperty = cpuPageProperty;
  417. MemoryPoolPreference = memoryPoolPreference;
  418. CreationNodeMask = creationNodeMask;
  419. VisibleNodeMask = nodeMask;
  420. }
  421. explicit CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE type,
  422. UINT creationNodeMask = 1,
  423. UINT nodeMask = 1) noexcept
  424. {
  425. Type = type;
  426. CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
  427. MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
  428. CreationNodeMask = creationNodeMask;
  429. VisibleNodeMask = nodeMask;
  430. }
  431. bool IsCPUAccessible() const noexcept
  432. {
  433. return Type == D3D12_HEAP_TYPE_UPLOAD
  434. || Type == D3D12_HEAP_TYPE_READBACK
  435. || (Type == D3D12_HEAP_TYPE_CUSTOM
  436. && (CPUPageProperty == D3D12_CPU_PAGE_PROPERTY_WRITE_COMBINE
  437. || CPUPageProperty == D3D12_CPU_PAGE_PROPERTY_WRITE_BACK));
  438. }
  439. };
  440. inline bool operator==(
  441. const D3D12_HEAP_PROPERTIES& l, const D3D12_HEAP_PROPERTIES& r) noexcept
  442. {
  443. return l.Type == r.Type && l.CPUPageProperty == r.CPUPageProperty
  444. && l.MemoryPoolPreference == r.MemoryPoolPreference
  445. && l.CreationNodeMask == r.CreationNodeMask
  446. && l.VisibleNodeMask == r.VisibleNodeMask;
  447. }
  448. inline bool operator!=(
  449. const D3D12_HEAP_PROPERTIES& l, const D3D12_HEAP_PROPERTIES& r) noexcept
  450. {
  451. return !(l == r);
  452. }
  453. //------------------------------------------------------------------------------------------------
  454. struct CD3DX12_HEAP_DESC : public D3D12_HEAP_DESC
  455. {
  456. CD3DX12_HEAP_DESC() = default;
  457. explicit CD3DX12_HEAP_DESC(const D3D12_HEAP_DESC& o) noexcept
  458. : D3D12_HEAP_DESC(o)
  459. {}
  460. CD3DX12_HEAP_DESC(UINT64 size,
  461. D3D12_HEAP_PROPERTIES properties,
  462. UINT64 alignment = 0,
  463. D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE)
  464. noexcept
  465. {
  466. SizeInBytes = size;
  467. Properties = properties;
  468. Alignment = alignment;
  469. Flags = flags;
  470. }
  471. CD3DX12_HEAP_DESC(UINT64 size,
  472. D3D12_HEAP_TYPE type,
  473. UINT64 alignment = 0,
  474. D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE)
  475. noexcept
  476. {
  477. SizeInBytes = size;
  478. Properties = CD3DX12_HEAP_PROPERTIES(type);
  479. Alignment = alignment;
  480. Flags = flags;
  481. }
  482. CD3DX12_HEAP_DESC(UINT64 size,
  483. D3D12_CPU_PAGE_PROPERTY cpuPageProperty,
  484. D3D12_MEMORY_POOL memoryPoolPreference,
  485. UINT64 alignment = 0,
  486. D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE)
  487. noexcept
  488. {
  489. SizeInBytes = size;
  490. Properties
  491. = CD3DX12_HEAP_PROPERTIES(cpuPageProperty, memoryPoolPreference);
  492. Alignment = alignment;
  493. Flags = flags;
  494. }
  495. CD3DX12_HEAP_DESC(const D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,
  496. D3D12_HEAP_PROPERTIES properties,
  497. D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE)
  498. noexcept
  499. {
  500. SizeInBytes = resAllocInfo.SizeInBytes;
  501. Properties = properties;
  502. Alignment = resAllocInfo.Alignment;
  503. Flags = flags;
  504. }
  505. CD3DX12_HEAP_DESC(const D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,
  506. D3D12_HEAP_TYPE type,
  507. D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE)
  508. noexcept
  509. {
  510. SizeInBytes = resAllocInfo.SizeInBytes;
  511. Properties = CD3DX12_HEAP_PROPERTIES(type);
  512. Alignment = resAllocInfo.Alignment;
  513. Flags = flags;
  514. }
  515. CD3DX12_HEAP_DESC(const D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,
  516. D3D12_CPU_PAGE_PROPERTY cpuPageProperty,
  517. D3D12_MEMORY_POOL memoryPoolPreference,
  518. D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE)
  519. noexcept
  520. {
  521. SizeInBytes = resAllocInfo.SizeInBytes;
  522. Properties
  523. = CD3DX12_HEAP_PROPERTIES(cpuPageProperty, memoryPoolPreference);
  524. Alignment = resAllocInfo.Alignment;
  525. Flags = flags;
  526. }
  527. bool IsCPUAccessible() const noexcept
  528. {
  529. return static_cast<const CD3DX12_HEAP_PROPERTIES*>(&Properties)
  530. ->IsCPUAccessible();
  531. }
  532. };
  533. inline bool operator==(
  534. const D3D12_HEAP_DESC& l, const D3D12_HEAP_DESC& r) noexcept
  535. {
  536. return l.SizeInBytes == r.SizeInBytes && l.Properties == r.Properties
  537. && l.Alignment == r.Alignment && l.Flags == r.Flags;
  538. }
  539. inline bool operator!=(
  540. const D3D12_HEAP_DESC& l, const D3D12_HEAP_DESC& r) noexcept
  541. {
  542. return !(l == r);
  543. }
  544. //------------------------------------------------------------------------------------------------
  545. struct CD3DX12_CLEAR_VALUE : public D3D12_CLEAR_VALUE
  546. {
  547. CD3DX12_CLEAR_VALUE() = default;
  548. explicit CD3DX12_CLEAR_VALUE(const D3D12_CLEAR_VALUE& o) noexcept
  549. : D3D12_CLEAR_VALUE(o)
  550. {}
  551. CD3DX12_CLEAR_VALUE(DXGI_FORMAT format, const FLOAT color[4]) noexcept
  552. {
  553. Format = format;
  554. memcpy(Color, color, sizeof(Color));
  555. }
  556. CD3DX12_CLEAR_VALUE(DXGI_FORMAT format, FLOAT depth, UINT8 stencil) noexcept
  557. {
  558. Format = format;
  559. memset(&Color, 0, sizeof(Color));
  560. /* Use memcpy to preserve NAN values */
  561. memcpy(&DepthStencil.Depth, &depth, sizeof(depth));
  562. DepthStencil.Stencil = stencil;
  563. }
  564. };
  565. //------------------------------------------------------------------------------------------------
  566. struct CD3DX12_RANGE : public D3D12_RANGE
  567. {
  568. CD3DX12_RANGE() = default;
  569. explicit CD3DX12_RANGE(const D3D12_RANGE& o) noexcept
  570. : D3D12_RANGE(o)
  571. {}
  572. CD3DX12_RANGE(SIZE_T begin, SIZE_T end) noexcept
  573. {
  574. Begin = begin;
  575. End = end;
  576. }
  577. };
  578. //------------------------------------------------------------------------------------------------
  579. struct CD3DX12_RANGE_UINT64 : public D3D12_RANGE_UINT64
  580. {
  581. CD3DX12_RANGE_UINT64() = default;
  582. explicit CD3DX12_RANGE_UINT64(const D3D12_RANGE_UINT64& o) noexcept
  583. : D3D12_RANGE_UINT64(o)
  584. {}
  585. CD3DX12_RANGE_UINT64(UINT64 begin, UINT64 end) noexcept
  586. {
  587. Begin = begin;
  588. End = end;
  589. }
  590. };
  591. //------------------------------------------------------------------------------------------------
  592. struct CD3DX12_SUBRESOURCE_RANGE_UINT64 : public D3D12_SUBRESOURCE_RANGE_UINT64
  593. {
  594. CD3DX12_SUBRESOURCE_RANGE_UINT64() = default;
  595. explicit CD3DX12_SUBRESOURCE_RANGE_UINT64(
  596. const D3D12_SUBRESOURCE_RANGE_UINT64& o) noexcept
  597. : D3D12_SUBRESOURCE_RANGE_UINT64(o)
  598. {}
  599. CD3DX12_SUBRESOURCE_RANGE_UINT64(
  600. UINT subresource, const D3D12_RANGE_UINT64& range)
  601. noexcept
  602. {
  603. Subresource = subresource;
  604. Range = range;
  605. }
  606. CD3DX12_SUBRESOURCE_RANGE_UINT64(UINT subresource, UINT64 begin, UINT64 end)
  607. noexcept
  608. {
  609. Subresource = subresource;
  610. Range.Begin = begin;
  611. Range.End = end;
  612. }
  613. };
  614. //------------------------------------------------------------------------------------------------
  615. struct CD3DX12_SHADER_BYTECODE : public D3D12_SHADER_BYTECODE
  616. {
  617. CD3DX12_SHADER_BYTECODE() = default;
  618. explicit CD3DX12_SHADER_BYTECODE(const D3D12_SHADER_BYTECODE& o) noexcept
  619. : D3D12_SHADER_BYTECODE(o)
  620. {}
  621. CD3DX12_SHADER_BYTECODE(_In_ ID3DBlob* pShaderBlob) noexcept
  622. {
  623. pShaderBytecode = pShaderBlob->GetBufferPointer();
  624. BytecodeLength = pShaderBlob->GetBufferSize();
  625. }
  626. CD3DX12_SHADER_BYTECODE(const void* _pShaderBytecode, SIZE_T bytecodeLength)
  627. noexcept
  628. {
  629. pShaderBytecode = _pShaderBytecode;
  630. BytecodeLength = bytecodeLength;
  631. }
  632. };
  633. //------------------------------------------------------------------------------------------------
  634. struct CD3DX12_TILED_RESOURCE_COORDINATE
  635. : public D3D12_TILED_RESOURCE_COORDINATE
  636. {
  637. CD3DX12_TILED_RESOURCE_COORDINATE() = default;
  638. explicit CD3DX12_TILED_RESOURCE_COORDINATE(
  639. const D3D12_TILED_RESOURCE_COORDINATE& o) noexcept
  640. : D3D12_TILED_RESOURCE_COORDINATE(o)
  641. {}
  642. CD3DX12_TILED_RESOURCE_COORDINATE(UINT x, UINT y, UINT z, UINT subresource)
  643. noexcept
  644. {
  645. X = x;
  646. Y = y;
  647. Z = z;
  648. Subresource = subresource;
  649. }
  650. };
  651. //------------------------------------------------------------------------------------------------
  652. struct CD3DX12_TILE_REGION_SIZE : public D3D12_TILE_REGION_SIZE
  653. {
  654. CD3DX12_TILE_REGION_SIZE() = default;
  655. explicit CD3DX12_TILE_REGION_SIZE(const D3D12_TILE_REGION_SIZE& o) noexcept
  656. : D3D12_TILE_REGION_SIZE(o)
  657. {}
  658. CD3DX12_TILE_REGION_SIZE(
  659. UINT numTiles, BOOL useBox, UINT width, UINT16 height, UINT16 depth)
  660. noexcept
  661. {
  662. NumTiles = numTiles;
  663. UseBox = useBox;
  664. Width = width;
  665. Height = height;
  666. Depth = depth;
  667. }
  668. };
  669. //------------------------------------------------------------------------------------------------
  670. struct CD3DX12_SUBRESOURCE_TILING : public D3D12_SUBRESOURCE_TILING
  671. {
  672. CD3DX12_SUBRESOURCE_TILING() = default;
  673. explicit CD3DX12_SUBRESOURCE_TILING(
  674. const D3D12_SUBRESOURCE_TILING& o) noexcept
  675. : D3D12_SUBRESOURCE_TILING(o)
  676. {}
  677. CD3DX12_SUBRESOURCE_TILING(UINT widthInTiles,
  678. UINT16 heightInTiles,
  679. UINT16 depthInTiles,
  680. UINT startTileIndexInOverallResource)
  681. noexcept
  682. {
  683. WidthInTiles = widthInTiles;
  684. HeightInTiles = heightInTiles;
  685. DepthInTiles = depthInTiles;
  686. StartTileIndexInOverallResource = startTileIndexInOverallResource;
  687. }
  688. };
  689. //------------------------------------------------------------------------------------------------
  690. struct CD3DX12_TILE_SHAPE : public D3D12_TILE_SHAPE
  691. {
  692. CD3DX12_TILE_SHAPE() = default;
  693. explicit CD3DX12_TILE_SHAPE(const D3D12_TILE_SHAPE& o) noexcept
  694. : D3D12_TILE_SHAPE(o)
  695. {}
  696. CD3DX12_TILE_SHAPE(
  697. UINT widthInTexels, UINT heightInTexels, UINT depthInTexels)
  698. noexcept
  699. {
  700. WidthInTexels = widthInTexels;
  701. HeightInTexels = heightInTexels;
  702. DepthInTexels = depthInTexels;
  703. }
  704. };
  705. //------------------------------------------------------------------------------------------------
  706. struct CD3DX12_RESOURCE_BARRIER : public D3D12_RESOURCE_BARRIER
  707. {
  708. CD3DX12_RESOURCE_BARRIER() = default;
  709. explicit CD3DX12_RESOURCE_BARRIER(const D3D12_RESOURCE_BARRIER& o) noexcept
  710. : D3D12_RESOURCE_BARRIER(o)
  711. {}
  712. inline static CD3DX12_RESOURCE_BARRIER Transition(
  713. _In_ ID3D12Resource* pResource,
  714. D3D12_RESOURCE_STATES stateBefore,
  715. D3D12_RESOURCE_STATES stateAfter,
  716. UINT subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
  717. D3D12_RESOURCE_BARRIER_FLAGS flags
  718. = D3D12_RESOURCE_BARRIER_FLAG_NONE) noexcept
  719. {
  720. CD3DX12_RESOURCE_BARRIER result = {};
  721. D3D12_RESOURCE_BARRIER& barrier = result;
  722. result.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
  723. result.Flags = flags;
  724. barrier.Transition.pResource = pResource;
  725. barrier.Transition.StateBefore = stateBefore;
  726. barrier.Transition.StateAfter = stateAfter;
  727. barrier.Transition.Subresource = subresource;
  728. return result;
  729. }
  730. inline static CD3DX12_RESOURCE_BARRIER Aliasing(
  731. _In_ ID3D12Resource* pResourceBefore,
  732. _In_ ID3D12Resource* pResourceAfter) noexcept
  733. {
  734. CD3DX12_RESOURCE_BARRIER result = {};
  735. D3D12_RESOURCE_BARRIER& barrier = result;
  736. result.Type = D3D12_RESOURCE_BARRIER_TYPE_ALIASING;
  737. barrier.Aliasing.pResourceBefore = pResourceBefore;
  738. barrier.Aliasing.pResourceAfter = pResourceAfter;
  739. return result;
  740. }
  741. inline static CD3DX12_RESOURCE_BARRIER UAV(
  742. _In_ ID3D12Resource* pResource) noexcept
  743. {
  744. CD3DX12_RESOURCE_BARRIER result = {};
  745. D3D12_RESOURCE_BARRIER& barrier = result;
  746. result.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
  747. barrier.UAV.pResource = pResource;
  748. return result;
  749. }
  750. };
  751. //------------------------------------------------------------------------------------------------
  752. struct CD3DX12_PACKED_MIP_INFO : public D3D12_PACKED_MIP_INFO
  753. {
  754. CD3DX12_PACKED_MIP_INFO() = default;
  755. explicit CD3DX12_PACKED_MIP_INFO(const D3D12_PACKED_MIP_INFO& o) noexcept
  756. : D3D12_PACKED_MIP_INFO(o)
  757. {}
  758. CD3DX12_PACKED_MIP_INFO(UINT8 numStandardMips,
  759. UINT8 numPackedMips,
  760. UINT numTilesForPackedMips,
  761. UINT startTileIndexInOverallResource)
  762. noexcept
  763. {
  764. NumStandardMips = numStandardMips;
  765. NumPackedMips = numPackedMips;
  766. NumTilesForPackedMips = numTilesForPackedMips;
  767. StartTileIndexInOverallResource = startTileIndexInOverallResource;
  768. }
  769. };
  770. //------------------------------------------------------------------------------------------------
  771. struct CD3DX12_SUBRESOURCE_FOOTPRINT : public D3D12_SUBRESOURCE_FOOTPRINT
  772. {
  773. CD3DX12_SUBRESOURCE_FOOTPRINT() = default;
  774. explicit CD3DX12_SUBRESOURCE_FOOTPRINT(
  775. const D3D12_SUBRESOURCE_FOOTPRINT& o) noexcept
  776. : D3D12_SUBRESOURCE_FOOTPRINT(o)
  777. {}
  778. CD3DX12_SUBRESOURCE_FOOTPRINT(
  779. DXGI_FORMAT format, UINT width, UINT height, UINT depth, UINT rowPitch)
  780. noexcept
  781. {
  782. Format = format;
  783. Width = width;
  784. Height = height;
  785. Depth = depth;
  786. RowPitch = rowPitch;
  787. }
  788. explicit CD3DX12_SUBRESOURCE_FOOTPRINT(
  789. const D3D12_RESOURCE_DESC& resDesc, UINT rowPitch) noexcept
  790. {
  791. Format = resDesc.Format;
  792. Width = UINT(resDesc.Width);
  793. Height = resDesc.Height;
  794. Depth = (resDesc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D
  795. ? resDesc.DepthOrArraySize
  796. : 1);
  797. RowPitch = rowPitch;
  798. }
  799. };
  800. //------------------------------------------------------------------------------------------------
  801. struct CD3DX12_TEXTURE_COPY_LOCATION : public D3D12_TEXTURE_COPY_LOCATION
  802. {
  803. CD3DX12_TEXTURE_COPY_LOCATION() = default;
  804. explicit CD3DX12_TEXTURE_COPY_LOCATION(
  805. const D3D12_TEXTURE_COPY_LOCATION& o) noexcept
  806. : D3D12_TEXTURE_COPY_LOCATION(o)
  807. {}
  808. CD3DX12_TEXTURE_COPY_LOCATION(_In_ ID3D12Resource* pRes) noexcept
  809. {
  810. pResource = pRes;
  811. Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
  812. PlacedFootprint = {};
  813. }
  814. CD3DX12_TEXTURE_COPY_LOCATION(_In_ ID3D12Resource* pRes,
  815. D3D12_PLACED_SUBRESOURCE_FOOTPRINT const& Footprint)
  816. noexcept
  817. {
  818. pResource = pRes;
  819. Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
  820. PlacedFootprint = Footprint;
  821. }
  822. CD3DX12_TEXTURE_COPY_LOCATION(_In_ ID3D12Resource* pRes, UINT Sub) noexcept
  823. {
  824. pResource = pRes;
  825. Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
  826. PlacedFootprint = {};
  827. SubresourceIndex = Sub;
  828. }
  829. };
  830. //------------------------------------------------------------------------------------------------
  831. struct CD3DX12_DESCRIPTOR_RANGE : public D3D12_DESCRIPTOR_RANGE
  832. {
  833. CD3DX12_DESCRIPTOR_RANGE() = default;
  834. explicit CD3DX12_DESCRIPTOR_RANGE(const D3D12_DESCRIPTOR_RANGE& o) noexcept
  835. : D3D12_DESCRIPTOR_RANGE(o)
  836. {}
  837. CD3DX12_DESCRIPTOR_RANGE(D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
  838. UINT numDescriptors,
  839. UINT baseShaderRegister,
  840. UINT registerSpace = 0,
  841. UINT offsetInDescriptorsFromTableStart
  842. = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
  843. noexcept
  844. {
  845. Init(rangeType,
  846. numDescriptors,
  847. baseShaderRegister,
  848. registerSpace,
  849. offsetInDescriptorsFromTableStart);
  850. }
  851. inline void Init(D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
  852. UINT numDescriptors,
  853. UINT baseShaderRegister,
  854. UINT registerSpace = 0,
  855. UINT offsetInDescriptorsFromTableStart
  856. = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) noexcept
  857. {
  858. Init(*this,
  859. rangeType,
  860. numDescriptors,
  861. baseShaderRegister,
  862. registerSpace,
  863. offsetInDescriptorsFromTableStart);
  864. }
  865. inline static void Init(_Out_ D3D12_DESCRIPTOR_RANGE& range,
  866. D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
  867. UINT numDescriptors,
  868. UINT baseShaderRegister,
  869. UINT registerSpace = 0,
  870. UINT offsetInDescriptorsFromTableStart
  871. = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) noexcept
  872. {
  873. range.RangeType = rangeType;
  874. range.NumDescriptors = numDescriptors;
  875. range.BaseShaderRegister = baseShaderRegister;
  876. range.RegisterSpace = registerSpace;
  877. range.OffsetInDescriptorsFromTableStart
  878. = offsetInDescriptorsFromTableStart;
  879. }
  880. };
  881. //------------------------------------------------------------------------------------------------
  882. struct CD3DX12_ROOT_DESCRIPTOR_TABLE : public D3D12_ROOT_DESCRIPTOR_TABLE
  883. {
  884. CD3DX12_ROOT_DESCRIPTOR_TABLE() = default;
  885. explicit CD3DX12_ROOT_DESCRIPTOR_TABLE(
  886. const D3D12_ROOT_DESCRIPTOR_TABLE& o) noexcept
  887. : D3D12_ROOT_DESCRIPTOR_TABLE(o)
  888. {}
  889. CD3DX12_ROOT_DESCRIPTOR_TABLE(UINT numDescriptorRanges,
  890. _In_reads_opt_(numDescriptorRanges)
  891. const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges)
  892. noexcept
  893. {
  894. Init(numDescriptorRanges, _pDescriptorRanges);
  895. }
  896. inline void Init(UINT numDescriptorRanges,
  897. _In_reads_opt_(numDescriptorRanges)
  898. const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges) noexcept
  899. {
  900. Init(*this, numDescriptorRanges, _pDescriptorRanges);
  901. }
  902. inline static void Init(
  903. _Out_ D3D12_ROOT_DESCRIPTOR_TABLE& rootDescriptorTable,
  904. UINT numDescriptorRanges,
  905. _In_reads_opt_(numDescriptorRanges)
  906. const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges) noexcept
  907. {
  908. rootDescriptorTable.NumDescriptorRanges = numDescriptorRanges;
  909. rootDescriptorTable.pDescriptorRanges = _pDescriptorRanges;
  910. }
  911. };
  912. //------------------------------------------------------------------------------------------------
  913. struct CD3DX12_ROOT_CONSTANTS : public D3D12_ROOT_CONSTANTS
  914. {
  915. CD3DX12_ROOT_CONSTANTS() = default;
  916. explicit CD3DX12_ROOT_CONSTANTS(const D3D12_ROOT_CONSTANTS& o) noexcept
  917. : D3D12_ROOT_CONSTANTS(o)
  918. {}
  919. CD3DX12_ROOT_CONSTANTS(
  920. UINT num32BitValues, UINT shaderRegister, UINT registerSpace = 0)
  921. noexcept
  922. {
  923. Init(num32BitValues, shaderRegister, registerSpace);
  924. }
  925. inline void Init(UINT num32BitValues,
  926. UINT shaderRegister,
  927. UINT registerSpace = 0) noexcept
  928. {
  929. Init(*this, num32BitValues, shaderRegister, registerSpace);
  930. }
  931. inline static void Init(_Out_ D3D12_ROOT_CONSTANTS& rootConstants,
  932. UINT num32BitValues,
  933. UINT shaderRegister,
  934. UINT registerSpace = 0) noexcept
  935. {
  936. rootConstants.Num32BitValues = num32BitValues;
  937. rootConstants.ShaderRegister = shaderRegister;
  938. rootConstants.RegisterSpace = registerSpace;
  939. }
  940. };
  941. //------------------------------------------------------------------------------------------------
  942. struct CD3DX12_ROOT_DESCRIPTOR : public D3D12_ROOT_DESCRIPTOR
  943. {
  944. CD3DX12_ROOT_DESCRIPTOR() = default;
  945. explicit CD3DX12_ROOT_DESCRIPTOR(const D3D12_ROOT_DESCRIPTOR& o) noexcept
  946. : D3D12_ROOT_DESCRIPTOR(o)
  947. {}
  948. CD3DX12_ROOT_DESCRIPTOR(UINT shaderRegister, UINT registerSpace = 0)
  949. noexcept
  950. {
  951. Init(shaderRegister, registerSpace);
  952. }
  953. inline void Init(UINT shaderRegister, UINT registerSpace = 0) noexcept
  954. {
  955. Init(*this, shaderRegister, registerSpace);
  956. }
  957. inline static void Init(_Out_ D3D12_ROOT_DESCRIPTOR& table,
  958. UINT shaderRegister,
  959. UINT registerSpace = 0) noexcept
  960. {
  961. table.ShaderRegister = shaderRegister;
  962. table.RegisterSpace = registerSpace;
  963. }
  964. };
  965. //------------------------------------------------------------------------------------------------
  966. struct CD3DX12_ROOT_PARAMETER : public D3D12_ROOT_PARAMETER
  967. {
  968. CD3DX12_ROOT_PARAMETER() = default;
  969. explicit CD3DX12_ROOT_PARAMETER(const D3D12_ROOT_PARAMETER& o) noexcept
  970. : D3D12_ROOT_PARAMETER(o)
  971. {}
  972. inline static void InitAsDescriptorTable(
  973. _Out_ D3D12_ROOT_PARAMETER& rootParam,
  974. UINT numDescriptorRanges,
  975. _In_reads_(numDescriptorRanges)
  976. const D3D12_DESCRIPTOR_RANGE* pDescriptorRanges,
  977. D3D12_SHADER_VISIBILITY visibility
  978. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  979. {
  980. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
  981. rootParam.ShaderVisibility = visibility;
  982. CD3DX12_ROOT_DESCRIPTOR_TABLE::Init(
  983. rootParam.DescriptorTable, numDescriptorRanges, pDescriptorRanges);
  984. }
  985. inline static void InitAsConstants(_Out_ D3D12_ROOT_PARAMETER& rootParam,
  986. UINT num32BitValues,
  987. UINT shaderRegister,
  988. UINT registerSpace = 0,
  989. D3D12_SHADER_VISIBILITY visibility
  990. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  991. {
  992. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
  993. rootParam.ShaderVisibility = visibility;
  994. CD3DX12_ROOT_CONSTANTS::Init(
  995. rootParam.Constants, num32BitValues, shaderRegister, registerSpace);
  996. }
  997. inline static void InitAsConstantBufferView(
  998. _Out_ D3D12_ROOT_PARAMETER& rootParam,
  999. UINT shaderRegister,
  1000. UINT registerSpace = 0,
  1001. D3D12_SHADER_VISIBILITY visibility
  1002. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  1003. {
  1004. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
  1005. rootParam.ShaderVisibility = visibility;
  1006. CD3DX12_ROOT_DESCRIPTOR::Init(
  1007. rootParam.Descriptor, shaderRegister, registerSpace);
  1008. }
  1009. inline static void InitAsShaderResourceView(
  1010. _Out_ D3D12_ROOT_PARAMETER& rootParam,
  1011. UINT shaderRegister,
  1012. UINT registerSpace = 0,
  1013. D3D12_SHADER_VISIBILITY visibility
  1014. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  1015. {
  1016. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;
  1017. rootParam.ShaderVisibility = visibility;
  1018. CD3DX12_ROOT_DESCRIPTOR::Init(
  1019. rootParam.Descriptor, shaderRegister, registerSpace);
  1020. }
  1021. inline static void InitAsUnorderedAccessView(
  1022. _Out_ D3D12_ROOT_PARAMETER& rootParam,
  1023. UINT shaderRegister,
  1024. UINT registerSpace = 0,
  1025. D3D12_SHADER_VISIBILITY visibility
  1026. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  1027. {
  1028. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV;
  1029. rootParam.ShaderVisibility = visibility;
  1030. CD3DX12_ROOT_DESCRIPTOR::Init(
  1031. rootParam.Descriptor, shaderRegister, registerSpace);
  1032. }
  1033. inline void InitAsDescriptorTable(UINT numDescriptorRanges,
  1034. _In_reads_(numDescriptorRanges)
  1035. const D3D12_DESCRIPTOR_RANGE* pDescriptorRanges,
  1036. D3D12_SHADER_VISIBILITY visibility
  1037. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  1038. {
  1039. InitAsDescriptorTable(
  1040. *this, numDescriptorRanges, pDescriptorRanges, visibility);
  1041. }
  1042. inline void InitAsConstants(UINT num32BitValues,
  1043. UINT shaderRegister,
  1044. UINT registerSpace = 0,
  1045. D3D12_SHADER_VISIBILITY visibility
  1046. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  1047. {
  1048. InitAsConstants(
  1049. *this, num32BitValues, shaderRegister, registerSpace, visibility);
  1050. }
  1051. inline void InitAsConstantBufferView(UINT shaderRegister,
  1052. UINT registerSpace = 0,
  1053. D3D12_SHADER_VISIBILITY visibility
  1054. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  1055. {
  1056. InitAsConstantBufferView(
  1057. *this, shaderRegister, registerSpace, visibility);
  1058. }
  1059. inline void InitAsShaderResourceView(UINT shaderRegister,
  1060. UINT registerSpace = 0,
  1061. D3D12_SHADER_VISIBILITY visibility
  1062. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  1063. {
  1064. InitAsShaderResourceView(
  1065. *this, shaderRegister, registerSpace, visibility);
  1066. }
  1067. inline void InitAsUnorderedAccessView(UINT shaderRegister,
  1068. UINT registerSpace = 0,
  1069. D3D12_SHADER_VISIBILITY visibility
  1070. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  1071. {
  1072. InitAsUnorderedAccessView(
  1073. *this, shaderRegister, registerSpace, visibility);
  1074. }
  1075. };
  1076. //------------------------------------------------------------------------------------------------
  1077. struct CD3DX12_STATIC_SAMPLER_DESC : public D3D12_STATIC_SAMPLER_DESC
  1078. {
  1079. CD3DX12_STATIC_SAMPLER_DESC() = default;
  1080. explicit CD3DX12_STATIC_SAMPLER_DESC(
  1081. const D3D12_STATIC_SAMPLER_DESC& o) noexcept
  1082. : D3D12_STATIC_SAMPLER_DESC(o)
  1083. {}
  1084. CD3DX12_STATIC_SAMPLER_DESC(UINT shaderRegister,
  1085. D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
  1086. D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  1087. D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  1088. D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  1089. FLOAT mipLODBias = 0,
  1090. UINT maxAnisotropy = 16,
  1091. D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
  1092. D3D12_STATIC_BORDER_COLOR borderColor
  1093. = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
  1094. FLOAT minLOD = 0.f,
  1095. FLOAT maxLOD = D3D12_FLOAT32_MAX,
  1096. D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
  1097. UINT registerSpace = 0)
  1098. noexcept
  1099. {
  1100. Init(shaderRegister,
  1101. filter,
  1102. addressU,
  1103. addressV,
  1104. addressW,
  1105. mipLODBias,
  1106. maxAnisotropy,
  1107. comparisonFunc,
  1108. borderColor,
  1109. minLOD,
  1110. maxLOD,
  1111. shaderVisibility,
  1112. registerSpace);
  1113. }
  1114. inline static void Init(_Out_ D3D12_STATIC_SAMPLER_DESC& samplerDesc,
  1115. UINT shaderRegister,
  1116. D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
  1117. D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  1118. D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  1119. D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  1120. FLOAT mipLODBias = 0,
  1121. UINT maxAnisotropy = 16,
  1122. D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
  1123. D3D12_STATIC_BORDER_COLOR borderColor
  1124. = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
  1125. FLOAT minLOD = 0.f,
  1126. FLOAT maxLOD = D3D12_FLOAT32_MAX,
  1127. D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
  1128. UINT registerSpace = 0) noexcept
  1129. {
  1130. samplerDesc.ShaderRegister = shaderRegister;
  1131. samplerDesc.Filter = filter;
  1132. samplerDesc.AddressU = addressU;
  1133. samplerDesc.AddressV = addressV;
  1134. samplerDesc.AddressW = addressW;
  1135. samplerDesc.MipLODBias = mipLODBias;
  1136. samplerDesc.MaxAnisotropy = maxAnisotropy;
  1137. samplerDesc.ComparisonFunc = comparisonFunc;
  1138. samplerDesc.BorderColor = borderColor;
  1139. samplerDesc.MinLOD = minLOD;
  1140. samplerDesc.MaxLOD = maxLOD;
  1141. samplerDesc.ShaderVisibility = shaderVisibility;
  1142. samplerDesc.RegisterSpace = registerSpace;
  1143. }
  1144. inline void Init(UINT shaderRegister,
  1145. D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
  1146. D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  1147. D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  1148. D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  1149. FLOAT mipLODBias = 0,
  1150. UINT maxAnisotropy = 16,
  1151. D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
  1152. D3D12_STATIC_BORDER_COLOR borderColor
  1153. = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
  1154. FLOAT minLOD = 0.f,
  1155. FLOAT maxLOD = D3D12_FLOAT32_MAX,
  1156. D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
  1157. UINT registerSpace = 0) noexcept
  1158. {
  1159. Init(*this,
  1160. shaderRegister,
  1161. filter,
  1162. addressU,
  1163. addressV,
  1164. addressW,
  1165. mipLODBias,
  1166. maxAnisotropy,
  1167. comparisonFunc,
  1168. borderColor,
  1169. minLOD,
  1170. maxLOD,
  1171. shaderVisibility,
  1172. registerSpace);
  1173. }
  1174. };
  1175. //------------------------------------------------------------------------------------------------
  1176. struct CD3DX12_ROOT_SIGNATURE_DESC : public D3D12_ROOT_SIGNATURE_DESC
  1177. {
  1178. CD3DX12_ROOT_SIGNATURE_DESC() = default;
  1179. explicit CD3DX12_ROOT_SIGNATURE_DESC(
  1180. const D3D12_ROOT_SIGNATURE_DESC& o) noexcept
  1181. : D3D12_ROOT_SIGNATURE_DESC(o)
  1182. {}
  1183. CD3DX12_ROOT_SIGNATURE_DESC(UINT numParameters,
  1184. _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
  1185. UINT numStaticSamplers = 0,
  1186. _In_reads_opt_(numStaticSamplers)
  1187. const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers
  1188. = nullptr,
  1189. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE)
  1190. noexcept
  1191. {
  1192. Init(numParameters,
  1193. _pParameters,
  1194. numStaticSamplers,
  1195. _pStaticSamplers,
  1196. flags);
  1197. }
  1198. CD3DX12_ROOT_SIGNATURE_DESC(CD3DX12_DEFAULT) noexcept
  1199. {
  1200. Init(0, nullptr, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  1201. }
  1202. inline void Init(UINT numParameters,
  1203. _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
  1204. UINT numStaticSamplers = 0,
  1205. _In_reads_opt_(numStaticSamplers)
  1206. const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers
  1207. = nullptr,
  1208. D3D12_ROOT_SIGNATURE_FLAGS flags
  1209. = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
  1210. {
  1211. Init(*this,
  1212. numParameters,
  1213. _pParameters,
  1214. numStaticSamplers,
  1215. _pStaticSamplers,
  1216. flags);
  1217. }
  1218. inline static void Init(_Out_ D3D12_ROOT_SIGNATURE_DESC& desc,
  1219. UINT numParameters,
  1220. _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
  1221. UINT numStaticSamplers = 0,
  1222. _In_reads_opt_(numStaticSamplers)
  1223. const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers
  1224. = nullptr,
  1225. D3D12_ROOT_SIGNATURE_FLAGS flags
  1226. = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
  1227. {
  1228. desc.NumParameters = numParameters;
  1229. desc.pParameters = _pParameters;
  1230. desc.NumStaticSamplers = numStaticSamplers;
  1231. desc.pStaticSamplers = _pStaticSamplers;
  1232. desc.Flags = flags;
  1233. }
  1234. };
  1235. //------------------------------------------------------------------------------------------------
  1236. struct CD3DX12_DESCRIPTOR_RANGE1 : public D3D12_DESCRIPTOR_RANGE1
  1237. {
  1238. CD3DX12_DESCRIPTOR_RANGE1() = default;
  1239. explicit CD3DX12_DESCRIPTOR_RANGE1(
  1240. const D3D12_DESCRIPTOR_RANGE1& o) noexcept
  1241. : D3D12_DESCRIPTOR_RANGE1(o)
  1242. {}
  1243. CD3DX12_DESCRIPTOR_RANGE1(D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
  1244. UINT numDescriptors,
  1245. UINT baseShaderRegister,
  1246. UINT registerSpace = 0,
  1247. D3D12_DESCRIPTOR_RANGE_FLAGS flags = D3D12_DESCRIPTOR_RANGE_FLAG_NONE,
  1248. UINT offsetInDescriptorsFromTableStart
  1249. = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
  1250. noexcept
  1251. {
  1252. Init(rangeType,
  1253. numDescriptors,
  1254. baseShaderRegister,
  1255. registerSpace,
  1256. flags,
  1257. offsetInDescriptorsFromTableStart);
  1258. }
  1259. inline void Init(D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
  1260. UINT numDescriptors,
  1261. UINT baseShaderRegister,
  1262. UINT registerSpace = 0,
  1263. D3D12_DESCRIPTOR_RANGE_FLAGS flags = D3D12_DESCRIPTOR_RANGE_FLAG_NONE,
  1264. UINT offsetInDescriptorsFromTableStart
  1265. = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) noexcept
  1266. {
  1267. Init(*this,
  1268. rangeType,
  1269. numDescriptors,
  1270. baseShaderRegister,
  1271. registerSpace,
  1272. flags,
  1273. offsetInDescriptorsFromTableStart);
  1274. }
  1275. inline static void Init(_Out_ D3D12_DESCRIPTOR_RANGE1& range,
  1276. D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
  1277. UINT numDescriptors,
  1278. UINT baseShaderRegister,
  1279. UINT registerSpace = 0,
  1280. D3D12_DESCRIPTOR_RANGE_FLAGS flags = D3D12_DESCRIPTOR_RANGE_FLAG_NONE,
  1281. UINT offsetInDescriptorsFromTableStart
  1282. = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) noexcept
  1283. {
  1284. range.RangeType = rangeType;
  1285. range.NumDescriptors = numDescriptors;
  1286. range.BaseShaderRegister = baseShaderRegister;
  1287. range.RegisterSpace = registerSpace;
  1288. range.Flags = flags;
  1289. range.OffsetInDescriptorsFromTableStart
  1290. = offsetInDescriptorsFromTableStart;
  1291. }
  1292. };
  1293. //------------------------------------------------------------------------------------------------
  1294. struct CD3DX12_ROOT_DESCRIPTOR_TABLE1 : public D3D12_ROOT_DESCRIPTOR_TABLE1
  1295. {
  1296. CD3DX12_ROOT_DESCRIPTOR_TABLE1() = default;
  1297. explicit CD3DX12_ROOT_DESCRIPTOR_TABLE1(
  1298. const D3D12_ROOT_DESCRIPTOR_TABLE1& o) noexcept
  1299. : D3D12_ROOT_DESCRIPTOR_TABLE1(o)
  1300. {}
  1301. CD3DX12_ROOT_DESCRIPTOR_TABLE1(UINT numDescriptorRanges,
  1302. _In_reads_opt_(numDescriptorRanges)
  1303. const D3D12_DESCRIPTOR_RANGE1* _pDescriptorRanges)
  1304. noexcept
  1305. {
  1306. Init(numDescriptorRanges, _pDescriptorRanges);
  1307. }
  1308. inline void Init(UINT numDescriptorRanges,
  1309. _In_reads_opt_(numDescriptorRanges)
  1310. const D3D12_DESCRIPTOR_RANGE1* _pDescriptorRanges) noexcept
  1311. {
  1312. Init(*this, numDescriptorRanges, _pDescriptorRanges);
  1313. }
  1314. inline static void Init(
  1315. _Out_ D3D12_ROOT_DESCRIPTOR_TABLE1& rootDescriptorTable,
  1316. UINT numDescriptorRanges,
  1317. _In_reads_opt_(numDescriptorRanges)
  1318. const D3D12_DESCRIPTOR_RANGE1* _pDescriptorRanges) noexcept
  1319. {
  1320. rootDescriptorTable.NumDescriptorRanges = numDescriptorRanges;
  1321. rootDescriptorTable.pDescriptorRanges = _pDescriptorRanges;
  1322. }
  1323. };
  1324. //------------------------------------------------------------------------------------------------
  1325. struct CD3DX12_ROOT_DESCRIPTOR1 : public D3D12_ROOT_DESCRIPTOR1
  1326. {
  1327. CD3DX12_ROOT_DESCRIPTOR1() = default;
  1328. explicit CD3DX12_ROOT_DESCRIPTOR1(const D3D12_ROOT_DESCRIPTOR1& o) noexcept
  1329. : D3D12_ROOT_DESCRIPTOR1(o)
  1330. {}
  1331. CD3DX12_ROOT_DESCRIPTOR1(UINT shaderRegister,
  1332. UINT registerSpace = 0,
  1333. D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE)
  1334. noexcept
  1335. {
  1336. Init(shaderRegister, registerSpace, flags);
  1337. }
  1338. inline void Init(UINT shaderRegister,
  1339. UINT registerSpace = 0,
  1340. D3D12_ROOT_DESCRIPTOR_FLAGS flags
  1341. = D3D12_ROOT_DESCRIPTOR_FLAG_NONE) noexcept
  1342. {
  1343. Init(*this, shaderRegister, registerSpace, flags);
  1344. }
  1345. inline static void Init(_Out_ D3D12_ROOT_DESCRIPTOR1& table,
  1346. UINT shaderRegister,
  1347. UINT registerSpace = 0,
  1348. D3D12_ROOT_DESCRIPTOR_FLAGS flags
  1349. = D3D12_ROOT_DESCRIPTOR_FLAG_NONE) noexcept
  1350. {
  1351. table.ShaderRegister = shaderRegister;
  1352. table.RegisterSpace = registerSpace;
  1353. table.Flags = flags;
  1354. }
  1355. };
  1356. //------------------------------------------------------------------------------------------------
  1357. struct CD3DX12_ROOT_PARAMETER1 : public D3D12_ROOT_PARAMETER1
  1358. {
  1359. CD3DX12_ROOT_PARAMETER1() = default;
  1360. explicit CD3DX12_ROOT_PARAMETER1(const D3D12_ROOT_PARAMETER1& o) noexcept
  1361. : D3D12_ROOT_PARAMETER1(o)
  1362. {}
  1363. inline static void InitAsDescriptorTable(
  1364. _Out_ D3D12_ROOT_PARAMETER1& rootParam,
  1365. UINT numDescriptorRanges,
  1366. _In_reads_(numDescriptorRanges)
  1367. const D3D12_DESCRIPTOR_RANGE1* pDescriptorRanges,
  1368. D3D12_SHADER_VISIBILITY visibility
  1369. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  1370. {
  1371. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
  1372. rootParam.ShaderVisibility = visibility;
  1373. CD3DX12_ROOT_DESCRIPTOR_TABLE1::Init(
  1374. rootParam.DescriptorTable, numDescriptorRanges, pDescriptorRanges);
  1375. }
  1376. inline static void InitAsConstants(_Out_ D3D12_ROOT_PARAMETER1& rootParam,
  1377. UINT num32BitValues,
  1378. UINT shaderRegister,
  1379. UINT registerSpace = 0,
  1380. D3D12_SHADER_VISIBILITY visibility
  1381. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  1382. {
  1383. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
  1384. rootParam.ShaderVisibility = visibility;
  1385. CD3DX12_ROOT_CONSTANTS::Init(
  1386. rootParam.Constants, num32BitValues, shaderRegister, registerSpace);
  1387. }
  1388. inline static void InitAsConstantBufferView(
  1389. _Out_ D3D12_ROOT_PARAMETER1& rootParam,
  1390. UINT shaderRegister,
  1391. UINT registerSpace = 0,
  1392. D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
  1393. D3D12_SHADER_VISIBILITY visibility
  1394. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  1395. {
  1396. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
  1397. rootParam.ShaderVisibility = visibility;
  1398. CD3DX12_ROOT_DESCRIPTOR1::Init(
  1399. rootParam.Descriptor, shaderRegister, registerSpace, flags);
  1400. }
  1401. inline static void InitAsShaderResourceView(
  1402. _Out_ D3D12_ROOT_PARAMETER1& rootParam,
  1403. UINT shaderRegister,
  1404. UINT registerSpace = 0,
  1405. D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
  1406. D3D12_SHADER_VISIBILITY visibility
  1407. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  1408. {
  1409. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;
  1410. rootParam.ShaderVisibility = visibility;
  1411. CD3DX12_ROOT_DESCRIPTOR1::Init(
  1412. rootParam.Descriptor, shaderRegister, registerSpace, flags);
  1413. }
  1414. inline static void InitAsUnorderedAccessView(
  1415. _Out_ D3D12_ROOT_PARAMETER1& rootParam,
  1416. UINT shaderRegister,
  1417. UINT registerSpace = 0,
  1418. D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
  1419. D3D12_SHADER_VISIBILITY visibility
  1420. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  1421. {
  1422. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV;
  1423. rootParam.ShaderVisibility = visibility;
  1424. CD3DX12_ROOT_DESCRIPTOR1::Init(
  1425. rootParam.Descriptor, shaderRegister, registerSpace, flags);
  1426. }
  1427. inline void InitAsDescriptorTable(UINT numDescriptorRanges,
  1428. _In_reads_(numDescriptorRanges)
  1429. const D3D12_DESCRIPTOR_RANGE1* pDescriptorRanges,
  1430. D3D12_SHADER_VISIBILITY visibility
  1431. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  1432. {
  1433. InitAsDescriptorTable(
  1434. *this, numDescriptorRanges, pDescriptorRanges, visibility);
  1435. }
  1436. inline void InitAsConstants(UINT num32BitValues,
  1437. UINT shaderRegister,
  1438. UINT registerSpace = 0,
  1439. D3D12_SHADER_VISIBILITY visibility
  1440. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  1441. {
  1442. InitAsConstants(
  1443. *this, num32BitValues, shaderRegister, registerSpace, visibility);
  1444. }
  1445. inline void InitAsConstantBufferView(UINT shaderRegister,
  1446. UINT registerSpace = 0,
  1447. D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
  1448. D3D12_SHADER_VISIBILITY visibility
  1449. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  1450. {
  1451. InitAsConstantBufferView(
  1452. *this, shaderRegister, registerSpace, flags, visibility);
  1453. }
  1454. inline void InitAsShaderResourceView(UINT shaderRegister,
  1455. UINT registerSpace = 0,
  1456. D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
  1457. D3D12_SHADER_VISIBILITY visibility
  1458. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  1459. {
  1460. InitAsShaderResourceView(
  1461. *this, shaderRegister, registerSpace, flags, visibility);
  1462. }
  1463. inline void InitAsUnorderedAccessView(UINT shaderRegister,
  1464. UINT registerSpace = 0,
  1465. D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
  1466. D3D12_SHADER_VISIBILITY visibility
  1467. = D3D12_SHADER_VISIBILITY_ALL) noexcept
  1468. {
  1469. InitAsUnorderedAccessView(
  1470. *this, shaderRegister, registerSpace, flags, visibility);
  1471. }
  1472. };
  1473. //------------------------------------------------------------------------------------------------
  1474. struct CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC
  1475. : public D3D12_VERSIONED_ROOT_SIGNATURE_DESC
  1476. {
  1477. CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC() = default;
  1478. explicit CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(
  1479. const D3D12_VERSIONED_ROOT_SIGNATURE_DESC& o) noexcept
  1480. : D3D12_VERSIONED_ROOT_SIGNATURE_DESC(o)
  1481. {}
  1482. explicit CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(
  1483. const D3D12_ROOT_SIGNATURE_DESC& o) noexcept
  1484. {
  1485. Version = D3D_ROOT_SIGNATURE_VERSION_1_0;
  1486. Desc_1_0 = o;
  1487. }
  1488. explicit CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(
  1489. const D3D12_ROOT_SIGNATURE_DESC1& o) noexcept
  1490. {
  1491. Version = D3D_ROOT_SIGNATURE_VERSION_1_1;
  1492. Desc_1_1 = o;
  1493. }
  1494. CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(UINT numParameters,
  1495. _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
  1496. UINT numStaticSamplers = 0,
  1497. _In_reads_opt_(numStaticSamplers)
  1498. const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers
  1499. = nullptr,
  1500. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE)
  1501. noexcept
  1502. {
  1503. Init_1_0(numParameters,
  1504. _pParameters,
  1505. numStaticSamplers,
  1506. _pStaticSamplers,
  1507. flags);
  1508. }
  1509. CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(UINT numParameters,
  1510. _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER1* _pParameters,
  1511. UINT numStaticSamplers = 0,
  1512. _In_reads_opt_(numStaticSamplers)
  1513. const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers
  1514. = nullptr,
  1515. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE)
  1516. noexcept
  1517. {
  1518. Init_1_1(numParameters,
  1519. _pParameters,
  1520. numStaticSamplers,
  1521. _pStaticSamplers,
  1522. flags);
  1523. }
  1524. CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(CD3DX12_DEFAULT) noexcept
  1525. {
  1526. Init_1_1(0, nullptr, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  1527. }
  1528. inline void Init_1_0(UINT numParameters,
  1529. _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
  1530. UINT numStaticSamplers = 0,
  1531. _In_reads_opt_(numStaticSamplers)
  1532. const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers
  1533. = nullptr,
  1534. D3D12_ROOT_SIGNATURE_FLAGS flags
  1535. = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
  1536. {
  1537. Init_1_0(*this,
  1538. numParameters,
  1539. _pParameters,
  1540. numStaticSamplers,
  1541. _pStaticSamplers,
  1542. flags);
  1543. }
  1544. inline static void Init_1_0(_Out_ D3D12_VERSIONED_ROOT_SIGNATURE_DESC& desc,
  1545. UINT numParameters,
  1546. _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
  1547. UINT numStaticSamplers = 0,
  1548. _In_reads_opt_(numStaticSamplers)
  1549. const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers
  1550. = nullptr,
  1551. D3D12_ROOT_SIGNATURE_FLAGS flags
  1552. = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
  1553. {
  1554. desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_0;
  1555. desc.Desc_1_0.NumParameters = numParameters;
  1556. desc.Desc_1_0.pParameters = _pParameters;
  1557. desc.Desc_1_0.NumStaticSamplers = numStaticSamplers;
  1558. desc.Desc_1_0.pStaticSamplers = _pStaticSamplers;
  1559. desc.Desc_1_0.Flags = flags;
  1560. }
  1561. inline void Init_1_1(UINT numParameters,
  1562. _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER1* _pParameters,
  1563. UINT numStaticSamplers = 0,
  1564. _In_reads_opt_(numStaticSamplers)
  1565. const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers
  1566. = nullptr,
  1567. D3D12_ROOT_SIGNATURE_FLAGS flags
  1568. = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
  1569. {
  1570. Init_1_1(*this,
  1571. numParameters,
  1572. _pParameters,
  1573. numStaticSamplers,
  1574. _pStaticSamplers,
  1575. flags);
  1576. }
  1577. inline static void Init_1_1(_Out_ D3D12_VERSIONED_ROOT_SIGNATURE_DESC& desc,
  1578. UINT numParameters,
  1579. _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER1* _pParameters,
  1580. UINT numStaticSamplers = 0,
  1581. _In_reads_opt_(numStaticSamplers)
  1582. const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers
  1583. = nullptr,
  1584. D3D12_ROOT_SIGNATURE_FLAGS flags
  1585. = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
  1586. {
  1587. desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_1;
  1588. desc.Desc_1_1.NumParameters = numParameters;
  1589. desc.Desc_1_1.pParameters = _pParameters;
  1590. desc.Desc_1_1.NumStaticSamplers = numStaticSamplers;
  1591. desc.Desc_1_1.pStaticSamplers = _pStaticSamplers;
  1592. desc.Desc_1_1.Flags = flags;
  1593. }
  1594. };
  1595. //------------------------------------------------------------------------------------------------
  1596. struct CD3DX12_CPU_DESCRIPTOR_HANDLE : public D3D12_CPU_DESCRIPTOR_HANDLE
  1597. {
  1598. CD3DX12_CPU_DESCRIPTOR_HANDLE() = default;
  1599. explicit CD3DX12_CPU_DESCRIPTOR_HANDLE(
  1600. const D3D12_CPU_DESCRIPTOR_HANDLE& o) noexcept
  1601. : D3D12_CPU_DESCRIPTOR_HANDLE(o)
  1602. {}
  1603. CD3DX12_CPU_DESCRIPTOR_HANDLE(CD3DX12_DEFAULT) noexcept
  1604. {
  1605. ptr = 0;
  1606. }
  1607. CD3DX12_CPU_DESCRIPTOR_HANDLE(const _In_ D3D12_CPU_DESCRIPTOR_HANDLE& other,
  1608. INT offsetScaledByIncrementSize)
  1609. noexcept
  1610. {
  1611. InitOffsetted(other, offsetScaledByIncrementSize);
  1612. }
  1613. CD3DX12_CPU_DESCRIPTOR_HANDLE(const _In_ D3D12_CPU_DESCRIPTOR_HANDLE& other,
  1614. INT offsetInDescriptors,
  1615. UINT descriptorIncrementSize)
  1616. noexcept
  1617. {
  1618. InitOffsetted(other, offsetInDescriptors, descriptorIncrementSize);
  1619. }
  1620. CD3DX12_CPU_DESCRIPTOR_HANDLE& Offset(
  1621. INT offsetInDescriptors, UINT descriptorIncrementSize) noexcept
  1622. {
  1623. ptr = SIZE_T(
  1624. INT64(ptr)
  1625. + INT64(offsetInDescriptors) * INT64(descriptorIncrementSize));
  1626. return *this;
  1627. }
  1628. CD3DX12_CPU_DESCRIPTOR_HANDLE& Offset(
  1629. INT offsetScaledByIncrementSize) noexcept
  1630. {
  1631. ptr = SIZE_T(INT64(ptr) + INT64(offsetScaledByIncrementSize));
  1632. return *this;
  1633. }
  1634. bool operator==(
  1635. const _In_ D3D12_CPU_DESCRIPTOR_HANDLE& other) const noexcept
  1636. {
  1637. return (ptr == other.ptr);
  1638. }
  1639. bool operator!=(
  1640. const _In_ D3D12_CPU_DESCRIPTOR_HANDLE& other) const noexcept
  1641. {
  1642. return (ptr != other.ptr);
  1643. }
  1644. CD3DX12_CPU_DESCRIPTOR_HANDLE& operator=(
  1645. const D3D12_CPU_DESCRIPTOR_HANDLE& other) noexcept
  1646. {
  1647. ptr = other.ptr;
  1648. return *this;
  1649. }
  1650. inline void InitOffsetted(const _In_ D3D12_CPU_DESCRIPTOR_HANDLE& base,
  1651. INT offsetScaledByIncrementSize) noexcept
  1652. {
  1653. InitOffsetted(*this, base, offsetScaledByIncrementSize);
  1654. }
  1655. inline void InitOffsetted(const _In_ D3D12_CPU_DESCRIPTOR_HANDLE& base,
  1656. INT offsetInDescriptors,
  1657. UINT descriptorIncrementSize) noexcept
  1658. {
  1659. InitOffsetted(
  1660. *this, base, offsetInDescriptors, descriptorIncrementSize);
  1661. }
  1662. inline static void InitOffsetted(_Out_ D3D12_CPU_DESCRIPTOR_HANDLE& handle,
  1663. const _In_ D3D12_CPU_DESCRIPTOR_HANDLE& base,
  1664. INT offsetScaledByIncrementSize) noexcept
  1665. {
  1666. handle.ptr
  1667. = SIZE_T(INT64(base.ptr) + INT64(offsetScaledByIncrementSize));
  1668. }
  1669. inline static void InitOffsetted(_Out_ D3D12_CPU_DESCRIPTOR_HANDLE& handle,
  1670. const _In_ D3D12_CPU_DESCRIPTOR_HANDLE& base,
  1671. INT offsetInDescriptors,
  1672. UINT descriptorIncrementSize) noexcept
  1673. {
  1674. handle.ptr = SIZE_T(
  1675. INT64(base.ptr)
  1676. + INT64(offsetInDescriptors) * INT64(descriptorIncrementSize));
  1677. }
  1678. };
  1679. //------------------------------------------------------------------------------------------------
  1680. struct CD3DX12_GPU_DESCRIPTOR_HANDLE : public D3D12_GPU_DESCRIPTOR_HANDLE
  1681. {
  1682. CD3DX12_GPU_DESCRIPTOR_HANDLE() = default;
  1683. explicit CD3DX12_GPU_DESCRIPTOR_HANDLE(
  1684. const D3D12_GPU_DESCRIPTOR_HANDLE& o) noexcept
  1685. : D3D12_GPU_DESCRIPTOR_HANDLE(o)
  1686. {}
  1687. CD3DX12_GPU_DESCRIPTOR_HANDLE(CD3DX12_DEFAULT) noexcept
  1688. {
  1689. ptr = 0;
  1690. }
  1691. CD3DX12_GPU_DESCRIPTOR_HANDLE(const _In_ D3D12_GPU_DESCRIPTOR_HANDLE& other,
  1692. INT offsetScaledByIncrementSize)
  1693. noexcept
  1694. {
  1695. InitOffsetted(other, offsetScaledByIncrementSize);
  1696. }
  1697. CD3DX12_GPU_DESCRIPTOR_HANDLE(const _In_ D3D12_GPU_DESCRIPTOR_HANDLE& other,
  1698. INT offsetInDescriptors,
  1699. UINT descriptorIncrementSize)
  1700. noexcept
  1701. {
  1702. InitOffsetted(other, offsetInDescriptors, descriptorIncrementSize);
  1703. }
  1704. CD3DX12_GPU_DESCRIPTOR_HANDLE& Offset(
  1705. INT offsetInDescriptors, UINT descriptorIncrementSize) noexcept
  1706. {
  1707. ptr = UINT64(
  1708. INT64(ptr)
  1709. + INT64(offsetInDescriptors) * INT64(descriptorIncrementSize));
  1710. return *this;
  1711. }
  1712. CD3DX12_GPU_DESCRIPTOR_HANDLE& Offset(
  1713. INT offsetScaledByIncrementSize) noexcept
  1714. {
  1715. ptr = UINT64(INT64(ptr) + INT64(offsetScaledByIncrementSize));
  1716. return *this;
  1717. }
  1718. inline bool operator==(
  1719. const _In_ D3D12_GPU_DESCRIPTOR_HANDLE& other) const noexcept
  1720. {
  1721. return (ptr == other.ptr);
  1722. }
  1723. inline bool operator!=(
  1724. const _In_ D3D12_GPU_DESCRIPTOR_HANDLE& other) const noexcept
  1725. {
  1726. return (ptr != other.ptr);
  1727. }
  1728. CD3DX12_GPU_DESCRIPTOR_HANDLE& operator=(
  1729. const D3D12_GPU_DESCRIPTOR_HANDLE& other) noexcept
  1730. {
  1731. ptr = other.ptr;
  1732. return *this;
  1733. }
  1734. inline void InitOffsetted(const _In_ D3D12_GPU_DESCRIPTOR_HANDLE& base,
  1735. INT offsetScaledByIncrementSize) noexcept
  1736. {
  1737. InitOffsetted(*this, base, offsetScaledByIncrementSize);
  1738. }
  1739. inline void InitOffsetted(const _In_ D3D12_GPU_DESCRIPTOR_HANDLE& base,
  1740. INT offsetInDescriptors,
  1741. UINT descriptorIncrementSize) noexcept
  1742. {
  1743. InitOffsetted(
  1744. *this, base, offsetInDescriptors, descriptorIncrementSize);
  1745. }
  1746. inline static void InitOffsetted(_Out_ D3D12_GPU_DESCRIPTOR_HANDLE& handle,
  1747. const _In_ D3D12_GPU_DESCRIPTOR_HANDLE& base,
  1748. INT offsetScaledByIncrementSize) noexcept
  1749. {
  1750. handle.ptr
  1751. = UINT64(INT64(base.ptr) + INT64(offsetScaledByIncrementSize));
  1752. }
  1753. inline static void InitOffsetted(_Out_ D3D12_GPU_DESCRIPTOR_HANDLE& handle,
  1754. const _In_ D3D12_GPU_DESCRIPTOR_HANDLE& base,
  1755. INT offsetInDescriptors,
  1756. UINT descriptorIncrementSize) noexcept
  1757. {
  1758. handle.ptr = UINT64(
  1759. INT64(base.ptr)
  1760. + INT64(offsetInDescriptors) * INT64(descriptorIncrementSize));
  1761. }
  1762. };
  1763. //------------------------------------------------------------------------------------------------
  1764. inline constexpr UINT D3D12CalcSubresource(UINT MipSlice,
  1765. UINT ArraySlice,
  1766. UINT PlaneSlice,
  1767. UINT MipLevels,
  1768. UINT ArraySize) noexcept
  1769. {
  1770. return MipSlice + ArraySlice * MipLevels
  1771. + PlaneSlice * MipLevels * ArraySize;
  1772. }
  1773. //------------------------------------------------------------------------------------------------
  1774. template<typename T, typename U, typename V>
  1775. inline void D3D12DecomposeSubresource(UINT Subresource,
  1776. UINT MipLevels,
  1777. UINT ArraySize,
  1778. _Out_ T& MipSlice,
  1779. _Out_ U& ArraySlice,
  1780. _Out_ V& PlaneSlice) noexcept
  1781. {
  1782. MipSlice = static_cast<T>(Subresource % MipLevels);
  1783. ArraySlice = static_cast<U>((Subresource / MipLevels) % ArraySize);
  1784. PlaneSlice = static_cast<V>(Subresource / (MipLevels * ArraySize));
  1785. }
  1786. //------------------------------------------------------------------------------------------------
  1787. inline UINT8 D3D12GetFormatPlaneCount(
  1788. _In_ ID3D12Device* pDevice, DXGI_FORMAT Format) noexcept
  1789. {
  1790. D3D12_FEATURE_DATA_FORMAT_INFO formatInfo = {Format, 0};
  1791. if (FAILED(pDevice->CheckFeatureSupport(
  1792. D3D12_FEATURE_FORMAT_INFO, &formatInfo, sizeof(formatInfo))))
  1793. {
  1794. return 0;
  1795. }
  1796. return formatInfo.PlaneCount;
  1797. }
  1798. //------------------------------------------------------------------------------------------------
  1799. struct CD3DX12_RESOURCE_DESC : public D3D12_RESOURCE_DESC
  1800. {
  1801. CD3DX12_RESOURCE_DESC() = default;
  1802. explicit CD3DX12_RESOURCE_DESC(const D3D12_RESOURCE_DESC& o) noexcept
  1803. : D3D12_RESOURCE_DESC(o)
  1804. {}
  1805. CD3DX12_RESOURCE_DESC(D3D12_RESOURCE_DIMENSION dimension,
  1806. UINT64 alignment,
  1807. UINT64 width,
  1808. UINT height,
  1809. UINT16 depthOrArraySize,
  1810. UINT16 mipLevels,
  1811. DXGI_FORMAT format,
  1812. UINT sampleCount,
  1813. UINT sampleQuality,
  1814. D3D12_TEXTURE_LAYOUT layout,
  1815. D3D12_RESOURCE_FLAGS flags)
  1816. noexcept
  1817. {
  1818. Dimension = dimension;
  1819. Alignment = alignment;
  1820. Width = width;
  1821. Height = height;
  1822. DepthOrArraySize = depthOrArraySize;
  1823. MipLevels = mipLevels;
  1824. Format = format;
  1825. SampleDesc.Count = sampleCount;
  1826. SampleDesc.Quality = sampleQuality;
  1827. Layout = layout;
  1828. Flags = flags;
  1829. }
  1830. inline static CD3DX12_RESOURCE_DESC Buffer(
  1831. const D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,
  1832. D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE) noexcept
  1833. {
  1834. return CD3DX12_RESOURCE_DESC(D3D12_RESOURCE_DIMENSION_BUFFER,
  1835. resAllocInfo.Alignment,
  1836. resAllocInfo.SizeInBytes,
  1837. 1,
  1838. 1,
  1839. 1,
  1840. DXGI_FORMAT_UNKNOWN,
  1841. 1,
  1842. 0,
  1843. D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
  1844. flags);
  1845. }
  1846. inline static CD3DX12_RESOURCE_DESC Buffer(UINT64 width,
  1847. D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
  1848. UINT64 alignment = 0) noexcept
  1849. {
  1850. return CD3DX12_RESOURCE_DESC(D3D12_RESOURCE_DIMENSION_BUFFER,
  1851. alignment,
  1852. width,
  1853. 1,
  1854. 1,
  1855. 1,
  1856. DXGI_FORMAT_UNKNOWN,
  1857. 1,
  1858. 0,
  1859. D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
  1860. flags);
  1861. }
  1862. inline static CD3DX12_RESOURCE_DESC Tex1D(DXGI_FORMAT format,
  1863. UINT64 width,
  1864. UINT16 arraySize = 1,
  1865. UINT16 mipLevels = 0,
  1866. D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
  1867. D3D12_TEXTURE_LAYOUT layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,
  1868. UINT64 alignment = 0) noexcept
  1869. {
  1870. return CD3DX12_RESOURCE_DESC(D3D12_RESOURCE_DIMENSION_TEXTURE1D,
  1871. alignment,
  1872. width,
  1873. 1,
  1874. arraySize,
  1875. mipLevels,
  1876. format,
  1877. 1,
  1878. 0,
  1879. layout,
  1880. flags);
  1881. }
  1882. inline static CD3DX12_RESOURCE_DESC Tex2D(DXGI_FORMAT format,
  1883. UINT64 width,
  1884. UINT height,
  1885. UINT16 arraySize = 1,
  1886. UINT16 mipLevels = 0,
  1887. UINT sampleCount = 1,
  1888. UINT sampleQuality = 0,
  1889. D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
  1890. D3D12_TEXTURE_LAYOUT layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,
  1891. UINT64 alignment = 0) noexcept
  1892. {
  1893. return CD3DX12_RESOURCE_DESC(D3D12_RESOURCE_DIMENSION_TEXTURE2D,
  1894. alignment,
  1895. width,
  1896. height,
  1897. arraySize,
  1898. mipLevels,
  1899. format,
  1900. sampleCount,
  1901. sampleQuality,
  1902. layout,
  1903. flags);
  1904. }
  1905. inline static CD3DX12_RESOURCE_DESC Tex3D(DXGI_FORMAT format,
  1906. UINT64 width,
  1907. UINT height,
  1908. UINT16 depth,
  1909. UINT16 mipLevels = 0,
  1910. D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
  1911. D3D12_TEXTURE_LAYOUT layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,
  1912. UINT64 alignment = 0) noexcept
  1913. {
  1914. return CD3DX12_RESOURCE_DESC(D3D12_RESOURCE_DIMENSION_TEXTURE3D,
  1915. alignment,
  1916. width,
  1917. height,
  1918. depth,
  1919. mipLevels,
  1920. format,
  1921. 1,
  1922. 0,
  1923. layout,
  1924. flags);
  1925. }
  1926. inline UINT16 Depth() const noexcept
  1927. {
  1928. return (Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D
  1929. ? DepthOrArraySize
  1930. : 1);
  1931. }
  1932. inline UINT16 ArraySize() const noexcept
  1933. {
  1934. return (Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE3D
  1935. ? DepthOrArraySize
  1936. : 1);
  1937. }
  1938. inline UINT8 PlaneCount(_In_ ID3D12Device* pDevice) const noexcept
  1939. {
  1940. return D3D12GetFormatPlaneCount(pDevice, Format);
  1941. }
  1942. inline UINT Subresources(_In_ ID3D12Device* pDevice) const noexcept
  1943. {
  1944. return MipLevels * ArraySize() * PlaneCount(pDevice);
  1945. }
  1946. inline UINT CalcSubresource(
  1947. UINT MipSlice, UINT ArraySlice, UINT PlaneSlice) noexcept
  1948. {
  1949. return D3D12CalcSubresource(
  1950. MipSlice, ArraySlice, PlaneSlice, MipLevels, ArraySize());
  1951. }
  1952. };
  1953. inline bool operator==(
  1954. const D3D12_RESOURCE_DESC& l, const D3D12_RESOURCE_DESC& r) noexcept
  1955. {
  1956. return l.Dimension == r.Dimension && l.Alignment == r.Alignment
  1957. && l.Width == r.Width && l.Height == r.Height
  1958. && l.DepthOrArraySize == r.DepthOrArraySize
  1959. && l.MipLevels == r.MipLevels && l.Format == r.Format
  1960. && l.SampleDesc.Count == r.SampleDesc.Count
  1961. && l.SampleDesc.Quality == r.SampleDesc.Quality && l.Layout == r.Layout
  1962. && l.Flags == r.Flags;
  1963. }
  1964. inline bool operator!=(
  1965. const D3D12_RESOURCE_DESC& l, const D3D12_RESOURCE_DESC& r) noexcept
  1966. {
  1967. return !(l == r);
  1968. }
  1969. //------------------------------------------------------------------------------------------------
  1970. struct CD3DX12_RESOURCE_DESC1 : public D3D12_RESOURCE_DESC1
  1971. {
  1972. CD3DX12_RESOURCE_DESC1() = default;
  1973. explicit CD3DX12_RESOURCE_DESC1(const D3D12_RESOURCE_DESC1& o) noexcept
  1974. : D3D12_RESOURCE_DESC1(o)
  1975. {}
  1976. CD3DX12_RESOURCE_DESC1(D3D12_RESOURCE_DIMENSION dimension,
  1977. UINT64 alignment,
  1978. UINT64 width,
  1979. UINT height,
  1980. UINT16 depthOrArraySize,
  1981. UINT16 mipLevels,
  1982. DXGI_FORMAT format,
  1983. UINT sampleCount,
  1984. UINT sampleQuality,
  1985. D3D12_TEXTURE_LAYOUT layout,
  1986. D3D12_RESOURCE_FLAGS flags,
  1987. UINT samplerFeedbackMipRegionWidth = 0,
  1988. UINT samplerFeedbackMipRegionHeight = 0,
  1989. UINT samplerFeedbackMipRegionDepth = 0)
  1990. noexcept
  1991. {
  1992. Dimension = dimension;
  1993. Alignment = alignment;
  1994. Width = width;
  1995. Height = height;
  1996. DepthOrArraySize = depthOrArraySize;
  1997. MipLevels = mipLevels;
  1998. Format = format;
  1999. SampleDesc.Count = sampleCount;
  2000. SampleDesc.Quality = sampleQuality;
  2001. Layout = layout;
  2002. Flags = flags;
  2003. SamplerFeedbackMipRegion.Width = samplerFeedbackMipRegionWidth;
  2004. SamplerFeedbackMipRegion.Height = samplerFeedbackMipRegionHeight;
  2005. SamplerFeedbackMipRegion.Depth = samplerFeedbackMipRegionDepth;
  2006. }
  2007. inline static CD3DX12_RESOURCE_DESC1 Buffer(
  2008. const D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,
  2009. D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE) noexcept
  2010. {
  2011. return CD3DX12_RESOURCE_DESC1(D3D12_RESOURCE_DIMENSION_BUFFER,
  2012. resAllocInfo.Alignment,
  2013. resAllocInfo.SizeInBytes,
  2014. 1,
  2015. 1,
  2016. 1,
  2017. DXGI_FORMAT_UNKNOWN,
  2018. 1,
  2019. 0,
  2020. D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
  2021. flags,
  2022. 0,
  2023. 0,
  2024. 0);
  2025. }
  2026. inline static CD3DX12_RESOURCE_DESC1 Buffer(UINT64 width,
  2027. D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
  2028. UINT64 alignment = 0) noexcept
  2029. {
  2030. return CD3DX12_RESOURCE_DESC1(D3D12_RESOURCE_DIMENSION_BUFFER,
  2031. alignment,
  2032. width,
  2033. 1,
  2034. 1,
  2035. 1,
  2036. DXGI_FORMAT_UNKNOWN,
  2037. 1,
  2038. 0,
  2039. D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
  2040. flags,
  2041. 0,
  2042. 0,
  2043. 0);
  2044. }
  2045. inline static CD3DX12_RESOURCE_DESC1 Tex1D(DXGI_FORMAT format,
  2046. UINT64 width,
  2047. UINT16 arraySize = 1,
  2048. UINT16 mipLevels = 0,
  2049. D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
  2050. D3D12_TEXTURE_LAYOUT layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,
  2051. UINT64 alignment = 0) noexcept
  2052. {
  2053. return CD3DX12_RESOURCE_DESC1(D3D12_RESOURCE_DIMENSION_TEXTURE1D,
  2054. alignment,
  2055. width,
  2056. 1,
  2057. arraySize,
  2058. mipLevels,
  2059. format,
  2060. 1,
  2061. 0,
  2062. layout,
  2063. flags,
  2064. 0,
  2065. 0,
  2066. 0);
  2067. }
  2068. inline static CD3DX12_RESOURCE_DESC1 Tex2D(DXGI_FORMAT format,
  2069. UINT64 width,
  2070. UINT height,
  2071. UINT16 arraySize = 1,
  2072. UINT16 mipLevels = 0,
  2073. UINT sampleCount = 1,
  2074. UINT sampleQuality = 0,
  2075. D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
  2076. D3D12_TEXTURE_LAYOUT layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,
  2077. UINT64 alignment = 0,
  2078. UINT samplerFeedbackMipRegionWidth = 0,
  2079. UINT samplerFeedbackMipRegionHeight = 0,
  2080. UINT samplerFeedbackMipRegionDepth = 0) noexcept
  2081. {
  2082. return CD3DX12_RESOURCE_DESC1(D3D12_RESOURCE_DIMENSION_TEXTURE2D,
  2083. alignment,
  2084. width,
  2085. height,
  2086. arraySize,
  2087. mipLevels,
  2088. format,
  2089. sampleCount,
  2090. sampleQuality,
  2091. layout,
  2092. flags,
  2093. samplerFeedbackMipRegionWidth,
  2094. samplerFeedbackMipRegionHeight,
  2095. samplerFeedbackMipRegionDepth);
  2096. }
  2097. inline static CD3DX12_RESOURCE_DESC1 Tex3D(DXGI_FORMAT format,
  2098. UINT64 width,
  2099. UINT height,
  2100. UINT16 depth,
  2101. UINT16 mipLevels = 0,
  2102. D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
  2103. D3D12_TEXTURE_LAYOUT layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,
  2104. UINT64 alignment = 0) noexcept
  2105. {
  2106. return CD3DX12_RESOURCE_DESC1(D3D12_RESOURCE_DIMENSION_TEXTURE3D,
  2107. alignment,
  2108. width,
  2109. height,
  2110. depth,
  2111. mipLevels,
  2112. format,
  2113. 1,
  2114. 0,
  2115. layout,
  2116. flags,
  2117. 0,
  2118. 0,
  2119. 0);
  2120. }
  2121. inline UINT16 Depth() const noexcept
  2122. {
  2123. return (Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D
  2124. ? DepthOrArraySize
  2125. : 1);
  2126. }
  2127. inline UINT16 ArraySize() const noexcept
  2128. {
  2129. return (Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE3D
  2130. ? DepthOrArraySize
  2131. : 1);
  2132. }
  2133. inline UINT8 PlaneCount(_In_ ID3D12Device* pDevice) const noexcept
  2134. {
  2135. return D3D12GetFormatPlaneCount(pDevice, Format);
  2136. }
  2137. inline UINT Subresources(_In_ ID3D12Device* pDevice) const noexcept
  2138. {
  2139. return MipLevels * ArraySize() * PlaneCount(pDevice);
  2140. }
  2141. inline UINT CalcSubresource(
  2142. UINT MipSlice, UINT ArraySlice, UINT PlaneSlice) noexcept
  2143. {
  2144. return D3D12CalcSubresource(
  2145. MipSlice, ArraySlice, PlaneSlice, MipLevels, ArraySize());
  2146. }
  2147. };
  2148. inline bool operator==(
  2149. const D3D12_RESOURCE_DESC1& l, const D3D12_RESOURCE_DESC1& r) noexcept
  2150. {
  2151. return l.Dimension == r.Dimension && l.Alignment == r.Alignment
  2152. && l.Width == r.Width && l.Height == r.Height
  2153. && l.DepthOrArraySize == r.DepthOrArraySize
  2154. && l.MipLevels == r.MipLevels && l.Format == r.Format
  2155. && l.SampleDesc.Count == r.SampleDesc.Count
  2156. && l.SampleDesc.Quality == r.SampleDesc.Quality && l.Layout == r.Layout
  2157. && l.Flags == r.Flags
  2158. && l.SamplerFeedbackMipRegion.Width == r.SamplerFeedbackMipRegion.Width
  2159. && l.SamplerFeedbackMipRegion.Height
  2160. == r.SamplerFeedbackMipRegion.Height
  2161. && l.SamplerFeedbackMipRegion.Depth == r.SamplerFeedbackMipRegion.Depth;
  2162. }
  2163. inline bool operator!=(
  2164. const D3D12_RESOURCE_DESC1& l, const D3D12_RESOURCE_DESC1& r) noexcept
  2165. {
  2166. return !(l == r);
  2167. }
  2168. //------------------------------------------------------------------------------------------------
  2169. struct CD3DX12_VIEW_INSTANCING_DESC : public D3D12_VIEW_INSTANCING_DESC
  2170. {
  2171. CD3DX12_VIEW_INSTANCING_DESC() = default;
  2172. explicit CD3DX12_VIEW_INSTANCING_DESC(
  2173. const D3D12_VIEW_INSTANCING_DESC& o) noexcept
  2174. : D3D12_VIEW_INSTANCING_DESC(o)
  2175. {}
  2176. explicit CD3DX12_VIEW_INSTANCING_DESC(CD3DX12_DEFAULT) noexcept
  2177. {
  2178. ViewInstanceCount = 0;
  2179. pViewInstanceLocations = nullptr;
  2180. Flags = D3D12_VIEW_INSTANCING_FLAG_NONE;
  2181. }
  2182. explicit CD3DX12_VIEW_INSTANCING_DESC(UINT InViewInstanceCount,
  2183. const D3D12_VIEW_INSTANCE_LOCATION* InViewInstanceLocations,
  2184. D3D12_VIEW_INSTANCING_FLAGS InFlags) noexcept
  2185. {
  2186. ViewInstanceCount = InViewInstanceCount;
  2187. pViewInstanceLocations = InViewInstanceLocations;
  2188. Flags = InFlags;
  2189. }
  2190. };
  2191. //------------------------------------------------------------------------------------------------
  2192. // Row-by-row memcpy
  2193. inline void MemcpySubresource(const _In_ D3D12_MEMCPY_DEST* pDest,
  2194. const _In_ D3D12_SUBRESOURCE_DATA* pSrc,
  2195. SIZE_T RowSizeInBytes,
  2196. UINT NumRows,
  2197. UINT NumSlices) noexcept
  2198. {
  2199. for (UINT z = 0; z < NumSlices; ++z)
  2200. {
  2201. auto pDestSlice
  2202. = static_cast<BYTE*>(pDest->pData) + pDest->SlicePitch * z;
  2203. auto pSrcSlice = static_cast<const BYTE*>(pSrc->pData)
  2204. + pSrc->SlicePitch * LONG_PTR(z);
  2205. for (UINT y = 0; y < NumRows; ++y)
  2206. {
  2207. memcpy(pDestSlice + pDest->RowPitch * y,
  2208. pSrcSlice + pSrc->RowPitch * LONG_PTR(y),
  2209. RowSizeInBytes);
  2210. }
  2211. }
  2212. }
  2213. //------------------------------------------------------------------------------------------------
  2214. // Row-by-row memcpy
  2215. inline void MemcpySubresource(const _In_ D3D12_MEMCPY_DEST* pDest,
  2216. _In_ const void* pResourceData,
  2217. const _In_ D3D12_SUBRESOURCE_INFO* pSrc,
  2218. SIZE_T RowSizeInBytes,
  2219. UINT NumRows,
  2220. UINT NumSlices) noexcept
  2221. {
  2222. for (UINT z = 0; z < NumSlices; ++z)
  2223. {
  2224. auto pDestSlice
  2225. = static_cast<BYTE*>(pDest->pData) + pDest->SlicePitch * z;
  2226. auto pSrcSlice
  2227. = (static_cast<const BYTE*>(pResourceData) + pSrc->Offset)
  2228. + pSrc->DepthPitch * ULONG_PTR(z);
  2229. for (UINT y = 0; y < NumRows; ++y)
  2230. {
  2231. memcpy(pDestSlice + pDest->RowPitch * y,
  2232. pSrcSlice + pSrc->RowPitch * ULONG_PTR(y),
  2233. RowSizeInBytes);
  2234. }
  2235. }
  2236. }
  2237. //------------------------------------------------------------------------------------------------
  2238. // Returns required size of a buffer to be used for data upload
  2239. inline UINT64 GetRequiredIntermediateSize(
  2240. _In_ ID3D12Resource* pDestinationResource,
  2241. _In_range_(0, D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
  2242. _In_range_(0, D3D12_REQ_SUBRESOURCES - FirstSubresource)
  2243. UINT NumSubresources) noexcept
  2244. {
  2245. auto Desc = pDestinationResource->GetDesc();
  2246. UINT64 RequiredSize = 0;
  2247. ID3D12Device* pDevice = nullptr;
  2248. pDestinationResource->GetDevice(
  2249. __uuidof(*pDevice), reinterpret_cast<void**>(&pDevice));
  2250. pDevice->GetCopyableFootprints(&Desc,
  2251. FirstSubresource,
  2252. NumSubresources,
  2253. 0,
  2254. nullptr,
  2255. nullptr,
  2256. nullptr,
  2257. &RequiredSize);
  2258. pDevice->Release();
  2259. return RequiredSize;
  2260. }
  2261. //------------------------------------------------------------------------------------------------
  2262. // All arrays must be populated (e.g. by calling GetCopyableFootprints)
  2263. inline UINT64 UpdateSubresources(_In_ ID3D12GraphicsCommandList* pCmdList,
  2264. _In_ ID3D12Resource* pDestinationResource,
  2265. _In_ ID3D12Resource* pIntermediate,
  2266. _In_range_(0, D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
  2267. _In_range_(0, D3D12_REQ_SUBRESOURCES - FirstSubresource)
  2268. UINT NumSubresources,
  2269. UINT64 RequiredSize,
  2270. _In_reads_(NumSubresources)
  2271. const D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts,
  2272. _In_reads_(NumSubresources) const UINT* pNumRows,
  2273. _In_reads_(NumSubresources) const UINT64* pRowSizesInBytes,
  2274. _In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData) noexcept
  2275. {
  2276. // Minor validation
  2277. auto IntermediateDesc = pIntermediate->GetDesc();
  2278. auto DestinationDesc = pDestinationResource->GetDesc();
  2279. if (IntermediateDesc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER
  2280. || IntermediateDesc.Width < RequiredSize + pLayouts[0].Offset
  2281. || RequiredSize > SIZE_T(-1)
  2282. || (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER
  2283. && (FirstSubresource != 0 || NumSubresources != 1)))
  2284. {
  2285. return 0;
  2286. }
  2287. BYTE* pData;
  2288. HRESULT hr
  2289. = pIntermediate->Map(0, nullptr, reinterpret_cast<void**>(&pData));
  2290. if (FAILED(hr))
  2291. {
  2292. return 0;
  2293. }
  2294. for (UINT i = 0; i < NumSubresources; ++i)
  2295. {
  2296. if (pRowSizesInBytes[i] > SIZE_T(-1)) return 0;
  2297. D3D12_MEMCPY_DEST DestData = {pData + pLayouts[i].Offset,
  2298. pLayouts[i].Footprint.RowPitch,
  2299. SIZE_T(pLayouts[i].Footprint.RowPitch) * SIZE_T(pNumRows[i])};
  2300. MemcpySubresource(&DestData,
  2301. &pSrcData[i],
  2302. static_cast<SIZE_T>(pRowSizesInBytes[i]),
  2303. pNumRows[i],
  2304. pLayouts[i].Footprint.Depth);
  2305. }
  2306. pIntermediate->Unmap(0, nullptr);
  2307. if (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
  2308. {
  2309. pCmdList->CopyBufferRegion(pDestinationResource,
  2310. 0,
  2311. pIntermediate,
  2312. pLayouts[0].Offset,
  2313. pLayouts[0].Footprint.Width);
  2314. }
  2315. else
  2316. {
  2317. for (UINT i = 0; i < NumSubresources; ++i)
  2318. {
  2319. CD3DX12_TEXTURE_COPY_LOCATION Dst(
  2320. pDestinationResource, i + FirstSubresource);
  2321. CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]);
  2322. pCmdList->CopyTextureRegion(&Dst, 0, 0, 0, &Src, nullptr);
  2323. }
  2324. }
  2325. return RequiredSize;
  2326. }
  2327. //------------------------------------------------------------------------------------------------
  2328. // All arrays must be populated (e.g. by calling GetCopyableFootprints)
  2329. inline UINT64 UpdateSubresources(_In_ ID3D12GraphicsCommandList* pCmdList,
  2330. _In_ ID3D12Resource* pDestinationResource,
  2331. _In_ ID3D12Resource* pIntermediate,
  2332. _In_range_(0, D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
  2333. _In_range_(0, D3D12_REQ_SUBRESOURCES - FirstSubresource)
  2334. UINT NumSubresources,
  2335. UINT64 RequiredSize,
  2336. _In_reads_(NumSubresources)
  2337. const D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts,
  2338. _In_reads_(NumSubresources) const UINT* pNumRows,
  2339. _In_reads_(NumSubresources) const UINT64* pRowSizesInBytes,
  2340. _In_ const void* pResourceData,
  2341. _In_reads_(NumSubresources) const D3D12_SUBRESOURCE_INFO* pSrcData) noexcept
  2342. {
  2343. // Minor validation
  2344. auto IntermediateDesc = pIntermediate->GetDesc();
  2345. auto DestinationDesc = pDestinationResource->GetDesc();
  2346. if (IntermediateDesc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER
  2347. || IntermediateDesc.Width < RequiredSize + pLayouts[0].Offset
  2348. || RequiredSize > SIZE_T(-1)
  2349. || (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER
  2350. && (FirstSubresource != 0 || NumSubresources != 1)))
  2351. {
  2352. return 0;
  2353. }
  2354. BYTE* pData;
  2355. HRESULT hr
  2356. = pIntermediate->Map(0, nullptr, reinterpret_cast<void**>(&pData));
  2357. if (FAILED(hr))
  2358. {
  2359. return 0;
  2360. }
  2361. for (UINT i = 0; i < NumSubresources; ++i)
  2362. {
  2363. if (pRowSizesInBytes[i] > SIZE_T(-1)) return 0;
  2364. D3D12_MEMCPY_DEST DestData = {pData + pLayouts[i].Offset,
  2365. pLayouts[i].Footprint.RowPitch,
  2366. SIZE_T(pLayouts[i].Footprint.RowPitch) * SIZE_T(pNumRows[i])};
  2367. MemcpySubresource(&DestData,
  2368. pResourceData,
  2369. &pSrcData[i],
  2370. static_cast<SIZE_T>(pRowSizesInBytes[i]),
  2371. pNumRows[i],
  2372. pLayouts[i].Footprint.Depth);
  2373. }
  2374. pIntermediate->Unmap(0, nullptr);
  2375. if (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
  2376. {
  2377. pCmdList->CopyBufferRegion(pDestinationResource,
  2378. 0,
  2379. pIntermediate,
  2380. pLayouts[0].Offset,
  2381. pLayouts[0].Footprint.Width);
  2382. }
  2383. else
  2384. {
  2385. for (UINT i = 0; i < NumSubresources; ++i)
  2386. {
  2387. CD3DX12_TEXTURE_COPY_LOCATION Dst(
  2388. pDestinationResource, i + FirstSubresource);
  2389. CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]);
  2390. pCmdList->CopyTextureRegion(&Dst, 0, 0, 0, &Src, nullptr);
  2391. }
  2392. }
  2393. return RequiredSize;
  2394. }
  2395. //------------------------------------------------------------------------------------------------
  2396. // Heap-allocating UpdateSubresources implementation
  2397. inline UINT64 UpdateSubresources(_In_ ID3D12GraphicsCommandList* pCmdList,
  2398. _In_ ID3D12Resource* pDestinationResource,
  2399. _In_ ID3D12Resource* pIntermediate,
  2400. UINT64 IntermediateOffset,
  2401. _In_range_(0, D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
  2402. _In_range_(0, D3D12_REQ_SUBRESOURCES - FirstSubresource)
  2403. UINT NumSubresources,
  2404. _In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData) noexcept
  2405. {
  2406. UINT64 RequiredSize = 0;
  2407. auto MemToAlloc
  2408. = static_cast<UINT64>(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT)
  2409. + sizeof(UINT) + sizeof(UINT64))
  2410. * NumSubresources;
  2411. if (MemToAlloc > SIZE_MAX)
  2412. {
  2413. return 0;
  2414. }
  2415. void* pMem
  2416. = HeapAlloc(GetProcessHeap(), 0, static_cast<SIZE_T>(MemToAlloc));
  2417. if (pMem == nullptr)
  2418. {
  2419. return 0;
  2420. }
  2421. auto pLayouts = static_cast<D3D12_PLACED_SUBRESOURCE_FOOTPRINT*>(pMem);
  2422. auto pRowSizesInBytes
  2423. = reinterpret_cast<UINT64*>(pLayouts + NumSubresources);
  2424. auto pNumRows = reinterpret_cast<UINT*>(pRowSizesInBytes + NumSubresources);
  2425. auto Desc = pDestinationResource->GetDesc();
  2426. ID3D12Device* pDevice = nullptr;
  2427. pDestinationResource->GetDevice(
  2428. __uuidof(*pDevice), reinterpret_cast<void**>(&pDevice));
  2429. pDevice->GetCopyableFootprints(&Desc,
  2430. FirstSubresource,
  2431. NumSubresources,
  2432. IntermediateOffset,
  2433. pLayouts,
  2434. pNumRows,
  2435. pRowSizesInBytes,
  2436. &RequiredSize);
  2437. pDevice->Release();
  2438. UINT64 Result = UpdateSubresources(pCmdList,
  2439. pDestinationResource,
  2440. pIntermediate,
  2441. FirstSubresource,
  2442. NumSubresources,
  2443. RequiredSize,
  2444. pLayouts,
  2445. pNumRows,
  2446. pRowSizesInBytes,
  2447. pSrcData);
  2448. HeapFree(GetProcessHeap(), 0, pMem);
  2449. return Result;
  2450. }
  2451. //------------------------------------------------------------------------------------------------
  2452. // Heap-allocating UpdateSubresources implementation
  2453. inline UINT64 UpdateSubresources(_In_ ID3D12GraphicsCommandList* pCmdList,
  2454. _In_ ID3D12Resource* pDestinationResource,
  2455. _In_ ID3D12Resource* pIntermediate,
  2456. UINT64 IntermediateOffset,
  2457. _In_range_(0, D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
  2458. _In_range_(0, D3D12_REQ_SUBRESOURCES - FirstSubresource)
  2459. UINT NumSubresources,
  2460. _In_ const void* pResourceData,
  2461. _In_reads_(NumSubresources) D3D12_SUBRESOURCE_INFO* pSrcData) noexcept
  2462. {
  2463. UINT64 RequiredSize = 0;
  2464. auto MemToAlloc
  2465. = static_cast<UINT64>(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT)
  2466. + sizeof(UINT) + sizeof(UINT64))
  2467. * NumSubresources;
  2468. if (MemToAlloc > SIZE_MAX)
  2469. {
  2470. return 0;
  2471. }
  2472. void* pMem
  2473. = HeapAlloc(GetProcessHeap(), 0, static_cast<SIZE_T>(MemToAlloc));
  2474. if (pMem == nullptr)
  2475. {
  2476. return 0;
  2477. }
  2478. auto pLayouts = reinterpret_cast<D3D12_PLACED_SUBRESOURCE_FOOTPRINT*>(pMem);
  2479. auto pRowSizesInBytes
  2480. = reinterpret_cast<UINT64*>(pLayouts + NumSubresources);
  2481. auto pNumRows = reinterpret_cast<UINT*>(pRowSizesInBytes + NumSubresources);
  2482. auto Desc = pDestinationResource->GetDesc();
  2483. ID3D12Device* pDevice = nullptr;
  2484. pDestinationResource->GetDevice(
  2485. __uuidof(*pDevice), reinterpret_cast<void**>(&pDevice));
  2486. pDevice->GetCopyableFootprints(&Desc,
  2487. FirstSubresource,
  2488. NumSubresources,
  2489. IntermediateOffset,
  2490. pLayouts,
  2491. pNumRows,
  2492. pRowSizesInBytes,
  2493. &RequiredSize);
  2494. pDevice->Release();
  2495. UINT64 Result = UpdateSubresources(pCmdList,
  2496. pDestinationResource,
  2497. pIntermediate,
  2498. FirstSubresource,
  2499. NumSubresources,
  2500. RequiredSize,
  2501. pLayouts,
  2502. pNumRows,
  2503. pRowSizesInBytes,
  2504. pResourceData,
  2505. pSrcData);
  2506. HeapFree(GetProcessHeap(), 0, pMem);
  2507. return Result;
  2508. }
  2509. //------------------------------------------------------------------------------------------------
  2510. // Stack-allocating UpdateSubresources implementation
  2511. template<UINT MaxSubresources>
  2512. inline UINT64 UpdateSubresources(_In_ ID3D12GraphicsCommandList* pCmdList,
  2513. _In_ ID3D12Resource* pDestinationResource,
  2514. _In_ ID3D12Resource* pIntermediate,
  2515. UINT64 IntermediateOffset,
  2516. _In_range_(0, MaxSubresources) UINT FirstSubresource,
  2517. _In_range_(1, MaxSubresources - FirstSubresource) UINT NumSubresources,
  2518. _In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData) noexcept
  2519. {
  2520. UINT64 RequiredSize = 0;
  2521. D3D12_PLACED_SUBRESOURCE_FOOTPRINT Layouts[MaxSubresources];
  2522. UINT NumRows[MaxSubresources];
  2523. UINT64 RowSizesInBytes[MaxSubresources];
  2524. auto Desc = pDestinationResource->GetDesc();
  2525. ID3D12Device* pDevice = nullptr;
  2526. pDestinationResource->GetDevice(
  2527. __uuidof(*pDevice), reinterpret_cast<void**>(&pDevice));
  2528. pDevice->GetCopyableFootprints(&Desc,
  2529. FirstSubresource,
  2530. NumSubresources,
  2531. IntermediateOffset,
  2532. Layouts,
  2533. NumRows,
  2534. RowSizesInBytes,
  2535. &RequiredSize);
  2536. pDevice->Release();
  2537. return UpdateSubresources(pCmdList,
  2538. pDestinationResource,
  2539. pIntermediate,
  2540. FirstSubresource,
  2541. NumSubresources,
  2542. RequiredSize,
  2543. Layouts,
  2544. NumRows,
  2545. RowSizesInBytes,
  2546. pSrcData);
  2547. }
  2548. //------------------------------------------------------------------------------------------------
  2549. // Stack-allocating UpdateSubresources implementation
  2550. template<UINT MaxSubresources>
  2551. inline UINT64 UpdateSubresources(_In_ ID3D12GraphicsCommandList* pCmdList,
  2552. _In_ ID3D12Resource* pDestinationResource,
  2553. _In_ ID3D12Resource* pIntermediate,
  2554. UINT64 IntermediateOffset,
  2555. _In_range_(0, MaxSubresources) UINT FirstSubresource,
  2556. _In_range_(1, MaxSubresources - FirstSubresource) UINT NumSubresources,
  2557. _In_ const void* pResourceData,
  2558. _In_reads_(NumSubresources) D3D12_SUBRESOURCE_INFO* pSrcData) noexcept
  2559. {
  2560. UINT64 RequiredSize = 0;
  2561. D3D12_PLACED_SUBRESOURCE_FOOTPRINT Layouts[MaxSubresources];
  2562. UINT NumRows[MaxSubresources];
  2563. UINT64 RowSizesInBytes[MaxSubresources];
  2564. auto Desc = pDestinationResource->GetDesc();
  2565. ID3D12Device* pDevice = nullptr;
  2566. pDestinationResource->GetDevice(
  2567. __uuidof(*pDevice), reinterpret_cast<void**>(&pDevice));
  2568. pDevice->GetCopyableFootprints(&Desc,
  2569. FirstSubresource,
  2570. NumSubresources,
  2571. IntermediateOffset,
  2572. Layouts,
  2573. NumRows,
  2574. RowSizesInBytes,
  2575. &RequiredSize);
  2576. pDevice->Release();
  2577. return UpdateSubresources(pCmdList,
  2578. pDestinationResource,
  2579. pIntermediate,
  2580. FirstSubresource,
  2581. NumSubresources,
  2582. RequiredSize,
  2583. Layouts,
  2584. NumRows,
  2585. RowSizesInBytes,
  2586. pResourceData,
  2587. pSrcData);
  2588. }
  2589. //------------------------------------------------------------------------------------------------
  2590. inline constexpr bool D3D12IsLayoutOpaque(D3D12_TEXTURE_LAYOUT Layout) noexcept
  2591. {
  2592. return Layout == D3D12_TEXTURE_LAYOUT_UNKNOWN
  2593. || Layout == D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE;
  2594. }
  2595. //------------------------------------------------------------------------------------------------
  2596. template<typename t_CommandListType> inline ID3D12CommandList* const*
  2597. CommandListCast(t_CommandListType* const* pp) noexcept
  2598. {
  2599. // This cast is useful for passing strongly typed command list pointers into
  2600. // ExecuteCommandLists.
  2601. // This cast is valid as long as the const-ness is respected. D3D12 APIs do
  2602. // respect the const-ness of their arguments.
  2603. return reinterpret_cast<ID3D12CommandList* const*>(pp);
  2604. }
  2605. //------------------------------------------------------------------------------------------------
  2606. // D3D12 exports a new method for serializing root signatures in the Windows 10
  2607. // Anniversary Update. To help enable root signature 1.1 features when they are
  2608. // available and not require maintaining two code paths for building root
  2609. // signatures, this helper method reconstructs a 1.0 signature when 1.1 is not
  2610. // supported.
  2611. inline HRESULT D3DX12SerializeVersionedRootSignature(
  2612. const _In_ D3D12_VERSIONED_ROOT_SIGNATURE_DESC* pRootSignatureDesc,
  2613. D3D_ROOT_SIGNATURE_VERSION MaxVersion,
  2614. _Outptr_ ID3DBlob** ppBlob,
  2615. _Always_(_Outptr_opt_result_maybenull_) ID3DBlob** ppErrorBlob,
  2616. PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE
  2617. D3D12SerializeVersionedRootSignature,
  2618. PFN_D3D12_SERIALIZE_ROOT_SIGNATURE D3D12SerializeRootSignature) noexcept
  2619. {
  2620. if (ppErrorBlob != nullptr)
  2621. {
  2622. *ppErrorBlob = nullptr;
  2623. }
  2624. switch (MaxVersion)
  2625. {
  2626. case D3D_ROOT_SIGNATURE_VERSION_1_0:
  2627. switch (pRootSignatureDesc->Version)
  2628. {
  2629. case D3D_ROOT_SIGNATURE_VERSION_1_0:
  2630. return D3D12SerializeRootSignature(&pRootSignatureDesc->Desc_1_0,
  2631. D3D_ROOT_SIGNATURE_VERSION_1,
  2632. ppBlob,
  2633. ppErrorBlob);
  2634. case D3D_ROOT_SIGNATURE_VERSION_1_1:
  2635. {
  2636. HRESULT hr = S_OK;
  2637. const D3D12_ROOT_SIGNATURE_DESC1& desc_1_1
  2638. = pRootSignatureDesc->Desc_1_1;
  2639. const SIZE_T ParametersSize
  2640. = sizeof(D3D12_ROOT_PARAMETER) * desc_1_1.NumParameters;
  2641. void* pParameters = (ParametersSize > 0) ? HeapAlloc(
  2642. GetProcessHeap(), 0, ParametersSize)
  2643. : nullptr;
  2644. if (ParametersSize > 0 && pParameters == nullptr)
  2645. {
  2646. hr = E_OUTOFMEMORY;
  2647. }
  2648. auto pParameters_1_0
  2649. = static_cast<D3D12_ROOT_PARAMETER*>(pParameters);
  2650. if (SUCCEEDED(hr))
  2651. {
  2652. for (UINT n = 0; n < desc_1_1.NumParameters; n++)
  2653. {
  2654. __analysis_assume(ParametersSize
  2655. == sizeof(D3D12_ROOT_PARAMETER)
  2656. * desc_1_1.NumParameters);
  2657. pParameters_1_0[n].ParameterType
  2658. = desc_1_1.pParameters[n].ParameterType;
  2659. pParameters_1_0[n].ShaderVisibility
  2660. = desc_1_1.pParameters[n].ShaderVisibility;
  2661. switch (desc_1_1.pParameters[n].ParameterType)
  2662. {
  2663. case D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS:
  2664. pParameters_1_0[n].Constants.Num32BitValues
  2665. = desc_1_1.pParameters[n]
  2666. .Constants.Num32BitValues;
  2667. pParameters_1_0[n].Constants.RegisterSpace
  2668. = desc_1_1.pParameters[n]
  2669. .Constants.RegisterSpace;
  2670. pParameters_1_0[n].Constants.ShaderRegister
  2671. = desc_1_1.pParameters[n]
  2672. .Constants.ShaderRegister;
  2673. break;
  2674. case D3D12_ROOT_PARAMETER_TYPE_CBV:
  2675. case D3D12_ROOT_PARAMETER_TYPE_SRV:
  2676. case D3D12_ROOT_PARAMETER_TYPE_UAV:
  2677. pParameters_1_0[n].Descriptor.RegisterSpace
  2678. = desc_1_1.pParameters[n]
  2679. .Descriptor.RegisterSpace;
  2680. pParameters_1_0[n].Descriptor.ShaderRegister
  2681. = desc_1_1.pParameters[n]
  2682. .Descriptor.ShaderRegister;
  2683. break;
  2684. case D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE:
  2685. const D3D12_ROOT_DESCRIPTOR_TABLE1& table_1_1
  2686. = desc_1_1.pParameters[n].DescriptorTable;
  2687. const SIZE_T DescriptorRangesSize
  2688. = sizeof(D3D12_DESCRIPTOR_RANGE)
  2689. * table_1_1.NumDescriptorRanges;
  2690. void* pDescriptorRanges
  2691. = (DescriptorRangesSize > 0 && SUCCEEDED(hr))
  2692. ? HeapAlloc(GetProcessHeap(),
  2693. 0,
  2694. DescriptorRangesSize)
  2695. : nullptr;
  2696. if (DescriptorRangesSize > 0
  2697. && pDescriptorRanges == nullptr)
  2698. {
  2699. hr = E_OUTOFMEMORY;
  2700. }
  2701. auto pDescriptorRanges_1_0
  2702. = static_cast<D3D12_DESCRIPTOR_RANGE*>(
  2703. pDescriptorRanges);
  2704. if (SUCCEEDED(hr))
  2705. {
  2706. for (UINT x = 0;
  2707. x < table_1_1.NumDescriptorRanges;
  2708. x++)
  2709. {
  2710. __analysis_assume(
  2711. DescriptorRangesSize
  2712. == sizeof(D3D12_DESCRIPTOR_RANGE)
  2713. * table_1_1.NumDescriptorRanges);
  2714. pDescriptorRanges_1_0[x].BaseShaderRegister
  2715. = table_1_1.pDescriptorRanges[x]
  2716. .BaseShaderRegister;
  2717. pDescriptorRanges_1_0[x].NumDescriptors
  2718. = table_1_1.pDescriptorRanges[x]
  2719. .NumDescriptors;
  2720. pDescriptorRanges_1_0[x]
  2721. .OffsetInDescriptorsFromTableStart
  2722. = table_1_1.pDescriptorRanges[x]
  2723. .OffsetInDescriptorsFromTableStart;
  2724. pDescriptorRanges_1_0[x].RangeType
  2725. = table_1_1.pDescriptorRanges[x]
  2726. .RangeType;
  2727. pDescriptorRanges_1_0[x].RegisterSpace
  2728. = table_1_1.pDescriptorRanges[x]
  2729. .RegisterSpace;
  2730. }
  2731. }
  2732. D3D12_ROOT_DESCRIPTOR_TABLE& table_1_0
  2733. = pParameters_1_0[n].DescriptorTable;
  2734. table_1_0.NumDescriptorRanges
  2735. = table_1_1.NumDescriptorRanges;
  2736. table_1_0.pDescriptorRanges = pDescriptorRanges_1_0;
  2737. }
  2738. }
  2739. }
  2740. if (SUCCEEDED(hr))
  2741. {
  2742. CD3DX12_ROOT_SIGNATURE_DESC desc_1_0(desc_1_1.NumParameters,
  2743. pParameters_1_0,
  2744. desc_1_1.NumStaticSamplers,
  2745. desc_1_1.pStaticSamplers,
  2746. desc_1_1.Flags);
  2747. hr = D3D12SerializeRootSignature(&desc_1_0,
  2748. D3D_ROOT_SIGNATURE_VERSION_1,
  2749. ppBlob,
  2750. ppErrorBlob);
  2751. }
  2752. if (pParameters)
  2753. {
  2754. for (UINT n = 0; n < desc_1_1.NumParameters; n++)
  2755. {
  2756. if (desc_1_1.pParameters[n].ParameterType
  2757. == D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE)
  2758. {
  2759. HeapFree(GetProcessHeap(),
  2760. 0,
  2761. reinterpret_cast<void*>(
  2762. const_cast<D3D12_DESCRIPTOR_RANGE*>(
  2763. pParameters_1_0[n]
  2764. .DescriptorTable
  2765. .pDescriptorRanges)));
  2766. }
  2767. }
  2768. HeapFree(GetProcessHeap(), 0, pParameters);
  2769. }
  2770. return hr;
  2771. }
  2772. }
  2773. break;
  2774. case D3D_ROOT_SIGNATURE_VERSION_1_1:
  2775. return D3D12SerializeVersionedRootSignature(
  2776. pRootSignatureDesc, ppBlob, ppErrorBlob);
  2777. }
  2778. return E_INVALIDARG;
  2779. }
  2780. //------------------------------------------------------------------------------------------------
  2781. struct CD3DX12_RT_FORMAT_ARRAY : public D3D12_RT_FORMAT_ARRAY
  2782. {
  2783. CD3DX12_RT_FORMAT_ARRAY() = default;
  2784. explicit CD3DX12_RT_FORMAT_ARRAY(const D3D12_RT_FORMAT_ARRAY& o) noexcept
  2785. : D3D12_RT_FORMAT_ARRAY(o)
  2786. {}
  2787. explicit CD3DX12_RT_FORMAT_ARRAY(_In_reads_(NumFormats)
  2788. const DXGI_FORMAT* pFormats,
  2789. UINT NumFormats) noexcept
  2790. {
  2791. NumRenderTargets = NumFormats;
  2792. memcpy(RTFormats, pFormats, sizeof(RTFormats));
  2793. // assumes ARRAY_SIZE(pFormats) == ARRAY_SIZE(RTFormats)
  2794. }
  2795. };
  2796. //------------------------------------------------------------------------------------------------
  2797. // Pipeline State Stream Helpers
  2798. //------------------------------------------------------------------------------------------------
  2799. //------------------------------------------------------------------------------------------------
  2800. // Stream Subobjects, i.e. elements of a stream
  2801. struct DefaultSampleMask
  2802. {
  2803. operator UINT() noexcept
  2804. {
  2805. return UINT_MAX;
  2806. }
  2807. };
  2808. struct DefaultSampleDesc
  2809. {
  2810. operator DXGI_SAMPLE_DESC() noexcept
  2811. {
  2812. return DXGI_SAMPLE_DESC{1, 0};
  2813. }
  2814. };
  2815. # pragma warning(push)
  2816. # pragma warning(disable : 4324)
  2817. template<typename InnerStructType,
  2818. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE Type,
  2819. typename DefaultArg = InnerStructType>
  2820. class alignas(void*) CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT
  2821. {
  2822. private:
  2823. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE _Type;
  2824. InnerStructType _Inner;
  2825. public:
  2826. CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT()
  2827. noexcept
  2828. : _Type(Type),
  2829. _Inner(DefaultArg())
  2830. {}
  2831. CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT(const InnerStructType& i)
  2832. noexcept
  2833. : _Type(Type),
  2834. _Inner(i)
  2835. {}
  2836. CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT& operator=(
  2837. const InnerStructType& i) noexcept
  2838. {
  2839. _Type = Type;
  2840. _Inner = i;
  2841. return *this;
  2842. }
  2843. operator const InnerStructType&() const noexcept
  2844. {
  2845. return _Inner;
  2846. }
  2847. operator InnerStructType&() noexcept
  2848. {
  2849. return _Inner;
  2850. }
  2851. InnerStructType* operator&() noexcept
  2852. {
  2853. return &_Inner;
  2854. }
  2855. const InnerStructType* operator&() const noexcept
  2856. {
  2857. return &_Inner;
  2858. }
  2859. };
  2860. # pragma warning(pop)
  2861. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<D3D12_PIPELINE_STATE_FLAGS,
  2862. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_FLAGS>
  2863. CD3DX12_PIPELINE_STATE_STREAM_FLAGS;
  2864. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<UINT,
  2865. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_NODE_MASK>
  2866. CD3DX12_PIPELINE_STATE_STREAM_NODE_MASK;
  2867. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<ID3D12RootSignature*,
  2868. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE>
  2869. CD3DX12_PIPELINE_STATE_STREAM_ROOT_SIGNATURE;
  2870. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<D3D12_INPUT_LAYOUT_DESC,
  2871. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_INPUT_LAYOUT>
  2872. CD3DX12_PIPELINE_STATE_STREAM_INPUT_LAYOUT;
  2873. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
  2874. D3D12_INDEX_BUFFER_STRIP_CUT_VALUE,
  2875. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_IB_STRIP_CUT_VALUE>
  2876. CD3DX12_PIPELINE_STATE_STREAM_IB_STRIP_CUT_VALUE;
  2877. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<D3D12_PRIMITIVE_TOPOLOGY_TYPE,
  2878. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PRIMITIVE_TOPOLOGY>
  2879. CD3DX12_PIPELINE_STATE_STREAM_PRIMITIVE_TOPOLOGY;
  2880. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<D3D12_SHADER_BYTECODE,
  2881. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VS>
  2882. CD3DX12_PIPELINE_STATE_STREAM_VS;
  2883. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<D3D12_SHADER_BYTECODE,
  2884. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_GS>
  2885. CD3DX12_PIPELINE_STATE_STREAM_GS;
  2886. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<D3D12_STREAM_OUTPUT_DESC,
  2887. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_STREAM_OUTPUT>
  2888. CD3DX12_PIPELINE_STATE_STREAM_STREAM_OUTPUT;
  2889. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<D3D12_SHADER_BYTECODE,
  2890. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_HS>
  2891. CD3DX12_PIPELINE_STATE_STREAM_HS;
  2892. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<D3D12_SHADER_BYTECODE,
  2893. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DS>
  2894. CD3DX12_PIPELINE_STATE_STREAM_DS;
  2895. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<D3D12_SHADER_BYTECODE,
  2896. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS>
  2897. CD3DX12_PIPELINE_STATE_STREAM_PS;
  2898. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<D3D12_SHADER_BYTECODE,
  2899. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_AS>
  2900. CD3DX12_PIPELINE_STATE_STREAM_AS;
  2901. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<D3D12_SHADER_BYTECODE,
  2902. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS>
  2903. CD3DX12_PIPELINE_STATE_STREAM_MS;
  2904. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<D3D12_SHADER_BYTECODE,
  2905. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CS>
  2906. CD3DX12_PIPELINE_STATE_STREAM_CS;
  2907. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<CD3DX12_BLEND_DESC,
  2908. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_BLEND,
  2909. CD3DX12_DEFAULT>
  2910. CD3DX12_PIPELINE_STATE_STREAM_BLEND_DESC;
  2911. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<CD3DX12_DEPTH_STENCIL_DESC,
  2912. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL,
  2913. CD3DX12_DEFAULT>
  2914. CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL;
  2915. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<CD3DX12_DEPTH_STENCIL_DESC1,
  2916. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1,
  2917. CD3DX12_DEFAULT>
  2918. CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL1;
  2919. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<DXGI_FORMAT,
  2920. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT>
  2921. CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL_FORMAT;
  2922. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<CD3DX12_RASTERIZER_DESC,
  2923. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RASTERIZER,
  2924. CD3DX12_DEFAULT>
  2925. CD3DX12_PIPELINE_STATE_STREAM_RASTERIZER;
  2926. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<D3D12_RT_FORMAT_ARRAY,
  2927. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RENDER_TARGET_FORMATS>
  2928. CD3DX12_PIPELINE_STATE_STREAM_RENDER_TARGET_FORMATS;
  2929. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<DXGI_SAMPLE_DESC,
  2930. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_DESC,
  2931. DefaultSampleDesc>
  2932. CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_DESC;
  2933. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<UINT,
  2934. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_MASK,
  2935. DefaultSampleMask>
  2936. CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_MASK;
  2937. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<D3D12_CACHED_PIPELINE_STATE,
  2938. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CACHED_PSO>
  2939. CD3DX12_PIPELINE_STATE_STREAM_CACHED_PSO;
  2940. typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<CD3DX12_VIEW_INSTANCING_DESC,
  2941. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VIEW_INSTANCING,
  2942. CD3DX12_DEFAULT>
  2943. CD3DX12_PIPELINE_STATE_STREAM_VIEW_INSTANCING;
  2944. //------------------------------------------------------------------------------------------------
  2945. // Stream Parser Helpers
  2946. struct ID3DX12PipelineParserCallbacks
  2947. {
  2948. // Subobject Callbacks
  2949. virtual void FlagsCb(D3D12_PIPELINE_STATE_FLAGS) {}
  2950. virtual void NodeMaskCb(UINT) {}
  2951. virtual void RootSignatureCb(ID3D12RootSignature*) {}
  2952. virtual void InputLayoutCb(const D3D12_INPUT_LAYOUT_DESC&) {}
  2953. virtual void IBStripCutValueCb(D3D12_INDEX_BUFFER_STRIP_CUT_VALUE) {}
  2954. virtual void PrimitiveTopologyTypeCb(D3D12_PRIMITIVE_TOPOLOGY_TYPE) {}
  2955. virtual void VSCb(const D3D12_SHADER_BYTECODE&) {}
  2956. virtual void GSCb(const D3D12_SHADER_BYTECODE&) {}
  2957. virtual void StreamOutputCb(const D3D12_STREAM_OUTPUT_DESC&) {}
  2958. virtual void HSCb(const D3D12_SHADER_BYTECODE&) {}
  2959. virtual void DSCb(const D3D12_SHADER_BYTECODE&) {}
  2960. virtual void PSCb(const D3D12_SHADER_BYTECODE&) {}
  2961. virtual void CSCb(const D3D12_SHADER_BYTECODE&) {}
  2962. virtual void ASCb(const D3D12_SHADER_BYTECODE&) {}
  2963. virtual void MSCb(const D3D12_SHADER_BYTECODE&) {}
  2964. virtual void BlendStateCb(const D3D12_BLEND_DESC&) {}
  2965. virtual void DepthStencilStateCb(const D3D12_DEPTH_STENCIL_DESC&) {}
  2966. virtual void DepthStencilState1Cb(const D3D12_DEPTH_STENCIL_DESC1&) {}
  2967. virtual void DSVFormatCb(DXGI_FORMAT) {}
  2968. virtual void RasterizerStateCb(const D3D12_RASTERIZER_DESC&) {}
  2969. virtual void RTVFormatsCb(const D3D12_RT_FORMAT_ARRAY&) {}
  2970. virtual void SampleDescCb(const DXGI_SAMPLE_DESC&) {}
  2971. virtual void SampleMaskCb(UINT) {}
  2972. virtual void ViewInstancingCb(const D3D12_VIEW_INSTANCING_DESC&) {}
  2973. virtual void CachedPSOCb(const D3D12_CACHED_PIPELINE_STATE&) {}
  2974. // Error Callbacks
  2975. virtual void ErrorBadInputParameter(UINT /*ParameterIndex*/) {}
  2976. virtual void ErrorDuplicateSubobject(
  2977. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE /*DuplicateType*/)
  2978. {}
  2979. virtual void ErrorUnknownSubobject(UINT /*UnknownTypeValue*/) {}
  2980. virtual ~ID3DX12PipelineParserCallbacks() = default;
  2981. };
  2982. struct D3DX12_MESH_SHADER_PIPELINE_STATE_DESC
  2983. {
  2984. ID3D12RootSignature* pRootSignature;
  2985. D3D12_SHADER_BYTECODE AS;
  2986. D3D12_SHADER_BYTECODE MS;
  2987. D3D12_SHADER_BYTECODE PS;
  2988. D3D12_BLEND_DESC BlendState;
  2989. UINT SampleMask;
  2990. D3D12_RASTERIZER_DESC RasterizerState;
  2991. D3D12_DEPTH_STENCIL_DESC DepthStencilState;
  2992. D3D12_PRIMITIVE_TOPOLOGY_TYPE PrimitiveTopologyType;
  2993. UINT NumRenderTargets;
  2994. DXGI_FORMAT RTVFormats[D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT];
  2995. DXGI_FORMAT DSVFormat;
  2996. DXGI_SAMPLE_DESC SampleDesc;
  2997. UINT NodeMask;
  2998. D3D12_CACHED_PIPELINE_STATE CachedPSO;
  2999. D3D12_PIPELINE_STATE_FLAGS Flags;
  3000. };
  3001. // CD3DX12_PIPELINE_STATE_STREAM2 Works on OS Build 19041+ (where there is a new
  3002. // mesh shader pipeline). Use CD3DX12_PIPELINE_STATE_STREAM1 for OS Build 16299+
  3003. // (where there is a new view instancing subobject). Use
  3004. // CD3DX12_PIPELINE_STATE_STREAM for OS Build 15063+ support.
  3005. struct CD3DX12_PIPELINE_STATE_STREAM2
  3006. {
  3007. CD3DX12_PIPELINE_STATE_STREAM2() = default;
  3008. // Mesh and amplification shaders must be set manually, since they do not
  3009. // have representation in D3D12_GRAPHICS_PIPELINE_STATE_DESC
  3010. CD3DX12_PIPELINE_STATE_STREAM2(
  3011. const D3D12_GRAPHICS_PIPELINE_STATE_DESC& Desc)
  3012. noexcept
  3013. : Flags(Desc.Flags),
  3014. NodeMask(Desc.NodeMask),
  3015. pRootSignature(Desc.pRootSignature),
  3016. InputLayout(Desc.InputLayout),
  3017. IBStripCutValue(Desc.IBStripCutValue),
  3018. PrimitiveTopologyType(Desc.PrimitiveTopologyType),
  3019. VS(Desc.VS),
  3020. GS(Desc.GS),
  3021. StreamOutput(Desc.StreamOutput),
  3022. HS(Desc.HS),
  3023. DS(Desc.DS),
  3024. PS(Desc.PS),
  3025. BlendState(CD3DX12_BLEND_DESC(Desc.BlendState)),
  3026. DepthStencilState(
  3027. CD3DX12_DEPTH_STENCIL_DESC1(Desc.DepthStencilState)),
  3028. DSVFormat(Desc.DSVFormat),
  3029. RasterizerState(CD3DX12_RASTERIZER_DESC(Desc.RasterizerState)),
  3030. RTVFormats(
  3031. CD3DX12_RT_FORMAT_ARRAY(Desc.RTVFormats, Desc.NumRenderTargets)),
  3032. SampleDesc(Desc.SampleDesc),
  3033. SampleMask(Desc.SampleMask),
  3034. CachedPSO(Desc.CachedPSO),
  3035. ViewInstancingDesc(CD3DX12_VIEW_INSTANCING_DESC(CD3DX12_DEFAULT()))
  3036. {}
  3037. CD3DX12_PIPELINE_STATE_STREAM2(
  3038. const D3DX12_MESH_SHADER_PIPELINE_STATE_DESC& Desc)
  3039. noexcept
  3040. : Flags(Desc.Flags),
  3041. NodeMask(Desc.NodeMask),
  3042. pRootSignature(Desc.pRootSignature),
  3043. PrimitiveTopologyType(Desc.PrimitiveTopologyType),
  3044. PS(Desc.PS),
  3045. AS(Desc.AS),
  3046. MS(Desc.MS),
  3047. BlendState(CD3DX12_BLEND_DESC(Desc.BlendState)),
  3048. DepthStencilState(
  3049. CD3DX12_DEPTH_STENCIL_DESC1(Desc.DepthStencilState)),
  3050. DSVFormat(Desc.DSVFormat),
  3051. RasterizerState(CD3DX12_RASTERIZER_DESC(Desc.RasterizerState)),
  3052. RTVFormats(
  3053. CD3DX12_RT_FORMAT_ARRAY(Desc.RTVFormats, Desc.NumRenderTargets)),
  3054. SampleDesc(Desc.SampleDesc),
  3055. SampleMask(Desc.SampleMask),
  3056. CachedPSO(Desc.CachedPSO),
  3057. ViewInstancingDesc(CD3DX12_VIEW_INSTANCING_DESC(CD3DX12_DEFAULT()))
  3058. {}
  3059. CD3DX12_PIPELINE_STATE_STREAM2(
  3060. const D3D12_COMPUTE_PIPELINE_STATE_DESC& Desc)
  3061. noexcept
  3062. : Flags(Desc.Flags),
  3063. NodeMask(Desc.NodeMask),
  3064. pRootSignature(Desc.pRootSignature),
  3065. CS(CD3DX12_SHADER_BYTECODE(Desc.CS)),
  3066. CachedPSO(Desc.CachedPSO)
  3067. {
  3068. static_cast<D3D12_DEPTH_STENCIL_DESC1&>(DepthStencilState).DepthEnable
  3069. = false;
  3070. }
  3071. CD3DX12_PIPELINE_STATE_STREAM_FLAGS Flags;
  3072. CD3DX12_PIPELINE_STATE_STREAM_NODE_MASK NodeMask;
  3073. CD3DX12_PIPELINE_STATE_STREAM_ROOT_SIGNATURE pRootSignature;
  3074. CD3DX12_PIPELINE_STATE_STREAM_INPUT_LAYOUT InputLayout;
  3075. CD3DX12_PIPELINE_STATE_STREAM_IB_STRIP_CUT_VALUE IBStripCutValue;
  3076. CD3DX12_PIPELINE_STATE_STREAM_PRIMITIVE_TOPOLOGY PrimitiveTopologyType;
  3077. CD3DX12_PIPELINE_STATE_STREAM_VS VS;
  3078. CD3DX12_PIPELINE_STATE_STREAM_GS GS;
  3079. CD3DX12_PIPELINE_STATE_STREAM_STREAM_OUTPUT StreamOutput;
  3080. CD3DX12_PIPELINE_STATE_STREAM_HS HS;
  3081. CD3DX12_PIPELINE_STATE_STREAM_DS DS;
  3082. CD3DX12_PIPELINE_STATE_STREAM_PS PS;
  3083. CD3DX12_PIPELINE_STATE_STREAM_AS AS;
  3084. CD3DX12_PIPELINE_STATE_STREAM_MS MS;
  3085. CD3DX12_PIPELINE_STATE_STREAM_CS CS;
  3086. CD3DX12_PIPELINE_STATE_STREAM_BLEND_DESC BlendState;
  3087. CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL1 DepthStencilState;
  3088. CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL_FORMAT DSVFormat;
  3089. CD3DX12_PIPELINE_STATE_STREAM_RASTERIZER RasterizerState;
  3090. CD3DX12_PIPELINE_STATE_STREAM_RENDER_TARGET_FORMATS RTVFormats;
  3091. CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_DESC SampleDesc;
  3092. CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_MASK SampleMask;
  3093. CD3DX12_PIPELINE_STATE_STREAM_CACHED_PSO CachedPSO;
  3094. CD3DX12_PIPELINE_STATE_STREAM_VIEW_INSTANCING ViewInstancingDesc;
  3095. D3D12_GRAPHICS_PIPELINE_STATE_DESC GraphicsDescV0() const noexcept
  3096. {
  3097. D3D12_GRAPHICS_PIPELINE_STATE_DESC D;
  3098. D.Flags = this->Flags;
  3099. D.NodeMask = this->NodeMask;
  3100. D.pRootSignature = this->pRootSignature;
  3101. D.InputLayout = this->InputLayout;
  3102. D.IBStripCutValue = this->IBStripCutValue;
  3103. D.PrimitiveTopologyType = this->PrimitiveTopologyType;
  3104. D.VS = this->VS;
  3105. D.GS = this->GS;
  3106. D.StreamOutput = this->StreamOutput;
  3107. D.HS = this->HS;
  3108. D.DS = this->DS;
  3109. D.PS = this->PS;
  3110. D.BlendState = this->BlendState;
  3111. D.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC1(
  3112. D3D12_DEPTH_STENCIL_DESC1(this->DepthStencilState));
  3113. D.DSVFormat = this->DSVFormat;
  3114. D.RasterizerState = this->RasterizerState;
  3115. D.NumRenderTargets
  3116. = D3D12_RT_FORMAT_ARRAY(this->RTVFormats).NumRenderTargets;
  3117. memcpy(D.RTVFormats,
  3118. D3D12_RT_FORMAT_ARRAY(this->RTVFormats).RTFormats,
  3119. sizeof(D.RTVFormats));
  3120. D.SampleDesc = this->SampleDesc;
  3121. D.SampleMask = this->SampleMask;
  3122. D.CachedPSO = this->CachedPSO;
  3123. return D;
  3124. }
  3125. D3D12_COMPUTE_PIPELINE_STATE_DESC ComputeDescV0() const noexcept
  3126. {
  3127. D3D12_COMPUTE_PIPELINE_STATE_DESC D;
  3128. D.Flags = this->Flags;
  3129. D.NodeMask = this->NodeMask;
  3130. D.pRootSignature = this->pRootSignature;
  3131. D.CS = this->CS;
  3132. D.CachedPSO = this->CachedPSO;
  3133. return D;
  3134. }
  3135. };
  3136. // CD3DX12_PIPELINE_STATE_STREAM1 Works on OS Build 16299+ (where there is a new
  3137. // view instancing subobject). Use CD3DX12_PIPELINE_STATE_STREAM for OS Build
  3138. // 15063+ support.
  3139. struct CD3DX12_PIPELINE_STATE_STREAM1
  3140. {
  3141. CD3DX12_PIPELINE_STATE_STREAM1() = default;
  3142. // Mesh and amplification shaders must be set manually, since they do not
  3143. // have representation in D3D12_GRAPHICS_PIPELINE_STATE_DESC
  3144. CD3DX12_PIPELINE_STATE_STREAM1(
  3145. const D3D12_GRAPHICS_PIPELINE_STATE_DESC& Desc)
  3146. noexcept
  3147. : Flags(Desc.Flags),
  3148. NodeMask(Desc.NodeMask),
  3149. pRootSignature(Desc.pRootSignature),
  3150. InputLayout(Desc.InputLayout),
  3151. IBStripCutValue(Desc.IBStripCutValue),
  3152. PrimitiveTopologyType(Desc.PrimitiveTopologyType),
  3153. VS(Desc.VS),
  3154. GS(Desc.GS),
  3155. StreamOutput(Desc.StreamOutput),
  3156. HS(Desc.HS),
  3157. DS(Desc.DS),
  3158. PS(Desc.PS),
  3159. BlendState(CD3DX12_BLEND_DESC(Desc.BlendState)),
  3160. DepthStencilState(
  3161. CD3DX12_DEPTH_STENCIL_DESC1(Desc.DepthStencilState)),
  3162. DSVFormat(Desc.DSVFormat),
  3163. RasterizerState(CD3DX12_RASTERIZER_DESC(Desc.RasterizerState)),
  3164. RTVFormats(
  3165. CD3DX12_RT_FORMAT_ARRAY(Desc.RTVFormats, Desc.NumRenderTargets)),
  3166. SampleDesc(Desc.SampleDesc),
  3167. SampleMask(Desc.SampleMask),
  3168. CachedPSO(Desc.CachedPSO),
  3169. ViewInstancingDesc(CD3DX12_VIEW_INSTANCING_DESC(CD3DX12_DEFAULT()))
  3170. {}
  3171. CD3DX12_PIPELINE_STATE_STREAM1(
  3172. const D3DX12_MESH_SHADER_PIPELINE_STATE_DESC& Desc)
  3173. noexcept
  3174. : Flags(Desc.Flags),
  3175. NodeMask(Desc.NodeMask),
  3176. pRootSignature(Desc.pRootSignature),
  3177. PrimitiveTopologyType(Desc.PrimitiveTopologyType),
  3178. PS(Desc.PS),
  3179. BlendState(CD3DX12_BLEND_DESC(Desc.BlendState)),
  3180. DepthStencilState(
  3181. CD3DX12_DEPTH_STENCIL_DESC1(Desc.DepthStencilState)),
  3182. DSVFormat(Desc.DSVFormat),
  3183. RasterizerState(CD3DX12_RASTERIZER_DESC(Desc.RasterizerState)),
  3184. RTVFormats(
  3185. CD3DX12_RT_FORMAT_ARRAY(Desc.RTVFormats, Desc.NumRenderTargets)),
  3186. SampleDesc(Desc.SampleDesc),
  3187. SampleMask(Desc.SampleMask),
  3188. CachedPSO(Desc.CachedPSO),
  3189. ViewInstancingDesc(CD3DX12_VIEW_INSTANCING_DESC(CD3DX12_DEFAULT()))
  3190. {}
  3191. CD3DX12_PIPELINE_STATE_STREAM1(
  3192. const D3D12_COMPUTE_PIPELINE_STATE_DESC& Desc)
  3193. noexcept
  3194. : Flags(Desc.Flags),
  3195. NodeMask(Desc.NodeMask),
  3196. pRootSignature(Desc.pRootSignature),
  3197. CS(CD3DX12_SHADER_BYTECODE(Desc.CS)),
  3198. CachedPSO(Desc.CachedPSO)
  3199. {
  3200. static_cast<D3D12_DEPTH_STENCIL_DESC1&>(DepthStencilState).DepthEnable
  3201. = false;
  3202. }
  3203. CD3DX12_PIPELINE_STATE_STREAM_FLAGS Flags;
  3204. CD3DX12_PIPELINE_STATE_STREAM_NODE_MASK NodeMask;
  3205. CD3DX12_PIPELINE_STATE_STREAM_ROOT_SIGNATURE pRootSignature;
  3206. CD3DX12_PIPELINE_STATE_STREAM_INPUT_LAYOUT InputLayout;
  3207. CD3DX12_PIPELINE_STATE_STREAM_IB_STRIP_CUT_VALUE IBStripCutValue;
  3208. CD3DX12_PIPELINE_STATE_STREAM_PRIMITIVE_TOPOLOGY PrimitiveTopologyType;
  3209. CD3DX12_PIPELINE_STATE_STREAM_VS VS;
  3210. CD3DX12_PIPELINE_STATE_STREAM_GS GS;
  3211. CD3DX12_PIPELINE_STATE_STREAM_STREAM_OUTPUT StreamOutput;
  3212. CD3DX12_PIPELINE_STATE_STREAM_HS HS;
  3213. CD3DX12_PIPELINE_STATE_STREAM_DS DS;
  3214. CD3DX12_PIPELINE_STATE_STREAM_PS PS;
  3215. CD3DX12_PIPELINE_STATE_STREAM_CS CS;
  3216. CD3DX12_PIPELINE_STATE_STREAM_BLEND_DESC BlendState;
  3217. CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL1 DepthStencilState;
  3218. CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL_FORMAT DSVFormat;
  3219. CD3DX12_PIPELINE_STATE_STREAM_RASTERIZER RasterizerState;
  3220. CD3DX12_PIPELINE_STATE_STREAM_RENDER_TARGET_FORMATS RTVFormats;
  3221. CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_DESC SampleDesc;
  3222. CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_MASK SampleMask;
  3223. CD3DX12_PIPELINE_STATE_STREAM_CACHED_PSO CachedPSO;
  3224. CD3DX12_PIPELINE_STATE_STREAM_VIEW_INSTANCING ViewInstancingDesc;
  3225. D3D12_GRAPHICS_PIPELINE_STATE_DESC GraphicsDescV0() const noexcept
  3226. {
  3227. D3D12_GRAPHICS_PIPELINE_STATE_DESC D;
  3228. D.Flags = this->Flags;
  3229. D.NodeMask = this->NodeMask;
  3230. D.pRootSignature = this->pRootSignature;
  3231. D.InputLayout = this->InputLayout;
  3232. D.IBStripCutValue = this->IBStripCutValue;
  3233. D.PrimitiveTopologyType = this->PrimitiveTopologyType;
  3234. D.VS = this->VS;
  3235. D.GS = this->GS;
  3236. D.StreamOutput = this->StreamOutput;
  3237. D.HS = this->HS;
  3238. D.DS = this->DS;
  3239. D.PS = this->PS;
  3240. D.BlendState = this->BlendState;
  3241. D.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC1(
  3242. D3D12_DEPTH_STENCIL_DESC1(this->DepthStencilState));
  3243. D.DSVFormat = this->DSVFormat;
  3244. D.RasterizerState = this->RasterizerState;
  3245. D.NumRenderTargets
  3246. = D3D12_RT_FORMAT_ARRAY(this->RTVFormats).NumRenderTargets;
  3247. memcpy(D.RTVFormats,
  3248. D3D12_RT_FORMAT_ARRAY(this->RTVFormats).RTFormats,
  3249. sizeof(D.RTVFormats));
  3250. D.SampleDesc = this->SampleDesc;
  3251. D.SampleMask = this->SampleMask;
  3252. D.CachedPSO = this->CachedPSO;
  3253. return D;
  3254. }
  3255. D3D12_COMPUTE_PIPELINE_STATE_DESC ComputeDescV0() const noexcept
  3256. {
  3257. D3D12_COMPUTE_PIPELINE_STATE_DESC D;
  3258. D.Flags = this->Flags;
  3259. D.NodeMask = this->NodeMask;
  3260. D.pRootSignature = this->pRootSignature;
  3261. D.CS = this->CS;
  3262. D.CachedPSO = this->CachedPSO;
  3263. return D;
  3264. }
  3265. };
  3266. struct CD3DX12_PIPELINE_MESH_STATE_STREAM
  3267. {
  3268. CD3DX12_PIPELINE_MESH_STATE_STREAM() = default;
  3269. CD3DX12_PIPELINE_MESH_STATE_STREAM(
  3270. const D3DX12_MESH_SHADER_PIPELINE_STATE_DESC& Desc)
  3271. noexcept
  3272. : Flags(Desc.Flags),
  3273. NodeMask(Desc.NodeMask),
  3274. pRootSignature(Desc.pRootSignature),
  3275. PS(Desc.PS),
  3276. AS(Desc.AS),
  3277. MS(Desc.MS),
  3278. BlendState(CD3DX12_BLEND_DESC(Desc.BlendState)),
  3279. DepthStencilState(
  3280. CD3DX12_DEPTH_STENCIL_DESC1(Desc.DepthStencilState)),
  3281. DSVFormat(Desc.DSVFormat),
  3282. RasterizerState(CD3DX12_RASTERIZER_DESC(Desc.RasterizerState)),
  3283. RTVFormats(
  3284. CD3DX12_RT_FORMAT_ARRAY(Desc.RTVFormats, Desc.NumRenderTargets)),
  3285. SampleDesc(Desc.SampleDesc),
  3286. SampleMask(Desc.SampleMask),
  3287. CachedPSO(Desc.CachedPSO),
  3288. ViewInstancingDesc(CD3DX12_VIEW_INSTANCING_DESC(CD3DX12_DEFAULT()))
  3289. {}
  3290. CD3DX12_PIPELINE_STATE_STREAM_FLAGS Flags;
  3291. CD3DX12_PIPELINE_STATE_STREAM_NODE_MASK NodeMask;
  3292. CD3DX12_PIPELINE_STATE_STREAM_ROOT_SIGNATURE pRootSignature;
  3293. CD3DX12_PIPELINE_STATE_STREAM_PS PS;
  3294. CD3DX12_PIPELINE_STATE_STREAM_AS AS;
  3295. CD3DX12_PIPELINE_STATE_STREAM_MS MS;
  3296. CD3DX12_PIPELINE_STATE_STREAM_BLEND_DESC BlendState;
  3297. CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL1 DepthStencilState;
  3298. CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL_FORMAT DSVFormat;
  3299. CD3DX12_PIPELINE_STATE_STREAM_RASTERIZER RasterizerState;
  3300. CD3DX12_PIPELINE_STATE_STREAM_RENDER_TARGET_FORMATS RTVFormats;
  3301. CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_DESC SampleDesc;
  3302. CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_MASK SampleMask;
  3303. CD3DX12_PIPELINE_STATE_STREAM_CACHED_PSO CachedPSO;
  3304. CD3DX12_PIPELINE_STATE_STREAM_VIEW_INSTANCING ViewInstancingDesc;
  3305. D3DX12_MESH_SHADER_PIPELINE_STATE_DESC MeshShaderDescV0() const noexcept
  3306. {
  3307. D3DX12_MESH_SHADER_PIPELINE_STATE_DESC D;
  3308. D.Flags = this->Flags;
  3309. D.NodeMask = this->NodeMask;
  3310. D.pRootSignature = this->pRootSignature;
  3311. D.PS = this->PS;
  3312. D.AS = this->AS;
  3313. D.MS = this->MS;
  3314. D.BlendState = this->BlendState;
  3315. D.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC1(
  3316. D3D12_DEPTH_STENCIL_DESC1(this->DepthStencilState));
  3317. D.DSVFormat = this->DSVFormat;
  3318. D.RasterizerState = this->RasterizerState;
  3319. D.NumRenderTargets
  3320. = D3D12_RT_FORMAT_ARRAY(this->RTVFormats).NumRenderTargets;
  3321. memcpy(D.RTVFormats,
  3322. D3D12_RT_FORMAT_ARRAY(this->RTVFormats).RTFormats,
  3323. sizeof(D.RTVFormats));
  3324. D.SampleDesc = this->SampleDesc;
  3325. D.SampleMask = this->SampleMask;
  3326. D.CachedPSO = this->CachedPSO;
  3327. return D;
  3328. }
  3329. };
  3330. // CD3DX12_PIPELINE_STATE_STREAM works on OS Build 15063+ but does not support
  3331. // new subobject(s) added in OS Build 16299+. See CD3DX12_PIPELINE_STATE_STREAM1
  3332. // for instance.
  3333. struct CD3DX12_PIPELINE_STATE_STREAM
  3334. {
  3335. CD3DX12_PIPELINE_STATE_STREAM() = default;
  3336. CD3DX12_PIPELINE_STATE_STREAM(
  3337. const D3D12_GRAPHICS_PIPELINE_STATE_DESC& Desc)
  3338. noexcept
  3339. : Flags(Desc.Flags),
  3340. NodeMask(Desc.NodeMask),
  3341. pRootSignature(Desc.pRootSignature),
  3342. InputLayout(Desc.InputLayout),
  3343. IBStripCutValue(Desc.IBStripCutValue),
  3344. PrimitiveTopologyType(Desc.PrimitiveTopologyType),
  3345. VS(Desc.VS),
  3346. GS(Desc.GS),
  3347. StreamOutput(Desc.StreamOutput),
  3348. HS(Desc.HS),
  3349. DS(Desc.DS),
  3350. PS(Desc.PS),
  3351. BlendState(CD3DX12_BLEND_DESC(Desc.BlendState)),
  3352. DepthStencilState(
  3353. CD3DX12_DEPTH_STENCIL_DESC1(Desc.DepthStencilState)),
  3354. DSVFormat(Desc.DSVFormat),
  3355. RasterizerState(CD3DX12_RASTERIZER_DESC(Desc.RasterizerState)),
  3356. RTVFormats(
  3357. CD3DX12_RT_FORMAT_ARRAY(Desc.RTVFormats, Desc.NumRenderTargets)),
  3358. SampleDesc(Desc.SampleDesc),
  3359. SampleMask(Desc.SampleMask),
  3360. CachedPSO(Desc.CachedPSO)
  3361. {}
  3362. CD3DX12_PIPELINE_STATE_STREAM(const D3D12_COMPUTE_PIPELINE_STATE_DESC& Desc)
  3363. noexcept
  3364. : Flags(Desc.Flags),
  3365. NodeMask(Desc.NodeMask),
  3366. pRootSignature(Desc.pRootSignature),
  3367. CS(CD3DX12_SHADER_BYTECODE(Desc.CS)),
  3368. CachedPSO(Desc.CachedPSO)
  3369. {}
  3370. CD3DX12_PIPELINE_STATE_STREAM_FLAGS Flags;
  3371. CD3DX12_PIPELINE_STATE_STREAM_NODE_MASK NodeMask;
  3372. CD3DX12_PIPELINE_STATE_STREAM_ROOT_SIGNATURE pRootSignature;
  3373. CD3DX12_PIPELINE_STATE_STREAM_INPUT_LAYOUT InputLayout;
  3374. CD3DX12_PIPELINE_STATE_STREAM_IB_STRIP_CUT_VALUE IBStripCutValue;
  3375. CD3DX12_PIPELINE_STATE_STREAM_PRIMITIVE_TOPOLOGY PrimitiveTopologyType;
  3376. CD3DX12_PIPELINE_STATE_STREAM_VS VS;
  3377. CD3DX12_PIPELINE_STATE_STREAM_GS GS;
  3378. CD3DX12_PIPELINE_STATE_STREAM_STREAM_OUTPUT StreamOutput;
  3379. CD3DX12_PIPELINE_STATE_STREAM_HS HS;
  3380. CD3DX12_PIPELINE_STATE_STREAM_DS DS;
  3381. CD3DX12_PIPELINE_STATE_STREAM_PS PS;
  3382. CD3DX12_PIPELINE_STATE_STREAM_CS CS;
  3383. CD3DX12_PIPELINE_STATE_STREAM_BLEND_DESC BlendState;
  3384. CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL1 DepthStencilState;
  3385. CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL_FORMAT DSVFormat;
  3386. CD3DX12_PIPELINE_STATE_STREAM_RASTERIZER RasterizerState;
  3387. CD3DX12_PIPELINE_STATE_STREAM_RENDER_TARGET_FORMATS RTVFormats;
  3388. CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_DESC SampleDesc;
  3389. CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_MASK SampleMask;
  3390. CD3DX12_PIPELINE_STATE_STREAM_CACHED_PSO CachedPSO;
  3391. D3D12_GRAPHICS_PIPELINE_STATE_DESC GraphicsDescV0() const noexcept
  3392. {
  3393. D3D12_GRAPHICS_PIPELINE_STATE_DESC D;
  3394. D.Flags = this->Flags;
  3395. D.NodeMask = this->NodeMask;
  3396. D.pRootSignature = this->pRootSignature;
  3397. D.InputLayout = this->InputLayout;
  3398. D.IBStripCutValue = this->IBStripCutValue;
  3399. D.PrimitiveTopologyType = this->PrimitiveTopologyType;
  3400. D.VS = this->VS;
  3401. D.GS = this->GS;
  3402. D.StreamOutput = this->StreamOutput;
  3403. D.HS = this->HS;
  3404. D.DS = this->DS;
  3405. D.PS = this->PS;
  3406. D.BlendState = this->BlendState;
  3407. D.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC1(
  3408. D3D12_DEPTH_STENCIL_DESC1(this->DepthStencilState));
  3409. D.DSVFormat = this->DSVFormat;
  3410. D.RasterizerState = this->RasterizerState;
  3411. D.NumRenderTargets
  3412. = D3D12_RT_FORMAT_ARRAY(this->RTVFormats).NumRenderTargets;
  3413. memcpy(D.RTVFormats,
  3414. D3D12_RT_FORMAT_ARRAY(this->RTVFormats).RTFormats,
  3415. sizeof(D.RTVFormats));
  3416. D.SampleDesc = this->SampleDesc;
  3417. D.SampleMask = this->SampleMask;
  3418. D.CachedPSO = this->CachedPSO;
  3419. return D;
  3420. }
  3421. D3D12_COMPUTE_PIPELINE_STATE_DESC ComputeDescV0() const noexcept
  3422. {
  3423. D3D12_COMPUTE_PIPELINE_STATE_DESC D;
  3424. D.Flags = this->Flags;
  3425. D.NodeMask = this->NodeMask;
  3426. D.pRootSignature = this->pRootSignature;
  3427. D.CS = this->CS;
  3428. D.CachedPSO = this->CachedPSO;
  3429. return D;
  3430. }
  3431. };
  3432. struct CD3DX12_PIPELINE_STATE_STREAM2_PARSE_HELPER
  3433. : public ID3DX12PipelineParserCallbacks
  3434. {
  3435. CD3DX12_PIPELINE_STATE_STREAM2 PipelineStream;
  3436. CD3DX12_PIPELINE_STATE_STREAM2_PARSE_HELPER()
  3437. noexcept
  3438. : SeenDSS(false)
  3439. {
  3440. // Adjust defaults to account for absent members.
  3441. PipelineStream.PrimitiveTopologyType
  3442. = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
  3443. // Depth disabled if no DSV format specified.
  3444. static_cast<D3D12_DEPTH_STENCIL_DESC1&>(
  3445. PipelineStream.DepthStencilState)
  3446. .DepthEnable
  3447. = false;
  3448. }
  3449. // ID3DX12PipelineParserCallbacks
  3450. void FlagsCb(D3D12_PIPELINE_STATE_FLAGS Flags) override
  3451. {
  3452. PipelineStream.Flags = Flags;
  3453. }
  3454. void NodeMaskCb(UINT NodeMask) override
  3455. {
  3456. PipelineStream.NodeMask = NodeMask;
  3457. }
  3458. void RootSignatureCb(ID3D12RootSignature* pRootSignature) override
  3459. {
  3460. PipelineStream.pRootSignature = pRootSignature;
  3461. }
  3462. void InputLayoutCb(const D3D12_INPUT_LAYOUT_DESC& InputLayout) override
  3463. {
  3464. PipelineStream.InputLayout = InputLayout;
  3465. }
  3466. void IBStripCutValueCb(
  3467. D3D12_INDEX_BUFFER_STRIP_CUT_VALUE IBStripCutValue) override
  3468. {
  3469. PipelineStream.IBStripCutValue = IBStripCutValue;
  3470. }
  3471. void PrimitiveTopologyTypeCb(
  3472. D3D12_PRIMITIVE_TOPOLOGY_TYPE PrimitiveTopologyType) override
  3473. {
  3474. PipelineStream.PrimitiveTopologyType = PrimitiveTopologyType;
  3475. }
  3476. void VSCb(const D3D12_SHADER_BYTECODE& VS) override
  3477. {
  3478. PipelineStream.VS = VS;
  3479. }
  3480. void GSCb(const D3D12_SHADER_BYTECODE& GS) override
  3481. {
  3482. PipelineStream.GS = GS;
  3483. }
  3484. void StreamOutputCb(const D3D12_STREAM_OUTPUT_DESC& StreamOutput) override
  3485. {
  3486. PipelineStream.StreamOutput = StreamOutput;
  3487. }
  3488. void HSCb(const D3D12_SHADER_BYTECODE& HS) override
  3489. {
  3490. PipelineStream.HS = HS;
  3491. }
  3492. void DSCb(const D3D12_SHADER_BYTECODE& DS) override
  3493. {
  3494. PipelineStream.DS = DS;
  3495. }
  3496. void PSCb(const D3D12_SHADER_BYTECODE& PS) override
  3497. {
  3498. PipelineStream.PS = PS;
  3499. }
  3500. void CSCb(const D3D12_SHADER_BYTECODE& CS) override
  3501. {
  3502. PipelineStream.CS = CS;
  3503. }
  3504. void ASCb(const D3D12_SHADER_BYTECODE& AS) override
  3505. {
  3506. PipelineStream.AS = AS;
  3507. }
  3508. void MSCb(const D3D12_SHADER_BYTECODE& MS) override
  3509. {
  3510. PipelineStream.MS = MS;
  3511. }
  3512. void BlendStateCb(const D3D12_BLEND_DESC& BlendState) override
  3513. {
  3514. PipelineStream.BlendState = CD3DX12_BLEND_DESC(BlendState);
  3515. }
  3516. void DepthStencilStateCb(
  3517. const D3D12_DEPTH_STENCIL_DESC& DepthStencilState) override
  3518. {
  3519. PipelineStream.DepthStencilState
  3520. = CD3DX12_DEPTH_STENCIL_DESC1(DepthStencilState);
  3521. SeenDSS = true;
  3522. }
  3523. void DepthStencilState1Cb(
  3524. const D3D12_DEPTH_STENCIL_DESC1& DepthStencilState) override
  3525. {
  3526. PipelineStream.DepthStencilState
  3527. = CD3DX12_DEPTH_STENCIL_DESC1(DepthStencilState);
  3528. SeenDSS = true;
  3529. }
  3530. void DSVFormatCb(DXGI_FORMAT DSVFormat) override
  3531. {
  3532. PipelineStream.DSVFormat = DSVFormat;
  3533. if (!SeenDSS && DSVFormat != DXGI_FORMAT_UNKNOWN)
  3534. {
  3535. // Re-enable depth for the default state.
  3536. static_cast<D3D12_DEPTH_STENCIL_DESC1&>(
  3537. PipelineStream.DepthStencilState)
  3538. .DepthEnable
  3539. = true;
  3540. }
  3541. }
  3542. void RasterizerStateCb(
  3543. const D3D12_RASTERIZER_DESC& RasterizerState) override
  3544. {
  3545. PipelineStream.RasterizerState
  3546. = CD3DX12_RASTERIZER_DESC(RasterizerState);
  3547. }
  3548. void RTVFormatsCb(const D3D12_RT_FORMAT_ARRAY& RTVFormats) override
  3549. {
  3550. PipelineStream.RTVFormats = RTVFormats;
  3551. }
  3552. void SampleDescCb(const DXGI_SAMPLE_DESC& SampleDesc) override
  3553. {
  3554. PipelineStream.SampleDesc = SampleDesc;
  3555. }
  3556. void SampleMaskCb(UINT SampleMask) override
  3557. {
  3558. PipelineStream.SampleMask = SampleMask;
  3559. }
  3560. void ViewInstancingCb(
  3561. const D3D12_VIEW_INSTANCING_DESC& ViewInstancingDesc) override
  3562. {
  3563. PipelineStream.ViewInstancingDesc
  3564. = CD3DX12_VIEW_INSTANCING_DESC(ViewInstancingDesc);
  3565. }
  3566. void CachedPSOCb(const D3D12_CACHED_PIPELINE_STATE& CachedPSO) override
  3567. {
  3568. PipelineStream.CachedPSO = CachedPSO;
  3569. }
  3570. private:
  3571. bool SeenDSS;
  3572. };
  3573. struct CD3DX12_PIPELINE_STATE_STREAM_PARSE_HELPER
  3574. : public ID3DX12PipelineParserCallbacks
  3575. {
  3576. CD3DX12_PIPELINE_STATE_STREAM1 PipelineStream;
  3577. CD3DX12_PIPELINE_STATE_STREAM_PARSE_HELPER()
  3578. noexcept
  3579. : SeenDSS(false)
  3580. {
  3581. // Adjust defaults to account for absent members.
  3582. PipelineStream.PrimitiveTopologyType
  3583. = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
  3584. // Depth disabled if no DSV format specified.
  3585. static_cast<D3D12_DEPTH_STENCIL_DESC1&>(
  3586. PipelineStream.DepthStencilState)
  3587. .DepthEnable
  3588. = false;
  3589. }
  3590. // ID3DX12PipelineParserCallbacks
  3591. void FlagsCb(D3D12_PIPELINE_STATE_FLAGS Flags) override
  3592. {
  3593. PipelineStream.Flags = Flags;
  3594. }
  3595. void NodeMaskCb(UINT NodeMask) override
  3596. {
  3597. PipelineStream.NodeMask = NodeMask;
  3598. }
  3599. void RootSignatureCb(ID3D12RootSignature* pRootSignature) override
  3600. {
  3601. PipelineStream.pRootSignature = pRootSignature;
  3602. }
  3603. void InputLayoutCb(const D3D12_INPUT_LAYOUT_DESC& InputLayout) override
  3604. {
  3605. PipelineStream.InputLayout = InputLayout;
  3606. }
  3607. void IBStripCutValueCb(
  3608. D3D12_INDEX_BUFFER_STRIP_CUT_VALUE IBStripCutValue) override
  3609. {
  3610. PipelineStream.IBStripCutValue = IBStripCutValue;
  3611. }
  3612. void PrimitiveTopologyTypeCb(
  3613. D3D12_PRIMITIVE_TOPOLOGY_TYPE PrimitiveTopologyType) override
  3614. {
  3615. PipelineStream.PrimitiveTopologyType = PrimitiveTopologyType;
  3616. }
  3617. void VSCb(const D3D12_SHADER_BYTECODE& VS) override
  3618. {
  3619. PipelineStream.VS = VS;
  3620. }
  3621. void GSCb(const D3D12_SHADER_BYTECODE& GS) override
  3622. {
  3623. PipelineStream.GS = GS;
  3624. }
  3625. void StreamOutputCb(const D3D12_STREAM_OUTPUT_DESC& StreamOutput) override
  3626. {
  3627. PipelineStream.StreamOutput = StreamOutput;
  3628. }
  3629. void HSCb(const D3D12_SHADER_BYTECODE& HS) override
  3630. {
  3631. PipelineStream.HS = HS;
  3632. }
  3633. void DSCb(const D3D12_SHADER_BYTECODE& DS) override
  3634. {
  3635. PipelineStream.DS = DS;
  3636. }
  3637. void PSCb(const D3D12_SHADER_BYTECODE& PS) override
  3638. {
  3639. PipelineStream.PS = PS;
  3640. }
  3641. void CSCb(const D3D12_SHADER_BYTECODE& CS) override
  3642. {
  3643. PipelineStream.CS = CS;
  3644. }
  3645. void BlendStateCb(const D3D12_BLEND_DESC& BlendState) override
  3646. {
  3647. PipelineStream.BlendState = CD3DX12_BLEND_DESC(BlendState);
  3648. }
  3649. void DepthStencilStateCb(
  3650. const D3D12_DEPTH_STENCIL_DESC& DepthStencilState) override
  3651. {
  3652. PipelineStream.DepthStencilState
  3653. = CD3DX12_DEPTH_STENCIL_DESC1(DepthStencilState);
  3654. SeenDSS = true;
  3655. }
  3656. void DepthStencilState1Cb(
  3657. const D3D12_DEPTH_STENCIL_DESC1& DepthStencilState) override
  3658. {
  3659. PipelineStream.DepthStencilState
  3660. = CD3DX12_DEPTH_STENCIL_DESC1(DepthStencilState);
  3661. SeenDSS = true;
  3662. }
  3663. void DSVFormatCb(DXGI_FORMAT DSVFormat) override
  3664. {
  3665. PipelineStream.DSVFormat = DSVFormat;
  3666. if (!SeenDSS && DSVFormat != DXGI_FORMAT_UNKNOWN)
  3667. {
  3668. // Re-enable depth for the default state.
  3669. static_cast<D3D12_DEPTH_STENCIL_DESC1&>(
  3670. PipelineStream.DepthStencilState)
  3671. .DepthEnable
  3672. = true;
  3673. }
  3674. }
  3675. void RasterizerStateCb(
  3676. const D3D12_RASTERIZER_DESC& RasterizerState) override
  3677. {
  3678. PipelineStream.RasterizerState
  3679. = CD3DX12_RASTERIZER_DESC(RasterizerState);
  3680. }
  3681. void RTVFormatsCb(const D3D12_RT_FORMAT_ARRAY& RTVFormats) override
  3682. {
  3683. PipelineStream.RTVFormats = RTVFormats;
  3684. }
  3685. void SampleDescCb(const DXGI_SAMPLE_DESC& SampleDesc) override
  3686. {
  3687. PipelineStream.SampleDesc = SampleDesc;
  3688. }
  3689. void SampleMaskCb(UINT SampleMask) override
  3690. {
  3691. PipelineStream.SampleMask = SampleMask;
  3692. }
  3693. void ViewInstancingCb(
  3694. const D3D12_VIEW_INSTANCING_DESC& ViewInstancingDesc) override
  3695. {
  3696. PipelineStream.ViewInstancingDesc
  3697. = CD3DX12_VIEW_INSTANCING_DESC(ViewInstancingDesc);
  3698. }
  3699. void CachedPSOCb(const D3D12_CACHED_PIPELINE_STATE& CachedPSO) override
  3700. {
  3701. PipelineStream.CachedPSO = CachedPSO;
  3702. }
  3703. private:
  3704. bool SeenDSS;
  3705. };
  3706. inline D3D12_PIPELINE_STATE_SUBOBJECT_TYPE D3DX12GetBaseSubobjectType(
  3707. D3D12_PIPELINE_STATE_SUBOBJECT_TYPE SubobjectType) noexcept
  3708. {
  3709. switch (SubobjectType)
  3710. {
  3711. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1:
  3712. return D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL;
  3713. default:
  3714. return SubobjectType;
  3715. }
  3716. }
  3717. inline HRESULT D3DX12ParsePipelineStream(
  3718. const D3D12_PIPELINE_STATE_STREAM_DESC& Desc,
  3719. ID3DX12PipelineParserCallbacks* pCallbacks)
  3720. {
  3721. if (pCallbacks == nullptr)
  3722. {
  3723. return E_INVALIDARG;
  3724. }
  3725. if (Desc.SizeInBytes == 0 || Desc.pPipelineStateSubobjectStream == nullptr)
  3726. {
  3727. pCallbacks->ErrorBadInputParameter(1); // first parameter issue
  3728. return E_INVALIDARG;
  3729. }
  3730. bool SubobjectSeen[D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MAX_VALID] = {};
  3731. for (SIZE_T CurOffset = 0, SizeOfSubobject = 0;
  3732. CurOffset < Desc.SizeInBytes;
  3733. CurOffset += SizeOfSubobject)
  3734. {
  3735. BYTE* pStream = static_cast<BYTE*>(Desc.pPipelineStateSubobjectStream)
  3736. + CurOffset;
  3737. auto SubobjectType
  3738. = *reinterpret_cast<D3D12_PIPELINE_STATE_SUBOBJECT_TYPE*>(pStream);
  3739. if (SubobjectType < 0
  3740. || SubobjectType >= D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MAX_VALID)
  3741. {
  3742. pCallbacks->ErrorUnknownSubobject(SubobjectType);
  3743. return E_INVALIDARG;
  3744. }
  3745. if (SubobjectSeen[D3DX12GetBaseSubobjectType(SubobjectType)])
  3746. {
  3747. pCallbacks->ErrorDuplicateSubobject(SubobjectType);
  3748. return E_INVALIDARG; // disallow subobject duplicates in a stream
  3749. }
  3750. SubobjectSeen[SubobjectType] = true;
  3751. switch (SubobjectType)
  3752. {
  3753. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE:
  3754. pCallbacks->RootSignatureCb(
  3755. *reinterpret_cast<
  3756. decltype(CD3DX12_PIPELINE_STATE_STREAM::pRootSignature)*>(
  3757. pStream));
  3758. SizeOfSubobject
  3759. = sizeof(CD3DX12_PIPELINE_STATE_STREAM::pRootSignature);
  3760. break;
  3761. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VS:
  3762. pCallbacks->VSCb(
  3763. *reinterpret_cast<decltype(CD3DX12_PIPELINE_STATE_STREAM::VS)*>(
  3764. pStream));
  3765. SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::VS);
  3766. break;
  3767. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS:
  3768. pCallbacks->PSCb(
  3769. *reinterpret_cast<decltype(CD3DX12_PIPELINE_STATE_STREAM::PS)*>(
  3770. pStream));
  3771. SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::PS);
  3772. break;
  3773. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DS:
  3774. pCallbacks->DSCb(
  3775. *reinterpret_cast<decltype(CD3DX12_PIPELINE_STATE_STREAM::DS)*>(
  3776. pStream));
  3777. SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::DS);
  3778. break;
  3779. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_HS:
  3780. pCallbacks->HSCb(
  3781. *reinterpret_cast<decltype(CD3DX12_PIPELINE_STATE_STREAM::HS)*>(
  3782. pStream));
  3783. SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::HS);
  3784. break;
  3785. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_GS:
  3786. pCallbacks->GSCb(
  3787. *reinterpret_cast<decltype(CD3DX12_PIPELINE_STATE_STREAM::GS)*>(
  3788. pStream));
  3789. SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::GS);
  3790. break;
  3791. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CS:
  3792. pCallbacks->CSCb(
  3793. *reinterpret_cast<decltype(CD3DX12_PIPELINE_STATE_STREAM::CS)*>(
  3794. pStream));
  3795. SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::CS);
  3796. break;
  3797. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_AS:
  3798. pCallbacks->ASCb(
  3799. *reinterpret_cast<
  3800. decltype(CD3DX12_PIPELINE_STATE_STREAM2::AS)*>(pStream));
  3801. SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM2::AS);
  3802. break;
  3803. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS:
  3804. pCallbacks->MSCb(
  3805. *reinterpret_cast<
  3806. decltype(CD3DX12_PIPELINE_STATE_STREAM2::MS)*>(pStream));
  3807. SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM2::MS);
  3808. break;
  3809. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_STREAM_OUTPUT:
  3810. pCallbacks->StreamOutputCb(
  3811. *reinterpret_cast<
  3812. decltype(CD3DX12_PIPELINE_STATE_STREAM::StreamOutput)*>(
  3813. pStream));
  3814. SizeOfSubobject
  3815. = sizeof(CD3DX12_PIPELINE_STATE_STREAM::StreamOutput);
  3816. break;
  3817. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_BLEND:
  3818. pCallbacks->BlendStateCb(
  3819. *reinterpret_cast<
  3820. decltype(CD3DX12_PIPELINE_STATE_STREAM::BlendState)*>(
  3821. pStream));
  3822. SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::BlendState);
  3823. break;
  3824. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_MASK:
  3825. pCallbacks->SampleMaskCb(
  3826. *reinterpret_cast<
  3827. decltype(CD3DX12_PIPELINE_STATE_STREAM::SampleMask)*>(
  3828. pStream));
  3829. SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::SampleMask);
  3830. break;
  3831. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RASTERIZER:
  3832. pCallbacks->RasterizerStateCb(
  3833. *reinterpret_cast<
  3834. decltype(CD3DX12_PIPELINE_STATE_STREAM::RasterizerState)*>(
  3835. pStream));
  3836. SizeOfSubobject
  3837. = sizeof(CD3DX12_PIPELINE_STATE_STREAM::RasterizerState);
  3838. break;
  3839. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL:
  3840. pCallbacks->DepthStencilStateCb(
  3841. *reinterpret_cast<CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL*>(
  3842. pStream));
  3843. SizeOfSubobject
  3844. = sizeof(CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL);
  3845. break;
  3846. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1:
  3847. pCallbacks->DepthStencilState1Cb(
  3848. *reinterpret_cast<decltype(CD3DX12_PIPELINE_STATE_STREAM::
  3849. DepthStencilState)*>(pStream));
  3850. SizeOfSubobject
  3851. = sizeof(CD3DX12_PIPELINE_STATE_STREAM::DepthStencilState);
  3852. break;
  3853. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_INPUT_LAYOUT:
  3854. pCallbacks->InputLayoutCb(
  3855. *reinterpret_cast<
  3856. decltype(CD3DX12_PIPELINE_STATE_STREAM::InputLayout)*>(
  3857. pStream));
  3858. SizeOfSubobject
  3859. = sizeof(CD3DX12_PIPELINE_STATE_STREAM::InputLayout);
  3860. break;
  3861. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_IB_STRIP_CUT_VALUE:
  3862. pCallbacks->IBStripCutValueCb(
  3863. *reinterpret_cast<
  3864. decltype(CD3DX12_PIPELINE_STATE_STREAM::IBStripCutValue)*>(
  3865. pStream));
  3866. SizeOfSubobject
  3867. = sizeof(CD3DX12_PIPELINE_STATE_STREAM::IBStripCutValue);
  3868. break;
  3869. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PRIMITIVE_TOPOLOGY:
  3870. pCallbacks->PrimitiveTopologyTypeCb(
  3871. *reinterpret_cast<decltype(CD3DX12_PIPELINE_STATE_STREAM::
  3872. PrimitiveTopologyType)*>(pStream));
  3873. SizeOfSubobject
  3874. = sizeof(CD3DX12_PIPELINE_STATE_STREAM::PrimitiveTopologyType);
  3875. break;
  3876. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RENDER_TARGET_FORMATS:
  3877. pCallbacks->RTVFormatsCb(
  3878. *reinterpret_cast<
  3879. decltype(CD3DX12_PIPELINE_STATE_STREAM::RTVFormats)*>(
  3880. pStream));
  3881. SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::RTVFormats);
  3882. break;
  3883. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT:
  3884. pCallbacks->DSVFormatCb(
  3885. *reinterpret_cast<
  3886. decltype(CD3DX12_PIPELINE_STATE_STREAM::DSVFormat)*>(
  3887. pStream));
  3888. SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::DSVFormat);
  3889. break;
  3890. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_DESC:
  3891. pCallbacks->SampleDescCb(
  3892. *reinterpret_cast<
  3893. decltype(CD3DX12_PIPELINE_STATE_STREAM::SampleDesc)*>(
  3894. pStream));
  3895. SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::SampleDesc);
  3896. break;
  3897. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_NODE_MASK:
  3898. pCallbacks->NodeMaskCb(
  3899. *reinterpret_cast<
  3900. decltype(CD3DX12_PIPELINE_STATE_STREAM::NodeMask)*>(
  3901. pStream));
  3902. SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::NodeMask);
  3903. break;
  3904. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CACHED_PSO:
  3905. pCallbacks->CachedPSOCb(
  3906. *reinterpret_cast<
  3907. decltype(CD3DX12_PIPELINE_STATE_STREAM::CachedPSO)*>(
  3908. pStream));
  3909. SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::CachedPSO);
  3910. break;
  3911. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_FLAGS:
  3912. pCallbacks->FlagsCb(
  3913. *reinterpret_cast<
  3914. decltype(CD3DX12_PIPELINE_STATE_STREAM::Flags)*>(pStream));
  3915. SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::Flags);
  3916. break;
  3917. case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VIEW_INSTANCING:
  3918. pCallbacks->ViewInstancingCb(
  3919. *reinterpret_cast<decltype(CD3DX12_PIPELINE_STATE_STREAM1::
  3920. ViewInstancingDesc)*>(pStream));
  3921. SizeOfSubobject
  3922. = sizeof(CD3DX12_PIPELINE_STATE_STREAM1::ViewInstancingDesc);
  3923. break;
  3924. default:
  3925. pCallbacks->ErrorUnknownSubobject(SubobjectType);
  3926. return E_INVALIDARG;
  3927. }
  3928. }
  3929. return S_OK;
  3930. }
  3931. //------------------------------------------------------------------------------------------------
  3932. inline bool operator==(
  3933. const D3D12_CLEAR_VALUE& a, const D3D12_CLEAR_VALUE& b) noexcept
  3934. {
  3935. if (a.Format != b.Format) return false;
  3936. if (a.Format == DXGI_FORMAT_D24_UNORM_S8_UINT
  3937. || a.Format == DXGI_FORMAT_D16_UNORM
  3938. || a.Format == DXGI_FORMAT_D32_FLOAT
  3939. || a.Format == DXGI_FORMAT_D32_FLOAT_S8X24_UINT)
  3940. {
  3941. return (a.DepthStencil.Depth == b.DepthStencil.Depth)
  3942. && (a.DepthStencil.Stencil == b.DepthStencil.Stencil);
  3943. }
  3944. else
  3945. {
  3946. return (a.Color[0] == b.Color[0]) && (a.Color[1] == b.Color[1])
  3947. && (a.Color[2] == b.Color[2]) && (a.Color[3] == b.Color[3]);
  3948. }
  3949. }
  3950. inline bool operator==(
  3951. const D3D12_RENDER_PASS_BEGINNING_ACCESS_CLEAR_PARAMETERS& a,
  3952. const D3D12_RENDER_PASS_BEGINNING_ACCESS_CLEAR_PARAMETERS& b) noexcept
  3953. {
  3954. return a.ClearValue == b.ClearValue;
  3955. }
  3956. inline bool operator==(
  3957. const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_PARAMETERS& a,
  3958. const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_PARAMETERS& b) noexcept
  3959. {
  3960. if (a.pSrcResource != b.pSrcResource) return false;
  3961. if (a.pDstResource != b.pDstResource) return false;
  3962. if (a.SubresourceCount != b.SubresourceCount) return false;
  3963. if (a.Format != b.Format) return false;
  3964. if (a.ResolveMode != b.ResolveMode) return false;
  3965. if (a.PreserveResolveSource != b.PreserveResolveSource) return false;
  3966. return true;
  3967. }
  3968. inline bool operator==(const D3D12_RENDER_PASS_BEGINNING_ACCESS& a,
  3969. const D3D12_RENDER_PASS_BEGINNING_ACCESS& b) noexcept
  3970. {
  3971. if (a.Type != b.Type) return false;
  3972. if (a.Type == D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR
  3973. && !(a.Clear == b.Clear))
  3974. return false;
  3975. return true;
  3976. }
  3977. inline bool operator==(const D3D12_RENDER_PASS_ENDING_ACCESS& a,
  3978. const D3D12_RENDER_PASS_ENDING_ACCESS& b) noexcept
  3979. {
  3980. if (a.Type != b.Type) return false;
  3981. if (a.Type == D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE
  3982. && !(a.Resolve == b.Resolve))
  3983. return false;
  3984. return true;
  3985. }
  3986. inline bool operator==(const D3D12_RENDER_PASS_RENDER_TARGET_DESC& a,
  3987. const D3D12_RENDER_PASS_RENDER_TARGET_DESC& b) noexcept
  3988. {
  3989. if (a.cpuDescriptor.ptr != b.cpuDescriptor.ptr) return false;
  3990. if (!(a.BeginningAccess == b.BeginningAccess)) return false;
  3991. if (!(a.EndingAccess == b.EndingAccess)) return false;
  3992. return true;
  3993. }
  3994. inline bool operator==(const D3D12_RENDER_PASS_DEPTH_STENCIL_DESC& a,
  3995. const D3D12_RENDER_PASS_DEPTH_STENCIL_DESC& b) noexcept
  3996. {
  3997. if (a.cpuDescriptor.ptr != b.cpuDescriptor.ptr) return false;
  3998. if (!(a.DepthBeginningAccess == b.DepthBeginningAccess)) return false;
  3999. if (!(a.StencilBeginningAccess == b.StencilBeginningAccess)) return false;
  4000. if (!(a.DepthEndingAccess == b.DepthEndingAccess)) return false;
  4001. if (!(a.StencilEndingAccess == b.StencilEndingAccess)) return false;
  4002. return true;
  4003. }
  4004. # ifndef D3DX12_NO_STATE_OBJECT_HELPERS
  4005. //================================================================================================
  4006. // D3DX12 State Object Creation Helpers
  4007. //
  4008. // Helper classes for creating new style state objects out of an arbitrary set
  4009. // of subobjects. Uses STL
  4010. //
  4011. // Start by instantiating CD3DX12_STATE_OBJECT_DESC (see it's public methods).
  4012. // One of its methods is CreateSubobject(), which has a comment showing a couple
  4013. // of options for defining subobjects using the helper classes for each
  4014. // subobject (CD3DX12_DXIL_LIBRARY_SUBOBJECT etc.). The subobject helpers each
  4015. // have methods specific to the subobject for configuring it's contents.
  4016. //
  4017. //================================================================================================
  4018. # include <list>
  4019. # include <memory>
  4020. # include <string>
  4021. # include <vector>
  4022. # ifndef D3DX12_USE_ATL
  4023. # include <wrl/client.h>
  4024. # define D3DX12_COM_PTR Microsoft::WRL::ComPtr
  4025. # define D3DX12_COM_PTR_GET(x) x.Get()
  4026. # define D3DX12_COM_PTR_ADDRESSOF(x) x.GetAddressOf()
  4027. # else
  4028. # include <atlbase.h>
  4029. # define D3DX12_COM_PTR ATL::CComPtr
  4030. # define D3DX12_COM_PTR_GET(x) x.p
  4031. # define D3DX12_COM_PTR_ADDRESSOF(x) &x.p
  4032. # endif
  4033. //------------------------------------------------------------------------------------------------
  4034. class CD3DX12_STATE_OBJECT_DESC
  4035. {
  4036. public:
  4037. CD3DX12_STATE_OBJECT_DESC() noexcept
  4038. {
  4039. Init(D3D12_STATE_OBJECT_TYPE_COLLECTION);
  4040. }
  4041. CD3DX12_STATE_OBJECT_DESC(D3D12_STATE_OBJECT_TYPE Type) noexcept
  4042. {
  4043. Init(Type);
  4044. }
  4045. void SetStateObjectType(D3D12_STATE_OBJECT_TYPE Type) noexcept
  4046. {
  4047. m_Desc.Type = Type;
  4048. }
  4049. operator const D3D12_STATE_OBJECT_DESC&()
  4050. {
  4051. // Do final preparation work
  4052. m_RepointedAssociations.clear();
  4053. m_SubobjectArray.clear();
  4054. m_SubobjectArray.reserve(m_Desc.NumSubobjects);
  4055. // Flatten subobjects into an array (each flattened subobject still has
  4056. // a member that's a pointer to it's desc that's not flattened)
  4057. for (auto Iter = m_SubobjectList.begin(); Iter != m_SubobjectList.end();
  4058. Iter++)
  4059. {
  4060. m_SubobjectArray.push_back(*Iter);
  4061. // Store new location in array so we can redirect pointers contained
  4062. // in subobjects
  4063. Iter->pSubobjectArrayLocation = &m_SubobjectArray.back();
  4064. }
  4065. // For subobjects with pointer fields, create a new copy of those
  4066. // subobject definitions with fixed pointers
  4067. for (UINT i = 0; i < m_Desc.NumSubobjects; i++)
  4068. {
  4069. if (m_SubobjectArray[i].Type
  4070. == D3D12_STATE_SUBOBJECT_TYPE_SUBOBJECT_TO_EXPORTS_ASSOCIATION)
  4071. {
  4072. auto pOriginalSubobjectAssociation = static_cast<
  4073. const D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION*>(
  4074. m_SubobjectArray[i].pDesc);
  4075. D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION Repointed
  4076. = *pOriginalSubobjectAssociation;
  4077. auto pWrapper = static_cast<const SUBOBJECT_WRAPPER*>(
  4078. pOriginalSubobjectAssociation->pSubobjectToAssociate);
  4079. Repointed.pSubobjectToAssociate
  4080. = pWrapper->pSubobjectArrayLocation;
  4081. m_RepointedAssociations.push_back(Repointed);
  4082. m_SubobjectArray[i].pDesc = &m_RepointedAssociations.back();
  4083. }
  4084. }
  4085. // Below: using ugly way to get pointer in case .data() is not defined
  4086. m_Desc.pSubobjects
  4087. = m_Desc.NumSubobjects ? &m_SubobjectArray[0] : nullptr;
  4088. return m_Desc;
  4089. }
  4090. operator const D3D12_STATE_OBJECT_DESC*()
  4091. {
  4092. // Cast calls the above final preparation work
  4093. return &static_cast<const D3D12_STATE_OBJECT_DESC&>(*this);
  4094. }
  4095. // CreateSubobject creates a sububject helper (e.g.
  4096. // CD3DX12_HIT_GROUP_SUBOBJECT) whose lifetime is owned by this class. e.g.
  4097. //
  4098. // CD3DX12_STATE_OBJECT_DESC
  4099. // Collection1(D3D12_STATE_OBJECT_TYPE_COLLECTION); auto Lib0 =
  4100. // Collection1.CreateSubobject<CD3DX12_DXIL_LIBRARY_SUBOBJECT>();
  4101. // Lib0->SetDXILLibrary(&pMyAppDxilLibs[0]);
  4102. // Lib0->DefineExport(L"rayGenShader0"); // in practice these export
  4103. // listings might be
  4104. // // data/engine driven
  4105. // etc.
  4106. //
  4107. // Alternatively, users can instantiate sububject helpers explicitly, such
  4108. // as via local variables instead, passing the state object desc that should
  4109. // point to it into the helper constructor (or call
  4110. // mySubobjectHelper.AddToStateObject(Collection1)). In this alternative
  4111. // scenario, the user must keep the subobject alive as long as the state
  4112. // object it is associated with is alive, else it's pointer references will
  4113. // be stale. e.g.
  4114. //
  4115. // CD3DX12_STATE_OBJECT_DESC
  4116. // RaytracingState2(D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE);
  4117. // CD3DX12_DXIL_LIBRARY_SUBOBJECT LibA(RaytracingState2);
  4118. // LibA.SetDXILLibrary(&pMyAppDxilLibs[4]); // not manually specifying
  4119. // exports
  4120. // // - meaning all exports in
  4121. // the libraries
  4122. // // are exported
  4123. // etc.
  4124. template<typename T> T* CreateSubobject()
  4125. {
  4126. T* pSubobject = new T(*this);
  4127. m_OwnedSubobjectHelpers.emplace_back(pSubobject);
  4128. return pSubobject;
  4129. }
  4130. private:
  4131. D3D12_STATE_SUBOBJECT* TrackSubobject(
  4132. D3D12_STATE_SUBOBJECT_TYPE Type, void* pDesc)
  4133. {
  4134. SUBOBJECT_WRAPPER Subobject;
  4135. Subobject.pSubobjectArrayLocation = nullptr;
  4136. Subobject.Type = Type;
  4137. Subobject.pDesc = pDesc;
  4138. m_SubobjectList.push_back(Subobject);
  4139. m_Desc.NumSubobjects++;
  4140. return &m_SubobjectList.back();
  4141. }
  4142. void Init(D3D12_STATE_OBJECT_TYPE Type) noexcept
  4143. {
  4144. SetStateObjectType(Type);
  4145. m_Desc.pSubobjects = nullptr;
  4146. m_Desc.NumSubobjects = 0;
  4147. m_SubobjectList.clear();
  4148. m_SubobjectArray.clear();
  4149. m_RepointedAssociations.clear();
  4150. }
  4151. typedef struct SUBOBJECT_WRAPPER : public D3D12_STATE_SUBOBJECT
  4152. {
  4153. D3D12_STATE_SUBOBJECT*
  4154. pSubobjectArrayLocation; // new location when flattened into array
  4155. // for repointing pointers in subobjects
  4156. } SUBOBJECT_WRAPPER;
  4157. D3D12_STATE_OBJECT_DESC m_Desc;
  4158. std::list<SUBOBJECT_WRAPPER>
  4159. m_SubobjectList; // Pointers to list nodes handed out so
  4160. // these can be edited live
  4161. std::vector<D3D12_STATE_SUBOBJECT>
  4162. m_SubobjectArray; // Built at the end, copying list contents
  4163. std::list<D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION>
  4164. m_RepointedAssociations; // subobject type that contains pointers to
  4165. // other subobjects, repointed to flattened
  4166. // array
  4167. class StringContainer
  4168. {
  4169. public:
  4170. LPCWSTR LocalCopy(LPCWSTR string, bool bSingleString = false)
  4171. {
  4172. if (string)
  4173. {
  4174. if (bSingleString)
  4175. {
  4176. m_Strings.clear();
  4177. m_Strings.push_back(string);
  4178. }
  4179. else
  4180. {
  4181. m_Strings.push_back(string);
  4182. }
  4183. return m_Strings.back().c_str();
  4184. }
  4185. else
  4186. {
  4187. return nullptr;
  4188. }
  4189. }
  4190. void clear() noexcept
  4191. {
  4192. m_Strings.clear();
  4193. }
  4194. private:
  4195. std::list<std::wstring> m_Strings;
  4196. };
  4197. class SUBOBJECT_HELPER_BASE
  4198. {
  4199. public:
  4200. SUBOBJECT_HELPER_BASE() noexcept
  4201. {
  4202. Init();
  4203. }
  4204. virtual ~SUBOBJECT_HELPER_BASE() = default;
  4205. virtual D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept = 0;
  4206. void AddToStateObject(CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
  4207. {
  4208. m_pSubobject = ContainingStateObject.TrackSubobject(Type(), Data());
  4209. }
  4210. protected:
  4211. virtual void* Data() noexcept = 0;
  4212. void Init() noexcept
  4213. {
  4214. m_pSubobject = nullptr;
  4215. }
  4216. D3D12_STATE_SUBOBJECT* m_pSubobject;
  4217. };
  4218. # if (__cplusplus >= 201103L)
  4219. std::list<std::unique_ptr<const SUBOBJECT_HELPER_BASE>>
  4220. m_OwnedSubobjectHelpers;
  4221. # else
  4222. class OWNED_HELPER
  4223. {
  4224. public:
  4225. OWNED_HELPER(const SUBOBJECT_HELPER_BASE* pHelper) noexcept
  4226. {
  4227. m_pHelper = pHelper;
  4228. }
  4229. ~OWNED_HELPER()
  4230. {
  4231. delete m_pHelper;
  4232. }
  4233. const SUBOBJECT_HELPER_BASE* m_pHelper;
  4234. };
  4235. std::list<OWNED_HELPER> m_OwnedSubobjectHelpers;
  4236. # endif
  4237. friend class CD3DX12_DXIL_LIBRARY_SUBOBJECT;
  4238. friend class CD3DX12_EXISTING_COLLECTION_SUBOBJECT;
  4239. friend class CD3DX12_SUBOBJECT_TO_EXPORTS_ASSOCIATION_SUBOBJECT;
  4240. friend class CD3DX12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION;
  4241. friend class CD3DX12_HIT_GROUP_SUBOBJECT;
  4242. friend class CD3DX12_RAYTRACING_SHADER_CONFIG_SUBOBJECT;
  4243. friend class CD3DX12_RAYTRACING_PIPELINE_CONFIG_SUBOBJECT;
  4244. friend class CD3DX12_RAYTRACING_PIPELINE_CONFIG1_SUBOBJECT;
  4245. friend class CD3DX12_GLOBAL_ROOT_SIGNATURE_SUBOBJECT;
  4246. friend class CD3DX12_LOCAL_ROOT_SIGNATURE_SUBOBJECT;
  4247. friend class CD3DX12_STATE_OBJECT_CONFIG_SUBOBJECT;
  4248. friend class CD3DX12_NODE_MASK_SUBOBJECT;
  4249. };
  4250. //------------------------------------------------------------------------------------------------
  4251. class CD3DX12_DXIL_LIBRARY_SUBOBJECT
  4252. : public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
  4253. {
  4254. public:
  4255. CD3DX12_DXIL_LIBRARY_SUBOBJECT() noexcept
  4256. {
  4257. Init();
  4258. }
  4259. CD3DX12_DXIL_LIBRARY_SUBOBJECT(
  4260. CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
  4261. {
  4262. Init();
  4263. AddToStateObject(ContainingStateObject);
  4264. }
  4265. void SetDXILLibrary(const D3D12_SHADER_BYTECODE* pCode) noexcept
  4266. {
  4267. static const D3D12_SHADER_BYTECODE Default = {};
  4268. m_Desc.DXILLibrary = pCode ? *pCode : Default;
  4269. }
  4270. void DefineExport(LPCWSTR Name,
  4271. LPCWSTR ExportToRename = nullptr,
  4272. D3D12_EXPORT_FLAGS Flags = D3D12_EXPORT_FLAG_NONE)
  4273. {
  4274. D3D12_EXPORT_DESC Export;
  4275. Export.Name = m_Strings.LocalCopy(Name);
  4276. Export.ExportToRename = m_Strings.LocalCopy(ExportToRename);
  4277. Export.Flags = Flags;
  4278. m_Exports.push_back(Export);
  4279. m_Desc.pExports = &m_Exports[0]; // using ugly way to get pointer in
  4280. // case .data() is not defined
  4281. m_Desc.NumExports = static_cast<UINT>(m_Exports.size());
  4282. }
  4283. template<size_t N> void DefineExports(LPCWSTR (&Exports)[N])
  4284. {
  4285. for (UINT i = 0; i < N; i++)
  4286. {
  4287. DefineExport(Exports[i]);
  4288. }
  4289. }
  4290. void DefineExports(const LPCWSTR* Exports, UINT N)
  4291. {
  4292. for (UINT i = 0; i < N; i++)
  4293. {
  4294. DefineExport(Exports[i]);
  4295. }
  4296. }
  4297. D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
  4298. {
  4299. return D3D12_STATE_SUBOBJECT_TYPE_DXIL_LIBRARY;
  4300. }
  4301. operator const D3D12_STATE_SUBOBJECT&() const noexcept
  4302. {
  4303. return *m_pSubobject;
  4304. }
  4305. operator const D3D12_DXIL_LIBRARY_DESC&() const noexcept
  4306. {
  4307. return m_Desc;
  4308. }
  4309. private:
  4310. void Init() noexcept
  4311. {
  4312. SUBOBJECT_HELPER_BASE::Init();
  4313. m_Desc = {};
  4314. m_Strings.clear();
  4315. m_Exports.clear();
  4316. }
  4317. void* Data() noexcept override
  4318. {
  4319. return &m_Desc;
  4320. }
  4321. D3D12_DXIL_LIBRARY_DESC m_Desc;
  4322. CD3DX12_STATE_OBJECT_DESC::StringContainer m_Strings;
  4323. std::vector<D3D12_EXPORT_DESC> m_Exports;
  4324. };
  4325. //------------------------------------------------------------------------------------------------
  4326. class CD3DX12_EXISTING_COLLECTION_SUBOBJECT
  4327. : public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
  4328. {
  4329. public:
  4330. CD3DX12_EXISTING_COLLECTION_SUBOBJECT() noexcept
  4331. {
  4332. Init();
  4333. }
  4334. CD3DX12_EXISTING_COLLECTION_SUBOBJECT(
  4335. CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
  4336. {
  4337. Init();
  4338. AddToStateObject(ContainingStateObject);
  4339. }
  4340. void SetExistingCollection(ID3D12StateObject* pExistingCollection) noexcept
  4341. {
  4342. m_Desc.pExistingCollection = pExistingCollection;
  4343. m_CollectionRef = pExistingCollection;
  4344. }
  4345. void DefineExport(LPCWSTR Name,
  4346. LPCWSTR ExportToRename = nullptr,
  4347. D3D12_EXPORT_FLAGS Flags = D3D12_EXPORT_FLAG_NONE)
  4348. {
  4349. D3D12_EXPORT_DESC Export;
  4350. Export.Name = m_Strings.LocalCopy(Name);
  4351. Export.ExportToRename = m_Strings.LocalCopy(ExportToRename);
  4352. Export.Flags = Flags;
  4353. m_Exports.push_back(Export);
  4354. m_Desc.pExports = &m_Exports[0]; // using ugly way to get pointer in
  4355. // case .data() is not defined
  4356. m_Desc.NumExports = static_cast<UINT>(m_Exports.size());
  4357. }
  4358. template<size_t N> void DefineExports(LPCWSTR (&Exports)[N])
  4359. {
  4360. for (UINT i = 0; i < N; i++)
  4361. {
  4362. DefineExport(Exports[i]);
  4363. }
  4364. }
  4365. void DefineExports(const LPCWSTR* Exports, UINT N)
  4366. {
  4367. for (UINT i = 0; i < N; i++)
  4368. {
  4369. DefineExport(Exports[i]);
  4370. }
  4371. }
  4372. D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
  4373. {
  4374. return D3D12_STATE_SUBOBJECT_TYPE_EXISTING_COLLECTION;
  4375. }
  4376. operator const D3D12_STATE_SUBOBJECT&() const noexcept
  4377. {
  4378. return *m_pSubobject;
  4379. }
  4380. operator const D3D12_EXISTING_COLLECTION_DESC&() const noexcept
  4381. {
  4382. return m_Desc;
  4383. }
  4384. private:
  4385. void Init() noexcept
  4386. {
  4387. SUBOBJECT_HELPER_BASE::Init();
  4388. m_Desc = {};
  4389. m_CollectionRef = nullptr;
  4390. m_Strings.clear();
  4391. m_Exports.clear();
  4392. }
  4393. void* Data() noexcept override
  4394. {
  4395. return &m_Desc;
  4396. }
  4397. D3D12_EXISTING_COLLECTION_DESC m_Desc;
  4398. D3DX12_COM_PTR<ID3D12StateObject> m_CollectionRef;
  4399. CD3DX12_STATE_OBJECT_DESC::StringContainer m_Strings;
  4400. std::vector<D3D12_EXPORT_DESC> m_Exports;
  4401. };
  4402. //------------------------------------------------------------------------------------------------
  4403. class CD3DX12_SUBOBJECT_TO_EXPORTS_ASSOCIATION_SUBOBJECT
  4404. : public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
  4405. {
  4406. public:
  4407. CD3DX12_SUBOBJECT_TO_EXPORTS_ASSOCIATION_SUBOBJECT() noexcept
  4408. {
  4409. Init();
  4410. }
  4411. CD3DX12_SUBOBJECT_TO_EXPORTS_ASSOCIATION_SUBOBJECT(
  4412. CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
  4413. {
  4414. Init();
  4415. AddToStateObject(ContainingStateObject);
  4416. }
  4417. void SetSubobjectToAssociate(
  4418. const D3D12_STATE_SUBOBJECT& SubobjectToAssociate) noexcept
  4419. {
  4420. m_Desc.pSubobjectToAssociate = &SubobjectToAssociate;
  4421. }
  4422. void AddExport(LPCWSTR Export)
  4423. {
  4424. m_Desc.NumExports++;
  4425. m_Exports.push_back(m_Strings.LocalCopy(Export));
  4426. m_Desc.pExports = &m_Exports[0]; // using ugly way to get pointer in
  4427. // case .data() is not defined
  4428. }
  4429. template<size_t N> void AddExports(LPCWSTR (&Exports)[N])
  4430. {
  4431. for (UINT i = 0; i < N; i++)
  4432. {
  4433. AddExport(Exports[i]);
  4434. }
  4435. }
  4436. void AddExports(const LPCWSTR* Exports, UINT N)
  4437. {
  4438. for (UINT i = 0; i < N; i++)
  4439. {
  4440. AddExport(Exports[i]);
  4441. }
  4442. }
  4443. D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
  4444. {
  4445. return D3D12_STATE_SUBOBJECT_TYPE_SUBOBJECT_TO_EXPORTS_ASSOCIATION;
  4446. }
  4447. operator const D3D12_STATE_SUBOBJECT&() const noexcept
  4448. {
  4449. return *m_pSubobject;
  4450. }
  4451. operator const D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION&() const noexcept
  4452. {
  4453. return m_Desc;
  4454. }
  4455. private:
  4456. void Init() noexcept
  4457. {
  4458. SUBOBJECT_HELPER_BASE::Init();
  4459. m_Desc = {};
  4460. m_Strings.clear();
  4461. m_Exports.clear();
  4462. }
  4463. void* Data() noexcept override
  4464. {
  4465. return &m_Desc;
  4466. }
  4467. D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION m_Desc;
  4468. CD3DX12_STATE_OBJECT_DESC::StringContainer m_Strings;
  4469. std::vector<LPCWSTR> m_Exports;
  4470. };
  4471. //------------------------------------------------------------------------------------------------
  4472. class CD3DX12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION
  4473. : public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
  4474. {
  4475. public:
  4476. CD3DX12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION() noexcept
  4477. {
  4478. Init();
  4479. }
  4480. CD3DX12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION(
  4481. CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
  4482. {
  4483. Init();
  4484. AddToStateObject(ContainingStateObject);
  4485. }
  4486. void SetSubobjectNameToAssociate(LPCWSTR SubobjectToAssociate)
  4487. {
  4488. m_Desc.SubobjectToAssociate
  4489. = m_SubobjectName.LocalCopy(SubobjectToAssociate, true);
  4490. }
  4491. void AddExport(LPCWSTR Export)
  4492. {
  4493. m_Desc.NumExports++;
  4494. m_Exports.push_back(m_Strings.LocalCopy(Export));
  4495. m_Desc.pExports = &m_Exports[0]; // using ugly way to get pointer in
  4496. // case .data() is not defined
  4497. }
  4498. template<size_t N> void AddExports(LPCWSTR (&Exports)[N])
  4499. {
  4500. for (UINT i = 0; i < N; i++)
  4501. {
  4502. AddExport(Exports[i]);
  4503. }
  4504. }
  4505. void AddExports(const LPCWSTR* Exports, UINT N)
  4506. {
  4507. for (UINT i = 0; i < N; i++)
  4508. {
  4509. AddExport(Exports[i]);
  4510. }
  4511. }
  4512. D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
  4513. {
  4514. return D3D12_STATE_SUBOBJECT_TYPE_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION;
  4515. }
  4516. operator const D3D12_STATE_SUBOBJECT&() const noexcept
  4517. {
  4518. return *m_pSubobject;
  4519. }
  4520. operator const D3D12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION&() const noexcept
  4521. {
  4522. return m_Desc;
  4523. }
  4524. private:
  4525. void Init() noexcept
  4526. {
  4527. SUBOBJECT_HELPER_BASE::Init();
  4528. m_Desc = {};
  4529. m_Strings.clear();
  4530. m_SubobjectName.clear();
  4531. m_Exports.clear();
  4532. }
  4533. void* Data() noexcept override
  4534. {
  4535. return &m_Desc;
  4536. }
  4537. D3D12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION m_Desc;
  4538. CD3DX12_STATE_OBJECT_DESC::StringContainer m_Strings;
  4539. CD3DX12_STATE_OBJECT_DESC::StringContainer m_SubobjectName;
  4540. std::vector<LPCWSTR> m_Exports;
  4541. };
  4542. //------------------------------------------------------------------------------------------------
  4543. class CD3DX12_HIT_GROUP_SUBOBJECT
  4544. : public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
  4545. {
  4546. public:
  4547. CD3DX12_HIT_GROUP_SUBOBJECT() noexcept
  4548. {
  4549. Init();
  4550. }
  4551. CD3DX12_HIT_GROUP_SUBOBJECT(
  4552. CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
  4553. {
  4554. Init();
  4555. AddToStateObject(ContainingStateObject);
  4556. }
  4557. void SetHitGroupExport(LPCWSTR exportName)
  4558. {
  4559. m_Desc.HitGroupExport = m_Strings[0].LocalCopy(exportName, true);
  4560. }
  4561. void SetHitGroupType(D3D12_HIT_GROUP_TYPE Type) noexcept
  4562. {
  4563. m_Desc.Type = Type;
  4564. }
  4565. void SetAnyHitShaderImport(LPCWSTR importName)
  4566. {
  4567. m_Desc.AnyHitShaderImport = m_Strings[1].LocalCopy(importName, true);
  4568. }
  4569. void SetClosestHitShaderImport(LPCWSTR importName)
  4570. {
  4571. m_Desc.ClosestHitShaderImport
  4572. = m_Strings[2].LocalCopy(importName, true);
  4573. }
  4574. void SetIntersectionShaderImport(LPCWSTR importName)
  4575. {
  4576. m_Desc.IntersectionShaderImport
  4577. = m_Strings[3].LocalCopy(importName, true);
  4578. }
  4579. D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
  4580. {
  4581. return D3D12_STATE_SUBOBJECT_TYPE_HIT_GROUP;
  4582. }
  4583. operator const D3D12_STATE_SUBOBJECT&() const noexcept
  4584. {
  4585. return *m_pSubobject;
  4586. }
  4587. operator const D3D12_HIT_GROUP_DESC&() const noexcept
  4588. {
  4589. return m_Desc;
  4590. }
  4591. private:
  4592. void Init() noexcept
  4593. {
  4594. SUBOBJECT_HELPER_BASE::Init();
  4595. m_Desc = {};
  4596. for (UINT i = 0; i < m_NumStrings; i++)
  4597. {
  4598. m_Strings[i].clear();
  4599. }
  4600. }
  4601. void* Data() noexcept override
  4602. {
  4603. return &m_Desc;
  4604. }
  4605. D3D12_HIT_GROUP_DESC m_Desc;
  4606. static const UINT m_NumStrings = 4;
  4607. CD3DX12_STATE_OBJECT_DESC::StringContainer
  4608. m_Strings[m_NumStrings]; // one string for every entrypoint name
  4609. };
  4610. //------------------------------------------------------------------------------------------------
  4611. class CD3DX12_RAYTRACING_SHADER_CONFIG_SUBOBJECT
  4612. : public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
  4613. {
  4614. public:
  4615. CD3DX12_RAYTRACING_SHADER_CONFIG_SUBOBJECT() noexcept
  4616. {
  4617. Init();
  4618. }
  4619. CD3DX12_RAYTRACING_SHADER_CONFIG_SUBOBJECT(
  4620. CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
  4621. {
  4622. Init();
  4623. AddToStateObject(ContainingStateObject);
  4624. }
  4625. void Config(
  4626. UINT MaxPayloadSizeInBytes, UINT MaxAttributeSizeInBytes) noexcept
  4627. {
  4628. m_Desc.MaxPayloadSizeInBytes = MaxPayloadSizeInBytes;
  4629. m_Desc.MaxAttributeSizeInBytes = MaxAttributeSizeInBytes;
  4630. }
  4631. D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
  4632. {
  4633. return D3D12_STATE_SUBOBJECT_TYPE_RAYTRACING_SHADER_CONFIG;
  4634. }
  4635. operator const D3D12_STATE_SUBOBJECT&() const noexcept
  4636. {
  4637. return *m_pSubobject;
  4638. }
  4639. operator const D3D12_RAYTRACING_SHADER_CONFIG&() const noexcept
  4640. {
  4641. return m_Desc;
  4642. }
  4643. private:
  4644. void Init() noexcept
  4645. {
  4646. SUBOBJECT_HELPER_BASE::Init();
  4647. m_Desc = {};
  4648. }
  4649. void* Data() noexcept override
  4650. {
  4651. return &m_Desc;
  4652. }
  4653. D3D12_RAYTRACING_SHADER_CONFIG m_Desc;
  4654. };
  4655. //------------------------------------------------------------------------------------------------
  4656. class CD3DX12_RAYTRACING_PIPELINE_CONFIG_SUBOBJECT
  4657. : public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
  4658. {
  4659. public:
  4660. CD3DX12_RAYTRACING_PIPELINE_CONFIG_SUBOBJECT() noexcept
  4661. {
  4662. Init();
  4663. }
  4664. CD3DX12_RAYTRACING_PIPELINE_CONFIG_SUBOBJECT(
  4665. CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
  4666. {
  4667. Init();
  4668. AddToStateObject(ContainingStateObject);
  4669. }
  4670. void Config(UINT MaxTraceRecursionDepth) noexcept
  4671. {
  4672. m_Desc.MaxTraceRecursionDepth = MaxTraceRecursionDepth;
  4673. }
  4674. D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
  4675. {
  4676. return D3D12_STATE_SUBOBJECT_TYPE_RAYTRACING_PIPELINE_CONFIG;
  4677. }
  4678. operator const D3D12_STATE_SUBOBJECT&() const noexcept
  4679. {
  4680. return *m_pSubobject;
  4681. }
  4682. operator const D3D12_RAYTRACING_PIPELINE_CONFIG&() const noexcept
  4683. {
  4684. return m_Desc;
  4685. }
  4686. private:
  4687. void Init() noexcept
  4688. {
  4689. SUBOBJECT_HELPER_BASE::Init();
  4690. m_Desc = {};
  4691. }
  4692. void* Data() noexcept override
  4693. {
  4694. return &m_Desc;
  4695. }
  4696. D3D12_RAYTRACING_PIPELINE_CONFIG m_Desc;
  4697. };
  4698. //------------------------------------------------------------------------------------------------
  4699. class CD3DX12_RAYTRACING_PIPELINE_CONFIG1_SUBOBJECT
  4700. : public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
  4701. {
  4702. public:
  4703. CD3DX12_RAYTRACING_PIPELINE_CONFIG1_SUBOBJECT() noexcept
  4704. {
  4705. Init();
  4706. }
  4707. CD3DX12_RAYTRACING_PIPELINE_CONFIG1_SUBOBJECT(
  4708. CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
  4709. {
  4710. Init();
  4711. AddToStateObject(ContainingStateObject);
  4712. }
  4713. void Config(UINT MaxTraceRecursionDepth,
  4714. D3D12_RAYTRACING_PIPELINE_FLAGS Flags) noexcept
  4715. {
  4716. m_Desc.MaxTraceRecursionDepth = MaxTraceRecursionDepth;
  4717. m_Desc.Flags = Flags;
  4718. }
  4719. D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
  4720. {
  4721. return D3D12_STATE_SUBOBJECT_TYPE_RAYTRACING_PIPELINE_CONFIG1;
  4722. }
  4723. operator const D3D12_STATE_SUBOBJECT&() const noexcept
  4724. {
  4725. return *m_pSubobject;
  4726. }
  4727. operator const D3D12_RAYTRACING_PIPELINE_CONFIG1&() const noexcept
  4728. {
  4729. return m_Desc;
  4730. }
  4731. private:
  4732. void Init() noexcept
  4733. {
  4734. SUBOBJECT_HELPER_BASE::Init();
  4735. m_Desc = {};
  4736. }
  4737. void* Data() noexcept override
  4738. {
  4739. return &m_Desc;
  4740. }
  4741. D3D12_RAYTRACING_PIPELINE_CONFIG1 m_Desc;
  4742. };
  4743. //------------------------------------------------------------------------------------------------
  4744. class CD3DX12_GLOBAL_ROOT_SIGNATURE_SUBOBJECT
  4745. : public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
  4746. {
  4747. public:
  4748. CD3DX12_GLOBAL_ROOT_SIGNATURE_SUBOBJECT() noexcept
  4749. {
  4750. Init();
  4751. }
  4752. CD3DX12_GLOBAL_ROOT_SIGNATURE_SUBOBJECT(
  4753. CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
  4754. {
  4755. Init();
  4756. AddToStateObject(ContainingStateObject);
  4757. }
  4758. void SetRootSignature(ID3D12RootSignature* pRootSig) noexcept
  4759. {
  4760. m_pRootSig = pRootSig;
  4761. }
  4762. D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
  4763. {
  4764. return D3D12_STATE_SUBOBJECT_TYPE_GLOBAL_ROOT_SIGNATURE;
  4765. }
  4766. operator const D3D12_STATE_SUBOBJECT&() const noexcept
  4767. {
  4768. return *m_pSubobject;
  4769. }
  4770. operator ID3D12RootSignature*() const noexcept
  4771. {
  4772. return D3DX12_COM_PTR_GET(m_pRootSig);
  4773. }
  4774. private:
  4775. void Init() noexcept
  4776. {
  4777. SUBOBJECT_HELPER_BASE::Init();
  4778. m_pRootSig = nullptr;
  4779. }
  4780. void* Data() noexcept override
  4781. {
  4782. return D3DX12_COM_PTR_ADDRESSOF(m_pRootSig);
  4783. }
  4784. D3DX12_COM_PTR<ID3D12RootSignature> m_pRootSig;
  4785. };
  4786. //------------------------------------------------------------------------------------------------
  4787. class CD3DX12_LOCAL_ROOT_SIGNATURE_SUBOBJECT
  4788. : public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
  4789. {
  4790. public:
  4791. CD3DX12_LOCAL_ROOT_SIGNATURE_SUBOBJECT() noexcept
  4792. {
  4793. Init();
  4794. }
  4795. CD3DX12_LOCAL_ROOT_SIGNATURE_SUBOBJECT(
  4796. CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
  4797. {
  4798. Init();
  4799. AddToStateObject(ContainingStateObject);
  4800. }
  4801. void SetRootSignature(ID3D12RootSignature* pRootSig) noexcept
  4802. {
  4803. m_pRootSig = pRootSig;
  4804. }
  4805. D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
  4806. {
  4807. return D3D12_STATE_SUBOBJECT_TYPE_LOCAL_ROOT_SIGNATURE;
  4808. }
  4809. operator const D3D12_STATE_SUBOBJECT&() const noexcept
  4810. {
  4811. return *m_pSubobject;
  4812. }
  4813. operator ID3D12RootSignature*() const noexcept
  4814. {
  4815. return D3DX12_COM_PTR_GET(m_pRootSig);
  4816. }
  4817. private:
  4818. void Init() noexcept
  4819. {
  4820. SUBOBJECT_HELPER_BASE::Init();
  4821. m_pRootSig = nullptr;
  4822. }
  4823. void* Data() noexcept override
  4824. {
  4825. return D3DX12_COM_PTR_ADDRESSOF(m_pRootSig);
  4826. }
  4827. D3DX12_COM_PTR<ID3D12RootSignature> m_pRootSig;
  4828. };
  4829. //------------------------------------------------------------------------------------------------
  4830. class CD3DX12_STATE_OBJECT_CONFIG_SUBOBJECT
  4831. : public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
  4832. {
  4833. public:
  4834. CD3DX12_STATE_OBJECT_CONFIG_SUBOBJECT() noexcept
  4835. {
  4836. Init();
  4837. }
  4838. CD3DX12_STATE_OBJECT_CONFIG_SUBOBJECT(
  4839. CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
  4840. {
  4841. Init();
  4842. AddToStateObject(ContainingStateObject);
  4843. }
  4844. void SetFlags(D3D12_STATE_OBJECT_FLAGS Flags) noexcept
  4845. {
  4846. m_Desc.Flags = Flags;
  4847. }
  4848. D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
  4849. {
  4850. return D3D12_STATE_SUBOBJECT_TYPE_STATE_OBJECT_CONFIG;
  4851. }
  4852. operator const D3D12_STATE_SUBOBJECT&() const noexcept
  4853. {
  4854. return *m_pSubobject;
  4855. }
  4856. operator const D3D12_STATE_OBJECT_CONFIG&() const noexcept
  4857. {
  4858. return m_Desc;
  4859. }
  4860. private:
  4861. void Init() noexcept
  4862. {
  4863. SUBOBJECT_HELPER_BASE::Init();
  4864. m_Desc = {};
  4865. }
  4866. void* Data() noexcept override
  4867. {
  4868. return &m_Desc;
  4869. }
  4870. D3D12_STATE_OBJECT_CONFIG m_Desc;
  4871. };
  4872. //------------------------------------------------------------------------------------------------
  4873. class CD3DX12_NODE_MASK_SUBOBJECT
  4874. : public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
  4875. {
  4876. public:
  4877. CD3DX12_NODE_MASK_SUBOBJECT() noexcept
  4878. {
  4879. Init();
  4880. }
  4881. CD3DX12_NODE_MASK_SUBOBJECT(
  4882. CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
  4883. {
  4884. Init();
  4885. AddToStateObject(ContainingStateObject);
  4886. }
  4887. void SetNodeMask(UINT NodeMask) noexcept
  4888. {
  4889. m_Desc.NodeMask = NodeMask;
  4890. }
  4891. D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
  4892. {
  4893. return D3D12_STATE_SUBOBJECT_TYPE_NODE_MASK;
  4894. }
  4895. operator const D3D12_STATE_SUBOBJECT&() const noexcept
  4896. {
  4897. return *m_pSubobject;
  4898. }
  4899. operator const D3D12_NODE_MASK&() const noexcept
  4900. {
  4901. return m_Desc;
  4902. }
  4903. private:
  4904. void Init() noexcept
  4905. {
  4906. SUBOBJECT_HELPER_BASE::Init();
  4907. m_Desc = {};
  4908. }
  4909. void* Data() noexcept override
  4910. {
  4911. return &m_Desc;
  4912. }
  4913. D3D12_NODE_MASK m_Desc;
  4914. };
  4915. # undef D3DX12_COM_PTR
  4916. # undef D3DX12_COM_PTR_GET
  4917. # undef D3DX12_COM_PTR_ADDRESSOF
  4918. # endif // #ifndef D3DX12_NO_STATE_OBJECT_HELPERS
  4919. #endif // defined( __cplusplus )
  4920. #endif //__D3DX12_H__