Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/rendering/rendering_device_graph.h
10277 views
1
/**************************************************************************/
2
/* rendering_device_graph.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "core/object/worker_thread_pool.h"
34
#include "rendering_device_commons.h"
35
#include "rendering_device_driver.h"
36
37
// Buffer barriers have not shown any significant improvement or shown to be
38
// even detrimental to performance. However, there are currently some known
39
// cases where using them can solve problems that using singular memory
40
// barriers does not, probably due to driver issues (see comment on PR #84976
41
// https://github.com/godotengine/godot/pull/84976#issuecomment-1878566830).
42
43
#define USE_BUFFER_BARRIERS 1
44
45
class RenderingDeviceGraph {
46
public:
47
struct ComputeListInstruction {
48
enum Type {
49
TYPE_NONE,
50
TYPE_BIND_PIPELINE,
51
TYPE_BIND_UNIFORM_SETS,
52
TYPE_DISPATCH,
53
TYPE_DISPATCH_INDIRECT,
54
TYPE_SET_PUSH_CONSTANT,
55
TYPE_UNIFORM_SET_PREPARE_FOR_USE
56
};
57
58
Type type = TYPE_NONE;
59
};
60
61
struct DrawListInstruction {
62
enum Type {
63
TYPE_NONE,
64
TYPE_BIND_INDEX_BUFFER,
65
TYPE_BIND_PIPELINE,
66
TYPE_BIND_UNIFORM_SETS,
67
TYPE_BIND_VERTEX_BUFFERS,
68
TYPE_CLEAR_ATTACHMENTS,
69
TYPE_DRAW,
70
TYPE_DRAW_INDEXED,
71
TYPE_DRAW_INDIRECT,
72
TYPE_DRAW_INDEXED_INDIRECT,
73
TYPE_EXECUTE_COMMANDS,
74
TYPE_NEXT_SUBPASS,
75
TYPE_SET_BLEND_CONSTANTS,
76
TYPE_SET_LINE_WIDTH,
77
TYPE_SET_PUSH_CONSTANT,
78
TYPE_SET_SCISSOR,
79
TYPE_SET_VIEWPORT,
80
TYPE_UNIFORM_SET_PREPARE_FOR_USE
81
};
82
83
Type type = TYPE_NONE;
84
};
85
86
struct RecordedCommand {
87
enum Type {
88
TYPE_NONE,
89
TYPE_BUFFER_CLEAR,
90
TYPE_BUFFER_COPY,
91
TYPE_BUFFER_GET_DATA,
92
TYPE_BUFFER_UPDATE,
93
TYPE_COMPUTE_LIST,
94
TYPE_DRAW_LIST,
95
TYPE_TEXTURE_CLEAR,
96
TYPE_TEXTURE_COPY,
97
TYPE_TEXTURE_GET_DATA,
98
TYPE_TEXTURE_RESOLVE,
99
TYPE_TEXTURE_UPDATE,
100
TYPE_CAPTURE_TIMESTAMP,
101
TYPE_DRIVER_CALLBACK,
102
TYPE_MAX
103
};
104
105
Type type = TYPE_NONE;
106
int32_t adjacent_command_list_index = -1;
107
RDD::MemoryBarrier memory_barrier;
108
int32_t normalization_barrier_index = -1;
109
int normalization_barrier_count = 0;
110
int32_t transition_barrier_index = -1;
111
int32_t transition_barrier_count = 0;
112
#if USE_BUFFER_BARRIERS
113
int32_t buffer_barrier_index = -1;
114
int32_t buffer_barrier_count = 0;
115
#endif
116
int32_t label_index = -1;
117
BitField<RDD::PipelineStageBits> previous_stages = {};
118
BitField<RDD::PipelineStageBits> next_stages = {};
119
BitField<RDD::PipelineStageBits> self_stages = {};
120
};
121
122
struct RecordedBufferCopy {
123
RDD::BufferID source;
124
RDD::BufferCopyRegion region;
125
};
126
127
struct RecordedBufferToTextureCopy {
128
RDD::BufferID from_buffer;
129
RDD::BufferTextureCopyRegion region;
130
};
131
132
enum ResourceUsage {
133
RESOURCE_USAGE_NONE,
134
RESOURCE_USAGE_COPY_FROM,
135
RESOURCE_USAGE_COPY_TO,
136
RESOURCE_USAGE_RESOLVE_FROM,
137
RESOURCE_USAGE_RESOLVE_TO,
138
RESOURCE_USAGE_UNIFORM_BUFFER_READ,
139
RESOURCE_USAGE_INDIRECT_BUFFER_READ,
140
RESOURCE_USAGE_TEXTURE_BUFFER_READ,
141
RESOURCE_USAGE_TEXTURE_BUFFER_READ_WRITE,
142
RESOURCE_USAGE_STORAGE_BUFFER_READ,
143
RESOURCE_USAGE_STORAGE_BUFFER_READ_WRITE,
144
RESOURCE_USAGE_VERTEX_BUFFER_READ,
145
RESOURCE_USAGE_INDEX_BUFFER_READ,
146
RESOURCE_USAGE_TEXTURE_SAMPLE,
147
RESOURCE_USAGE_STORAGE_IMAGE_READ,
148
RESOURCE_USAGE_STORAGE_IMAGE_READ_WRITE,
149
RESOURCE_USAGE_ATTACHMENT_COLOR_READ_WRITE,
150
RESOURCE_USAGE_ATTACHMENT_DEPTH_STENCIL_READ_WRITE,
151
RESOURCE_USAGE_ATTACHMENT_FRAGMENT_SHADING_RATE_READ,
152
RESOURCE_USAGE_ATTACHMENT_FRAGMENT_DENSITY_MAP_READ,
153
RESOURCE_USAGE_GENERAL,
154
RESOURCE_USAGE_MAX
155
};
156
157
struct ResourceTracker {
158
uint32_t reference_count = 0;
159
int64_t command_frame = -1;
160
BitField<RDD::PipelineStageBits> previous_frame_stages = {};
161
BitField<RDD::PipelineStageBits> current_frame_stages = {};
162
int32_t read_full_command_list_index = -1;
163
int32_t read_slice_command_list_index = -1;
164
int32_t write_command_or_list_index = -1;
165
int32_t draw_list_index = -1;
166
ResourceUsage draw_list_usage = RESOURCE_USAGE_NONE;
167
int32_t compute_list_index = -1;
168
ResourceUsage compute_list_usage = RESOURCE_USAGE_NONE;
169
ResourceUsage usage = RESOURCE_USAGE_NONE;
170
BitField<RDD::BarrierAccessBits> usage_access = {};
171
RDD::BufferID buffer_driver_id;
172
RDD::TextureID texture_driver_id;
173
RDD::TextureSubresourceRange texture_subresources;
174
Size2i texture_size;
175
uint32_t texture_usage = 0;
176
int32_t texture_slice_command_index = -1;
177
ResourceTracker *parent = nullptr;
178
ResourceTracker *dirty_shared_list = nullptr;
179
ResourceTracker *next_shared = nullptr;
180
Rect2i texture_slice_or_dirty_rect;
181
bool in_parent_dirty_list = false;
182
bool write_command_list_enabled = false;
183
bool is_discardable = false;
184
185
_FORCE_INLINE_ void reset_if_outdated(int64_t new_command_frame) {
186
if (new_command_frame != command_frame) {
187
command_frame = new_command_frame;
188
previous_frame_stages = current_frame_stages;
189
current_frame_stages.clear();
190
read_full_command_list_index = -1;
191
read_slice_command_list_index = -1;
192
write_command_or_list_index = -1;
193
draw_list_index = -1;
194
compute_list_index = -1;
195
texture_slice_command_index = -1;
196
write_command_list_enabled = false;
197
}
198
}
199
};
200
201
typedef RDD::RenderPassID (*RenderPassCreationFunction)(RenderingDeviceDriver *p_driver, VectorView<RDD::AttachmentLoadOp> p_load_ops, VectorView<RDD::AttachmentStoreOp> p_store_ops, void *p_user_data);
202
203
struct FramebufferStorage {
204
RDD::FramebufferID framebuffer;
205
RDD::RenderPassID render_pass;
206
};
207
208
struct FramebufferCache {
209
uint32_t width = 0;
210
uint32_t height = 0;
211
LocalVector<RDD::TextureID> textures;
212
LocalVector<ResourceTracker *> trackers;
213
HashMap<uint64_t, FramebufferStorage> storage_map;
214
void *render_pass_creation_user_data = nullptr;
215
};
216
217
struct CommandBufferPool {
218
// Provided by RenderingDevice.
219
RDD::CommandPoolID pool;
220
221
// Created internally by RenderingDeviceGraph.
222
LocalVector<RDD::CommandBufferID> buffers;
223
LocalVector<RDD::SemaphoreID> semaphores;
224
uint32_t buffers_used = 0;
225
};
226
227
struct WorkaroundsState {
228
bool draw_list_found = false;
229
};
230
231
enum AttachmentOperation {
232
// Loads or ignores if the attachment is discardable.
233
ATTACHMENT_OPERATION_DEFAULT,
234
// Clear the attachment to a value.
235
ATTACHMENT_OPERATION_CLEAR,
236
// Ignore any contents from the attachment.
237
ATTACHMENT_OPERATION_IGNORE,
238
};
239
240
private:
241
struct InstructionList {
242
LocalVector<uint8_t> data;
243
LocalVector<ResourceTracker *> command_trackers;
244
LocalVector<ResourceUsage> command_tracker_usages;
245
BitField<RDD::PipelineStageBits> stages = {};
246
int32_t index = 0;
247
248
void clear() {
249
data.clear();
250
command_trackers.clear();
251
command_tracker_usages.clear();
252
stages.clear();
253
}
254
};
255
256
struct ComputeInstructionList : InstructionList {
257
#if defined(DEBUG_ENABLED) || defined(DEV_ENABLED)
258
uint32_t breadcrumb;
259
#endif
260
};
261
262
struct DrawInstructionList : InstructionList {
263
FramebufferCache *framebuffer_cache = nullptr;
264
RDD::RenderPassID render_pass;
265
RDD::FramebufferID framebuffer;
266
Rect2i region;
267
LocalVector<AttachmentOperation> attachment_operations;
268
LocalVector<RDD::RenderPassClearValue> attachment_clear_values;
269
270
#if defined(DEBUG_ENABLED) || defined(DEV_ENABLED)
271
uint32_t breadcrumb;
272
#endif
273
bool split_cmd_buffer = false;
274
};
275
276
struct RecordedCommandSort {
277
uint32_t level = 0;
278
uint32_t priority = 0;
279
int32_t index = -1;
280
281
RecordedCommandSort() = default;
282
283
bool operator<(const RecordedCommandSort &p_other) const {
284
if (level < p_other.level) {
285
return true;
286
} else if (level > p_other.level) {
287
return false;
288
}
289
290
if (priority < p_other.priority) {
291
return true;
292
} else if (priority > p_other.priority) {
293
return false;
294
}
295
296
return index < p_other.index;
297
}
298
};
299
300
struct RecordedCommandListNode {
301
int32_t command_index = -1;
302
int32_t next_list_index = -1;
303
};
304
305
struct RecordedSliceListNode {
306
int32_t command_index = -1;
307
int32_t next_list_index = -1;
308
Rect2i subresources;
309
bool partial_coverage = false;
310
};
311
312
struct RecordedBufferClearCommand : RecordedCommand {
313
RDD::BufferID buffer;
314
uint32_t offset = 0;
315
uint32_t size = 0;
316
};
317
318
struct RecordedBufferCopyCommand : RecordedCommand {
319
RDD::BufferID source;
320
RDD::BufferID destination;
321
RDD::BufferCopyRegion region;
322
};
323
324
struct RecordedBufferGetDataCommand : RecordedCommand {
325
RDD::BufferID source;
326
RDD::BufferID destination;
327
RDD::BufferCopyRegion region;
328
};
329
330
struct RecordedBufferUpdateCommand : RecordedCommand {
331
RDD::BufferID destination;
332
uint32_t buffer_copies_count = 0;
333
334
_FORCE_INLINE_ RecordedBufferCopy *buffer_copies() {
335
return reinterpret_cast<RecordedBufferCopy *>(&this[1]);
336
}
337
338
_FORCE_INLINE_ const RecordedBufferCopy *buffer_copies() const {
339
return reinterpret_cast<const RecordedBufferCopy *>(&this[1]);
340
}
341
};
342
343
struct RecordedDriverCallbackCommand : RecordedCommand {
344
RDD::DriverCallback callback;
345
void *userdata = nullptr;
346
};
347
348
struct RecordedComputeListCommand : RecordedCommand {
349
uint32_t instruction_data_size = 0;
350
uint32_t breadcrumb = 0;
351
352
_FORCE_INLINE_ uint8_t *instruction_data() {
353
return reinterpret_cast<uint8_t *>(&this[1]);
354
}
355
356
_FORCE_INLINE_ const uint8_t *instruction_data() const {
357
return reinterpret_cast<const uint8_t *>(&this[1]);
358
}
359
};
360
361
struct RecordedDrawListCommand : RecordedCommand {
362
FramebufferCache *framebuffer_cache = nullptr;
363
RDD::FramebufferID framebuffer;
364
RDD::RenderPassID render_pass;
365
uint32_t instruction_data_size = 0;
366
RDD::CommandBufferType command_buffer_type;
367
Rect2i region;
368
uint32_t clear_values_count = 0;
369
uint32_t trackers_count = 0;
370
371
#if defined(DEBUG_ENABLED) || defined(DEV_ENABLED)
372
uint32_t breadcrumb = 0;
373
#endif
374
bool split_cmd_buffer = false;
375
376
_FORCE_INLINE_ RDD::RenderPassClearValue *clear_values() {
377
return reinterpret_cast<RDD::RenderPassClearValue *>(&this[1]);
378
}
379
380
_FORCE_INLINE_ const RDD::RenderPassClearValue *clear_values() const {
381
return reinterpret_cast<const RDD::RenderPassClearValue *>(&this[1]);
382
}
383
384
_FORCE_INLINE_ ResourceTracker **trackers() {
385
return reinterpret_cast<ResourceTracker **>(&clear_values()[clear_values_count]);
386
}
387
388
_FORCE_INLINE_ ResourceTracker *const *trackers() const {
389
return reinterpret_cast<ResourceTracker *const *>(&clear_values()[clear_values_count]);
390
}
391
392
_FORCE_INLINE_ RDD::AttachmentLoadOp *load_ops() {
393
return reinterpret_cast<RDD::AttachmentLoadOp *>(&trackers()[trackers_count]);
394
}
395
396
_FORCE_INLINE_ const RDD::AttachmentLoadOp *load_ops() const {
397
return reinterpret_cast<const RDD::AttachmentLoadOp *>(&trackers()[trackers_count]);
398
}
399
400
_FORCE_INLINE_ RDD::AttachmentStoreOp *store_ops() {
401
return reinterpret_cast<RDD::AttachmentStoreOp *>(&load_ops()[trackers_count]);
402
}
403
404
_FORCE_INLINE_ const RDD::AttachmentStoreOp *store_ops() const {
405
return reinterpret_cast<const RDD::AttachmentStoreOp *>(&load_ops()[trackers_count]);
406
}
407
408
_FORCE_INLINE_ uint8_t *instruction_data() {
409
return reinterpret_cast<uint8_t *>(&store_ops()[trackers_count]);
410
}
411
412
_FORCE_INLINE_ const uint8_t *instruction_data() const {
413
return reinterpret_cast<const uint8_t *>(&store_ops()[trackers_count]);
414
}
415
};
416
417
struct RecordedTextureClearCommand : RecordedCommand {
418
RDD::TextureID texture;
419
RDD::TextureSubresourceRange range;
420
Color color;
421
};
422
423
struct RecordedTextureCopyCommand : RecordedCommand {
424
RDD::TextureID from_texture;
425
RDD::TextureID to_texture;
426
uint32_t texture_copy_regions_count = 0;
427
428
_FORCE_INLINE_ RDD::TextureCopyRegion *texture_copy_regions() {
429
return reinterpret_cast<RDD::TextureCopyRegion *>(&this[1]);
430
}
431
432
_FORCE_INLINE_ const RDD::TextureCopyRegion *texture_copy_regions() const {
433
return reinterpret_cast<const RDD::TextureCopyRegion *>(&this[1]);
434
}
435
};
436
437
struct RecordedTextureGetDataCommand : RecordedCommand {
438
RDD::TextureID from_texture;
439
RDD::BufferID to_buffer;
440
uint32_t buffer_texture_copy_regions_count = 0;
441
442
_FORCE_INLINE_ RDD::BufferTextureCopyRegion *buffer_texture_copy_regions() {
443
return reinterpret_cast<RDD::BufferTextureCopyRegion *>(&this[1]);
444
}
445
446
_FORCE_INLINE_ const RDD::BufferTextureCopyRegion *buffer_texture_copy_regions() const {
447
return reinterpret_cast<const RDD::BufferTextureCopyRegion *>(&this[1]);
448
}
449
};
450
451
struct RecordedTextureResolveCommand : RecordedCommand {
452
RDD::TextureID from_texture;
453
RDD::TextureID to_texture;
454
uint32_t src_layer = 0;
455
uint32_t src_mipmap = 0;
456
uint32_t dst_layer = 0;
457
uint32_t dst_mipmap = 0;
458
};
459
460
struct RecordedTextureUpdateCommand : RecordedCommand {
461
RDD::TextureID to_texture;
462
uint32_t buffer_to_texture_copies_count = 0;
463
464
_FORCE_INLINE_ RecordedBufferToTextureCopy *buffer_to_texture_copies() {
465
return reinterpret_cast<RecordedBufferToTextureCopy *>(&this[1]);
466
}
467
468
_FORCE_INLINE_ const RecordedBufferToTextureCopy *buffer_to_texture_copies() const {
469
return reinterpret_cast<const RecordedBufferToTextureCopy *>(&this[1]);
470
}
471
};
472
473
struct RecordedCaptureTimestampCommand : RecordedCommand {
474
RDD::QueryPoolID pool;
475
uint32_t index = 0;
476
};
477
478
struct DrawListBindIndexBufferInstruction : DrawListInstruction {
479
RDD::BufferID buffer;
480
RenderingDeviceCommons::IndexBufferFormat format;
481
uint32_t offset = 0;
482
};
483
484
struct DrawListBindPipelineInstruction : DrawListInstruction {
485
RDD::PipelineID pipeline;
486
};
487
488
struct DrawListBindUniformSetsInstruction : DrawListInstruction {
489
RDD::ShaderID shader;
490
uint32_t first_set_index = 0;
491
uint32_t set_count = 0;
492
493
_FORCE_INLINE_ RDD::UniformSetID *uniform_set_ids() {
494
return reinterpret_cast<RDD::UniformSetID *>(&this[1]);
495
}
496
497
_FORCE_INLINE_ const RDD::UniformSetID *uniform_set_ids() const {
498
return reinterpret_cast<const RDD::UniformSetID *>(&this[1]);
499
}
500
};
501
502
struct DrawListBindVertexBuffersInstruction : DrawListInstruction {
503
uint32_t vertex_buffers_count = 0;
504
505
_FORCE_INLINE_ RDD::BufferID *vertex_buffers() {
506
return reinterpret_cast<RDD::BufferID *>(&this[1]);
507
}
508
509
_FORCE_INLINE_ const RDD::BufferID *vertex_buffers() const {
510
return reinterpret_cast<const RDD::BufferID *>(&this[1]);
511
}
512
513
_FORCE_INLINE_ uint64_t *vertex_buffer_offsets() {
514
return reinterpret_cast<uint64_t *>(&vertex_buffers()[vertex_buffers_count]);
515
}
516
517
_FORCE_INLINE_ const uint64_t *vertex_buffer_offsets() const {
518
return reinterpret_cast<const uint64_t *>(&vertex_buffers()[vertex_buffers_count]);
519
}
520
};
521
522
struct DrawListClearAttachmentsInstruction : DrawListInstruction {
523
uint32_t attachments_clear_count = 0;
524
uint32_t attachments_clear_rect_count = 0;
525
526
_FORCE_INLINE_ RDD::AttachmentClear *attachments_clear() {
527
return reinterpret_cast<RDD::AttachmentClear *>(&this[1]);
528
}
529
530
_FORCE_INLINE_ const RDD::AttachmentClear *attachments_clear() const {
531
return reinterpret_cast<const RDD::AttachmentClear *>(&this[1]);
532
}
533
534
_FORCE_INLINE_ Rect2i *attachments_clear_rect() {
535
return reinterpret_cast<Rect2i *>(&attachments_clear()[attachments_clear_count]);
536
}
537
538
_FORCE_INLINE_ const Rect2i *attachments_clear_rect() const {
539
return reinterpret_cast<const Rect2i *>(&attachments_clear()[attachments_clear_count]);
540
}
541
};
542
543
struct DrawListDrawInstruction : DrawListInstruction {
544
uint32_t vertex_count = 0;
545
uint32_t instance_count = 0;
546
};
547
548
struct DrawListDrawIndexedInstruction : DrawListInstruction {
549
uint32_t index_count = 0;
550
uint32_t instance_count = 0;
551
uint32_t first_index = 0;
552
};
553
554
struct DrawListDrawIndirectInstruction : DrawListInstruction {
555
RDD::BufferID buffer;
556
uint32_t offset = 0;
557
uint32_t draw_count = 0;
558
uint32_t stride = 0;
559
};
560
561
struct DrawListDrawIndexedIndirectInstruction : DrawListInstruction {
562
RDD::BufferID buffer;
563
uint32_t offset = 0;
564
uint32_t draw_count = 0;
565
uint32_t stride = 0;
566
};
567
568
struct DrawListEndRenderPassInstruction : DrawListInstruction {
569
// No contents.
570
};
571
572
struct DrawListExecuteCommandsInstruction : DrawListInstruction {
573
RDD::CommandBufferID command_buffer;
574
};
575
576
struct DrawListSetPushConstantInstruction : DrawListInstruction {
577
uint32_t size = 0;
578
RDD::ShaderID shader;
579
580
_FORCE_INLINE_ uint8_t *data() {
581
return reinterpret_cast<uint8_t *>(&this[1]);
582
}
583
584
_FORCE_INLINE_ const uint8_t *data() const {
585
return reinterpret_cast<const uint8_t *>(&this[1]);
586
}
587
};
588
589
struct DrawListNextSubpassInstruction : DrawListInstruction {
590
RDD::CommandBufferType command_buffer_type;
591
};
592
593
struct DrawListSetBlendConstantsInstruction : DrawListInstruction {
594
Color color;
595
};
596
597
struct DrawListSetLineWidthInstruction : DrawListInstruction {
598
float width;
599
};
600
601
struct DrawListSetScissorInstruction : DrawListInstruction {
602
Rect2i rect;
603
};
604
605
struct DrawListSetViewportInstruction : DrawListInstruction {
606
Rect2i rect;
607
};
608
609
struct DrawListUniformSetPrepareForUseInstruction : DrawListInstruction {
610
RDD::UniformSetID uniform_set;
611
RDD::ShaderID shader;
612
uint32_t set_index = 0;
613
};
614
615
struct ComputeListBindPipelineInstruction : ComputeListInstruction {
616
RDD::PipelineID pipeline;
617
};
618
619
struct ComputeListBindUniformSetsInstruction : ComputeListInstruction {
620
RDD::ShaderID shader;
621
uint32_t first_set_index = 0;
622
uint32_t set_count = 0;
623
624
_FORCE_INLINE_ RDD::UniformSetID *uniform_set_ids() {
625
return reinterpret_cast<RDD::UniformSetID *>(&this[1]);
626
}
627
628
_FORCE_INLINE_ const RDD::UniformSetID *uniform_set_ids() const {
629
return reinterpret_cast<const RDD::UniformSetID *>(&this[1]);
630
}
631
};
632
633
struct ComputeListDispatchInstruction : ComputeListInstruction {
634
uint32_t x_groups = 0;
635
uint32_t y_groups = 0;
636
uint32_t z_groups = 0;
637
};
638
639
struct ComputeListDispatchIndirectInstruction : ComputeListInstruction {
640
RDD::BufferID buffer;
641
uint32_t offset = 0;
642
};
643
644
struct ComputeListSetPushConstantInstruction : ComputeListInstruction {
645
uint32_t size = 0;
646
RDD::ShaderID shader;
647
648
_FORCE_INLINE_ uint8_t *data() {
649
return reinterpret_cast<uint8_t *>(&this[1]);
650
}
651
652
_FORCE_INLINE_ const uint8_t *data() const {
653
return reinterpret_cast<const uint8_t *>(&this[1]);
654
}
655
};
656
657
struct ComputeListUniformSetPrepareForUseInstruction : ComputeListInstruction {
658
RDD::UniformSetID uniform_set;
659
RDD::ShaderID shader;
660
uint32_t set_index = 0;
661
};
662
663
struct BarrierGroup {
664
BitField<RDD::PipelineStageBits> src_stages = {};
665
BitField<RDD::PipelineStageBits> dst_stages = {};
666
RDD::MemoryBarrier memory_barrier;
667
LocalVector<RDD::TextureBarrier> normalization_barriers;
668
LocalVector<RDD::TextureBarrier> transition_barriers;
669
#if USE_BUFFER_BARRIERS
670
LocalVector<RDD::BufferBarrier> buffer_barriers;
671
#endif
672
673
void clear() {
674
src_stages.clear();
675
dst_stages.clear();
676
memory_barrier.src_access.clear();
677
memory_barrier.dst_access.clear();
678
normalization_barriers.clear();
679
transition_barriers.clear();
680
#if USE_BUFFER_BARRIERS
681
buffer_barriers.clear();
682
#endif
683
}
684
};
685
686
struct SecondaryCommandBuffer {
687
LocalVector<uint8_t> instruction_data;
688
RDD::CommandBufferID command_buffer;
689
RDD::CommandPoolID command_pool;
690
RDD::RenderPassID render_pass;
691
RDD::FramebufferID framebuffer;
692
WorkerThreadPool::TaskID task;
693
};
694
695
struct Frame {
696
TightLocalVector<SecondaryCommandBuffer> secondary_command_buffers;
697
uint32_t secondary_command_buffers_used = 0;
698
};
699
700
RDD *driver = nullptr;
701
RenderingContextDriver::Device device;
702
RenderPassCreationFunction render_pass_creation_function = nullptr;
703
int64_t tracking_frame = 0;
704
LocalVector<uint8_t> command_data;
705
LocalVector<uint32_t> command_data_offsets;
706
LocalVector<RDD::TextureBarrier> command_normalization_barriers;
707
LocalVector<RDD::TextureBarrier> command_transition_barriers;
708
LocalVector<RDD::BufferBarrier> command_buffer_barriers;
709
LocalVector<char> command_label_chars;
710
LocalVector<Color> command_label_colors;
711
LocalVector<uint32_t> command_label_offsets;
712
int32_t command_label_index = -1;
713
DrawInstructionList draw_instruction_list;
714
ComputeInstructionList compute_instruction_list;
715
uint32_t command_count = 0;
716
uint32_t command_label_count = 0;
717
LocalVector<RecordedCommandListNode> command_list_nodes;
718
LocalVector<RecordedSliceListNode> read_slice_list_nodes;
719
LocalVector<RecordedSliceListNode> write_slice_list_nodes;
720
int32_t command_timestamp_index = -1;
721
int32_t command_synchronization_index = -1;
722
bool command_synchronization_pending = false;
723
BarrierGroup barrier_group;
724
bool driver_honors_barriers : 1;
725
bool driver_clears_with_copy_engine : 1;
726
bool driver_buffers_require_transitions : 1;
727
WorkaroundsState workarounds_state;
728
TightLocalVector<Frame> frames;
729
uint32_t frame = 0;
730
731
#ifdef DEV_ENABLED
732
RBMap<ResourceTracker *, uint32_t> write_dependency_counters;
733
#endif
734
735
static String _usage_to_string(ResourceUsage p_usage);
736
static bool _is_write_usage(ResourceUsage p_usage);
737
static RDD::TextureLayout _usage_to_image_layout(ResourceUsage p_usage);
738
static RDD::BarrierAccessBits _usage_to_access_bits(ResourceUsage p_usage);
739
bool _check_command_intersection(ResourceTracker *p_resource_tracker, int32_t p_previous_command_index, int32_t p_command_index) const;
740
bool _check_command_partial_coverage(ResourceTracker *p_resource_tracker, int32_t p_command_index) const;
741
int32_t _add_to_command_list(int32_t p_command_index, int32_t p_list_index);
742
void _add_adjacent_command(int32_t p_previous_command_index, int32_t p_command_index, RecordedCommand *r_command);
743
int32_t _add_to_slice_read_list(int32_t p_command_index, Rect2i p_subresources, int32_t p_list_index);
744
int32_t _add_to_write_list(int32_t p_command_index, Rect2i p_subresources, int32_t p_list_index, bool p_partial_coverage);
745
RecordedCommand *_allocate_command(uint32_t p_command_size, int32_t &r_command_index);
746
DrawListInstruction *_allocate_draw_list_instruction(uint32_t p_instruction_size);
747
ComputeListInstruction *_allocate_compute_list_instruction(uint32_t p_instruction_size);
748
void _check_discardable_attachment_dependency(ResourceTracker *p_resource_tracker, int32_t p_previous_command_index, int32_t p_command_index);
749
void _add_command_to_graph(ResourceTracker **p_resource_trackers, ResourceUsage *p_resource_usages, uint32_t p_resource_count, int32_t p_command_index, RecordedCommand *r_command);
750
void _add_texture_barrier_to_command(RDD::TextureID p_texture_id, BitField<RDD::BarrierAccessBits> p_src_access, BitField<RDD::BarrierAccessBits> p_dst_access, ResourceUsage p_prev_usage, ResourceUsage p_next_usage, RDD::TextureSubresourceRange p_subresources, LocalVector<RDD::TextureBarrier> &r_barrier_vector, int32_t &r_barrier_index, int32_t &r_barrier_count);
751
#if USE_BUFFER_BARRIERS
752
void _add_buffer_barrier_to_command(RDD::BufferID p_buffer_id, BitField<RDD::BarrierAccessBits> p_src_access, BitField<RDD::BarrierAccessBits> p_dst_access, int32_t &r_barrier_index, int32_t &r_barrier_count);
753
#endif
754
void _run_compute_list_command(RDD::CommandBufferID p_command_buffer, const uint8_t *p_instruction_data, uint32_t p_instruction_data_size);
755
void _get_draw_list_render_pass_and_framebuffer(const RecordedDrawListCommand *p_draw_list_command, RDD::RenderPassID &r_render_pass, RDD::FramebufferID &r_framebuffer);
756
void _run_draw_list_command(RDD::CommandBufferID p_command_buffer, const uint8_t *p_instruction_data, uint32_t p_instruction_data_size);
757
void _add_draw_list_begin(FramebufferCache *p_framebuffer_cache, RDD::RenderPassID p_render_pass, RDD::FramebufferID p_framebuffer, Rect2i p_region, VectorView<AttachmentOperation> p_attachment_operations, VectorView<RDD::RenderPassClearValue> p_attachment_clear_values, BitField<RDD::PipelineStageBits> p_stages, uint32_t p_breadcrumb, bool p_split_cmd_buffer);
758
void _run_secondary_command_buffer_task(const SecondaryCommandBuffer *p_secondary);
759
void _wait_for_secondary_command_buffer_tasks();
760
void _run_render_commands(int32_t p_level, const RecordedCommandSort *p_sorted_commands, uint32_t p_sorted_commands_count, RDD::CommandBufferID &r_command_buffer, CommandBufferPool &r_command_buffer_pool, int32_t &r_current_label_index, int32_t &r_current_label_level);
761
void _run_label_command_change(RDD::CommandBufferID p_command_buffer, int32_t p_new_label_index, int32_t p_new_level, bool p_ignore_previous_value, bool p_use_label_for_empty, const RecordedCommandSort *p_sorted_commands, uint32_t p_sorted_commands_count, int32_t &r_current_label_index, int32_t &r_current_label_level);
762
void _boost_priority_for_render_commands(RecordedCommandSort *p_sorted_commands, uint32_t p_sorted_commands_count, uint32_t &r_boosted_priority);
763
void _group_barriers_for_render_commands(RDD::CommandBufferID p_command_buffer, const RecordedCommandSort *p_sorted_commands, uint32_t p_sorted_commands_count, bool p_full_memory_barrier);
764
void _print_render_commands(const RecordedCommandSort *p_sorted_commands, uint32_t p_sorted_commands_count);
765
void _print_draw_list(const uint8_t *p_instruction_data, uint32_t p_instruction_data_size);
766
void _print_compute_list(const uint8_t *p_instruction_data, uint32_t p_instruction_data_size);
767
768
public:
769
RenderingDeviceGraph();
770
~RenderingDeviceGraph();
771
void initialize(RDD *p_driver, RenderingContextDriver::Device p_device, RenderPassCreationFunction p_render_pass_creation_function, uint32_t p_frame_count, RDD::CommandQueueFamilyID p_secondary_command_queue_family, uint32_t p_secondary_command_buffers_per_frame);
772
void finalize();
773
void begin();
774
void add_buffer_clear(RDD::BufferID p_dst, ResourceTracker *p_dst_tracker, uint32_t p_offset, uint32_t p_size);
775
void add_buffer_copy(RDD::BufferID p_src, ResourceTracker *p_src_tracker, RDD::BufferID p_dst, ResourceTracker *p_dst_tracker, RDD::BufferCopyRegion p_region);
776
void add_buffer_get_data(RDD::BufferID p_src, ResourceTracker *p_src_tracker, RDD::BufferID p_dst, RDD::BufferCopyRegion p_region);
777
void add_buffer_update(RDD::BufferID p_dst, ResourceTracker *p_dst_tracker, VectorView<RecordedBufferCopy> p_buffer_copies);
778
void add_driver_callback(RDD::DriverCallback p_callback, void *p_userdata, VectorView<ResourceTracker *> p_trackers, VectorView<ResourceUsage> p_usages);
779
void add_compute_list_begin(RDD::BreadcrumbMarker p_phase = RDD::BreadcrumbMarker::NONE, uint32_t p_breadcrumb_data = 0);
780
void add_compute_list_bind_pipeline(RDD::PipelineID p_pipeline);
781
void add_compute_list_bind_uniform_set(RDD::ShaderID p_shader, RDD::UniformSetID p_uniform_set, uint32_t set_index);
782
void add_compute_list_bind_uniform_sets(RDD::ShaderID p_shader, VectorView<RDD::UniformSetID> p_uniform_set, uint32_t p_first_set_index, uint32_t p_set_count);
783
void add_compute_list_dispatch(uint32_t p_x_groups, uint32_t p_y_groups, uint32_t p_z_groups);
784
void add_compute_list_dispatch_indirect(RDD::BufferID p_buffer, uint32_t p_offset);
785
void add_compute_list_set_push_constant(RDD::ShaderID p_shader, const void *p_data, uint32_t p_data_size);
786
void add_compute_list_uniform_set_prepare_for_use(RDD::ShaderID p_shader, RDD::UniformSetID p_uniform_set, uint32_t set_index);
787
void add_compute_list_usage(ResourceTracker *p_tracker, ResourceUsage p_usage);
788
void add_compute_list_usages(VectorView<ResourceTracker *> p_trackers, VectorView<ResourceUsage> p_usages);
789
void add_compute_list_end();
790
void add_draw_list_begin(FramebufferCache *p_framebuffer_cache, Rect2i p_region, VectorView<AttachmentOperation> p_attachment_operations, VectorView<RDD::RenderPassClearValue> p_attachment_clear_values, BitField<RDD::PipelineStageBits> p_stages, uint32_t p_breadcrumb = 0, bool p_split_cmd_buffer = false);
791
void add_draw_list_begin(RDD::RenderPassID p_render_pass, RDD::FramebufferID p_framebuffer, Rect2i p_region, VectorView<AttachmentOperation> p_attachment_operations, VectorView<RDD::RenderPassClearValue> p_attachment_clear_values, BitField<RDD::PipelineStageBits> p_stages, uint32_t p_breadcrumb = 0, bool p_split_cmd_buffer = false);
792
void add_draw_list_bind_index_buffer(RDD::BufferID p_buffer, RDD::IndexBufferFormat p_format, uint32_t p_offset);
793
void add_draw_list_bind_pipeline(RDD::PipelineID p_pipeline, BitField<RDD::PipelineStageBits> p_pipeline_stage_bits);
794
void add_draw_list_bind_uniform_set(RDD::ShaderID p_shader, RDD::UniformSetID p_uniform_set, uint32_t set_index);
795
void add_draw_list_bind_uniform_sets(RDD::ShaderID p_shader, VectorView<RDD::UniformSetID> p_uniform_set, uint32_t p_first_index, uint32_t p_set_count);
796
void add_draw_list_bind_vertex_buffers(VectorView<RDD::BufferID> p_vertex_buffers, VectorView<uint64_t> p_vertex_buffer_offsets);
797
void add_draw_list_clear_attachments(VectorView<RDD::AttachmentClear> p_attachments_clear, VectorView<Rect2i> p_attachments_clear_rect);
798
void add_draw_list_draw(uint32_t p_vertex_count, uint32_t p_instance_count);
799
void add_draw_list_draw_indexed(uint32_t p_index_count, uint32_t p_instance_count, uint32_t p_first_index);
800
void add_draw_list_draw_indirect(RDD::BufferID p_buffer, uint32_t p_offset, uint32_t p_draw_count, uint32_t p_stride);
801
void add_draw_list_draw_indexed_indirect(RDD::BufferID p_buffer, uint32_t p_offset, uint32_t p_draw_count, uint32_t p_stride);
802
void add_draw_list_execute_commands(RDD::CommandBufferID p_command_buffer);
803
void add_draw_list_next_subpass(RDD::CommandBufferType p_command_buffer_type);
804
void add_draw_list_set_blend_constants(const Color &p_color);
805
void add_draw_list_set_line_width(float p_width);
806
void add_draw_list_set_push_constant(RDD::ShaderID p_shader, const void *p_data, uint32_t p_data_size);
807
void add_draw_list_set_scissor(Rect2i p_rect);
808
void add_draw_list_set_viewport(Rect2i p_rect);
809
void add_draw_list_uniform_set_prepare_for_use(RDD::ShaderID p_shader, RDD::UniformSetID p_uniform_set, uint32_t set_index);
810
void add_draw_list_usage(ResourceTracker *p_tracker, ResourceUsage p_usage);
811
void add_draw_list_usages(VectorView<ResourceTracker *> p_trackers, VectorView<ResourceUsage> p_usages);
812
void add_draw_list_end();
813
void add_texture_clear(RDD::TextureID p_dst, ResourceTracker *p_dst_tracker, const Color &p_color, const RDD::TextureSubresourceRange &p_range);
814
void add_texture_copy(RDD::TextureID p_src, ResourceTracker *p_src_tracker, RDD::TextureID p_dst, ResourceTracker *p_dst_tracker, VectorView<RDD::TextureCopyRegion> p_texture_copy_regions);
815
void add_texture_get_data(RDD::TextureID p_src, ResourceTracker *p_src_tracker, RDD::BufferID p_dst, VectorView<RDD::BufferTextureCopyRegion> p_buffer_texture_copy_regions, ResourceTracker *p_dst_tracker = nullptr);
816
void add_texture_resolve(RDD::TextureID p_src, ResourceTracker *p_src_tracker, RDD::TextureID p_dst, ResourceTracker *p_dst_tracker, uint32_t p_src_layer, uint32_t p_src_mipmap, uint32_t p_dst_layer, uint32_t p_dst_mipmap);
817
void add_texture_update(RDD::TextureID p_dst, ResourceTracker *p_dst_tracker, VectorView<RecordedBufferToTextureCopy> p_buffer_copies, VectorView<ResourceTracker *> p_buffer_trackers = VectorView<ResourceTracker *>());
818
void add_capture_timestamp(RDD::QueryPoolID p_query_pool, uint32_t p_index);
819
void add_synchronization();
820
void begin_label(const Span<char> &p_label_name, const Color &p_color);
821
void end_label();
822
void end(bool p_reorder_commands, bool p_full_barriers, RDD::CommandBufferID &r_command_buffer, CommandBufferPool &r_command_buffer_pool);
823
static ResourceTracker *resource_tracker_create();
824
static void resource_tracker_free(ResourceTracker *p_tracker);
825
static FramebufferCache *framebuffer_cache_create();
826
static void framebuffer_cache_free(RDD *p_driver, FramebufferCache *p_cache);
827
};
828
829
using RDG = RenderingDeviceGraph;
830
831