-
Notifications
You must be signed in to change notification settings - Fork 5
/
commands.hpp
1881 lines (1559 loc) · 76.1 KB
/
commands.hpp
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
#pragma once
#include <fwd.hpp>
#include <command/record.hpp>
#include <pipe.hpp>
#include <util/dlg.hpp>
#include <util/linalloc.hpp>
#include <nytl/flags.hpp>
#include <nytl/span.hpp>
// See ~Command. Keep in mind that we use a custom per-CommandRecord allocator
// for all Commands, that's why we can use span<> here without the referenced
// data being owned anywhere. It's just guaranteed to stay alive as long
// as the CommandRecord.
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
#endif // __GNUC__
namespace vil {
// The type of a command is used e.g. to hide them in the UI.
enum class CommandCategory : u32 {
other = (1u << 0u),
// Commands that bind state, buffers, push constants etc
bind = (1u << 1u),
// States that are responsible for synchronization, events,
// barriers etc.
sync = (1u << 2u),
// Draw commands
draw = (1u << 3u),
// Dispatch commdnas
dispatch = (1u << 4u),
// Copies, clears and blits
transfer = (1u << 5u),
// Commands that end a section
end = (1u << 6u),
// Query pool commands
query = (1u << 7u),
// TracyRays commands
traceRays = (1u << 8u),
// BuildAccelerationStructures commands
buildAccelStruct = (1u << 9u),
// BeginRenderPass
beginRenderPass = (1u << 10u),
// RenderSectionCommand
renderSection = (1u << 11u),
};
enum class CommandType : u32 {
root = 0,
waitEvents,
waitEvents2,
barrier,
barrier2,
beginRenderPass,
nextSubpass,
firstSubpass, // implicit
endRenderPass,
draw,
drawIndirect,
drawIndexed,
drawIndirectCount,
drawMulti,
drawMultiIndexed,
bindVertexBuffers,
bindIndexBuffer,
bindDescriptorSet,
dispatch,
dispatchIndirect,
dispatchBase, // DispatchBaseCmd NOT DispatchCmdBase
copyImage,
copyBufferToImage,
copyImageToBuffer,
blitImage,
resolveImage,
copyBuffer,
updateBuffer,
fillBuffer,
clearColorImage,
clearDepthStencilImage,
clearAttachment,
setEvent,
setEvent2,
resetEvent,
executeCommandsChild, // implicit
executeCommands,
beginDebugUtilsLabel,
endDebugUtilsLabel,
insertDebugUtilsLabel,
bindPipeline,
pushConstants,
setViewport,
setScissor,
setLineWidth,
setDepthBias,
setDepthBounds,
setBlendConstants,
setStencilCompareMask,
setStencilWriteMask,
setStencilReference,
beginQuery,
endQuery,
resetQueryPool,
writeTimestamp,
copyQueryPoolResults,
pushDescriptorSet,
pushDescriptorSetWithTemplate,
setFragmentShadingRate,
beginConditionalRendering,
endConditionalRendering,
setLineStipple,
setCullMode,
setFrontFace,
setPrimitiveTopology,
setViewportWithCount,
setScissorWithCount,
setDepthTestEnable,
setDepthWriteEnable,
setDepthCompareOp,
setDepthBoundsTestEnable,
setStencilTestEnable,
setStencilOp,
setPatchControlPoints,
setRasterizerDiscardEnable,
setDepthBiasEnable,
setLogicOp,
setPrimitiveRestartEnable,
setSampleLocations,
setDisacrdRectangle,
copyAccelStruct,
copyAccelStructToMemory,
copyMemoryToAccelStruct,
writeAccelStructsProperties,
buildAccelStructs,
buildAccelStructsIndirect,
traceRays,
traceRaysIndirect,
setRayTracingPipelineStackSize,
beginRendering,
endRendering,
setVertexInput,
setColorWriteEnable,
count,
};
using CommandCategoryFlags = nytl::Flags<CommandCategory>;
struct CommandVisitor;
template<typename C>
void doVisit(CommandVisitor& v, C& cmd);
// The list of commands in a CommandBuffer is organized as a tree.
// Section-like commands (e.g. cmdBeginRenderPass) have all their commands
// stored as children
struct Command {
using Type = CommandType;
using Category = CommandCategory;
using CategoryFlags = CommandCategoryFlags;
Command();
// NOTE: Commands should never have a non-trivial destructor (that is
// static_assert'd in addCmd) since it won't be called. We do this
// so that resetting command buffers does not add significant overhead
// as we can have *a lot* of commands in a command buffer.
// When special commands need resources with destructor, those should
// be separately stored in the command record.
~Command() = default;
// The name of the command as string (might include parameter information).
// Used by the default 'display' implementation.
virtual std::string toString() const { return std::string(nameDesc()); }
// Returns the name of the command.
virtual std::string_view nameDesc() const = 0;
virtual Category category() const { return Category::other; }
virtual Type type() const = 0;
// Records itself into the given command buffer.
// Does not record its child commands (if it has any).
virtual void record(const Device& dev, VkCommandBuffer, u32 qfam) const = 0;
// Draws the command inspector UI.
// Gets a list of destroyed handled, might include referenced handles
// by this command. Must not dereference them.
virtual void displayInspector(Gui&) const {}
// Returns the children command list. For non-parent commands, this
// is simply null.
virtual Command* children() const { return nullptr; }
// Returns whether the given command is a child of this one.
// Complexity is linear in the number of child commands.
// Returns false for itself.
virtual bool isChild(const Command& cmd) const;
// Returns whether the given command is a descendant of this one.
// Complexity is linear in the number of descendants.
// Returns false for itself.
virtual bool isDescendant(const Command& cmd) const;
virtual void visit(CommandVisitor& v) const = 0;
// Forms a forward linked list with siblings
Command* next {};
#ifdef VIL_COMMAND_CALLSTACKS
span<void*> stacktrace {};
#endif // VIL_COMMAND_CALLSTACKS
};
NYTL_FLAG_OPS(Command::Category)
enum class NullName {
empty, // ""
null, // "<null>"
destroyed, // "<destroyed>"
};
enum class NameType {
null, // handle was null. Name depends on NullName passed to name()
unnamed, // handle has no name. Name might contain meta information
named, // name will contain application-given debug name
};
struct NameResult {
NameType type;
std::string name;
};
NameResult nameRes(Handle*, VkObjectType, NullName = NullName::null, bool displayType = false);
template<typename H>
NameResult nameRes(H* handle, NullName nn = NullName::null, bool displayType = false) {
return nameRes(handle, handle ? handle->objectType : VK_OBJECT_TYPE_MAX_ENUM, nn, displayType);
}
// Base Command class for commands that have children.
// These children might be directly part of the command record (see SectionCommand)
// or external (e.g. ExecuteCommandBuffersCmd).
struct ParentCommand : Command {
struct SectionStats {
u32 numDraws {};
u32 numDispatches {};
u32 numRayTraces {};
u32 numTransfers {};
u32 numSyncCommands {};
u32 numTotalCommands {};
u32 numChildSections {};
u32 totalNumCommands {};
// Most significant used handles. Important to not include
// anything temporary here.
// TODO: add a BlockVector utility and use that here.
struct BoundPipeNode {
BoundPipeNode* next {};
Pipeline* pipe {};
};
BoundPipeNode* boundPipelines {};
u32 numPipeBinds {};
};
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
// Returns the stats over the section this ParentCommand represents.
// Note that the stats only contain information about the direct children.
virtual const SectionStats& sectionStats() const = 0;
// First command of the direct children that is also a ParentCommand.
// Might be null if all children are leaf commands.
virtual ParentCommand* firstChildParent() const = 0;
// Points to the next ParentCommand on the same level as this one.
ParentCommand* nextParent_ {};
};
// Base Command class for all commands containing their children, such
// as BeginRenderPassCmd, BeginDebugUtilsLabelCmd or BeginConditionalRenderingCmd.
struct SectionCommand : ParentCommand {
Command* children_ {};
SectionStats stats_ {};
ParentCommand* firstChildParent_ {};
Command* children() const override { return children_; }
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
const SectionStats& sectionStats() const override { return stats_; }
ParentCommand* firstChildParent() const override { return firstChildParent_; }
};
template<typename B, CommandType Type>
struct CmdDerive : B {
using B::B;
static constexpr CommandType staticType() { return Type; }
CommandType type() const override { return staticType(); }
};
// Meta-command. Root node of the command hierarchy.
// Empty SectionCommand.
struct RootCommand final : CmdDerive<SectionCommand, CommandType::root> {
void record(const Device&, VkCommandBuffer, u32) const override {}
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
Category category() const override { return Category::other; }
std::string_view nameDesc() const override { return "<RootCommand>"; }
};
struct BarrierCmdBase : Command {
VkPipelineStageFlags srcStageMask {}; // only set when legacy
VkPipelineStageFlags dstStageMask {}; // only set when legacy
span<VkMemoryBarrier> memBarriers;
span<VkBufferMemoryBarrier> bufBarriers;
span<VkImageMemoryBarrier> imgBarriers;
span<Image*> images;
span<Buffer*> buffers;
void displayInspector(Gui& gui) const override;
MatchVal doMatch(const BarrierCmdBase& rhs) const;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
// NOTE: we need to patch barriers when recording (instead of just
// storing the patched versions) so we can still show the correct,
// application-provided barriers in the UI.
struct PatchedBarriers {
span<const VkMemoryBarrier> memBarriers;
span<VkBufferMemoryBarrier> bufBarriers;
span<VkImageMemoryBarrier> imgBarriers;
};
PatchedBarriers patchedBarriers(ThreadMemScope& memScope,
u32 qfam) const;
};
// For synchronization2 commands.
// Not merged with BarrierCmdBase so we can display them correctly
// in the UI.
struct Barrier2CmdBase : Command {
VkDependencyFlags flags {};
span<VkMemoryBarrier2> memBarriers;
span<VkBufferMemoryBarrier2> bufBarriers;
span<VkImageMemoryBarrier2> imgBarriers;
span<Image*> images;
span<Buffer*> buffers;
void displayInspector(Gui& gui) const override;
MatchVal doMatch(const Barrier2CmdBase& rhs) const;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
// NOTE: we need to patch barriers when recording (instead of just
// storing the patched versions) so we can still show the correct,
// application-provided barriers in the UI.
VkDependencyInfo patchedBarriers(ThreadMemScope& memScope,
u32 qfam) const;
};
struct WaitEventsCmd : CmdDerive<BarrierCmdBase, CommandType::waitEvents> {
span<Event*> events;
std::string_view nameDesc() const override { return "WaitEvents"; }
Category category() const override { return Category::sync; }
void displayInspector(Gui& gui) const override;
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct WaitEvents2Cmd : CmdDerive<Barrier2CmdBase, CommandType::waitEvents2> {
span<Event*> events;
std::string_view nameDesc() const override { return "WaitEvents2"; }
Category category() const override { return Category::sync; }
void displayInspector(Gui& gui) const override;
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct BarrierCmd : CmdDerive<BarrierCmdBase, CommandType::barrier> {
VkDependencyFlags dependencyFlags {};
std::string_view nameDesc() const override { return "PipelineBarrier"; }
Category category() const override { return Category::sync; }
void displayInspector(Gui& gui) const override;
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct Barrier2Cmd : CmdDerive<Barrier2CmdBase, CommandType::barrier2> {
std::string_view nameDesc() const override { return "PipelineBarrier2"; }
Category category() const override { return Category::sync; }
void displayInspector(Gui& gui) const override;
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
// All direct children must be of type 'NextSubpassCmd'
struct BeginRenderPassCmd final : CmdDerive<SectionCommand, CommandType::beginRenderPass> {
VkRenderPassBeginInfo info {}; // TODO: remove, extract renderArea
span<VkClearValue> clearValues;
RenderPass* rp {};
// Used attachments, stored here separately from framebuffer since
// the framebuffer might be imageless
span<ImageView*> attachments;
Framebuffer* fb {}; // NOTE: might be null for imageless framebuffer ext
VkSubpassBeginInfo subpassBeginInfo {}; // for the first subpass
// Returns the subpass that contains the given command.
// Returns u32(-1) if no subpass is ancestor of the given command.
u32 subpassOfDescendant(const Command& cmd) const;
std::string toString() const override;
std::string_view nameDesc() const override { return "BeginRenderPass"; }
void displayInspector(Gui& gui) const override;
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
Category category() const override { return Category::beginRenderPass; }
};
struct RenderSectionCommand : SectionCommand {
RenderPassInstanceState rpi;
Category category() const override { return Category::renderSection; }
};
struct SubpassCmd : RenderSectionCommand {
u32 subpassID {};
};
struct NextSubpassCmd final : CmdDerive<SubpassCmd, CommandType::nextSubpass> {
VkSubpassEndInfo endInfo {}; // for the previous subpass
VkSubpassBeginInfo beginInfo; // for the new subpass
using CmdDerive::CmdDerive;
// toString should probably rather return the subpass number.
// Must be tracked while recording
std::string_view nameDesc() const override { return "NextSubpass"; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
// Meta command needed for correct hierachy. We want each subpass to
// have its own section.
struct FirstSubpassCmd final : CmdDerive<SubpassCmd, CommandType::firstSubpass> {
using CmdDerive::CmdDerive;
std::string_view nameDesc() const override { return "Subpass 0"; }
void record(const Device&, VkCommandBuffer, u32) const override {}
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct EndRenderPassCmd final : CmdDerive<Command, CommandType::endRenderPass> {
VkSubpassEndInfo endInfo {}; // for the previous subpass
std::string_view nameDesc() const override { return "EndRenderPass"; }
Category category() const override { return Category::end; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
// Base command from which all draw, dispatch and traceRays command are derived.
struct StateCmdBase : Command {
virtual const DescriptorState& boundDescriptors() const = 0;
virtual const Pipeline* boundPipe() const = 0;
virtual const PushConstantData& boundPushConstants() const = 0;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct DrawCmdBase : StateCmdBase {
const GraphicsState* state {};
PushConstantData pushConstants;
DrawCmdBase(); // dummy constructor
DrawCmdBase(CommandBuffer& cb);
Category category() const override { return Category::draw; }
void displayGrahpicsState(Gui& gui, bool indices) const;
MatchVal doMatch(const DrawCmdBase& cmd, bool indexed) const;
const DescriptorState& boundDescriptors() const override { return *state; }
const Pipeline* boundPipe() const override { return state->pipe; }
const PushConstantData& boundPushConstants() const override { return pushConstants; }
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct DrawCmd final : CmdDerive<DrawCmdBase, CommandType::draw> {
u32 vertexCount;
u32 instanceCount;
u32 firstVertex;
u32 firstInstance;
using CmdDerive::CmdDerive;
std::string toString() const override;
void displayInspector(Gui& gui) const override;
std::string_view nameDesc() const override { return "Draw"; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct DrawIndirectCmd final : CmdDerive<DrawCmdBase, CommandType::drawIndirect> {
Buffer* buffer {};
VkDeviceSize offset {};
u32 drawCount {};
u32 stride {};
bool indexed {};
using CmdDerive::CmdDerive;
std::string toString() const override;
std::string_view nameDesc() const override {
return indexed ? "DrawIndexedIndirect" : "DrawIndirect";
}
void displayInspector(Gui& gui) const override;
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct DrawIndexedCmd final : CmdDerive<DrawCmdBase, CommandType::drawIndexed> {
u32 indexCount {};
u32 instanceCount {};
u32 firstIndex {};
i32 vertexOffset {};
u32 firstInstance {};
using CmdDerive::CmdDerive;
std::string toString() const override;
void displayInspector(Gui& gui) const override;
std::string_view nameDesc() const override { return "DrawIndexed"; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct DrawIndirectCountCmd final : CmdDerive<DrawCmdBase, CommandType::drawIndirectCount> {
Buffer* buffer {};
VkDeviceSize offset {};
u32 maxDrawCount {};
u32 stride {};
Buffer* countBuffer {};
VkDeviceSize countBufferOffset {};
bool indexed {};
using CmdDerive::CmdDerive;
std::string toString() const override;
std::string_view nameDesc() const override {
return indexed ? "DrawIndexedIndirectCount" : "DrawIndirectCount";
}
void displayInspector(Gui& gui) const override;
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct DrawMultiCmd final : CmdDerive<DrawCmdBase, CommandType::drawMulti> {
span<VkMultiDrawInfoEXT> vertexInfos;
u32 instanceCount {};
u32 firstInstance {};
// NOTE: only here for gui, we don't forward it since we copied
// the vertexInfos into a tight span
u32 stride {};
using CmdDerive::CmdDerive;
std::string toString() const override;
std::string_view nameDesc() const override { return "DrawMulti"; };
void displayInspector(Gui& gui) const override;
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct DrawMultiIndexedCmd final : CmdDerive<DrawCmdBase, CommandType::drawMultiIndexed> {
span<VkMultiDrawIndexedInfoEXT> indexInfos;
u32 instanceCount {};
u32 firstInstance {};
u32 stride {}; // NOTE: only here for gui, we don't forward it
std::optional<i32> vertexOffset {};
using CmdDerive::CmdDerive;
std::string toString() const override;
std::string_view nameDesc() const override { return "DrawMultiIndexed"; };
void displayInspector(Gui& gui) const override;
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct BindVertexBuffersCmd final : CmdDerive<Command, CommandType::bindVertexBuffers> {
u32 firstBinding;
span<BoundVertexBuffer> buffers;
std::string toString() const override;
void displayInspector(Gui&) const override;
std::string_view nameDesc() const override { return "BindVertexBuffers"; }
Category category() const override { return Category::bind; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct BindIndexBufferCmd final : CmdDerive<Command, CommandType::bindIndexBuffer> {
Buffer* buffer {};
VkDeviceSize offset {};
VkIndexType indexType {};
std::string_view nameDesc() const override { return "BindIndexBuffer"; }
Category category() const override { return Category::bind; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct BindDescriptorSetCmd final : CmdDerive<Command, CommandType::bindDescriptorSet> {
u32 firstSet;
VkPipelineBindPoint pipeBindPoint;
PipelineLayout* pipeLayout; // kept alive via shared_ptr in CommandBuffer
span<DescriptorSet*> sets; // NOTE: handles may be invalid
span<u32> dynamicOffsets;
std::string toString() const override;
std::string_view nameDesc() const override { return "BindDescriptorSets"; }
Category category() const override { return Category::bind; }
void record(const Device&, VkCommandBuffer, u32) const override;
void displayInspector(Gui& gui) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct DispatchCmdBase : StateCmdBase {
const ComputeState* state {};
PushConstantData pushConstants;
DispatchCmdBase() = default;
DispatchCmdBase(CommandBuffer&);
Category category() const override { return Category::dispatch; }
void displayComputeState(Gui& gui) const;
MatchVal doMatch(const DispatchCmdBase&) const;
const DescriptorState& boundDescriptors() const override { return *state; }
const Pipeline* boundPipe() const override { return state->pipe; }
const PushConstantData& boundPushConstants() const override { return pushConstants; }
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct DispatchCmd final : CmdDerive<DispatchCmdBase, CommandType::dispatch> {
u32 groupsX {};
u32 groupsY {};
u32 groupsZ {};
using CmdDerive::CmdDerive;
std::string toString() const override;
void displayInspector(Gui& gui) const override;
std::string_view nameDesc() const override { return "Dispatch"; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct DispatchIndirectCmd final : CmdDerive<DispatchCmdBase, CommandType::dispatchIndirect> {
Buffer* buffer {};
VkDeviceSize offset {};
using CmdDerive::CmdDerive;
std::string toString() const override;
void displayInspector(Gui& gui) const override;
std::string_view nameDesc() const override { return "DispatchIndirect"; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct DispatchBaseCmd final : CmdDerive<DispatchCmdBase, CommandType::dispatchBase> {
u32 baseGroupX {};
u32 baseGroupY {};
u32 baseGroupZ {};
u32 groupsX {};
u32 groupsY {};
u32 groupsZ {};
using CmdDerive::CmdDerive;
std::string toString() const override;
void displayInspector(Gui& gui) const override;
std::string_view nameDesc() const override { return "DispatchBase"; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
// transfer commands
struct CopyImageCmd final : CmdDerive<Command, CommandType::copyImage> {
Image* src {};
Image* dst {};
VkImageLayout srcLayout {};
VkImageLayout dstLayout {};
span<VkImageCopy2> copies;
const void* pNext {};
std::string toString() const override;
Category category() const override { return Category::transfer; }
void displayInspector(Gui& gui) const override;
std::string_view nameDesc() const override { return "CopyImage"; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct CopyBufferToImageCmd final : CmdDerive<Command, CommandType::copyBufferToImage> {
Buffer* src {};
Image* dst {};
VkImageLayout dstLayout {};
span<VkBufferImageCopy2> copies;
const void* pNext {};
std::string toString() const override;
Category category() const override { return Category::transfer; }
void displayInspector(Gui& gui) const override;
std::string_view nameDesc() const override { return "CopyBufferToImage"; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct CopyImageToBufferCmd final : CmdDerive<Command, CommandType::copyImageToBuffer> {
Image* src {};
Buffer* dst {};
VkImageLayout srcLayout {};
span<VkBufferImageCopy2> copies;
const void* pNext {};
std::string toString() const override;
Category category() const override { return Category::transfer; }
void displayInspector(Gui& gui) const override;
std::string_view nameDesc() const override { return "CopyImageToBuffer"; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct BlitImageCmd final : CmdDerive<Command, CommandType::blitImage> {
Image* src {};
Image* dst {};
VkImageLayout srcLayout {};
VkImageLayout dstLayout {};
span<VkImageBlit2> blits;
VkFilter filter {};
const void* pNext {};
std::string toString() const override;
Category category() const override { return Category::transfer; }
void displayInspector(Gui& gui) const override;
std::string_view nameDesc() const override { return "BlitImage"; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct ResolveImageCmd final : CmdDerive<Command, CommandType::resolveImage> {
Image* src {};
VkImageLayout srcLayout {};
Image* dst {};
VkImageLayout dstLayout {};
span<VkImageResolve2> regions;
const void* pNext {};
std::string toString() const override;
void displayInspector(Gui& gui) const override;
std::string_view nameDesc() const override { return "ResolveImage"; }
Category category() const override { return Category::transfer; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct CopyBufferCmd final : CmdDerive<Command, CommandType::copyBuffer> {
Buffer* src {};
Buffer* dst {};
span<VkBufferCopy2> regions;
const void* pNext {};
std::string toString() const override;
void displayInspector(Gui& gui) const override;
std::string_view nameDesc() const override { return "CopyBuffer"; }
Category category() const override { return Category::transfer; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct UpdateBufferCmd final : CmdDerive<Command, CommandType::updateBuffer> {
Buffer* dst {};
VkDeviceSize offset {};
span<std::byte> data;
std::string toString() const override;
void displayInspector(Gui& gui) const override;
std::string_view nameDesc() const override { return "UpdateBuffer"; }
Category category() const override { return Category::transfer; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct FillBufferCmd final : CmdDerive<Command, CommandType::fillBuffer> {
Buffer* dst {};
VkDeviceSize offset {};
VkDeviceSize size {};
u32 data {};
std::string toString() const override;
void displayInspector(Gui& gui) const override;
std::string_view nameDesc() const override { return "FillBuffer"; }
Category category() const override { return Category::transfer; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct ClearColorImageCmd final : CmdDerive<Command, CommandType::clearColorImage> {
Image* dst {};
VkClearColorValue color;
VkImageLayout dstLayout {};
span<VkImageSubresourceRange> ranges;
std::string toString() const override;
void displayInspector(Gui& gui) const override;
Category category() const override { return Category::transfer; }
std::string_view nameDesc() const override { return "ClearColorImage"; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct ClearDepthStencilImageCmd final : CmdDerive<Command, CommandType::clearDepthStencilImage> {
Image* dst {};
VkClearDepthStencilValue value {};
VkImageLayout dstLayout {};
span<VkImageSubresourceRange> ranges;
std::string toString() const override;
void displayInspector(Gui& gui) const override;
Category category() const override { return Category::transfer; }
std::string_view nameDesc() const override { return "ClearDepthStencilImage"; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct ClearAttachmentCmd final : CmdDerive<Command, CommandType::clearAttachment> {
span<VkClearAttachment> attachments;
span<VkClearRect> rects;
std::string_view nameDesc() const override { return "ClearAttachment"; }
void displayInspector(Gui& gui) const override;
// NOTE: strictly speaking this isn't a transfer, we don't care.
Category category() const override { return Category::transfer; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct SetEventCmd final : CmdDerive<Command, CommandType::setEvent> {
Event* event {};
VkPipelineStageFlags stageMask {};
std::string toString() const override;
void displayInspector(Gui& gui) const override;
std::string_view nameDesc() const override { return "SetEvent"; }
Category category() const override { return Category::sync; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct SetEvent2Cmd final : CmdDerive<Barrier2CmdBase, CommandType::setEvent2> {
Event* event {};
std::string toString() const override;
void displayInspector(Gui& gui) const override;
std::string_view nameDesc() const override { return "SetEvent"; }
Category category() const override { return Category::sync; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct ResetEventCmd final : CmdDerive<Command, CommandType::resetEvent> {
Event* event {};
VkPipelineStageFlags2 stageMask {};
bool legacy {}; // whether it's coming from a legacy (not sync2) command
std::string toString() const override;
void displayInspector(Gui& gui) const override;
std::string_view nameDesc() const override {
return legacy ? "ResetEvent" : "ResetEvent2";
}
Category category() const override { return Category::sync; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
// Meta-command, inserted for each command buffer passed to CmdExecuteCommands.
// We want this since ExecuteCommandsCmd::children() would be awkward otherwise
// when there are multiple command buffers executed.
struct ExecuteCommandsChildCmd final : CmdDerive<ParentCommand, CommandType::executeCommandsChild> {
CommandRecord* record_ {}; // kept alive in parent CommandRecord
unsigned id_ {};
std::string_view nameDesc() const override { return "ExecuteCommandsChild"; }
std::string toString() const override;
void record(const Device&, VkCommandBuffer, u32) const override {}
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
// Will return the commands from the embedded record.
// This means that traversal of the command hierarchy can happen without
// special consideration of ExecuteCommands, they will automatically
// be part of the hierarchy, *without* being duplicated into it.
Command* children() const override;
const SectionStats& sectionStats() const override;
ParentCommand* firstChildParent() const override;
};
struct ExecuteCommandsCmd final : CmdDerive<ParentCommand, CommandType::executeCommands> {
ExecuteCommandsChildCmd* children_ {};
SectionStats stats_ {};
Command* children() const override { return children_; }
void displayInspector(Gui& gui) const override;
std::string_view nameDesc() const override { return "ExecuteCommands"; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
ParentCommand* firstChildParent() const override { return children_; }
const SectionStats& sectionStats() const override {
// needed only for numChildSections, empty otherwise.
return stats_;
}
};
struct BeginDebugUtilsLabelCmd final : CmdDerive<SectionCommand, CommandType::beginDebugUtilsLabel> {
const char* name {};
std::array<float, 4> color; // NOTE: could use this in UI
std::string toString() const override { return name; }
void record(const Device&, VkCommandBuffer, u32) const override;
// NOTE: yes, we return more than just the command here.
// But that's because the command itself isn't of any use without the label.
std::string_view nameDesc() const override { return name; }
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct EndDebugUtilsLabelCmd final : CmdDerive<Command, CommandType::endDebugUtilsLabel> {
std::string_view nameDesc() const override { return "EndLabel"; }
Category category() const override { return Category::end; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct InsertDebugUtilsLabelCmd final : CmdDerive<Command, CommandType::insertDebugUtilsLabel> {
const char* name {};
std::array<float, 4> color; // NOTE: could use this in UI
std::string_view nameDesc() const override { return name; }
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
void record(const Device&, VkCommandBuffer, u32) const override;
};
struct BindPipelineCmd final : CmdDerive<Command, CommandType::bindPipeline> {
VkPipelineBindPoint bindPoint {};
Pipeline* pipe {};
std::string toString() const override;
void displayInspector(Gui& gui) const override;
std::string_view nameDesc() const override { return "BindPipeline"; }
Category category() const override { return Category::bind; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct PushConstantsCmd final : CmdDerive<Command, CommandType::pushConstants> {
PipelineLayout* pipeLayout; // kept alive via shared_ptr in CommandBuffer
VkShaderStageFlags stages {};
u32 offset {};
span<std::byte> values;
std::string_view nameDesc() const override { return "PushConstants"; }
Category category() const override { return Category::bind; }
void record(const Device&, VkCommandBuffer, u32) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
// dynamic state
struct SetViewportCmd final : CmdDerive<Command, CommandType::setViewport> {
u32 first {};
span<VkViewport> viewports;
Category category() const override { return Category::bind; }
std::string_view nameDesc() const override { return "SetViewport"; }
void record(const Device&, VkCommandBuffer cb, u32) const override;
void displayInspector(Gui& gui) const override;
void visit(CommandVisitor& v) const override { doVisit(v, *this); }
};
struct SetScissorCmd final : CmdDerive<Command, CommandType::setScissor> {
u32 first {};
span<VkRect2D> scissors;
Category category() const override { return Category::bind; }
std::string_view nameDesc() const override { return "SetScissor"; }