BRE12
d3dx12.h
1 //
3 // Copyright (C) Microsoft Corporation. All Rights Reserved.
4 //
5 // File: d3dx12.h
6 // Content: D3DX12 utility library
7 //
9 
10 #ifndef __D3DX12_H__
11 #define __D3DX12_H__
12 
13 #include <d3d12.h>
14 
15 #include <Utils/DebugUtils.h>
16 
17 #if defined( __cplusplus )
18 
19 struct CD3DX12_DEFAULT {};
20 extern const DECLSPEC_SELECTANY CD3DX12_DEFAULT D3D12_DEFAULT;
21 
22 //------------------------------------------------------------------------------------------------
23 inline bool operator==( const D3D12_VIEWPORT& l, const D3D12_VIEWPORT& r )
24 {
25  return l.TopLeftX == r.TopLeftX && l.TopLeftY == r.TopLeftY && l.Width == r.Width &&
26  l.Height == r.Height && l.MinDepth == r.MinDepth && l.MaxDepth == r.MaxDepth;
27 }
28 
29 //------------------------------------------------------------------------------------------------
30 inline bool operator!=( const D3D12_VIEWPORT& l, const D3D12_VIEWPORT& r )
31 { return !( l == r ); }
32 
33 //------------------------------------------------------------------------------------------------
34 struct CD3DX12_RECT : public D3D12_RECT
35 {
36  CD3DX12_RECT()
37  {}
38  explicit CD3DX12_RECT( const D3D12_RECT& o ) :
39  D3D12_RECT( o )
40  {}
41  explicit CD3DX12_RECT(
42  LONG Left,
43  LONG Top,
44  LONG Right,
45  LONG Bottom )
46  {
47  left = Left;
48  top = Top;
49  right = Right;
50  bottom = Bottom;
51  }
52  ~CD3DX12_RECT() {}
53  operator const D3D12_RECT&() const { return *this; }
54 };
55 
56 //------------------------------------------------------------------------------------------------
57 struct CD3DX12_BOX : public D3D12_BOX
58 {
59  CD3DX12_BOX()
60  {}
61  explicit CD3DX12_BOX( const D3D12_BOX& o ) :
62  D3D12_BOX( o )
63  {}
64  explicit CD3DX12_BOX(
65  LONG Left,
66  LONG Right )
67  {
68  left = Left;
69  top = 0;
70  front = 0;
71  right = Right;
72  bottom = 1;
73  back = 1;
74  }
75  explicit CD3DX12_BOX(
76  LONG Left,
77  LONG Top,
78  LONG Right,
79  LONG Bottom )
80  {
81  left = Left;
82  top = Top;
83  front = 0;
84  right = Right;
85  bottom = Bottom;
86  back = 1;
87  }
88  explicit CD3DX12_BOX(
89  LONG Left,
90  LONG Top,
91  LONG Front,
92  LONG Right,
93  LONG Bottom,
94  LONG Back )
95  {
96  left = Left;
97  top = Top;
98  front = Front;
99  right = Right;
100  bottom = Bottom;
101  back = Back;
102  }
103  ~CD3DX12_BOX() {}
104  operator const D3D12_BOX&() const { return *this; }
105 };
106 inline bool operator==( const D3D12_BOX& l, const D3D12_BOX& r )
107 {
108  return l.left == r.left && l.top == r.top && l.front == r.front &&
109  l.right == r.right && l.bottom == r.bottom && l.back == r.back;
110 }
111 inline bool operator!=( const D3D12_BOX& l, const D3D12_BOX& r )
112 { return !( l == r ); }
113 
114 //------------------------------------------------------------------------------------------------
115 struct CD3DX12_DEPTH_STENCIL_DESC : public D3D12_DEPTH_STENCIL_DESC
116 {
117  CD3DX12_DEPTH_STENCIL_DESC()
118  {}
119  explicit CD3DX12_DEPTH_STENCIL_DESC( const D3D12_DEPTH_STENCIL_DESC& o ) :
120  D3D12_DEPTH_STENCIL_DESC( o )
121  {}
122  explicit CD3DX12_DEPTH_STENCIL_DESC( CD3DX12_DEFAULT )
123  {
124  DepthEnable = TRUE;
125  DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
126  DepthFunc = D3D12_COMPARISON_FUNC_LESS;
127  StencilEnable = FALSE;
128  StencilReadMask = D3D12_DEFAULT_STENCIL_READ_MASK;
129  StencilWriteMask = D3D12_DEFAULT_STENCIL_WRITE_MASK;
130  const D3D12_DEPTH_STENCILOP_DESC defaultStencilOp =
131  { D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_COMPARISON_FUNC_ALWAYS };
132  FrontFace = defaultStencilOp;
133  BackFace = defaultStencilOp;
134  }
135  explicit CD3DX12_DEPTH_STENCIL_DESC(
136  BOOL depthEnable,
137  D3D12_DEPTH_WRITE_MASK depthWriteMask,
138  D3D12_COMPARISON_FUNC depthFunc,
139  BOOL stencilEnable,
140  UINT8 stencilReadMask,
141  UINT8 stencilWriteMask,
142  D3D12_STENCIL_OP frontStencilFailOp,
143  D3D12_STENCIL_OP frontStencilDepthFailOp,
144  D3D12_STENCIL_OP frontStencilPassOp,
145  D3D12_COMPARISON_FUNC frontStencilFunc,
146  D3D12_STENCIL_OP backStencilFailOp,
147  D3D12_STENCIL_OP backStencilDepthFailOp,
148  D3D12_STENCIL_OP backStencilPassOp,
149  D3D12_COMPARISON_FUNC backStencilFunc )
150  {
151  DepthEnable = depthEnable;
152  DepthWriteMask = depthWriteMask;
153  DepthFunc = depthFunc;
154  StencilEnable = stencilEnable;
155  StencilReadMask = stencilReadMask;
156  StencilWriteMask = stencilWriteMask;
157  FrontFace.StencilFailOp = frontStencilFailOp;
158  FrontFace.StencilDepthFailOp = frontStencilDepthFailOp;
159  FrontFace.StencilPassOp = frontStencilPassOp;
160  FrontFace.StencilFunc = frontStencilFunc;
161  BackFace.StencilFailOp = backStencilFailOp;
162  BackFace.StencilDepthFailOp = backStencilDepthFailOp;
163  BackFace.StencilPassOp = backStencilPassOp;
164  BackFace.StencilFunc = backStencilFunc;
165  }
166  ~CD3DX12_DEPTH_STENCIL_DESC() {}
167  operator const D3D12_DEPTH_STENCIL_DESC&() const { return *this; }
168 };
169 
170 //------------------------------------------------------------------------------------------------
171 struct CD3DX12_BLEND_DESC : public D3D12_BLEND_DESC
172 {
173  CD3DX12_BLEND_DESC()
174  {}
175  explicit CD3DX12_BLEND_DESC( const D3D12_BLEND_DESC& o ) :
176  D3D12_BLEND_DESC( o )
177  {}
178  explicit CD3DX12_BLEND_DESC( CD3DX12_DEFAULT )
179  {
180  AlphaToCoverageEnable = FALSE;
181  IndependentBlendEnable = FALSE;
182  const D3D12_RENDER_TARGET_BLEND_DESC defaultRenderTargetBlendDesc =
183  {
184  FALSE,FALSE,
185  D3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD,
186  D3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD,
187  D3D12_LOGIC_OP_NOOP,
188  D3D12_COLOR_WRITE_ENABLE_ALL,
189  };
190  for (UINT i = 0; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
191  RenderTarget[ i ] = defaultRenderTargetBlendDesc;
192  }
193  ~CD3DX12_BLEND_DESC() {}
194  operator const D3D12_BLEND_DESC&() const { return *this; }
195 };
196 
197 //------------------------------------------------------------------------------------------------
198 struct CD3DX12_RASTERIZER_DESC : public D3D12_RASTERIZER_DESC
199 {
200  CD3DX12_RASTERIZER_DESC()
201  {}
202  explicit CD3DX12_RASTERIZER_DESC( const D3D12_RASTERIZER_DESC& o ) :
203  D3D12_RASTERIZER_DESC( o )
204  {}
205  explicit CD3DX12_RASTERIZER_DESC( CD3DX12_DEFAULT )
206  {
207  FillMode = D3D12_FILL_MODE_SOLID;
208  CullMode = D3D12_CULL_MODE_BACK;
209  FrontCounterClockwise = FALSE;
210  DepthBias = D3D12_DEFAULT_DEPTH_BIAS;
211  DepthBiasClamp = D3D12_DEFAULT_DEPTH_BIAS_CLAMP;
212  SlopeScaledDepthBias = D3D12_DEFAULT_SLOPE_SCALED_DEPTH_BIAS;
213  DepthClipEnable = TRUE;
214  MultisampleEnable = FALSE;
215  AntialiasedLineEnable = FALSE;
216  ForcedSampleCount = 0;
217  ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF;
218  }
219  explicit CD3DX12_RASTERIZER_DESC(
220  D3D12_FILL_MODE fillMode,
221  D3D12_CULL_MODE cullMode,
222  BOOL frontCounterClockwise,
223  INT depthBias,
224  FLOAT depthBiasClamp,
225  FLOAT slopeScaledDepthBias,
226  BOOL depthClipEnable,
227  BOOL multisampleEnable,
228  BOOL antialiasedLineEnable,
229  UINT forcedSampleCount,
230  D3D12_CONSERVATIVE_RASTERIZATION_MODE conservativeRaster)
231  {
232  FillMode = fillMode;
233  CullMode = cullMode;
234  FrontCounterClockwise = frontCounterClockwise;
235  DepthBias = depthBias;
236  DepthBiasClamp = depthBiasClamp;
237  SlopeScaledDepthBias = slopeScaledDepthBias;
238  DepthClipEnable = depthClipEnable;
239  MultisampleEnable = multisampleEnable;
240  AntialiasedLineEnable = antialiasedLineEnable;
241  ForcedSampleCount = forcedSampleCount;
242  ConservativeRaster = conservativeRaster;
243  }
244  ~CD3DX12_RASTERIZER_DESC() {}
245  operator const D3D12_RASTERIZER_DESC&() const { return *this; }
246 };
247 
248 //------------------------------------------------------------------------------------------------
249 struct CD3DX12_RESOURCE_ALLOCATION_INFO : public D3D12_RESOURCE_ALLOCATION_INFO
250 {
251  CD3DX12_RESOURCE_ALLOCATION_INFO()
252  {}
253  explicit CD3DX12_RESOURCE_ALLOCATION_INFO( const D3D12_RESOURCE_ALLOCATION_INFO& o ) :
254  D3D12_RESOURCE_ALLOCATION_INFO( o )
255  {}
256  CD3DX12_RESOURCE_ALLOCATION_INFO(
257  UINT64 size,
258  UINT64 alignment )
259  {
260  SizeInBytes = size;
261  Alignment = alignment;
262  }
263  operator const D3D12_RESOURCE_ALLOCATION_INFO&() const { return *this; }
264 };
265 
266 //------------------------------------------------------------------------------------------------
267 struct CD3DX12_HEAP_PROPERTIES : public D3D12_HEAP_PROPERTIES
268 {
269  CD3DX12_HEAP_PROPERTIES()
270  {}
271  explicit CD3DX12_HEAP_PROPERTIES(const D3D12_HEAP_PROPERTIES &o) :
272  D3D12_HEAP_PROPERTIES(o)
273  {}
274  CD3DX12_HEAP_PROPERTIES(
275  D3D12_CPU_PAGE_PROPERTY cpuPageProperty,
276  D3D12_MEMORY_POOL memoryPoolPreference,
277  UINT creationNodeMask = 1,
278  UINT nodeMask = 1 )
279  {
280  Type = D3D12_HEAP_TYPE_CUSTOM;
281  CPUPageProperty = cpuPageProperty;
282  MemoryPoolPreference = memoryPoolPreference;
283  CreationNodeMask = creationNodeMask;
284  VisibleNodeMask = nodeMask;
285  }
286  explicit CD3DX12_HEAP_PROPERTIES(
287  D3D12_HEAP_TYPE type,
288  UINT creationNodeMask = 1,
289  UINT nodeMask = 1 )
290  {
291  Type = type;
292  CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
293  MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
294  CreationNodeMask = creationNodeMask;
295  VisibleNodeMask = nodeMask;
296  }
297  operator const D3D12_HEAP_PROPERTIES&() const { return *this; }
298  bool IsCPUAccessible() const
299  {
300  return Type == D3D12_HEAP_TYPE_UPLOAD || Type == D3D12_HEAP_TYPE_READBACK || (Type == D3D12_HEAP_TYPE_CUSTOM &&
301  (CPUPageProperty == D3D12_CPU_PAGE_PROPERTY_WRITE_COMBINE || CPUPageProperty == D3D12_CPU_PAGE_PROPERTY_WRITE_BACK));
302  }
303 };
304 inline bool operator==( const D3D12_HEAP_PROPERTIES& l, const D3D12_HEAP_PROPERTIES& r )
305 {
306  return l.Type == r.Type && l.CPUPageProperty == r.CPUPageProperty &&
307  l.MemoryPoolPreference == r.MemoryPoolPreference &&
308  l.CreationNodeMask == r.CreationNodeMask &&
309  l.VisibleNodeMask == r.VisibleNodeMask;
310 }
311 inline bool operator!=( const D3D12_HEAP_PROPERTIES& l, const D3D12_HEAP_PROPERTIES& r )
312 { return !( l == r ); }
313 
314 //------------------------------------------------------------------------------------------------
315 struct CD3DX12_HEAP_DESC : public D3D12_HEAP_DESC
316 {
317  CD3DX12_HEAP_DESC()
318  {}
319  explicit CD3DX12_HEAP_DESC(const D3D12_HEAP_DESC &o) :
320  D3D12_HEAP_DESC(o)
321  {}
322  CD3DX12_HEAP_DESC(
323  UINT64 size,
324  D3D12_HEAP_PROPERTIES properties,
325  UINT64 alignment = 0,
326  D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE )
327  {
328  SizeInBytes = size;
329  Properties = properties;
330  Alignment = alignment;
331  Flags = flags;
332  }
333  CD3DX12_HEAP_DESC(
334  UINT64 size,
335  D3D12_HEAP_TYPE type,
336  UINT64 alignment = 0,
337  D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE )
338  {
339  SizeInBytes = size;
340  Properties = CD3DX12_HEAP_PROPERTIES( type );
341  Alignment = alignment;
342  Flags = flags;
343  }
344  CD3DX12_HEAP_DESC(
345  UINT64 size,
346  D3D12_CPU_PAGE_PROPERTY cpuPageProperty,
347  D3D12_MEMORY_POOL memoryPoolPreference,
348  UINT64 alignment = 0,
349  D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE )
350  {
351  SizeInBytes = size;
352  Properties = CD3DX12_HEAP_PROPERTIES( cpuPageProperty, memoryPoolPreference );
353  Alignment = alignment;
354  Flags = flags;
355  }
356  CD3DX12_HEAP_DESC(
357  const D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,
358  D3D12_HEAP_PROPERTIES properties,
359  D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE )
360  {
361  SizeInBytes = resAllocInfo.SizeInBytes;
362  Properties = properties;
363  Alignment = resAllocInfo.Alignment;
364  Flags = flags;
365  }
366  CD3DX12_HEAP_DESC(
367  const D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,
368  D3D12_HEAP_TYPE type,
369  D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE )
370  {
371  SizeInBytes = resAllocInfo.SizeInBytes;
372  Properties = CD3DX12_HEAP_PROPERTIES( type );
373  Alignment = resAllocInfo.Alignment;
374  Flags = flags;
375  }
376  CD3DX12_HEAP_DESC(
377  const D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,
378  D3D12_CPU_PAGE_PROPERTY cpuPageProperty,
379  D3D12_MEMORY_POOL memoryPoolPreference,
380  D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE )
381  {
382  SizeInBytes = resAllocInfo.SizeInBytes;
383  Properties = CD3DX12_HEAP_PROPERTIES( cpuPageProperty, memoryPoolPreference );
384  Alignment = resAllocInfo.Alignment;
385  Flags = flags;
386  }
387  operator const D3D12_HEAP_DESC&() const { return *this; }
388  bool IsCPUAccessible() const
389  { return static_cast< const CD3DX12_HEAP_PROPERTIES* >( &Properties )->IsCPUAccessible(); }
390 };
391 inline bool operator==( const D3D12_HEAP_DESC& l, const D3D12_HEAP_DESC& r )
392 {
393  return l.SizeInBytes == r.SizeInBytes &&
394  l.Properties == r.Properties &&
395  l.Alignment == r.Alignment &&
396  l.Flags == r.Flags;
397 }
398 inline bool operator!=( const D3D12_HEAP_DESC& l, const D3D12_HEAP_DESC& r )
399 { return !( l == r ); }
400 
401 //------------------------------------------------------------------------------------------------
402 struct CD3DX12_CLEAR_VALUE : public D3D12_CLEAR_VALUE
403 {
404  CD3DX12_CLEAR_VALUE()
405  {}
406  explicit CD3DX12_CLEAR_VALUE(const D3D12_CLEAR_VALUE &o) :
407  D3D12_CLEAR_VALUE(o)
408  {}
409  CD3DX12_CLEAR_VALUE(
410  DXGI_FORMAT format,
411  const FLOAT color[4] )
412  {
413  Format = format;
414  memcpy( Color, color, sizeof( Color ) );
415  }
416  CD3DX12_CLEAR_VALUE(
417  DXGI_FORMAT format,
418  FLOAT depth,
419  UINT8 stencil )
420  {
421  Format = format;
422  /* Use memcpy to preserve NAN values */
423  memcpy( &DepthStencil.Depth, &depth, sizeof( depth ) );
424  DepthStencil.Stencil = stencil;
425  }
426  operator const D3D12_CLEAR_VALUE&() const { return *this; }
427 };
428 
429 //------------------------------------------------------------------------------------------------
430 struct CD3DX12_RANGE : public D3D12_RANGE
431 {
432  CD3DX12_RANGE()
433  {}
434  explicit CD3DX12_RANGE(const D3D12_RANGE &o) :
435  D3D12_RANGE(o)
436  {}
437  CD3DX12_RANGE(
438  std::size_t begin,
439  std::size_t end )
440  {
441  Begin = begin;
442  End = end;
443  }
444  operator const D3D12_RANGE&() const { return *this; }
445 };
446 
447 //------------------------------------------------------------------------------------------------
448 struct CD3DX12_TILED_RESOURCE_COORDINATE : public D3D12_TILED_RESOURCE_COORDINATE
449 {
450  CD3DX12_TILED_RESOURCE_COORDINATE()
451  {}
452  explicit CD3DX12_TILED_RESOURCE_COORDINATE(const D3D12_TILED_RESOURCE_COORDINATE &o) :
453  D3D12_TILED_RESOURCE_COORDINATE(o)
454  {}
455  CD3DX12_TILED_RESOURCE_COORDINATE(
456  UINT x,
457  UINT y,
458  UINT z,
459  UINT subresource )
460  {
461  X = x;
462  Y = y;
463  Z = z;
464  Subresource = subresource;
465  }
466  operator const D3D12_TILED_RESOURCE_COORDINATE&() const { return *this; }
467 };
468 
469 //------------------------------------------------------------------------------------------------
470 struct CD3DX12_TILE_REGION_SIZE : public D3D12_TILE_REGION_SIZE
471 {
472  CD3DX12_TILE_REGION_SIZE()
473  {}
474  explicit CD3DX12_TILE_REGION_SIZE(const D3D12_TILE_REGION_SIZE &o) :
475  D3D12_TILE_REGION_SIZE(o)
476  {}
477  CD3DX12_TILE_REGION_SIZE(
478  UINT numTiles,
479  BOOL useBox,
480  UINT width,
481  UINT16 height,
482  UINT16 depth )
483  {
484  NumTiles = numTiles;
485  UseBox = useBox;
486  Width = width;
487  Height = height;
488  Depth = depth;
489  }
490  operator const D3D12_TILE_REGION_SIZE&() const { return *this; }
491 };
492 
493 //------------------------------------------------------------------------------------------------
494 struct CD3DX12_SUBRESOURCE_TILING : public D3D12_SUBRESOURCE_TILING
495 {
496  CD3DX12_SUBRESOURCE_TILING()
497  {}
498  explicit CD3DX12_SUBRESOURCE_TILING(const D3D12_SUBRESOURCE_TILING &o) :
499  D3D12_SUBRESOURCE_TILING(o)
500  {}
501  CD3DX12_SUBRESOURCE_TILING(
502  UINT widthInTiles,
503  UINT16 heightInTiles,
504  UINT16 depthInTiles,
505  UINT startTileIndexInOverallResource )
506  {
507  WidthInTiles = widthInTiles;
508  HeightInTiles = heightInTiles;
509  DepthInTiles = depthInTiles;
510  StartTileIndexInOverallResource = startTileIndexInOverallResource;
511  }
512  operator const D3D12_SUBRESOURCE_TILING&() const { return *this; }
513 };
514 
515 //------------------------------------------------------------------------------------------------
516 struct CD3DX12_TILE_SHAPE : public D3D12_TILE_SHAPE
517 {
518  CD3DX12_TILE_SHAPE()
519  {}
520  explicit CD3DX12_TILE_SHAPE(const D3D12_TILE_SHAPE &o) :
521  D3D12_TILE_SHAPE(o)
522  {}
523  CD3DX12_TILE_SHAPE(
524  UINT widthInTexels,
525  UINT heightInTexels,
526  UINT depthInTexels )
527  {
528  WidthInTexels = widthInTexels;
529  HeightInTexels = heightInTexels;
530  DepthInTexels = depthInTexels;
531  }
532  operator const D3D12_TILE_SHAPE&() const { return *this; }
533 };
534 
535 //------------------------------------------------------------------------------------------------
536 struct CD3DX12_RESOURCE_BARRIER : public D3D12_RESOURCE_BARRIER
537 {
538  CD3DX12_RESOURCE_BARRIER()
539  {}
540  explicit CD3DX12_RESOURCE_BARRIER(const D3D12_RESOURCE_BARRIER &o) :
541  D3D12_RESOURCE_BARRIER(o)
542  {}
543  static inline CD3DX12_RESOURCE_BARRIER Transition(
544  _In_ ID3D12Resource* pResource,
545  D3D12_RESOURCE_STATES stateBefore,
546  D3D12_RESOURCE_STATES stateAfter,
547  UINT subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
548  D3D12_RESOURCE_BARRIER_FLAGS flags = D3D12_RESOURCE_BARRIER_FLAG_NONE)
549  {
550  CD3DX12_RESOURCE_BARRIER result;
551  ZeroMemory(&result, sizeof(result));
552  D3D12_RESOURCE_BARRIER &barrier = result;
553  result.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
554  result.Flags = flags;
555  barrier.Transition.pResource = pResource;
556  barrier.Transition.StateBefore = stateBefore;
557  barrier.Transition.StateAfter = stateAfter;
558  barrier.Transition.Subresource = subresource;
559  return result;
560  }
561  static inline CD3DX12_RESOURCE_BARRIER Aliasing(
562  _In_ ID3D12Resource* pResourceBefore,
563  _In_ ID3D12Resource* pResourceAfter)
564  {
565  CD3DX12_RESOURCE_BARRIER result;
566  ZeroMemory(&result, sizeof(result));
567  D3D12_RESOURCE_BARRIER &barrier = result;
568  result.Type = D3D12_RESOURCE_BARRIER_TYPE_ALIASING;
569  barrier.Aliasing.pResourceBefore = pResourceBefore;
570  barrier.Aliasing.pResourceAfter = pResourceAfter;
571  return result;
572  }
573  static inline CD3DX12_RESOURCE_BARRIER UAV(
574  _In_ ID3D12Resource* pResource)
575  {
576  CD3DX12_RESOURCE_BARRIER result;
577  ZeroMemory(&result, sizeof(result));
578  D3D12_RESOURCE_BARRIER &barrier = result;
579  result.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
580  barrier.UAV.pResource = pResource;
581  return result;
582  }
583  operator const D3D12_RESOURCE_BARRIER&() const { return *this; }
584 };
585 
586 //------------------------------------------------------------------------------------------------
587 struct CD3DX12_PACKED_MIP_INFO : public D3D12_PACKED_MIP_INFO
588 {
589  CD3DX12_PACKED_MIP_INFO()
590  {}
591  explicit CD3DX12_PACKED_MIP_INFO(const D3D12_PACKED_MIP_INFO &o) :
592  D3D12_PACKED_MIP_INFO(o)
593  {}
594  CD3DX12_PACKED_MIP_INFO(
595  UINT8 numStandardMips,
596  UINT8 numPackedMips,
597  UINT numTilesForPackedMips,
598  UINT startTileIndexInOverallResource )
599  {
600  NumStandardMips = numStandardMips;
601  NumPackedMips = numPackedMips;
602  NumTilesForPackedMips = numTilesForPackedMips;
603  StartTileIndexInOverallResource = startTileIndexInOverallResource;
604  }
605  operator const D3D12_PACKED_MIP_INFO&() const { return *this; }
606 };
607 
608 //------------------------------------------------------------------------------------------------
609 struct CD3DX12_SUBRESOURCE_FOOTPRINT : public D3D12_SUBRESOURCE_FOOTPRINT
610 {
611  CD3DX12_SUBRESOURCE_FOOTPRINT()
612  {}
613  explicit CD3DX12_SUBRESOURCE_FOOTPRINT(const D3D12_SUBRESOURCE_FOOTPRINT &o) :
614  D3D12_SUBRESOURCE_FOOTPRINT(o)
615  {}
616  CD3DX12_SUBRESOURCE_FOOTPRINT(
617  DXGI_FORMAT format,
618  UINT width,
619  UINT height,
620  UINT depth,
621  UINT rowPitch )
622  {
623  Format = format;
624  Width = width;
625  Height = height;
626  Depth = depth;
627  RowPitch = rowPitch;
628  }
629  explicit CD3DX12_SUBRESOURCE_FOOTPRINT(
630  const D3D12_RESOURCE_DESC& resDesc,
631  UINT rowPitch )
632  {
633  Format = resDesc.Format;
634  Width = UINT( resDesc.Width );
635  Height = resDesc.Height;
636  Depth = (resDesc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? resDesc.DepthOrArraySize : 1);
637  RowPitch = rowPitch;
638  }
639  operator const D3D12_SUBRESOURCE_FOOTPRINT&() const { return *this; }
640 };
641 
642 //------------------------------------------------------------------------------------------------
643 struct CD3DX12_TEXTURE_COPY_LOCATION : public D3D12_TEXTURE_COPY_LOCATION
644 {
645  CD3DX12_TEXTURE_COPY_LOCATION()
646  {}
647  explicit CD3DX12_TEXTURE_COPY_LOCATION(const D3D12_TEXTURE_COPY_LOCATION &o) :
648  D3D12_TEXTURE_COPY_LOCATION(o)
649  {}
650  CD3DX12_TEXTURE_COPY_LOCATION(ID3D12Resource* pRes) { pResource = pRes; }
651  CD3DX12_TEXTURE_COPY_LOCATION(ID3D12Resource* pRes, D3D12_PLACED_SUBRESOURCE_FOOTPRINT const& Footprint)
652  {
653  pResource = pRes;
654  Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
655  PlacedFootprint = Footprint;
656  }
657  CD3DX12_TEXTURE_COPY_LOCATION(ID3D12Resource* pRes, UINT Sub)
658  {
659  pResource = pRes;
660  Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
661  SubresourceIndex = Sub;
662  }
663 };
664 
665 //------------------------------------------------------------------------------------------------
666 struct CD3DX12_DESCRIPTOR_RANGE : public D3D12_DESCRIPTOR_RANGE
667 {
668  CD3DX12_DESCRIPTOR_RANGE() { }
669  explicit CD3DX12_DESCRIPTOR_RANGE(const D3D12_DESCRIPTOR_RANGE &o) :
670  D3D12_DESCRIPTOR_RANGE(o)
671  {}
672  CD3DX12_DESCRIPTOR_RANGE(
673  D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
674  UINT numDescriptors,
675  UINT baseShaderRegister,
676  UINT registerSpace = 0,
677  UINT offsetInDescriptorsFromTableStart =
678  D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
679  {
680  Init(rangeType, numDescriptors, baseShaderRegister, registerSpace, offsetInDescriptorsFromTableStart);
681  }
682 
683  inline void Init(
684  D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
685  UINT numDescriptors,
686  UINT baseShaderRegister,
687  UINT registerSpace = 0,
688  UINT offsetInDescriptorsFromTableStart =
689  D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
690  {
691  Init(*this, rangeType, numDescriptors, baseShaderRegister, registerSpace, offsetInDescriptorsFromTableStart);
692  }
693 
694  static inline void Init(
695  _Out_ D3D12_DESCRIPTOR_RANGE &range,
696  D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
697  UINT numDescriptors,
698  UINT baseShaderRegister,
699  UINT registerSpace = 0,
700  UINT offsetInDescriptorsFromTableStart =
701  D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
702  {
703  range.RangeType = rangeType;
704  range.NumDescriptors = numDescriptors;
705  range.BaseShaderRegister = baseShaderRegister;
706  range.RegisterSpace = registerSpace;
707  range.OffsetInDescriptorsFromTableStart = offsetInDescriptorsFromTableStart;
708  }
709 };
710 
711 //------------------------------------------------------------------------------------------------
712 struct CD3DX12_ROOT_DESCRIPTOR_TABLE : public D3D12_ROOT_DESCRIPTOR_TABLE
713 {
714  CD3DX12_ROOT_DESCRIPTOR_TABLE() {}
715  explicit CD3DX12_ROOT_DESCRIPTOR_TABLE(const D3D12_ROOT_DESCRIPTOR_TABLE &o) :
716  D3D12_ROOT_DESCRIPTOR_TABLE(o)
717  {}
718  CD3DX12_ROOT_DESCRIPTOR_TABLE(
719  UINT numDescriptorRanges,
720  _In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges)
721  {
722  BRE_ASSERT(_pDescriptorRanges != nullptr);
723  Init(numDescriptorRanges, _pDescriptorRanges);
724  }
725 
726  inline void Init(
727  UINT numDescriptorRanges,
728  _In_reads_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges)
729  {
730  BRE_ASSERT(_pDescriptorRanges != nullptr);
731  Init(*this, numDescriptorRanges, _pDescriptorRanges);
732  }
733 
734  static inline void Init(
735  _Out_ D3D12_ROOT_DESCRIPTOR_TABLE &rootDescriptorTable,
736  UINT numDescriptorRanges,
737  _In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges)
738  {
739  BRE_ASSERT(_pDescriptorRanges != nullptr);
740  rootDescriptorTable.NumDescriptorRanges = numDescriptorRanges;
741  rootDescriptorTable.pDescriptorRanges = _pDescriptorRanges;
742  }
743 };
744 
745 //------------------------------------------------------------------------------------------------
746 struct CD3DX12_ROOT_CONSTANTS : public D3D12_ROOT_CONSTANTS
747 {
748  CD3DX12_ROOT_CONSTANTS() {}
749  explicit CD3DX12_ROOT_CONSTANTS(const D3D12_ROOT_CONSTANTS &o) :
750  D3D12_ROOT_CONSTANTS(o)
751  {}
752  CD3DX12_ROOT_CONSTANTS(
753  UINT num32BitValues,
754  UINT shaderRegister,
755  UINT registerSpace = 0)
756  {
757  Init(num32BitValues, shaderRegister, registerSpace);
758  }
759 
760  inline void Init(
761  UINT num32BitValues,
762  UINT shaderRegister,
763  UINT registerSpace = 0)
764  {
765  Init(*this, num32BitValues, shaderRegister, registerSpace);
766  }
767 
768  static inline void Init(
769  _Out_ D3D12_ROOT_CONSTANTS &rootConstants,
770  UINT num32BitValues,
771  UINT shaderRegister,
772  UINT registerSpace = 0)
773  {
774  rootConstants.Num32BitValues = num32BitValues;
775  rootConstants.ShaderRegister = shaderRegister;
776  rootConstants.RegisterSpace = registerSpace;
777  }
778 };
779 
780 //------------------------------------------------------------------------------------------------
781 struct CD3DX12_ROOT_DESCRIPTOR : public D3D12_ROOT_DESCRIPTOR
782 {
783  CD3DX12_ROOT_DESCRIPTOR() {}
784  explicit CD3DX12_ROOT_DESCRIPTOR(const D3D12_ROOT_DESCRIPTOR &o) :
785  D3D12_ROOT_DESCRIPTOR(o)
786  {}
787  CD3DX12_ROOT_DESCRIPTOR(
788  UINT shaderRegister,
789  UINT registerSpace = 0)
790  {
791  Init(shaderRegister, registerSpace);
792  }
793 
794  inline void Init(
795  UINT shaderRegister,
796  UINT registerSpace = 0)
797  {
798  Init(*this, shaderRegister, registerSpace);
799  }
800 
801  static inline void Init(_Out_ D3D12_ROOT_DESCRIPTOR &table, UINT shaderRegister, UINT registerSpace = 0)
802  {
803  table.ShaderRegister = shaderRegister;
804  table.RegisterSpace = registerSpace;
805  }
806 };
807 
808 //------------------------------------------------------------------------------------------------
809 struct CD3DX12_ROOT_PARAMETER : public D3D12_ROOT_PARAMETER
810 {
811  CD3DX12_ROOT_PARAMETER() {}
812  explicit CD3DX12_ROOT_PARAMETER(const D3D12_ROOT_PARAMETER &o) :
813  D3D12_ROOT_PARAMETER(o)
814  {}
815 
816  static inline void InitAsDescriptorTable(
817  _Out_ D3D12_ROOT_PARAMETER &rootParam,
818  UINT numDescriptorRanges,
819  _In_reads_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* pDescriptorRanges,
820  D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
821  {
822  rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
823  rootParam.ShaderVisibility = visibility;
824  CD3DX12_ROOT_DESCRIPTOR_TABLE::Init(rootParam.DescriptorTable, numDescriptorRanges, pDescriptorRanges);
825  }
826 
827  static inline void InitAsConstants(
828  _Out_ D3D12_ROOT_PARAMETER &rootParam,
829  UINT num32BitValues,
830  UINT shaderRegister,
831  UINT registerSpace = 0,
832  D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
833  {
834  rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
835  rootParam.ShaderVisibility = visibility;
836  CD3DX12_ROOT_CONSTANTS::Init(rootParam.Constants, num32BitValues, shaderRegister, registerSpace);
837  }
838 
839  static inline void InitAsConstantBufferView(
840  _Out_ D3D12_ROOT_PARAMETER &rootParam,
841  UINT shaderRegister,
842  UINT registerSpace = 0,
843  D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
844  {
845  rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
846  rootParam.ShaderVisibility = visibility;
847  CD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister, registerSpace);
848  }
849 
850  static inline void InitAsShaderResourceView(
851  _Out_ D3D12_ROOT_PARAMETER &rootParam,
852  UINT shaderRegister,
853  UINT registerSpace = 0,
854  D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
855  {
856  rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;
857  rootParam.ShaderVisibility = visibility;
858  CD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister, registerSpace);
859  }
860 
861  static inline void InitAsUnorderedAccessView(
862  _Out_ D3D12_ROOT_PARAMETER &rootParam,
863  UINT shaderRegister,
864  UINT registerSpace = 0,
865  D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
866  {
867  rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV;
868  rootParam.ShaderVisibility = visibility;
869  CD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister, registerSpace);
870  }
871 
872  inline void InitAsDescriptorTable(
873  UINT numDescriptorRanges,
874  _In_reads_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* pDescriptorRanges,
875  D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
876  {
877  InitAsDescriptorTable(*this, numDescriptorRanges, pDescriptorRanges, visibility);
878  }
879 
880  inline void InitAsConstants(
881  UINT num32BitValues,
882  UINT shaderRegister,
883  UINT registerSpace = 0,
884  D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
885  {
886  InitAsConstants(*this, num32BitValues, shaderRegister, registerSpace, visibility);
887  }
888 
889  inline void InitAsConstantBufferView(
890  UINT shaderRegister,
891  UINT registerSpace = 0,
892  D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
893  {
894  InitAsConstantBufferView(*this, shaderRegister, registerSpace, visibility);
895  }
896 
897  inline void InitAsShaderResourceView(
898  UINT shaderRegister,
899  UINT registerSpace = 0,
900  D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
901  {
902  InitAsShaderResourceView(*this, shaderRegister, registerSpace, visibility);
903  }
904 
905  inline void InitAsUnorderedAccessView(
906  UINT shaderRegister,
907  UINT registerSpace = 0,
908  D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
909  {
910  InitAsUnorderedAccessView(*this, shaderRegister, registerSpace, visibility);
911  }
912 };
913 
914 //------------------------------------------------------------------------------------------------
915 struct CD3DX12_STATIC_SAMPLER_DESC : public D3D12_STATIC_SAMPLER_DESC
916 {
917  CD3DX12_STATIC_SAMPLER_DESC() {}
918  explicit CD3DX12_STATIC_SAMPLER_DESC(const D3D12_STATIC_SAMPLER_DESC &o) :
919  D3D12_STATIC_SAMPLER_DESC(o)
920  {}
921  CD3DX12_STATIC_SAMPLER_DESC(
922  UINT shaderRegister,
923  D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
924  D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
925  D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
926  D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
927  FLOAT mipLODBias = 0,
928  UINT maxAnisotropy = 16,
929  D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
930  D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
931  FLOAT minLOD = 0.f,
932  FLOAT maxLOD = D3D12_FLOAT32_MAX,
933  D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
934  UINT registerSpace = 0)
935  {
936  Init(
937  shaderRegister,
938  filter,
939  addressU,
940  addressV,
941  addressW,
942  mipLODBias,
943  maxAnisotropy,
944  comparisonFunc,
945  borderColor,
946  minLOD,
947  maxLOD,
948  shaderVisibility,
949  registerSpace);
950  }
951 
952  static inline void Init(
953  _Out_ D3D12_STATIC_SAMPLER_DESC &samplerDesc,
954  UINT shaderRegister,
955  D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
956  D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
957  D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
958  D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
959  FLOAT mipLODBias = 0,
960  UINT maxAnisotropy = 16,
961  D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
962  D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
963  FLOAT minLOD = 0.f,
964  FLOAT maxLOD = D3D12_FLOAT32_MAX,
965  D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
966  UINT registerSpace = 0)
967  {
968  samplerDesc.ShaderRegister = shaderRegister;
969  samplerDesc.Filter = filter;
970  samplerDesc.AddressU = addressU;
971  samplerDesc.AddressV = addressV;
972  samplerDesc.AddressW = addressW;
973  samplerDesc.MipLODBias = mipLODBias;
974  samplerDesc.MaxAnisotropy = maxAnisotropy;
975  samplerDesc.ComparisonFunc = comparisonFunc;
976  samplerDesc.BorderColor = borderColor;
977  samplerDesc.MinLOD = minLOD;
978  samplerDesc.MaxLOD = maxLOD;
979  samplerDesc.ShaderVisibility = shaderVisibility;
980  samplerDesc.RegisterSpace = registerSpace;
981  }
982  inline void Init(
983  UINT shaderRegister,
984  D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
985  D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
986  D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
987  D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
988  FLOAT mipLODBias = 0,
989  UINT maxAnisotropy = 16,
990  D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
991  D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
992  FLOAT minLOD = 0.f,
993  FLOAT maxLOD = D3D12_FLOAT32_MAX,
994  D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
995  UINT registerSpace = 0)
996  {
997  Init(
998  *this,
999  shaderRegister,
1000  filter,
1001  addressU,
1002  addressV,
1003  addressW,
1004  mipLODBias,
1005  maxAnisotropy,
1006  comparisonFunc,
1007  borderColor,
1008  minLOD,
1009  maxLOD,
1010  shaderVisibility,
1011  registerSpace);
1012  }
1013 
1014 };
1015 
1016 //------------------------------------------------------------------------------------------------
1017 struct CD3DX12_ROOT_SIGNATURE_DESC : public D3D12_ROOT_SIGNATURE_DESC
1018 {
1019  CD3DX12_ROOT_SIGNATURE_DESC() {}
1020  explicit CD3DX12_ROOT_SIGNATURE_DESC(const D3D12_ROOT_SIGNATURE_DESC &o) :
1021  D3D12_ROOT_SIGNATURE_DESC(o)
1022  {}
1023  CD3DX12_ROOT_SIGNATURE_DESC(
1024  UINT numParameters,
1025  _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
1026  UINT numStaticSamplers = 0,
1027  _In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
1028  D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE)
1029  {
1030  Init(numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
1031  }
1032  CD3DX12_ROOT_SIGNATURE_DESC(CD3DX12_DEFAULT)
1033  {
1034  Init(0, nullptr, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
1035  }
1036 
1037  inline void Init(
1038  UINT numParameters,
1039  _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
1040  UINT numStaticSamplers = 0,
1041  _In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
1042  D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE)
1043  {
1044  Init(*this, numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
1045  }
1046 
1047  static inline void Init(
1048  _Out_ D3D12_ROOT_SIGNATURE_DESC &desc,
1049  UINT numParameters,
1050  _In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
1051  UINT numStaticSamplers = 0,
1052  _In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
1053  D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE)
1054  {
1055  desc.NumParameters = numParameters;
1056  desc.pParameters = _pParameters;
1057  desc.NumStaticSamplers = numStaticSamplers;
1058  desc.pStaticSamplers = _pStaticSamplers;
1059  desc.Flags = flags;
1060  }
1061 };
1062 
1063 //------------------------------------------------------------------------------------------------
1064 struct CD3DX12_CPU_DESCRIPTOR_HANDLE : public D3D12_CPU_DESCRIPTOR_HANDLE
1065 {
1066  CD3DX12_CPU_DESCRIPTOR_HANDLE() {}
1067  explicit CD3DX12_CPU_DESCRIPTOR_HANDLE(const D3D12_CPU_DESCRIPTOR_HANDLE &o) :
1068  D3D12_CPU_DESCRIPTOR_HANDLE(o)
1069  {}
1070  CD3DX12_CPU_DESCRIPTOR_HANDLE(CD3DX12_DEFAULT) { ptr = 0; }
1071  CD3DX12_CPU_DESCRIPTOR_HANDLE(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &other, INT offsetScaledByIncrementSize)
1072  {
1073  InitOffsetted(other, offsetScaledByIncrementSize);
1074  }
1075  CD3DX12_CPU_DESCRIPTOR_HANDLE(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &other, INT offsetInDescriptors, UINT descriptorIncrementSize)
1076  {
1077  InitOffsetted(other, offsetInDescriptors, descriptorIncrementSize);
1078  }
1079  CD3DX12_CPU_DESCRIPTOR_HANDLE& Offset(INT offsetInDescriptors, UINT descriptorIncrementSize)
1080  {
1081  ptr += offsetInDescriptors * descriptorIncrementSize;
1082  return *this;
1083  }
1084  CD3DX12_CPU_DESCRIPTOR_HANDLE& Offset(INT offsetScaledByIncrementSize)
1085  {
1086  ptr += offsetScaledByIncrementSize;
1087  return *this;
1088  }
1089  bool operator==(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE& other) const
1090  {
1091  return (ptr == other.ptr);
1092  }
1093  bool operator!=(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE& other) const
1094  {
1095  return (ptr != other.ptr);
1096  }
1097  CD3DX12_CPU_DESCRIPTOR_HANDLE &operator=(const D3D12_CPU_DESCRIPTOR_HANDLE &other)
1098  {
1099  ptr = other.ptr;
1100  return *this;
1101  }
1102 
1103  inline void InitOffsetted(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize)
1104  {
1105  InitOffsetted(*this, base, offsetScaledByIncrementSize);
1106  }
1107 
1108  inline void InitOffsetted(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize)
1109  {
1110  InitOffsetted(*this, base, offsetInDescriptors, descriptorIncrementSize);
1111  }
1112 
1113  static inline void InitOffsetted(_Out_ D3D12_CPU_DESCRIPTOR_HANDLE &handle, _In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize)
1114  {
1115  handle.ptr = base.ptr + offsetScaledByIncrementSize;
1116  }
1117 
1118  static inline void InitOffsetted(_Out_ D3D12_CPU_DESCRIPTOR_HANDLE &handle, _In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize)
1119  {
1120  handle.ptr = base.ptr + offsetInDescriptors * descriptorIncrementSize;
1121  }
1122 };
1123 
1124 //------------------------------------------------------------------------------------------------
1125 struct CD3DX12_GPU_DESCRIPTOR_HANDLE : public D3D12_GPU_DESCRIPTOR_HANDLE
1126 {
1127  CD3DX12_GPU_DESCRIPTOR_HANDLE() {}
1128  explicit CD3DX12_GPU_DESCRIPTOR_HANDLE(const D3D12_GPU_DESCRIPTOR_HANDLE &o) :
1129  D3D12_GPU_DESCRIPTOR_HANDLE(o)
1130  {}
1131  CD3DX12_GPU_DESCRIPTOR_HANDLE(CD3DX12_DEFAULT) { ptr = 0; }
1132  CD3DX12_GPU_DESCRIPTOR_HANDLE(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &other, INT offsetScaledByIncrementSize)
1133  {
1134  InitOffsetted(other, offsetScaledByIncrementSize);
1135  }
1136  CD3DX12_GPU_DESCRIPTOR_HANDLE(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &other, INT offsetInDescriptors, UINT descriptorIncrementSize)
1137  {
1138  InitOffsetted(other, offsetInDescriptors, descriptorIncrementSize);
1139  }
1140  CD3DX12_GPU_DESCRIPTOR_HANDLE& Offset(INT offsetInDescriptors, UINT descriptorIncrementSize)
1141  {
1142  ptr += offsetInDescriptors * descriptorIncrementSize;
1143  return *this;
1144  }
1145  CD3DX12_GPU_DESCRIPTOR_HANDLE& Offset(INT offsetScaledByIncrementSize)
1146  {
1147  ptr += offsetScaledByIncrementSize;
1148  return *this;
1149  }
1150  inline bool operator==(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE& other) const
1151  {
1152  return (ptr == other.ptr);
1153  }
1154  inline bool operator!=(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE& other) const
1155  {
1156  return (ptr != other.ptr);
1157  }
1158  CD3DX12_GPU_DESCRIPTOR_HANDLE &operator=(const D3D12_GPU_DESCRIPTOR_HANDLE &other)
1159  {
1160  ptr = other.ptr;
1161  return *this;
1162  }
1163 
1164  inline void InitOffsetted(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize)
1165  {
1166  InitOffsetted(*this, base, offsetScaledByIncrementSize);
1167  }
1168 
1169  inline void InitOffsetted(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize)
1170  {
1171  InitOffsetted(*this, base, offsetInDescriptors, descriptorIncrementSize);
1172  }
1173 
1174  static inline void InitOffsetted(_Out_ D3D12_GPU_DESCRIPTOR_HANDLE &handle, _In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize)
1175  {
1176  handle.ptr = base.ptr + offsetScaledByIncrementSize;
1177  }
1178 
1179  static inline void InitOffsetted(_Out_ D3D12_GPU_DESCRIPTOR_HANDLE &handle, _In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize)
1180  {
1181  handle.ptr = base.ptr + offsetInDescriptors * descriptorIncrementSize;
1182  }
1183 };
1184 
1185 //------------------------------------------------------------------------------------------------
1186 inline UINT D3D12CalcSubresource( UINT MipSlice, UINT ArraySlice, UINT PlaneSlice, UINT MipLevels, UINT ArraySize )
1187 {
1188  return MipSlice + ArraySlice * MipLevels + PlaneSlice * MipLevels * ArraySize;
1189 }
1190 
1191 //------------------------------------------------------------------------------------------------
1192 template <typename T, typename U, typename V>
1193 inline void D3D12DecomposeSubresource( UINT Subresource, UINT MipLevels, UINT ArraySize, _Out_ T& MipSlice, _Out_ U& ArraySlice, _Out_ V& PlaneSlice )
1194 {
1195  MipSlice = static_cast<T>(Subresource % MipLevels);
1196  ArraySlice = static_cast<U>((Subresource / MipLevels) % ArraySize);
1197  PlaneSlice = static_cast<V>(Subresource / (MipLevels * ArraySize));
1198 }
1199 
1200 //------------------------------------------------------------------------------------------------
1201 inline UINT8 D3D12GetFormatPlaneCount(
1202  _In_ ID3D12Device* pDevice,
1203  DXGI_FORMAT Format
1204  )
1205 {
1206  D3D12_FEATURE_DATA_FORMAT_INFO formatInfo = {Format};
1207  if (FAILED(pDevice->CheckFeatureSupport(D3D12_FEATURE_FORMAT_INFO, &formatInfo, sizeof(formatInfo))))
1208  {
1209  return 0;
1210  }
1211  return formatInfo.PlaneCount;
1212 }
1213 
1214 //------------------------------------------------------------------------------------------------
1215 struct CD3DX12_RESOURCE_DESC : public D3D12_RESOURCE_DESC
1216 {
1217  CD3DX12_RESOURCE_DESC()
1218  {}
1219  explicit CD3DX12_RESOURCE_DESC( const D3D12_RESOURCE_DESC& o ) :
1220  D3D12_RESOURCE_DESC( o )
1221  {}
1222  CD3DX12_RESOURCE_DESC(
1223  D3D12_RESOURCE_DIMENSION dimension,
1224  UINT64 alignment,
1225  UINT64 width,
1226  UINT height,
1227  UINT16 depthOrArraySize,
1228  UINT16 mipLevels,
1229  DXGI_FORMAT format,
1230  UINT sampleCount,
1231  UINT sampleQuality,
1232  D3D12_TEXTURE_LAYOUT layout,
1233  D3D12_RESOURCE_FLAGS flags )
1234  {
1235  Dimension = dimension;
1236  Alignment = alignment;
1237  Width = width;
1238  Height = height;
1239  DepthOrArraySize = depthOrArraySize;
1240  MipLevels = mipLevels;
1241  Format = format;
1242  SampleDesc.Count = sampleCount;
1243  SampleDesc.Quality = sampleQuality;
1244  Layout = layout;
1245  Flags = flags;
1246  }
1247  static inline CD3DX12_RESOURCE_DESC Buffer(
1248  const D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,
1249  D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE )
1250  {
1251  return CD3DX12_RESOURCE_DESC( D3D12_RESOURCE_DIMENSION_BUFFER, resAllocInfo.Alignment, resAllocInfo.SizeInBytes,
1252  1, 1, 1, DXGI_FORMAT_UNKNOWN, 1, 0, D3D12_TEXTURE_LAYOUT_ROW_MAJOR, flags );
1253  }
1254  static inline CD3DX12_RESOURCE_DESC Buffer(
1255  UINT64 width,
1256  D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
1257  UINT64 alignment = 0 )
1258  {
1259  return CD3DX12_RESOURCE_DESC( D3D12_RESOURCE_DIMENSION_BUFFER, alignment, width, 1, 1, 1,
1260  DXGI_FORMAT_UNKNOWN, 1, 0, D3D12_TEXTURE_LAYOUT_ROW_MAJOR, flags );
1261  }
1262  static inline CD3DX12_RESOURCE_DESC Tex1D(
1263  DXGI_FORMAT format,
1264  UINT64 width,
1265  UINT16 arraySize = 1,
1266  UINT16 mipLevels = 0,
1267  D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
1268  D3D12_TEXTURE_LAYOUT layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,
1269  UINT64 alignment = 0 )
1270  {
1271  return CD3DX12_RESOURCE_DESC( D3D12_RESOURCE_DIMENSION_TEXTURE1D, alignment, width, 1, arraySize,
1272  mipLevels, format, 1, 0, layout, flags );
1273  }
1274  static inline CD3DX12_RESOURCE_DESC Tex2D(
1275  DXGI_FORMAT format,
1276  UINT64 width,
1277  UINT height,
1278  UINT16 arraySize = 1,
1279  UINT16 mipLevels = 0,
1280  UINT sampleCount = 1,
1281  UINT sampleQuality = 0,
1282  D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
1283  D3D12_TEXTURE_LAYOUT layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,
1284  UINT64 alignment = 0 )
1285  {
1286  return CD3DX12_RESOURCE_DESC( D3D12_RESOURCE_DIMENSION_TEXTURE2D, alignment, width, height, arraySize,
1287  mipLevels, format, sampleCount, sampleQuality, layout, flags );
1288  }
1289  static inline CD3DX12_RESOURCE_DESC Tex3D(
1290  DXGI_FORMAT format,
1291  UINT64 width,
1292  UINT height,
1293  UINT16 depth,
1294  UINT16 mipLevels = 0,
1295  D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
1296  D3D12_TEXTURE_LAYOUT layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,
1297  UINT64 alignment = 0 )
1298  {
1299  return CD3DX12_RESOURCE_DESC( D3D12_RESOURCE_DIMENSION_TEXTURE3D, alignment, width, height, depth,
1300  mipLevels, format, 1, 0, layout, flags );
1301  }
1302  inline UINT16 Depth() const
1303  { return (Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? DepthOrArraySize : 1); }
1304  inline UINT16 ArraySize() const
1305  { return (Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE3D ? DepthOrArraySize : 1); }
1306  inline UINT8 PlaneCount(_In_ ID3D12Device* pDevice) const
1307  { return D3D12GetFormatPlaneCount(pDevice, Format); }
1308  inline UINT Subresources(_In_ ID3D12Device* pDevice) const
1309  { return MipLevels * ArraySize() * PlaneCount(pDevice); }
1310  inline UINT CalcSubresource(UINT MipSlice, UINT ArraySlice, UINT PlaneSlice) const
1311  { return D3D12CalcSubresource(MipSlice, ArraySlice, PlaneSlice, MipLevels, ArraySize()); }
1312  operator const D3D12_RESOURCE_DESC&() const { return *this; }
1313 };
1314 inline bool operator==( const D3D12_RESOURCE_DESC& l, const D3D12_RESOURCE_DESC& r )
1315 {
1316  return l.Dimension == r.Dimension &&
1317  l.Alignment == r.Alignment &&
1318  l.Width == r.Width &&
1319  l.Height == r.Height &&
1320  l.DepthOrArraySize == r.DepthOrArraySize &&
1321  l.MipLevels == r.MipLevels &&
1322  l.Format == r.Format &&
1323  l.SampleDesc.Count == r.SampleDesc.Count &&
1324  l.SampleDesc.Quality == r.SampleDesc.Quality &&
1325  l.Layout == r.Layout &&
1326  l.Flags == r.Flags;
1327 }
1328 inline bool operator!=( const D3D12_RESOURCE_DESC& l, const D3D12_RESOURCE_DESC& r )
1329 { return !( l == r ); }
1330 
1331 //------------------------------------------------------------------------------------------------
1332 // Row-by-row memcpy
1333 inline void MemcpySubresource(
1334  _In_ const D3D12_MEMCPY_DEST* pDest,
1335  _In_ const D3D12_SUBRESOURCE_DATA* pSrc,
1336  std::size_t RowSizeInBytes,
1337  UINT NumRows,
1338  UINT NumSlices)
1339 {
1340  for (UINT z = 0; z < NumSlices; ++z)
1341  {
1342  BYTE* pDestSlice = reinterpret_cast<BYTE*>(pDest->pData) + pDest->SlicePitch * z;
1343  const BYTE* pSrcSlice = reinterpret_cast<const BYTE*>(pSrc->pData) + pSrc->SlicePitch * z;
1344  for (UINT y = 0; y < NumRows; ++y)
1345  {
1346  memcpy(pDestSlice + pDest->RowPitch * y,
1347  pSrcSlice + pSrc->RowPitch * y,
1348  RowSizeInBytes);
1349  }
1350  }
1351 }
1352 
1353 //------------------------------------------------------------------------------------------------
1354 // Returns required size of a buffer to be used for data upload
1355 inline UINT64 GetRequiredIntermediateSize(
1356  _In_ ID3D12Resource* pDestinationResource,
1357  _In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
1358  _In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources)
1359 {
1360  D3D12_RESOURCE_DESC Desc = pDestinationResource->GetDesc();
1361  UINT64 RequiredSize = 0;
1362 
1363  ID3D12Device* pDevice;
1364  pDestinationResource->GetDevice(__uuidof(*pDevice), reinterpret_cast<void**>(&pDevice));
1365  pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, 0, nullptr, nullptr, nullptr, &RequiredSize);
1366  pDevice->Release();
1367 
1368  return RequiredSize;
1369 }
1370 
1371 //------------------------------------------------------------------------------------------------
1372 // All arrays must be populated (e.g. by calling GetCopyableFootprints)
1373 inline UINT64 UpdateSubresources(
1374  _In_ ID3D12GraphicsCommandList* pCmdList,
1375  _In_ ID3D12Resource* pDestinationResource,
1376  _In_ ID3D12Resource* pIntermediate,
1377  _In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
1378  _In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources,
1379  UINT64 RequiredSize,
1380  _In_reads_(NumSubresources) const D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts,
1381  _In_reads_(NumSubresources) const UINT* pNumRows,
1382  _In_reads_(NumSubresources) const UINT64* pRowSizesInBytes,
1383  _In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData)
1384 {
1385  // Minor validation
1386  D3D12_RESOURCE_DESC IntermediateDesc = pIntermediate->GetDesc();
1387  D3D12_RESOURCE_DESC DestinationDesc = pDestinationResource->GetDesc();
1388  if (IntermediateDesc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER ||
1389  IntermediateDesc.Width < RequiredSize + pLayouts[0].Offset ||
1390  RequiredSize > static_cast<std::size_t>(-1) ||
1391  (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER &&
1392  (FirstSubresource != 0 || NumSubresources != 1)))
1393  {
1394  return 0;
1395  }
1396 
1397  BYTE* pData;
1398  HRESULT hr = pIntermediate->Map(0, nullptr, reinterpret_cast<void**>(&pData));
1399  if (FAILED(hr))
1400  {
1401  return 0;
1402  }
1403 
1404  for (UINT i = 0; i < NumSubresources; ++i)
1405  {
1406  if (pRowSizesInBytes[i] > static_cast<std::size_t>(-1)) return 0;
1407  D3D12_MEMCPY_DEST DestData = { pData + pLayouts[i].Offset, pLayouts[i].Footprint.RowPitch, pLayouts[i].Footprint.RowPitch * pNumRows[i] };
1408  MemcpySubresource(&DestData, &pSrcData[i], static_cast<std::size_t>(pRowSizesInBytes[i]), pNumRows[i], pLayouts[i].Footprint.Depth);
1409  }
1410  pIntermediate->Unmap(0, nullptr);
1411 
1412  if (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
1413  {
1414  CD3DX12_BOX SrcBox( UINT( pLayouts[0].Offset ), UINT( pLayouts[0].Offset + pLayouts[0].Footprint.Width ) );
1415  pCmdList->CopyBufferRegion(
1416  pDestinationResource, 0, pIntermediate, pLayouts[0].Offset, pLayouts[0].Footprint.Width);
1417  }
1418  else
1419  {
1420  for (UINT i = 0; i < NumSubresources; ++i)
1421  {
1422  CD3DX12_TEXTURE_COPY_LOCATION Dst(pDestinationResource, i + FirstSubresource);
1423  CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]);
1424  pCmdList->CopyTextureRegion(&Dst, 0, 0, 0, &Src, nullptr);
1425  }
1426  }
1427  return RequiredSize;
1428 }
1429 
1430 //------------------------------------------------------------------------------------------------
1431 // Heap-allocating UpdateSubresources implementation
1432 inline UINT64 UpdateSubresources(
1433  _In_ ID3D12GraphicsCommandList* pCmdList,
1434  _In_ ID3D12Resource* pDestinationResource,
1435  _In_ ID3D12Resource* pIntermediate,
1436  UINT64 IntermediateOffset,
1437  _In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
1438  _In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources,
1439  _In_reads_(NumSubresources) D3D12_SUBRESOURCE_DATA* pSrcData)
1440 {
1441  UINT64 RequiredSize = 0;
1442  UINT64 MemToAlloc = static_cast<UINT64>(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(UINT) + sizeof(UINT64)) * NumSubresources;
1443  if (MemToAlloc > SIZE_MAX)
1444  {
1445  return 0;
1446  }
1447  void* pMem = HeapAlloc(GetProcessHeap(), 0, static_cast<std::size_t>(MemToAlloc));
1448  if (pMem == nullptr)
1449  {
1450  return 0;
1451  }
1452  D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts = reinterpret_cast<D3D12_PLACED_SUBRESOURCE_FOOTPRINT*>(pMem);
1453  UINT64* pRowSizesInBytes = reinterpret_cast<UINT64*>(pLayouts + NumSubresources);
1454  UINT* pNumRows = reinterpret_cast<UINT*>(pRowSizesInBytes + NumSubresources);
1455 
1456  D3D12_RESOURCE_DESC Desc = pDestinationResource->GetDesc();
1457  ID3D12Device* pDevice;
1458  pDestinationResource->GetDevice(__uuidof(*pDevice), reinterpret_cast<void**>(&pDevice));
1459  pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, pLayouts, pNumRows, pRowSizesInBytes, &RequiredSize);
1460  pDevice->Release();
1461 
1462  UINT64 Result = UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, pLayouts, pNumRows, pRowSizesInBytes, pSrcData);
1463  HeapFree(GetProcessHeap(), 0, pMem);
1464  return Result;
1465 }
1466 
1467 //------------------------------------------------------------------------------------------------
1468 // Stack-allocating UpdateSubresources implementation
1469 template <UINT MaxSubresources>
1470 inline UINT64 UpdateSubresources(
1471  _In_ ID3D12GraphicsCommandList* pCmdList,
1472  _In_ ID3D12Resource* pDestinationResource,
1473  _In_ ID3D12Resource* pIntermediate,
1474  UINT64 IntermediateOffset,
1475  _In_range_(0, MaxSubresources) UINT FirstSubresource,
1476  _In_range_(1, MaxSubresources - FirstSubresource) UINT NumSubresources,
1477  _In_reads_(NumSubresources) D3D12_SUBRESOURCE_DATA* pSrcData)
1478 {
1479  UINT64 RequiredSize = 0;
1480  D3D12_PLACED_SUBRESOURCE_FOOTPRINT Layouts[MaxSubresources];
1481  UINT NumRows[MaxSubresources];
1482  UINT64 RowSizesInBytes[MaxSubresources];
1483 
1484  D3D12_RESOURCE_DESC Desc = pDestinationResource->GetDesc();
1485  ID3D12Device* pDevice;
1486  pDestinationResource->GetDevice(__uuidof(*pDevice), reinterpret_cast<void**>(&pDevice));
1487  pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, Layouts, NumRows, RowSizesInBytes, &RequiredSize);
1488  pDevice->Release();
1489 
1490  return UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, Layouts, NumRows, RowSizesInBytes, pSrcData);
1491 }
1492 
1493 //------------------------------------------------------------------------------------------------
1494 inline bool D3D12IsLayoutOpaque( D3D12_TEXTURE_LAYOUT Layout )
1495 { return Layout == D3D12_TEXTURE_LAYOUT_UNKNOWN || Layout == D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE; }
1496 
1497 //------------------------------------------------------------------------------------------------
1498 inline ID3D12CommandList * const * CommandListCast(ID3D12GraphicsCommandList * const * pp)
1499 {
1500  // This cast is useful for passing strongly typed command list pointers into
1501  // ExecuteCommandLists.
1502  // This cast is valid as long as the const-ness is respected. D3D12 APIs do
1503  // respect the const-ness of their arguments.
1504  return reinterpret_cast<ID3D12CommandList * const *>(pp);
1505 }
1506 
1507 
1508 #endif // defined( __cplusplus )
1509 
1510 #endif //__D3DX12_H__
1511 
1512 
1513