15 #if defined( __cplusplus ) 17 struct CD3DX12_DEFAULT {};
18 extern const DECLSPEC_SELECTANY CD3DX12_DEFAULT D3D12_DEFAULT;
21 inline bool operator==(
const D3D12_VIEWPORT& l,
const D3D12_VIEWPORT& r )
23 return l.TopLeftX == r.TopLeftX && l.TopLeftY == r.TopLeftY && l.Width == r.Width &&
24 l.Height == r.Height && l.MinDepth == r.MinDepth && l.MaxDepth == r.MaxDepth;
28 inline bool operator!=(
const D3D12_VIEWPORT& l,
const D3D12_VIEWPORT& r )
29 {
return !( l == r ); }
32 struct CD3DX12_RECT :
public D3D12_RECT
36 explicit CD3DX12_RECT(
const D3D12_RECT& o ) :
39 explicit CD3DX12_RECT(
51 operator const D3D12_RECT&()
const {
return *
this; }
55 struct CD3DX12_BOX :
public D3D12_BOX
59 explicit CD3DX12_BOX(
const D3D12_BOX& o ) :
102 operator const D3D12_BOX&()
const {
return *
this; }
104 inline bool operator==(
const D3D12_BOX& l,
const D3D12_BOX& r )
106 return l.left == r.left && l.top == r.top && l.front == r.front &&
107 l.right == r.right && l.bottom == r.bottom && l.back == r.back;
109 inline bool operator!=(
const D3D12_BOX& l,
const D3D12_BOX& r )
110 {
return !( l == r ); }
113 struct CD3DX12_DEPTH_STENCIL_DESC :
public D3D12_DEPTH_STENCIL_DESC
115 CD3DX12_DEPTH_STENCIL_DESC()
117 explicit CD3DX12_DEPTH_STENCIL_DESC(
const D3D12_DEPTH_STENCIL_DESC& o ) :
118 D3D12_DEPTH_STENCIL_DESC( o )
120 explicit CD3DX12_DEPTH_STENCIL_DESC( CD3DX12_DEFAULT )
123 DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
124 DepthFunc = D3D12_COMPARISON_FUNC_LESS;
125 StencilEnable = FALSE;
126 StencilReadMask = D3D12_DEFAULT_STENCIL_READ_MASK;
127 StencilWriteMask = D3D12_DEFAULT_STENCIL_WRITE_MASK;
128 const D3D12_DEPTH_STENCILOP_DESC defaultStencilOp =
129 { D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_COMPARISON_FUNC_ALWAYS };
130 FrontFace = defaultStencilOp;
131 BackFace = defaultStencilOp;
133 explicit CD3DX12_DEPTH_STENCIL_DESC(
135 D3D12_DEPTH_WRITE_MASK depthWriteMask,
136 D3D12_COMPARISON_FUNC depthFunc,
138 UINT8 stencilReadMask,
139 UINT8 stencilWriteMask,
140 D3D12_STENCIL_OP frontStencilFailOp,
141 D3D12_STENCIL_OP frontStencilDepthFailOp,
142 D3D12_STENCIL_OP frontStencilPassOp,
143 D3D12_COMPARISON_FUNC frontStencilFunc,
144 D3D12_STENCIL_OP backStencilFailOp,
145 D3D12_STENCIL_OP backStencilDepthFailOp,
146 D3D12_STENCIL_OP backStencilPassOp,
147 D3D12_COMPARISON_FUNC backStencilFunc )
149 DepthEnable = depthEnable;
150 DepthWriteMask = depthWriteMask;
151 DepthFunc = depthFunc;
152 StencilEnable = stencilEnable;
153 StencilReadMask = stencilReadMask;
154 StencilWriteMask = stencilWriteMask;
155 FrontFace.StencilFailOp = frontStencilFailOp;
156 FrontFace.StencilDepthFailOp = frontStencilDepthFailOp;
157 FrontFace.StencilPassOp = frontStencilPassOp;
158 FrontFace.StencilFunc = frontStencilFunc;
159 BackFace.StencilFailOp = backStencilFailOp;
160 BackFace.StencilDepthFailOp = backStencilDepthFailOp;
161 BackFace.StencilPassOp = backStencilPassOp;
162 BackFace.StencilFunc = backStencilFunc;
164 ~CD3DX12_DEPTH_STENCIL_DESC() {}
165 operator const D3D12_DEPTH_STENCIL_DESC&()
const {
return *
this; }
169 struct CD3DX12_BLEND_DESC :
public D3D12_BLEND_DESC
173 explicit CD3DX12_BLEND_DESC(
const D3D12_BLEND_DESC& o ) :
174 D3D12_BLEND_DESC( o )
176 explicit CD3DX12_BLEND_DESC( CD3DX12_DEFAULT )
178 AlphaToCoverageEnable = FALSE;
179 IndependentBlendEnable = FALSE;
180 const D3D12_RENDER_TARGET_BLEND_DESC defaultRenderTargetBlendDesc =
183 D3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD,
184 D3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD,
186 D3D12_COLOR_WRITE_ENABLE_ALL,
188 for (UINT i = 0; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
191 ~CD3DX12_BLEND_DESC() {}
192 operator const D3D12_BLEND_DESC&()
const {
return *
this; }
196 struct CD3DX12_RASTERIZER_DESC :
public D3D12_RASTERIZER_DESC
198 CD3DX12_RASTERIZER_DESC()
200 explicit CD3DX12_RASTERIZER_DESC(
const D3D12_RASTERIZER_DESC& o ) :
201 D3D12_RASTERIZER_DESC( o )
203 explicit CD3DX12_RASTERIZER_DESC( CD3DX12_DEFAULT )
205 FillMode = D3D12_FILL_MODE_SOLID;
206 CullMode = D3D12_CULL_MODE_BACK;
207 FrontCounterClockwise = FALSE;
208 DepthBias = D3D12_DEFAULT_DEPTH_BIAS;
209 DepthBiasClamp = D3D12_DEFAULT_DEPTH_BIAS_CLAMP;
210 SlopeScaledDepthBias = D3D12_DEFAULT_SLOPE_SCALED_DEPTH_BIAS;
211 DepthClipEnable = TRUE;
212 MultisampleEnable = FALSE;
213 AntialiasedLineEnable = FALSE;
214 ForcedSampleCount = 0;
215 ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF;
217 explicit CD3DX12_RASTERIZER_DESC(
218 D3D12_FILL_MODE fillMode,
219 D3D12_CULL_MODE cullMode,
220 BOOL frontCounterClockwise,
222 FLOAT depthBiasClamp,
223 FLOAT slopeScaledDepthBias,
224 BOOL depthClipEnable,
225 BOOL multisampleEnable,
226 BOOL antialiasedLineEnable,
227 UINT forcedSampleCount,
228 D3D12_CONSERVATIVE_RASTERIZATION_MODE conservativeRaster)
232 FrontCounterClockwise = frontCounterClockwise;
233 DepthBias = depthBias;
234 DepthBiasClamp = depthBiasClamp;
235 SlopeScaledDepthBias = slopeScaledDepthBias;
236 DepthClipEnable = depthClipEnable;
237 MultisampleEnable = multisampleEnable;
238 AntialiasedLineEnable = antialiasedLineEnable;
239 ForcedSampleCount = forcedSampleCount;
240 ConservativeRaster = conservativeRaster;
242 ~CD3DX12_RASTERIZER_DESC() {}
243 operator const D3D12_RASTERIZER_DESC&()
const {
return *
this; }
247 struct CD3DX12_RESOURCE_ALLOCATION_INFO :
public D3D12_RESOURCE_ALLOCATION_INFO
249 CD3DX12_RESOURCE_ALLOCATION_INFO()
251 explicit CD3DX12_RESOURCE_ALLOCATION_INFO(
const D3D12_RESOURCE_ALLOCATION_INFO& o ) :
252 D3D12_RESOURCE_ALLOCATION_INFO( o )
254 CD3DX12_RESOURCE_ALLOCATION_INFO(
259 Alignment = alignment;
261 operator const D3D12_RESOURCE_ALLOCATION_INFO&()
const {
return *
this; }
265 struct CD3DX12_HEAP_PROPERTIES :
public D3D12_HEAP_PROPERTIES
267 CD3DX12_HEAP_PROPERTIES()
269 explicit CD3DX12_HEAP_PROPERTIES(
const D3D12_HEAP_PROPERTIES &o) :
270 D3D12_HEAP_PROPERTIES(o)
272 CD3DX12_HEAP_PROPERTIES(
273 D3D12_CPU_PAGE_PROPERTY cpuPageProperty,
274 D3D12_MEMORY_POOL memoryPoolPreference,
275 UINT creationNodeMask = 1,
278 Type = D3D12_HEAP_TYPE_CUSTOM;
279 CPUPageProperty = cpuPageProperty;
280 MemoryPoolPreference = memoryPoolPreference;
281 CreationNodeMask = creationNodeMask;
282 VisibleNodeMask = nodeMask;
284 explicit CD3DX12_HEAP_PROPERTIES(
285 D3D12_HEAP_TYPE type,
286 UINT creationNodeMask = 1,
290 CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
291 MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
292 CreationNodeMask = creationNodeMask;
293 VisibleNodeMask = nodeMask;
295 operator const D3D12_HEAP_PROPERTIES&()
const {
return *
this; }
296 bool IsCPUAccessible()
const 298 return Type == D3D12_HEAP_TYPE_UPLOAD || Type == D3D12_HEAP_TYPE_READBACK || (Type == D3D12_HEAP_TYPE_CUSTOM &&
299 (CPUPageProperty == D3D12_CPU_PAGE_PROPERTY_WRITE_COMBINE || CPUPageProperty == D3D12_CPU_PAGE_PROPERTY_WRITE_BACK));
302 inline bool operator==(
const D3D12_HEAP_PROPERTIES& l,
const D3D12_HEAP_PROPERTIES& r )
304 return l.Type == r.Type && l.CPUPageProperty == r.CPUPageProperty &&
305 l.MemoryPoolPreference == r.MemoryPoolPreference &&
306 l.CreationNodeMask == r.CreationNodeMask &&
307 l.VisibleNodeMask == r.VisibleNodeMask;
309 inline bool operator!=(
const D3D12_HEAP_PROPERTIES& l,
const D3D12_HEAP_PROPERTIES& r )
310 {
return !( l == r ); }
313 struct CD3DX12_HEAP_DESC :
public D3D12_HEAP_DESC
317 explicit CD3DX12_HEAP_DESC(
const D3D12_HEAP_DESC &o) :
322 D3D12_HEAP_PROPERTIES properties,
323 UINT64 alignment = 0,
324 D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE )
327 Properties = properties;
328 Alignment = alignment;
333 D3D12_HEAP_TYPE type,
334 UINT64 alignment = 0,
335 D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE )
338 Properties = CD3DX12_HEAP_PROPERTIES( type );
339 Alignment = alignment;
344 D3D12_CPU_PAGE_PROPERTY cpuPageProperty,
345 D3D12_MEMORY_POOL memoryPoolPreference,
346 UINT64 alignment = 0,
347 D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE )
350 Properties = CD3DX12_HEAP_PROPERTIES( cpuPageProperty, memoryPoolPreference );
351 Alignment = alignment;
355 const D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,
356 D3D12_HEAP_PROPERTIES properties,
357 D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE )
359 SizeInBytes = resAllocInfo.SizeInBytes;
360 Properties = properties;
361 Alignment = resAllocInfo.Alignment;
365 const D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,
366 D3D12_HEAP_TYPE type,
367 D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE )
369 SizeInBytes = resAllocInfo.SizeInBytes;
370 Properties = CD3DX12_HEAP_PROPERTIES( type );
371 Alignment = resAllocInfo.Alignment;
375 const D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,
376 D3D12_CPU_PAGE_PROPERTY cpuPageProperty,
377 D3D12_MEMORY_POOL memoryPoolPreference,
378 D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE )
380 SizeInBytes = resAllocInfo.SizeInBytes;
381 Properties = CD3DX12_HEAP_PROPERTIES( cpuPageProperty, memoryPoolPreference );
382 Alignment = resAllocInfo.Alignment;
385 operator const D3D12_HEAP_DESC&()
const {
return *
this; }
386 bool IsCPUAccessible()
const 387 {
return static_cast< const CD3DX12_HEAP_PROPERTIES*
>( &Properties )->IsCPUAccessible(); }
389 inline bool operator==(
const D3D12_HEAP_DESC& l,
const D3D12_HEAP_DESC& r )
391 return l.SizeInBytes == r.SizeInBytes &&
392 l.Properties == r.Properties &&
393 l.Alignment == r.Alignment &&
396 inline bool operator!=(
const D3D12_HEAP_DESC& l,
const D3D12_HEAP_DESC& r )
397 {
return !( l == r ); }
400 struct CD3DX12_CLEAR_VALUE :
public D3D12_CLEAR_VALUE
402 CD3DX12_CLEAR_VALUE()
404 explicit CD3DX12_CLEAR_VALUE(
const D3D12_CLEAR_VALUE &o) :
409 const FLOAT color[4] )
412 memcpy( Color, color,
sizeof( Color ) );
421 memcpy( &DepthStencil.Depth, &depth,
sizeof( depth ) );
422 DepthStencil.Stencil = stencil;
424 operator const D3D12_CLEAR_VALUE&()
const {
return *
this; }
428 struct CD3DX12_RANGE :
public D3D12_RANGE
432 explicit CD3DX12_RANGE(
const D3D12_RANGE &o) :
442 operator const D3D12_RANGE&()
const {
return *
this; }
446 struct CD3DX12_SHADER_BYTECODE :
public D3D12_SHADER_BYTECODE
448 CD3DX12_SHADER_BYTECODE()
450 explicit CD3DX12_SHADER_BYTECODE(
const D3D12_SHADER_BYTECODE &o) :
451 D3D12_SHADER_BYTECODE(o)
453 CD3DX12_SHADER_BYTECODE(
454 ID3DBlob* pShaderBlob )
456 pShaderBytecode = pShaderBlob->GetBufferPointer();
457 BytecodeLength = pShaderBlob->GetBufferSize();
459 CD3DX12_SHADER_BYTECODE(
460 void* _pShaderBytecode,
461 SIZE_T bytecodeLength )
463 pShaderBytecode = _pShaderBytecode;
464 BytecodeLength = bytecodeLength;
466 operator const D3D12_SHADER_BYTECODE&()
const {
return *
this; }
470 struct CD3DX12_TILED_RESOURCE_COORDINATE :
public D3D12_TILED_RESOURCE_COORDINATE
472 CD3DX12_TILED_RESOURCE_COORDINATE()
474 explicit CD3DX12_TILED_RESOURCE_COORDINATE(
const D3D12_TILED_RESOURCE_COORDINATE &o) :
475 D3D12_TILED_RESOURCE_COORDINATE(o)
477 CD3DX12_TILED_RESOURCE_COORDINATE(
486 Subresource = subresource;
488 operator const D3D12_TILED_RESOURCE_COORDINATE&()
const {
return *
this; }
492 struct CD3DX12_TILE_REGION_SIZE :
public D3D12_TILE_REGION_SIZE
494 CD3DX12_TILE_REGION_SIZE()
496 explicit CD3DX12_TILE_REGION_SIZE(
const D3D12_TILE_REGION_SIZE &o) :
497 D3D12_TILE_REGION_SIZE(o)
499 CD3DX12_TILE_REGION_SIZE(
512 operator const D3D12_TILE_REGION_SIZE&()
const {
return *
this; }
516 struct CD3DX12_SUBRESOURCE_TILING :
public D3D12_SUBRESOURCE_TILING
518 CD3DX12_SUBRESOURCE_TILING()
520 explicit CD3DX12_SUBRESOURCE_TILING(
const D3D12_SUBRESOURCE_TILING &o) :
521 D3D12_SUBRESOURCE_TILING(o)
523 CD3DX12_SUBRESOURCE_TILING(
525 UINT16 heightInTiles,
527 UINT startTileIndexInOverallResource )
529 WidthInTiles = widthInTiles;
530 HeightInTiles = heightInTiles;
531 DepthInTiles = depthInTiles;
532 StartTileIndexInOverallResource = startTileIndexInOverallResource;
534 operator const D3D12_SUBRESOURCE_TILING&()
const {
return *
this; }
538 struct CD3DX12_TILE_SHAPE :
public D3D12_TILE_SHAPE
542 explicit CD3DX12_TILE_SHAPE(
const D3D12_TILE_SHAPE &o) :
550 WidthInTexels = widthInTexels;
551 HeightInTexels = heightInTexels;
552 DepthInTexels = depthInTexels;
554 operator const D3D12_TILE_SHAPE&()
const {
return *
this; }
558 struct CD3DX12_RESOURCE_BARRIER :
public D3D12_RESOURCE_BARRIER
560 CD3DX12_RESOURCE_BARRIER()
562 explicit CD3DX12_RESOURCE_BARRIER(
const D3D12_RESOURCE_BARRIER &o) :
563 D3D12_RESOURCE_BARRIER(o)
565 static inline CD3DX12_RESOURCE_BARRIER Transition(
566 _In_ ID3D12Resource* pResource,
567 D3D12_RESOURCE_STATES stateBefore,
568 D3D12_RESOURCE_STATES stateAfter,
569 UINT subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
570 D3D12_RESOURCE_BARRIER_FLAGS flags = D3D12_RESOURCE_BARRIER_FLAG_NONE)
572 CD3DX12_RESOURCE_BARRIER result;
573 ZeroMemory(&result,
sizeof(result));
574 D3D12_RESOURCE_BARRIER &barrier = result;
575 result.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
576 result.Flags = flags;
577 barrier.Transition.pResource = pResource;
578 barrier.Transition.StateBefore = stateBefore;
579 barrier.Transition.StateAfter = stateAfter;
580 barrier.Transition.Subresource = subresource;
583 static inline CD3DX12_RESOURCE_BARRIER Aliasing(
584 _In_ ID3D12Resource* pResourceBefore,
585 _In_ ID3D12Resource* pResourceAfter)
587 CD3DX12_RESOURCE_BARRIER result;
588 ZeroMemory(&result,
sizeof(result));
589 D3D12_RESOURCE_BARRIER &barrier = result;
590 result.Type = D3D12_RESOURCE_BARRIER_TYPE_ALIASING;
591 barrier.Aliasing.pResourceBefore = pResourceBefore;
592 barrier.Aliasing.pResourceAfter = pResourceAfter;
595 static inline CD3DX12_RESOURCE_BARRIER UAV(
596 _In_ ID3D12Resource* pResource)
598 CD3DX12_RESOURCE_BARRIER result;
599 ZeroMemory(&result,
sizeof(result));
600 D3D12_RESOURCE_BARRIER &barrier = result;
601 result.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
602 barrier.UAV.pResource = pResource;
605 operator const D3D12_RESOURCE_BARRIER&()
const {
return *
this; }
609 struct CD3DX12_PACKED_MIP_INFO :
public D3D12_PACKED_MIP_INFO
611 CD3DX12_PACKED_MIP_INFO()
613 explicit CD3DX12_PACKED_MIP_INFO(
const D3D12_PACKED_MIP_INFO &o) :
614 D3D12_PACKED_MIP_INFO(o)
616 CD3DX12_PACKED_MIP_INFO(
617 UINT8 numStandardMips,
619 UINT numTilesForPackedMips,
620 UINT startTileIndexInOverallResource )
622 NumStandardMips = numStandardMips;
623 NumPackedMips = numPackedMips;
624 NumTilesForPackedMips = numTilesForPackedMips;
625 StartTileIndexInOverallResource = startTileIndexInOverallResource;
627 operator const D3D12_PACKED_MIP_INFO&()
const {
return *
this; }
631 struct CD3DX12_SUBRESOURCE_FOOTPRINT :
public D3D12_SUBRESOURCE_FOOTPRINT
633 CD3DX12_SUBRESOURCE_FOOTPRINT()
635 explicit CD3DX12_SUBRESOURCE_FOOTPRINT(
const D3D12_SUBRESOURCE_FOOTPRINT &o) :
636 D3D12_SUBRESOURCE_FOOTPRINT(o)
638 CD3DX12_SUBRESOURCE_FOOTPRINT(
651 explicit CD3DX12_SUBRESOURCE_FOOTPRINT(
652 const D3D12_RESOURCE_DESC& resDesc,
655 Format = resDesc.Format;
656 Width = UINT( resDesc.Width );
657 Height = resDesc.Height;
658 Depth = (resDesc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? resDesc.DepthOrArraySize : 1);
661 operator const D3D12_SUBRESOURCE_FOOTPRINT&()
const {
return *
this; }
665 struct CD3DX12_TEXTURE_COPY_LOCATION :
public D3D12_TEXTURE_COPY_LOCATION
667 CD3DX12_TEXTURE_COPY_LOCATION()
669 explicit CD3DX12_TEXTURE_COPY_LOCATION(
const D3D12_TEXTURE_COPY_LOCATION &o) :
670 D3D12_TEXTURE_COPY_LOCATION(o)
672 CD3DX12_TEXTURE_COPY_LOCATION(ID3D12Resource* pRes) { pResource = pRes; }
673 CD3DX12_TEXTURE_COPY_LOCATION(ID3D12Resource* pRes, D3D12_PLACED_SUBRESOURCE_FOOTPRINT
const& Footprint)
676 Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
677 PlacedFootprint = Footprint;
679 CD3DX12_TEXTURE_COPY_LOCATION(ID3D12Resource* pRes, UINT Sub)
682 Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
683 SubresourceIndex = Sub;
688 struct CD3DX12_DESCRIPTOR_RANGE :
public D3D12_DESCRIPTOR_RANGE
690 CD3DX12_DESCRIPTOR_RANGE() { }
691 explicit CD3DX12_DESCRIPTOR_RANGE(
const D3D12_DESCRIPTOR_RANGE &o) :
692 D3D12_DESCRIPTOR_RANGE(o)
694 CD3DX12_DESCRIPTOR_RANGE(
695 D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
697 UINT baseShaderRegister,
698 UINT registerSpace = 0,
699 UINT offsetInDescriptorsFromTableStart =
700 D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
702 Init(rangeType, numDescriptors, baseShaderRegister, registerSpace, offsetInDescriptorsFromTableStart);
706 D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
708 UINT baseShaderRegister,
709 UINT registerSpace = 0,
710 UINT offsetInDescriptorsFromTableStart =
711 D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
713 Init(*
this, rangeType, numDescriptors, baseShaderRegister, registerSpace, offsetInDescriptorsFromTableStart);
716 static inline void Init(
717 _Out_ D3D12_DESCRIPTOR_RANGE &range,
718 D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
720 UINT baseShaderRegister,
721 UINT registerSpace = 0,
722 UINT offsetInDescriptorsFromTableStart =
723 D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
725 range.RangeType = rangeType;
726 range.NumDescriptors = numDescriptors;
727 range.BaseShaderRegister = baseShaderRegister;
728 range.RegisterSpace = registerSpace;
729 range.OffsetInDescriptorsFromTableStart = offsetInDescriptorsFromTableStart;
734 struct CD3DX12_ROOT_DESCRIPTOR_TABLE :
public D3D12_ROOT_DESCRIPTOR_TABLE
736 CD3DX12_ROOT_DESCRIPTOR_TABLE() {}
737 explicit CD3DX12_ROOT_DESCRIPTOR_TABLE(
const D3D12_ROOT_DESCRIPTOR_TABLE &o) :
738 D3D12_ROOT_DESCRIPTOR_TABLE(o)
740 CD3DX12_ROOT_DESCRIPTOR_TABLE(
741 UINT numDescriptorRanges,
742 _In_reads_opt_(numDescriptorRanges)
const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges)
744 Init(numDescriptorRanges, _pDescriptorRanges);
748 UINT numDescriptorRanges,
749 _In_reads_opt_(numDescriptorRanges)
const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges)
751 Init(*
this, numDescriptorRanges, _pDescriptorRanges);
754 static inline void Init(
755 _Out_ D3D12_ROOT_DESCRIPTOR_TABLE &rootDescriptorTable,
756 UINT numDescriptorRanges,
757 _In_reads_opt_(numDescriptorRanges)
const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges)
759 rootDescriptorTable.NumDescriptorRanges = numDescriptorRanges;
760 rootDescriptorTable.pDescriptorRanges = _pDescriptorRanges;
765 struct CD3DX12_ROOT_CONSTANTS :
public D3D12_ROOT_CONSTANTS
767 CD3DX12_ROOT_CONSTANTS() {}
768 explicit CD3DX12_ROOT_CONSTANTS(
const D3D12_ROOT_CONSTANTS &o) :
769 D3D12_ROOT_CONSTANTS(o)
771 CD3DX12_ROOT_CONSTANTS(
774 UINT registerSpace = 0)
776 Init(num32BitValues, shaderRegister, registerSpace);
782 UINT registerSpace = 0)
784 Init(*
this, num32BitValues, shaderRegister, registerSpace);
787 static inline void Init(
788 _Out_ D3D12_ROOT_CONSTANTS &rootConstants,
791 UINT registerSpace = 0)
793 rootConstants.Num32BitValues = num32BitValues;
794 rootConstants.ShaderRegister = shaderRegister;
795 rootConstants.RegisterSpace = registerSpace;
800 struct CD3DX12_ROOT_DESCRIPTOR :
public D3D12_ROOT_DESCRIPTOR
802 CD3DX12_ROOT_DESCRIPTOR() {}
803 explicit CD3DX12_ROOT_DESCRIPTOR(
const D3D12_ROOT_DESCRIPTOR &o) :
804 D3D12_ROOT_DESCRIPTOR(o)
806 CD3DX12_ROOT_DESCRIPTOR(
808 UINT registerSpace = 0)
810 Init(shaderRegister, registerSpace);
815 UINT registerSpace = 0)
817 Init(*
this, shaderRegister, registerSpace);
820 static inline void Init(_Out_ D3D12_ROOT_DESCRIPTOR &table, UINT shaderRegister, UINT registerSpace = 0)
822 table.ShaderRegister = shaderRegister;
823 table.RegisterSpace = registerSpace;
828 struct CD3DX12_ROOT_PARAMETER :
public D3D12_ROOT_PARAMETER
830 CD3DX12_ROOT_PARAMETER() {}
831 explicit CD3DX12_ROOT_PARAMETER(
const D3D12_ROOT_PARAMETER &o) :
832 D3D12_ROOT_PARAMETER(o)
835 static inline void InitAsDescriptorTable(
836 _Out_ D3D12_ROOT_PARAMETER &rootParam,
837 UINT numDescriptorRanges,
838 _In_reads_(numDescriptorRanges)
const D3D12_DESCRIPTOR_RANGE* pDescriptorRanges,
839 D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
841 rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
842 rootParam.ShaderVisibility = visibility;
843 CD3DX12_ROOT_DESCRIPTOR_TABLE::Init(rootParam.DescriptorTable, numDescriptorRanges, pDescriptorRanges);
846 static inline void InitAsConstants(
847 _Out_ D3D12_ROOT_PARAMETER &rootParam,
850 UINT registerSpace = 0,
851 D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
853 rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
854 rootParam.ShaderVisibility = visibility;
855 CD3DX12_ROOT_CONSTANTS::Init(rootParam.Constants, num32BitValues, shaderRegister, registerSpace);
858 static inline void InitAsConstantBufferView(
859 _Out_ D3D12_ROOT_PARAMETER &rootParam,
861 UINT registerSpace = 0,
862 D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
864 rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
865 rootParam.ShaderVisibility = visibility;
866 CD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister, registerSpace);
869 static inline void InitAsShaderResourceView(
870 _Out_ D3D12_ROOT_PARAMETER &rootParam,
872 UINT registerSpace = 0,
873 D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
875 rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;
876 rootParam.ShaderVisibility = visibility;
877 CD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister, registerSpace);
880 static inline void InitAsUnorderedAccessView(
881 _Out_ D3D12_ROOT_PARAMETER &rootParam,
883 UINT registerSpace = 0,
884 D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
886 rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV;
887 rootParam.ShaderVisibility = visibility;
888 CD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister, registerSpace);
891 inline void InitAsDescriptorTable(
892 UINT numDescriptorRanges,
893 _In_reads_(numDescriptorRanges)
const D3D12_DESCRIPTOR_RANGE* pDescriptorRanges,
894 D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
896 InitAsDescriptorTable(*
this, numDescriptorRanges, pDescriptorRanges, visibility);
899 inline void InitAsConstants(
902 UINT registerSpace = 0,
903 D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
905 InitAsConstants(*
this, num32BitValues, shaderRegister, registerSpace, visibility);
908 inline void InitAsConstantBufferView(
910 UINT registerSpace = 0,
911 D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
913 InitAsConstantBufferView(*
this, shaderRegister, registerSpace, visibility);
916 inline void InitAsShaderResourceView(
918 UINT registerSpace = 0,
919 D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
921 InitAsShaderResourceView(*
this, shaderRegister, registerSpace, visibility);
924 inline void InitAsUnorderedAccessView(
926 UINT registerSpace = 0,
927 D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)
929 InitAsUnorderedAccessView(*
this, shaderRegister, registerSpace, visibility);
934 struct CD3DX12_STATIC_SAMPLER_DESC :
public D3D12_STATIC_SAMPLER_DESC
936 CD3DX12_STATIC_SAMPLER_DESC() {}
937 explicit CD3DX12_STATIC_SAMPLER_DESC(
const D3D12_STATIC_SAMPLER_DESC &o) :
938 D3D12_STATIC_SAMPLER_DESC(o)
940 CD3DX12_STATIC_SAMPLER_DESC(
942 D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
943 D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
944 D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
945 D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
946 FLOAT mipLODBias = 0,
947 UINT maxAnisotropy = 16,
948 D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
949 D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
951 FLOAT maxLOD = D3D12_FLOAT32_MAX,
952 D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
953 UINT registerSpace = 0)
971 static inline void Init(
972 _Out_ D3D12_STATIC_SAMPLER_DESC &samplerDesc,
974 D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
975 D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
976 D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
977 D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
978 FLOAT mipLODBias = 0,
979 UINT maxAnisotropy = 16,
980 D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
981 D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
983 FLOAT maxLOD = D3D12_FLOAT32_MAX,
984 D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
985 UINT registerSpace = 0)
987 samplerDesc.ShaderRegister = shaderRegister;
988 samplerDesc.Filter = filter;
989 samplerDesc.AddressU = addressU;
990 samplerDesc.AddressV = addressV;
991 samplerDesc.AddressW = addressW;
992 samplerDesc.MipLODBias = mipLODBias;
993 samplerDesc.MaxAnisotropy = maxAnisotropy;
994 samplerDesc.ComparisonFunc = comparisonFunc;
995 samplerDesc.BorderColor = borderColor;
996 samplerDesc.MinLOD = minLOD;
997 samplerDesc.MaxLOD = maxLOD;
998 samplerDesc.ShaderVisibility = shaderVisibility;
999 samplerDesc.RegisterSpace = registerSpace;
1002 UINT shaderRegister,
1003 D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
1004 D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
1005 D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
1006 D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
1007 FLOAT mipLODBias = 0,
1008 UINT maxAnisotropy = 16,
1009 D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
1010 D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
1012 FLOAT maxLOD = D3D12_FLOAT32_MAX,
1013 D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
1014 UINT registerSpace = 0)
1036 struct CD3DX12_ROOT_SIGNATURE_DESC :
public D3D12_ROOT_SIGNATURE_DESC
1038 CD3DX12_ROOT_SIGNATURE_DESC() {}
1039 explicit CD3DX12_ROOT_SIGNATURE_DESC(
const D3D12_ROOT_SIGNATURE_DESC &o) :
1040 D3D12_ROOT_SIGNATURE_DESC(o)
1042 CD3DX12_ROOT_SIGNATURE_DESC(
1044 _In_reads_opt_(numParameters)
const D3D12_ROOT_PARAMETER* _pParameters,
1045 UINT numStaticSamplers = 0,
1046 _In_reads_opt_(numStaticSamplers)
const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = NULL,
1047 D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE)
1049 Init(numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
1051 CD3DX12_ROOT_SIGNATURE_DESC(CD3DX12_DEFAULT)
1053 Init(0, NULL, 0, NULL, D3D12_ROOT_SIGNATURE_FLAG_NONE);
1058 _In_reads_opt_(numParameters)
const D3D12_ROOT_PARAMETER* _pParameters,
1059 UINT numStaticSamplers = 0,
1060 _In_reads_opt_(numStaticSamplers)
const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = NULL,
1061 D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE)
1063 Init(*
this, numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
1066 static inline void Init(
1067 _Out_ D3D12_ROOT_SIGNATURE_DESC &desc,
1069 _In_reads_opt_(numParameters)
const D3D12_ROOT_PARAMETER* _pParameters,
1070 UINT numStaticSamplers = 0,
1071 _In_reads_opt_(numStaticSamplers)
const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = NULL,
1072 D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE)
1074 desc.NumParameters = numParameters;
1075 desc.pParameters = _pParameters;
1076 desc.NumStaticSamplers = numStaticSamplers;
1077 desc.pStaticSamplers = _pStaticSamplers;
1083 struct CD3DX12_CPU_DESCRIPTOR_HANDLE :
public D3D12_CPU_DESCRIPTOR_HANDLE
1085 CD3DX12_CPU_DESCRIPTOR_HANDLE() {}
1086 explicit CD3DX12_CPU_DESCRIPTOR_HANDLE(
const D3D12_CPU_DESCRIPTOR_HANDLE &o) :
1087 D3D12_CPU_DESCRIPTOR_HANDLE(o)
1089 CD3DX12_CPU_DESCRIPTOR_HANDLE(CD3DX12_DEFAULT) { ptr = 0; }
1090 CD3DX12_CPU_DESCRIPTOR_HANDLE(_In_
const D3D12_CPU_DESCRIPTOR_HANDLE &other, INT offsetScaledByIncrementSize)
1092 InitOffsetted(other, offsetScaledByIncrementSize);
1094 CD3DX12_CPU_DESCRIPTOR_HANDLE(_In_
const D3D12_CPU_DESCRIPTOR_HANDLE &other, INT offsetInDescriptors, UINT descriptorIncrementSize)
1096 InitOffsetted(other, offsetInDescriptors, descriptorIncrementSize);
1098 CD3DX12_CPU_DESCRIPTOR_HANDLE& Offset(INT offsetInDescriptors, UINT descriptorIncrementSize)
1100 ptr += offsetInDescriptors * descriptorIncrementSize;
1103 CD3DX12_CPU_DESCRIPTOR_HANDLE& Offset(INT offsetScaledByIncrementSize)
1105 ptr += offsetScaledByIncrementSize;
1108 bool operator==(_In_
const D3D12_CPU_DESCRIPTOR_HANDLE& other)
1110 return (ptr == other.ptr);
1112 bool operator!=(_In_
const D3D12_CPU_DESCRIPTOR_HANDLE& other)
1114 return (ptr != other.ptr);
1116 CD3DX12_CPU_DESCRIPTOR_HANDLE &operator=(
const D3D12_CPU_DESCRIPTOR_HANDLE &other)
1122 inline void InitOffsetted(_In_
const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize)
1124 InitOffsetted(*
this, base, offsetScaledByIncrementSize);
1127 inline void InitOffsetted(_In_
const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize)
1129 InitOffsetted(*
this, base, offsetInDescriptors, descriptorIncrementSize);
1132 static inline void InitOffsetted(_Out_ D3D12_CPU_DESCRIPTOR_HANDLE &handle, _In_
const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize)
1134 handle.ptr = base.ptr + offsetScaledByIncrementSize;
1137 static inline void InitOffsetted(_Out_ D3D12_CPU_DESCRIPTOR_HANDLE &handle, _In_
const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize)
1139 handle.ptr = base.ptr + offsetInDescriptors * descriptorIncrementSize;
1144 struct CD3DX12_GPU_DESCRIPTOR_HANDLE :
public D3D12_GPU_DESCRIPTOR_HANDLE
1146 CD3DX12_GPU_DESCRIPTOR_HANDLE() {}
1147 explicit CD3DX12_GPU_DESCRIPTOR_HANDLE(
const D3D12_GPU_DESCRIPTOR_HANDLE &o) :
1148 D3D12_GPU_DESCRIPTOR_HANDLE(o)
1150 CD3DX12_GPU_DESCRIPTOR_HANDLE(CD3DX12_DEFAULT) { ptr = 0; }
1151 CD3DX12_GPU_DESCRIPTOR_HANDLE(_In_
const D3D12_GPU_DESCRIPTOR_HANDLE &other, INT offsetScaledByIncrementSize)
1153 InitOffsetted(other, offsetScaledByIncrementSize);
1155 CD3DX12_GPU_DESCRIPTOR_HANDLE(_In_
const D3D12_GPU_DESCRIPTOR_HANDLE &other, INT offsetInDescriptors, UINT descriptorIncrementSize)
1157 InitOffsetted(other, offsetInDescriptors, descriptorIncrementSize);
1159 CD3DX12_GPU_DESCRIPTOR_HANDLE& Offset(INT offsetInDescriptors, UINT descriptorIncrementSize)
1161 ptr += offsetInDescriptors * descriptorIncrementSize;
1164 CD3DX12_GPU_DESCRIPTOR_HANDLE& Offset(INT offsetScaledByIncrementSize)
1166 ptr += offsetScaledByIncrementSize;
1169 inline bool operator==(_In_
const D3D12_GPU_DESCRIPTOR_HANDLE& other)
1171 return (ptr == other.ptr);
1173 inline bool operator!=(_In_
const D3D12_GPU_DESCRIPTOR_HANDLE& other)
1175 return (ptr != other.ptr);
1177 CD3DX12_GPU_DESCRIPTOR_HANDLE &operator=(
const D3D12_GPU_DESCRIPTOR_HANDLE &other)
1183 inline void InitOffsetted(_In_
const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize)
1185 InitOffsetted(*
this, base, offsetScaledByIncrementSize);
1188 inline void InitOffsetted(_In_
const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize)
1190 InitOffsetted(*
this, base, offsetInDescriptors, descriptorIncrementSize);
1193 static inline void InitOffsetted(_Out_ D3D12_GPU_DESCRIPTOR_HANDLE &handle, _In_
const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize)
1195 handle.ptr = base.ptr + offsetScaledByIncrementSize;
1198 static inline void InitOffsetted(_Out_ D3D12_GPU_DESCRIPTOR_HANDLE &handle, _In_
const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize)
1200 handle.ptr = base.ptr + offsetInDescriptors * descriptorIncrementSize;
1205 inline UINT D3D12CalcSubresource( UINT MipSlice, UINT ArraySlice, UINT PlaneSlice, UINT MipLevels, UINT ArraySize )
1207 return MipSlice + ArraySlice * MipLevels + PlaneSlice * MipLevels * ArraySize;
1211 template <
typename T,
typename U,
typename V>
1212 inline void D3D12DecomposeSubresource( UINT Subresource, UINT MipLevels, UINT ArraySize, _Out_ T& MipSlice, _Out_ U& ArraySlice, _Out_ V& PlaneSlice )
1214 MipSlice =
static_cast<T
>(Subresource % MipLevels);
1215 ArraySlice =
static_cast<U
>((Subresource / MipLevels) % ArraySize);
1216 PlaneSlice =
static_cast<V
>(Subresource / (MipLevels * ArraySize));
1220 inline UINT8 D3D12GetFormatPlaneCount(
1221 _In_ ID3D12Device* pDevice,
1225 D3D12_FEATURE_DATA_FORMAT_INFO formatInfo = {Format};
1226 if (FAILED(pDevice->CheckFeatureSupport(D3D12_FEATURE_FORMAT_INFO, &formatInfo,
sizeof(formatInfo))))
1230 return formatInfo.PlaneCount;
1234 struct CD3DX12_RESOURCE_DESC :
public D3D12_RESOURCE_DESC
1236 CD3DX12_RESOURCE_DESC()
1238 explicit CD3DX12_RESOURCE_DESC(
const D3D12_RESOURCE_DESC& o ) :
1239 D3D12_RESOURCE_DESC( o )
1241 CD3DX12_RESOURCE_DESC(
1242 D3D12_RESOURCE_DIMENSION dimension,
1246 UINT16 depthOrArraySize,
1251 D3D12_TEXTURE_LAYOUT layout,
1252 D3D12_RESOURCE_FLAGS flags )
1254 Dimension = dimension;
1255 Alignment = alignment;
1258 DepthOrArraySize = depthOrArraySize;
1259 MipLevels = mipLevels;
1261 SampleDesc.Count = sampleCount;
1262 SampleDesc.Quality = sampleQuality;
1266 static inline CD3DX12_RESOURCE_DESC Buffer(
1267 const D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,
1268 D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE )
1270 return CD3DX12_RESOURCE_DESC( D3D12_RESOURCE_DIMENSION_BUFFER, resAllocInfo.Alignment, resAllocInfo.SizeInBytes,
1271 1, 1, 1, DXGI_FORMAT_UNKNOWN, 1, 0, D3D12_TEXTURE_LAYOUT_ROW_MAJOR, flags );
1273 static inline CD3DX12_RESOURCE_DESC Buffer(
1275 D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
1276 UINT64 alignment = 0 )
1278 return CD3DX12_RESOURCE_DESC( D3D12_RESOURCE_DIMENSION_BUFFER, alignment, width, 1, 1, 1,
1279 DXGI_FORMAT_UNKNOWN, 1, 0, D3D12_TEXTURE_LAYOUT_ROW_MAJOR, flags );
1281 static inline CD3DX12_RESOURCE_DESC Tex1D(
1284 UINT16 arraySize = 1,
1285 UINT16 mipLevels = 0,
1286 D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
1287 D3D12_TEXTURE_LAYOUT layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,
1288 UINT64 alignment = 0 )
1290 return CD3DX12_RESOURCE_DESC( D3D12_RESOURCE_DIMENSION_TEXTURE1D, alignment, width, 1, arraySize,
1291 mipLevels, format, 1, 0, layout, flags );
1293 static inline CD3DX12_RESOURCE_DESC Tex2D(
1297 UINT16 arraySize = 1,
1298 UINT16 mipLevels = 0,
1299 UINT sampleCount = 1,
1300 UINT sampleQuality = 0,
1301 D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
1302 D3D12_TEXTURE_LAYOUT layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,
1303 UINT64 alignment = 0 )
1305 return CD3DX12_RESOURCE_DESC( D3D12_RESOURCE_DIMENSION_TEXTURE2D, alignment, width, height, arraySize,
1306 mipLevels, format, sampleCount, sampleQuality, layout, flags );
1308 static inline CD3DX12_RESOURCE_DESC Tex3D(
1313 UINT16 mipLevels = 0,
1314 D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
1315 D3D12_TEXTURE_LAYOUT layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,
1316 UINT64 alignment = 0 )
1318 return CD3DX12_RESOURCE_DESC( D3D12_RESOURCE_DIMENSION_TEXTURE3D, alignment, width, height, depth,
1319 mipLevels, format, 1, 0, layout, flags );
1321 inline UINT16 Depth()
const 1322 {
return (Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? DepthOrArraySize : 1); }
1323 inline UINT16 ArraySize()
const 1324 {
return (Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE3D ? DepthOrArraySize : 1); }
1325 inline UINT8 PlaneCount(_In_ ID3D12Device* pDevice)
const 1326 {
return D3D12GetFormatPlaneCount(pDevice, Format); }
1327 inline UINT Subresources(_In_ ID3D12Device* pDevice)
const 1328 {
return MipLevels * ArraySize() * PlaneCount(pDevice); }
1329 inline UINT CalcSubresource(UINT MipSlice, UINT ArraySlice, UINT PlaneSlice)
1330 {
return D3D12CalcSubresource(MipSlice, ArraySlice, PlaneSlice, MipLevels, ArraySize()); }
1331 operator const D3D12_RESOURCE_DESC&()
const {
return *
this; }
1333 inline bool operator==(
const D3D12_RESOURCE_DESC& l,
const D3D12_RESOURCE_DESC& r )
1335 return l.Dimension == r.Dimension &&
1336 l.Alignment == r.Alignment &&
1337 l.Width == r.Width &&
1338 l.Height == r.Height &&
1339 l.DepthOrArraySize == r.DepthOrArraySize &&
1340 l.MipLevels == r.MipLevels &&
1341 l.Format == r.Format &&
1342 l.SampleDesc.Count == r.SampleDesc.Count &&
1343 l.SampleDesc.Quality == r.SampleDesc.Quality &&
1344 l.Layout == r.Layout &&
1347 inline bool operator!=(
const D3D12_RESOURCE_DESC& l,
const D3D12_RESOURCE_DESC& r )
1348 {
return !( l == r ); }
1352 inline void MemcpySubresource(
1353 _In_
const D3D12_MEMCPY_DEST* pDest,
1354 _In_
const D3D12_SUBRESOURCE_DATA* pSrc,
1355 SIZE_T RowSizeInBytes,
1359 for (UINT z = 0; z < NumSlices; ++z)
1361 BYTE* pDestSlice =
reinterpret_cast<BYTE*
>(pDest->pData) + pDest->SlicePitch * z;
1362 const BYTE* pSrcSlice = reinterpret_cast<const BYTE*>(pSrc->pData) + pSrc->SlicePitch * z;
1363 for (UINT y = 0; y < NumRows; ++y)
1365 memcpy(pDestSlice + pDest->RowPitch * y,
1366 pSrcSlice + pSrc->RowPitch * y,
1374 inline UINT64 GetRequiredIntermediateSize(
1375 _In_ ID3D12Resource* pDestinationResource,
1376 _In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
1377 _In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources)
1379 D3D12_RESOURCE_DESC Desc = pDestinationResource->GetDesc();
1380 UINT64 RequiredSize = 0;
1382 ID3D12Device* pDevice;
1383 pDestinationResource->GetDevice(__uuidof(*pDevice), reinterpret_cast<void**>(&pDevice));
1384 pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, 0,
nullptr,
nullptr,
nullptr, &RequiredSize);
1387 return RequiredSize;
1392 inline UINT64 UpdateSubresources(
1393 _In_ ID3D12GraphicsCommandList* pCmdList,
1394 _In_ ID3D12Resource* pDestinationResource,
1395 _In_ ID3D12Resource* pIntermediate,
1396 _In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
1397 _In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources,
1398 UINT64 RequiredSize,
1399 _In_reads_(NumSubresources)
const D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts,
1400 _In_reads_(NumSubresources)
const UINT* pNumRows,
1401 _In_reads_(NumSubresources)
const UINT64* pRowSizesInBytes,
1402 _In_reads_(NumSubresources)
const D3D12_SUBRESOURCE_DATA* pSrcData)
1405 D3D12_RESOURCE_DESC IntermediateDesc = pIntermediate->GetDesc();
1406 D3D12_RESOURCE_DESC DestinationDesc = pDestinationResource->GetDesc();
1407 if (IntermediateDesc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER ||
1408 IntermediateDesc.Width < RequiredSize + pLayouts[0].Offset ||
1409 RequiredSize > (SIZE_T)-1 ||
1410 (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER &&
1411 (FirstSubresource != 0 || NumSubresources != 1)))
1417 HRESULT hr = pIntermediate->Map(0, NULL, reinterpret_cast<void**>(&pData));
1423 for (UINT i = 0; i < NumSubresources; ++i)
1425 if (pRowSizesInBytes[i] > (SIZE_T)-1)
return 0;
1426 D3D12_MEMCPY_DEST DestData = { pData + pLayouts[i].Offset, pLayouts[i].Footprint.RowPitch, pLayouts[i].Footprint.RowPitch * pNumRows[i] };
1427 MemcpySubresource(&DestData, &pSrcData[i], (SIZE_T)pRowSizesInBytes[i], pNumRows[i], pLayouts[i].Footprint.Depth);
1429 pIntermediate->Unmap(0, NULL);
1431 if (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
1433 CD3DX12_BOX SrcBox( UINT( pLayouts[0].Offset ), UINT( pLayouts[0].Offset + pLayouts[0].Footprint.Width ) );
1434 pCmdList->CopyBufferRegion(
1435 pDestinationResource, 0, pIntermediate, pLayouts[0].Offset, pLayouts[0].Footprint.Width);
1439 for (UINT i = 0; i < NumSubresources; ++i)
1441 CD3DX12_TEXTURE_COPY_LOCATION Dst(pDestinationResource, i + FirstSubresource);
1442 CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]);
1443 pCmdList->CopyTextureRegion(&Dst, 0, 0, 0, &Src,
nullptr);
1446 return RequiredSize;
1451 inline UINT64 UpdateSubresources(
1452 _In_ ID3D12GraphicsCommandList* pCmdList,
1453 _In_ ID3D12Resource* pDestinationResource,
1454 _In_ ID3D12Resource* pIntermediate,
1455 UINT64 IntermediateOffset,
1456 _In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
1457 _In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources,
1458 _In_reads_(NumSubresources) D3D12_SUBRESOURCE_DATA* pSrcData)
1460 UINT64 RequiredSize = 0;
1461 UINT64 MemToAlloc =
static_cast<UINT64
>(
sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) +
sizeof(UINT) +
sizeof(UINT64)) * NumSubresources;
1462 if (MemToAlloc > SIZE_MAX)
1466 void* pMem = HeapAlloc(GetProcessHeap(), 0, static_cast<SIZE_T>(MemToAlloc));
1471 D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts =
reinterpret_cast<D3D12_PLACED_SUBRESOURCE_FOOTPRINT*
>(pMem);
1472 UINT64* pRowSizesInBytes =
reinterpret_cast<UINT64*
>(pLayouts + NumSubresources);
1473 UINT* pNumRows =
reinterpret_cast<UINT*
>(pRowSizesInBytes + NumSubresources);
1475 D3D12_RESOURCE_DESC Desc = pDestinationResource->GetDesc();
1476 ID3D12Device* pDevice;
1477 pDestinationResource->GetDevice(__uuidof(*pDevice), reinterpret_cast<void**>(&pDevice));
1478 pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, pLayouts, pNumRows, pRowSizesInBytes, &RequiredSize);
1481 UINT64 Result = UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, pLayouts, pNumRows, pRowSizesInBytes, pSrcData);
1482 HeapFree(GetProcessHeap(), 0, pMem);
1488 template <UINT MaxSubresources>
1489 inline UINT64 UpdateSubresources(
1490 _In_ ID3D12GraphicsCommandList* pCmdList,
1491 _In_ ID3D12Resource* pDestinationResource,
1492 _In_ ID3D12Resource* pIntermediate,
1493 UINT64 IntermediateOffset,
1494 _In_range_(0, MaxSubresources) UINT FirstSubresource,
1495 _In_range_(1, MaxSubresources - FirstSubresource) UINT NumSubresources,
1496 _In_reads_(NumSubresources) D3D12_SUBRESOURCE_DATA* pSrcData)
1498 UINT64 RequiredSize = 0;
1499 D3D12_PLACED_SUBRESOURCE_FOOTPRINT Layouts[MaxSubresources];
1500 UINT NumRows[MaxSubresources];
1501 UINT64 RowSizesInBytes[MaxSubresources];
1503 D3D12_RESOURCE_DESC Desc = pDestinationResource->GetDesc();
1504 ID3D12Device* pDevice;
1505 pDestinationResource->GetDevice(__uuidof(*pDevice), reinterpret_cast<void**>(&pDevice));
1506 pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, Layouts, NumRows, RowSizesInBytes, &RequiredSize);
1509 return UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, Layouts, NumRows, RowSizesInBytes, pSrcData);
1513 inline bool D3D12IsLayoutOpaque( D3D12_TEXTURE_LAYOUT Layout )
1514 {
return Layout == D3D12_TEXTURE_LAYOUT_UNKNOWN || Layout == D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE; }
1517 inline ID3D12CommandList *
const * CommandListCast(ID3D12GraphicsCommandList *
const * pp)
1523 return reinterpret_cast<ID3D12CommandList *
const *
>(pp);
1527 #endif // defined( __cplusplus ) 1529 #endif //__D3DX12_H__ Hatchit Engine Copyright(c) 2015-2016 Third-Degree.