Path: blob/master/servers/rendering/rendering_device.h
10277 views
/**************************************************************************/1/* rendering_device.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/object/worker_thread_pool.h"33#include "core/os/condition_variable.h"34#include "core/os/thread_safe.h"35#include "core/templates/local_vector.h"36#include "core/templates/rid_owner.h"37#include "core/variant/typed_array.h"38#include "servers/display_server.h"39#include "servers/rendering/rendering_device_commons.h"40#include "servers/rendering/rendering_device_driver.h"41#include "servers/rendering/rendering_device_graph.h"4243class RDTextureFormat;44class RDTextureView;45class RDAttachmentFormat;46class RDSamplerState;47class RDVertexAttribute;48class RDShaderSource;49class RDShaderSPIRV;50class RDUniform;51class RDPipelineRasterizationState;52class RDPipelineMultisampleState;53class RDPipelineDepthStencilState;54class RDPipelineColorBlendState;55class RDFramebufferPass;56class RDPipelineSpecializationConstant;5758class RenderingDevice : public RenderingDeviceCommons {59GDCLASS(RenderingDevice, Object)6061_THREAD_SAFE_CLASS_6263private:64Thread::ID render_thread_id;6566public:67typedef int64_t DrawListID;68typedef int64_t ComputeListID;6970typedef void (*InvalidationCallback)(void *);7172private:73static RenderingDevice *singleton;7475RenderingContextDriver *context = nullptr;76RenderingDeviceDriver *driver = nullptr;77RenderingContextDriver::Device device;7879bool local_device_processing = false;80bool is_main_instance = false;8182protected:83static void _bind_methods();8485#ifndef DISABLE_DEPRECATED86RID _shader_create_from_bytecode_bind_compat_79606(const Vector<uint8_t> &p_shader_binary);87RID _texture_create_from_extension_compat_105570(TextureType p_type, DataFormat p_format, TextureSamples p_samples, BitField<RenderingDevice::TextureUsageBits> p_usage, uint64_t p_image, uint64_t p_width, uint64_t p_height, uint64_t p_depth, uint64_t p_layers);88static void _bind_compatibility_methods();89#endif9091/***************************/92/**** ID INFRASTRUCTURE ****/93/***************************/94public:95//base numeric ID for all types96enum {97INVALID_FORMAT_ID = -198};99100enum IDType {101ID_TYPE_FRAMEBUFFER_FORMAT,102ID_TYPE_VERTEX_FORMAT,103ID_TYPE_DRAW_LIST,104ID_TYPE_COMPUTE_LIST = 4,105ID_TYPE_MAX,106ID_BASE_SHIFT = 58, // 5 bits for ID types.107ID_MASK = (ID_BASE_SHIFT - 1),108};109110private:111HashMap<RID, HashSet<RID>> dependency_map; // IDs to IDs that depend on it.112HashMap<RID, HashSet<RID>> reverse_dependency_map; // Same as above, but in reverse.113114void _add_dependency(RID p_id, RID p_depends_on);115void _free_dependencies(RID p_id);116117private:118/***************************/119/**** BUFFER MANAGEMENT ****/120/***************************/121122// These are temporary buffers on CPU memory that hold123// the information until the CPU fetches it and places it124// either on GPU buffers, or images (textures). It ensures125// updates are properly synchronized with whatever the126// GPU is doing.127//128// The logic here is as follows, only 3 of these129// blocks are created at the beginning (one per frame)130// they can each belong to a frame (assigned to current when131// used) and they can only be reused after the same frame is132// recycled.133//134// When CPU requires to allocate more than what is available,135// more of these buffers are created. If a limit is reached,136// then a fence will ensure will wait for blocks allocated137// in previous frames are processed. If that fails, then138// another fence will ensure everything pending for the current139// frame is processed (effectively stalling).140//141// See the comments in the code to understand better how it works.142143enum StagingRequiredAction {144STAGING_REQUIRED_ACTION_NONE,145STAGING_REQUIRED_ACTION_FLUSH_AND_STALL_ALL,146STAGING_REQUIRED_ACTION_STALL_PREVIOUS,147};148149struct StagingBufferBlock {150RDD::BufferID driver_id;151uint64_t frame_used = 0;152uint32_t fill_amount = 0;153};154155struct StagingBuffers {156Vector<StagingBufferBlock> blocks;157int current = 0;158uint32_t block_size = 0;159uint64_t max_size = 0;160BitField<RDD::BufferUsageBits> usage_bits = {};161bool used = false;162};163164Error _staging_buffer_allocate(StagingBuffers &p_staging_buffers, uint32_t p_amount, uint32_t p_required_align, uint32_t &r_alloc_offset, uint32_t &r_alloc_size, StagingRequiredAction &r_required_action, bool p_can_segment = true);165void _staging_buffer_execute_required_action(StagingBuffers &p_staging_buffers, StagingRequiredAction p_required_action);166Error _insert_staging_block(StagingBuffers &p_staging_buffers);167168StagingBuffers upload_staging_buffers;169StagingBuffers download_staging_buffers;170171struct Buffer {172RDD::BufferID driver_id;173uint32_t size = 0;174BitField<RDD::BufferUsageBits> usage = {};175RDG::ResourceTracker *draw_tracker = nullptr;176int32_t transfer_worker_index = -1;177uint64_t transfer_worker_operation = 0;178};179180Buffer *_get_buffer_from_owner(RID p_buffer);181Error _buffer_initialize(Buffer *p_buffer, Span<uint8_t> p_data, uint32_t p_required_align = 32);182183void update_perf_report();184// Flag for batching descriptor sets.185bool descriptor_set_batching = true;186// When true, the final draw call that copies our offscreen result into the Swapchain is put into its187// own cmd buffer, so that the whole rendering can start early instead of having to wait for the188// swapchain semaphore to be signaled (which causes bubbles).189bool split_swapchain_into_its_own_cmd_buffer = true;190uint32_t gpu_copy_count = 0;191uint32_t copy_bytes_count = 0;192uint32_t prev_gpu_copy_count = 0;193uint32_t prev_copy_bytes_count = 0;194195RID_Owner<Buffer, true> uniform_buffer_owner;196RID_Owner<Buffer, true> storage_buffer_owner;197RID_Owner<Buffer, true> texture_buffer_owner;198199struct BufferGetDataRequest {200uint32_t frame_local_index = 0;201uint32_t frame_local_count = 0;202Callable callback;203uint32_t size = 0;204};205206public:207Error buffer_copy(RID p_src_buffer, RID p_dst_buffer, uint32_t p_src_offset, uint32_t p_dst_offset, uint32_t p_size);208Error buffer_update(RID p_buffer, uint32_t p_offset, uint32_t p_size, const void *p_data);209Error buffer_clear(RID p_buffer, uint32_t p_offset, uint32_t p_size);210Vector<uint8_t> buffer_get_data(RID p_buffer, uint32_t p_offset = 0, uint32_t p_size = 0); // This causes stall, only use to retrieve large buffers for saving.211Error buffer_get_data_async(RID p_buffer, const Callable &p_callback, uint32_t p_offset = 0, uint32_t p_size = 0);212uint64_t buffer_get_device_address(RID p_buffer);213214private:215/******************/216/**** CALLBACK ****/217/******************/218219public:220enum CallbackResourceType {221CALLBACK_RESOURCE_TYPE_TEXTURE,222CALLBACK_RESOURCE_TYPE_BUFFER,223};224225enum CallbackResourceUsage {226CALLBACK_RESOURCE_USAGE_NONE,227CALLBACK_RESOURCE_USAGE_COPY_FROM,228CALLBACK_RESOURCE_USAGE_COPY_TO,229CALLBACK_RESOURCE_USAGE_RESOLVE_FROM,230CALLBACK_RESOURCE_USAGE_RESOLVE_TO,231CALLBACK_RESOURCE_USAGE_UNIFORM_BUFFER_READ,232CALLBACK_RESOURCE_USAGE_INDIRECT_BUFFER_READ,233CALLBACK_RESOURCE_USAGE_TEXTURE_BUFFER_READ,234CALLBACK_RESOURCE_USAGE_TEXTURE_BUFFER_READ_WRITE,235CALLBACK_RESOURCE_USAGE_STORAGE_BUFFER_READ,236CALLBACK_RESOURCE_USAGE_STORAGE_BUFFER_READ_WRITE,237CALLBACK_RESOURCE_USAGE_VERTEX_BUFFER_READ,238CALLBACK_RESOURCE_USAGE_INDEX_BUFFER_READ,239CALLBACK_RESOURCE_USAGE_TEXTURE_SAMPLE,240CALLBACK_RESOURCE_USAGE_STORAGE_IMAGE_READ,241CALLBACK_RESOURCE_USAGE_STORAGE_IMAGE_READ_WRITE,242CALLBACK_RESOURCE_USAGE_ATTACHMENT_COLOR_READ_WRITE,243CALLBACK_RESOURCE_USAGE_ATTACHMENT_DEPTH_STENCIL_READ_WRITE,244CALLBACK_RESOURCE_USAGE_ATTACHMENT_FRAGMENT_SHADING_RATE_READ,245CALLBACK_RESOURCE_USAGE_ATTACHMENT_FRAGMENT_DENSITY_MAP_READ,246CALLBACK_RESOURCE_USAGE_GENERAL,247CALLBACK_RESOURCE_USAGE_MAX248};249250struct CallbackResource {251RID rid;252CallbackResourceType type = CALLBACK_RESOURCE_TYPE_TEXTURE;253CallbackResourceUsage usage = CALLBACK_RESOURCE_USAGE_NONE;254};255256Error driver_callback_add(RDD::DriverCallback p_callback, void *p_userdata, VectorView<CallbackResource> p_resources);257258/*****************/259/**** TEXTURE ****/260/*****************/261262// In modern APIs, the concept of textures may not exist;263// instead there is the image (the memory pretty much,264// the view (how the memory is interpreted) and the265// sampler (how it's sampled from the shader).266//267// Texture here includes the first two stages, but268// It's possible to create textures sharing the image269// but with different views. The main use case for this270// is textures that can be read as both SRGB/Linear,271// or slices of a texture (a mipmap, a layer, a 3D slice)272// for a framebuffer to render into it.273274struct Texture {275struct SharedFallback {276uint32_t revision = 1;277RDD::TextureID texture;278RDG::ResourceTracker *texture_tracker = nullptr;279RDD::BufferID buffer;280RDG::ResourceTracker *buffer_tracker = nullptr;281bool raw_reinterpretation = false;282};283284RDD::TextureID driver_id;285286TextureType type = TEXTURE_TYPE_MAX;287DataFormat format = DATA_FORMAT_MAX;288TextureSamples samples = TEXTURE_SAMPLES_MAX;289TextureSliceType slice_type = TEXTURE_SLICE_MAX;290Rect2i slice_rect;291uint32_t width = 0;292uint32_t height = 0;293uint32_t depth = 0;294uint32_t layers = 0;295uint32_t mipmaps = 0;296uint32_t usage_flags = 0;297uint32_t base_mipmap = 0;298uint32_t base_layer = 0;299300Vector<DataFormat> allowed_shared_formats;301302bool is_resolve_buffer = false;303bool is_discardable = false;304bool has_initial_data = false;305306BitField<RDD::TextureAspectBits> read_aspect_flags = {};307BitField<RDD::TextureAspectBits> barrier_aspect_flags = {};308bool bound = false; // Bound to framebuffer.309RID owner;310311RDG::ResourceTracker *draw_tracker = nullptr;312HashMap<Rect2i, RDG::ResourceTracker *> *slice_trackers = nullptr;313SharedFallback *shared_fallback = nullptr;314int32_t transfer_worker_index = -1;315uint64_t transfer_worker_operation = 0;316317RDD::TextureSubresourceRange barrier_range() const {318RDD::TextureSubresourceRange r;319r.aspect = barrier_aspect_flags;320r.base_mipmap = base_mipmap;321r.mipmap_count = mipmaps;322r.base_layer = base_layer;323r.layer_count = layers;324return r;325}326327TextureFormat texture_format() const {328TextureFormat tf;329tf.format = format;330tf.width = width;331tf.height = height;332tf.depth = depth;333tf.array_layers = layers;334tf.mipmaps = mipmaps;335tf.texture_type = type;336tf.samples = samples;337tf.usage_bits = usage_flags;338tf.shareable_formats = allowed_shared_formats;339tf.is_resolve_buffer = is_resolve_buffer;340tf.is_discardable = is_discardable;341return tf;342}343};344345RID_Owner<Texture, true> texture_owner;346uint32_t texture_upload_region_size_px = 0;347uint32_t texture_download_region_size_px = 0;348349Vector<uint8_t> _texture_get_data(Texture *tex, uint32_t p_layer, bool p_2d = false);350uint32_t _texture_layer_count(Texture *p_texture) const;351uint32_t _texture_alignment(Texture *p_texture) const;352Error _texture_initialize(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, RDD::TextureLayout p_dst_layout, bool p_immediate_flush);353void _texture_check_shared_fallback(Texture *p_texture);354void _texture_update_shared_fallback(RID p_texture_rid, Texture *p_texture, bool p_for_writing);355void _texture_free_shared_fallback(Texture *p_texture);356void _texture_copy_shared(RID p_src_texture_rid, Texture *p_src_texture, RID p_dst_texture_rid, Texture *p_dst_texture);357void _texture_create_reinterpret_buffer(Texture *p_texture);358uint32_t _texture_vrs_method_to_usage_bits() const;359360struct TextureGetDataRequest {361uint32_t frame_local_index = 0;362uint32_t frame_local_count = 0;363Callable callback;364uint32_t width = 0;365uint32_t height = 0;366uint32_t depth = 0;367uint32_t mipmaps = 0;368RDD::DataFormat format = RDD::DATA_FORMAT_MAX;369};370371public:372struct TextureView {373DataFormat format_override = DATA_FORMAT_MAX; // // Means, use same as format.374TextureSwizzle swizzle_r = TEXTURE_SWIZZLE_R;375TextureSwizzle swizzle_g = TEXTURE_SWIZZLE_G;376TextureSwizzle swizzle_b = TEXTURE_SWIZZLE_B;377TextureSwizzle swizzle_a = TEXTURE_SWIZZLE_A;378379bool operator==(const TextureView &p_other) const {380if (format_override != p_other.format_override) {381return false;382} else if (swizzle_r != p_other.swizzle_r) {383return false;384} else if (swizzle_g != p_other.swizzle_g) {385return false;386} else if (swizzle_b != p_other.swizzle_b) {387return false;388} else if (swizzle_a != p_other.swizzle_a) {389return false;390} else {391return true;392}393}394};395396RID texture_create(const TextureFormat &p_format, const TextureView &p_view, const Vector<Vector<uint8_t>> &p_data = Vector<Vector<uint8_t>>());397RID texture_create_shared(const TextureView &p_view, RID p_with_texture);398RID texture_create_from_extension(TextureType p_type, DataFormat p_format, TextureSamples p_samples, BitField<RenderingDevice::TextureUsageBits> p_usage, uint64_t p_image, uint64_t p_width, uint64_t p_height, uint64_t p_depth, uint64_t p_layers, uint64_t p_mipmaps = 1);399RID texture_create_shared_from_slice(const TextureView &p_view, RID p_with_texture, uint32_t p_layer, uint32_t p_mipmap, uint32_t p_mipmaps = 1, TextureSliceType p_slice_type = TEXTURE_SLICE_2D, uint32_t p_layers = 0);400Error texture_update(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data);401Vector<uint8_t> texture_get_data(RID p_texture, uint32_t p_layer); // CPU textures will return immediately, while GPU textures will most likely force a flush402Error texture_get_data_async(RID p_texture, uint32_t p_layer, const Callable &p_callback);403404bool texture_is_format_supported_for_usage(DataFormat p_format, BitField<TextureUsageBits> p_usage) const;405bool texture_is_shared(RID p_texture);406bool texture_is_valid(RID p_texture);407TextureFormat texture_get_format(RID p_texture);408Size2i texture_size(RID p_texture);409#ifndef DISABLE_DEPRECATED410uint64_t texture_get_native_handle(RID p_texture);411#endif412413Error texture_copy(RID p_from_texture, RID p_to_texture, const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_size, uint32_t p_src_mipmap, uint32_t p_dst_mipmap, uint32_t p_src_layer, uint32_t p_dst_layer);414Error texture_clear(RID p_texture, const Color &p_color, uint32_t p_base_mipmap, uint32_t p_mipmaps, uint32_t p_base_layer, uint32_t p_layers);415Error texture_resolve_multisample(RID p_from_texture, RID p_to_texture);416417void texture_set_discardable(RID p_texture, bool p_discardable);418bool texture_is_discardable(RID p_texture);419420public:421/*************/422/**** VRS ****/423/*************/424425enum VRSMethod {426VRS_METHOD_NONE,427VRS_METHOD_FRAGMENT_SHADING_RATE,428VRS_METHOD_FRAGMENT_DENSITY_MAP,429};430431private:432VRSMethod vrs_method = VRS_METHOD_NONE;433DataFormat vrs_format = DATA_FORMAT_MAX;434Size2i vrs_texel_size;435436static RDG::ResourceUsage _vrs_usage_from_method(VRSMethod p_method);437static RDD::PipelineStageBits _vrs_stages_from_method(VRSMethod p_method);438static RDD::TextureLayout _vrs_layout_from_method(VRSMethod p_method);439void _vrs_detect_method();440441public:442VRSMethod vrs_get_method() const;443DataFormat vrs_get_format() const;444Size2i vrs_get_texel_size() const;445446/*********************/447/**** FRAMEBUFFER ****/448/*********************/449450// In modern APIs, generally, framebuffers work similar to how they451// do in OpenGL, with the exception that452// the "format" (RDD::RenderPassID) is not dynamic453// and must be more or less the same as the one454// used for the render pipelines.455456struct AttachmentFormat {457enum : uint32_t {458UNUSED_ATTACHMENT = 0xFFFFFFFF459};460DataFormat format;461TextureSamples samples;462uint32_t usage_flags;463AttachmentFormat() {464format = DATA_FORMAT_R8G8B8A8_UNORM;465samples = TEXTURE_SAMPLES_1;466usage_flags = 0;467}468};469470struct FramebufferPass {471Vector<int32_t> color_attachments;472Vector<int32_t> input_attachments;473Vector<int32_t> resolve_attachments;474Vector<int32_t> preserve_attachments;475int32_t depth_attachment = ATTACHMENT_UNUSED;476};477478typedef int64_t FramebufferFormatID;479480private:481struct FramebufferFormatKey {482Vector<AttachmentFormat> attachments;483Vector<FramebufferPass> passes;484uint32_t view_count = 1;485VRSMethod vrs_method = VRS_METHOD_NONE;486int32_t vrs_attachment = ATTACHMENT_UNUSED;487Size2i vrs_texel_size;488489bool operator<(const FramebufferFormatKey &p_key) const {490if (vrs_texel_size != p_key.vrs_texel_size) {491return vrs_texel_size < p_key.vrs_texel_size;492}493494if (vrs_attachment != p_key.vrs_attachment) {495return vrs_attachment < p_key.vrs_attachment;496}497498if (vrs_method != p_key.vrs_method) {499return vrs_method < p_key.vrs_method;500}501502if (view_count != p_key.view_count) {503return view_count < p_key.view_count;504}505506uint32_t pass_size = passes.size();507uint32_t key_pass_size = p_key.passes.size();508if (pass_size != key_pass_size) {509return pass_size < key_pass_size;510}511const FramebufferPass *pass_ptr = passes.ptr();512const FramebufferPass *key_pass_ptr = p_key.passes.ptr();513514for (uint32_t i = 0; i < pass_size; i++) {515{ // Compare color attachments.516uint32_t attachment_size = pass_ptr[i].color_attachments.size();517uint32_t key_attachment_size = key_pass_ptr[i].color_attachments.size();518if (attachment_size != key_attachment_size) {519return attachment_size < key_attachment_size;520}521const int32_t *pass_attachment_ptr = pass_ptr[i].color_attachments.ptr();522const int32_t *key_pass_attachment_ptr = key_pass_ptr[i].color_attachments.ptr();523524for (uint32_t j = 0; j < attachment_size; j++) {525if (pass_attachment_ptr[j] != key_pass_attachment_ptr[j]) {526return pass_attachment_ptr[j] < key_pass_attachment_ptr[j];527}528}529}530{ // Compare input attachments.531uint32_t attachment_size = pass_ptr[i].input_attachments.size();532uint32_t key_attachment_size = key_pass_ptr[i].input_attachments.size();533if (attachment_size != key_attachment_size) {534return attachment_size < key_attachment_size;535}536const int32_t *pass_attachment_ptr = pass_ptr[i].input_attachments.ptr();537const int32_t *key_pass_attachment_ptr = key_pass_ptr[i].input_attachments.ptr();538539for (uint32_t j = 0; j < attachment_size; j++) {540if (pass_attachment_ptr[j] != key_pass_attachment_ptr[j]) {541return pass_attachment_ptr[j] < key_pass_attachment_ptr[j];542}543}544}545{ // Compare resolve attachments.546uint32_t attachment_size = pass_ptr[i].resolve_attachments.size();547uint32_t key_attachment_size = key_pass_ptr[i].resolve_attachments.size();548if (attachment_size != key_attachment_size) {549return attachment_size < key_attachment_size;550}551const int32_t *pass_attachment_ptr = pass_ptr[i].resolve_attachments.ptr();552const int32_t *key_pass_attachment_ptr = key_pass_ptr[i].resolve_attachments.ptr();553554for (uint32_t j = 0; j < attachment_size; j++) {555if (pass_attachment_ptr[j] != key_pass_attachment_ptr[j]) {556return pass_attachment_ptr[j] < key_pass_attachment_ptr[j];557}558}559}560{ // Compare preserve attachments.561uint32_t attachment_size = pass_ptr[i].preserve_attachments.size();562uint32_t key_attachment_size = key_pass_ptr[i].preserve_attachments.size();563if (attachment_size != key_attachment_size) {564return attachment_size < key_attachment_size;565}566const int32_t *pass_attachment_ptr = pass_ptr[i].preserve_attachments.ptr();567const int32_t *key_pass_attachment_ptr = key_pass_ptr[i].preserve_attachments.ptr();568569for (uint32_t j = 0; j < attachment_size; j++) {570if (pass_attachment_ptr[j] != key_pass_attachment_ptr[j]) {571return pass_attachment_ptr[j] < key_pass_attachment_ptr[j];572}573}574}575if (pass_ptr[i].depth_attachment != key_pass_ptr[i].depth_attachment) {576return pass_ptr[i].depth_attachment < key_pass_ptr[i].depth_attachment;577}578}579580int as = attachments.size();581int bs = p_key.attachments.size();582if (as != bs) {583return as < bs;584}585586const AttachmentFormat *af_a = attachments.ptr();587const AttachmentFormat *af_b = p_key.attachments.ptr();588for (int i = 0; i < as; i++) {589const AttachmentFormat &a = af_a[i];590const AttachmentFormat &b = af_b[i];591if (a.format != b.format) {592return a.format < b.format;593}594if (a.samples != b.samples) {595return a.samples < b.samples;596}597if (a.usage_flags != b.usage_flags) {598return a.usage_flags < b.usage_flags;599}600}601602return false; // Equal.603}604};605606static RDD::RenderPassID _render_pass_create(RenderingDeviceDriver *p_driver, const Vector<AttachmentFormat> &p_attachments, const Vector<FramebufferPass> &p_passes, VectorView<RDD::AttachmentLoadOp> p_load_ops, VectorView<RDD::AttachmentStoreOp> p_store_ops, uint32_t p_view_count = 1, VRSMethod p_vrs_method = VRS_METHOD_NONE, int32_t p_vrs_attachment = -1, Size2i p_vrs_texel_size = Size2i(), Vector<TextureSamples> *r_samples = nullptr);607static RDD::RenderPassID _render_pass_create_from_graph(RenderingDeviceDriver *p_driver, VectorView<RDD::AttachmentLoadOp> p_load_ops, VectorView<RDD::AttachmentStoreOp> p_store_ops, void *p_user_data);608609// This is a cache and it's never freed, it ensures610// IDs for a given format are always unique.611RBMap<FramebufferFormatKey, FramebufferFormatID> framebuffer_format_cache;612struct FramebufferFormat {613const RBMap<FramebufferFormatKey, FramebufferFormatID>::Element *E;614RDD::RenderPassID render_pass; // Here for constructing shaders, never used, see section (7.2. Render Pass Compatibility from Vulkan spec).615Vector<TextureSamples> pass_samples;616uint32_t view_count = 1; // Number of views.617};618619HashMap<FramebufferFormatID, FramebufferFormat> framebuffer_formats;620621struct Framebuffer {622RenderingDevice *rendering_device = nullptr;623FramebufferFormatID format_id;624uint32_t storage_mask = 0;625Vector<RID> texture_ids;626InvalidationCallback invalidated_callback = nullptr;627void *invalidated_callback_userdata = nullptr;628RDG::FramebufferCache *framebuffer_cache = nullptr;629Size2 size;630uint32_t view_count;631};632633RID_Owner<Framebuffer, true> framebuffer_owner;634635public:636// This ID is warranted to be unique for the same formats, does not need to be freed637FramebufferFormatID framebuffer_format_create(const Vector<AttachmentFormat> &p_format, uint32_t p_view_count = 1, int32_t p_vrs_attachment = -1);638FramebufferFormatID framebuffer_format_create_multipass(const Vector<AttachmentFormat> &p_attachments, const Vector<FramebufferPass> &p_passes, uint32_t p_view_count = 1, int32_t p_vrs_attachment = -1);639FramebufferFormatID framebuffer_format_create_empty(TextureSamples p_samples = TEXTURE_SAMPLES_1);640TextureSamples framebuffer_format_get_texture_samples(FramebufferFormatID p_format, uint32_t p_pass = 0);641642RID framebuffer_create(const Vector<RID> &p_texture_attachments, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1);643RID framebuffer_create_multipass(const Vector<RID> &p_texture_attachments, const Vector<FramebufferPass> &p_passes, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1);644RID framebuffer_create_empty(const Size2i &p_size, TextureSamples p_samples = TEXTURE_SAMPLES_1, FramebufferFormatID p_format_check = INVALID_ID);645bool framebuffer_is_valid(RID p_framebuffer) const;646void framebuffer_set_invalidation_callback(RID p_framebuffer, InvalidationCallback p_callback, void *p_userdata);647648FramebufferFormatID framebuffer_get_format(RID p_framebuffer);649Size2 framebuffer_get_size(RID p_framebuffer);650651/*****************/652/**** SAMPLER ****/653/*****************/654private:655RID_Owner<RDD::SamplerID, true> sampler_owner;656657public:658RID sampler_create(const SamplerState &p_state);659bool sampler_is_format_supported_for_filter(DataFormat p_format, SamplerFilter p_sampler_filter) const;660661/**********************/662/**** VERTEX ARRAY ****/663/**********************/664665typedef int64_t VertexFormatID;666667private:668// Vertex buffers in Vulkan are similar to how669// they work in OpenGL, except that instead of670// an attribute index, there is a buffer binding671// index (for binding the buffers in real-time)672// and a location index (what is used in the shader).673//674// This mapping is done here internally, and it's not675// exposed.676677RID_Owner<Buffer, true> vertex_buffer_owner;678679struct VertexDescriptionKey {680Vector<VertexAttribute> vertex_formats;681682bool operator==(const VertexDescriptionKey &p_key) const {683int vdc = vertex_formats.size();684int vdck = p_key.vertex_formats.size();685686if (vdc != vdck) {687return false;688} else {689const VertexAttribute *a_ptr = vertex_formats.ptr();690const VertexAttribute *b_ptr = p_key.vertex_formats.ptr();691for (int i = 0; i < vdc; i++) {692const VertexAttribute &a = a_ptr[i];693const VertexAttribute &b = b_ptr[i];694695if (a.location != b.location) {696return false;697}698if (a.offset != b.offset) {699return false;700}701if (a.format != b.format) {702return false;703}704if (a.stride != b.stride) {705return false;706}707if (a.frequency != b.frequency) {708return false;709}710}711return true; // They are equal.712}713}714715uint32_t hash() const {716int vdc = vertex_formats.size();717uint32_t h = hash_murmur3_one_32(vdc);718const VertexAttribute *ptr = vertex_formats.ptr();719for (int i = 0; i < vdc; i++) {720const VertexAttribute &vd = ptr[i];721h = hash_murmur3_one_32(vd.location, h);722h = hash_murmur3_one_32(vd.offset, h);723h = hash_murmur3_one_32(vd.format, h);724h = hash_murmur3_one_32(vd.stride, h);725h = hash_murmur3_one_32(vd.frequency, h);726}727return hash_fmix32(h);728}729};730731struct VertexDescriptionHash {732static _FORCE_INLINE_ uint32_t hash(const VertexDescriptionKey &p_key) {733return p_key.hash();734}735};736737// This is a cache and it's never freed, it ensures that738// ID used for a specific format always remain the same.739HashMap<VertexDescriptionKey, VertexFormatID, VertexDescriptionHash> vertex_format_cache;740741struct VertexDescriptionCache {742Vector<VertexAttribute> vertex_formats;743RDD::VertexFormatID driver_id;744};745746HashMap<VertexFormatID, VertexDescriptionCache> vertex_formats;747748struct VertexArray {749RID buffer;750VertexFormatID description;751int vertex_count = 0;752uint32_t max_instances_allowed = 0;753754Vector<RDD::BufferID> buffers; // Not owned, just referenced.755Vector<RDG::ResourceTracker *> draw_trackers; // Not owned, just referenced.756Vector<uint64_t> offsets;757Vector<int32_t> transfer_worker_indices;758Vector<uint64_t> transfer_worker_operations;759HashSet<RID> untracked_buffers;760};761762RID_Owner<VertexArray, true> vertex_array_owner;763764struct IndexBuffer : public Buffer {765uint32_t max_index = 0; // Used for validation.766uint32_t index_count = 0;767IndexBufferFormat format = INDEX_BUFFER_FORMAT_UINT16;768bool supports_restart_indices = false;769};770771RID_Owner<IndexBuffer, true> index_buffer_owner;772773struct IndexArray {774uint32_t max_index = 0; // Remember the maximum index here too, for validation.775RDD::BufferID driver_id; // Not owned, inherited from index buffer.776RDG::ResourceTracker *draw_tracker = nullptr; // Not owned, inherited from index buffer.777uint32_t offset = 0;778uint32_t indices = 0;779IndexBufferFormat format = INDEX_BUFFER_FORMAT_UINT16;780bool supports_restart_indices = false;781int32_t transfer_worker_index = -1;782uint64_t transfer_worker_operation = 0;783};784785RID_Owner<IndexArray, true> index_array_owner;786787public:788enum BufferCreationBits {789BUFFER_CREATION_DEVICE_ADDRESS_BIT = (1 << 0),790BUFFER_CREATION_AS_STORAGE_BIT = (1 << 1),791};792793enum StorageBufferUsage {794STORAGE_BUFFER_USAGE_DISPATCH_INDIRECT = (1 << 0),795};796797RID vertex_buffer_create(uint32_t p_size_bytes, Span<uint8_t> p_data = {}, BitField<BufferCreationBits> p_creation_bits = 0);798RID _vertex_buffer_create(uint32_t p_size_bytes, const Vector<uint8_t> &p_data, BitField<BufferCreationBits> p_creation_bits = 0) {799return vertex_buffer_create(p_size_bytes, p_data, p_creation_bits);800}801802// This ID is warranted to be unique for the same formats, does not need to be freed803VertexFormatID vertex_format_create(const Vector<VertexAttribute> &p_vertex_descriptions);804RID vertex_array_create(uint32_t p_vertex_count, VertexFormatID p_vertex_format, const Vector<RID> &p_src_buffers, const Vector<uint64_t> &p_offsets = Vector<uint64_t>());805806RID index_buffer_create(uint32_t p_index_count, IndexBufferFormat p_format, Span<uint8_t> p_data = {}, bool p_use_restart_indices = false, BitField<BufferCreationBits> p_creation_bits = 0);807RID _index_buffer_create(uint32_t p_index_count, IndexBufferFormat p_format, const Vector<uint8_t> &p_data, bool p_use_restart_indices = false, BitField<BufferCreationBits> p_creation_bits = 0) {808return index_buffer_create(p_index_count, p_format, p_data, p_use_restart_indices, p_creation_bits);809}810811RID index_array_create(RID p_index_buffer, uint32_t p_index_offset, uint32_t p_index_count);812813/****************/814/**** SHADER ****/815/****************/816817// Some APIs (e.g., Vulkan) specifies a really complex behavior for the application818// in order to tell when descriptor sets need to be re-bound (or not).819// "When binding a descriptor set (see Descriptor Set Binding) to set820// number N, if the previously bound descriptor sets for sets zero821// through N-1 were all bound using compatible pipeline layouts,822// then performing this binding does not disturb any of the lower numbered sets.823// If, additionally, the previous bound descriptor set for set N was824// bound using a pipeline layout compatible for set N, then the bindings825// in sets numbered greater than N are also not disturbed."826// As a result, we need to figure out quickly when something is no longer "compatible".827// in order to avoid costly rebinds.828829private:830struct UniformSetFormat {831Vector<ShaderUniform> uniforms;832833_FORCE_INLINE_ bool operator<(const UniformSetFormat &p_other) const {834if (uniforms.size() != p_other.uniforms.size()) {835return uniforms.size() < p_other.uniforms.size();836}837for (int i = 0; i < uniforms.size(); i++) {838if (uniforms[i] < p_other.uniforms[i]) {839return true;840} else if (p_other.uniforms[i] < uniforms[i]) {841return false;842}843}844return false;845}846};847848// Always grows, never shrinks, ensuring unique IDs, but we assume849// the amount of formats will never be a problem, as the amount of shaders850// in a game is limited.851RBMap<UniformSetFormat, uint32_t> uniform_set_format_cache;852853// Shaders in Vulkan are just pretty much854// precompiled blocks of SPIR-V bytecode. They855// are most likely not really compiled to host856// assembly until a pipeline is created.857//858// When supplying the shaders, this implementation859// will use the reflection abilities of glslang to860// understand and cache everything required to861// create and use the descriptor sets (Vulkan's862// biggest pain).863//864// Additionally, hashes are created for every set865// to do quick validation and ensuring the user866// does not submit something invalid.867868struct Shader : public ShaderReflection {869String name; // Used for debug.870RDD::ShaderID driver_id;871uint32_t layout_hash = 0;872BitField<RDD::PipelineStageBits> stage_bits = {};873Vector<uint32_t> set_formats;874};875876String _shader_uniform_debug(RID p_shader, int p_set = -1);877878RID_Owner<Shader, true> shader_owner;879880#ifndef DISABLE_DEPRECATED881public:882enum BarrierMask {883BARRIER_MASK_VERTEX = 1,884BARRIER_MASK_FRAGMENT = 8,885BARRIER_MASK_COMPUTE = 2,886BARRIER_MASK_TRANSFER = 4,887888BARRIER_MASK_RASTER = BARRIER_MASK_VERTEX | BARRIER_MASK_FRAGMENT, // 9,889BARRIER_MASK_ALL_BARRIERS = 0x7FFF, // all flags set890BARRIER_MASK_NO_BARRIER = 0x8000,891};892893enum InitialAction {894INITIAL_ACTION_LOAD,895INITIAL_ACTION_CLEAR,896INITIAL_ACTION_DISCARD,897INITIAL_ACTION_MAX,898INITIAL_ACTION_CLEAR_REGION = INITIAL_ACTION_CLEAR,899INITIAL_ACTION_CLEAR_REGION_CONTINUE = INITIAL_ACTION_CLEAR,900INITIAL_ACTION_KEEP = INITIAL_ACTION_LOAD,901INITIAL_ACTION_DROP = INITIAL_ACTION_DISCARD,902INITIAL_ACTION_CONTINUE = INITIAL_ACTION_LOAD,903};904905enum FinalAction {906FINAL_ACTION_STORE,907FINAL_ACTION_DISCARD,908FINAL_ACTION_MAX,909FINAL_ACTION_READ = FINAL_ACTION_STORE,910FINAL_ACTION_CONTINUE = FINAL_ACTION_STORE,911};912913void barrier(BitField<BarrierMask> p_from = BARRIER_MASK_ALL_BARRIERS, BitField<BarrierMask> p_to = BARRIER_MASK_ALL_BARRIERS);914void full_barrier();915void draw_command_insert_label(String p_label_name, const Color &p_color = Color(1, 1, 1, 1));916Error draw_list_begin_split(RID p_framebuffer, uint32_t p_splits, DrawListID *r_split_ids, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2(), const Vector<RID> &p_storage_textures = Vector<RID>());917Error draw_list_switch_to_next_pass_split(uint32_t p_splits, DrawListID *r_split_ids);918Vector<int64_t> _draw_list_begin_split(RID p_framebuffer, uint32_t p_splits, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2(), const TypedArray<RID> &p_storage_textures = TypedArray<RID>());919Vector<int64_t> _draw_list_switch_to_next_pass_split(uint32_t p_splits);920921private:922void _draw_list_end_bind_compat_81356(BitField<BarrierMask> p_post_barrier);923void _compute_list_end_bind_compat_81356(BitField<BarrierMask> p_post_barrier);924void _barrier_bind_compat_81356(BitField<BarrierMask> p_from, BitField<BarrierMask> p_to);925926void _draw_list_end_bind_compat_84976(BitField<BarrierMask> p_post_barrier);927void _compute_list_end_bind_compat_84976(BitField<BarrierMask> p_post_barrier);928InitialAction _convert_initial_action_84976(InitialAction p_old_initial_action);929FinalAction _convert_final_action_84976(FinalAction p_old_final_action);930DrawListID _draw_list_begin_bind_compat_84976(RID p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values, float p_clear_depth, uint32_t p_clear_stencil, const Rect2 &p_region, const TypedArray<RID> &p_storage_textures);931ComputeListID _compute_list_begin_bind_compat_84976(bool p_allow_draw_overlap);932Error _buffer_update_bind_compat_84976(RID p_buffer, uint32_t p_offset, uint32_t p_size, const Vector<uint8_t> &p_data, BitField<BarrierMask> p_post_barrier);933Error _buffer_clear_bind_compat_84976(RID p_buffer, uint32_t p_offset, uint32_t p_size, BitField<BarrierMask> p_post_barrier);934Error _texture_update_bind_compat_84976(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, BitField<BarrierMask> p_post_barrier);935Error _texture_copy_bind_compat_84976(RID p_from_texture, RID p_to_texture, const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_size, uint32_t p_src_mipmap, uint32_t p_dst_mipmap, uint32_t p_src_layer, uint32_t p_dst_layer, BitField<BarrierMask> p_post_barrier);936Error _texture_clear_bind_compat_84976(RID p_texture, const Color &p_color, uint32_t p_base_mipmap, uint32_t p_mipmaps, uint32_t p_base_layer, uint32_t p_layers, BitField<BarrierMask> p_post_barrier);937Error _texture_resolve_multisample_bind_compat_84976(RID p_from_texture, RID p_to_texture, BitField<BarrierMask> p_post_barrier);938939FramebufferFormatID _screen_get_framebuffer_format_bind_compat_87340() const;940941DrawListID _draw_list_begin_bind_compat_90993(RID p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values, float p_clear_depth, uint32_t p_clear_stencil, const Rect2 &p_region);942943DrawListID _draw_list_begin_bind_compat_98670(RID p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values, float p_clear_depth, uint32_t p_clear_stencil, const Rect2 &p_region, uint32_t p_breadcrumb);944945RID _uniform_buffer_create_bind_compat_101561(uint32_t p_size_bytes, const Vector<uint8_t> &p_data);946RID _vertex_buffer_create_bind_compat_101561(uint32_t p_size_bytes, const Vector<uint8_t> &p_data, bool p_use_as_storage);947RID _index_buffer_create_bind_compat_101561(uint32_t p_size_indices, IndexBufferFormat p_format, const Vector<uint8_t> &p_data, bool p_use_restart_indices);948RID _storage_buffer_create_bind_compat_101561(uint32_t p_size, const Vector<uint8_t> &p_data, BitField<StorageBufferUsage> p_usage);949#endif950951public:952RenderingDeviceDriver *get_device_driver() const { return driver; }953RenderingContextDriver *get_context_driver() const { return context; }954955const RDD::Capabilities &get_device_capabilities() const { return driver->get_capabilities(); }956957bool has_feature(const Features p_feature) const;958959Vector<uint8_t> shader_compile_spirv_from_source(ShaderStage p_stage, const String &p_source_code, ShaderLanguage p_language = SHADER_LANGUAGE_GLSL, String *r_error = nullptr, bool p_allow_cache = true);960Vector<uint8_t> shader_compile_binary_from_spirv(const Vector<ShaderStageSPIRVData> &p_spirv, const String &p_shader_name = "");961962RID shader_create_from_spirv(const Vector<ShaderStageSPIRVData> &p_spirv, const String &p_shader_name = "");963RID shader_create_from_bytecode(const Vector<uint8_t> &p_shader_binary, RID p_placeholder = RID());964RID shader_create_placeholder();965void shader_destroy_modules(RID p_shader);966967uint64_t shader_get_vertex_input_attribute_mask(RID p_shader);968969/******************/970/**** UNIFORMS ****/971/******************/972String get_perf_report() const;973974/*****************/975/**** BUFFERS ****/976/*****************/977978RID uniform_buffer_create(uint32_t p_size_bytes, Span<uint8_t> p_data = {}, BitField<BufferCreationBits> p_creation_bits = 0);979RID _uniform_buffer_create(uint32_t p_size_bytes, const Vector<uint8_t> &p_data, BitField<BufferCreationBits> p_creation_bits = 0) {980return uniform_buffer_create(p_size_bytes, p_data, p_creation_bits);981}982983RID storage_buffer_create(uint32_t p_size_bytes, Span<uint8_t> p_data = {}, BitField<StorageBufferUsage> p_usage = 0, BitField<BufferCreationBits> p_creation_bits = 0);984RID _storage_buffer_create(uint32_t p_size_bytes, const Vector<uint8_t> &p_data, BitField<StorageBufferUsage> p_usage = 0, BitField<BufferCreationBits> p_creation_bits = 0) {985return storage_buffer_create(p_size_bytes, p_data, p_usage, p_creation_bits);986}987988RID texture_buffer_create(uint32_t p_size_elements, DataFormat p_format, Span<uint8_t> p_data = {});989RID _texture_buffer_create(uint32_t p_size_elements, DataFormat p_format, const Vector<uint8_t> &p_data) {990return texture_buffer_create(p_size_elements, p_format, p_data);991}992993struct Uniform {994UniformType uniform_type = UNIFORM_TYPE_IMAGE;995uint32_t binding = 0; // Binding index as specified in shader.996// This flag specifies that this is an immutable sampler to be set when creating pipeline layout.997bool immutable_sampler = false;998999private:1000// In most cases only one ID is provided per binding, so avoid allocating memory unnecessarily for performance.1001RID id; // If only one is provided, this is used.1002Vector<RID> ids; // If multiple ones are provided, this is used instead.10031004public:1005_FORCE_INLINE_ uint32_t get_id_count() const {1006return (id.is_valid() ? 1 : ids.size());1007}10081009_FORCE_INLINE_ RID get_id(uint32_t p_idx) const {1010if (id.is_valid()) {1011ERR_FAIL_COND_V(p_idx != 0, RID());1012return id;1013} else {1014return ids[p_idx];1015}1016}1017_FORCE_INLINE_ void set_id(uint32_t p_idx, RID p_id) {1018if (id.is_valid()) {1019ERR_FAIL_COND(p_idx != 0);1020id = p_id;1021} else {1022ids.write[p_idx] = p_id;1023}1024}10251026_FORCE_INLINE_ void append_id(RID p_id) {1027if (ids.is_empty()) {1028if (id == RID()) {1029id = p_id;1030} else {1031ids.push_back(id);1032ids.push_back(p_id);1033id = RID();1034}1035} else {1036ids.push_back(p_id);1037}1038}10391040_FORCE_INLINE_ void clear_ids() {1041id = RID();1042ids.clear();1043}10441045_FORCE_INLINE_ Uniform(UniformType p_type, int p_binding, RID p_id) {1046uniform_type = p_type;1047binding = p_binding;1048id = p_id;1049}1050_FORCE_INLINE_ Uniform(UniformType p_type, int p_binding, const Vector<RID> &p_ids) {1051uniform_type = p_type;1052binding = p_binding;1053ids = p_ids;1054}1055_FORCE_INLINE_ Uniform() = default;1056};10571058typedef Uniform PipelineImmutableSampler;1059RID shader_create_from_bytecode_with_samplers(const Vector<uint8_t> &p_shader_binary, RID p_placeholder = RID(), const Vector<PipelineImmutableSampler> &p_immutable_samplers = Vector<PipelineImmutableSampler>());10601061private:1062static const uint32_t MAX_UNIFORM_SETS = 16;1063static const uint32_t MAX_PUSH_CONSTANT_SIZE = 128;10641065// This structure contains the descriptor set. They _need_ to be allocated1066// for a shader (and will be erased when this shader is erased), but should1067// work for other shaders as long as the hash matches. This covers using1068// them in shader variants.1069//1070// Keep also in mind that you can share buffers between descriptor sets, so1071// the above restriction is not too serious.10721073struct UniformSet {1074uint32_t format = 0;1075RID shader_id;1076uint32_t shader_set = 0;1077RDD::UniformSetID driver_id;1078struct AttachableTexture {1079uint32_t bind = 0;1080RID texture;1081};10821083struct SharedTexture {1084uint32_t writing = 0;1085RID texture;1086};10871088LocalVector<AttachableTexture> attachable_textures; // Used for validation.1089Vector<RDG::ResourceTracker *> draw_trackers;1090Vector<RDG::ResourceUsage> draw_trackers_usage;1091HashMap<RID, RDG::ResourceUsage> untracked_usage;1092LocalVector<SharedTexture> shared_textures_to_update;1093InvalidationCallback invalidated_callback = nullptr;1094void *invalidated_callback_userdata = nullptr;1095};10961097RID_Owner<UniformSet, true> uniform_set_owner;10981099void _uniform_set_update_shared(UniformSet *p_uniform_set);11001101public:1102/** Bake a set of uniforms that can be bound at runtime with the given shader.1103* @remark Setting p_linear_pool = true while keeping the RID around for longer than the current frame will result in undefined behavior.1104* @param p_uniforms The uniforms to bake into a set.1105* @param p_shader The shader you intend to bind these uniforms with.1106* @param p_set_index The set. Should be in range [0; 4)1107* The value 4 comes from physical_device_properties.limits.maxBoundDescriptorSets. Vulkan only guarantees maxBoundDescriptorSets >= 4 (== 4 is very common on Mobile).1108* @param p_linear_pool If you call this function every frame (and free the returned RID within the same frame!), set it to true for better performance.1109* If you plan on keeping the return value around for more than one frame (e.g. Sets that are created once and reused forever) you MUST set it to false.1110* @return Baked descriptor set.1111*/1112RID uniform_set_create(const VectorView<Uniform> &p_uniforms, RID p_shader, uint32_t p_shader_set, bool p_linear_pool = false);1113bool uniform_set_is_valid(RID p_uniform_set);1114void uniform_set_set_invalidation_callback(RID p_uniform_set, InvalidationCallback p_callback, void *p_userdata);11151116bool uniform_sets_have_linear_pools() const;11171118/*******************/1119/**** PIPELINES ****/1120/*******************/11211122// Render pipeline contains ALL the1123// information required for drawing.1124// This includes all the rasterizer state1125// as well as shader used, framebuffer format,1126// etc.1127// While the pipeline is just a single object1128// (VkPipeline) a lot of values are also saved1129// here to do validation (vulkan does none by1130// default) and warn the user if something1131// was not supplied as intended.1132private:1133struct RenderPipeline {1134// Cached values for validation.1135#ifdef DEBUG_ENABLED1136struct Validation {1137FramebufferFormatID framebuffer_format;1138uint32_t render_pass = 0;1139uint32_t dynamic_state = 0;1140VertexFormatID vertex_format;1141bool uses_restart_indices = false;1142uint32_t primitive_minimum = 0;1143uint32_t primitive_divisor = 0;1144} validation;1145#endif1146// Actual pipeline.1147RID shader;1148RDD::ShaderID shader_driver_id;1149uint32_t shader_layout_hash = 0;1150Vector<uint32_t> set_formats;1151RDD::PipelineID driver_id;1152BitField<RDD::PipelineStageBits> stage_bits = {};1153uint32_t push_constant_size = 0;1154};11551156RID_Owner<RenderPipeline, true> render_pipeline_owner;11571158bool pipeline_cache_enabled = false;1159size_t pipeline_cache_size = 0;1160String pipeline_cache_file_path;1161WorkerThreadPool::TaskID pipeline_cache_save_task = WorkerThreadPool::INVALID_TASK_ID;11621163Vector<uint8_t> _load_pipeline_cache();1164void _update_pipeline_cache(bool p_closing = false);1165static void _save_pipeline_cache(void *p_data);11661167struct ComputePipeline {1168RID shader;1169RDD::ShaderID shader_driver_id;1170uint32_t shader_layout_hash = 0;1171Vector<uint32_t> set_formats;1172RDD::PipelineID driver_id;1173uint32_t push_constant_size = 0;1174uint32_t local_group_size[3] = { 0, 0, 0 };1175};11761177RID_Owner<ComputePipeline, true> compute_pipeline_owner;11781179public:1180RID render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const PipelineRasterizationState &p_rasterization_state, const PipelineMultisampleState &p_multisample_state, const PipelineDepthStencilState &p_depth_stencil_state, const PipelineColorBlendState &p_blend_state, BitField<PipelineDynamicStateFlags> p_dynamic_state_flags = 0, uint32_t p_for_render_pass = 0, const Vector<PipelineSpecializationConstant> &p_specialization_constants = Vector<PipelineSpecializationConstant>());1181bool render_pipeline_is_valid(RID p_pipeline);11821183RID compute_pipeline_create(RID p_shader, const Vector<PipelineSpecializationConstant> &p_specialization_constants = Vector<PipelineSpecializationConstant>());1184bool compute_pipeline_is_valid(RID p_pipeline);11851186private:1187/****************/1188/**** SCREEN ****/1189/****************/1190HashMap<DisplayServer::WindowID, RDD::SwapChainID> screen_swap_chains;1191HashMap<DisplayServer::WindowID, RDD::FramebufferID> screen_framebuffers;11921193uint32_t _get_swap_chain_desired_count() const;11941195public:1196Error screen_create(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID);1197Error screen_prepare_for_drawing(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID);1198int screen_get_width(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID) const;1199int screen_get_height(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID) const;1200int screen_get_pre_rotation_degrees(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID) const;1201FramebufferFormatID screen_get_framebuffer_format(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID) const;1202Error screen_free(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID);12031204/*************************/1205/**** DRAW LISTS (II) ****/1206/*************************/12071208private:1209// Draw list contains both the command buffer1210// used for drawing as well as a LOT of1211// information used for validation. This1212// validation is cheap so most of it can1213// also run in release builds.12141215struct DrawList {1216Rect2i viewport;1217bool active = false;12181219struct SetState {1220uint32_t pipeline_expected_format = 0;1221uint32_t uniform_set_format = 0;1222RDD::UniformSetID uniform_set_driver_id;1223RID uniform_set;1224bool bound = false;1225};12261227struct State {1228SetState sets[MAX_UNIFORM_SETS];1229uint32_t set_count = 0;1230RID pipeline;1231RID pipeline_shader;1232RDD::ShaderID pipeline_shader_driver_id;1233uint32_t pipeline_shader_layout_hash = 0;1234uint32_t pipeline_push_constant_size = 0;1235RID vertex_array;1236RID index_array;1237uint32_t draw_count = 0;1238} state;12391240#ifdef DEBUG_ENABLED1241struct Validation {1242// Actual render pass values.1243uint32_t dynamic_state = 0;1244VertexFormatID vertex_format = INVALID_ID;1245uint32_t vertex_array_size = 0;1246uint32_t vertex_max_instances_allowed = 0xFFFFFFFF;1247bool index_buffer_uses_restart_indices = false;1248uint32_t index_array_count = 0;1249uint32_t index_array_max_index = 0;1250Vector<uint32_t> set_formats;1251Vector<bool> set_bound;1252Vector<RID> set_rids;1253// Last pipeline set values.1254bool pipeline_active = false;1255uint32_t pipeline_dynamic_state = 0;1256VertexFormatID pipeline_vertex_format = INVALID_ID;1257RID pipeline_shader;1258bool pipeline_uses_restart_indices = false;1259uint32_t pipeline_primitive_divisor = 0;1260uint32_t pipeline_primitive_minimum = 0;1261uint32_t pipeline_push_constant_size = 0;1262bool pipeline_push_constant_supplied = false;1263} validation;1264#else1265struct Validation {1266uint32_t vertex_array_size = 0;1267uint32_t index_array_count = 0;1268} validation;1269#endif1270};12711272DrawList draw_list;1273uint32_t draw_list_subpass_count = 0;1274#ifdef DEBUG_ENABLED1275FramebufferFormatID draw_list_framebuffer_format = INVALID_ID;1276#endif1277uint32_t draw_list_current_subpass = 0;12781279LocalVector<RID> draw_list_bound_textures;12801281void _draw_list_start(const Rect2i &p_viewport);1282void _draw_list_end(Rect2i *r_last_viewport = nullptr);12831284public:1285enum DrawFlags {1286DRAW_DEFAULT_ALL = 0,1287DRAW_CLEAR_COLOR_0 = (1 << 0),1288DRAW_CLEAR_COLOR_1 = (1 << 1),1289DRAW_CLEAR_COLOR_2 = (1 << 2),1290DRAW_CLEAR_COLOR_3 = (1 << 3),1291DRAW_CLEAR_COLOR_4 = (1 << 4),1292DRAW_CLEAR_COLOR_5 = (1 << 5),1293DRAW_CLEAR_COLOR_6 = (1 << 6),1294DRAW_CLEAR_COLOR_7 = (1 << 7),1295DRAW_CLEAR_COLOR_MASK = 0xFF,1296DRAW_CLEAR_COLOR_ALL = DRAW_CLEAR_COLOR_MASK,1297DRAW_IGNORE_COLOR_0 = (1 << 8),1298DRAW_IGNORE_COLOR_1 = (1 << 9),1299DRAW_IGNORE_COLOR_2 = (1 << 10),1300DRAW_IGNORE_COLOR_3 = (1 << 11),1301DRAW_IGNORE_COLOR_4 = (1 << 12),1302DRAW_IGNORE_COLOR_5 = (1 << 13),1303DRAW_IGNORE_COLOR_6 = (1 << 14),1304DRAW_IGNORE_COLOR_7 = (1 << 15),1305DRAW_IGNORE_COLOR_MASK = 0xFF00,1306DRAW_IGNORE_COLOR_ALL = DRAW_IGNORE_COLOR_MASK,1307DRAW_CLEAR_DEPTH = (1 << 16),1308DRAW_IGNORE_DEPTH = (1 << 17),1309DRAW_CLEAR_STENCIL = (1 << 18),1310DRAW_IGNORE_STENCIL = (1 << 19),1311DRAW_CLEAR_ALL = DRAW_CLEAR_COLOR_ALL | DRAW_CLEAR_DEPTH | DRAW_CLEAR_STENCIL,1312DRAW_IGNORE_ALL = DRAW_IGNORE_COLOR_ALL | DRAW_IGNORE_DEPTH | DRAW_IGNORE_STENCIL1313};13141315DrawListID draw_list_begin_for_screen(DisplayServer::WindowID p_screen = 0, const Color &p_clear_color = Color());1316DrawListID draw_list_begin(RID p_framebuffer, BitField<DrawFlags> p_draw_flags = DRAW_DEFAULT_ALL, VectorView<Color> p_clear_color_values = VectorView<Color>(), float p_clear_depth_value = 1.0f, uint32_t p_clear_stencil_value = 0, const Rect2 &p_region = Rect2(), uint32_t p_breadcrumb = 0);1317DrawListID _draw_list_begin_bind(RID p_framebuffer, BitField<DrawFlags> p_draw_flags = DRAW_DEFAULT_ALL, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth_value = 1.0f, uint32_t p_clear_stencil_value = 0, const Rect2 &p_region = Rect2(), uint32_t p_breadcrumb = 0);13181319void draw_list_set_blend_constants(DrawListID p_list, const Color &p_color);1320void draw_list_bind_render_pipeline(DrawListID p_list, RID p_render_pipeline);1321void draw_list_bind_uniform_set(DrawListID p_list, RID p_uniform_set, uint32_t p_index);1322void draw_list_bind_vertex_array(DrawListID p_list, RID p_vertex_array);1323void draw_list_bind_index_array(DrawListID p_list, RID p_index_array);1324void draw_list_set_line_width(DrawListID p_list, float p_width);1325void draw_list_set_push_constant(DrawListID p_list, const void *p_data, uint32_t p_data_size);13261327void draw_list_draw(DrawListID p_list, bool p_use_indices, uint32_t p_instances = 1, uint32_t p_procedural_vertices = 0);1328void draw_list_draw_indirect(DrawListID p_list, bool p_use_indices, RID p_buffer, uint32_t p_offset = 0, uint32_t p_draw_count = 1, uint32_t p_stride = 0);13291330void draw_list_set_viewport(DrawListID p_list, const Rect2 &p_rect);1331void draw_list_enable_scissor(DrawListID p_list, const Rect2 &p_rect);1332void draw_list_disable_scissor(DrawListID p_list);13331334uint32_t draw_list_get_current_pass();1335DrawListID draw_list_switch_to_next_pass();13361337void draw_list_end();13381339private:1340/***********************/1341/**** COMPUTE LISTS ****/1342/***********************/13431344struct ComputeList {1345bool active = false;1346struct SetState {1347uint32_t pipeline_expected_format = 0;1348uint32_t uniform_set_format = 0;1349RDD::UniformSetID uniform_set_driver_id;1350RID uniform_set;1351bool bound = false;1352};13531354struct State {1355SetState sets[MAX_UNIFORM_SETS];1356uint32_t set_count = 0;1357RID pipeline;1358RID pipeline_shader;1359RDD::ShaderID pipeline_shader_driver_id;1360uint32_t pipeline_shader_layout_hash = 0;1361uint32_t local_group_size[3] = { 0, 0, 0 };1362uint8_t push_constant_data[MAX_PUSH_CONSTANT_SIZE] = {};1363uint32_t push_constant_size = 0;1364uint32_t dispatch_count = 0;1365} state;13661367#ifdef DEBUG_ENABLED1368struct Validation {1369Vector<uint32_t> set_formats;1370Vector<bool> set_bound;1371Vector<RID> set_rids;1372// Last pipeline set values.1373bool pipeline_active = false;1374RID pipeline_shader;1375uint32_t invalid_set_from = 0;1376uint32_t pipeline_push_constant_size = 0;1377bool pipeline_push_constant_supplied = false;1378} validation;1379#endif1380};13811382ComputeList compute_list;1383ComputeList::State compute_list_barrier_state;13841385public:1386ComputeListID compute_list_begin();1387void compute_list_bind_compute_pipeline(ComputeListID p_list, RID p_compute_pipeline);1388void compute_list_bind_uniform_set(ComputeListID p_list, RID p_uniform_set, uint32_t p_index);1389void compute_list_set_push_constant(ComputeListID p_list, const void *p_data, uint32_t p_data_size);1390void compute_list_dispatch(ComputeListID p_list, uint32_t p_x_groups, uint32_t p_y_groups, uint32_t p_z_groups);1391void compute_list_dispatch_threads(ComputeListID p_list, uint32_t p_x_threads, uint32_t p_y_threads, uint32_t p_z_threads);1392void compute_list_dispatch_indirect(ComputeListID p_list, RID p_buffer, uint32_t p_offset);1393void compute_list_add_barrier(ComputeListID p_list);13941395void compute_list_end();13961397private:1398/*************************/1399/**** TRANSFER WORKER ****/1400/*************************/14011402struct TransferWorker {1403uint32_t index = 0;1404RDD::BufferID staging_buffer;1405uint32_t max_transfer_size = 0;1406uint32_t staging_buffer_size_in_use = 0;1407uint32_t staging_buffer_size_allocated = 0;1408RDD::CommandBufferID command_buffer;1409RDD::CommandPoolID command_pool;1410RDD::FenceID command_fence;1411LocalVector<RDD::TextureBarrier> texture_barriers;1412bool recording = false;1413bool submitted = false;1414BinaryMutex thread_mutex;1415uint64_t operations_processed = 0;1416uint64_t operations_submitted = 0;1417uint64_t operations_counter = 0;1418BinaryMutex operations_mutex;1419};14201421LocalVector<TransferWorker *> transfer_worker_pool;1422uint32_t transfer_worker_pool_max_size = 1;1423LocalVector<uint64_t> transfer_worker_operation_used_by_draw;1424LocalVector<uint32_t> transfer_worker_pool_available_list;1425LocalVector<RDD::TextureBarrier> transfer_worker_pool_texture_barriers;1426BinaryMutex transfer_worker_pool_mutex;1427BinaryMutex transfer_worker_pool_texture_barriers_mutex;1428ConditionVariable transfer_worker_pool_condition;14291430TransferWorker *_acquire_transfer_worker(uint32_t p_transfer_size, uint32_t p_required_align, uint32_t &r_staging_offset);1431void _release_transfer_worker(TransferWorker *p_transfer_worker);1432void _end_transfer_worker(TransferWorker *p_transfer_worker);1433void _submit_transfer_worker(TransferWorker *p_transfer_worker, VectorView<RDD::SemaphoreID> p_signal_semaphores = VectorView<RDD::SemaphoreID>());1434void _wait_for_transfer_worker(TransferWorker *p_transfer_worker);1435void _flush_barriers_for_transfer_worker(TransferWorker *p_transfer_worker);1436void _check_transfer_worker_operation(uint32_t p_transfer_worker_index, uint64_t p_transfer_worker_operation);1437void _check_transfer_worker_buffer(Buffer *p_buffer);1438void _check_transfer_worker_texture(Texture *p_texture);1439void _check_transfer_worker_vertex_array(VertexArray *p_vertex_array);1440void _check_transfer_worker_index_array(IndexArray *p_index_array);1441void _submit_transfer_workers(RDD::CommandBufferID p_draw_command_buffer = RDD::CommandBufferID());1442void _submit_transfer_barriers(RDD::CommandBufferID p_draw_command_buffer);1443void _wait_for_transfer_workers();1444void _free_transfer_workers();14451446/***********************/1447/**** COMMAND GRAPH ****/1448/***********************/14491450bool _texture_make_mutable(Texture *p_texture, RID p_texture_id);1451bool _buffer_make_mutable(Buffer *p_buffer, RID p_buffer_id);1452bool _vertex_array_make_mutable(VertexArray *p_vertex_array, RID p_resource_id, RDG::ResourceTracker *p_resource_tracker);1453bool _index_array_make_mutable(IndexArray *p_index_array, RDG::ResourceTracker *p_resource_tracker);1454bool _uniform_set_make_mutable(UniformSet *p_uniform_set, RID p_resource_id, RDG::ResourceTracker *p_resource_tracker);1455bool _dependency_make_mutable(RID p_id, RID p_resource_id, RDG::ResourceTracker *p_resource_tracker);1456bool _dependencies_make_mutable_recursive(RID p_id, RDG::ResourceTracker *p_resource_tracker);1457bool _dependencies_make_mutable(RID p_id, RDG::ResourceTracker *p_resource_tracker);14581459RenderingDeviceGraph draw_graph;14601461/**************************/1462/**** QUEUE MANAGEMENT ****/1463/**************************/14641465RDD::CommandQueueFamilyID main_queue_family;1466RDD::CommandQueueFamilyID transfer_queue_family;1467RDD::CommandQueueFamilyID present_queue_family;1468RDD::CommandQueueID main_queue;1469RDD::CommandQueueID transfer_queue;1470RDD::CommandQueueID present_queue;14711472/**************************/1473/**** FRAME MANAGEMENT ****/1474/**************************/14751476// This is the frame structure. There are normally1477// 3 of these (used for triple buffering), or 21478// (double buffering). They are cycled constantly.1479//1480// It contains two command buffers, one that is1481// used internally for setting up (creating stuff)1482// and another used mostly for drawing.1483//1484// They also contains a list of things that need1485// to be disposed of when deleted, which can't1486// happen immediately due to the asynchronous1487// nature of the GPU. They will get deleted1488// when the frame is cycled.14891490struct Frame {1491// List in usage order, from last to free to first to free.1492List<Buffer> buffers_to_dispose_of;1493List<Texture> textures_to_dispose_of;1494List<Framebuffer> framebuffers_to_dispose_of;1495List<RDD::SamplerID> samplers_to_dispose_of;1496List<Shader> shaders_to_dispose_of;1497List<UniformSet> uniform_sets_to_dispose_of;1498List<RenderPipeline> render_pipelines_to_dispose_of;1499List<ComputePipeline> compute_pipelines_to_dispose_of;15001501// Pending asynchronous data transfer for buffers.1502LocalVector<RDD::BufferID> download_buffer_staging_buffers;1503LocalVector<RDD::BufferCopyRegion> download_buffer_copy_regions;1504LocalVector<BufferGetDataRequest> download_buffer_get_data_requests;15051506// Pending asynchronous data transfer for textures.1507LocalVector<RDD::BufferID> download_texture_staging_buffers;1508LocalVector<RDD::BufferTextureCopyRegion> download_buffer_texture_copy_regions;1509LocalVector<uint32_t> download_texture_mipmap_offsets;1510LocalVector<TextureGetDataRequest> download_texture_get_data_requests;15111512// The command pool used by the command buffer.1513RDD::CommandPoolID command_pool;15141515// The command buffer used by the main thread when recording the frame.1516RDD::CommandBufferID command_buffer;15171518// Signaled by the command buffer submission. Present must wait on this semaphore.1519RDD::SemaphoreID semaphore;15201521// Signaled by the command buffer submission. Must wait on this fence before beginning command recording for the frame.1522RDD::FenceID fence;1523bool fence_signaled = false;15241525// Semaphores the frame must wait on before executing the command buffer.1526LocalVector<RDD::SemaphoreID> semaphores_to_wait_on;15271528// Swap chains prepared for drawing during the frame that must be presented.1529LocalVector<RDD::SwapChainID> swap_chains_to_present;15301531// Semaphores the transfer workers can use to wait before rendering the frame.1532// This must have the same size of the transfer worker pool.1533TightLocalVector<RDD::SemaphoreID> transfer_worker_semaphores;15341535// Extra command buffer pool used for driver workarounds or to reduce GPU bubbles by1536// splitting the final render pass to the swapchain into its own cmd buffer.1537RDG::CommandBufferPool command_buffer_pool;15381539struct Timestamp {1540String description;1541uint64_t value = 0;1542};15431544RDD::QueryPoolID timestamp_pool;15451546TightLocalVector<String> timestamp_names;1547TightLocalVector<uint64_t> timestamp_cpu_values;1548uint32_t timestamp_count = 0;1549TightLocalVector<String> timestamp_result_names;1550TightLocalVector<uint64_t> timestamp_cpu_result_values;1551TightLocalVector<uint64_t> timestamp_result_values;1552uint32_t timestamp_result_count = 0;1553uint64_t index = 0;1554};15551556uint32_t max_timestamp_query_elements = 0;15571558int frame = 0;1559TightLocalVector<Frame> frames;1560uint64_t frames_drawn = 0;15611562// Whenever logic/physics request a graphics operation (not just deleting a resource) that requires1563// us to flush all graphics commands, we must set frames_pending_resources_for_processing = frames.size().1564// This is important for when the user requested for the logic loop to still be updated while1565// graphics should not (e.g. headless Multiplayer servers, minimized windows that need to still1566// process something on the background).1567uint32_t frames_pending_resources_for_processing = 0u;15681569public:1570bool has_pending_resources_for_processing() const { return frames_pending_resources_for_processing != 0u; }15711572private:1573void _free_pending_resources(int p_frame);15741575uint64_t texture_memory = 0;1576uint64_t buffer_memory = 0;15771578protected:1579void execute_chained_cmds(bool p_present_swap_chain,1580RenderingDeviceDriver::FenceID p_draw_fence,1581RenderingDeviceDriver::SemaphoreID p_dst_draw_semaphore_to_signal);15821583public:1584void _free_internal(RID p_id);1585void _begin_frame(bool p_presented = false);1586void _end_frame();1587void _execute_frame(bool p_present);1588void _stall_for_frame(uint32_t p_frame);1589void _stall_for_previous_frames();1590void _flush_and_stall_for_all_frames();15911592template <typename T>1593void _free_rids(T &p_owner, const char *p_type);15941595#ifdef DEV_ENABLED1596HashMap<RID, String> resource_names;1597#endif15981599public:1600Error initialize(RenderingContextDriver *p_context, DisplayServer::WindowID p_main_window = DisplayServer::INVALID_WINDOW_ID);1601void finalize();16021603void _set_max_fps(int p_max_fps);16041605void free(RID p_id);16061607/****************/1608/**** Timing ****/1609/****************/16101611void capture_timestamp(const String &p_name);1612uint32_t get_captured_timestamps_count() const;1613uint64_t get_captured_timestamps_frame() const;1614uint64_t get_captured_timestamp_gpu_time(uint32_t p_index) const;1615uint64_t get_captured_timestamp_cpu_time(uint32_t p_index) const;1616String get_captured_timestamp_name(uint32_t p_index) const;16171618/****************/1619/**** LIMITS ****/1620/****************/16211622uint64_t limit_get(Limit p_limit) const;16231624void swap_buffers(bool p_present);16251626uint32_t get_frame_delay() const;16271628void submit();1629void sync();16301631enum MemoryType {1632MEMORY_TEXTURES,1633MEMORY_BUFFERS,1634MEMORY_TOTAL1635};16361637uint64_t get_memory_usage(MemoryType p_type) const;16381639RenderingDevice *create_local_device();16401641void set_resource_name(RID p_id, const String &p_name);16421643void _draw_command_begin_label(String p_label_name, const Color &p_color = Color(1, 1, 1, 1));1644void draw_command_begin_label(const Span<char> p_label_name, const Color &p_color = Color(1, 1, 1, 1));1645void draw_command_end_label();16461647String get_device_vendor_name() const;1648String get_device_name() const;1649DeviceType get_device_type() const;1650String get_device_api_name() const;1651String get_device_api_version() const;1652String get_device_pipeline_cache_uuid() const;16531654bool is_composite_alpha_supported() const;16551656uint64_t get_driver_resource(DriverResource p_resource, RID p_rid = RID(), uint64_t p_index = 0);16571658String get_driver_and_device_memory_report() const;16591660String get_tracked_object_name(uint32_t p_type_index) const;1661uint64_t get_tracked_object_type_count() const;16621663uint64_t get_driver_total_memory() const;1664uint64_t get_driver_allocation_count() const;1665uint64_t get_driver_memory_by_object_type(uint32_t p_type) const;1666uint64_t get_driver_allocs_by_object_type(uint32_t p_type) const;16671668uint64_t get_device_total_memory() const;1669uint64_t get_device_allocation_count() const;1670uint64_t get_device_memory_by_object_type(uint32_t p_type) const;1671uint64_t get_device_allocs_by_object_type(uint32_t p_type) const;16721673static RenderingDevice *get_singleton();16741675void make_current();16761677RenderingDevice();1678~RenderingDevice();16791680private:1681/*****************/1682/**** BINDERS ****/1683/*****************/16841685RID _texture_create(const Ref<RDTextureFormat> &p_format, const Ref<RDTextureView> &p_view, const TypedArray<PackedByteArray> &p_data = Array());1686RID _texture_create_shared(const Ref<RDTextureView> &p_view, RID p_with_texture);1687RID _texture_create_shared_from_slice(const Ref<RDTextureView> &p_view, RID p_with_texture, uint32_t p_layer, uint32_t p_mipmap, uint32_t p_mipmaps = 1, TextureSliceType p_slice_type = TEXTURE_SLICE_2D);1688Ref<RDTextureFormat> _texture_get_format(RID p_rd_texture);16891690FramebufferFormatID _framebuffer_format_create(const TypedArray<RDAttachmentFormat> &p_attachments, uint32_t p_view_count);1691FramebufferFormatID _framebuffer_format_create_multipass(const TypedArray<RDAttachmentFormat> &p_attachments, const TypedArray<RDFramebufferPass> &p_passes, uint32_t p_view_count);1692RID _framebuffer_create(const TypedArray<RID> &p_textures, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1);1693RID _framebuffer_create_multipass(const TypedArray<RID> &p_textures, const TypedArray<RDFramebufferPass> &p_passes, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1);16941695RID _sampler_create(const Ref<RDSamplerState> &p_state);16961697VertexFormatID _vertex_format_create(const TypedArray<RDVertexAttribute> &p_vertex_formats);1698RID _vertex_array_create(uint32_t p_vertex_count, VertexFormatID p_vertex_format, const TypedArray<RID> &p_src_buffers, const Vector<int64_t> &p_offsets = Vector<int64_t>());16991700Ref<RDShaderSPIRV> _shader_compile_spirv_from_source(const Ref<RDShaderSource> &p_source, bool p_allow_cache = true);1701Vector<uint8_t> _shader_compile_binary_from_spirv(const Ref<RDShaderSPIRV> &p_bytecode, const String &p_shader_name = "");1702RID _shader_create_from_spirv(const Ref<RDShaderSPIRV> &p_spirv, const String &p_shader_name = "");17031704RID _uniform_set_create(const TypedArray<RDUniform> &p_uniforms, RID p_shader, uint32_t p_shader_set);17051706Error _buffer_update_bind(RID p_buffer, uint32_t p_offset, uint32_t p_size, const Vector<uint8_t> &p_data);17071708RID _render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const Ref<RDPipelineRasterizationState> &p_rasterization_state, const Ref<RDPipelineMultisampleState> &p_multisample_state, const Ref<RDPipelineDepthStencilState> &p_depth_stencil_state, const Ref<RDPipelineColorBlendState> &p_blend_state, BitField<PipelineDynamicStateFlags> p_dynamic_state_flags, uint32_t p_for_render_pass, const TypedArray<RDPipelineSpecializationConstant> &p_specialization_constants);1709RID _compute_pipeline_create(RID p_shader, const TypedArray<RDPipelineSpecializationConstant> &p_specialization_constants);17101711void _draw_list_set_push_constant(DrawListID p_list, const Vector<uint8_t> &p_data, uint32_t p_data_size);1712void _compute_list_set_push_constant(ComputeListID p_list, const Vector<uint8_t> &p_data, uint32_t p_data_size);1713};17141715VARIANT_ENUM_CAST(RenderingDevice::DeviceType)1716VARIANT_ENUM_CAST(RenderingDevice::DriverResource)1717VARIANT_ENUM_CAST(RenderingDevice::ShaderStage)1718VARIANT_ENUM_CAST(RenderingDevice::ShaderLanguage)1719VARIANT_ENUM_CAST(RenderingDevice::CompareOperator)1720VARIANT_ENUM_CAST(RenderingDevice::DataFormat)1721VARIANT_ENUM_CAST(RenderingDevice::TextureType)1722VARIANT_ENUM_CAST(RenderingDevice::TextureSamples)1723VARIANT_BITFIELD_CAST(RenderingDevice::TextureUsageBits)1724VARIANT_ENUM_CAST(RenderingDevice::TextureSwizzle)1725VARIANT_ENUM_CAST(RenderingDevice::TextureSliceType)1726VARIANT_ENUM_CAST(RenderingDevice::SamplerFilter)1727VARIANT_ENUM_CAST(RenderingDevice::SamplerRepeatMode)1728VARIANT_ENUM_CAST(RenderingDevice::SamplerBorderColor)1729VARIANT_ENUM_CAST(RenderingDevice::VertexFrequency)1730VARIANT_ENUM_CAST(RenderingDevice::IndexBufferFormat)1731VARIANT_BITFIELD_CAST(RenderingDevice::StorageBufferUsage)1732VARIANT_BITFIELD_CAST(RenderingDevice::BufferCreationBits)1733VARIANT_ENUM_CAST(RenderingDevice::UniformType)1734VARIANT_ENUM_CAST(RenderingDevice::RenderPrimitive)1735VARIANT_ENUM_CAST(RenderingDevice::PolygonCullMode)1736VARIANT_ENUM_CAST(RenderingDevice::PolygonFrontFace)1737VARIANT_ENUM_CAST(RenderingDevice::StencilOperation)1738VARIANT_ENUM_CAST(RenderingDevice::LogicOperation)1739VARIANT_ENUM_CAST(RenderingDevice::BlendFactor)1740VARIANT_ENUM_CAST(RenderingDevice::BlendOperation)1741VARIANT_BITFIELD_CAST(RenderingDevice::PipelineDynamicStateFlags)1742VARIANT_ENUM_CAST(RenderingDevice::PipelineSpecializationConstantType)1743VARIANT_ENUM_CAST(RenderingDevice::Limit)1744VARIANT_ENUM_CAST(RenderingDevice::MemoryType)1745VARIANT_ENUM_CAST(RenderingDevice::Features)1746VARIANT_ENUM_CAST(RenderingDevice::BreadcrumbMarker)1747VARIANT_BITFIELD_CAST(RenderingDevice::DrawFlags);17481749#ifndef DISABLE_DEPRECATED1750VARIANT_BITFIELD_CAST(RenderingDevice::BarrierMask);1751VARIANT_ENUM_CAST(RenderingDevice::InitialAction)1752VARIANT_ENUM_CAST(RenderingDevice::FinalAction)1753#endif17541755typedef RenderingDevice RD;175617571758