diff --git a/servers/rendering/renderer_rd/environment/fog.cpp b/servers/rendering/renderer_rd/environment/fog.cpp index 57da55db4d0..78b785153fa 100644 --- a/servers/rendering/renderer_rd/environment/fog.cpp +++ b/servers/rendering/renderer_rd/environment/fog.cpp @@ -388,6 +388,37 @@ Fog::FogShaderData::~FogShaderData() { //////////////////////////////////////////////////////////////////////////////// // Volumetric Fog +bool Fog::VolumetricFog::sync_gi_dependent_sets_validity(bool p_ensure_freed) { + bool null = gi_dependent_sets.copy_uniform_set.is_null(); + bool valid = !null && RD::get_singleton()->uniform_set_is_valid(gi_dependent_sets.copy_uniform_set); + +#ifdef DEV_ENABLED + // It's all-or-nothing, or something else has changed that requires dev attention. + DEV_ASSERT(null == gi_dependent_sets.process_uniform_set_density.is_null()); + DEV_ASSERT(null == gi_dependent_sets.process_uniform_set.is_null()); + DEV_ASSERT(null == gi_dependent_sets.process_uniform_set2.is_null()); + DEV_ASSERT(valid == RD::get_singleton()->uniform_set_is_valid(gi_dependent_sets.process_uniform_set_density)); + DEV_ASSERT(valid == RD::get_singleton()->uniform_set_is_valid(gi_dependent_sets.process_uniform_set)); + DEV_ASSERT(valid == RD::get_singleton()->uniform_set_is_valid(gi_dependent_sets.process_uniform_set2)); +#endif + + if (valid) { + if (p_ensure_freed) { + RD::get_singleton()->free(gi_dependent_sets.copy_uniform_set); + RD::get_singleton()->free(gi_dependent_sets.process_uniform_set_density); + RD::get_singleton()->free(gi_dependent_sets.process_uniform_set); + RD::get_singleton()->free(gi_dependent_sets.process_uniform_set2); + valid = false; + } + } + + if (!valid && !null) { + gi_dependent_sets = {}; + } + + return valid; +} + void Fog::VolumetricFog::init(const Vector3i &fog_size, RID p_sky_shader) { width = fog_size.x; height = fog_size.y; @@ -464,17 +495,7 @@ Fog::VolumetricFog::~VolumetricFog() { RD::get_singleton()->free(fog_uniform_set); } - // At this point, due to cascade deletions, the sets may no longer be valid, but still they must work as a group. - gi_dependent_sets.valid = RD::get_singleton()->uniform_set_is_valid(gi_dependent_sets.process_uniform_set_density); -#ifdef DEV_ENABLED - gi_dependent_sets.assert_actual_validity(); -#endif - if (gi_dependent_sets.valid) { - RD::get_singleton()->free(gi_dependent_sets.copy_uniform_set); - RD::get_singleton()->free(gi_dependent_sets.process_uniform_set_density); - RD::get_singleton()->free(gi_dependent_sets.process_uniform_set); - RD::get_singleton()->free(gi_dependent_sets.process_uniform_set2); - } + sync_gi_dependent_sets_validity(true); if (sdfgi_uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(sdfgi_uniform_set)) { RD::get_singleton()->free(sdfgi_uniform_set); @@ -717,10 +738,7 @@ void Fog::volumetric_fog_update(const VolumetricFogSettings &p_settings, const P RD::get_singleton()->compute_list_end(); } -#ifdef DEV_ENABLED - fog->gi_dependent_sets.assert_actual_validity(); -#endif - if (!fog->gi_dependent_sets.valid) { + if (!fog->sync_gi_dependent_sets_validity()) { //re create uniform set if needed Vector uniforms; Vector copy_uniforms; @@ -932,8 +950,6 @@ void Fog::volumetric_fog_update(const VolumetricFogSettings &p_settings, const P uniforms.remove_at(8); uniforms.write[7].set_id(0, aux7); fog->gi_dependent_sets.process_uniform_set_density = RD::get_singleton()->uniform_set_create(uniforms, volumetric_fog.process_shader.version_get_shader(volumetric_fog.process_shader_version, VolumetricFogShader::VOLUMETRIC_FOG_PROCESS_SHADER_DENSITY), 0); - - fog->gi_dependent_sets.valid = true; } bool using_sdfgi = RendererSceneRenderRD::get_singleton()->environment_get_volumetric_fog_gi_inject(p_settings.env) > 0.0001 && RendererSceneRenderRD::get_singleton()->environment_get_sdfgi_enabled(p_settings.env) && (p_settings.sdfgi.is_valid()); diff --git a/servers/rendering/renderer_rd/environment/fog.h b/servers/rendering/renderer_rd/environment/fog.h index 926da4026cc..277389c596d 100644 --- a/servers/rendering/renderer_rd/environment/fog.h +++ b/servers/rendering/renderer_rd/environment/fog.h @@ -303,21 +303,10 @@ public: RID fog_uniform_set; struct { - bool valid = false; RID copy_uniform_set; RID process_uniform_set_density; RID process_uniform_set; RID process_uniform_set2; - -#ifdef DEV_ENABLED - void assert_actual_validity() { - // It's all-or-nothing, or something else has changed that requires dev attention. - DEV_ASSERT(valid == RD::get_singleton()->uniform_set_is_valid(copy_uniform_set)); - DEV_ASSERT(valid == RD::get_singleton()->uniform_set_is_valid(process_uniform_set_density)); - DEV_ASSERT(valid == RD::get_singleton()->uniform_set_is_valid(process_uniform_set)); - DEV_ASSERT(valid == RD::get_singleton()->uniform_set_is_valid(process_uniform_set2)); - } -#endif } gi_dependent_sets; RID sdfgi_uniform_set; @@ -328,6 +317,8 @@ public: virtual void configure(RenderSceneBuffersRD *p_render_buffers) override{}; virtual void free_data() override{}; + bool sync_gi_dependent_sets_validity(bool p_ensure_freed = false); + void init(const Vector3i &fog_size, RID p_sky_shader); ~VolumetricFog(); }; diff --git a/servers/rendering/renderer_rd/environment/gi.cpp b/servers/rendering/renderer_rd/environment/gi.cpp index 52f09e1ccb5..c2a018c7c6c 100644 --- a/servers/rendering/renderer_rd/environment/gi.cpp +++ b/servers/rendering/renderer_rd/environment/gi.cpp @@ -3695,20 +3695,6 @@ void GI::setup_voxel_gi_instances(RenderDataRD *p_render_data, Refuniform_set[v] = RID(); } - if (p_render_buffers->has_custom_data(RB_SCOPE_FOG)) { - Ref fog = p_render_buffers->get_custom_data(RB_SCOPE_FOG); - -#ifdef DEV_ENABLED - fog->gi_dependent_sets.assert_actual_validity(); -#endif - if (fog->gi_dependent_sets.valid) { - RD::get_singleton()->free(fog->gi_dependent_sets.copy_uniform_set); - RD::get_singleton()->free(fog->gi_dependent_sets.process_uniform_set_density); - RD::get_singleton()->free(fog->gi_dependent_sets.process_uniform_set); - RD::get_singleton()->free(fog->gi_dependent_sets.process_uniform_set2); - fog->gi_dependent_sets.valid = false; - } - } } if (p_voxel_gi_instances.size() > 0) { diff --git a/servers/rendering/renderer_rd/storage_rd/light_storage.h b/servers/rendering/renderer_rd/storage_rd/light_storage.h index c36d1ef503b..3360358169a 100644 --- a/servers/rendering/renderer_rd/storage_rd/light_storage.h +++ b/servers/rendering/renderer_rd/storage_rd/light_storage.h @@ -93,11 +93,11 @@ private: struct ShadowTransform { Projection camera; Transform3D transform; - float farplane; - float split; - float bias_scale; - float shadow_texel_size; - float range_begin; + float farplane = 0.0; + float split = 0.0; + float bias_scale = 0.0; + float shadow_texel_size = 0.0; + float range_begin = 0.0; Rect2 atlas_rect; Vector2 uv_scale; };