d3dx12.h 138 KB

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