15 #include <Utils/DebugUtils.h> 17 #if defined( __cplusplus ) 19 struct CD3DX12_DEFAULT {};
20 extern const DECLSPEC_SELECTANY CD3DX12_DEFAULT D3D12_DEFAULT;
23 inline bool operator==(
const D3D12_VIEWPORT& l,
const D3D12_VIEWPORT& r )
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;
30 inline bool operator!=(
const D3D12_VIEWPORT& l,
const D3D12_VIEWPORT& r )
31 {
return !( l == r ); }
34 struct CD3DX12_RECT :
public D3D12_RECT
38 explicit CD3DX12_RECT(
const D3D12_RECT& o ) :
41 explicit CD3DX12_RECT(
53 operator const D3D12_RECT&()
const {
return *
this; }
57 struct CD3DX12_BOX :
public D3D12_BOX
61 explicit CD3DX12_BOX(
const D3D12_BOX& o ) :
104 operator const D3D12_BOX&()
const {
return *
this; }
106 inline bool operator==(
const D3D12_BOX& l,
const D3D12_BOX& r )
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;
111 inline bool operator!=(
const D3D12_BOX& l,
const D3D12_BOX& r )
112 {
return !( l == r ); }
115 struct CD3DX12_DEPTH_STENCIL_DESC :
public D3D12_DEPTH_STENCIL_DESC
117 CD3DX12_DEPTH_STENCIL_DESC()
119 explicit CD3DX12_DEPTH_STENCIL_DESC(
const D3D12_DEPTH_STENCIL_DESC& o ) :
120 D3D12_DEPTH_STENCIL_DESC( o )
122 explicit CD3DX12_DEPTH_STENCIL_DESC( CD3DX12_DEFAULT )
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;
135 explicit CD3DX12_DEPTH_STENCIL_DESC(
137 D3D12_DEPTH_WRITE_MASK depthWriteMask,
138 D3D12_COMPARISON_FUNC depthFunc,
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 )
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;
166 ~CD3DX12_DEPTH_STENCIL_DESC() {}
167 operator const D3D12_DEPTH_STENCIL_DESC&()
const {
return *
this; }
171 struct CD3DX12_BLEND_DESC :
public D3D12_BLEND_DESC
175 explicit CD3DX12_BLEND_DESC(
const D3D12_BLEND_DESC& o ) :
176 D3D12_BLEND_DESC( o )
178 explicit CD3DX12_BLEND_DESC( CD3DX12_DEFAULT )
180 AlphaToCoverageEnable = FALSE;
181 IndependentBlendEnable = FALSE;
182 const D3D12_RENDER_TARGET_BLEND_DESC defaultRenderTargetBlendDesc =
185 D3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD,
186 D3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD,
188 D3D12_COLOR_WRITE_ENABLE_ALL,
190 for (UINT i = 0; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
191 RenderTarget[ i ] = defaultRenderTargetBlendDesc;
193 ~CD3DX12_BLEND_DESC() {}
194 operator const D3D12_BLEND_DESC&()
const {
return *
this; }
198 struct CD3DX12_RASTERIZER_DESC :
public D3D12_RASTERIZER_DESC
200 CD3DX12_RASTERIZER_DESC()
202 explicit CD3DX12_RASTERIZER_DESC(
const D3D12_RASTERIZER_DESC& o ) :
203 D3D12_RASTERIZER_DESC( o )
205 explicit CD3DX12_RASTERIZER_DESC( CD3DX12_DEFAULT )
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;
219 explicit CD3DX12_RASTERIZER_DESC(
220 D3D12_FILL_MODE fillMode,
221 D3D12_CULL_MODE cullMode,
222 BOOL frontCounterClockwise,
224 FLOAT depthBiasClamp,
225 FLOAT slopeScaledDepthBias,
226 BOOL depthClipEnable,
227 BOOL multisampleEnable,
228 BOOL antialiasedLineEnable,
229 UINT forcedSampleCount,
230 D3D12_CONSERVATIVE_RASTERIZATION_MODE conservativeRaster)
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;
244 ~CD3DX12_RASTERIZER_DESC() {}
245 operator const D3D12_RASTERIZER_DESC&()
const {
return *
this; }
249 struct CD3DX12_RESOURCE_ALLOCATION_INFO :
public D3D12_RESOURCE_ALLOCATION_INFO
251 CD3DX12_RESOURCE_ALLOCATION_INFO()
253 explicit CD3DX12_RESOURCE_ALLOCATION_INFO(
const D3D12_RESOURCE_ALLOCATION_INFO& o ) :
254 D3D12_RESOURCE_ALLOCATION_INFO( o )
256 CD3DX12_RESOURCE_ALLOCATION_INFO(
261 Alignment = alignment;
263 operator const D3D12_RESOURCE_ALLOCATION_INFO&()
const {
return *
this; }
267 struct CD3DX12_HEAP_PROPERTIES :
public D3D12_HEAP_PROPERTIES
269 CD3DX12_HEAP_PROPERTIES()
271 explicit CD3DX12_HEAP_PROPERTIES(
const D3D12_HEAP_PROPERTIES &o) :
272 D3D12_HEAP_PROPERTIES(o)
274 CD3DX12_HEAP_PROPERTIES(
275 D3D12_CPU_PAGE_PROPERTY cpuPageProperty,
276 D3D12_MEMORY_POOL memoryPoolPreference,
277 UINT creationNodeMask = 1,
280 Type = D3D12_HEAP_TYPE_CUSTOM;
281 CPUPageProperty = cpuPageProperty;
282 MemoryPoolPreference = memoryPoolPreference;
283 CreationNodeMask = creationNodeMask;
284 VisibleNodeMask = nodeMask;
286 explicit CD3DX12_HEAP_PROPERTIES(
287 D3D12_HEAP_TYPE type,
288 UINT creationNodeMask = 1,
292 CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
293 MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
294 CreationNodeMask = creationNodeMask;
295 VisibleNodeMask = nodeMask;
297 operator const D3D12_HEAP_PROPERTIES&()
const {
return *
this; }
298 bool IsCPUAccessible()
const 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));
304 inline bool operator==(
const D3D12_HEAP_PROPERTIES& l,
const D3D12_HEAP_PROPERTIES& r )
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;
311 inline bool operator!=(
const D3D12_HEAP_PROPERTIES& l,
const D3D12_HEAP_PROPERTIES& r )
312 {
return !( l == r ); }
315 struct CD3DX12_HEAP_DESC :
public D3D12_HEAP_DESC
319 explicit CD3DX12_HEAP_DESC(
const D3D12_HEAP_DESC &o) :
324 D3D12_HEAP_PROPERTIES properties,
325 UINT64 alignment = 0,
326 D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE )
329 Properties = properties;
330 Alignment = alignment;
335 D3D12_HEAP_TYPE type,
336 UINT64 alignment = 0,
337 D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE )
340 Properties = CD3DX12_HEAP_PROPERTIES( type );
341 Alignment = alignment;
346 D3D12_CPU_PAGE_PROPERTY cpuPageProperty,
347 D3D12_MEMORY_POOL memoryPoolPreference,
348 UINT64 alignment = 0,
349 D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE )
352 Properties = CD3DX12_HEAP_PROPERTIES( cpuPageProperty, memoryPoolPreference );
353 Alignment = alignment;
357 const D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,
358 D3D12_HEAP_PROPERTIES properties,
359 D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE )
361 SizeInBytes = resAllocInfo.SizeInBytes;
362 Properties = properties;
363 Alignment = resAllocInfo.Alignment;
367 const D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,
368 D3D12_HEAP_TYPE type,
369 D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE )
371 SizeInBytes = resAllocInfo.SizeInBytes;
372 Properties = CD3DX12_HEAP_PROPERTIES( type );
373 Alignment = resAllocInfo.Alignment;
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 )
382 SizeInBytes = resAllocInfo.SizeInBytes;
383 Properties = CD3DX12_HEAP_PROPERTIES( cpuPageProperty, memoryPoolPreference );
384 Alignment = resAllocInfo.Alignment;
387 operator const D3D12_HEAP_DESC&()
const {
return *
this; }
388 bool IsCPUAccessible()
const 389 {
return static_cast< const CD3DX12_HEAP_PROPERTIES*
>( &Properties )->IsCPUAccessible(); }
391 inline bool operator==(
const D3D12_HEAP_DESC& l,
const D3D12_HEAP_DESC& r )
393 return l.SizeInBytes == r.SizeInBytes &&
394 l.Properties == r.Properties &&
395 l.Alignment == r.Alignment &&
398 inline bool operator!=(
const D3D12_HEAP_DESC& l,
const D3D12_HEAP_DESC& r )
399 {
return !( l == r ); }
402 struct CD3DX12_CLEAR_VALUE :
public D3D12_CLEAR_VALUE
404 CD3DX12_CLEAR_VALUE()
406 explicit CD3DX12_CLEAR_VALUE(
const D3D12_CLEAR_VALUE &o) :
411 const FLOAT color[4] )
414 memcpy( Color, color,
sizeof( Color ) );
423 memcpy( &DepthStencil.Depth, &depth,
sizeof( depth ) );
424 DepthStencil.Stencil = stencil;
426 operator const D3D12_CLEAR_VALUE&()
const {
return *
this; }
430 struct CD3DX12_RANGE :
public D3D12_RANGE
434 explicit CD3DX12_RANGE(
const D3D12_RANGE &o) :
444 operator const D3D12_RANGE&()
const {
return *
this; }
448 struct CD3DX12_TILED_RESOURCE_COORDINATE :
public D3D12_TILED_RESOURCE_COORDINATE
450 CD3DX12_TILED_RESOURCE_COORDINATE()
452 explicit CD3DX12_TILED_RESOURCE_COORDINATE(
const D3D12_TILED_RESOURCE_COORDINATE &o) :
453 D3D12_TILED_RESOURCE_COORDINATE(o)
455 CD3DX12_TILED_RESOURCE_COORDINATE(
464 Subresource = subresource;
466 operator const D3D12_TILED_RESOURCE_COORDINATE&()
const {
return *
this; }
470 struct CD3DX12_TILE_REGION_SIZE :
public D3D12_TILE_REGION_SIZE
472 CD3DX12_TILE_REGION_SIZE()
474 explicit CD3DX12_TILE_REGION_SIZE(
const D3D12_TILE_REGION_SIZE &o) :
475 D3D12_TILE_REGION_SIZE(o)
477 CD3DX12_TILE_REGION_SIZE(
490 operator const D3D12_TILE_REGION_SIZE&()
const {
return *
this; }
494 struct CD3DX12_SUBRESOURCE_TILING :
public D3D12_SUBRESOURCE_TILING
496 CD3DX12_SUBRESOURCE_TILING()
498 explicit CD3DX12_SUBRESOURCE_TILING(
const D3D12_SUBRESOURCE_TILING &o) :
499 D3D12_SUBRESOURCE_TILING(o)
501 CD3DX12_SUBRESOURCE_TILING(
503 UINT16 heightInTiles,
505 UINT startTileIndexInOverallResource )
507 WidthInTiles = widthInTiles;
508 HeightInTiles = heightInTiles;
509 DepthInTiles = depthInTiles;
510 StartTileIndexInOverallResource = startTileIndexInOverallResource;
512 operator const D3D12_SUBRESOURCE_TILING&()
const {
return *
this; }
516 struct CD3DX12_TILE_SHAPE :
public D3D12_TILE_SHAPE
520 explicit CD3DX12_TILE_SHAPE(
const D3D12_TILE_SHAPE &o) :
528 WidthInTexels = widthInTexels;
529 HeightInTexels = heightInTexels;
530 DepthInTexels = depthInTexels;
532 operator const D3D12_TILE_SHAPE&()
const {
return *
this; }
536 struct CD3DX12_RESOURCE_BARRIER :
public D3D12_RESOURCE_BARRIER
538 CD3DX12_RESOURCE_BARRIER()
540 explicit CD3DX12_RESOURCE_BARRIER(
const D3D12_RESOURCE_BARRIER &o) :
541 D3D12_RESOURCE_BARRIER(o)
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)
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;
561 static inline CD3DX12_RESOURCE_BARRIER Aliasing(
562 _In_ ID3D12Resource* pResourceBefore,
563 _In_ ID3D12Resource* pResourceAfter)
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;
573 static inline CD3DX12_RESOURCE_BARRIER UAV(
574 _In_ ID3D12Resource* pResource)
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;
583 operator const D3D12_RESOURCE_BARRIER&()
const {
return *
this; }
587 struct CD3DX12_PACKED_MIP_INFO :
public D3D12_PACKED_MIP_INFO
589 CD3DX12_PACKED_MIP_INFO()
591 explicit CD3DX12_PACKED_MIP_INFO(
const D3D12_PACKED_MIP_INFO &o) :
592 D3D12_PACKED_MIP_INFO(o)
594 CD3DX12_PACKED_MIP_INFO(
595 UINT8 numStandardMips,
597 UINT numTilesForPackedMips,
598 UINT startTileIndexInOverallResource )
600 NumStandardMips = numStandardMips;
601 NumPackedMips = numPackedMips;
602 NumTilesForPackedMips = numTilesForPackedMips;
603 StartTileIndexInOverallResource = startTileIndexInOverallResource;
605 operator const D3D12_PACKED_MIP_INFO&()
const {
return *
this; }
609 struct CD3DX12_SUBRESOURCE_FOOTPRINT :
public D3D12_SUBRESOURCE_FOOTPRINT
611 CD3DX12_SUBRESOURCE_FOOTPRINT()
613 explicit CD3DX12_SUBRESOURCE_FOOTPRINT(
const D3D12_SUBRESOURCE_FOOTPRINT &o) :
614 D3D12_SUBRESOURCE_FOOTPRINT(o)
616 CD3DX12_SUBRESOURCE_FOOTPRINT(
629 explicit CD3DX12_SUBRESOURCE_FOOTPRINT(
630 const D3D12_RESOURCE_DESC& resDesc,
633 Format = resDesc.Format;
634 Width = UINT( resDesc.Width );
635 Height = resDesc.Height;
636 Depth = (resDesc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? resDesc.DepthOrArraySize : 1);
639 operator const D3D12_SUBRESOURCE_FOOTPRINT&()
const {
return *
this; }
643 struct CD3DX12_TEXTURE_COPY_LOCATION :
public D3D12_TEXTURE_COPY_LOCATION
645 CD3DX12_TEXTURE_COPY_LOCATION()
647 explicit CD3DX12_TEXTURE_COPY_LOCATION(
const D3D12_TEXTURE_COPY_LOCATION &o) :
648 D3D12_TEXTURE_COPY_LOCATION(o)
650 CD3DX12_TEXTURE_COPY_LOCATION(ID3D12Resource* pRes) { pResource = pRes; }
651 CD3DX12_TEXTURE_COPY_LOCATION(ID3D12Resource* pRes, D3D12_PLACED_SUBRESOURCE_FOOTPRINT
const& Footprint)
654 Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
655 PlacedFootprint = Footprint;
657 CD3DX12_TEXTURE_COPY_LOCATION(ID3D12Resource* pRes, UINT Sub)
660 Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
661 SubresourceIndex = Sub;
666 struct CD3DX12_DESCRIPTOR_RANGE :
public D3D12_DESCRIPTOR_RANGE
668 CD3DX12_DESCRIPTOR_RANGE() { }
669 explicit CD3DX12_DESCRIPTOR_RANGE(
const D3D12_DESCRIPTOR_RANGE &o) :
670 D3D12_DESCRIPTOR_RANGE(o)
672 CD3DX12_DESCRIPTOR_RANGE(
673 D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
675 UINT baseShaderRegister,
676 UINT registerSpace = 0,
677 UINT offsetInDescriptorsFromTableStart =
678 D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
680 Init(rangeType, numDescriptors, baseShaderRegister, registerSpace, offsetInDescriptorsFromTableStart);
684 D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
686 UINT baseShaderRegister,
687 UINT registerSpace = 0,
688 UINT offsetInDescriptorsFromTableStart =
689 D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
691 Init(*
this, rangeType, numDescriptors, baseShaderRegister, registerSpace, offsetInDescriptorsFromTableStart);
694 static inline void Init(
695 _Out_ D3D12_DESCRIPTOR_RANGE &range,
696 D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
698 UINT baseShaderRegister,
699 UINT registerSpace = 0,
700 UINT offsetInDescriptorsFromTableStart =
701 D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
703 range.RangeType = rangeType;
704 range.NumDescriptors = numDescriptors;
705 range.BaseShaderRegister = baseShaderRegister;
706 range.RegisterSpace = registerSpace;
707 range.OffsetInDescriptorsFromTableStart = offsetInDescriptorsFromTableStart;
712 struct CD3DX12_ROOT_DESCRIPTOR_TABLE :
public D3D12_ROOT_DESCRIPTOR_TABLE
714 CD3DX12_ROOT_DESCRIPTOR_TABLE() {}
715 explicit CD3DX12_ROOT_DESCRIPTOR_TABLE(
const D3D12_ROOT_DESCRIPTOR_TABLE &o) :
716 D3D12_ROOT_DESCRIPTOR_TABLE(o)
718 CD3DX12_ROOT_DESCRIPTOR_TABLE(
719 UINT numDescriptorRanges,
720 _In_reads_opt_(numDescriptorRanges)
const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges)
722 BRE_ASSERT(_pDescriptorRanges !=
nullptr);
723 Init(numDescriptorRanges, _pDescriptorRanges);
727 UINT numDescriptorRanges,
728 _In_reads_(numDescriptorRanges)
const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges)
730 BRE_ASSERT(_pDescriptorRanges !=
nullptr);
731 Init(*
this, numDescriptorRanges, _pDescriptorRanges);
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)
739 BRE_ASSERT(_pDescriptorRanges !=
nullptr);
740 rootDescriptorTable.NumDescriptorRanges = numDescriptorRanges;
741 rootDescriptorTable.pDescriptorRanges = _pDescriptorRanges;
746 struct CD3DX12_ROOT_CONSTANTS :
public D3D12_ROOT_CONSTANTS
748 CD3DX12_ROOT_CONSTANTS() {}
749 explicit CD3DX12_ROOT_CONSTANTS(
const D3D12_ROOT_CONSTANTS &o) :
750 D3D12_ROOT_CONSTANTS(o)
752 CD3DX12_ROOT_CONSTANTS(
755 UINT registerSpace = 0)
757 Init(num32BitValues, shaderRegister, registerSpace);
763 UINT registerSpace = 0)
765 Init(*
this, num32BitValues, shaderRegister, registerSpace);
768 static inline void Init(
769 _Out_ D3D12_ROOT_CONSTANTS &rootConstants,
772 UINT registerSpace = 0)
774 rootConstants.Num32BitValues = num32BitValues;
775 rootConstants.ShaderRegister = shaderRegister;
776 rootConstants.RegisterSpace = registerSpace;
781 struct CD3DX12_ROOT_DESCRIPTOR :
public D3D12_ROOT_DESCRIPTOR
783 CD3DX12_ROOT_DESCRIPTOR() {}
784 explicit CD3DX12_ROOT_DESCRIPTOR(
const D3D12_ROOT_DESCRIPTOR &o) :
785 D3D12_ROOT_DESCRIPTOR(o)
787 CD3DX12_ROOT_DESCRIPTOR(
789 UINT registerSpace = 0)
791 Init(shaderRegister, registerSpace);
796 UINT registerSpace = 0)
798 Init(*
this, shaderRegister, registerSpace);
801 static inline void Init(_Out_ D3D12_ROOT_DESCRIPTOR &table, UINT shaderRegister, UINT registerSpace = 0)
803 table.ShaderRegister = shaderRegister;
804 table.RegisterSpace = registerSpace;
809 struct CD3DX12_ROOT_PARAMETER :
public D3D12_ROOT_PARAMETER
811 CD3DX12_ROOT_PARAMETER() {}
812 explicit CD3DX12_ROOT_PARAMETER(
const D3D12_ROOT_PARAMETER &o) :
813 D3D12_ROOT_PARAMETER(o)
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)
822 rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
823 rootParam.ShaderVisibility = visibility;
824 CD3DX12_ROOT_DESCRIPTOR_TABLE::Init(rootParam.DescriptorTable, numDescriptorRanges, pDescriptorRanges);
827 static inline void InitAsConstants(
828 _Out_ D3D12_ROOT_PARAMETER &rootParam,
831 UINT registerSpace = 0,
832 D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
834 rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
835 rootParam.ShaderVisibility = visibility;
836 CD3DX12_ROOT_CONSTANTS::Init(rootParam.Constants, num32BitValues, shaderRegister, registerSpace);
839 static inline void InitAsConstantBufferView(
840 _Out_ D3D12_ROOT_PARAMETER &rootParam,
842 UINT registerSpace = 0,
843 D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
845 rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
846 rootParam.ShaderVisibility = visibility;
847 CD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister, registerSpace);
850 static inline void InitAsShaderResourceView(
851 _Out_ D3D12_ROOT_PARAMETER &rootParam,
853 UINT registerSpace = 0,
854 D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
856 rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;
857 rootParam.ShaderVisibility = visibility;
858 CD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister, registerSpace);
861 static inline void InitAsUnorderedAccessView(
862 _Out_ D3D12_ROOT_PARAMETER &rootParam,
864 UINT registerSpace = 0,
865 D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
867 rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV;
868 rootParam.ShaderVisibility = visibility;
869 CD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister, registerSpace);
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)
877 InitAsDescriptorTable(*
this, numDescriptorRanges, pDescriptorRanges, visibility);
880 inline void InitAsConstants(
883 UINT registerSpace = 0,
884 D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
886 InitAsConstants(*
this, num32BitValues, shaderRegister, registerSpace, visibility);
889 inline void InitAsConstantBufferView(
891 UINT registerSpace = 0,
892 D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
894 InitAsConstantBufferView(*
this, shaderRegister, registerSpace, visibility);
897 inline void InitAsShaderResourceView(
899 UINT registerSpace = 0,
900 D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
902 InitAsShaderResourceView(*
this, shaderRegister, registerSpace, visibility);
905 inline void InitAsUnorderedAccessView(
907 UINT registerSpace = 0,
908 D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
910 InitAsUnorderedAccessView(*
this, shaderRegister, registerSpace, visibility);
915 struct CD3DX12_STATIC_SAMPLER_DESC :
public D3D12_STATIC_SAMPLER_DESC
917 CD3DX12_STATIC_SAMPLER_DESC() {}
918 explicit CD3DX12_STATIC_SAMPLER_DESC(
const D3D12_STATIC_SAMPLER_DESC &o) :
919 D3D12_STATIC_SAMPLER_DESC(o)
921 CD3DX12_STATIC_SAMPLER_DESC(
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,
932 FLOAT maxLOD = D3D12_FLOAT32_MAX,
933 D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
934 UINT registerSpace = 0)
952 static inline void Init(
953 _Out_ D3D12_STATIC_SAMPLER_DESC &samplerDesc,
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,
964 FLOAT maxLOD = D3D12_FLOAT32_MAX,
965 D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
966 UINT registerSpace = 0)
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;
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,
993 FLOAT maxLOD = D3D12_FLOAT32_MAX,
994 D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
995 UINT registerSpace = 0)
1017 struct CD3DX12_ROOT_SIGNATURE_DESC :
public D3D12_ROOT_SIGNATURE_DESC
1019 CD3DX12_ROOT_SIGNATURE_DESC() {}
1020 explicit CD3DX12_ROOT_SIGNATURE_DESC(
const D3D12_ROOT_SIGNATURE_DESC &o) :
1021 D3D12_ROOT_SIGNATURE_DESC(o)
1023 CD3DX12_ROOT_SIGNATURE_DESC(
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)
1030 Init(numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
1032 CD3DX12_ROOT_SIGNATURE_DESC(CD3DX12_DEFAULT)
1034 Init(0,
nullptr, 0,
nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
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)
1044 Init(*
this, numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
1047 static inline void Init(
1048 _Out_ D3D12_ROOT_SIGNATURE_DESC &desc,
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)
1055 desc.NumParameters = numParameters;
1056 desc.pParameters = _pParameters;
1057 desc.NumStaticSamplers = numStaticSamplers;
1058 desc.pStaticSamplers = _pStaticSamplers;
1064 struct CD3DX12_CPU_DESCRIPTOR_HANDLE :
public D3D12_CPU_DESCRIPTOR_HANDLE
1066 CD3DX12_CPU_DESCRIPTOR_HANDLE() {}
1067 explicit CD3DX12_CPU_DESCRIPTOR_HANDLE(
const D3D12_CPU_DESCRIPTOR_HANDLE &o) :
1068 D3D12_CPU_DESCRIPTOR_HANDLE(o)
1070 CD3DX12_CPU_DESCRIPTOR_HANDLE(CD3DX12_DEFAULT) { ptr = 0; }
1071 CD3DX12_CPU_DESCRIPTOR_HANDLE(_In_
const D3D12_CPU_DESCRIPTOR_HANDLE &other, INT offsetScaledByIncrementSize)
1073 InitOffsetted(other, offsetScaledByIncrementSize);
1075 CD3DX12_CPU_DESCRIPTOR_HANDLE(_In_
const D3D12_CPU_DESCRIPTOR_HANDLE &other, INT offsetInDescriptors, UINT descriptorIncrementSize)
1077 InitOffsetted(other, offsetInDescriptors, descriptorIncrementSize);
1079 CD3DX12_CPU_DESCRIPTOR_HANDLE& Offset(INT offsetInDescriptors, UINT descriptorIncrementSize)
1081 ptr += offsetInDescriptors * descriptorIncrementSize;
1084 CD3DX12_CPU_DESCRIPTOR_HANDLE& Offset(INT offsetScaledByIncrementSize)
1086 ptr += offsetScaledByIncrementSize;
1089 bool operator==(_In_
const D3D12_CPU_DESCRIPTOR_HANDLE& other)
const 1091 return (ptr == other.ptr);
1093 bool operator!=(_In_
const D3D12_CPU_DESCRIPTOR_HANDLE& other)
const 1095 return (ptr != other.ptr);
1097 CD3DX12_CPU_DESCRIPTOR_HANDLE &operator=(
const D3D12_CPU_DESCRIPTOR_HANDLE &other)
1103 inline void InitOffsetted(_In_
const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize)
1105 InitOffsetted(*
this, base, offsetScaledByIncrementSize);
1108 inline void InitOffsetted(_In_
const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize)
1110 InitOffsetted(*
this, base, offsetInDescriptors, descriptorIncrementSize);
1113 static inline void InitOffsetted(_Out_ D3D12_CPU_DESCRIPTOR_HANDLE &handle, _In_
const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize)
1115 handle.ptr = base.ptr + offsetScaledByIncrementSize;
1118 static inline void InitOffsetted(_Out_ D3D12_CPU_DESCRIPTOR_HANDLE &handle, _In_
const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize)
1120 handle.ptr = base.ptr + offsetInDescriptors * descriptorIncrementSize;
1125 struct CD3DX12_GPU_DESCRIPTOR_HANDLE :
public D3D12_GPU_DESCRIPTOR_HANDLE
1127 CD3DX12_GPU_DESCRIPTOR_HANDLE() {}
1128 explicit CD3DX12_GPU_DESCRIPTOR_HANDLE(
const D3D12_GPU_DESCRIPTOR_HANDLE &o) :
1129 D3D12_GPU_DESCRIPTOR_HANDLE(o)
1131 CD3DX12_GPU_DESCRIPTOR_HANDLE(CD3DX12_DEFAULT) { ptr = 0; }
1132 CD3DX12_GPU_DESCRIPTOR_HANDLE(_In_
const D3D12_GPU_DESCRIPTOR_HANDLE &other, INT offsetScaledByIncrementSize)
1134 InitOffsetted(other, offsetScaledByIncrementSize);
1136 CD3DX12_GPU_DESCRIPTOR_HANDLE(_In_
const D3D12_GPU_DESCRIPTOR_HANDLE &other, INT offsetInDescriptors, UINT descriptorIncrementSize)
1138 InitOffsetted(other, offsetInDescriptors, descriptorIncrementSize);
1140 CD3DX12_GPU_DESCRIPTOR_HANDLE& Offset(INT offsetInDescriptors, UINT descriptorIncrementSize)
1142 ptr += offsetInDescriptors * descriptorIncrementSize;
1145 CD3DX12_GPU_DESCRIPTOR_HANDLE& Offset(INT offsetScaledByIncrementSize)
1147 ptr += offsetScaledByIncrementSize;
1150 inline bool operator==(_In_
const D3D12_GPU_DESCRIPTOR_HANDLE& other)
const 1152 return (ptr == other.ptr);
1154 inline bool operator!=(_In_
const D3D12_GPU_DESCRIPTOR_HANDLE& other)
const 1156 return (ptr != other.ptr);
1158 CD3DX12_GPU_DESCRIPTOR_HANDLE &operator=(
const D3D12_GPU_DESCRIPTOR_HANDLE &other)
1164 inline void InitOffsetted(_In_
const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize)
1166 InitOffsetted(*
this, base, offsetScaledByIncrementSize);
1169 inline void InitOffsetted(_In_
const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize)
1171 InitOffsetted(*
this, base, offsetInDescriptors, descriptorIncrementSize);
1174 static inline void InitOffsetted(_Out_ D3D12_GPU_DESCRIPTOR_HANDLE &handle, _In_
const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize)
1176 handle.ptr = base.ptr + offsetScaledByIncrementSize;
1179 static inline void InitOffsetted(_Out_ D3D12_GPU_DESCRIPTOR_HANDLE &handle, _In_
const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize)
1181 handle.ptr = base.ptr + offsetInDescriptors * descriptorIncrementSize;
1186 inline UINT D3D12CalcSubresource( UINT MipSlice, UINT ArraySlice, UINT PlaneSlice, UINT MipLevels, UINT ArraySize )
1188 return MipSlice + ArraySlice * MipLevels + PlaneSlice * MipLevels * ArraySize;
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 )
1195 MipSlice =
static_cast<T
>(Subresource % MipLevels);
1196 ArraySlice =
static_cast<U
>((Subresource / MipLevels) % ArraySize);
1197 PlaneSlice =
static_cast<V
>(Subresource / (MipLevels * ArraySize));
1201 inline UINT8 D3D12GetFormatPlaneCount(
1202 _In_ ID3D12Device* pDevice,
1206 D3D12_FEATURE_DATA_FORMAT_INFO formatInfo = {Format};
1207 if (FAILED(pDevice->CheckFeatureSupport(D3D12_FEATURE_FORMAT_INFO, &formatInfo,
sizeof(formatInfo))))
1211 return formatInfo.PlaneCount;
1215 struct CD3DX12_RESOURCE_DESC :
public D3D12_RESOURCE_DESC
1217 CD3DX12_RESOURCE_DESC()
1219 explicit CD3DX12_RESOURCE_DESC(
const D3D12_RESOURCE_DESC& o ) :
1220 D3D12_RESOURCE_DESC( o )
1222 CD3DX12_RESOURCE_DESC(
1223 D3D12_RESOURCE_DIMENSION dimension,
1227 UINT16 depthOrArraySize,
1232 D3D12_TEXTURE_LAYOUT layout,
1233 D3D12_RESOURCE_FLAGS flags )
1235 Dimension = dimension;
1236 Alignment = alignment;
1239 DepthOrArraySize = depthOrArraySize;
1240 MipLevels = mipLevels;
1242 SampleDesc.Count = sampleCount;
1243 SampleDesc.Quality = sampleQuality;
1247 static inline CD3DX12_RESOURCE_DESC Buffer(
1248 const D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,
1249 D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE )
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 );
1254 static inline CD3DX12_RESOURCE_DESC Buffer(
1256 D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
1257 UINT64 alignment = 0 )
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 );
1262 static inline CD3DX12_RESOURCE_DESC Tex1D(
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 )
1271 return CD3DX12_RESOURCE_DESC( D3D12_RESOURCE_DIMENSION_TEXTURE1D, alignment, width, 1, arraySize,
1272 mipLevels, format, 1, 0, layout, flags );
1274 static inline CD3DX12_RESOURCE_DESC Tex2D(
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 )
1286 return CD3DX12_RESOURCE_DESC( D3D12_RESOURCE_DIMENSION_TEXTURE2D, alignment, width, height, arraySize,
1287 mipLevels, format, sampleCount, sampleQuality, layout, flags );
1289 static inline CD3DX12_RESOURCE_DESC Tex3D(
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 )
1299 return CD3DX12_RESOURCE_DESC( D3D12_RESOURCE_DIMENSION_TEXTURE3D, alignment, width, height, depth,
1300 mipLevels, format, 1, 0, layout, flags );
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; }
1314 inline bool operator==(
const D3D12_RESOURCE_DESC& l,
const D3D12_RESOURCE_DESC& r )
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 &&
1328 inline bool operator!=(
const D3D12_RESOURCE_DESC& l,
const D3D12_RESOURCE_DESC& r )
1329 {
return !( l == r ); }
1333 inline void MemcpySubresource(
1334 _In_
const D3D12_MEMCPY_DEST* pDest,
1335 _In_
const D3D12_SUBRESOURCE_DATA* pSrc,
1336 std::size_t RowSizeInBytes,
1340 for (UINT z = 0; z < NumSlices; ++z)
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)
1346 memcpy(pDestSlice + pDest->RowPitch * y,
1347 pSrcSlice + pSrc->RowPitch * y,
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)
1360 D3D12_RESOURCE_DESC Desc = pDestinationResource->GetDesc();
1361 UINT64 RequiredSize = 0;
1363 ID3D12Device* pDevice;
1364 pDestinationResource->GetDevice(__uuidof(*pDevice), reinterpret_cast<void**>(&pDevice));
1365 pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, 0,
nullptr,
nullptr,
nullptr, &RequiredSize);
1368 return RequiredSize;
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)
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)))
1398 HRESULT hr = pIntermediate->Map(0,
nullptr, reinterpret_cast<void**>(&pData));
1404 for (UINT i = 0; i < NumSubresources; ++i)
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);
1410 pIntermediate->Unmap(0,
nullptr);
1412 if (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
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);
1420 for (UINT i = 0; i < NumSubresources; ++i)
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);
1427 return RequiredSize;
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)
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)
1447 void* pMem = HeapAlloc(GetProcessHeap(), 0, static_cast<std::size_t>(MemToAlloc));
1448 if (pMem ==
nullptr)
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);
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);
1462 UINT64 Result = UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, pLayouts, pNumRows, pRowSizesInBytes, pSrcData);
1463 HeapFree(GetProcessHeap(), 0, pMem);
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)
1479 UINT64 RequiredSize = 0;
1480 D3D12_PLACED_SUBRESOURCE_FOOTPRINT Layouts[MaxSubresources];
1481 UINT NumRows[MaxSubresources];
1482 UINT64 RowSizesInBytes[MaxSubresources];
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);
1490 return UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, Layouts, NumRows, RowSizesInBytes, pSrcData);
1494 inline bool D3D12IsLayoutOpaque( D3D12_TEXTURE_LAYOUT Layout )
1495 {
return Layout == D3D12_TEXTURE_LAYOUT_UNKNOWN || Layout == D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE; }
1498 inline ID3D12CommandList *
const * CommandListCast(ID3D12GraphicsCommandList *
const * pp)
1504 return reinterpret_cast<ID3D12CommandList *
const *
>(pp);
1508 #endif // defined( __cplusplus ) 1510 #endif //__D3DX12_H__