d3dx12.h 171 KB

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