diff options
Diffstat (limited to 'servers/rendering/renderer_rd/environment/fog.cpp')
-rw-r--r-- | servers/rendering/renderer_rd/environment/fog.cpp | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/servers/rendering/renderer_rd/environment/fog.cpp b/servers/rendering/renderer_rd/environment/fog.cpp index 57da55db4d..78b785153f 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<RD::Uniform> uniforms; Vector<RD::Uniform> 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()); |