1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-12 13:20:55 +00:00

Add Persistent Buffers

This work is a heavily refactored and rewritten from TheForge's initial
code.

TheForge's original code had too many race conditions and was
fundamentally flawed as it was too easy to incur into those data races
by accident.

However they identified the proper places that needed changes, and the
idea was sound. I used their work as a blueprint to design this work.

This PR implements:

 - Introduction of UMA buffers used by a few buffers
(most notably the ones filled by _fill_instance_data).

Ironically this change seems to positively affect PC more than it does
on Mobile.

Updates D3D12 Memory Allocator to get GPU_UPLOAD heap support.

Metal implementation by Stuart Carnie.

Co-authored-by: Stuart Carnie <stuart.carnie@gmail.com>
Co-authored-by: TheForge team
This commit is contained in:
Stuart Carnie
2025-10-18 07:00:58 +11:00
parent 5950fca36c
commit 230adb7511
38 changed files with 2848 additions and 1466 deletions

View File

@@ -65,6 +65,7 @@ private:
Vector<bool> group_enabled;
Vector<RD::PipelineImmutableSampler> immutable_samplers;
Vector<uint64_t> dynamic_buffers;
struct Version {
Mutex *mutex = nullptr;
@@ -225,6 +226,8 @@ public:
const String &get_name() const;
const Vector<uint64_t> &get_dynamic_buffers() const;
static void shaders_embedded_set_lock();
static const ShaderVersionPairSet &shaders_embedded_set_get();
static void shaders_embedded_set_unlock();
@@ -237,15 +240,26 @@ public:
static void set_shader_cache_save_compressed_zstd(bool p_enable);
static void set_shader_cache_save_debug(bool p_enable);
static Vector<RD::ShaderStageSPIRVData> compile_stages(const Vector<String> &p_stage_sources);
static Vector<RD::ShaderStageSPIRVData> compile_stages(const Vector<String> &p_stage_sources, const Vector<uint64_t> &p_dynamic_buffers);
static PackedByteArray save_shader_cache_bytes(const LocalVector<int> &p_variants, const Vector<Vector<uint8_t>> &p_variant_data);
Vector<String> version_build_variant_stage_sources(RID p_version, int p_variant);
RS::ShaderNativeSourceCode version_get_native_source_code(RID p_version);
String version_get_cache_file_relative_path(RID p_version, int p_group, const String &p_api_name);
void initialize(const Vector<String> &p_variant_defines, const String &p_general_defines = "", const Vector<RD::PipelineImmutableSampler> &p_immutable_samplers = Vector<RD::PipelineImmutableSampler>());
void initialize(const Vector<VariantDefine> &p_variant_defines, const String &p_general_defines = "", const Vector<RD::PipelineImmutableSampler> &p_immutable_samplers = Vector<RD::PipelineImmutableSampler>());
struct DynamicBuffer {
static uint64_t encode(uint32_t p_set_id, uint32_t p_binding) {
return uint64_t(p_set_id) << 32ul | uint64_t(p_binding);
}
};
// Dynamic Buffers specifies Which buffers will be persistent/dynamic when used.
// See DynamicBuffer::encode. We need this argument because SPIR-V does not distinguish between a
// uniform buffer and a dynamic uniform buffer. At shader level they're the same thing, but the PSO
// is created slightly differently and they're bound differently.
// On D3D12 the Root Layout is also different.
void initialize(const Vector<String> &p_variant_defines, const String &p_general_defines = "", const Vector<RD::PipelineImmutableSampler> &p_immutable_samplers = Vector<RD::PipelineImmutableSampler>(), const Vector<uint64_t> &p_dynamic_buffers = Vector<uint64_t>());
void initialize(const Vector<VariantDefine> &p_variant_defines, const String &p_general_defines = "", const Vector<RD::PipelineImmutableSampler> &p_immutable_samplers = Vector<RD::PipelineImmutableSampler>(), const Vector<uint64_t> &p_dynamic_buffers = Vector<uint64_t>());
virtual ~ShaderRD();
};