Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure 2D MSAA resolve is performed when 3D content but no 2D content in scene #84957

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions drivers/gles3/storage/texture_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,9 @@ class TextureStorage : public RendererTextureStorage {
void render_target_clear_used(RID p_render_target);
virtual void render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa) override;
virtual RS::ViewportMSAA render_target_get_msaa(RID p_render_target) const override;
virtual void render_target_set_msaa_needs_resolve(RID p_render_target, bool p_needs_resolve) override {}
virtual bool render_target_get_msaa_needs_resolve(RID p_render_target) const override { return false; }
virtual void render_target_do_msaa_resolve(RID p_render_target) override {}
virtual void render_target_set_use_hdr(RID p_render_target, bool p_use_hdr_2d) override {}
virtual bool render_target_is_using_hdr(RID p_render_target) const override { return false; }

Expand Down
3 changes: 3 additions & 0 deletions servers/rendering/dummy/storage/texture_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ class TextureStorage : public RendererTextureStorage {
virtual void render_target_set_as_unused(RID p_render_target) override {}
virtual void render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa) override {}
virtual RS::ViewportMSAA render_target_get_msaa(RID p_render_target) const override { return RS::VIEWPORT_MSAA_DISABLED; }
virtual void render_target_set_msaa_needs_resolve(RID p_render_target, bool p_needs_resolve) override {}
virtual bool render_target_get_msaa_needs_resolve(RID p_render_target) const override { return false; }
virtual void render_target_do_msaa_resolve(RID p_render_target) override {}
virtual void render_target_set_use_hdr(RID p_render_target, bool p_use_hdr_2d) override {}
virtual bool render_target_is_using_hdr(RID p_render_target) const override { return false; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ RID RenderForwardMobile::RenderBufferDataForwardMobile::get_color_fbs(Framebuffe
target_buffer = texture_storage->render_target_get_rd_texture(render_target);
} else {
target_buffer = texture_storage->render_target_get_rd_texture_msaa(render_target);
texture_storage->render_target_set_msaa_needs_resolve(render_target, true); // Make sure this gets resolved.
}
ERR_FAIL_COND_V(target_buffer.is_null(), RID());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ void RendererCanvasRenderRD::_render_items(RID p_to_render_target, int p_item_co
fb_uniform_set = texture_storage->render_target_get_backbuffer_uniform_set(p_to_render_target);
} else {
framebuffer = texture_storage->render_target_get_rd_framebuffer(p_to_render_target);
texture_storage->render_target_set_msaa_needs_resolve(p_to_render_target, false); // If MSAA is enabled, our framebuffer will be resolved!

if (texture_storage->render_target_is_clear_requested(p_to_render_target)) {
clear = true;
Expand Down
3 changes: 3 additions & 0 deletions servers/rendering/renderer_rd/renderer_scene_render_rd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ void RendererSceneRenderRD::_render_buffers_post_process_and_tonemap(const Rende

if (dest_is_msaa_2d) {
dest_fb = FramebufferCacheRD::get_singleton()->get_cache(texture_storage->render_target_get_rd_texture_msaa(render_target));
texture_storage->render_target_set_msaa_needs_resolve(render_target, true); // Make sure this gets resolved.
} else {
dest_fb = texture_storage->render_target_get_rd_framebuffer(render_target);
}
Expand All @@ -611,6 +612,8 @@ void RendererSceneRenderRD::_render_buffers_post_process_and_tonemap(const Rende
RID source_texture = texture_storage->render_target_get_rd_texture(render_target);
RID dest_fb = FramebufferCacheRD::get_singleton()->get_cache(texture_storage->render_target_get_rd_texture_msaa(render_target));
copy_effects->copy_to_fb_rect(source_texture, dest_fb, Rect2i(Point2i(), rb->get_target_size()));

texture_storage->render_target_set_msaa_needs_resolve(render_target, true); // Make sure this gets resolved.
}

RD::get_singleton()->draw_command_end_label();
Expand Down
26 changes: 26 additions & 0 deletions servers/rendering/renderer_rd/storage_rd/texture_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3364,6 +3364,31 @@ RS::ViewportMSAA TextureStorage::render_target_get_msaa(RID p_render_target) con
return rt->msaa;
}

void TextureStorage::render_target_set_msaa_needs_resolve(RID p_render_target, bool p_needs_resolve) {
RenderTarget *rt = render_target_owner.get_or_null(p_render_target);
ERR_FAIL_NULL(rt);

rt->msaa_needs_resolve = p_needs_resolve;
}

bool TextureStorage::render_target_get_msaa_needs_resolve(RID p_render_target) const {
RenderTarget *rt = render_target_owner.get_or_null(p_render_target);
ERR_FAIL_NULL_V(rt, false);

return rt->msaa_needs_resolve;
}

void TextureStorage::render_target_do_msaa_resolve(RID p_render_target) {
RenderTarget *rt = render_target_owner.get_or_null(p_render_target);
ERR_FAIL_NULL(rt);
if (!rt->msaa_needs_resolve) {
return;
}
RD::get_singleton()->draw_list_begin(rt->get_framebuffer(), RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD);
RD::get_singleton()->draw_list_end();
rt->msaa_needs_resolve = false;
}

void TextureStorage::render_target_set_use_hdr(RID p_render_target, bool p_use_hdr) {
RenderTarget *rt = render_target_owner.get_or_null(p_render_target);
ERR_FAIL_NULL(rt);
Expand Down Expand Up @@ -3479,6 +3504,7 @@ void TextureStorage::render_target_do_clear_request(RID p_render_target) {
RD::get_singleton()->draw_list_begin(rt->get_framebuffer(), RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD, clear_colors);
RD::get_singleton()->draw_list_end();
rt->clear_requested = false;
rt->msaa_needs_resolve = false;
}

void TextureStorage::render_target_set_sdf_size_and_scale(RID p_render_target, RS::ViewportSDFOversize p_size, RS::ViewportSDFScale p_scale) {
Expand Down
8 changes: 6 additions & 2 deletions servers/rendering/renderer_rd/storage_rd/texture_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,10 @@ class TextureStorage : public RendererTextureStorage {
uint32_t view_count;
RID color;
Vector<RID> color_slices;
RID color_multisample; // Needed when MSAA is enabled.
RID color_multisample; // Needed when 2D MSAA is enabled.

RS::ViewportMSAA msaa = RS::VIEWPORT_MSAA_DISABLED;
RS::ViewportMSAA msaa = RS::VIEWPORT_MSAA_DISABLED; // 2D MSAA mode
bool msaa_needs_resolve = false; // 2D MSAA needs resolved

//used for retrieving from CPU
RD::DataFormat color_format = RD::DATA_FORMAT_R4G4_UNORM_PACK8;
Expand Down Expand Up @@ -718,6 +719,9 @@ class TextureStorage : public RendererTextureStorage {
virtual void render_target_set_as_unused(RID p_render_target) override;
virtual void render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa) override;
virtual RS::ViewportMSAA render_target_get_msaa(RID p_render_target) const override;
virtual void render_target_set_msaa_needs_resolve(RID p_render_target, bool p_needs_resolve) override;
virtual bool render_target_get_msaa_needs_resolve(RID p_render_target) const override;
virtual void render_target_do_msaa_resolve(RID p_render_target) override;
virtual void render_target_set_use_hdr(RID p_render_target, bool p_use_hdr) override;
virtual bool render_target_is_using_hdr(RID p_render_target) const override;

Expand Down
5 changes: 5 additions & 0 deletions servers/rendering/renderer_viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,11 @@ void RendererViewport::_draw_viewport(Viewport *p_viewport) {
RSG::texture_storage->render_target_do_clear_request(p_viewport->render_target);
}

if (RSG::texture_storage->render_target_get_msaa_needs_resolve(p_viewport->render_target)) {
WARN_PRINT_ONCE("2D MSAA is enabled while there is no 2D content. Disable 2D MSAA for better performance.");
RSG::texture_storage->render_target_do_msaa_resolve(p_viewport->render_target);
}

if (p_viewport->measure_render_time) {
String rt_id = "vp_end_" + itos(p_viewport->self.get_id());
RSG::utilities->capture_timestamp(rt_id);
Expand Down
3 changes: 3 additions & 0 deletions servers/rendering/storage/texture_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ class RendererTextureStorage {
virtual void render_target_set_as_unused(RID p_render_target) = 0;
virtual void render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa) = 0;
virtual RS::ViewportMSAA render_target_get_msaa(RID p_render_target) const = 0;
virtual void render_target_set_msaa_needs_resolve(RID p_render_target, bool p_needs_resolve) = 0;
virtual bool render_target_get_msaa_needs_resolve(RID p_render_target) const = 0;
virtual void render_target_do_msaa_resolve(RID p_render_target) = 0;
virtual void render_target_set_use_hdr(RID p_render_target, bool p_use_hdr) = 0;
virtual bool render_target_is_using_hdr(RID p_render_target) const = 0;

Expand Down
Loading