Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/rendering/rendering_device_driver.h
20951 views
1
/**************************************************************************/
2
/* rendering_device_driver.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
// ***********************************************************************************
34
// RenderingDeviceDriver - Design principles
35
// -----------------------------------------
36
// - Very little validation is done, and normally only in dev or debug builds.
37
// - Error reporting is generally simple: returning an id of 0 or a false boolean.
38
// - Certain enums/constants/structs follow Vulkan values/layout. That makes things easier for RDDVulkan (it asserts compatibility).
39
// - We allocate as little as possible in functions expected to be quick (a counterexample is loading/saving shaders) and use alloca() whenever suitable.
40
// - We try to back opaque ids with the native ones or memory addresses.
41
// - When using bookkeeping structures because the actual API id of a resource is not enough, we use a PagedAllocator.
42
// - Every struct has default initializers.
43
// - Using VectorView to take array-like arguments. Vector<uint8_t> is an exception (an indiom for "BLOB").
44
// - If a driver needs some higher-level information (the kind of info RenderingDevice keeps), it shall store a copy of what it needs.
45
// There's no backwards communication from the driver to query data from RenderingDevice.
46
// ***********************************************************************************
47
48
#include "core/object/object.h"
49
#include "core/variant/type_info.h"
50
#include "servers/rendering/rendering_context_driver.h"
51
#include "servers/rendering/rendering_device_commons.h"
52
53
class RenderingShaderContainer;
54
class RenderingShaderContainerFormat;
55
56
// These utilities help drivers avoid allocations.
57
#define ALLOCA(m_size) ((m_size != 0) ? alloca(m_size) : nullptr)
58
#define ALLOCA_ARRAY(m_type, m_count) ((m_type *)ALLOCA(sizeof(m_type) * (m_count)))
59
#define ALLOCA_SINGLE(m_type) ALLOCA_ARRAY(m_type, 1)
60
61
// This helps forwarding certain arrays to the API with confidence.
62
#define ARRAYS_COMPATIBLE(m_type_a, m_type_b) (sizeof(m_type_a) == sizeof(m_type_b) && alignof(m_type_a) == alignof(m_type_b))
63
// This is used when you also need to ensure structured types are compatible field-by-field.
64
// TODO: The fieldwise check is unimplemented, but still this one is useful, as a strong annotation about the needs.
65
#define ARRAYS_COMPATIBLE_FIELDWISE(m_type_a, m_type_b) ARRAYS_COMPATIBLE(m_type_a, m_type_b)
66
// Another utility, to make it easy to compare members of different enums, which is not fine with some compilers.
67
#define ENUM_MEMBERS_EQUAL(m_a, m_b) ((int64_t)m_a == (int64_t)m_b)
68
69
// This helps using a single paged allocator for many resource types.
70
template <typename... RESOURCE_TYPES>
71
struct VersatileResourceTemplate {
72
static constexpr size_t RESOURCE_SIZES[] = { sizeof(RESOURCE_TYPES)... };
73
static constexpr size_t MAX_RESOURCE_SIZE = Span(RESOURCE_SIZES).max();
74
uint8_t data[MAX_RESOURCE_SIZE];
75
76
template <typename T>
77
static T *allocate(PagedAllocator<VersatileResourceTemplate, true> &p_allocator) {
78
T *obj = (T *)p_allocator.alloc();
79
memnew_placement(obj, T);
80
return obj;
81
}
82
83
template <typename T>
84
static void free(PagedAllocator<VersatileResourceTemplate, true> &p_allocator, T *p_object) {
85
p_object->~T();
86
p_allocator.free((VersatileResourceTemplate *)p_object);
87
}
88
};
89
90
class RenderingDeviceDriver : public RenderingDeviceCommons {
91
GDSOFTCLASS(RenderingDeviceDriver, RenderingDeviceCommons);
92
93
public:
94
struct ID {
95
uint64_t id = 0;
96
_ALWAYS_INLINE_ ID() = default;
97
_ALWAYS_INLINE_ ID(uint64_t p_id) :
98
id(p_id) {}
99
};
100
101
#define DEFINE_ID(m_name) \
102
struct m_name##ID : public ID { \
103
_ALWAYS_INLINE_ explicit operator bool() const { \
104
return id != 0; \
105
} \
106
_ALWAYS_INLINE_ m_name##ID &operator=(m_name##ID p_other) { \
107
id = p_other.id; \
108
return *this; \
109
} \
110
_ALWAYS_INLINE_ bool operator<(const m_name##ID &p_other) const { \
111
return id < p_other.id; \
112
} \
113
_ALWAYS_INLINE_ bool operator==(const m_name##ID &p_other) const { \
114
return id == p_other.id; \
115
} \
116
_ALWAYS_INLINE_ bool operator!=(const m_name##ID &p_other) const { \
117
return id != p_other.id; \
118
} \
119
_ALWAYS_INLINE_ m_name##ID(const m_name##ID &p_other) : ID(p_other.id) {} \
120
_ALWAYS_INLINE_ explicit m_name##ID(uint64_t p_int) : ID(p_int) {} \
121
_ALWAYS_INLINE_ explicit m_name##ID(void *p_ptr) : ID((uint64_t)p_ptr) {} \
122
_ALWAYS_INLINE_ m_name##ID() = default; \
123
};
124
125
// Id types declared before anything else to prevent cyclic dependencies between the different concerns.
126
DEFINE_ID(Buffer);
127
DEFINE_ID(Texture);
128
DEFINE_ID(Sampler);
129
DEFINE_ID(VertexFormat);
130
DEFINE_ID(CommandQueue);
131
DEFINE_ID(CommandQueueFamily);
132
DEFINE_ID(CommandPool);
133
DEFINE_ID(CommandBuffer);
134
DEFINE_ID(SwapChain);
135
DEFINE_ID(Framebuffer);
136
DEFINE_ID(Shader);
137
DEFINE_ID(UniformSet);
138
DEFINE_ID(Pipeline);
139
DEFINE_ID(RenderPass);
140
DEFINE_ID(QueryPool);
141
DEFINE_ID(Fence);
142
DEFINE_ID(Semaphore);
143
DEFINE_ID(AccelerationStructure);
144
DEFINE_ID(RaytracingPipeline);
145
146
public:
147
/*****************/
148
/**** GENERIC ****/
149
/*****************/
150
151
virtual Error initialize(uint32_t p_device_index, uint32_t p_frame_count) = 0;
152
153
/****************/
154
/**** MEMORY ****/
155
/****************/
156
157
enum MemoryAllocationType {
158
MEMORY_ALLOCATION_TYPE_CPU, // For images, CPU allocation also means linear, GPU is tiling optimal.
159
MEMORY_ALLOCATION_TYPE_GPU,
160
};
161
162
/*****************/
163
/**** BUFFERS ****/
164
/*****************/
165
166
enum BufferUsageBits {
167
BUFFER_USAGE_TRANSFER_FROM_BIT = (1 << 0),
168
BUFFER_USAGE_TRANSFER_TO_BIT = (1 << 1),
169
BUFFER_USAGE_TEXEL_BIT = (1 << 2),
170
BUFFER_USAGE_UNIFORM_BIT = (1 << 4),
171
BUFFER_USAGE_STORAGE_BIT = (1 << 5),
172
BUFFER_USAGE_INDEX_BIT = (1 << 6),
173
BUFFER_USAGE_VERTEX_BIT = (1 << 7),
174
BUFFER_USAGE_INDIRECT_BIT = (1 << 8),
175
BUFFER_USAGE_SHADER_BINDING_TABLE_BIT = (1 << 10),
176
BUFFER_USAGE_DEVICE_ADDRESS_BIT = (1 << 17),
177
BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT = (1 << 19),
178
BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT = (1 << 20),
179
// There are no Vulkan-equivalent. Try to use unused/unclaimed bits.
180
BUFFER_USAGE_DYNAMIC_PERSISTENT_BIT = (1 << 31),
181
};
182
183
enum {
184
BUFFER_WHOLE_SIZE = ~0ULL
185
};
186
187
/** Allocates a new GPU buffer. Must be destroyed with buffer_free().
188
* @param p_size The size in bytes of the buffer.
189
* @param p_usage Usage flags.
190
* @param p_allocation_type See MemoryAllocationType.
191
* @param p_frames_drawn Used for debug checks when BUFFER_USAGE_DYNAMIC_PERSISTENT_BIT is set.
192
* @return the buffer.
193
*/
194
virtual BufferID buffer_create(uint64_t p_size, BitField<BufferUsageBits> p_usage, MemoryAllocationType p_allocation_type, uint64_t p_frames_drawn) = 0;
195
// Only for a buffer with BUFFER_USAGE_TEXEL_BIT.
196
virtual bool buffer_set_texel_format(BufferID p_buffer, DataFormat p_format) = 0;
197
virtual void buffer_free(BufferID p_buffer) = 0;
198
virtual uint64_t buffer_get_allocation_size(BufferID p_buffer) = 0;
199
virtual uint8_t *buffer_map(BufferID p_buffer) = 0;
200
virtual void buffer_unmap(BufferID p_buffer) = 0;
201
virtual uint8_t *buffer_persistent_map_advance(BufferID p_buffer, uint64_t p_frames_drawn) = 0;
202
virtual uint64_t buffer_get_dynamic_offsets(Span<BufferID> p_buffers) = 0;
203
virtual void buffer_flush(BufferID p_buffer) {}
204
// Only for a buffer with BUFFER_USAGE_DEVICE_ADDRESS_BIT.
205
virtual uint64_t buffer_get_device_address(BufferID p_buffer) = 0;
206
207
/*****************/
208
/**** TEXTURE ****/
209
/*****************/
210
211
struct TextureView {
212
DataFormat format = DATA_FORMAT_MAX;
213
TextureSwizzle swizzle_r = TEXTURE_SWIZZLE_R;
214
TextureSwizzle swizzle_g = TEXTURE_SWIZZLE_G;
215
TextureSwizzle swizzle_b = TEXTURE_SWIZZLE_B;
216
TextureSwizzle swizzle_a = TEXTURE_SWIZZLE_A;
217
};
218
219
enum TextureLayout {
220
TEXTURE_LAYOUT_UNDEFINED,
221
TEXTURE_LAYOUT_GENERAL,
222
TEXTURE_LAYOUT_STORAGE_OPTIMAL,
223
TEXTURE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
224
TEXTURE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
225
TEXTURE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,
226
TEXTURE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
227
TEXTURE_LAYOUT_COPY_SRC_OPTIMAL,
228
TEXTURE_LAYOUT_COPY_DST_OPTIMAL,
229
TEXTURE_LAYOUT_RESOLVE_SRC_OPTIMAL,
230
TEXTURE_LAYOUT_RESOLVE_DST_OPTIMAL,
231
TEXTURE_LAYOUT_FRAGMENT_SHADING_RATE_ATTACHMENT_OPTIMAL,
232
TEXTURE_LAYOUT_FRAGMENT_DENSITY_MAP_ATTACHMENT_OPTIMAL,
233
TEXTURE_LAYOUT_MAX
234
};
235
236
enum TextureAspect {
237
TEXTURE_ASPECT_COLOR = 0,
238
TEXTURE_ASPECT_DEPTH = 1,
239
TEXTURE_ASPECT_STENCIL = 2,
240
TEXTURE_ASPECT_MAX
241
};
242
243
enum TextureUsageMethod {
244
TEXTURE_USAGE_VRS_FRAGMENT_SHADING_RATE_BIT = TEXTURE_USAGE_MAX_BIT << 1,
245
TEXTURE_USAGE_VRS_FRAGMENT_DENSITY_MAP_BIT = TEXTURE_USAGE_MAX_BIT << 2,
246
};
247
248
enum TextureAspectBits {
249
TEXTURE_ASPECT_COLOR_BIT = (1 << TEXTURE_ASPECT_COLOR),
250
TEXTURE_ASPECT_DEPTH_BIT = (1 << TEXTURE_ASPECT_DEPTH),
251
TEXTURE_ASPECT_STENCIL_BIT = (1 << TEXTURE_ASPECT_STENCIL),
252
};
253
254
struct TextureSubresource {
255
TextureAspect aspect = TEXTURE_ASPECT_COLOR;
256
uint32_t layer = 0;
257
uint32_t mipmap = 0;
258
};
259
260
struct TextureSubresourceLayers {
261
BitField<TextureAspectBits> aspect = {};
262
uint32_t mipmap = 0;
263
uint32_t base_layer = 0;
264
uint32_t layer_count = 0;
265
};
266
267
struct TextureSubresourceRange {
268
BitField<TextureAspectBits> aspect = {};
269
uint32_t base_mipmap = 0;
270
uint32_t mipmap_count = 0;
271
uint32_t base_layer = 0;
272
uint32_t layer_count = 0;
273
};
274
275
struct TextureCopyableLayout {
276
uint64_t size = 0;
277
uint64_t row_pitch = 0;
278
};
279
280
virtual TextureID texture_create(const TextureFormat &p_format, const TextureView &p_view) = 0;
281
virtual TextureID texture_create_from_extension(uint64_t p_native_texture, TextureType p_type, DataFormat p_format, uint32_t p_array_layers, bool p_depth_stencil, uint32_t p_mipmaps) = 0;
282
// texture_create_shared_*() can only use original, non-view textures as original. RenderingDevice is responsible for ensuring that.
283
virtual TextureID texture_create_shared(TextureID p_original_texture, const TextureView &p_view) = 0;
284
virtual TextureID texture_create_shared_from_slice(TextureID p_original_texture, const TextureView &p_view, TextureSliceType p_slice_type, uint32_t p_layer, uint32_t p_layers, uint32_t p_mipmap, uint32_t p_mipmaps) = 0;
285
virtual void texture_free(TextureID p_texture) = 0;
286
virtual uint64_t texture_get_allocation_size(TextureID p_texture) = 0;
287
// Returns a texture layout for buffer <-> texture copies. If you are copying multiple texture subresources to/from the same buffer,
288
// you are responsible for correctly aligning the start offset for every buffer region. See API_TRAIT_TEXTURE_TRANSFER_ALIGNMENT.
289
virtual void texture_get_copyable_layout(TextureID p_texture, const TextureSubresource &p_subresource, TextureCopyableLayout *r_layout) = 0;
290
// Returns the data of a texture layer for a CPU texture that was created with TEXTURE_USAGE_CPU_READ_BIT.
291
virtual Vector<uint8_t> texture_get_data(TextureID p_texture, uint32_t p_layer) = 0;
292
virtual BitField<TextureUsageBits> texture_get_usages_supported_by_format(DataFormat p_format, bool p_cpu_readable) = 0;
293
virtual bool texture_can_make_shared_with_format(TextureID p_texture, DataFormat p_format, bool &r_raw_reinterpretation) = 0;
294
295
/*****************/
296
/**** SAMPLER ****/
297
/*****************/
298
299
virtual SamplerID sampler_create(const SamplerState &p_state) = 0;
300
virtual void sampler_free(SamplerID p_sampler) = 0;
301
virtual bool sampler_is_format_supported_for_filter(DataFormat p_format, SamplerFilter p_filter) = 0;
302
303
/**********************/
304
/**** VERTEX ARRAY ****/
305
/**********************/
306
307
virtual VertexFormatID vertex_format_create(Span<VertexAttribute> p_vertex_attribs, const VertexAttributeBindingsMap &p_vertex_bindings) = 0;
308
virtual void vertex_format_free(VertexFormatID p_vertex_format) = 0;
309
310
/******************/
311
/**** BARRIERS ****/
312
/******************/
313
314
enum PipelineStageBits {
315
PIPELINE_STAGE_TOP_OF_PIPE_BIT = (1 << 0),
316
PIPELINE_STAGE_DRAW_INDIRECT_BIT = (1 << 1),
317
PIPELINE_STAGE_VERTEX_INPUT_BIT = (1 << 2),
318
PIPELINE_STAGE_VERTEX_SHADER_BIT = (1 << 3),
319
PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT = (1 << 4),
320
PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT = (1 << 5),
321
PIPELINE_STAGE_GEOMETRY_SHADER_BIT = (1 << 6),
322
PIPELINE_STAGE_FRAGMENT_SHADER_BIT = (1 << 7),
323
PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT = (1 << 8),
324
PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT = (1 << 9),
325
PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT = (1 << 10),
326
PIPELINE_STAGE_COMPUTE_SHADER_BIT = (1 << 11),
327
PIPELINE_STAGE_COPY_BIT = (1 << 12),
328
PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT = (1 << 13),
329
PIPELINE_STAGE_RESOLVE_BIT = (1 << 14),
330
PIPELINE_STAGE_ALL_GRAPHICS_BIT = (1 << 15),
331
PIPELINE_STAGE_ALL_COMMANDS_BIT = (1 << 16),
332
PIPELINE_STAGE_CLEAR_STORAGE_BIT = (1 << 17),
333
PIPELINE_STAGE_RAY_TRACING_SHADER_BIT = (1 << 21),
334
PIPELINE_STAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT = (1 << 22),
335
PIPELINE_STAGE_FRAGMENT_DENSITY_PROCESS_BIT = (1 << 23),
336
PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT = (1 << 25),
337
};
338
339
enum BarrierAccessBits {
340
BARRIER_ACCESS_INDIRECT_COMMAND_READ_BIT = (1 << 0),
341
BARRIER_ACCESS_INDEX_READ_BIT = (1 << 1),
342
BARRIER_ACCESS_VERTEX_ATTRIBUTE_READ_BIT = (1 << 2),
343
BARRIER_ACCESS_UNIFORM_READ_BIT = (1 << 3),
344
BARRIER_ACCESS_INPUT_ATTACHMENT_READ_BIT = (1 << 4),
345
BARRIER_ACCESS_SHADER_READ_BIT = (1 << 5),
346
BARRIER_ACCESS_SHADER_WRITE_BIT = (1 << 6),
347
BARRIER_ACCESS_COLOR_ATTACHMENT_READ_BIT = (1 << 7),
348
BARRIER_ACCESS_COLOR_ATTACHMENT_WRITE_BIT = (1 << 8),
349
BARRIER_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT = (1 << 9),
350
BARRIER_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT = (1 << 10),
351
BARRIER_ACCESS_COPY_READ_BIT = (1 << 11),
352
BARRIER_ACCESS_COPY_WRITE_BIT = (1 << 12),
353
BARRIER_ACCESS_HOST_READ_BIT = (1 << 13),
354
BARRIER_ACCESS_HOST_WRITE_BIT = (1 << 14),
355
BARRIER_ACCESS_MEMORY_READ_BIT = (1 << 15),
356
BARRIER_ACCESS_MEMORY_WRITE_BIT = (1 << 16),
357
BARRIER_ACCESS_ACCELERATION_STRUCTURE_READ_BIT = (1 << 21),
358
BARRIER_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT = (1 << 22),
359
BARRIER_ACCESS_FRAGMENT_SHADING_RATE_ATTACHMENT_READ_BIT = (1 << 23),
360
BARRIER_ACCESS_FRAGMENT_DENSITY_MAP_ATTACHMENT_READ_BIT = (1 << 24),
361
BARRIER_ACCESS_RESOLVE_READ_BIT = (1 << 25),
362
BARRIER_ACCESS_RESOLVE_WRITE_BIT = (1 << 26),
363
BARRIER_ACCESS_STORAGE_CLEAR_BIT = (1 << 27),
364
};
365
366
// https://github.com/godotengine/godot/pull/110360 - "MemoryBarrier" conflicts with Windows header defines
367
struct MemoryAccessBarrier {
368
BitField<BarrierAccessBits> src_access = {};
369
BitField<BarrierAccessBits> dst_access = {};
370
};
371
372
struct BufferBarrier {
373
BufferID buffer;
374
BitField<BarrierAccessBits> src_access = {};
375
BitField<BarrierAccessBits> dst_access = {};
376
uint64_t offset = 0;
377
uint64_t size = 0;
378
};
379
380
struct TextureBarrier {
381
TextureID texture;
382
BitField<BarrierAccessBits> src_access = {};
383
BitField<BarrierAccessBits> dst_access = {};
384
TextureLayout prev_layout = TEXTURE_LAYOUT_UNDEFINED;
385
TextureLayout next_layout = TEXTURE_LAYOUT_UNDEFINED;
386
TextureSubresourceRange subresources;
387
};
388
389
struct AccelerationStructureBarrier {
390
AccelerationStructureID acceleration_structure;
391
BitField<BarrierAccessBits> src_access;
392
BitField<BarrierAccessBits> dst_access;
393
uint64_t offset = 0;
394
uint64_t size = 0;
395
};
396
397
virtual void command_pipeline_barrier(
398
CommandBufferID p_cmd_buffer,
399
BitField<PipelineStageBits> p_src_stages,
400
BitField<PipelineStageBits> p_dst_stages,
401
VectorView<MemoryAccessBarrier> p_memory_barriers,
402
VectorView<BufferBarrier> p_buffer_barriers,
403
VectorView<TextureBarrier> p_texture_barriers,
404
VectorView<AccelerationStructureBarrier> p_acceleration_structure_barriers) = 0;
405
406
/****************/
407
/**** FENCES ****/
408
/****************/
409
410
virtual FenceID fence_create() = 0;
411
virtual Error fence_wait(FenceID p_fence) = 0;
412
virtual void fence_free(FenceID p_fence) = 0;
413
414
/********************/
415
/**** SEMAPHORES ****/
416
/********************/
417
418
virtual SemaphoreID semaphore_create() = 0;
419
virtual void semaphore_free(SemaphoreID p_semaphore) = 0;
420
421
/*************************/
422
/**** COMMAND BUFFERS ****/
423
/*************************/
424
425
// ----- QUEUE FAMILY -----
426
427
enum CommandQueueFamilyBits {
428
COMMAND_QUEUE_FAMILY_GRAPHICS_BIT = 0x1,
429
COMMAND_QUEUE_FAMILY_COMPUTE_BIT = 0x2,
430
COMMAND_QUEUE_FAMILY_TRANSFER_BIT = 0x4
431
};
432
433
// The requested command queue family must support all specified bits or it'll fail to return a valid family otherwise. If a valid surface is specified, the queue must support presenting to it.
434
// It is valid to specify no bits and a valid surface: in this case, the dedicated presentation queue family will be the preferred option.
435
virtual CommandQueueFamilyID command_queue_family_get(BitField<CommandQueueFamilyBits> p_cmd_queue_family_bits, RenderingContextDriver::SurfaceID p_surface = 0) = 0;
436
437
// ----- QUEUE -----
438
439
virtual CommandQueueID command_queue_create(CommandQueueFamilyID p_cmd_queue_family, bool p_identify_as_main_queue = false) = 0;
440
virtual Error command_queue_execute_and_present(CommandQueueID p_cmd_queue, VectorView<SemaphoreID> p_wait_semaphores, VectorView<CommandBufferID> p_cmd_buffers, VectorView<SemaphoreID> p_cmd_semaphores, FenceID p_cmd_fence, VectorView<SwapChainID> p_swap_chains) = 0;
441
virtual void command_queue_free(CommandQueueID p_cmd_queue) = 0;
442
443
// ----- POOL -----
444
445
enum CommandBufferType {
446
COMMAND_BUFFER_TYPE_PRIMARY,
447
COMMAND_BUFFER_TYPE_SECONDARY,
448
};
449
450
virtual CommandPoolID command_pool_create(CommandQueueFamilyID p_cmd_queue_family, CommandBufferType p_cmd_buffer_type) = 0;
451
virtual bool command_pool_reset(CommandPoolID p_cmd_pool) = 0;
452
virtual void command_pool_free(CommandPoolID p_cmd_pool) = 0;
453
454
// ----- BUFFER -----
455
456
virtual CommandBufferID command_buffer_create(CommandPoolID p_cmd_pool) = 0;
457
virtual bool command_buffer_begin(CommandBufferID p_cmd_buffer) = 0;
458
virtual bool command_buffer_begin_secondary(CommandBufferID p_cmd_buffer, RenderPassID p_render_pass, uint32_t p_subpass, FramebufferID p_framebuffer) = 0;
459
virtual void command_buffer_end(CommandBufferID p_cmd_buffer) = 0;
460
virtual void command_buffer_execute_secondary(CommandBufferID p_cmd_buffer, VectorView<CommandBufferID> p_secondary_cmd_buffers) = 0;
461
462
/********************/
463
/**** SWAP CHAIN ****/
464
/********************/
465
466
// The swap chain won't be valid for use until it is resized at least once.
467
virtual SwapChainID swap_chain_create(RenderingContextDriver::SurfaceID p_surface) = 0;
468
469
// The swap chain must not be in use when a resize is requested. Wait until all rendering associated to the swap chain is finished before resizing it.
470
virtual Error swap_chain_resize(CommandQueueID p_cmd_queue, SwapChainID p_swap_chain, uint32_t p_desired_framebuffer_count) = 0;
471
472
// Acquire the framebuffer that can be used for drawing. This must be called only once every time a new frame will be rendered.
473
virtual FramebufferID swap_chain_acquire_framebuffer(CommandQueueID p_cmd_queue, SwapChainID p_swap_chain, bool &r_resize_required) = 0;
474
475
// Retrieve the render pass that can be used to draw on the swap chain's framebuffers.
476
virtual RenderPassID swap_chain_get_render_pass(SwapChainID p_swap_chain) = 0;
477
478
// Retrieve the rotation in degrees to apply as a pre-transform. Usually 0 on PC. May be 0, 90, 180 & 270 on Android.
479
virtual int swap_chain_get_pre_rotation_degrees(SwapChainID p_swap_chain) { return 0; }
480
481
// Retrieve the format used by the swap chain's framebuffers.
482
virtual DataFormat swap_chain_get_format(SwapChainID p_swap_chain) = 0;
483
484
// Tells the swapchain the max_fps so it can use the proper frame pacing.
485
// Android uses this with Swappy library. Some implementations or platforms may ignore this hint.
486
virtual void swap_chain_set_max_fps(SwapChainID p_swap_chain, int p_max_fps) {}
487
488
// Wait until all rendering associated to the swap chain is finished before deleting it.
489
virtual void swap_chain_free(SwapChainID p_swap_chain) = 0;
490
491
/*********************/
492
/**** FRAMEBUFFER ****/
493
/*********************/
494
495
virtual FramebufferID framebuffer_create(RenderPassID p_render_pass, VectorView<TextureID> p_attachments, uint32_t p_width, uint32_t p_height) = 0;
496
virtual void framebuffer_free(FramebufferID p_framebuffer) = 0;
497
498
/****************/
499
/**** SHADER ****/
500
/****************/
501
502
struct ImmutableSampler {
503
UniformType type = UNIFORM_TYPE_MAX;
504
uint32_t binding = 0xffffffff; // Binding index as specified in shader.
505
LocalVector<ID> ids;
506
};
507
508
// Creates a Pipeline State Object (PSO) out of the shader and all the input data it needs.
509
// Immutable samplers can be embedded when creating the pipeline layout on the condition they remain valid and unchanged, so they don't need to be
510
// specified when creating uniform sets PSO resource for binding.
511
virtual ShaderID shader_create_from_container(const Ref<RenderingShaderContainer> &p_shader_container, const Vector<ImmutableSampler> &p_immutable_samplers) = 0;
512
// Only meaningful if API_TRAIT_SHADER_CHANGE_INVALIDATION is SHADER_CHANGE_INVALIDATION_ALL_OR_NONE_ACCORDING_TO_LAYOUT_HASH.
513
virtual uint32_t shader_get_layout_hash(ShaderID p_shader) { return 0; }
514
virtual void shader_free(ShaderID p_shader) = 0;
515
virtual void shader_destroy_modules(ShaderID p_shader) = 0;
516
517
public:
518
/*********************/
519
/**** UNIFORM SET ****/
520
/*********************/
521
522
struct BoundUniform {
523
UniformType type = UNIFORM_TYPE_MAX;
524
uint32_t binding = 0xffffffff; // Binding index as specified in shader.
525
LocalVector<ID> ids;
526
// Flag to indicate that this is an immutable sampler so it is skipped when creating uniform
527
// sets, as it would be set previously when creating the pipeline layout.
528
bool immutable_sampler = false;
529
530
_FORCE_INLINE_ bool is_dynamic() const {
531
return type == UNIFORM_TYPE_STORAGE_BUFFER_DYNAMIC || type == UNIFORM_TYPE_UNIFORM_BUFFER_DYNAMIC;
532
}
533
};
534
535
virtual UniformSetID uniform_set_create(VectorView<BoundUniform> p_uniforms, ShaderID p_shader, uint32_t p_set_index, int p_linear_pool_index) = 0;
536
virtual void linear_uniform_set_pools_reset(int p_linear_pool_index) {}
537
virtual void uniform_set_free(UniformSetID p_uniform_set) = 0;
538
virtual bool uniform_sets_have_linear_pools() const { return false; }
539
virtual uint32_t uniform_sets_get_dynamic_offsets(VectorView<UniformSetID> p_uniform_sets, ShaderID p_shader, uint32_t p_first_set_index, uint32_t p_set_count) const = 0;
540
541
// ----- COMMANDS -----
542
543
virtual void command_uniform_set_prepare_for_use(CommandBufferID p_cmd_buffer, UniformSetID p_uniform_set, ShaderID p_shader, uint32_t p_set_index) = 0;
544
545
/******************/
546
/**** TRANSFER ****/
547
/******************/
548
549
struct BufferCopyRegion {
550
uint64_t src_offset = 0;
551
uint64_t dst_offset = 0;
552
uint64_t size = 0;
553
};
554
555
struct TextureCopyRegion {
556
TextureSubresourceLayers src_subresources;
557
Vector3i src_offset;
558
TextureSubresourceLayers dst_subresources;
559
Vector3i dst_offset;
560
Vector3i size;
561
};
562
563
struct BufferTextureCopyRegion {
564
uint64_t buffer_offset = 0;
565
uint64_t row_pitch = 0;
566
TextureSubresource texture_subresource;
567
Vector3i texture_offset;
568
Vector3i texture_region_size;
569
};
570
571
virtual void command_clear_buffer(CommandBufferID p_cmd_buffer, BufferID p_buffer, uint64_t p_offset, uint64_t p_size) = 0;
572
virtual void command_copy_buffer(CommandBufferID p_cmd_buffer, BufferID p_src_buffer, BufferID p_dst_buffer, VectorView<BufferCopyRegion> p_regions) = 0;
573
574
virtual void command_copy_texture(CommandBufferID p_cmd_buffer, TextureID p_src_texture, TextureLayout p_src_texture_layout, TextureID p_dst_texture, TextureLayout p_dst_texture_layout, VectorView<TextureCopyRegion> p_regions) = 0;
575
virtual void command_resolve_texture(CommandBufferID p_cmd_buffer, TextureID p_src_texture, TextureLayout p_src_texture_layout, uint32_t p_src_layer, uint32_t p_src_mipmap, TextureID p_dst_texture, TextureLayout p_dst_texture_layout, uint32_t p_dst_layer, uint32_t p_dst_mipmap) = 0;
576
virtual void command_clear_color_texture(CommandBufferID p_cmd_buffer, TextureID p_texture, TextureLayout p_texture_layout, const Color &p_color, const TextureSubresourceRange &p_subresources) = 0;
577
virtual void command_clear_depth_stencil_texture(CommandBufferID p_cmd_buffer, TextureID p_texture, TextureLayout p_texture_layout, float p_depth, uint8_t p_stencil, const TextureSubresourceRange &p_subresources) = 0;
578
579
virtual void command_copy_buffer_to_texture(CommandBufferID p_cmd_buffer, BufferID p_src_buffer, TextureID p_dst_texture, TextureLayout p_dst_texture_layout, VectorView<BufferTextureCopyRegion> p_regions) = 0;
580
virtual void command_copy_texture_to_buffer(CommandBufferID p_cmd_buffer, TextureID p_src_texture, TextureLayout p_src_texture_layout, BufferID p_dst_buffer, VectorView<BufferTextureCopyRegion> p_regions) = 0;
581
582
/******************/
583
/**** PIPELINE ****/
584
/******************/
585
586
virtual void pipeline_free(PipelineID p_pipeline) = 0;
587
588
// ----- BINDING -----
589
590
virtual void command_bind_push_constants(CommandBufferID p_cmd_buffer, ShaderID p_shader, uint32_t p_first_index, VectorView<uint32_t> p_data) = 0;
591
592
// ----- CACHE -----
593
594
virtual bool pipeline_cache_create(const Vector<uint8_t> &p_data) = 0;
595
virtual void pipeline_cache_free() = 0;
596
virtual size_t pipeline_cache_query_size() = 0;
597
virtual Vector<uint8_t> pipeline_cache_serialize() = 0;
598
599
/*******************/
600
/**** RENDERING ****/
601
/*******************/
602
603
// ----- SUBPASS -----
604
605
enum AttachmentLoadOp {
606
ATTACHMENT_LOAD_OP_LOAD = 0,
607
ATTACHMENT_LOAD_OP_CLEAR = 1,
608
ATTACHMENT_LOAD_OP_DONT_CARE = 2,
609
};
610
611
enum AttachmentStoreOp {
612
ATTACHMENT_STORE_OP_STORE = 0,
613
ATTACHMENT_STORE_OP_DONT_CARE = 1,
614
};
615
616
struct Attachment {
617
DataFormat format = DATA_FORMAT_MAX;
618
TextureSamples samples = TEXTURE_SAMPLES_MAX;
619
AttachmentLoadOp load_op = ATTACHMENT_LOAD_OP_DONT_CARE;
620
AttachmentStoreOp store_op = ATTACHMENT_STORE_OP_DONT_CARE;
621
AttachmentLoadOp stencil_load_op = ATTACHMENT_LOAD_OP_DONT_CARE;
622
AttachmentStoreOp stencil_store_op = ATTACHMENT_STORE_OP_DONT_CARE;
623
TextureLayout initial_layout = TEXTURE_LAYOUT_UNDEFINED;
624
TextureLayout final_layout = TEXTURE_LAYOUT_UNDEFINED;
625
};
626
627
struct AttachmentReference {
628
static constexpr uint32_t UNUSED = 0xffffffff;
629
uint32_t attachment = UNUSED;
630
TextureLayout layout = TEXTURE_LAYOUT_UNDEFINED;
631
BitField<TextureAspectBits> aspect = {};
632
};
633
634
struct Subpass {
635
LocalVector<AttachmentReference> input_references;
636
LocalVector<AttachmentReference> color_references;
637
AttachmentReference depth_stencil_reference;
638
AttachmentReference depth_resolve_reference;
639
LocalVector<AttachmentReference> resolve_references;
640
LocalVector<uint32_t> preserve_attachments;
641
AttachmentReference fragment_shading_rate_reference;
642
Size2i fragment_shading_rate_texel_size;
643
};
644
645
struct SubpassDependency {
646
uint32_t src_subpass = 0xffffffff;
647
uint32_t dst_subpass = 0xffffffff;
648
BitField<PipelineStageBits> src_stages = {};
649
BitField<PipelineStageBits> dst_stages = {};
650
BitField<BarrierAccessBits> src_access = {};
651
BitField<BarrierAccessBits> dst_access = {};
652
};
653
654
virtual RenderPassID render_pass_create(VectorView<Attachment> p_attachments, VectorView<Subpass> p_subpasses, VectorView<SubpassDependency> p_subpass_dependencies, uint32_t p_view_count, AttachmentReference p_fragment_density_map_attachment) = 0;
655
virtual void render_pass_free(RenderPassID p_render_pass) = 0;
656
657
// ----- COMMANDS -----
658
659
union RenderPassClearValue {
660
Color color = {};
661
struct {
662
float depth;
663
uint32_t stencil;
664
};
665
666
RenderPassClearValue() {}
667
};
668
669
struct AttachmentClear {
670
BitField<TextureAspectBits> aspect = {};
671
uint32_t color_attachment = 0xffffffff;
672
RenderPassClearValue value;
673
};
674
675
virtual void command_begin_render_pass(CommandBufferID p_cmd_buffer, RenderPassID p_render_pass, FramebufferID p_framebuffer, CommandBufferType p_cmd_buffer_type, const Rect2i &p_rect, VectorView<RenderPassClearValue> p_clear_values) = 0;
676
virtual void command_end_render_pass(CommandBufferID p_cmd_buffer) = 0;
677
virtual void command_next_render_subpass(CommandBufferID p_cmd_buffer, CommandBufferType p_cmd_buffer_type) = 0;
678
virtual void command_render_set_viewport(CommandBufferID p_cmd_buffer, VectorView<Rect2i> p_viewports) = 0;
679
virtual void command_render_set_scissor(CommandBufferID p_cmd_buffer, VectorView<Rect2i> p_scissors) = 0;
680
virtual void command_render_clear_attachments(CommandBufferID p_cmd_buffer, VectorView<AttachmentClear> p_attachment_clears, VectorView<Rect2i> p_rects) = 0;
681
682
// Binding.
683
virtual void command_bind_render_pipeline(CommandBufferID p_cmd_buffer, PipelineID p_pipeline) = 0;
684
virtual void command_bind_render_uniform_sets(CommandBufferID p_cmd_buffer, VectorView<UniformSetID> p_uniform_sets, ShaderID p_shader, uint32_t p_first_set_index, uint32_t p_set_count, uint32_t p_dynamic_offsets) = 0;
685
686
// Drawing.
687
virtual void command_render_draw(CommandBufferID p_cmd_buffer, uint32_t p_vertex_count, uint32_t p_instance_count, uint32_t p_base_vertex, uint32_t p_first_instance) = 0;
688
virtual void command_render_draw_indexed(CommandBufferID p_cmd_buffer, uint32_t p_index_count, uint32_t p_instance_count, uint32_t p_first_index, int32_t p_vertex_offset, uint32_t p_first_instance) = 0;
689
virtual void command_render_draw_indexed_indirect(CommandBufferID p_cmd_buffer, BufferID p_indirect_buffer, uint64_t p_offset, uint32_t p_draw_count, uint32_t p_stride) = 0;
690
virtual void command_render_draw_indexed_indirect_count(CommandBufferID p_cmd_buffer, BufferID p_indirect_buffer, uint64_t p_offset, BufferID p_count_buffer, uint64_t p_count_buffer_offset, uint32_t p_max_draw_count, uint32_t p_stride) = 0;
691
virtual void command_render_draw_indirect(CommandBufferID p_cmd_buffer, BufferID p_indirect_buffer, uint64_t p_offset, uint32_t p_draw_count, uint32_t p_stride) = 0;
692
virtual void command_render_draw_indirect_count(CommandBufferID p_cmd_buffer, BufferID p_indirect_buffer, uint64_t p_offset, BufferID p_count_buffer, uint64_t p_count_buffer_offset, uint32_t p_max_draw_count, uint32_t p_stride) = 0;
693
694
// Buffer binding.
695
virtual void command_render_bind_vertex_buffers(CommandBufferID p_cmd_buffer, uint32_t p_binding_count, const BufferID *p_buffers, const uint64_t *p_offsets, uint64_t p_dynamic_offsets) = 0;
696
virtual void command_render_bind_index_buffer(CommandBufferID p_cmd_buffer, BufferID p_buffer, IndexBufferFormat p_format, uint64_t p_offset) = 0;
697
698
// Dynamic state.
699
virtual void command_render_set_blend_constants(CommandBufferID p_cmd_buffer, const Color &p_constants) = 0;
700
virtual void command_render_set_line_width(CommandBufferID p_cmd_buffer, float p_width) = 0;
701
702
// ----- PIPELINE -----
703
704
virtual PipelineID render_pipeline_create(
705
ShaderID p_shader,
706
VertexFormatID p_vertex_format,
707
RenderPrimitive p_render_primitive,
708
PipelineRasterizationState p_rasterization_state,
709
PipelineMultisampleState p_multisample_state,
710
PipelineDepthStencilState p_depth_stencil_state,
711
PipelineColorBlendState p_blend_state,
712
VectorView<int32_t> p_color_attachments,
713
BitField<PipelineDynamicStateFlags> p_dynamic_state,
714
RenderPassID p_render_pass,
715
uint32_t p_render_subpass,
716
VectorView<PipelineSpecializationConstant> p_specialization_constants) = 0;
717
718
/*****************/
719
/**** COMPUTE ****/
720
/*****************/
721
722
// ----- COMMANDS -----
723
724
// Binding.
725
virtual void command_bind_compute_pipeline(CommandBufferID p_cmd_buffer, PipelineID p_pipeline) = 0;
726
virtual void command_bind_compute_uniform_sets(CommandBufferID p_cmd_buffer, VectorView<UniformSetID> p_uniform_sets, ShaderID p_shader, uint32_t p_first_set_index, uint32_t p_set_count, uint32_t p_dynamic_offsets) = 0;
727
728
// Dispatching.
729
virtual void command_compute_dispatch(CommandBufferID p_cmd_buffer, uint32_t p_x_groups, uint32_t p_y_groups, uint32_t p_z_groups) = 0;
730
virtual void command_compute_dispatch_indirect(CommandBufferID p_cmd_buffer, BufferID p_indirect_buffer, uint64_t p_offset) = 0;
731
732
// ----- PIPELINE -----
733
734
virtual PipelineID compute_pipeline_create(ShaderID p_shader, VectorView<PipelineSpecializationConstant> p_specialization_constants) = 0;
735
736
/********************/
737
/**** RAYTRACING ****/
738
/********************/
739
740
// ----- ACCELERATION STRUCTURE -----
741
742
enum AccelerationStructureType {
743
ACCELERATION_STRUCTURE_TYPE_BLAS,
744
ACCELERATION_STRUCTURE_TYPE_TLAS,
745
};
746
747
enum AccelerationStructureGeometryBits {
748
ACCELERATION_STRUCTURE_GEOMETRY_OPAQUE = 1 << 0,
749
ACCELERATION_STRUCTURE_GEOMETRY_NO_DUPLICATE_ANY_HIT_INVOCATION = 1 << 1,
750
};
751
752
virtual AccelerationStructureID blas_create(BufferID p_vertex_buffer, uint64_t p_vertex_offset, VertexFormatID p_vertex_format, uint32_t p_vertex_count, uint32_t p_position_attribute_location, BufferID p_index_buffer, IndexBufferFormat p_index_format, uint64_t p_index_offset, uint32_t p_index_count, BitField<AccelerationStructureGeometryBits> p_geometry_bits) = 0;
753
virtual uint32_t tlas_instances_buffer_get_size_bytes(uint32_t p_instance_count) = 0;
754
virtual void tlas_instances_buffer_fill(BufferID p_instances_buffer, VectorView<AccelerationStructureID> p_blases, VectorView<Transform3D> p_transforms) = 0;
755
virtual AccelerationStructureID tlas_create(BufferID p_instances_buffer) = 0;
756
virtual void acceleration_structure_free(AccelerationStructureID p_acceleration_structure) = 0;
757
virtual uint32_t acceleration_structure_get_scratch_size_bytes(AccelerationStructureID p_acceleration_structure) = 0;
758
759
// ----- PIPELINE -----
760
761
virtual RaytracingPipelineID raytracing_pipeline_create(ShaderID p_shader, VectorView<PipelineSpecializationConstant> p_specialization_constants) = 0;
762
virtual void raytracing_pipeline_free(RaytracingPipelineID p_pipeline) = 0;
763
764
// ----- COMMANDS -----
765
766
virtual void command_build_acceleration_structure(CommandBufferID p_cmd_buffer, AccelerationStructureID p_acceleration_structure, BufferID p_scratch_buffer) = 0;
767
virtual void command_bind_raytracing_pipeline(CommandBufferID p_cmd_buffer, RaytracingPipelineID p_pipeline) = 0;
768
virtual void command_bind_raytracing_uniform_set(CommandBufferID p_cmd_buffer, UniformSetID p_uniform_set, ShaderID p_shader, uint32_t p_set_index) = 0;
769
virtual void command_trace_rays(CommandBufferID p_cmd_buffer, uint32_t p_width, uint32_t p_height) = 0;
770
771
/******************/
772
/**** CALLBACK ****/
773
/******************/
774
775
typedef void (*DriverCallback)(RenderingDeviceDriver *p_driver, CommandBufferID p_command_buffer, void *p_userdata);
776
777
/*****************/
778
/**** QUERIES ****/
779
/*****************/
780
781
// ----- TIMESTAMP -----
782
783
// Basic.
784
virtual QueryPoolID timestamp_query_pool_create(uint32_t p_query_count) = 0;
785
virtual void timestamp_query_pool_free(QueryPoolID p_pool_id) = 0;
786
virtual void timestamp_query_pool_get_results(QueryPoolID p_pool_id, uint32_t p_query_count, uint64_t *r_results) = 0;
787
virtual uint64_t timestamp_query_result_to_time(uint64_t p_result) = 0;
788
789
// Commands.
790
virtual void command_timestamp_query_pool_reset(CommandBufferID p_cmd_buffer, QueryPoolID p_pool_id, uint32_t p_query_count) = 0;
791
virtual void command_timestamp_write(CommandBufferID p_cmd_buffer, QueryPoolID p_pool_id, uint32_t p_index) = 0;
792
793
/****************/
794
/**** LABELS ****/
795
/****************/
796
797
virtual void command_begin_label(CommandBufferID p_cmd_buffer, const char *p_label_name, const Color &p_color) = 0;
798
virtual void command_end_label(CommandBufferID p_cmd_buffer) = 0;
799
800
/****************/
801
/**** DEBUG *****/
802
/****************/
803
virtual void command_insert_breadcrumb(CommandBufferID p_cmd_buffer, uint32_t p_data) = 0;
804
805
/********************/
806
/**** SUBMISSION ****/
807
/********************/
808
809
virtual void begin_segment(uint32_t p_frame_index, uint32_t p_frames_drawn) = 0;
810
virtual void end_segment() = 0;
811
812
/**************/
813
/**** MISC ****/
814
/**************/
815
816
enum ObjectType {
817
OBJECT_TYPE_TEXTURE,
818
OBJECT_TYPE_SAMPLER,
819
OBJECT_TYPE_BUFFER,
820
OBJECT_TYPE_SHADER,
821
OBJECT_TYPE_UNIFORM_SET,
822
OBJECT_TYPE_PIPELINE,
823
OBJECT_TYPE_ACCELERATION_STRUCTURE,
824
OBJECT_TYPE_RAYTRACING_PIPELINE,
825
};
826
827
struct MultiviewCapabilities {
828
bool is_supported = false;
829
bool geometry_shader_is_supported = false;
830
bool tessellation_shader_is_supported = false;
831
uint32_t max_view_count = 0;
832
uint32_t max_instance_count = 0;
833
};
834
835
struct FragmentShadingRateCapabilities {
836
Size2i min_texel_size;
837
Size2i max_texel_size;
838
Size2i max_fragment_size;
839
bool pipeline_supported = false;
840
bool primitive_supported = false;
841
bool attachment_supported = false;
842
};
843
844
struct FragmentDensityMapCapabilities {
845
Size2i min_texel_size;
846
Size2i max_texel_size;
847
Size2i offset_granularity;
848
bool attachment_supported = false;
849
bool dynamic_attachment_supported = false;
850
bool non_subsampled_images_supported = false;
851
bool invocations_supported = false;
852
bool offset_supported = false;
853
};
854
855
enum ApiTrait {
856
API_TRAIT_HONORS_PIPELINE_BARRIERS,
857
API_TRAIT_SHADER_CHANGE_INVALIDATION,
858
API_TRAIT_TEXTURE_TRANSFER_ALIGNMENT,
859
API_TRAIT_TEXTURE_DATA_ROW_PITCH_STEP,
860
API_TRAIT_SECONDARY_VIEWPORT_SCISSOR,
861
API_TRAIT_CLEARS_WITH_COPY_ENGINE,
862
API_TRAIT_USE_GENERAL_IN_COPY_QUEUES,
863
API_TRAIT_BUFFERS_REQUIRE_TRANSITIONS,
864
API_TRAIT_TEXTURE_OUTPUTS_REQUIRE_CLEARS,
865
};
866
867
enum ShaderChangeInvalidation {
868
SHADER_CHANGE_INVALIDATION_ALL_BOUND_UNIFORM_SETS,
869
// What Vulkan does.
870
SHADER_CHANGE_INVALIDATION_INCOMPATIBLE_SETS_PLUS_CASCADE,
871
// What D3D12 does.
872
SHADER_CHANGE_INVALIDATION_ALL_OR_NONE_ACCORDING_TO_LAYOUT_HASH,
873
};
874
875
enum DeviceFamily {
876
DEVICE_UNKNOWN,
877
DEVICE_OPENGL,
878
DEVICE_VULKAN,
879
DEVICE_DIRECTX,
880
DEVICE_METAL,
881
};
882
883
struct Capabilities {
884
DeviceFamily device_family = DEVICE_UNKNOWN;
885
uint32_t version_major = 1;
886
uint32_t version_minor = 0;
887
};
888
889
virtual void set_object_name(ObjectType p_type, ID p_driver_id, const String &p_name) = 0;
890
virtual uint64_t get_resource_native_handle(DriverResource p_type, ID p_driver_id) = 0;
891
virtual uint64_t get_total_memory_used() = 0;
892
virtual uint64_t get_lazily_memory_used() = 0;
893
virtual uint64_t limit_get(Limit p_limit) = 0;
894
virtual uint64_t api_trait_get(ApiTrait p_trait);
895
virtual bool has_feature(Features p_feature) = 0;
896
virtual const MultiviewCapabilities &get_multiview_capabilities() = 0;
897
virtual const FragmentShadingRateCapabilities &get_fragment_shading_rate_capabilities() = 0;
898
virtual const FragmentDensityMapCapabilities &get_fragment_density_map_capabilities() = 0;
899
virtual String get_api_name() const = 0;
900
virtual String get_api_version() const = 0;
901
virtual String get_pipeline_cache_uuid() const = 0;
902
virtual const Capabilities &get_capabilities() const = 0;
903
virtual const RenderingShaderContainerFormat &get_shader_container_format() const = 0;
904
905
virtual bool is_composite_alpha_supported(CommandQueueID p_queue) const { return false; }
906
907
/******************/
908
909
virtual ~RenderingDeviceDriver();
910
};
911
912
using RDD = RenderingDeviceDriver;
913
914