d3dx12_root_signature.h 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  1. //*********************************************************
  2. //
  3. // Copyright (c) Microsoft Corporation.
  4. // Licensed under the MIT License (MIT).
  5. //
  6. //*********************************************************
  7. #pragma once
  8. #ifndef __cplusplus
  9. #error D3DX12 requires C++
  10. #endif
  11. #include "d3d12.h"
  12. #include "d3dx12_default.h"
  13. //------------------------------------------------------------------------------------------------
  14. struct CD3DX12_DESCRIPTOR_RANGE : public D3D12_DESCRIPTOR_RANGE
  15. {
  16. CD3DX12_DESCRIPTOR_RANGE() = default;
  17. explicit CD3DX12_DESCRIPTOR_RANGE(const D3D12_DESCRIPTOR_RANGE &o) noexcept :
  18. D3D12_DESCRIPTOR_RANGE(o)
  19. {}
  20. CD3DX12_DESCRIPTOR_RANGE(
  21. D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
  22. UINT numDescriptors,
  23. UINT baseShaderRegister,
  24. UINT registerSpace = 0,
  25. UINT offsetInDescriptorsFromTableStart =
  26. D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) noexcept
  27. {
  28. Init(rangeType, numDescriptors, baseShaderRegister, registerSpace, offsetInDescriptorsFromTableStart);
  29. }
  30. inline void Init(
  31. D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
  32. UINT numDescriptors,
  33. UINT baseShaderRegister,
  34. UINT registerSpace = 0,
  35. UINT offsetInDescriptorsFromTableStart =
  36. D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) noexcept
  37. {
  38. Init(*this, rangeType, numDescriptors, baseShaderRegister, registerSpace, offsetInDescriptorsFromTableStart);
  39. }
  40. static inline void Init(
  41. _Out_ D3D12_DESCRIPTOR_RANGE &range,
  42. D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
  43. UINT numDescriptors,
  44. UINT baseShaderRegister,
  45. UINT registerSpace = 0,
  46. UINT offsetInDescriptorsFromTableStart =
  47. D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) noexcept
  48. {
  49. range.RangeType = rangeType;
  50. range.NumDescriptors = numDescriptors;
  51. range.BaseShaderRegister = baseShaderRegister;
  52. range.RegisterSpace = registerSpace;
  53. range.OffsetInDescriptorsFromTableStart = offsetInDescriptorsFromTableStart;
  54. }
  55. };
  56. //------------------------------------------------------------------------------------------------
  57. struct CD3DX12_ROOT_DESCRIPTOR_TABLE : public D3D12_ROOT_DESCRIPTOR_TABLE
  58. {
  59. CD3DX12_ROOT_DESCRIPTOR_TABLE() = default;
  60. explicit CD3DX12_ROOT_DESCRIPTOR_TABLE(const D3D12_ROOT_DESCRIPTOR_TABLE &o) noexcept :
  61. D3D12_ROOT_DESCRIPTOR_TABLE(o)
  62. {}
  63. CD3DX12_ROOT_DESCRIPTOR_TABLE(
  64. UINT numDescriptorRanges,
  65. _In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges) noexcept
  66. {
  67. Init(numDescriptorRanges, _pDescriptorRanges);
  68. }
  69. inline void Init(
  70. UINT numDescriptorRanges,
  71. _In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges) noexcept
  72. {
  73. Init(*this, numDescriptorRanges, _pDescriptorRanges);
  74. }
  75. static inline void Init(
  76. _Out_ D3D12_ROOT_DESCRIPTOR_TABLE &rootDescriptorTable,
  77. UINT numDescriptorRanges,
  78. _In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges) noexcept
  79. {
  80. rootDescriptorTable.NumDescriptorRanges = numDescriptorRanges;
  81. rootDescriptorTable.pDescriptorRanges = _pDescriptorRanges;
  82. }
  83. };
  84. //------------------------------------------------------------------------------------------------
  85. struct CD3DX12_ROOT_CONSTANTS : public D3D12_ROOT_CONSTANTS
  86. {
  87. CD3DX12_ROOT_CONSTANTS() = default;
  88. explicit CD3DX12_ROOT_CONSTANTS(const D3D12_ROOT_CONSTANTS &o) noexcept :
  89. D3D12_ROOT_CONSTANTS(o)
  90. {}
  91. CD3DX12_ROOT_CONSTANTS(
  92. UINT num32BitValues,
  93. UINT shaderRegister,
  94. UINT registerSpace = 0) noexcept
  95. {
  96. Init(num32BitValues, shaderRegister, registerSpace);
  97. }
  98. inline void Init(
  99. UINT num32BitValues,
  100. UINT shaderRegister,
  101. UINT registerSpace = 0) noexcept
  102. {
  103. Init(*this, num32BitValues, shaderRegister, registerSpace);
  104. }
  105. static inline void Init(
  106. _Out_ D3D12_ROOT_CONSTANTS &rootConstants,
  107. UINT num32BitValues,
  108. UINT shaderRegister,
  109. UINT registerSpace = 0) noexcept
  110. {
  111. rootConstants.Num32BitValues = num32BitValues;
  112. rootConstants.ShaderRegister = shaderRegister;
  113. rootConstants.RegisterSpace = registerSpace;
  114. }
  115. };
  116. //------------------------------------------------------------------------------------------------
  117. struct CD3DX12_ROOT_DESCRIPTOR : public D3D12_ROOT_DESCRIPTOR
  118. {
  119. CD3DX12_ROOT_DESCRIPTOR() = default;
  120. explicit CD3DX12_ROOT_DESCRIPTOR(const D3D12_ROOT_DESCRIPTOR &o) noexcept :
  121. D3D12_ROOT_DESCRIPTOR(o)
  122. {}
  123. CD3DX12_ROOT_DESCRIPTOR(
  124. UINT shaderRegister,
  125. UINT registerSpace = 0) noexcept
  126. {
  127. Init(shaderRegister, registerSpace);
  128. }
  129. inline void Init(
  130. UINT shaderRegister,
  131. UINT registerSpace = 0) noexcept
  132. {
  133. Init(*this, shaderRegister, registerSpace);
  134. }
  135. static inline void Init(_Out_ D3D12_ROOT_DESCRIPTOR &table, UINT shaderRegister, UINT registerSpace = 0) noexcept
  136. {
  137. table.ShaderRegister = shaderRegister;
  138. table.RegisterSpace = registerSpace;
  139. }
  140. };
  141. //------------------------------------------------------------------------------------------------
  142. struct CD3DX12_ROOT_PARAMETER : public D3D12_ROOT_PARAMETER
  143. {
  144. CD3DX12_ROOT_PARAMETER() = default;
  145. explicit CD3DX12_ROOT_PARAMETER(const D3D12_ROOT_PARAMETER &o) noexcept :
  146. D3D12_ROOT_PARAMETER(o)
  147. {}
  148. static inline void InitAsDescriptorTable(
  149. _Out_ D3D12_ROOT_PARAMETER &rootParam,
  150. UINT numDescriptorRanges,
  151. _In_reads_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* pDescriptorRanges,
  152. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  153. {
  154. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
  155. rootParam.ShaderVisibility = visibility;
  156. CD3DX12_ROOT_DESCRIPTOR_TABLE::Init(rootParam.DescriptorTable, numDescriptorRanges, pDescriptorRanges);
  157. }
  158. static inline void InitAsConstants(
  159. _Out_ D3D12_ROOT_PARAMETER &rootParam,
  160. UINT num32BitValues,
  161. UINT shaderRegister,
  162. UINT registerSpace = 0,
  163. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  164. {
  165. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
  166. rootParam.ShaderVisibility = visibility;
  167. CD3DX12_ROOT_CONSTANTS::Init(rootParam.Constants, num32BitValues, shaderRegister, registerSpace);
  168. }
  169. static inline void InitAsConstantBufferView(
  170. _Out_ D3D12_ROOT_PARAMETER &rootParam,
  171. UINT shaderRegister,
  172. UINT registerSpace = 0,
  173. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  174. {
  175. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
  176. rootParam.ShaderVisibility = visibility;
  177. CD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister, registerSpace);
  178. }
  179. static inline void InitAsShaderResourceView(
  180. _Out_ D3D12_ROOT_PARAMETER &rootParam,
  181. UINT shaderRegister,
  182. UINT registerSpace = 0,
  183. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  184. {
  185. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;
  186. rootParam.ShaderVisibility = visibility;
  187. CD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister, registerSpace);
  188. }
  189. static inline void InitAsUnorderedAccessView(
  190. _Out_ D3D12_ROOT_PARAMETER &rootParam,
  191. UINT shaderRegister,
  192. UINT registerSpace = 0,
  193. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  194. {
  195. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV;
  196. rootParam.ShaderVisibility = visibility;
  197. CD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister, registerSpace);
  198. }
  199. inline void InitAsDescriptorTable(
  200. UINT numDescriptorRanges,
  201. _In_reads_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* pDescriptorRanges,
  202. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  203. {
  204. InitAsDescriptorTable(*this, numDescriptorRanges, pDescriptorRanges, visibility);
  205. }
  206. inline void InitAsConstants(
  207. UINT num32BitValues,
  208. UINT shaderRegister,
  209. UINT registerSpace = 0,
  210. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  211. {
  212. InitAsConstants(*this, num32BitValues, shaderRegister, registerSpace, visibility);
  213. }
  214. inline void InitAsConstantBufferView(
  215. UINT shaderRegister,
  216. UINT registerSpace = 0,
  217. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  218. {
  219. InitAsConstantBufferView(*this, shaderRegister, registerSpace, visibility);
  220. }
  221. inline void InitAsShaderResourceView(
  222. UINT shaderRegister,
  223. UINT registerSpace = 0,
  224. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  225. {
  226. InitAsShaderResourceView(*this, shaderRegister, registerSpace, visibility);
  227. }
  228. inline void InitAsUnorderedAccessView(
  229. UINT shaderRegister,
  230. UINT registerSpace = 0,
  231. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  232. {
  233. InitAsUnorderedAccessView(*this, shaderRegister, registerSpace, visibility);
  234. }
  235. };
  236. //------------------------------------------------------------------------------------------------
  237. struct CD3DX12_STATIC_SAMPLER_DESC : public D3D12_STATIC_SAMPLER_DESC
  238. {
  239. CD3DX12_STATIC_SAMPLER_DESC() = default;
  240. explicit CD3DX12_STATIC_SAMPLER_DESC(const D3D12_STATIC_SAMPLER_DESC &o) noexcept :
  241. D3D12_STATIC_SAMPLER_DESC(o)
  242. {}
  243. CD3DX12_STATIC_SAMPLER_DESC(
  244. UINT shaderRegister,
  245. D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
  246. D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  247. D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  248. D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  249. FLOAT mipLODBias = 0,
  250. UINT maxAnisotropy = 16,
  251. D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
  252. D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
  253. FLOAT minLOD = 0.f,
  254. FLOAT maxLOD = D3D12_FLOAT32_MAX,
  255. D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
  256. UINT registerSpace = 0) noexcept
  257. {
  258. Init(
  259. shaderRegister,
  260. filter,
  261. addressU,
  262. addressV,
  263. addressW,
  264. mipLODBias,
  265. maxAnisotropy,
  266. comparisonFunc,
  267. borderColor,
  268. minLOD,
  269. maxLOD,
  270. shaderVisibility,
  271. registerSpace);
  272. }
  273. static inline void Init(
  274. _Out_ D3D12_STATIC_SAMPLER_DESC &samplerDesc,
  275. UINT shaderRegister,
  276. D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
  277. D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  278. D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  279. D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  280. FLOAT mipLODBias = 0,
  281. UINT maxAnisotropy = 16,
  282. D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
  283. D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
  284. FLOAT minLOD = 0.f,
  285. FLOAT maxLOD = D3D12_FLOAT32_MAX,
  286. D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
  287. UINT registerSpace = 0) noexcept
  288. {
  289. samplerDesc.ShaderRegister = shaderRegister;
  290. samplerDesc.Filter = filter;
  291. samplerDesc.AddressU = addressU;
  292. samplerDesc.AddressV = addressV;
  293. samplerDesc.AddressW = addressW;
  294. samplerDesc.MipLODBias = mipLODBias;
  295. samplerDesc.MaxAnisotropy = maxAnisotropy;
  296. samplerDesc.ComparisonFunc = comparisonFunc;
  297. samplerDesc.BorderColor = borderColor;
  298. samplerDesc.MinLOD = minLOD;
  299. samplerDesc.MaxLOD = maxLOD;
  300. samplerDesc.ShaderVisibility = shaderVisibility;
  301. samplerDesc.RegisterSpace = registerSpace;
  302. }
  303. inline void Init(
  304. UINT shaderRegister,
  305. D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
  306. D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  307. D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  308. D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  309. FLOAT mipLODBias = 0,
  310. UINT maxAnisotropy = 16,
  311. D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
  312. D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
  313. FLOAT minLOD = 0.f,
  314. FLOAT maxLOD = D3D12_FLOAT32_MAX,
  315. D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
  316. UINT registerSpace = 0) noexcept
  317. {
  318. Init(
  319. *this,
  320. shaderRegister,
  321. filter,
  322. addressU,
  323. addressV,
  324. addressW,
  325. mipLODBias,
  326. maxAnisotropy,
  327. comparisonFunc,
  328. borderColor,
  329. minLOD,
  330. maxLOD,
  331. shaderVisibility,
  332. registerSpace);
  333. }
  334. };
  335. //------------------------------------------------------------------------------------------------
  336. #if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609)
  337. struct CD3DX12_STATIC_SAMPLER_DESC1 : public D3D12_STATIC_SAMPLER_DESC1
  338. {
  339. CD3DX12_STATIC_SAMPLER_DESC1() = default;
  340. explicit CD3DX12_STATIC_SAMPLER_DESC1(const D3D12_STATIC_SAMPLER_DESC &o) noexcept
  341. {
  342. memcpy(this, &o, sizeof(D3D12_STATIC_SAMPLER_DESC));
  343. Flags = D3D12_SAMPLER_FLAGS::D3D12_SAMPLER_FLAG_NONE;
  344. }
  345. explicit CD3DX12_STATIC_SAMPLER_DESC1(const D3D12_STATIC_SAMPLER_DESC1 & o) noexcept :
  346. D3D12_STATIC_SAMPLER_DESC1(o)
  347. {}
  348. CD3DX12_STATIC_SAMPLER_DESC1(
  349. UINT shaderRegister,
  350. D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
  351. D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  352. D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  353. D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  354. FLOAT mipLODBias = 0,
  355. UINT maxAnisotropy = 16,
  356. D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
  357. D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
  358. FLOAT minLOD = 0.f,
  359. FLOAT maxLOD = D3D12_FLOAT32_MAX,
  360. D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
  361. UINT registerSpace = 0,
  362. D3D12_SAMPLER_FLAGS flags = D3D12_SAMPLER_FLAGS::D3D12_SAMPLER_FLAG_NONE) noexcept
  363. {
  364. Init(
  365. shaderRegister,
  366. filter,
  367. addressU,
  368. addressV,
  369. addressW,
  370. mipLODBias,
  371. maxAnisotropy,
  372. comparisonFunc,
  373. borderColor,
  374. minLOD,
  375. maxLOD,
  376. shaderVisibility,
  377. registerSpace,
  378. flags);
  379. }
  380. static inline void Init(
  381. _Out_ D3D12_STATIC_SAMPLER_DESC1 &samplerDesc,
  382. UINT shaderRegister,
  383. D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
  384. D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  385. D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  386. D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  387. FLOAT mipLODBias = 0,
  388. UINT maxAnisotropy = 16,
  389. D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
  390. D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
  391. FLOAT minLOD = 0.f,
  392. FLOAT maxLOD = D3D12_FLOAT32_MAX,
  393. D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
  394. UINT registerSpace = 0,
  395. D3D12_SAMPLER_FLAGS flags = D3D12_SAMPLER_FLAGS::D3D12_SAMPLER_FLAG_NONE) noexcept
  396. {
  397. samplerDesc.ShaderRegister = shaderRegister;
  398. samplerDesc.Filter = filter;
  399. samplerDesc.AddressU = addressU;
  400. samplerDesc.AddressV = addressV;
  401. samplerDesc.AddressW = addressW;
  402. samplerDesc.MipLODBias = mipLODBias;
  403. samplerDesc.MaxAnisotropy = maxAnisotropy;
  404. samplerDesc.ComparisonFunc = comparisonFunc;
  405. samplerDesc.BorderColor = borderColor;
  406. samplerDesc.MinLOD = minLOD;
  407. samplerDesc.MaxLOD = maxLOD;
  408. samplerDesc.ShaderVisibility = shaderVisibility;
  409. samplerDesc.RegisterSpace = registerSpace;
  410. samplerDesc.Flags = flags;
  411. }
  412. inline void Init(
  413. UINT shaderRegister,
  414. D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
  415. D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  416. D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  417. D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
  418. FLOAT mipLODBias = 0,
  419. UINT maxAnisotropy = 16,
  420. D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
  421. D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
  422. FLOAT minLOD = 0.f,
  423. FLOAT maxLOD = D3D12_FLOAT32_MAX,
  424. D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
  425. UINT registerSpace = 0,
  426. D3D12_SAMPLER_FLAGS flags = D3D12_SAMPLER_FLAGS::D3D12_SAMPLER_FLAG_NONE) noexcept
  427. {
  428. Init(
  429. *this,
  430. shaderRegister,
  431. filter,
  432. addressU,
  433. addressV,
  434. addressW,
  435. mipLODBias,
  436. maxAnisotropy,
  437. comparisonFunc,
  438. borderColor,
  439. minLOD,
  440. maxLOD,
  441. shaderVisibility,
  442. registerSpace,
  443. flags);
  444. }
  445. };
  446. #endif // D3D12_SDK_VERSION >= 609
  447. //------------------------------------------------------------------------------------------------
  448. struct CD3DX12_ROOT_SIGNATURE_DESC : public D3D12_ROOT_SIGNATURE_DESC
  449. {
  450. CD3DX12_ROOT_SIGNATURE_DESC() = default;
  451. explicit CD3DX12_ROOT_SIGNATURE_DESC(const D3D12_ROOT_SIGNATURE_DESC &o) noexcept :
  452. D3D12_ROOT_SIGNATURE_DESC(o)
  453. {}
  454. CD3DX12_ROOT_SIGNATURE_DESC(
  455. UINT numParameters,
  456. _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
  457. UINT numStaticSamplers = 0,
  458. _In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
  459. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
  460. {
  461. Init(numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
  462. }
  463. CD3DX12_ROOT_SIGNATURE_DESC(CD3DX12_DEFAULT) noexcept
  464. {
  465. Init(0, nullptr, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  466. }
  467. inline void Init(
  468. UINT numParameters,
  469. _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
  470. UINT numStaticSamplers = 0,
  471. _In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
  472. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
  473. {
  474. Init(*this, numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
  475. }
  476. static inline void Init(
  477. _Out_ D3D12_ROOT_SIGNATURE_DESC &desc,
  478. UINT numParameters,
  479. _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
  480. UINT numStaticSamplers = 0,
  481. _In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
  482. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
  483. {
  484. desc.NumParameters = numParameters;
  485. desc.pParameters = _pParameters;
  486. desc.NumStaticSamplers = numStaticSamplers;
  487. desc.pStaticSamplers = _pStaticSamplers;
  488. desc.Flags = flags;
  489. }
  490. };
  491. //------------------------------------------------------------------------------------------------
  492. struct CD3DX12_DESCRIPTOR_RANGE1 : public D3D12_DESCRIPTOR_RANGE1
  493. {
  494. CD3DX12_DESCRIPTOR_RANGE1() = default;
  495. explicit CD3DX12_DESCRIPTOR_RANGE1(const D3D12_DESCRIPTOR_RANGE1 &o) noexcept :
  496. D3D12_DESCRIPTOR_RANGE1(o)
  497. {}
  498. CD3DX12_DESCRIPTOR_RANGE1(
  499. D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
  500. UINT numDescriptors,
  501. UINT baseShaderRegister,
  502. UINT registerSpace = 0,
  503. D3D12_DESCRIPTOR_RANGE_FLAGS flags = D3D12_DESCRIPTOR_RANGE_FLAG_NONE,
  504. UINT offsetInDescriptorsFromTableStart =
  505. D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) noexcept
  506. {
  507. Init(rangeType, numDescriptors, baseShaderRegister, registerSpace, flags, offsetInDescriptorsFromTableStart);
  508. }
  509. inline void Init(
  510. D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
  511. UINT numDescriptors,
  512. UINT baseShaderRegister,
  513. UINT registerSpace = 0,
  514. D3D12_DESCRIPTOR_RANGE_FLAGS flags = D3D12_DESCRIPTOR_RANGE_FLAG_NONE,
  515. UINT offsetInDescriptorsFromTableStart =
  516. D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) noexcept
  517. {
  518. Init(*this, rangeType, numDescriptors, baseShaderRegister, registerSpace, flags, offsetInDescriptorsFromTableStart);
  519. }
  520. static inline void Init(
  521. _Out_ D3D12_DESCRIPTOR_RANGE1 &range,
  522. D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
  523. UINT numDescriptors,
  524. UINT baseShaderRegister,
  525. UINT registerSpace = 0,
  526. D3D12_DESCRIPTOR_RANGE_FLAGS flags = D3D12_DESCRIPTOR_RANGE_FLAG_NONE,
  527. UINT offsetInDescriptorsFromTableStart =
  528. D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) noexcept
  529. {
  530. range.RangeType = rangeType;
  531. range.NumDescriptors = numDescriptors;
  532. range.BaseShaderRegister = baseShaderRegister;
  533. range.RegisterSpace = registerSpace;
  534. range.Flags = flags;
  535. range.OffsetInDescriptorsFromTableStart = offsetInDescriptorsFromTableStart;
  536. }
  537. };
  538. //------------------------------------------------------------------------------------------------
  539. struct CD3DX12_ROOT_DESCRIPTOR_TABLE1 : public D3D12_ROOT_DESCRIPTOR_TABLE1
  540. {
  541. CD3DX12_ROOT_DESCRIPTOR_TABLE1() = default;
  542. explicit CD3DX12_ROOT_DESCRIPTOR_TABLE1(const D3D12_ROOT_DESCRIPTOR_TABLE1 &o) noexcept :
  543. D3D12_ROOT_DESCRIPTOR_TABLE1(o)
  544. {}
  545. CD3DX12_ROOT_DESCRIPTOR_TABLE1(
  546. UINT numDescriptorRanges,
  547. _In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE1* _pDescriptorRanges) noexcept
  548. {
  549. Init(numDescriptorRanges, _pDescriptorRanges);
  550. }
  551. inline void Init(
  552. UINT numDescriptorRanges,
  553. _In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE1* _pDescriptorRanges) noexcept
  554. {
  555. Init(*this, numDescriptorRanges, _pDescriptorRanges);
  556. }
  557. static inline void Init(
  558. _Out_ D3D12_ROOT_DESCRIPTOR_TABLE1 &rootDescriptorTable,
  559. UINT numDescriptorRanges,
  560. _In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE1* _pDescriptorRanges) noexcept
  561. {
  562. rootDescriptorTable.NumDescriptorRanges = numDescriptorRanges;
  563. rootDescriptorTable.pDescriptorRanges = _pDescriptorRanges;
  564. }
  565. };
  566. //------------------------------------------------------------------------------------------------
  567. struct CD3DX12_ROOT_DESCRIPTOR1 : public D3D12_ROOT_DESCRIPTOR1
  568. {
  569. CD3DX12_ROOT_DESCRIPTOR1() = default;
  570. explicit CD3DX12_ROOT_DESCRIPTOR1(const D3D12_ROOT_DESCRIPTOR1 &o) noexcept :
  571. D3D12_ROOT_DESCRIPTOR1(o)
  572. {}
  573. CD3DX12_ROOT_DESCRIPTOR1(
  574. UINT shaderRegister,
  575. UINT registerSpace = 0,
  576. D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE) noexcept
  577. {
  578. Init(shaderRegister, registerSpace, flags);
  579. }
  580. inline void Init(
  581. UINT shaderRegister,
  582. UINT registerSpace = 0,
  583. D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE) noexcept
  584. {
  585. Init(*this, shaderRegister, registerSpace, flags);
  586. }
  587. static inline void Init(
  588. _Out_ D3D12_ROOT_DESCRIPTOR1 &table,
  589. UINT shaderRegister,
  590. UINT registerSpace = 0,
  591. D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE) noexcept
  592. {
  593. table.ShaderRegister = shaderRegister;
  594. table.RegisterSpace = registerSpace;
  595. table.Flags = flags;
  596. }
  597. };
  598. //------------------------------------------------------------------------------------------------
  599. struct CD3DX12_ROOT_PARAMETER1 : public D3D12_ROOT_PARAMETER1
  600. {
  601. CD3DX12_ROOT_PARAMETER1() = default;
  602. explicit CD3DX12_ROOT_PARAMETER1(const D3D12_ROOT_PARAMETER1 &o) noexcept :
  603. D3D12_ROOT_PARAMETER1(o)
  604. {}
  605. static inline void InitAsDescriptorTable(
  606. _Out_ D3D12_ROOT_PARAMETER1 &rootParam,
  607. UINT numDescriptorRanges,
  608. _In_reads_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE1* pDescriptorRanges,
  609. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  610. {
  611. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
  612. rootParam.ShaderVisibility = visibility;
  613. CD3DX12_ROOT_DESCRIPTOR_TABLE1::Init(rootParam.DescriptorTable, numDescriptorRanges, pDescriptorRanges);
  614. }
  615. static inline void InitAsConstants(
  616. _Out_ D3D12_ROOT_PARAMETER1 &rootParam,
  617. UINT num32BitValues,
  618. UINT shaderRegister,
  619. UINT registerSpace = 0,
  620. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  621. {
  622. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
  623. rootParam.ShaderVisibility = visibility;
  624. CD3DX12_ROOT_CONSTANTS::Init(rootParam.Constants, num32BitValues, shaderRegister, registerSpace);
  625. }
  626. static inline void InitAsConstantBufferView(
  627. _Out_ D3D12_ROOT_PARAMETER1 &rootParam,
  628. UINT shaderRegister,
  629. UINT registerSpace = 0,
  630. D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
  631. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  632. {
  633. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
  634. rootParam.ShaderVisibility = visibility;
  635. CD3DX12_ROOT_DESCRIPTOR1::Init(rootParam.Descriptor, shaderRegister, registerSpace, flags);
  636. }
  637. static inline void InitAsShaderResourceView(
  638. _Out_ D3D12_ROOT_PARAMETER1 &rootParam,
  639. UINT shaderRegister,
  640. UINT registerSpace = 0,
  641. D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
  642. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  643. {
  644. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;
  645. rootParam.ShaderVisibility = visibility;
  646. CD3DX12_ROOT_DESCRIPTOR1::Init(rootParam.Descriptor, shaderRegister, registerSpace, flags);
  647. }
  648. static inline void InitAsUnorderedAccessView(
  649. _Out_ D3D12_ROOT_PARAMETER1 &rootParam,
  650. UINT shaderRegister,
  651. UINT registerSpace = 0,
  652. D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
  653. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  654. {
  655. rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV;
  656. rootParam.ShaderVisibility = visibility;
  657. CD3DX12_ROOT_DESCRIPTOR1::Init(rootParam.Descriptor, shaderRegister, registerSpace, flags);
  658. }
  659. inline void InitAsDescriptorTable(
  660. UINT numDescriptorRanges,
  661. _In_reads_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE1* pDescriptorRanges,
  662. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  663. {
  664. InitAsDescriptorTable(*this, numDescriptorRanges, pDescriptorRanges, visibility);
  665. }
  666. inline void InitAsConstants(
  667. UINT num32BitValues,
  668. UINT shaderRegister,
  669. UINT registerSpace = 0,
  670. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  671. {
  672. InitAsConstants(*this, num32BitValues, shaderRegister, registerSpace, visibility);
  673. }
  674. inline void InitAsConstantBufferView(
  675. UINT shaderRegister,
  676. UINT registerSpace = 0,
  677. D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
  678. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  679. {
  680. InitAsConstantBufferView(*this, shaderRegister, registerSpace, flags, visibility);
  681. }
  682. inline void InitAsShaderResourceView(
  683. UINT shaderRegister,
  684. UINT registerSpace = 0,
  685. D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
  686. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  687. {
  688. InitAsShaderResourceView(*this, shaderRegister, registerSpace, flags, visibility);
  689. }
  690. inline void InitAsUnorderedAccessView(
  691. UINT shaderRegister,
  692. UINT registerSpace = 0,
  693. D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
  694. D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
  695. {
  696. InitAsUnorderedAccessView(*this, shaderRegister, registerSpace, flags, visibility);
  697. }
  698. };
  699. //------------------------------------------------------------------------------------------------
  700. struct CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC : public D3D12_VERSIONED_ROOT_SIGNATURE_DESC
  701. {
  702. CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC() = default;
  703. explicit CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(const D3D12_VERSIONED_ROOT_SIGNATURE_DESC &o) noexcept :
  704. D3D12_VERSIONED_ROOT_SIGNATURE_DESC(o)
  705. {}
  706. explicit CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(const D3D12_ROOT_SIGNATURE_DESC &o) noexcept
  707. {
  708. Version = D3D_ROOT_SIGNATURE_VERSION_1_0;
  709. Desc_1_0 = o;
  710. }
  711. explicit CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(const D3D12_ROOT_SIGNATURE_DESC1 &o) noexcept
  712. {
  713. Version = D3D_ROOT_SIGNATURE_VERSION_1_1;
  714. Desc_1_1 = o;
  715. }
  716. #if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609)
  717. explicit CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(const D3D12_ROOT_SIGNATURE_DESC2& o) noexcept
  718. {
  719. Version = D3D_ROOT_SIGNATURE_VERSION_1_2;
  720. Desc_1_2 = o;
  721. }
  722. #endif
  723. CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(
  724. UINT numParameters,
  725. _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
  726. UINT numStaticSamplers = 0,
  727. _In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
  728. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
  729. {
  730. Init_1_0(numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
  731. }
  732. CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(
  733. UINT numParameters,
  734. _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER1* _pParameters,
  735. UINT numStaticSamplers = 0,
  736. _In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
  737. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
  738. {
  739. Init_1_1(numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
  740. }
  741. CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(CD3DX12_DEFAULT) noexcept
  742. {
  743. Init_1_1(0, nullptr, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  744. }
  745. inline void Init_1_0(
  746. UINT numParameters,
  747. _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
  748. UINT numStaticSamplers = 0,
  749. _In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
  750. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
  751. {
  752. Init_1_0(*this, numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
  753. }
  754. static inline void Init_1_0(
  755. _Out_ D3D12_VERSIONED_ROOT_SIGNATURE_DESC &desc,
  756. UINT numParameters,
  757. _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
  758. UINT numStaticSamplers = 0,
  759. _In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
  760. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
  761. {
  762. desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_0;
  763. desc.Desc_1_0.NumParameters = numParameters;
  764. desc.Desc_1_0.pParameters = _pParameters;
  765. desc.Desc_1_0.NumStaticSamplers = numStaticSamplers;
  766. desc.Desc_1_0.pStaticSamplers = _pStaticSamplers;
  767. desc.Desc_1_0.Flags = flags;
  768. }
  769. inline void Init_1_1(
  770. UINT numParameters,
  771. _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER1* _pParameters,
  772. UINT numStaticSamplers = 0,
  773. _In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
  774. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
  775. {
  776. Init_1_1(*this, numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
  777. }
  778. static inline void Init_1_1(
  779. _Out_ D3D12_VERSIONED_ROOT_SIGNATURE_DESC &desc,
  780. UINT numParameters,
  781. _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER1* _pParameters,
  782. UINT numStaticSamplers = 0,
  783. _In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
  784. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
  785. {
  786. desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_1;
  787. desc.Desc_1_1.NumParameters = numParameters;
  788. desc.Desc_1_1.pParameters = _pParameters;
  789. desc.Desc_1_1.NumStaticSamplers = numStaticSamplers;
  790. desc.Desc_1_1.pStaticSamplers = _pStaticSamplers;
  791. desc.Desc_1_1.Flags = flags;
  792. }
  793. #if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609)
  794. static inline void Init_1_2(
  795. _Out_ D3D12_VERSIONED_ROOT_SIGNATURE_DESC& desc,
  796. UINT numParameters,
  797. _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER1* _pParameters,
  798. UINT numStaticSamplers = 0,
  799. _In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC1* _pStaticSamplers = nullptr,
  800. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
  801. {
  802. desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_2;
  803. desc.Desc_1_2.NumParameters = numParameters;
  804. desc.Desc_1_2.pParameters = _pParameters;
  805. desc.Desc_1_2.NumStaticSamplers = numStaticSamplers;
  806. desc.Desc_1_2.pStaticSamplers = _pStaticSamplers;
  807. desc.Desc_1_2.Flags = flags;
  808. }
  809. #endif
  810. };
  811. //------------------------------------------------------------------------------------------------
  812. struct CD3DX12_CPU_DESCRIPTOR_HANDLE : public D3D12_CPU_DESCRIPTOR_HANDLE
  813. {
  814. CD3DX12_CPU_DESCRIPTOR_HANDLE() = default;
  815. explicit CD3DX12_CPU_DESCRIPTOR_HANDLE(const D3D12_CPU_DESCRIPTOR_HANDLE &o) noexcept :
  816. D3D12_CPU_DESCRIPTOR_HANDLE(o)
  817. {}
  818. CD3DX12_CPU_DESCRIPTOR_HANDLE(CD3DX12_DEFAULT) noexcept { ptr = 0; }
  819. CD3DX12_CPU_DESCRIPTOR_HANDLE(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &other, INT offsetScaledByIncrementSize) noexcept
  820. {
  821. InitOffsetted(other, offsetScaledByIncrementSize);
  822. }
  823. CD3DX12_CPU_DESCRIPTOR_HANDLE(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &other, INT offsetInDescriptors, UINT descriptorIncrementSize) noexcept
  824. {
  825. InitOffsetted(other, offsetInDescriptors, descriptorIncrementSize);
  826. }
  827. CD3DX12_CPU_DESCRIPTOR_HANDLE& Offset(INT offsetInDescriptors, UINT descriptorIncrementSize) noexcept
  828. {
  829. ptr = SIZE_T(INT64(ptr) + INT64(offsetInDescriptors) * INT64(descriptorIncrementSize));
  830. return *this;
  831. }
  832. CD3DX12_CPU_DESCRIPTOR_HANDLE& Offset(INT offsetScaledByIncrementSize) noexcept
  833. {
  834. ptr = SIZE_T(INT64(ptr) + INT64(offsetScaledByIncrementSize));
  835. return *this;
  836. }
  837. bool operator==(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE& other) const noexcept
  838. {
  839. return (ptr == other.ptr);
  840. }
  841. bool operator!=(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE& other) const noexcept
  842. {
  843. return (ptr != other.ptr);
  844. }
  845. CD3DX12_CPU_DESCRIPTOR_HANDLE &operator=(const D3D12_CPU_DESCRIPTOR_HANDLE &other) noexcept
  846. {
  847. ptr = other.ptr;
  848. return *this;
  849. }
  850. inline void InitOffsetted(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize) noexcept
  851. {
  852. InitOffsetted(*this, base, offsetScaledByIncrementSize);
  853. }
  854. inline void InitOffsetted(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize) noexcept
  855. {
  856. InitOffsetted(*this, base, offsetInDescriptors, descriptorIncrementSize);
  857. }
  858. static inline void InitOffsetted(_Out_ D3D12_CPU_DESCRIPTOR_HANDLE &handle, _In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize) noexcept
  859. {
  860. handle.ptr = SIZE_T(INT64(base.ptr) + INT64(offsetScaledByIncrementSize));
  861. }
  862. static inline void InitOffsetted(_Out_ D3D12_CPU_DESCRIPTOR_HANDLE &handle, _In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize) noexcept
  863. {
  864. handle.ptr = SIZE_T(INT64(base.ptr) + INT64(offsetInDescriptors) * INT64(descriptorIncrementSize));
  865. }
  866. };
  867. //------------------------------------------------------------------------------------------------
  868. struct CD3DX12_GPU_DESCRIPTOR_HANDLE : public D3D12_GPU_DESCRIPTOR_HANDLE
  869. {
  870. CD3DX12_GPU_DESCRIPTOR_HANDLE() = default;
  871. explicit CD3DX12_GPU_DESCRIPTOR_HANDLE(const D3D12_GPU_DESCRIPTOR_HANDLE &o) noexcept :
  872. D3D12_GPU_DESCRIPTOR_HANDLE(o)
  873. {}
  874. CD3DX12_GPU_DESCRIPTOR_HANDLE(CD3DX12_DEFAULT) noexcept { ptr = 0; }
  875. CD3DX12_GPU_DESCRIPTOR_HANDLE(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &other, INT offsetScaledByIncrementSize) noexcept
  876. {
  877. InitOffsetted(other, offsetScaledByIncrementSize);
  878. }
  879. CD3DX12_GPU_DESCRIPTOR_HANDLE(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &other, INT offsetInDescriptors, UINT descriptorIncrementSize) noexcept
  880. {
  881. InitOffsetted(other, offsetInDescriptors, descriptorIncrementSize);
  882. }
  883. CD3DX12_GPU_DESCRIPTOR_HANDLE& Offset(INT offsetInDescriptors, UINT descriptorIncrementSize) noexcept
  884. {
  885. ptr = UINT64(INT64(ptr) + INT64(offsetInDescriptors) * INT64(descriptorIncrementSize));
  886. return *this;
  887. }
  888. CD3DX12_GPU_DESCRIPTOR_HANDLE& Offset(INT offsetScaledByIncrementSize) noexcept
  889. {
  890. ptr = UINT64(INT64(ptr) + INT64(offsetScaledByIncrementSize));
  891. return *this;
  892. }
  893. inline bool operator==(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE& other) const noexcept
  894. {
  895. return (ptr == other.ptr);
  896. }
  897. inline bool operator!=(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE& other) const noexcept
  898. {
  899. return (ptr != other.ptr);
  900. }
  901. CD3DX12_GPU_DESCRIPTOR_HANDLE &operator=(const D3D12_GPU_DESCRIPTOR_HANDLE &other) noexcept
  902. {
  903. ptr = other.ptr;
  904. return *this;
  905. }
  906. inline void InitOffsetted(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize) noexcept
  907. {
  908. InitOffsetted(*this, base, offsetScaledByIncrementSize);
  909. }
  910. inline void InitOffsetted(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize) noexcept
  911. {
  912. InitOffsetted(*this, base, offsetInDescriptors, descriptorIncrementSize);
  913. }
  914. static inline void InitOffsetted(_Out_ D3D12_GPU_DESCRIPTOR_HANDLE &handle, _In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize) noexcept
  915. {
  916. handle.ptr = UINT64(INT64(base.ptr) + INT64(offsetScaledByIncrementSize));
  917. }
  918. static inline void InitOffsetted(_Out_ D3D12_GPU_DESCRIPTOR_HANDLE &handle, _In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize) noexcept
  919. {
  920. handle.ptr = UINT64(INT64(base.ptr) + INT64(offsetInDescriptors) * INT64(descriptorIncrementSize));
  921. }
  922. };
  923. //------------------------------------------------------------------------------------------------
  924. // D3D12 exports a new method for serializing root signatures in the Windows 10 Anniversary Update.
  925. // To help enable root signature 1.1 features when they are available and not require maintaining
  926. // two code paths for building root signatures, this helper method reconstructs a 1.0 signature when
  927. // 1.1 is not supported.
  928. inline HRESULT D3DX12SerializeVersionedRootSignature(
  929. _In_ HMODULE pLibD3D12,
  930. _In_ const D3D12_VERSIONED_ROOT_SIGNATURE_DESC* pRootSignatureDesc,
  931. D3D_ROOT_SIGNATURE_VERSION MaxVersion,
  932. _Outptr_ ID3DBlob** ppBlob,
  933. _Always_(_Outptr_opt_result_maybenull_) ID3DBlob** ppErrorBlob) noexcept
  934. {
  935. if (ppErrorBlob != nullptr)
  936. {
  937. *ppErrorBlob = nullptr;
  938. }
  939. PFN_D3D12_SERIALIZE_ROOT_SIGNATURE d3d_D3D12SerializeRootSignature = (PFN_D3D12_SERIALIZE_ROOT_SIGNATURE)(void *)GetProcAddress(pLibD3D12, "D3D12SerializeRootSignature");
  940. if (d3d_D3D12SerializeRootSignature == nullptr) {
  941. return E_INVALIDARG;
  942. }
  943. PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE d3d_D3D12SerializeVersionedRootSignature = (PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE)(void *)GetProcAddress(pLibD3D12, "D3D12SerializeVersionedRootSignature");
  944. switch (MaxVersion)
  945. {
  946. case D3D_ROOT_SIGNATURE_VERSION_1_0:
  947. switch (pRootSignatureDesc->Version)
  948. {
  949. case D3D_ROOT_SIGNATURE_VERSION_1_0:
  950. return d3d_D3D12SerializeRootSignature(&pRootSignatureDesc->Desc_1_0, D3D_ROOT_SIGNATURE_VERSION_1, ppBlob, ppErrorBlob);
  951. case D3D_ROOT_SIGNATURE_VERSION_1_1:
  952. #if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609)
  953. case D3D_ROOT_SIGNATURE_VERSION_1_2:
  954. #endif
  955. {
  956. HRESULT hr = S_OK;
  957. const D3D12_ROOT_SIGNATURE_DESC1& desc_1_1 = pRootSignatureDesc->Desc_1_1;
  958. const SIZE_T ParametersSize = sizeof(D3D12_ROOT_PARAMETER) * desc_1_1.NumParameters;
  959. void* pParameters = (ParametersSize > 0) ? HeapAlloc(GetProcessHeap(), 0, ParametersSize) : nullptr;
  960. if (ParametersSize > 0 && pParameters == nullptr)
  961. {
  962. hr = E_OUTOFMEMORY;
  963. }
  964. auto pParameters_1_0 = static_cast<D3D12_ROOT_PARAMETER*>(pParameters);
  965. if (SUCCEEDED(hr))
  966. {
  967. for (UINT n = 0; n < desc_1_1.NumParameters; n++)
  968. {
  969. __analysis_assume(ParametersSize == sizeof(D3D12_ROOT_PARAMETER) * desc_1_1.NumParameters);
  970. pParameters_1_0[n].ParameterType = desc_1_1.pParameters[n].ParameterType;
  971. pParameters_1_0[n].ShaderVisibility = desc_1_1.pParameters[n].ShaderVisibility;
  972. switch (desc_1_1.pParameters[n].ParameterType)
  973. {
  974. case D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS:
  975. pParameters_1_0[n].Constants.Num32BitValues = desc_1_1.pParameters[n].Constants.Num32BitValues;
  976. pParameters_1_0[n].Constants.RegisterSpace = desc_1_1.pParameters[n].Constants.RegisterSpace;
  977. pParameters_1_0[n].Constants.ShaderRegister = desc_1_1.pParameters[n].Constants.ShaderRegister;
  978. break;
  979. case D3D12_ROOT_PARAMETER_TYPE_CBV:
  980. case D3D12_ROOT_PARAMETER_TYPE_SRV:
  981. case D3D12_ROOT_PARAMETER_TYPE_UAV:
  982. pParameters_1_0[n].Descriptor.RegisterSpace = desc_1_1.pParameters[n].Descriptor.RegisterSpace;
  983. pParameters_1_0[n].Descriptor.ShaderRegister = desc_1_1.pParameters[n].Descriptor.ShaderRegister;
  984. break;
  985. case D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE:
  986. const D3D12_ROOT_DESCRIPTOR_TABLE1& table_1_1 = desc_1_1.pParameters[n].DescriptorTable;
  987. const SIZE_T DescriptorRangesSize = sizeof(D3D12_DESCRIPTOR_RANGE) * table_1_1.NumDescriptorRanges;
  988. void* pDescriptorRanges = (DescriptorRangesSize > 0 && SUCCEEDED(hr)) ? HeapAlloc(GetProcessHeap(), 0, DescriptorRangesSize) : nullptr;
  989. if (DescriptorRangesSize > 0 && pDescriptorRanges == nullptr)
  990. {
  991. hr = E_OUTOFMEMORY;
  992. }
  993. auto pDescriptorRanges_1_0 = static_cast<D3D12_DESCRIPTOR_RANGE*>(pDescriptorRanges);
  994. if (SUCCEEDED(hr))
  995. {
  996. for (UINT x = 0; x < table_1_1.NumDescriptorRanges; x++)
  997. {
  998. __analysis_assume(DescriptorRangesSize == sizeof(D3D12_DESCRIPTOR_RANGE) * table_1_1.NumDescriptorRanges);
  999. pDescriptorRanges_1_0[x].BaseShaderRegister = table_1_1.pDescriptorRanges[x].BaseShaderRegister;
  1000. pDescriptorRanges_1_0[x].NumDescriptors = table_1_1.pDescriptorRanges[x].NumDescriptors;
  1001. pDescriptorRanges_1_0[x].OffsetInDescriptorsFromTableStart = table_1_1.pDescriptorRanges[x].OffsetInDescriptorsFromTableStart;
  1002. pDescriptorRanges_1_0[x].RangeType = table_1_1.pDescriptorRanges[x].RangeType;
  1003. pDescriptorRanges_1_0[x].RegisterSpace = table_1_1.pDescriptorRanges[x].RegisterSpace;
  1004. }
  1005. }
  1006. D3D12_ROOT_DESCRIPTOR_TABLE& table_1_0 = pParameters_1_0[n].DescriptorTable;
  1007. table_1_0.NumDescriptorRanges = table_1_1.NumDescriptorRanges;
  1008. table_1_0.pDescriptorRanges = pDescriptorRanges_1_0;
  1009. }
  1010. }
  1011. }
  1012. D3D12_STATIC_SAMPLER_DESC* pStaticSamplers = nullptr;
  1013. #if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609)
  1014. if (desc_1_1.NumStaticSamplers > 0 && pRootSignatureDesc->Version == D3D_ROOT_SIGNATURE_VERSION_1_2)
  1015. {
  1016. const SIZE_T SamplersSize = sizeof(D3D12_STATIC_SAMPLER_DESC) * desc_1_1.NumStaticSamplers;
  1017. pStaticSamplers = static_cast<D3D12_STATIC_SAMPLER_DESC*>(HeapAlloc(GetProcessHeap(), 0, SamplersSize));
  1018. if (pStaticSamplers == nullptr)
  1019. {
  1020. hr = E_OUTOFMEMORY;
  1021. }
  1022. else
  1023. {
  1024. const D3D12_ROOT_SIGNATURE_DESC2& desc_1_2 = pRootSignatureDesc->Desc_1_2;
  1025. for (UINT n = 0; n < desc_1_1.NumStaticSamplers; ++n)
  1026. {
  1027. if ((desc_1_2.pStaticSamplers[n].Flags & ~D3D12_SAMPLER_FLAG_UINT_BORDER_COLOR) != 0)
  1028. {
  1029. hr = E_INVALIDARG;
  1030. break;
  1031. }
  1032. memcpy(pStaticSamplers + n, desc_1_2.pStaticSamplers + n, sizeof(D3D12_STATIC_SAMPLER_DESC));
  1033. }
  1034. }
  1035. }
  1036. #endif
  1037. if (SUCCEEDED(hr))
  1038. {
  1039. const CD3DX12_ROOT_SIGNATURE_DESC desc_1_0(desc_1_1.NumParameters, pParameters_1_0, desc_1_1.NumStaticSamplers, pStaticSamplers == nullptr ? desc_1_1.pStaticSamplers : pStaticSamplers, desc_1_1.Flags);
  1040. hr = d3d_D3D12SerializeRootSignature(&desc_1_0, D3D_ROOT_SIGNATURE_VERSION_1, ppBlob, ppErrorBlob);
  1041. }
  1042. if (pParameters)
  1043. {
  1044. for (UINT n = 0; n < desc_1_1.NumParameters; n++)
  1045. {
  1046. if (desc_1_1.pParameters[n].ParameterType == D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE)
  1047. {
  1048. auto pDescriptorRanges_1_0 = pParameters_1_0[n].DescriptorTable.pDescriptorRanges;
  1049. HeapFree(GetProcessHeap(), 0, reinterpret_cast<void*>(const_cast<D3D12_DESCRIPTOR_RANGE*>(pDescriptorRanges_1_0)));
  1050. }
  1051. }
  1052. HeapFree(GetProcessHeap(), 0, pParameters);
  1053. }
  1054. if (pStaticSamplers)
  1055. {
  1056. HeapFree(GetProcessHeap(), 0, pStaticSamplers);
  1057. }
  1058. return hr;
  1059. }
  1060. }
  1061. break;
  1062. case D3D_ROOT_SIGNATURE_VERSION_1_1:
  1063. switch (pRootSignatureDesc->Version)
  1064. {
  1065. case D3D_ROOT_SIGNATURE_VERSION_1_0:
  1066. case D3D_ROOT_SIGNATURE_VERSION_1_1:
  1067. return d3d_D3D12SerializeVersionedRootSignature(pRootSignatureDesc, ppBlob, ppErrorBlob);
  1068. #if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609)
  1069. case D3D_ROOT_SIGNATURE_VERSION_1_2:
  1070. {
  1071. HRESULT hr = S_OK;
  1072. const D3D12_ROOT_SIGNATURE_DESC1& desc_1_1 = pRootSignatureDesc->Desc_1_1;
  1073. D3D12_STATIC_SAMPLER_DESC* pStaticSamplers = nullptr;
  1074. if (desc_1_1.NumStaticSamplers > 0)
  1075. {
  1076. const SIZE_T SamplersSize = sizeof(D3D12_STATIC_SAMPLER_DESC) * desc_1_1.NumStaticSamplers;
  1077. pStaticSamplers = static_cast<D3D12_STATIC_SAMPLER_DESC*>(HeapAlloc(GetProcessHeap(), 0, SamplersSize));
  1078. if (pStaticSamplers == nullptr)
  1079. {
  1080. hr = E_OUTOFMEMORY;
  1081. }
  1082. else
  1083. {
  1084. const D3D12_ROOT_SIGNATURE_DESC2& desc_1_2 = pRootSignatureDesc->Desc_1_2;
  1085. for (UINT n = 0; n < desc_1_1.NumStaticSamplers; ++n)
  1086. {
  1087. if ((desc_1_2.pStaticSamplers[n].Flags & ~D3D12_SAMPLER_FLAG_UINT_BORDER_COLOR) != 0)
  1088. {
  1089. hr = E_INVALIDARG;
  1090. break;
  1091. }
  1092. memcpy(pStaticSamplers + n, desc_1_2.pStaticSamplers + n, sizeof(D3D12_STATIC_SAMPLER_DESC));
  1093. }
  1094. }
  1095. }
  1096. if (SUCCEEDED(hr))
  1097. {
  1098. const CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC desc(desc_1_1.NumParameters, desc_1_1.pParameters, desc_1_1.NumStaticSamplers, pStaticSamplers == nullptr ? desc_1_1.pStaticSamplers : pStaticSamplers, desc_1_1.Flags);
  1099. hr = d3d_D3D12SerializeVersionedRootSignature(&desc, ppBlob, ppErrorBlob);
  1100. }
  1101. if (pStaticSamplers)
  1102. {
  1103. HeapFree(GetProcessHeap(), 0, pStaticSamplers);
  1104. }
  1105. return hr;
  1106. }
  1107. #endif
  1108. }
  1109. #if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609)
  1110. case D3D_ROOT_SIGNATURE_VERSION_1_2:
  1111. #endif
  1112. return d3d_D3D12SerializeVersionedRootSignature(pRootSignatureDesc, ppBlob, ppErrorBlob);
  1113. }
  1114. return E_INVALIDARG;
  1115. }