summaryrefslogtreecommitdiff
path: root/servers/rendering/renderer_rd/storage_rd
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-12-17 12:26:51 +0100
committerRémi Verschelde <rverschelde@gmail.com>2022-12-17 12:26:51 +0100
commit676f60b0ccd38df41648b942fe9b437ac3ea954a (patch)
tree0a1fa5f3c1f8bfa4a25e72eb6abb6b6ee51230eb /servers/rendering/renderer_rd/storage_rd
parent376290ea86b70c15452ec97e1cd1937c319383b1 (diff)
parent1b330820bf4c145060462624534dea81055a8bf0 (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/storage_rd')
-rw-r--r--servers/rendering/renderer_rd/storage_rd/material_storage.cpp11
-rw-r--r--servers/rendering/renderer_rd/storage_rd/material_storage.h4
-rw-r--r--servers/rendering/renderer_rd/storage_rd/particles_storage.cpp1
-rw-r--r--servers/rendering/renderer_rd/storage_rd/texture_storage.cpp17
-rw-r--r--servers/rendering/renderer_rd/storage_rd/texture_storage.h3
5 files changed, 36 insertions, 0 deletions
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;