diff options
author | Dario <dariosamo@gmail.com> | 2024-10-31 11:37:54 -0300 |
---|---|---|
committer | Dario <dariosamo@gmail.com> | 2024-11-01 09:46:52 -0300 |
commit | 5216ef5f9cb9479989b58aaab797a87a61899630 (patch) | |
tree | 5fcd29a20bebf185586f26d25583dad49f60472d /servers/rendering/renderer_rd | |
parent | c6c464cf9ae56e8b68620af65125dd980d0e8122 (diff) | |
download | redot-engine-5216ef5f9cb9479989b58aaab797a87a61899630.tar.gz |
Add dependency detection improvements to the render graph.
- Buffers changing their usage are no longer treated as write usage unless the API requires it.
- Draw lists are not treated as being dependent on each other if their regions do not intersect despite both being write commands.
- Particles were tweaked to use different unused buffers to reduce dependencies.
Diffstat (limited to 'servers/rendering/renderer_rd')
5 files changed, 39 insertions, 26 deletions
diff --git a/servers/rendering/renderer_rd/effects/copy_effects.cpp b/servers/rendering/renderer_rd/effects/copy_effects.cpp index c7a7532d76..808c82f712 100644 --- a/servers/rendering/renderer_rd/effects/copy_effects.cpp +++ b/servers/rendering/renderer_rd/effects/copy_effects.cpp @@ -1002,15 +1002,19 @@ void CopyEffects::copy_cubemap_to_dp(RID p_source_rd_texture, RID p_dst_framebuf MaterialStorage *material_storage = MaterialStorage::get_singleton(); ERR_FAIL_NULL(material_storage); + Rect2i screen_rect; + float atlas_width = p_dst_size.width / p_rect.size.width; + float atlas_height = p_dst_size.height / p_rect.size.height; + screen_rect.position.x = (int32_t)(Math::round(p_rect.position.x * atlas_width)); + screen_rect.position.y = (int32_t)(Math::round(p_rect.position.y * atlas_height)); + screen_rect.size.width = (int32_t)(Math::round(p_dst_size.width)); + screen_rect.size.height = (int32_t)(Math::round(p_dst_size.height)); + CopyToDPPushConstant push_constant; - push_constant.screen_rect[0] = p_rect.position.x; - push_constant.screen_rect[1] = p_rect.position.y; - push_constant.screen_rect[2] = p_rect.size.width; - push_constant.screen_rect[3] = p_rect.size.height; push_constant.z_far = p_z_far; push_constant.z_near = p_z_near; - push_constant.texel_size[0] = 1.0f / p_dst_size.x; - push_constant.texel_size[1] = 1.0f / p_dst_size.y; + push_constant.texel_size[0] = 1.0f / p_dst_size.width; + push_constant.texel_size[1] = 1.0f / p_dst_size.height; push_constant.texel_size[0] *= p_dp_flip ? -1.0f : 1.0f; // Encode dp flip as x size sign // setup our uniforms @@ -1021,7 +1025,7 @@ void CopyEffects::copy_cubemap_to_dp(RID p_source_rd_texture, RID p_dst_framebuf RID shader = cube_to_dp.shader.version_get_shader(cube_to_dp.shader_version, 0); ERR_FAIL_COND(shader.is_null()); - RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dst_framebuffer, RD::INITIAL_ACTION_DISCARD, RD::FINAL_ACTION_DISCARD, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_STORE); + RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dst_framebuffer, RD::INITIAL_ACTION_DISCARD, RD::FINAL_ACTION_DISCARD, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_STORE, Vector<Color>(), 1.0f, 0, screen_rect); RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, cube_to_dp.pipeline.get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dst_framebuffer))); RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 0, u_source_rd_texture), 0); RD::get_singleton()->draw_list_bind_index_array(draw_list, material_storage->get_quad_index_array()); diff --git a/servers/rendering/renderer_rd/effects/copy_effects.h b/servers/rendering/renderer_rd/effects/copy_effects.h index 014f78e2b9..b6fc95d0f1 100644 --- a/servers/rendering/renderer_rd/effects/copy_effects.h +++ b/servers/rendering/renderer_rd/effects/copy_effects.h @@ -217,7 +217,6 @@ private: float z_far; float z_near; float texel_size[2]; - float screen_rect[4]; }; struct CopyToDP { diff --git a/servers/rendering/renderer_rd/shaders/effects/cube_to_dp.glsl b/servers/rendering/renderer_rd/shaders/effects/cube_to_dp.glsl index 3fb93dda35..b45e310b61 100644 --- a/servers/rendering/renderer_rd/shaders/effects/cube_to_dp.glsl +++ b/servers/rendering/renderer_rd/shaders/effects/cube_to_dp.glsl @@ -8,7 +8,6 @@ layout(push_constant, std430) uniform Params { float z_far; float z_near; vec2 texel_size; - vec4 screen_rect; } params; @@ -17,8 +16,7 @@ layout(location = 0) out vec2 uv_interp; void main() { vec2 base_arr[4] = vec2[](vec2(0.0, 0.0), vec2(0.0, 1.0), vec2(1.0, 1.0), vec2(1.0, 0.0)); uv_interp = base_arr[gl_VertexIndex]; - vec2 screen_pos = uv_interp * params.screen_rect.zw + params.screen_rect.xy; - gl_Position = vec4(screen_pos * 2.0 - 1.0, 0.0, 1.0); + gl_Position = vec4(uv_interp * 2.0 - 1.0, 0.0, 1.0); } #[fragment] @@ -35,7 +33,6 @@ layout(push_constant, std430) uniform Params { float z_far; float z_near; vec2 texel_size; - vec4 screen_rect; } params; diff --git a/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp b/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp index 314cbf9aa9..6efb8c176f 100644 --- a/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp @@ -306,9 +306,14 @@ void ParticlesStorage::_particles_free_data(Particles *particles) { particles->emission_storage_buffer = RID(); } - if (particles->unused_storage_buffer.is_valid()) { - RD::get_singleton()->free(particles->unused_storage_buffer); - particles->unused_storage_buffer = RID(); + if (particles->unused_emission_storage_buffer.is_valid()) { + RD::get_singleton()->free(particles->unused_emission_storage_buffer); + particles->unused_emission_storage_buffer = RID(); + } + + if (particles->unused_trail_storage_buffer.is_valid()) { + RD::get_singleton()->free(particles->unused_trail_storage_buffer); + particles->unused_trail_storage_buffer = RID(); } if (RD::get_singleton()->uniform_set_is_valid(particles->particles_material_uniform_set)) { @@ -534,9 +539,15 @@ void ParticlesStorage::_particles_allocate_emission_buffer(Particles *particles) } } -void ParticlesStorage::_particles_ensure_unused_buffer(Particles *particles) { - if (particles->unused_storage_buffer.is_null()) { - particles->unused_storage_buffer = RD::get_singleton()->storage_buffer_create(sizeof(uint32_t) * 4); +void ParticlesStorage::_particles_ensure_unused_emission_buffer(Particles *particles) { + if (particles->unused_emission_storage_buffer.is_null()) { + particles->unused_emission_storage_buffer = RD::get_singleton()->storage_buffer_create(sizeof(uint32_t) * 4); + } +} + +void ParticlesStorage::_particles_ensure_unused_trail_buffer(Particles *particles) { + if (particles->unused_trail_storage_buffer.is_null()) { + particles->unused_trail_storage_buffer = RD::get_singleton()->storage_buffer_create(sizeof(uint32_t) * 4); } } @@ -763,8 +774,8 @@ void ParticlesStorage::_particles_process(Particles *p_particles, double p_delta if (p_particles->emission_storage_buffer.is_valid()) { u.append_id(p_particles->emission_storage_buffer); } else { - _particles_ensure_unused_buffer(p_particles); - u.append_id(p_particles->unused_storage_buffer); + _particles_ensure_unused_emission_buffer(p_particles); + u.append_id(p_particles->unused_emission_storage_buffer); } uniforms.push_back(u); } @@ -779,8 +790,8 @@ void ParticlesStorage::_particles_process(Particles *p_particles, double p_delta } u.append_id(sub_emitter->emission_storage_buffer); } else { - _particles_ensure_unused_buffer(p_particles); - u.append_id(p_particles->unused_storage_buffer); + _particles_ensure_unused_emission_buffer(p_particles); + u.append_id(p_particles->unused_emission_storage_buffer); } uniforms.push_back(u); } @@ -1481,8 +1492,8 @@ void ParticlesStorage::update_particles() { if (particles->trail_bind_pose_buffer.is_valid()) { u.append_id(particles->trail_bind_pose_buffer); } else { - _particles_ensure_unused_buffer(particles); - u.append_id(particles->unused_storage_buffer); + _particles_ensure_unused_trail_buffer(particles); + u.append_id(particles->unused_trail_storage_buffer); } uniforms.push_back(u); } diff --git a/servers/rendering/renderer_rd/storage_rd/particles_storage.h b/servers/rendering/renderer_rd/storage_rd/particles_storage.h index 33f44f3045..98c693f477 100644 --- a/servers/rendering/renderer_rd/storage_rd/particles_storage.h +++ b/servers/rendering/renderer_rd/storage_rd/particles_storage.h @@ -247,7 +247,8 @@ private: ParticleEmissionBuffer *emission_buffer = nullptr; RID emission_storage_buffer; - RID unused_storage_buffer; + RID unused_emission_storage_buffer; + RID unused_trail_storage_buffer; HashSet<RID> collisions; @@ -265,7 +266,8 @@ private: void _particles_process(Particles *p_particles, double p_delta); void _particles_allocate_emission_buffer(Particles *particles); - void _particles_ensure_unused_buffer(Particles *particles); + void _particles_ensure_unused_emission_buffer(Particles *particles); + void _particles_ensure_unused_trail_buffer(Particles *particles); void _particles_free_data(Particles *particles); void _particles_update_buffers(Particles *particles); |