forked from microsoft/DirectML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
d3dx12.h
3463 lines (3283 loc) · 136 KB
/
d3dx12.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
#ifndef __D3DX12_H__
#define __D3DX12_H__
#include "d3d12.h"
#if defined( __cplusplus )
struct CD3DX12_DEFAULT {};
extern const DECLSPEC_SELECTANY CD3DX12_DEFAULT D3D12_DEFAULT;
//------------------------------------------------------------------------------------------------
inline bool operator==(const D3D12_VIEWPORT& l, const D3D12_VIEWPORT& r)
{
return l.TopLeftX == r.TopLeftX && l.TopLeftY == r.TopLeftY && l.Width == r.Width &&
l.Height == r.Height && l.MinDepth == r.MinDepth && l.MaxDepth == r.MaxDepth;
}
//------------------------------------------------------------------------------------------------
inline bool operator!=(const D3D12_VIEWPORT& l, const D3D12_VIEWPORT& r)
{
return !(l == r);
}
//------------------------------------------------------------------------------------------------
struct CD3DX12_RECT : public D3D12_RECT
{
CD3DX12_RECT() = default;
explicit CD3DX12_RECT(const D3D12_RECT& o) :
D3D12_RECT(o)
{}
explicit CD3DX12_RECT(
LONG Left,
LONG Top,
LONG Right,
LONG Bottom)
{
left = Left;
top = Top;
right = Right;
bottom = Bottom;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_VIEWPORT : public D3D12_VIEWPORT
{
CD3DX12_VIEWPORT() = default;
explicit CD3DX12_VIEWPORT(const D3D12_VIEWPORT& o) :
D3D12_VIEWPORT(o)
{}
explicit CD3DX12_VIEWPORT(
FLOAT topLeftX,
FLOAT topLeftY,
FLOAT width,
FLOAT height,
FLOAT minDepth = D3D12_MIN_DEPTH,
FLOAT maxDepth = D3D12_MAX_DEPTH)
{
TopLeftX = topLeftX;
TopLeftY = topLeftY;
Width = width;
Height = height;
MinDepth = minDepth;
MaxDepth = maxDepth;
}
explicit CD3DX12_VIEWPORT(
_In_ ID3D12Resource* pResource,
UINT mipSlice = 0,
FLOAT topLeftX = 0.0f,
FLOAT topLeftY = 0.0f,
FLOAT minDepth = D3D12_MIN_DEPTH,
FLOAT maxDepth = D3D12_MAX_DEPTH)
{
auto Desc = pResource->GetDesc();
const UINT64 SubresourceWidth = Desc.Width >> mipSlice;
const UINT64 SubresourceHeight = Desc.Height >> mipSlice;
switch (Desc.Dimension)
{
case D3D12_RESOURCE_DIMENSION_BUFFER:
TopLeftX = topLeftX;
TopLeftY = 0.0f;
Width = Desc.Width - topLeftX;
Height = 1.0f;
break;
case D3D12_RESOURCE_DIMENSION_TEXTURE1D:
TopLeftX = topLeftX;
TopLeftY = 0.0f;
Width = (SubresourceWidth ? SubresourceWidth : 1.0f) - topLeftX;
Height = 1.0f;
break;
case D3D12_RESOURCE_DIMENSION_TEXTURE2D:
case D3D12_RESOURCE_DIMENSION_TEXTURE3D:
TopLeftX = topLeftX;
TopLeftY = topLeftY;
Width = (SubresourceWidth ? SubresourceWidth : 1.0f) - topLeftX;
Height = (SubresourceHeight ? SubresourceHeight : 1.0f) - topLeftY;
break;
default: break;
}
MinDepth = minDepth;
MaxDepth = maxDepth;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_BOX : public D3D12_BOX
{
CD3DX12_BOX() = default;
explicit CD3DX12_BOX(const D3D12_BOX& o) :
D3D12_BOX(o)
{}
explicit CD3DX12_BOX(
LONG Left,
LONG Right)
{
left = Left;
top = 0;
front = 0;
right = Right;
bottom = 1;
back = 1;
}
explicit CD3DX12_BOX(
LONG Left,
LONG Top,
LONG Right,
LONG Bottom)
{
left = Left;
top = Top;
front = 0;
right = Right;
bottom = Bottom;
back = 1;
}
explicit CD3DX12_BOX(
LONG Left,
LONG Top,
LONG Front,
LONG Right,
LONG Bottom,
LONG Back)
{
left = Left;
top = Top;
front = Front;
right = Right;
bottom = Bottom;
back = Back;
}
};
inline bool operator==(const D3D12_BOX& l, const D3D12_BOX& r)
{
return l.left == r.left && l.top == r.top && l.front == r.front &&
l.right == r.right && l.bottom == r.bottom && l.back == r.back;
}
inline bool operator!=(const D3D12_BOX& l, const D3D12_BOX& r)
{
return !(l == r);
}
//------------------------------------------------------------------------------------------------
struct CD3DX12_DEPTH_STENCIL_DESC : public D3D12_DEPTH_STENCIL_DESC
{
CD3DX12_DEPTH_STENCIL_DESC() = default;
explicit CD3DX12_DEPTH_STENCIL_DESC(const D3D12_DEPTH_STENCIL_DESC& o) :
D3D12_DEPTH_STENCIL_DESC(o)
{}
explicit CD3DX12_DEPTH_STENCIL_DESC(CD3DX12_DEFAULT)
{
DepthEnable = TRUE;
DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
DepthFunc = D3D12_COMPARISON_FUNC_LESS;
StencilEnable = FALSE;
StencilReadMask = D3D12_DEFAULT_STENCIL_READ_MASK;
StencilWriteMask = D3D12_DEFAULT_STENCIL_WRITE_MASK;
const D3D12_DEPTH_STENCILOP_DESC defaultStencilOp =
{ D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_COMPARISON_FUNC_ALWAYS };
FrontFace = defaultStencilOp;
BackFace = defaultStencilOp;
}
explicit CD3DX12_DEPTH_STENCIL_DESC(
BOOL depthEnable,
D3D12_DEPTH_WRITE_MASK depthWriteMask,
D3D12_COMPARISON_FUNC depthFunc,
BOOL stencilEnable,
UINT8 stencilReadMask,
UINT8 stencilWriteMask,
D3D12_STENCIL_OP frontStencilFailOp,
D3D12_STENCIL_OP frontStencilDepthFailOp,
D3D12_STENCIL_OP frontStencilPassOp,
D3D12_COMPARISON_FUNC frontStencilFunc,
D3D12_STENCIL_OP backStencilFailOp,
D3D12_STENCIL_OP backStencilDepthFailOp,
D3D12_STENCIL_OP backStencilPassOp,
D3D12_COMPARISON_FUNC backStencilFunc)
{
DepthEnable = depthEnable;
DepthWriteMask = depthWriteMask;
DepthFunc = depthFunc;
StencilEnable = stencilEnable;
StencilReadMask = stencilReadMask;
StencilWriteMask = stencilWriteMask;
FrontFace.StencilFailOp = frontStencilFailOp;
FrontFace.StencilDepthFailOp = frontStencilDepthFailOp;
FrontFace.StencilPassOp = frontStencilPassOp;
FrontFace.StencilFunc = frontStencilFunc;
BackFace.StencilFailOp = backStencilFailOp;
BackFace.StencilDepthFailOp = backStencilDepthFailOp;
BackFace.StencilPassOp = backStencilPassOp;
BackFace.StencilFunc = backStencilFunc;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_DEPTH_STENCIL_DESC1 : public D3D12_DEPTH_STENCIL_DESC1
{
CD3DX12_DEPTH_STENCIL_DESC1() = default;
explicit CD3DX12_DEPTH_STENCIL_DESC1(const D3D12_DEPTH_STENCIL_DESC1& o) :
D3D12_DEPTH_STENCIL_DESC1(o)
{}
explicit CD3DX12_DEPTH_STENCIL_DESC1(const D3D12_DEPTH_STENCIL_DESC& o)
{
DepthEnable = o.DepthEnable;
DepthWriteMask = o.DepthWriteMask;
DepthFunc = o.DepthFunc;
StencilEnable = o.StencilEnable;
StencilReadMask = o.StencilReadMask;
StencilWriteMask = o.StencilWriteMask;
FrontFace.StencilFailOp = o.FrontFace.StencilFailOp;
FrontFace.StencilDepthFailOp = o.FrontFace.StencilDepthFailOp;
FrontFace.StencilPassOp = o.FrontFace.StencilPassOp;
FrontFace.StencilFunc = o.FrontFace.StencilFunc;
BackFace.StencilFailOp = o.BackFace.StencilFailOp;
BackFace.StencilDepthFailOp = o.BackFace.StencilDepthFailOp;
BackFace.StencilPassOp = o.BackFace.StencilPassOp;
BackFace.StencilFunc = o.BackFace.StencilFunc;
DepthBoundsTestEnable = FALSE;
}
explicit CD3DX12_DEPTH_STENCIL_DESC1(CD3DX12_DEFAULT)
{
DepthEnable = TRUE;
DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
DepthFunc = D3D12_COMPARISON_FUNC_LESS;
StencilEnable = FALSE;
StencilReadMask = D3D12_DEFAULT_STENCIL_READ_MASK;
StencilWriteMask = D3D12_DEFAULT_STENCIL_WRITE_MASK;
const D3D12_DEPTH_STENCILOP_DESC defaultStencilOp =
{ D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_COMPARISON_FUNC_ALWAYS };
FrontFace = defaultStencilOp;
BackFace = defaultStencilOp;
DepthBoundsTestEnable = FALSE;
}
explicit CD3DX12_DEPTH_STENCIL_DESC1(
BOOL depthEnable,
D3D12_DEPTH_WRITE_MASK depthWriteMask,
D3D12_COMPARISON_FUNC depthFunc,
BOOL stencilEnable,
UINT8 stencilReadMask,
UINT8 stencilWriteMask,
D3D12_STENCIL_OP frontStencilFailOp,
D3D12_STENCIL_OP frontStencilDepthFailOp,
D3D12_STENCIL_OP frontStencilPassOp,
D3D12_COMPARISON_FUNC frontStencilFunc,
D3D12_STENCIL_OP backStencilFailOp,
D3D12_STENCIL_OP backStencilDepthFailOp,
D3D12_STENCIL_OP backStencilPassOp,
D3D12_COMPARISON_FUNC backStencilFunc,
BOOL depthBoundsTestEnable)
{
DepthEnable = depthEnable;
DepthWriteMask = depthWriteMask;
DepthFunc = depthFunc;
StencilEnable = stencilEnable;
StencilReadMask = stencilReadMask;
StencilWriteMask = stencilWriteMask;
FrontFace.StencilFailOp = frontStencilFailOp;
FrontFace.StencilDepthFailOp = frontStencilDepthFailOp;
FrontFace.StencilPassOp = frontStencilPassOp;
FrontFace.StencilFunc = frontStencilFunc;
BackFace.StencilFailOp = backStencilFailOp;
BackFace.StencilDepthFailOp = backStencilDepthFailOp;
BackFace.StencilPassOp = backStencilPassOp;
BackFace.StencilFunc = backStencilFunc;
DepthBoundsTestEnable = depthBoundsTestEnable;
}
operator D3D12_DEPTH_STENCIL_DESC() const
{
D3D12_DEPTH_STENCIL_DESC D;
D.DepthEnable = DepthEnable;
D.DepthWriteMask = DepthWriteMask;
D.DepthFunc = DepthFunc;
D.StencilEnable = StencilEnable;
D.StencilReadMask = StencilReadMask;
D.StencilWriteMask = StencilWriteMask;
D.FrontFace.StencilFailOp = FrontFace.StencilFailOp;
D.FrontFace.StencilDepthFailOp = FrontFace.StencilDepthFailOp;
D.FrontFace.StencilPassOp = FrontFace.StencilPassOp;
D.FrontFace.StencilFunc = FrontFace.StencilFunc;
D.BackFace.StencilFailOp = BackFace.StencilFailOp;
D.BackFace.StencilDepthFailOp = BackFace.StencilDepthFailOp;
D.BackFace.StencilPassOp = BackFace.StencilPassOp;
D.BackFace.StencilFunc = BackFace.StencilFunc;
return D;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_BLEND_DESC : public D3D12_BLEND_DESC
{
CD3DX12_BLEND_DESC() = default;
explicit CD3DX12_BLEND_DESC(const D3D12_BLEND_DESC& o) :
D3D12_BLEND_DESC(o)
{}
explicit CD3DX12_BLEND_DESC(CD3DX12_DEFAULT)
{
AlphaToCoverageEnable = FALSE;
IndependentBlendEnable = FALSE;
const D3D12_RENDER_TARGET_BLEND_DESC defaultRenderTargetBlendDesc =
{
FALSE,FALSE,
D3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD,
D3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD,
D3D12_LOGIC_OP_NOOP,
D3D12_COLOR_WRITE_ENABLE_ALL,
};
for (UINT i = 0; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
RenderTarget[i] = defaultRenderTargetBlendDesc;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_RASTERIZER_DESC : public D3D12_RASTERIZER_DESC
{
CD3DX12_RASTERIZER_DESC() = default;
explicit CD3DX12_RASTERIZER_DESC(const D3D12_RASTERIZER_DESC& o) :
D3D12_RASTERIZER_DESC(o)
{}
explicit CD3DX12_RASTERIZER_DESC(CD3DX12_DEFAULT)
{
FillMode = D3D12_FILL_MODE_SOLID;
CullMode = D3D12_CULL_MODE_BACK;
FrontCounterClockwise = FALSE;
DepthBias = D3D12_DEFAULT_DEPTH_BIAS;
DepthBiasClamp = D3D12_DEFAULT_DEPTH_BIAS_CLAMP;
SlopeScaledDepthBias = D3D12_DEFAULT_SLOPE_SCALED_DEPTH_BIAS;
DepthClipEnable = TRUE;
MultisampleEnable = FALSE;
AntialiasedLineEnable = FALSE;
ForcedSampleCount = 0;
ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF;
}
explicit CD3DX12_RASTERIZER_DESC(
D3D12_FILL_MODE fillMode,
D3D12_CULL_MODE cullMode,
BOOL frontCounterClockwise,
INT depthBias,
FLOAT depthBiasClamp,
FLOAT slopeScaledDepthBias,
BOOL depthClipEnable,
BOOL multisampleEnable,
BOOL antialiasedLineEnable,
UINT forcedSampleCount,
D3D12_CONSERVATIVE_RASTERIZATION_MODE conservativeRaster)
{
FillMode = fillMode;
CullMode = cullMode;
FrontCounterClockwise = frontCounterClockwise;
DepthBias = depthBias;
DepthBiasClamp = depthBiasClamp;
SlopeScaledDepthBias = slopeScaledDepthBias;
DepthClipEnable = depthClipEnable;
MultisampleEnable = multisampleEnable;
AntialiasedLineEnable = antialiasedLineEnable;
ForcedSampleCount = forcedSampleCount;
ConservativeRaster = conservativeRaster;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_RESOURCE_ALLOCATION_INFO : public D3D12_RESOURCE_ALLOCATION_INFO
{
CD3DX12_RESOURCE_ALLOCATION_INFO() = default;
explicit CD3DX12_RESOURCE_ALLOCATION_INFO(const D3D12_RESOURCE_ALLOCATION_INFO& o) :
D3D12_RESOURCE_ALLOCATION_INFO(o)
{}
CD3DX12_RESOURCE_ALLOCATION_INFO(
UINT64 size,
UINT64 alignment)
{
SizeInBytes = size;
Alignment = alignment;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_HEAP_PROPERTIES : public D3D12_HEAP_PROPERTIES
{
CD3DX12_HEAP_PROPERTIES() = default;
explicit CD3DX12_HEAP_PROPERTIES(const D3D12_HEAP_PROPERTIES& o) :
D3D12_HEAP_PROPERTIES(o)
{}
CD3DX12_HEAP_PROPERTIES(
D3D12_CPU_PAGE_PROPERTY cpuPageProperty,
D3D12_MEMORY_POOL memoryPoolPreference,
UINT creationNodeMask = 1,
UINT nodeMask = 1)
{
Type = D3D12_HEAP_TYPE_CUSTOM;
CPUPageProperty = cpuPageProperty;
MemoryPoolPreference = memoryPoolPreference;
CreationNodeMask = creationNodeMask;
VisibleNodeMask = nodeMask;
}
explicit CD3DX12_HEAP_PROPERTIES(
D3D12_HEAP_TYPE type,
UINT creationNodeMask = 1,
UINT nodeMask = 1)
{
Type = type;
CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
CreationNodeMask = creationNodeMask;
VisibleNodeMask = nodeMask;
}
bool IsCPUAccessible() const
{
return Type == D3D12_HEAP_TYPE_UPLOAD || Type == D3D12_HEAP_TYPE_READBACK || (Type == D3D12_HEAP_TYPE_CUSTOM &&
(CPUPageProperty == D3D12_CPU_PAGE_PROPERTY_WRITE_COMBINE || CPUPageProperty == D3D12_CPU_PAGE_PROPERTY_WRITE_BACK));
}
};
inline bool operator==(const D3D12_HEAP_PROPERTIES& l, const D3D12_HEAP_PROPERTIES& r)
{
return l.Type == r.Type && l.CPUPageProperty == r.CPUPageProperty &&
l.MemoryPoolPreference == r.MemoryPoolPreference &&
l.CreationNodeMask == r.CreationNodeMask &&
l.VisibleNodeMask == r.VisibleNodeMask;
}
inline bool operator!=(const D3D12_HEAP_PROPERTIES& l, const D3D12_HEAP_PROPERTIES& r)
{
return !(l == r);
}
//------------------------------------------------------------------------------------------------
struct CD3DX12_HEAP_DESC : public D3D12_HEAP_DESC
{
CD3DX12_HEAP_DESC() = default;
explicit CD3DX12_HEAP_DESC(const D3D12_HEAP_DESC& o) :
D3D12_HEAP_DESC(o)
{}
CD3DX12_HEAP_DESC(
UINT64 size,
D3D12_HEAP_PROPERTIES properties,
UINT64 alignment = 0,
D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE)
{
SizeInBytes = size;
Properties = properties;
Alignment = alignment;
Flags = flags;
}
CD3DX12_HEAP_DESC(
UINT64 size,
D3D12_HEAP_TYPE type,
UINT64 alignment = 0,
D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE)
{
SizeInBytes = size;
Properties = CD3DX12_HEAP_PROPERTIES(type);
Alignment = alignment;
Flags = flags;
}
CD3DX12_HEAP_DESC(
UINT64 size,
D3D12_CPU_PAGE_PROPERTY cpuPageProperty,
D3D12_MEMORY_POOL memoryPoolPreference,
UINT64 alignment = 0,
D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE)
{
SizeInBytes = size;
Properties = CD3DX12_HEAP_PROPERTIES(cpuPageProperty, memoryPoolPreference);
Alignment = alignment;
Flags = flags;
}
CD3DX12_HEAP_DESC(
const D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,
D3D12_HEAP_PROPERTIES properties,
D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE)
{
SizeInBytes = resAllocInfo.SizeInBytes;
Properties = properties;
Alignment = resAllocInfo.Alignment;
Flags = flags;
}
CD3DX12_HEAP_DESC(
const D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,
D3D12_HEAP_TYPE type,
D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE)
{
SizeInBytes = resAllocInfo.SizeInBytes;
Properties = CD3DX12_HEAP_PROPERTIES(type);
Alignment = resAllocInfo.Alignment;
Flags = flags;
}
CD3DX12_HEAP_DESC(
const D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,
D3D12_CPU_PAGE_PROPERTY cpuPageProperty,
D3D12_MEMORY_POOL memoryPoolPreference,
D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE)
{
SizeInBytes = resAllocInfo.SizeInBytes;
Properties = CD3DX12_HEAP_PROPERTIES(cpuPageProperty, memoryPoolPreference);
Alignment = resAllocInfo.Alignment;
Flags = flags;
}
bool IsCPUAccessible() const
{
return static_cast<const CD3DX12_HEAP_PROPERTIES*>(&Properties)->IsCPUAccessible();
}
};
inline bool operator==(const D3D12_HEAP_DESC& l, const D3D12_HEAP_DESC& r)
{
return l.SizeInBytes == r.SizeInBytes &&
l.Properties == r.Properties &&
l.Alignment == r.Alignment &&
l.Flags == r.Flags;
}
inline bool operator!=(const D3D12_HEAP_DESC& l, const D3D12_HEAP_DESC& r)
{
return !(l == r);
}
//------------------------------------------------------------------------------------------------
struct CD3DX12_CLEAR_VALUE : public D3D12_CLEAR_VALUE
{
CD3DX12_CLEAR_VALUE() = default;
explicit CD3DX12_CLEAR_VALUE(const D3D12_CLEAR_VALUE& o) :
D3D12_CLEAR_VALUE(o)
{}
CD3DX12_CLEAR_VALUE(
DXGI_FORMAT format,
const FLOAT color[4])
{
Format = format;
memcpy(Color, color, sizeof(Color));
}
CD3DX12_CLEAR_VALUE(
DXGI_FORMAT format,
FLOAT depth,
UINT8 stencil)
{
Format = format;
/* Use memcpy to preserve NAN values */
memcpy(&DepthStencil.Depth, &depth, sizeof(depth));
DepthStencil.Stencil = stencil;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_RANGE : public D3D12_RANGE
{
CD3DX12_RANGE() = default;
explicit CD3DX12_RANGE(const D3D12_RANGE& o) :
D3D12_RANGE(o)
{}
CD3DX12_RANGE(
SIZE_T begin,
SIZE_T end)
{
Begin = begin;
End = end;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_RANGE_UINT64 : public D3D12_RANGE_UINT64
{
CD3DX12_RANGE_UINT64() = default;
explicit CD3DX12_RANGE_UINT64(const D3D12_RANGE_UINT64& o) :
D3D12_RANGE_UINT64(o)
{}
CD3DX12_RANGE_UINT64(
UINT64 begin,
UINT64 end)
{
Begin = begin;
End = end;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_SUBRESOURCE_RANGE_UINT64 : public D3D12_SUBRESOURCE_RANGE_UINT64
{
CD3DX12_SUBRESOURCE_RANGE_UINT64() = default;
explicit CD3DX12_SUBRESOURCE_RANGE_UINT64(const D3D12_SUBRESOURCE_RANGE_UINT64& o) :
D3D12_SUBRESOURCE_RANGE_UINT64(o)
{}
CD3DX12_SUBRESOURCE_RANGE_UINT64(
UINT subresource,
const D3D12_RANGE_UINT64& range)
{
Subresource = subresource;
Range = range;
}
CD3DX12_SUBRESOURCE_RANGE_UINT64(
UINT subresource,
UINT64 begin,
UINT64 end)
{
Subresource = subresource;
Range.Begin = begin;
Range.End = end;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_SHADER_BYTECODE : public D3D12_SHADER_BYTECODE
{
CD3DX12_SHADER_BYTECODE() = default;
explicit CD3DX12_SHADER_BYTECODE(const D3D12_SHADER_BYTECODE& o) :
D3D12_SHADER_BYTECODE(o)
{}
CD3DX12_SHADER_BYTECODE(
_In_ ID3DBlob* pShaderBlob)
{
pShaderBytecode = pShaderBlob->GetBufferPointer();
BytecodeLength = pShaderBlob->GetBufferSize();
}
CD3DX12_SHADER_BYTECODE(
const void* _pShaderBytecode,
SIZE_T bytecodeLength)
{
pShaderBytecode = _pShaderBytecode;
BytecodeLength = bytecodeLength;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_TILED_RESOURCE_COORDINATE : public D3D12_TILED_RESOURCE_COORDINATE
{
CD3DX12_TILED_RESOURCE_COORDINATE() = default;
explicit CD3DX12_TILED_RESOURCE_COORDINATE(const D3D12_TILED_RESOURCE_COORDINATE& o) :
D3D12_TILED_RESOURCE_COORDINATE(o)
{}
CD3DX12_TILED_RESOURCE_COORDINATE(
UINT x,
UINT y,
UINT z,
UINT subresource)
{
X = x;
Y = y;
Z = z;
Subresource = subresource;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_TILE_REGION_SIZE : public D3D12_TILE_REGION_SIZE
{
CD3DX12_TILE_REGION_SIZE() = default;
explicit CD3DX12_TILE_REGION_SIZE(const D3D12_TILE_REGION_SIZE& o) :
D3D12_TILE_REGION_SIZE(o)
{}
CD3DX12_TILE_REGION_SIZE(
UINT numTiles,
BOOL useBox,
UINT width,
UINT16 height,
UINT16 depth)
{
NumTiles = numTiles;
UseBox = useBox;
Width = width;
Height = height;
Depth = depth;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_SUBRESOURCE_TILING : public D3D12_SUBRESOURCE_TILING
{
CD3DX12_SUBRESOURCE_TILING() = default;
explicit CD3DX12_SUBRESOURCE_TILING(const D3D12_SUBRESOURCE_TILING& o) :
D3D12_SUBRESOURCE_TILING(o)
{}
CD3DX12_SUBRESOURCE_TILING(
UINT widthInTiles,
UINT16 heightInTiles,
UINT16 depthInTiles,
UINT startTileIndexInOverallResource)
{
WidthInTiles = widthInTiles;
HeightInTiles = heightInTiles;
DepthInTiles = depthInTiles;
StartTileIndexInOverallResource = startTileIndexInOverallResource;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_TILE_SHAPE : public D3D12_TILE_SHAPE
{
CD3DX12_TILE_SHAPE() = default;
explicit CD3DX12_TILE_SHAPE(const D3D12_TILE_SHAPE& o) :
D3D12_TILE_SHAPE(o)
{}
CD3DX12_TILE_SHAPE(
UINT widthInTexels,
UINT heightInTexels,
UINT depthInTexels)
{
WidthInTexels = widthInTexels;
HeightInTexels = heightInTexels;
DepthInTexels = depthInTexels;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_RESOURCE_BARRIER : public D3D12_RESOURCE_BARRIER
{
CD3DX12_RESOURCE_BARRIER() = default;
explicit CD3DX12_RESOURCE_BARRIER(const D3D12_RESOURCE_BARRIER& o) :
D3D12_RESOURCE_BARRIER(o)
{}
static inline CD3DX12_RESOURCE_BARRIER Transition(
_In_ ID3D12Resource* pResource,
D3D12_RESOURCE_STATES stateBefore,
D3D12_RESOURCE_STATES stateAfter,
UINT subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
D3D12_RESOURCE_BARRIER_FLAGS flags = D3D12_RESOURCE_BARRIER_FLAG_NONE)
{
CD3DX12_RESOURCE_BARRIER result = {};
D3D12_RESOURCE_BARRIER& barrier = result;
result.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
result.Flags = flags;
barrier.Transition.pResource = pResource;
barrier.Transition.StateBefore = stateBefore;
barrier.Transition.StateAfter = stateAfter;
barrier.Transition.Subresource = subresource;
return result;
}
static inline CD3DX12_RESOURCE_BARRIER Aliasing(
_In_ ID3D12Resource* pResourceBefore,
_In_ ID3D12Resource* pResourceAfter)
{
CD3DX12_RESOURCE_BARRIER result = {};
D3D12_RESOURCE_BARRIER& barrier = result;
result.Type = D3D12_RESOURCE_BARRIER_TYPE_ALIASING;
barrier.Aliasing.pResourceBefore = pResourceBefore;
barrier.Aliasing.pResourceAfter = pResourceAfter;
return result;
}
static inline CD3DX12_RESOURCE_BARRIER UAV(
_In_ ID3D12Resource* pResource)
{
CD3DX12_RESOURCE_BARRIER result = {};
D3D12_RESOURCE_BARRIER& barrier = result;
result.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
barrier.UAV.pResource = pResource;
return result;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_PACKED_MIP_INFO : public D3D12_PACKED_MIP_INFO
{
CD3DX12_PACKED_MIP_INFO() = default;
explicit CD3DX12_PACKED_MIP_INFO(const D3D12_PACKED_MIP_INFO& o) :
D3D12_PACKED_MIP_INFO(o)
{}
CD3DX12_PACKED_MIP_INFO(
UINT8 numStandardMips,
UINT8 numPackedMips,
UINT numTilesForPackedMips,
UINT startTileIndexInOverallResource)
{
NumStandardMips = numStandardMips;
NumPackedMips = numPackedMips;
NumTilesForPackedMips = numTilesForPackedMips;
StartTileIndexInOverallResource = startTileIndexInOverallResource;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_SUBRESOURCE_FOOTPRINT : public D3D12_SUBRESOURCE_FOOTPRINT
{
CD3DX12_SUBRESOURCE_FOOTPRINT() = default;
explicit CD3DX12_SUBRESOURCE_FOOTPRINT(const D3D12_SUBRESOURCE_FOOTPRINT& o) :
D3D12_SUBRESOURCE_FOOTPRINT(o)
{}
CD3DX12_SUBRESOURCE_FOOTPRINT(
DXGI_FORMAT format,
UINT width,
UINT height,
UINT depth,
UINT rowPitch)
{
Format = format;
Width = width;
Height = height;
Depth = depth;
RowPitch = rowPitch;
}
explicit CD3DX12_SUBRESOURCE_FOOTPRINT(
const D3D12_RESOURCE_DESC& resDesc,
UINT rowPitch)
{
Format = resDesc.Format;
Width = UINT(resDesc.Width);
Height = resDesc.Height;
Depth = (resDesc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? resDesc.DepthOrArraySize : 1);
RowPitch = rowPitch;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_TEXTURE_COPY_LOCATION : public D3D12_TEXTURE_COPY_LOCATION
{
CD3DX12_TEXTURE_COPY_LOCATION() = default;
explicit CD3DX12_TEXTURE_COPY_LOCATION(const D3D12_TEXTURE_COPY_LOCATION& o) :
D3D12_TEXTURE_COPY_LOCATION(o)
{}
CD3DX12_TEXTURE_COPY_LOCATION(_In_ ID3D12Resource* pRes)
{
pResource = pRes;
Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
PlacedFootprint = {};
}
CD3DX12_TEXTURE_COPY_LOCATION(_In_ ID3D12Resource* pRes, D3D12_PLACED_SUBRESOURCE_FOOTPRINT const& Footprint)
{
pResource = pRes;
Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
PlacedFootprint = Footprint;
}
CD3DX12_TEXTURE_COPY_LOCATION(_In_ ID3D12Resource* pRes, UINT Sub)
{
pResource = pRes;
Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
SubresourceIndex = Sub;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_DESCRIPTOR_RANGE : public D3D12_DESCRIPTOR_RANGE
{
CD3DX12_DESCRIPTOR_RANGE() = default;
explicit CD3DX12_DESCRIPTOR_RANGE(const D3D12_DESCRIPTOR_RANGE& o) :
D3D12_DESCRIPTOR_RANGE(o)
{}
CD3DX12_DESCRIPTOR_RANGE(
D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
UINT numDescriptors,
UINT baseShaderRegister,
UINT registerSpace = 0,
UINT offsetInDescriptorsFromTableStart =
D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
{
Init(rangeType, numDescriptors, baseShaderRegister, registerSpace, offsetInDescriptorsFromTableStart);
}
inline void Init(
D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
UINT numDescriptors,
UINT baseShaderRegister,
UINT registerSpace = 0,
UINT offsetInDescriptorsFromTableStart =
D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
{
Init(*this, rangeType, numDescriptors, baseShaderRegister, registerSpace, offsetInDescriptorsFromTableStart);
}
static inline void Init(
_Out_ D3D12_DESCRIPTOR_RANGE& range,
D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
UINT numDescriptors,
UINT baseShaderRegister,
UINT registerSpace = 0,
UINT offsetInDescriptorsFromTableStart =
D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
{
range.RangeType = rangeType;
range.NumDescriptors = numDescriptors;
range.BaseShaderRegister = baseShaderRegister;
range.RegisterSpace = registerSpace;
range.OffsetInDescriptorsFromTableStart = offsetInDescriptorsFromTableStart;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_DESCRIPTOR_TABLE : public D3D12_ROOT_DESCRIPTOR_TABLE
{
CD3DX12_ROOT_DESCRIPTOR_TABLE() = default;
explicit CD3DX12_ROOT_DESCRIPTOR_TABLE(const D3D12_ROOT_DESCRIPTOR_TABLE& o) :
D3D12_ROOT_DESCRIPTOR_TABLE(o)
{}
CD3DX12_ROOT_DESCRIPTOR_TABLE(
UINT numDescriptorRanges,
_In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges)
{
Init(numDescriptorRanges, _pDescriptorRanges);
}
inline void Init(
UINT numDescriptorRanges,
_In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges)
{
Init(*this, numDescriptorRanges, _pDescriptorRanges);
}
static inline void Init(
_Out_ D3D12_ROOT_DESCRIPTOR_TABLE& rootDescriptorTable,
UINT numDescriptorRanges,
_In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges)
{
rootDescriptorTable.NumDescriptorRanges = numDescriptorRanges;
rootDescriptorTable.pDescriptorRanges = _pDescriptorRanges;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_CONSTANTS : public D3D12_ROOT_CONSTANTS
{
CD3DX12_ROOT_CONSTANTS() = default;
explicit CD3DX12_ROOT_CONSTANTS(const D3D12_ROOT_CONSTANTS& o) :
D3D12_ROOT_CONSTANTS(o)
{}
CD3DX12_ROOT_CONSTANTS(
UINT num32BitValues,
UINT shaderRegister,
UINT registerSpace = 0)
{
Init(num32BitValues, shaderRegister, registerSpace);
}
inline void Init(
UINT num32BitValues,
UINT shaderRegister,
UINT registerSpace = 0)
{
Init(*this, num32BitValues, shaderRegister, registerSpace);
}
static inline void Init(
_Out_ D3D12_ROOT_CONSTANTS& rootConstants,
UINT num32BitValues,
UINT shaderRegister,
UINT registerSpace = 0)
{
rootConstants.Num32BitValues = num32BitValues;
rootConstants.ShaderRegister = shaderRegister;
rootConstants.RegisterSpace = registerSpace;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_DESCRIPTOR : public D3D12_ROOT_DESCRIPTOR
{
CD3DX12_ROOT_DESCRIPTOR() = default;
explicit CD3DX12_ROOT_DESCRIPTOR(const D3D12_ROOT_DESCRIPTOR& o) :
D3D12_ROOT_DESCRIPTOR(o)
{}
CD3DX12_ROOT_DESCRIPTOR(
UINT shaderRegister,
UINT registerSpace = 0)
{
Init(shaderRegister, registerSpace);
}
inline void Init(
UINT shaderRegister,
UINT registerSpace = 0)
{
Init(*this, shaderRegister, registerSpace);
}
static inline void Init(_Out_ D3D12_ROOT_DESCRIPTOR& table, UINT shaderRegister, UINT registerSpace = 0)
{
table.ShaderRegister = shaderRegister;
table.RegisterSpace = registerSpace;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_PARAMETER : public D3D12_ROOT_PARAMETER
{
CD3DX12_ROOT_PARAMETER() = default;
explicit CD3DX12_ROOT_PARAMETER(const D3D12_ROOT_PARAMETER& o) :
D3D12_ROOT_PARAMETER(o)