diff options
| author | reduz <reduzio@gmail.com> | 2021-07-07 19:55:20 -0300 |
|---|---|---|
| committer | reduz <reduzio@gmail.com> | 2021-07-07 19:55:20 -0300 |
| commit | 83addd6ee550ca338c246d1659e08029a4c588d1 (patch) | |
| tree | ceb876d6cb502f414724000cdf916c6ecd3c1457 /servers/rendering/renderer_rd/renderer_storage_rd.cpp | |
| parent | b1068f9f01f5a5382ed3f1994d1302a35e96f445 (diff) | |
| download | redot-engine-83addd6ee550ca338c246d1659e08029a4c588d1.tar.gz | |
Fix material invalidation on reimport.
* IF a texture was reimported (calling replace as an example), it would invalidate all materials using it, causing plenty of errors.
* Added the possibility to get a notification when a uniform set is erased.
* With this notification, materials can be queued for update properly.
Diffstat (limited to 'servers/rendering/renderer_rd/renderer_storage_rd.cpp')
| -rw-r--r-- | servers/rendering/renderer_rd/renderer_storage_rd.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/servers/rendering/renderer_rd/renderer_storage_rd.cpp b/servers/rendering/renderer_rd/renderer_storage_rd.cpp index 3aa201882f..6738f499bd 100644 --- a/servers/rendering/renderer_rd/renderer_storage_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_storage_rd.cpp @@ -2377,6 +2377,13 @@ void RendererStorageRD::MaterialData::update_textures(const Map<StringName, Vari } } +void RendererStorageRD::MaterialData::free_parameters_uniform_set(RID p_uniform_set) { + if (p_uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(p_uniform_set)) { + RD::get_singleton()->uniform_set_set_invalidation_callback(p_uniform_set, nullptr, nullptr); + RD::get_singleton()->free(p_uniform_set); + } +} + bool RendererStorageRD::MaterialData::update_parameters_uniform_set(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty, const Map<StringName, ShaderLanguage::ShaderNode::Uniform> &p_uniforms, const uint32_t *p_uniform_offsets, const Vector<ShaderCompilerRD::GeneratedCode::Texture> &p_texture_uniforms, const Map<StringName, RID> &p_default_texture_params, uint32_t p_ubo_size, RID &uniform_set, RID p_shader, uint32_t p_shader_uniform_set, uint32_t p_barrier) { if ((uint32_t)ubo_data.size() != p_ubo_size) { p_uniform_dirty = true; @@ -2393,6 +2400,7 @@ bool RendererStorageRD::MaterialData::update_parameters_uniform_set(const Map<St //clear previous uniform set if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { + RD::get_singleton()->uniform_set_set_invalidation_callback(uniform_set, nullptr, nullptr); RD::get_singleton()->free(uniform_set); uniform_set = RID(); } @@ -2412,6 +2420,7 @@ bool RendererStorageRD::MaterialData::update_parameters_uniform_set(const Map<St //clear previous uniform set if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { + RD::get_singleton()->uniform_set_set_invalidation_callback(uniform_set, nullptr, nullptr); RD::get_singleton()->free(uniform_set); uniform_set = RID(); } @@ -2454,9 +2463,19 @@ bool RendererStorageRD::MaterialData::update_parameters_uniform_set(const Map<St uniform_set = RD::get_singleton()->uniform_set_create(uniforms, p_shader, p_shader_uniform_set); + RD::get_singleton()->uniform_set_set_invalidation_callback(uniform_set, _material_uniform_set_erased, &self); + return true; } +void RendererStorageRD::_material_uniform_set_erased(const RID &p_set, void *p_material) { + RID rid = *(RID *)p_material; + Material *material = base_singleton->material_owner.getornull(rid); + if (material) { + material->dependency.changed_notify(DEPENDENCY_CHANGED_MATERIAL); + } +} + void RendererStorageRD::material_force_update_textures(RID p_material, ShaderType p_shader_type) { Material *material = material_owner.getornull(p_material); if (material->shader_type != p_shader_type) { @@ -5367,9 +5386,7 @@ bool RendererStorageRD::ParticlesMaterialData::update_parameters(const Map<Strin } RendererStorageRD::ParticlesMaterialData::~ParticlesMaterialData() { - if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - RD::get_singleton()->free(uniform_set); - } + free_parameters_uniform_set(uniform_set); } RendererStorageRD::MaterialData *RendererStorageRD::_create_particles_material_func(ParticlesShaderData *p_shader) { |
