-
Notifications
You must be signed in to change notification settings - Fork 144
/
Copy pathDeviceContext.h
3664 lines (2979 loc) · 188 KB
/
DeviceContext.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 2019-2024 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* In no event and under no legal theory, whether in tort (including negligence),
* contract, or otherwise, unless required by applicable law (such as deliberate
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
* liable for any damages, including any direct, indirect, special, incidental,
* or consequential damages of any character arising as a result of this License or
* out of the use or inability to use the software (including but not limited to damages
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
* all other commercial damages or losses), even if such Contributor has been advised
* of the possibility of such damages.
*/
#pragma once
// clang-format off
/// \file
/// Definition of the Diligent::IDeviceContext interface and related data structures
#include "../../../Primitives/interface/Object.h"
#include "../../../Primitives/interface/FlagEnum.h"
#include "GraphicsTypes.h"
#include "Constants.h"
#include "Buffer.h"
#include "InputLayout.h"
#include "Shader.h"
#include "Texture.h"
#include "Sampler.h"
#include "ResourceMapping.h"
#include "TextureView.h"
#include "BufferView.h"
#include "DepthStencilState.h"
#include "BlendState.h"
#include "PipelineState.h"
#include "Fence.h"
#include "Query.h"
#include "RenderPass.h"
#include "Framebuffer.h"
#include "CommandList.h"
#include "SwapChain.h"
#include "BottomLevelAS.h"
#include "TopLevelAS.h"
#include "ShaderBindingTable.h"
#include "DeviceMemory.h"
#include "CommandQueue.h"
DILIGENT_BEGIN_NAMESPACE(Diligent)
// {DC92711B-A1BE-4319-B2BD-C662D1CC19E4}
static DILIGENT_CONSTEXPR INTERFACE_ID IID_DeviceContext =
{0xdc92711b, 0xa1be, 0x4319, {0xb2, 0xbd, 0xc6, 0x62, 0xd1, 0xcc, 0x19, 0xe4}};
/// Device context description.
struct DeviceContextDesc
{
/// Device context name. This name is what was specified in
/// ImmediateContextCreateInfo::Name when the engine was initialized.
const Char* Name DEFAULT_INITIALIZER(nullptr);
/// Command queue type that this context uses.
/// For immediate contexts, this type matches GraphicsAdapterInfo::Queues[QueueId].QueueType.
/// For deferred contexts, the type is only defined between IDeviceContext::Begin and IDeviceContext::FinishCommandList
/// calls and matches the type of the immediate context where the command list will be executed.
COMMAND_QUEUE_TYPE QueueType DEFAULT_INITIALIZER(COMMAND_QUEUE_TYPE_UNKNOWN);
/// Indicates if this is a deferred context.
Bool IsDeferred DEFAULT_INITIALIZER(False);
/// Device context ID. This value corresponds to the index of the device context
/// in ppContexts array when the engine was initialized.
/// When starting recording commands with a deferred context, the context id
/// of the immediate context where the command list will be executed should be
/// given to IDeviceContext::Begin() method.
Uint8 ContextId DEFAULT_INITIALIZER(0);
/// Hardware queue index in GraphicsAdapterInfo::Queues array.
/// \remarks This member is only defined for immediate contexts and matches
/// QueueId member of ImmediateContextCreateInfo struct that was used to
/// initialize the context.
///
/// - Vulkan backend: same as queue family index.
/// - Direct3D12 backend:
/// - 0 - Graphics queue
/// - 1 - Compute queue
/// - 2 - Transfer queue
/// - Metal backend: index of the unique command queue.
Uint8 QueueId DEFAULT_INITIALIZER(DEFAULT_QUEUE_ID);
/// Required texture granularity for copy operations, for a transfer queue.
/// \remarks For graphics and compute queues, the granularity is always {1,1,1}.
/// For transfer queues, an application must align the texture offsets and sizes
/// by the granularity defined by this member.
///
/// For deferred contexts, this member is only defined between IDeviceContext::Begin and
/// IDeviceContext::FinishCommandList calls and matches the texture copy granularity of
/// the immediate context where the command list will be executed.
Uint32 TextureCopyGranularity[3] DEFAULT_INITIALIZER({});
#if DILIGENT_CPP_INTERFACE
constexpr DeviceContextDesc() noexcept {}
/// Initializes the structure with user-specified values.
constexpr DeviceContextDesc(const Char* _Name,
COMMAND_QUEUE_TYPE _QueueType,
Bool _IsDeferred,
Uint32 _ContextId,
Uint32 _QueueId = DeviceContextDesc{}.QueueId) noexcept :
Name {_Name },
QueueType {_QueueType },
IsDeferred{_IsDeferred},
ContextId {static_cast<decltype(ContextId)>(_ContextId)},
QueueId {static_cast<decltype(QueueId)>(_QueueId)}
{
if (!IsDeferred)
{
TextureCopyGranularity[0] = 1;
TextureCopyGranularity[1] = 1;
TextureCopyGranularity[2] = 1;
}
else
{
// For deferred contexts texture copy granularity is set by IDeviceContext::Begin() method.
}
}
#endif
};
typedef struct DeviceContextDesc DeviceContextDesc;
/// Draw command flags
DILIGENT_TYPED_ENUM(DRAW_FLAGS, Uint8)
{
/// No flags.
DRAW_FLAG_NONE = 0x00,
/// Verify the state of index and vertex buffers (if any) used by the draw
/// command. State validation is only performed in debug and development builds
/// and the flag has no effect in release build.
DRAW_FLAG_VERIFY_STATES = 0x01,
/// Verify correctness of parameters passed to the draw command.
///
/// \remarks This flag only has effect in debug and development builds.
/// Verification is always disabled in release configuration.
DRAW_FLAG_VERIFY_DRAW_ATTRIBS = 0x02,
/// Verify that render targets bound to the context are consistent with the pipeline state.
///
/// \remarks This flag only has effect in debug and development builds.
/// Verification is always disabled in release configuration.
DRAW_FLAG_VERIFY_RENDER_TARGETS = 0x04,
/// Perform all state validation checks
///
/// \remarks This flag only has effect in debug and development builds.
/// Verification is always disabled in release configuration.
DRAW_FLAG_VERIFY_ALL = DRAW_FLAG_VERIFY_STATES | DRAW_FLAG_VERIFY_DRAW_ATTRIBS | DRAW_FLAG_VERIFY_RENDER_TARGETS,
/// Indicates that none of the dynamic resource buffers used by the draw command
/// have been modified by the CPU since the last command.
///
/// \remarks This flag should be used to improve performance when an application issues a
/// series of draw commands that use the same pipeline state and shader resources and
/// no dynamic buffers (constant or bound as shader resources) are updated between the
/// commands.
/// Any buffer variable not created with SHADER_VARIABLE_FLAG_NO_DYNAMIC_BUFFERS or
/// PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS flags is counted as dynamic.
/// The flag has no effect on dynamic vertex and index buffers.
///
/// Details
///
/// D3D12 and Vulkan back-ends have to perform some work to make data in buffers
/// available to draw commands. When a dynamic buffer is mapped, the engine allocates
/// new memory and assigns a new GPU address to this buffer. When a draw command is issued,
/// this GPU address needs to be used. By default the engine assumes that the CPU may
/// map the buffer before any command (to write new transformation matrices for example)
/// and that all GPU addresses need to always be refreshed. This is not always the case,
/// and the application may use the flag to inform the engine that the data in the buffer
/// stay intact to avoid extra work.\n
/// Note that after a new PSO is bound or an SRB is committed, the engine will always set all
/// required buffer addresses/offsets regardless of the flag. The flag will only take effect
/// on the second and subsequent draw calls that use the same PSO and SRB.\n
/// The flag has no effect in D3D11 and OpenGL backends.
///
/// Implementation details
///
/// Vulkan backend allocates VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC descriptors for all uniform (constant),
/// buffers and VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC descriptors for storage buffers.
/// Note that HLSL structured buffers are mapped to read-only storage buffers in SPIRV and RW buffers
/// are mapped to RW-storage buffers.
/// By default, all dynamic descriptor sets that have dynamic buffers bound are updated every time a draw command is
/// issued (see PipelineStateVkImpl::BindDescriptorSetsWithDynamicOffsets). When DRAW_FLAG_DYNAMIC_RESOURCE_BUFFERS_INTACT
/// is specified, dynamic descriptor sets are only bound by the first draw command that uses the PSO and the SRB.
/// The flag avoids binding descriptors with the same offsets if none of the dynamic offsets have changed.
///
/// Direct3D12 backend binds constant buffers to root views. By default the engine assumes that virtual GPU addresses
/// of all dynamic buffers may change between the draw commands and always binds dynamic buffers to root views
/// (see RootSignature::CommitRootViews). When DRAW_FLAG_DYNAMIC_RESOURCE_BUFFERS_INTACT is set, root views are only bound
/// by the first draw command that uses the PSO + SRB pair. The flag avoids setting the same GPU virtual addresses when
/// they stay unchanged.
DRAW_FLAG_DYNAMIC_RESOURCE_BUFFERS_INTACT = 0x08
};
DEFINE_FLAG_ENUM_OPERATORS(DRAW_FLAGS)
/// Defines resource state transition mode performed by various commands.
/// Refer to http://diligentgraphics.com/2018/12/09/resource-state-management/ for detailed explanation
/// of resource state management in Diligent Engine.
DILIGENT_TYPED_ENUM(RESOURCE_STATE_TRANSITION_MODE, Uint8)
{
/// Perform no state transitions and no state validation.
/// Resource states are not accessed (either read or written) by the command.
RESOURCE_STATE_TRANSITION_MODE_NONE = 0,
/// Transition resources to the states required by the specific command.
/// Resources in unknown state are ignored.
///
/// \note Any method that uses this mode may alter the state of the resources it works with.
/// As automatic state management is not thread-safe, no other thread is allowed to read
/// or write the state of the resources being transitioned.
/// If the application intends to use the same resources in other threads simultaneously, it needs to
/// explicitly manage the states using IDeviceContext::TransitionResourceStates() method.
/// Refer to http://diligentgraphics.com/2018/12/09/resource-state-management/ for detailed explanation
/// of resource state management in Diligent Engine.
///
/// \note If a resource is used in multiple threads by multiple contexts, there will be race condition accessing
/// internal resource state. An application should use manual resource state management in this case.
RESOURCE_STATE_TRANSITION_MODE_TRANSITION,
/// Do not transition, but verify that states are correct.
/// No validation is performed if the state is unknown to the engine.
/// This mode only has effect in debug and development builds. No validation
/// is performed in release build.
///
/// \note Any method that uses this mode will read the state of resources it works with.
/// As automatic state management is not thread-safe, no other thread is allowed to alter
/// the state of resources being used by the command. It is safe to read these states.
RESOURCE_STATE_TRANSITION_MODE_VERIFY
};
/// Defines the draw command attributes.
/// This structure is used by IDeviceContext::Draw().
struct DrawAttribs
{
/// The number of vertices to draw.
Uint32 NumVertices DEFAULT_INITIALIZER(0);
/// Additional flags, see Diligent::DRAW_FLAGS.
DRAW_FLAGS Flags DEFAULT_INITIALIZER(DRAW_FLAG_NONE);
/// The number of instances to draw. If more than one instance is specified,
/// instanced draw call will be performed.
Uint32 NumInstances DEFAULT_INITIALIZER(1);
/// LOCATION (or INDEX, but NOT the byte offset) of the first vertex in the
/// vertex buffer to start reading vertices from.
Uint32 StartVertexLocation DEFAULT_INITIALIZER(0);
/// LOCATION (or INDEX, but NOT the byte offset) in the vertex buffer to start
/// reading instance data from.
Uint32 FirstInstanceLocation DEFAULT_INITIALIZER(0);
#if DILIGENT_CPP_INTERFACE
/// Initializes the structure members with default values.
/// Default values:
///
/// Member | Default value
/// -----------------------------------------|--------------------------------------
/// NumVertices | 0
/// Flags | DRAW_FLAG_NONE
/// NumInstances | 1
/// StartVertexLocation | 0
/// FirstInstanceLocation | 0
constexpr DrawAttribs() noexcept {}
/// Initializes the structure with user-specified values.
constexpr DrawAttribs(Uint32 _NumVertices,
DRAW_FLAGS _Flags,
Uint32 _NumInstances = 1,
Uint32 _StartVertexLocation = 0,
Uint32 _FirstInstanceLocation = 0) noexcept :
NumVertices {_NumVertices },
Flags {_Flags },
NumInstances {_NumInstances },
StartVertexLocation {_StartVertexLocation },
FirstInstanceLocation{_FirstInstanceLocation}
{}
#endif
};
typedef struct DrawAttribs DrawAttribs;
/// Defines the indexed draw command attributes.
/// This structure is used by IDeviceContext::DrawIndexed().
struct DrawIndexedAttribs
{
/// The number of indices to draw.
Uint32 NumIndices DEFAULT_INITIALIZER(0);
/// The type of elements in the index buffer.
/// Allowed values: VT_UINT16 and VT_UINT32.
VALUE_TYPE IndexType DEFAULT_INITIALIZER(VT_UNDEFINED);
/// Additional flags, see Diligent::DRAW_FLAGS.
DRAW_FLAGS Flags DEFAULT_INITIALIZER(DRAW_FLAG_NONE);
/// Number of instances to draw. If more than one instance is specified,
/// instanced draw call will be performed.
Uint32 NumInstances DEFAULT_INITIALIZER(1);
/// LOCATION (NOT the byte offset) of the first index in
/// the index buffer to start reading indices from.
Uint32 FirstIndexLocation DEFAULT_INITIALIZER(0);
/// A constant which is added to each index before accessing the vertex buffer.
Uint32 BaseVertex DEFAULT_INITIALIZER(0);
/// LOCATION (or INDEX, but NOT the byte offset) in the vertex
/// buffer to start reading instance data from.
Uint32 FirstInstanceLocation DEFAULT_INITIALIZER(0);
#if DILIGENT_CPP_INTERFACE
/// Initializes the structure members with default values.
/// Default values:
/// Member | Default value
/// -----------------------------------------|--------------------------------------
/// NumIndices | 0
/// IndexType | VT_UNDEFINED
/// Flags | DRAW_FLAG_NONE
/// NumInstances | 1
/// FirstIndexLocation | 0
/// BaseVertex | 0
/// FirstInstanceLocation | 0
constexpr DrawIndexedAttribs() noexcept {}
/// Initializes the structure members with user-specified values.
constexpr DrawIndexedAttribs(Uint32 _NumIndices,
VALUE_TYPE _IndexType,
DRAW_FLAGS _Flags,
Uint32 _NumInstances = 1,
Uint32 _FirstIndexLocation = 0,
Uint32 _BaseVertex = 0,
Uint32 _FirstInstanceLocation = 0) noexcept :
NumIndices {_NumIndices },
IndexType {_IndexType },
Flags {_Flags },
NumInstances {_NumInstances },
FirstIndexLocation {_FirstIndexLocation },
BaseVertex {_BaseVertex },
FirstInstanceLocation{_FirstInstanceLocation}
{}
#endif
};
typedef struct DrawIndexedAttribs DrawIndexedAttribs;
/// Defines the indirect draw command attributes.
/// This structure is used by IDeviceContext::DrawIndirect().
struct DrawIndirectAttribs
{
/// A pointer to the buffer, from which indirect draw attributes will be read.
///
/// The buffer must contain the following arguments at the specified offset:
/// Uint32 NumVertices;
/// Uint32 NumInstances;
/// Uint32 StartVertexLocation;
/// Uint32 FirstInstanceLocation;
IBuffer* pAttribsBuffer DEFAULT_VALUE(nullptr);
/// Offset from the beginning of the buffer to the location of draw command attributes.
Uint64 DrawArgsOffset DEFAULT_INITIALIZER(0);
/// Additional flags, see Diligent::DRAW_FLAGS.
DRAW_FLAGS Flags DEFAULT_INITIALIZER(DRAW_FLAG_NONE);
/// The number of draw commands to execute. When the pCounterBuffer is not null, this member
/// defines the maximum number of commands that will be executed.
/// Must be less than DrawCommandProperties::MaxDrawIndirectCount.
Uint32 DrawCount DEFAULT_INITIALIZER(1);
/// When DrawCount > 1, the byte stride between successive sets of draw parameters.
/// Must be a multiple of 4 and greater than or equal to 16 bytes (sizeof(Uint32) * 4).
Uint32 DrawArgsStride DEFAULT_INITIALIZER(16);
/// State transition mode for indirect draw arguments buffer.
RESOURCE_STATE_TRANSITION_MODE AttribsBufferStateTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
/// A pointer to the optional buffer, from which Uint32 value with the draw count will be read.
IBuffer* pCounterBuffer DEFAULT_VALUE(nullptr);
/// When pCounterBuffer is not null, an offset from the beginning of the buffer to the
/// location of the command counter.
Uint64 CounterOffset DEFAULT_INITIALIZER(0);
/// When counter buffer is not null, state transition mode for the count buffer.
RESOURCE_STATE_TRANSITION_MODE CounterBufferStateTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
#if DILIGENT_CPP_INTERFACE
/// Initializes the structure members with default values
constexpr DrawIndirectAttribs() noexcept {}
/// Initializes the structure members with user-specified values.
explicit constexpr DrawIndirectAttribs(IBuffer* _pAttribsBuffer,
DRAW_FLAGS _Flags,
Uint32 _DrawCount = DrawIndirectAttribs{}.DrawCount,
Uint64 _DrawArgsOffset = DrawIndirectAttribs{}.DrawArgsOffset,
Uint32 _DrawArgsStride = DrawIndirectAttribs{}.DrawArgsStride,
RESOURCE_STATE_TRANSITION_MODE _AttribsBufferTransitionMode = DrawIndirectAttribs{}.AttribsBufferStateTransitionMode,
IBuffer* _pCounterBuffer = DrawIndirectAttribs{}.pCounterBuffer,
Uint64 _CounterOffset = DrawIndirectAttribs{}.CounterOffset,
RESOURCE_STATE_TRANSITION_MODE _CounterBufferTransitionMode = DrawIndirectAttribs{}.CounterBufferStateTransitionMode) noexcept :
pAttribsBuffer {_pAttribsBuffer },
DrawArgsOffset {_DrawArgsOffset },
Flags {_Flags },
DrawCount {_DrawCount },
DrawArgsStride {_DrawArgsStride },
AttribsBufferStateTransitionMode{_AttribsBufferTransitionMode},
pCounterBuffer {_pCounterBuffer },
CounterOffset {_CounterOffset },
CounterBufferStateTransitionMode{_CounterBufferTransitionMode}
{}
#endif
};
typedef struct DrawIndirectAttribs DrawIndirectAttribs;
/// Defines the indexed indirect draw command attributes.
/// This structure is used by IDeviceContext::DrawIndexedIndirect().
struct DrawIndexedIndirectAttribs
{
/// The type of the elements in the index buffer.
/// Allowed values: VT_UINT16 and VT_UINT32.
VALUE_TYPE IndexType DEFAULT_INITIALIZER(VT_UNDEFINED);
/// A pointer to the buffer, from which indirect draw attributes will be read.
///
/// The buffer must contain the following arguments at the specified offset:
/// Uint32 NumIndices;
/// Uint32 NumInstances;
/// Uint32 FirstIndexLocation;
/// Uint32 BaseVertex;
/// Uint32 FirstInstanceLocation
IBuffer* pAttribsBuffer DEFAULT_INITIALIZER(nullptr);
/// Offset from the beginning of the buffer to the location of the draw command attributes.
Uint64 DrawArgsOffset DEFAULT_INITIALIZER(0);
/// Additional flags, see Diligent::DRAW_FLAGS.
DRAW_FLAGS Flags DEFAULT_INITIALIZER(DRAW_FLAG_NONE);
/// The number of draw commands to execute. When the pCounterBuffer is not null, this member
/// defines the maximum number of commands that will be executed.
/// Must be less than DrawCommandProperties::MaxDrawIndirectCount.
Uint32 DrawCount DEFAULT_INITIALIZER(1);
/// When DrawCount > 1, the byte stride between successive sets of draw parameters.
/// Must be a multiple of 4 and greater than or equal to 20 bytes (sizeof(Uint32) * 5).
Uint32 DrawArgsStride DEFAULT_INITIALIZER(20);
/// State transition mode for indirect draw arguments buffer.
RESOURCE_STATE_TRANSITION_MODE AttribsBufferStateTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
/// A pointer to the optional buffer, from which Uint32 value with the draw count will be read.
IBuffer* pCounterBuffer DEFAULT_INITIALIZER(nullptr);
/// When pCounterBuffer is not null, offset from the beginning of the counter buffer to the
/// location of the command counter.
Uint64 CounterOffset DEFAULT_INITIALIZER(0);
/// When counter buffer is not null, state transition mode for the count buffer.
RESOURCE_STATE_TRANSITION_MODE CounterBufferStateTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
#if DILIGENT_CPP_INTERFACE
/// Initializes the structure members with default values
constexpr DrawIndexedIndirectAttribs() noexcept {}
/// Initializes the structure members with user-specified values.
constexpr DrawIndexedIndirectAttribs(VALUE_TYPE _IndexType,
IBuffer* _pAttribsBuffer,
DRAW_FLAGS _Flags,
Uint32 _DrawCount = DrawIndexedIndirectAttribs{}.DrawCount,
Uint64 _DrawArgsOffset = DrawIndexedIndirectAttribs{}.DrawArgsOffset,
Uint32 _DrawArgsStride = DrawIndexedIndirectAttribs{}.DrawArgsStride,
RESOURCE_STATE_TRANSITION_MODE _AttribsBufferTransitionMode = DrawIndexedIndirectAttribs{}.AttribsBufferStateTransitionMode,
IBuffer* _pCounterBuffer = DrawIndexedIndirectAttribs{}.pCounterBuffer,
Uint64 _CounterOffset = DrawIndexedIndirectAttribs{}.CounterOffset,
RESOURCE_STATE_TRANSITION_MODE _CounterBufferTransitionMode = DrawIndexedIndirectAttribs{}.CounterBufferStateTransitionMode) noexcept :
IndexType {_IndexType },
pAttribsBuffer {_pAttribsBuffer },
DrawArgsOffset {_DrawArgsOffset },
Flags {_Flags },
DrawCount {_DrawCount },
DrawArgsStride {_DrawArgsStride },
AttribsBufferStateTransitionMode{_AttribsBufferTransitionMode},
pCounterBuffer {_pCounterBuffer },
CounterOffset {_CounterOffset },
CounterBufferStateTransitionMode{_CounterBufferTransitionMode}
{}
#endif
};
typedef struct DrawIndexedIndirectAttribs DrawIndexedIndirectAttribs;
/// Defines the mesh draw command attributes.
/// This structure is used by IDeviceContext::DrawMesh().
struct DrawMeshAttribs
{
/// The number of groups dispatched in X direction.
Uint32 ThreadGroupCountX DEFAULT_INITIALIZER(1);
/// The number of groups dispatched in Y direction.
Uint32 ThreadGroupCountY DEFAULT_INITIALIZER(1);
/// The number of groups dispatched in Y direction.
Uint32 ThreadGroupCountZ DEFAULT_INITIALIZER(1);
/// Additional flags, see Diligent::DRAW_FLAGS.
DRAW_FLAGS Flags DEFAULT_INITIALIZER(DRAW_FLAG_NONE);
#if DILIGENT_CPP_INTERFACE
/// Initializes the structure members with default values.
constexpr DrawMeshAttribs() noexcept {}
explicit constexpr DrawMeshAttribs(Uint32 _ThreadGroupCountX,
DRAW_FLAGS _Flags = DRAW_FLAG_NONE) noexcept :
ThreadGroupCountX{_ThreadGroupCountX},
Flags {_Flags}
{}
constexpr DrawMeshAttribs(Uint32 _ThreadGroupCountX,
Uint32 _ThreadGroupCountY,
DRAW_FLAGS _Flags = DRAW_FLAG_NONE) noexcept :
ThreadGroupCountX{_ThreadGroupCountX},
ThreadGroupCountY{_ThreadGroupCountY},
Flags {_Flags}
{}
constexpr DrawMeshAttribs(Uint32 _ThreadGroupCountX,
Uint32 _ThreadGroupCountY,
Uint32 _ThreadGroupCountZ,
DRAW_FLAGS _Flags = DRAW_FLAG_NONE) noexcept :
ThreadGroupCountX{_ThreadGroupCountX},
ThreadGroupCountY{_ThreadGroupCountY},
ThreadGroupCountZ{_ThreadGroupCountZ},
Flags {_Flags}
{}
#endif
};
typedef struct DrawMeshAttribs DrawMeshAttribs;
/// Defines the mesh indirect draw command attributes.
/// This structure is used by IDeviceContext::DrawMeshIndirect().
struct DrawMeshIndirectAttribs
{
/// A pointer to the buffer, from which indirect draw attributes will be read.
/// The buffer must contain the following arguments at the specified offset:
/// Direct3D12:
/// Uint32 ThreadGroupCountX;
/// Uint32 ThreadGroupCountY;
/// Uint32 ThreadGroupCountZ;
/// Vulkan:
/// Uint32 TaskCount;
/// Uint32 FirstTask;
/// Size of the buffer must be sizeof(Uint32[3]) * Attribs.MaxDrawCommands.
IBuffer* pAttribsBuffer DEFAULT_INITIALIZER(nullptr);
/// Offset from the beginning of the attribs buffer to the location of the draw command attributes.
Uint64 DrawArgsOffset DEFAULT_INITIALIZER(0);
/// Additional flags, see Diligent::DRAW_FLAGS.
DRAW_FLAGS Flags DEFAULT_INITIALIZER(DRAW_FLAG_NONE);
/// When pCounterBuffer is null, the number of commands to run.
/// When pCounterBuffer is not null, the maximum number of commands
/// that will be read from the count buffer.
Uint32 CommandCount DEFAULT_INITIALIZER(1);
/// State transition mode for indirect draw arguments buffer.
RESOURCE_STATE_TRANSITION_MODE AttribsBufferStateTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
/// A pointer to the optional buffer, from which Uint32 value with the draw count will be read.
IBuffer* pCounterBuffer DEFAULT_INITIALIZER(nullptr);
/// When pCounterBuffer is not null, an offset from the beginning of the buffer to the location of the command counter.
Uint64 CounterOffset DEFAULT_INITIALIZER(0);
/// When pCounterBuffer is not null, state transition mode for the count buffer.
RESOURCE_STATE_TRANSITION_MODE CounterBufferStateTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
#if DILIGENT_CPP_INTERFACE
/// Initializes the structure members with default values
constexpr DrawMeshIndirectAttribs() noexcept {}
/// Initializes the structure members with user-specified values.
constexpr DrawMeshIndirectAttribs(IBuffer* _pAttribsBuffer,
DRAW_FLAGS _Flags,
Uint32 _CommandCount,
Uint64 _DrawArgsOffset = DrawMeshIndirectAttribs{}.DrawArgsOffset,
RESOURCE_STATE_TRANSITION_MODE _AttribsBufferStateTransitionMode = DrawMeshIndirectAttribs{}.AttribsBufferStateTransitionMode,
IBuffer* _pCounterBuffer = DrawMeshIndirectAttribs{}.pCounterBuffer,
Uint64 _CounterOffset = DrawMeshIndirectAttribs{}.CounterOffset,
RESOURCE_STATE_TRANSITION_MODE _CounterBufferStateTransitionMode = DrawMeshIndirectAttribs{}.CounterBufferStateTransitionMode) noexcept :
pAttribsBuffer {_pAttribsBuffer },
DrawArgsOffset {_DrawArgsOffset },
Flags {_Flags },
CommandCount {_CommandCount },
AttribsBufferStateTransitionMode{_AttribsBufferStateTransitionMode},
pCounterBuffer {_pCounterBuffer },
CounterOffset {_CounterOffset },
CounterBufferStateTransitionMode{_CounterBufferStateTransitionMode}
{}
#endif
};
typedef struct DrawMeshIndirectAttribs DrawMeshIndirectAttribs;
/// Multi-draw command item.
struct MultiDrawItem
{
/// The number of vertices to draw.
Uint32 NumVertices DEFAULT_INITIALIZER(0);
/// LOCATION (or INDEX, but NOT the byte offset) of the first vertex in the
/// vertex buffer to start reading vertices from.
Uint32 StartVertexLocation DEFAULT_INITIALIZER(0);
};
typedef struct MultiDrawItem MultiDrawItem;
/// MultiDraw command attributes.
struct MultiDrawAttribs
{
/// The number of draw items to execute.
Uint32 DrawCount DEFAULT_INITIALIZER(0);
/// A pointer to the array of DrawCount draw command items.
const MultiDrawItem* pDrawItems DEFAULT_INITIALIZER(nullptr);
/// Additional flags, see Diligent::DRAW_FLAGS.
DRAW_FLAGS Flags DEFAULT_INITIALIZER(DRAW_FLAG_NONE);
/// The number of instances to draw. If more than one instance is specified,
/// instanced draw call will be performed.
Uint32 NumInstances DEFAULT_INITIALIZER(1);
/// LOCATION (or INDEX, but NOT the byte offset) in the vertex buffer to start
/// reading instance data from.
Uint32 FirstInstanceLocation DEFAULT_INITIALIZER(0);
#if DILIGENT_CPP_INTERFACE
constexpr MultiDrawAttribs() noexcept {}
constexpr MultiDrawAttribs(Uint32 _DrawCount,
const MultiDrawItem* _pDrawItems,
DRAW_FLAGS _Flags,
Uint32 _NumInstances = 1,
Uint32 _FirstInstanceLocation = 0) noexcept :
DrawCount {_DrawCount },
pDrawItems {_pDrawItems },
Flags {_Flags },
NumInstances {_NumInstances },
FirstInstanceLocation{_FirstInstanceLocation}
{}
#endif
};
typedef struct MultiDrawAttribs MultiDrawAttribs;
/// Multi-draw indexed command item.
struct MultiDrawIndexedItem
{
/// The number of indices to draw.
Uint32 NumIndices DEFAULT_INITIALIZER(0);
/// LOCATION (NOT the byte offset) of the first index in
/// the index buffer to start reading indices from.
Uint32 FirstIndexLocation DEFAULT_INITIALIZER(0);
/// A constant which is added to each index before accessing the vertex buffer.
Uint32 BaseVertex DEFAULT_INITIALIZER(0);
};
typedef struct MultiDrawIndexedItem MultiDrawIndexedItem;
/// MultiDraw command attributes.
struct MultiDrawIndexedAttribs
{
/// The number of draw items to execute.
Uint32 DrawCount DEFAULT_INITIALIZER(0);
/// A pointer to the array of DrawCount draw command items.
const MultiDrawIndexedItem* pDrawItems DEFAULT_INITIALIZER(nullptr);
/// The type of elements in the index buffer.
/// Allowed values: VT_UINT16 and VT_UINT32.
VALUE_TYPE IndexType DEFAULT_INITIALIZER(VT_UNDEFINED);
/// Additional flags, see Diligent::DRAW_FLAGS.
DRAW_FLAGS Flags DEFAULT_INITIALIZER(DRAW_FLAG_NONE);
/// Number of instances to draw. If more than one instance is specified,
/// instanced draw call will be performed.
Uint32 NumInstances DEFAULT_INITIALIZER(1);
/// LOCATION (or INDEX, but NOT the byte offset) in the vertex
/// buffer to start reading instance data from.
Uint32 FirstInstanceLocation DEFAULT_INITIALIZER(0);
#if DILIGENT_CPP_INTERFACE
constexpr MultiDrawIndexedAttribs() noexcept {}
constexpr MultiDrawIndexedAttribs(Uint32 _DrawCount,
const MultiDrawIndexedItem* _pDrawItems,
VALUE_TYPE _IndexType,
DRAW_FLAGS _Flags,
Uint32 _NumInstances = 1,
Uint32 _FirstInstanceLocation = 0) noexcept :
DrawCount {_DrawCount },
pDrawItems {_pDrawItems },
IndexType {_IndexType },
Flags {_Flags },
NumInstances {_NumInstances },
FirstInstanceLocation{_FirstInstanceLocation}
{}
#endif
};
typedef struct MultiDrawIndexedAttribs MultiDrawIndexedAttribs;
/// Defines which parts of the depth-stencil buffer to clear.
/// These flags are used by IDeviceContext::ClearDepthStencil().
DILIGENT_TYPED_ENUM(CLEAR_DEPTH_STENCIL_FLAGS, Uint32)
{
/// Perform no clear.
CLEAR_DEPTH_FLAG_NONE = 0x00,
/// Clear depth part of the buffer.
CLEAR_DEPTH_FLAG = 0x01,
/// Clear stencil part of the buffer.
CLEAR_STENCIL_FLAG = 0x02
};
DEFINE_FLAG_ENUM_OPERATORS(CLEAR_DEPTH_STENCIL_FLAGS)
/// Describes dispatch command arguments.
/// This structure is used by IDeviceContext::DispatchCompute().
struct DispatchComputeAttribs
{
/// The number of groups dispatched in X direction.
Uint32 ThreadGroupCountX DEFAULT_INITIALIZER(1);
/// The number of groups dispatched in Y direction.
Uint32 ThreadGroupCountY DEFAULT_INITIALIZER(1);
/// The number of groups dispatched in Z direction.
Uint32 ThreadGroupCountZ DEFAULT_INITIALIZER(1);
/// Compute group X size. This member is only used
/// by Metal backend and is ignored by others.
Uint32 MtlThreadGroupSizeX DEFAULT_INITIALIZER(0);
/// Compute group Y size. This member is only used
/// by Metal backend and is ignored by others.
Uint32 MtlThreadGroupSizeY DEFAULT_INITIALIZER(0);
/// Compute group Z size. This member is only used
/// by Metal backend and is ignored by others.
Uint32 MtlThreadGroupSizeZ DEFAULT_INITIALIZER(0);
#if DILIGENT_CPP_INTERFACE
constexpr DispatchComputeAttribs() noexcept {}
/// Initializes the structure with user-specified values.
constexpr DispatchComputeAttribs(Uint32 GroupsX, Uint32 GroupsY, Uint32 GroupsZ = 1) noexcept :
ThreadGroupCountX {GroupsX},
ThreadGroupCountY {GroupsY},
ThreadGroupCountZ {GroupsZ}
{}
#endif
};
typedef struct DispatchComputeAttribs DispatchComputeAttribs;
/// Describes dispatch command arguments.
/// This structure is used by IDeviceContext::DispatchComputeIndirect().
struct DispatchComputeIndirectAttribs
{
/// A pointer to the buffer containing indirect dispatch attributes.
/// The buffer must contain the following arguments at the specified offset:
/// Uint32 ThreadGroupCountX;
/// Uint32 ThreadGroupCountY;
/// Uint32 ThreadGroupCountZ;
IBuffer* pAttribsBuffer DEFAULT_INITIALIZER(nullptr);
/// State transition mode for indirect dispatch attributes buffer.
RESOURCE_STATE_TRANSITION_MODE AttribsBufferStateTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
/// The offset from the beginning of the buffer to the dispatch command arguments.
Uint64 DispatchArgsByteOffset DEFAULT_INITIALIZER(0);
/// Compute group X size. This member is only used
/// by Metal backend and is ignored by others.
Uint32 MtlThreadGroupSizeX DEFAULT_INITIALIZER(0);
/// Compute group Y size. This member is only used
/// by Metal backend and is ignored by others.
Uint32 MtlThreadGroupSizeY DEFAULT_INITIALIZER(0);
/// Compute group Z size. This member is only used
/// by Metal backend and is ignored by others.
Uint32 MtlThreadGroupSizeZ DEFAULT_INITIALIZER(0);
#if DILIGENT_CPP_INTERFACE
constexpr DispatchComputeIndirectAttribs() noexcept {}
/// Initializes the structure with user-specified values.
constexpr DispatchComputeIndirectAttribs(IBuffer* _pAttribsBuffer,
RESOURCE_STATE_TRANSITION_MODE _StateTransitionMode,
Uint64 _Offset = 0) :
pAttribsBuffer {_pAttribsBuffer },
AttribsBufferStateTransitionMode{_StateTransitionMode},
DispatchArgsByteOffset {_Offset }
{}
#endif
};
typedef struct DispatchComputeIndirectAttribs DispatchComputeIndirectAttribs;
/// Describes tile dispatch command arguments.
/// This structure is used by IDeviceContext::DispatchTile().
struct DispatchTileAttribs
{
/// The number of threads in one tile dispatched in X direction.
/// Must not be greater than TileSizeX returned by IDeviceContext::GetTileSize().
Uint32 ThreadsPerTileX DEFAULT_INITIALIZER(1);
/// The number of threads in one tile dispatched in Y direction.
/// Must not be greater than TileSizeY returned by IDeviceContext::GetTileSize().
Uint32 ThreadsPerTileY DEFAULT_INITIALIZER(1);
/// Additional flags, see Diligent::DRAW_FLAGS.
DRAW_FLAGS Flags DEFAULT_INITIALIZER(DRAW_FLAG_NONE);
#if DILIGENT_CPP_INTERFACE
constexpr DispatchTileAttribs() noexcept {}
/// Initializes the structure with user-specified values.
constexpr DispatchTileAttribs(Uint32 _ThreadsX,
Uint32 _ThreadsY,
DRAW_FLAGS _Flags = DRAW_FLAG_NONE) noexcept :
ThreadsPerTileX {_ThreadsX},
ThreadsPerTileY {_ThreadsY},
Flags {_Flags }
{}
#endif
};
typedef struct DispatchTileAttribs DispatchTileAttribs;
/// Describes multi-sampled texture resolve command arguments.
/// This structure is used by IDeviceContext::ResolveTextureSubresource().
struct ResolveTextureSubresourceAttribs
{
/// Mip level of the source multi-sampled texture to resolve.
Uint32 SrcMipLevel DEFAULT_INITIALIZER(0);
/// Array slice of the source multi-sampled texture to resolve.
Uint32 SrcSlice DEFAULT_INITIALIZER(0);
/// Source texture state transition mode, see Diligent::RESOURCE_STATE_TRANSITION_MODE.
RESOURCE_STATE_TRANSITION_MODE SrcTextureTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
/// Mip level of the destination non-multi-sampled texture.
Uint32 DstMipLevel DEFAULT_INITIALIZER(0);
/// Array slice of the destination non-multi-sampled texture.
Uint32 DstSlice DEFAULT_INITIALIZER(0);
/// Destination texture state transition mode, see Diligent::RESOURCE_STATE_TRANSITION_MODE.
RESOURCE_STATE_TRANSITION_MODE DstTextureTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
/// If one or both textures are typeless, specifies the type of the typeless texture.
/// If both texture formats are not typeless, in which case they must be identical, this member must be
/// either TEX_FORMAT_UNKNOWN, or match this format.
TEXTURE_FORMAT Format DEFAULT_INITIALIZER(TEX_FORMAT_UNKNOWN);
};
typedef struct ResolveTextureSubresourceAttribs ResolveTextureSubresourceAttribs;
/// Defines allowed flags for IDeviceContext::SetVertexBuffers() function.
DILIGENT_TYPED_ENUM(SET_VERTEX_BUFFERS_FLAGS, Uint8)
{
/// No extra operations.
SET_VERTEX_BUFFERS_FLAG_NONE = 0x00,
/// Reset the vertex buffers to only the buffers specified in this
/// call. All buffers previously bound to the pipeline will be unbound.
SET_VERTEX_BUFFERS_FLAG_RESET = 0x01
};
DEFINE_FLAG_ENUM_OPERATORS(SET_VERTEX_BUFFERS_FLAGS)
/// Describes the viewport.
/// This structure is used by IDeviceContext::SetViewports().
struct Viewport
{
/// X coordinate of the left boundary of the viewport.
Float32 TopLeftX DEFAULT_INITIALIZER(0.f);
/// Y coordinate of the top boundary of the viewport.
/// When defining a viewport, DirectX convention is used:
/// window coordinate systems originates in the LEFT TOP corner
/// of the screen with Y axis pointing down.
Float32 TopLeftY DEFAULT_INITIALIZER(0.f);
/// Viewport width.
Float32 Width DEFAULT_INITIALIZER(0.f);
/// Viewport Height.
Float32 Height DEFAULT_INITIALIZER(0.f);
/// Minimum depth of the viewport. Ranges between 0 and 1.
Float32 MinDepth DEFAULT_INITIALIZER(0.f);
/// Maximum depth of the viewport. Ranges between 0 and 1.
Float32 MaxDepth DEFAULT_INITIALIZER(1.f);
#if DILIGENT_CPP_INTERFACE
/// Initializes the structure.
constexpr Viewport(Float32 _TopLeftX, Float32 _TopLeftY,
Float32 _Width, Float32 _Height,
Float32 _MinDepth = 0, Float32 _MaxDepth = 1) noexcept :
TopLeftX {_TopLeftX},
TopLeftY {_TopLeftY},
Width {_Width },
Height {_Height },
MinDepth {_MinDepth},
MaxDepth {_MaxDepth}
{}
constexpr Viewport(Uint32 _Width, Uint32 _Height,
Float32 _MinDepth = 0, Float32 _MaxDepth = 1) noexcept :
Width {static_cast<Float32>(_Width) },
Height {static_cast<Float32>(_Height)},
MinDepth{_MinDepth},
MaxDepth{_MaxDepth}
{}
constexpr Viewport(Float32 _Width, Float32 _Height) noexcept :
Width {_Width },
Height{_Height}
{}