Diligent Engine API Reference: D:/GitHub/DiligentEngine/DiligentCore/Graphics/GraphicsEngineD3D12/include/d3dx12_win.h Source File

Diligent Engine API Reference

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