diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-12-17 12:26:51 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-12-17 12:26:51 +0100 |
commit | 676f60b0ccd38df41648b942fe9b437ac3ea954a (patch) | |
tree | 0a1fa5f3c1f8bfa4a25e72eb6abb6b6ee51230eb /servers/rendering/renderer_rd | |
parent | 376290ea86b70c15452ec97e1cd1937c319383b1 (diff) | |
parent | 1b330820bf4c145060462624534dea81055a8bf0 (diff) |
Merge pull request #70132 from clayjohn/RT-update
Implement render_target_was_used API so that Viewports can properly check if they have been used.
Diffstat (limited to 'servers/rendering/renderer_rd')
12 files changed, 52 insertions, 0 deletions
diff --git a/servers/rendering/renderer_rd/environment/fog.cpp b/servers/rendering/renderer_rd/environment/fog.cpp index c60fa91664..38066b6613 100644 --- a/servers/rendering/renderer_rd/environment/fog.cpp +++ b/servers/rendering/renderer_rd/environment/fog.cpp @@ -699,6 +699,7 @@ void Fog::volumetric_fog_update(const VolumetricFogSettings &p_settings, const P RD::get_singleton()->compute_list_bind_uniform_set(compute_list, volumetric_fog.base_uniform_set, VolumetricFogShader::FogSet::FOG_SET_BASE); if (material->uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(material->uniform_set)) { // Material may not have a uniform set. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, material->uniform_set, VolumetricFogShader::FogSet::FOG_SET_MATERIAL); + material->set_as_used(); } RD::get_singleton()->compute_list_dispatch_threads(compute_list, kernel_size.x, kernel_size.y, kernel_size.z); diff --git a/servers/rendering/renderer_rd/environment/sky.cpp b/servers/rendering/renderer_rd/environment/sky.cpp index 9a8b917802..40f68eb118 100644 --- a/servers/rendering/renderer_rd/environment/sky.cpp +++ b/servers/rendering/renderer_rd/environment/sky.cpp @@ -1053,6 +1053,8 @@ void SkyRD::setup(RID p_env, Ref<RenderSceneBuffersRD> p_render_buffers, const P ERR_FAIL_COND(!shader_data); + material->set_as_used(); + // Invalidate supbass buffers if screen size changes if (sky->screen_size != p_screen_size) { sky->screen_size = p_screen_size; @@ -1453,6 +1455,8 @@ void SkyRD::draw(RID p_env, bool p_can_continue_color, bool p_can_continue_depth ERR_FAIL_COND(!shader_data); + material->set_as_used(); + Basis sky_transform = RendererSceneRenderRD::get_singleton()->environment_get_sky_orientation(p_env); sky_transform.invert(); @@ -1550,6 +1554,8 @@ void SkyRD::update_res_buffers(RID p_env, uint32_t p_view_count, const Projectio ERR_FAIL_COND(!shader_data); + material->set_as_used(); + Basis sky_transform = RendererSceneRenderRD::get_singleton()->environment_get_sky_orientation(p_env); sky_transform.invert(); @@ -1643,6 +1649,8 @@ void SkyRD::draw(RD::DrawListID p_draw_list, RID p_env, RID p_fb, uint32_t p_vie ERR_FAIL_COND(!shader_data); + material->set_as_used(); + Basis sky_transform = RendererSceneRenderRD::get_singleton()->environment_get_sky_orientation(p_env); sky_transform.invert(); diff --git a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp index bd27eeb981..c853ae6c69 100644 --- a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp +++ b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp @@ -348,6 +348,7 @@ void RenderForwardClustered::_render_list_template(RenderingDevice::DrawListID p #endif material_uniform_set = surf->material_uniform_set; shader = surf->shader; + surf->material->set_as_used(); #ifdef DEBUG_ENABLED } #endif @@ -3378,6 +3379,7 @@ void RenderForwardClustered::_geometry_instance_add_surface_with_material(Geomet sdcache->flags = flags; sdcache->shader = p_material->shader_data; + sdcache->material = p_material; sdcache->material_uniform_set = p_material->uniform_set; sdcache->surface = mesh_storage->mesh_get_surface(p_mesh, p_surface); sdcache->primitive = mesh_storage->mesh_surface_get_primitive(sdcache->surface); diff --git a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h index d9145b5818..a5e8bb76d9 100644 --- a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h +++ b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h @@ -441,6 +441,7 @@ class RenderForwardClustered : public RendererSceneRenderRD { void *surface = nullptr; RID material_uniform_set; SceneShaderForwardClustered::ShaderData *shader = nullptr; + SceneShaderForwardClustered::MaterialData *material = nullptr; void *surface_shadow = nullptr; RID material_uniform_set_shadow; diff --git a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp index 765f71aa6f..350a5eb0e4 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp @@ -2092,6 +2092,7 @@ void RenderForwardMobile::_render_list_template(RenderingDevice::DrawListID p_dr #endif material_uniform_set = surf->material_uniform_set; shader = surf->shader; + surf->material->set_as_used(); #ifdef DEBUG_ENABLED } #endif @@ -2407,6 +2408,7 @@ void RenderForwardMobile::_geometry_instance_add_surface_with_material(GeometryI sdcache->flags = flags; sdcache->shader = p_material->shader_data; + sdcache->material = p_material; sdcache->material_uniform_set = p_material->uniform_set; sdcache->surface = mesh_storage->mesh_get_surface(p_mesh, p_surface); sdcache->primitive = mesh_storage->mesh_surface_get_primitive(sdcache->surface); diff --git a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h index 6c85e1cffc..0f5a229d61 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h @@ -440,6 +440,7 @@ protected: void *surface = nullptr; RID material_uniform_set; SceneShaderForwardMobile::ShaderData *shader = nullptr; + SceneShaderForwardMobile::MaterialData *material = nullptr; void *surface_shadow = nullptr; RID material_uniform_set_shadow; diff --git a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp index 200bc461fd..f7302adbf6 100644 --- a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp @@ -1136,6 +1136,7 @@ void RendererCanvasRenderRD::_render_items(RID p_to_render_target, int p_item_co // Update uniform set. if (material_data->uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(material_data->uniform_set)) { // Material may not have a uniform set. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, material_data->uniform_set, MATERIAL_UNIFORM_SET); + material_data->set_as_used(); } } else { pipeline_variants = &shader.pipeline_variants; diff --git a/servers/rendering/renderer_rd/storage_rd/material_storage.cpp b/servers/rendering/renderer_rd/storage_rd/material_storage.cpp index 23ee9c3842..709e4b449f 100644 --- a/servers/rendering/renderer_rd/storage_rd/material_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/material_storage.cpp @@ -1319,6 +1319,10 @@ void MaterialStorage::MaterialData::update_textures(const HashMap<StringName, Va roughness_detect_texture = tex; roughness_channel = RS::TextureDetectRoughnessChannel(p_texture_uniforms[i].hint - ShaderLanguage::ShaderNode::Uniform::HINT_ROUGHNESS_R); } + if (tex->render_target) { + tex->render_target->was_used = true; + render_target_cache.push_back(tex->render_target); + } #endif } if (rd_texture.is_null()) { @@ -1405,6 +1409,7 @@ bool MaterialStorage::MaterialData::update_parameters_uniform_set(const HashMap< if ((uint32_t)texture_cache.size() != tex_uniform_count || p_textures_dirty) { texture_cache.resize(tex_uniform_count); + render_target_cache.clear(); p_textures_dirty = true; //clear previous uniform set @@ -1465,6 +1470,12 @@ bool MaterialStorage::MaterialData::update_parameters_uniform_set(const HashMap< return true; } +void MaterialStorage::MaterialData::set_as_used() { + for (int i = 0; i < render_target_cache.size(); i++) { + render_target_cache[i]->was_used = true; + } +} + /////////////////////////////////////////////////////////////////////////// // MaterialStorage diff --git a/servers/rendering/renderer_rd/storage_rd/material_storage.h b/servers/rendering/renderer_rd/storage_rd/material_storage.h index d7d8303a06..989a0f7b45 100644 --- a/servers/rendering/renderer_rd/storage_rd/material_storage.h +++ b/servers/rendering/renderer_rd/storage_rd/material_storage.h @@ -31,6 +31,8 @@ #ifndef MATERIAL_STORAGE_RD_H #define MATERIAL_STORAGE_RD_H +#include "texture_storage.h" + #include "core/math/projection.h" #include "core/templates/local_vector.h" #include "core/templates/rid_owner.h" @@ -74,8 +76,10 @@ public: }; struct MaterialData { + Vector<RendererRD::TextureStorage::RenderTarget *> render_target_cache; void update_uniform_buffer(const HashMap<StringName, ShaderLanguage::ShaderNode::Uniform> &p_uniforms, const uint32_t *p_uniform_offsets, const HashMap<StringName, Variant> &p_parameters, uint8_t *p_buffer, uint32_t p_buffer_size, bool p_use_linear_color); void update_textures(const HashMap<StringName, Variant> &p_parameters, const HashMap<StringName, HashMap<int, RID>> &p_default_textures, const Vector<ShaderCompiler::GeneratedCode::Texture> &p_texture_uniforms, RID *p_textures, bool p_use_linear_color); + void set_as_used(); virtual void set_render_priority(int p_priority) = 0; virtual void set_next_pass(RID p_pass) = 0; diff --git a/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp b/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp index 9eac2c3b85..1e91982fe1 100644 --- a/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp @@ -1116,6 +1116,7 @@ void ParticlesStorage::_particles_process(Particles *p_particles, double p_delta if (m->uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(m->uniform_set)) { RD::get_singleton()->compute_list_bind_uniform_set(compute_list, m->uniform_set, 3); + m->set_as_used(); } RD::get_singleton()->compute_list_set_push_constant(compute_list, &push_constant, sizeof(ParticlesShader::PushConstant)); diff --git a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp index cc9f92de9b..67f013cfb0 100644 --- a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp @@ -582,6 +582,9 @@ bool TextureStorage::canvas_texture_get_uniform_set(RID p_texture, RS::CanvasIte } ct = t->canvas_texture; + if (t->render_target) { + t->render_target->was_used = true; + } } else { ct = canvas_texture_owner.get_or_null(p_texture); } @@ -612,6 +615,9 @@ bool TextureStorage::canvas_texture_get_uniform_set(RID p_texture, RS::CanvasIte } else { u.append_id(t->rd_texture); ct->size_cache = Size2i(t->width_2d, t->height_2d); + if (t->render_target) { + t->render_target->was_used = true; + } } uniforms.push_back(u); } @@ -627,6 +633,9 @@ bool TextureStorage::canvas_texture_get_uniform_set(RID p_texture, RS::CanvasIte } else { u.append_id(t->rd_texture); ct->use_normal_cache = true; + if (t->render_target) { + t->render_target->was_used = true; + } } uniforms.push_back(u); } @@ -642,6 +651,9 @@ bool TextureStorage::canvas_texture_get_uniform_set(RID p_texture, RS::CanvasIte } else { u.append_id(t->rd_texture); ct->use_specular_cache = true; + if (t->render_target) { + t->render_target->was_used = true; + } } uniforms.push_back(u); } @@ -2399,6 +2411,10 @@ void TextureStorage::_clear_render_target(RenderTarget *rt) { rt->color = RID(); rt->color_multisample = RID(); + if (rt->texture.is_valid()) { + Texture *tex = get_texture(rt->texture); + tex->render_target = nullptr; + } } void TextureStorage::_update_render_target(RenderTarget *rt) { @@ -2479,6 +2495,7 @@ void TextureStorage::_update_render_target(RenderTarget *rt) { tex->rd_texture = RID(); tex->rd_texture_srgb = RID(); + tex->render_target = rt; //create shared textures to the color buffer, //so transparent can be supported diff --git a/servers/rendering/renderer_rd/storage_rd/texture_storage.h b/servers/rendering/renderer_rd/storage_rd/texture_storage.h index f4737eb63d..0c70d3f938 100644 --- a/servers/rendering/renderer_rd/storage_rd/texture_storage.h +++ b/servers/rendering/renderer_rd/storage_rd/texture_storage.h @@ -108,6 +108,8 @@ private: /* Texture API */ + struct RenderTarget; + class Texture { public: TextureType type; @@ -141,6 +143,7 @@ private: Vector<BufferSlice3D> buffer_slices_3d; uint32_t buffer_size_3d = 0; + RenderTarget *render_target = nullptr; bool is_render_target; bool is_proxy; |