You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10: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:
@@ -302,7 +302,7 @@ void ShaderRD::_compile_variant(uint32_t p_variant, CompileData p_data) {
|
||||
}
|
||||
|
||||
Vector<String> variant_stage_sources = _build_variant_stage_sources(variant, p_data);
|
||||
Vector<RD::ShaderStageSPIRVData> variant_stages = compile_stages(variant_stage_sources);
|
||||
Vector<RD::ShaderStageSPIRVData> variant_stages = compile_stages(variant_stage_sources, dynamic_buffers);
|
||||
ERR_FAIL_COND(variant_stages.is_empty());
|
||||
|
||||
Vector<uint8_t> shader_data = RD::get_singleton()->shader_compile_binary_from_spirv(variant_stages, name + ":" + itos(variant));
|
||||
@@ -783,6 +783,10 @@ const String &ShaderRD::get_name() const {
|
||||
return name;
|
||||
}
|
||||
|
||||
const Vector<uint64_t> &ShaderRD::get_dynamic_buffers() const {
|
||||
return dynamic_buffers;
|
||||
}
|
||||
|
||||
bool ShaderRD::shader_cache_cleanup_on_start = false;
|
||||
|
||||
ShaderRD::ShaderRD() {
|
||||
@@ -801,12 +805,13 @@ ShaderRD::ShaderRD() {
|
||||
base_compute_defines = base_compute_define_text.ascii();
|
||||
}
|
||||
|
||||
void ShaderRD::initialize(const Vector<String> &p_variant_defines, const String &p_general_defines, const Vector<RD::PipelineImmutableSampler> &p_immutable_samplers) {
|
||||
void ShaderRD::initialize(const Vector<String> &p_variant_defines, const String &p_general_defines, const Vector<RD::PipelineImmutableSampler> &p_immutable_samplers, const Vector<uint64_t> &p_dynamic_buffers) {
|
||||
ERR_FAIL_COND(variant_defines.size());
|
||||
ERR_FAIL_COND(p_variant_defines.is_empty());
|
||||
|
||||
general_defines = p_general_defines.utf8();
|
||||
immutable_samplers = p_immutable_samplers;
|
||||
dynamic_buffers = p_dynamic_buffers;
|
||||
|
||||
// When initialized this way, there is just one group and its always enabled.
|
||||
group_to_variant_map.insert(0, LocalVector<int>{});
|
||||
@@ -846,6 +851,11 @@ void ShaderRD::_initialize_cache() {
|
||||
hash_build.append(variant_defines[E.value[i]].text.get_data());
|
||||
}
|
||||
|
||||
for (const uint64_t dyn_buffer : dynamic_buffers) {
|
||||
hash_build.append("[dynamic_buffer]");
|
||||
hash_build.append(uitos(dyn_buffer));
|
||||
}
|
||||
|
||||
group_sha256[E.key] = hash_build.as_string().sha256_text();
|
||||
|
||||
if (!shader_cache_user_dir.is_empty()) {
|
||||
@@ -880,12 +890,13 @@ void ShaderRD::_initialize_cache() {
|
||||
}
|
||||
|
||||
// Same as above, but allows specifying shader compilation groups.
|
||||
void ShaderRD::initialize(const Vector<VariantDefine> &p_variant_defines, const String &p_general_defines, const Vector<RD::PipelineImmutableSampler> &p_immutable_samplers) {
|
||||
void ShaderRD::initialize(const Vector<VariantDefine> &p_variant_defines, const String &p_general_defines, const Vector<RD::PipelineImmutableSampler> &p_immutable_samplers, const Vector<uint64_t> &p_dynamic_buffers) {
|
||||
ERR_FAIL_COND(variant_defines.size());
|
||||
ERR_FAIL_COND(p_variant_defines.is_empty());
|
||||
|
||||
general_defines = p_general_defines.utf8();
|
||||
immutable_samplers = p_immutable_samplers;
|
||||
dynamic_buffers = p_dynamic_buffers;
|
||||
|
||||
int max_group_id = 0;
|
||||
|
||||
@@ -962,7 +973,7 @@ void ShaderRD::set_shader_cache_save_debug(bool p_enable) {
|
||||
shader_cache_save_debug = p_enable;
|
||||
}
|
||||
|
||||
Vector<RD::ShaderStageSPIRVData> ShaderRD::compile_stages(const Vector<String> &p_stage_sources) {
|
||||
Vector<RD::ShaderStageSPIRVData> ShaderRD::compile_stages(const Vector<String> &p_stage_sources, const Vector<uint64_t> &p_dynamic_buffers) {
|
||||
RD::ShaderStageSPIRVData stage;
|
||||
Vector<RD::ShaderStageSPIRVData> stages;
|
||||
String error;
|
||||
@@ -974,6 +985,7 @@ Vector<RD::ShaderStageSPIRVData> ShaderRD::compile_stages(const Vector<String> &
|
||||
}
|
||||
|
||||
stage.spirv = RD::get_singleton()->shader_compile_spirv_from_source(RD::ShaderStage(i), p_stage_sources[i], RD::SHADER_LANGUAGE_GLSL, &error);
|
||||
stage.dynamic_buffers = p_dynamic_buffers;
|
||||
stage.shader_stage = RD::ShaderStage(i);
|
||||
if (!stage.spirv.is_empty()) {
|
||||
stages.push_back(stage);
|
||||
|
||||
Reference in New Issue
Block a user