From e816e8d983e2f946e653ee14c9768eaac9d875ba Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Mon, 4 Mar 2024 14:10:20 -0800 Subject: [PATCH] [Impeller] Fix the clip replay mechanism. (flutter/engine#51173) Clips were being ignored whenever MSAA backdrop restores were being done by attachment load. Unblocks the StC flag flip: https://github.com/flutter/engine/pull/50856 Note that the new Gaussian blur does not currently work on GLES, and it's expected that this will cause backdrop blurs to cut a transparent hole wherever the backdrop blur should render. This happens because the gaussian blur renders as fully transparent black (among other things, it uses arrays of structs for the uniforms, which is unsupported in GLES). Then, the backdrop blur renders the blur's result with the `Source` blend mode, cutting out a hole in this case. --- engine/src/flutter/impeller/entity/entity_pass.cc | 14 ++++++++------ .../flutter/impeller/entity/inline_pass_context.cc | 1 + .../flutter/impeller/entity/inline_pass_context.h | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/impeller/entity/entity_pass.cc b/engine/src/flutter/impeller/entity/entity_pass.cc index f3f0f225c7..f85a383fb3 100644 --- a/engine/src/flutter/impeller/entity/entity_pass.cc +++ b/engine/src/flutter/impeller/entity/entity_pass.cc @@ -721,12 +721,7 @@ bool EntityPass::RenderElement(Entity& element_entity, return false; } - // If the pass context returns a backdrop texture, we need to draw it to the - // current pass. We do this because it's faster and takes significantly less - // memory than storing/loading large MSAA textures. Also, it's not possible to - // blit the non-MSAA resolve texture of the previous pass to MSAA textures - // (let alone a transient one). - if (result.backdrop_texture) { + if (result.just_created) { // Restore any clips that were recorded before the backdrop filter was // applied. auto& replay_entities = clip_replay_->GetReplayEntities(); @@ -735,7 +730,14 @@ bool EntityPass::RenderElement(Entity& element_entity, VALIDATION_LOG << "Failed to render entity for clip restore."; } } + } + // If the pass context returns a backdrop texture, we need to draw it to the + // current pass. We do this because it's faster and takes significantly less + // memory than storing/loading large MSAA textures. Also, it's not possible to + // blit the non-MSAA resolve texture of the previous pass to MSAA textures + // (let alone a transient one). + if (result.backdrop_texture) { auto size_rect = Rect::MakeSize(result.pass->GetRenderTargetSize()); auto msaa_backdrop_contents = TextureContents::MakeRect(size_rect); msaa_backdrop_contents->SetStencilEnabled(false); diff --git a/engine/src/flutter/impeller/entity/inline_pass_context.cc b/engine/src/flutter/impeller/entity/inline_pass_context.cc index d39d41394f..73b15b16a9 100644 --- a/engine/src/flutter/impeller/entity/inline_pass_context.cc +++ b/engine/src/flutter/impeller/entity/inline_pass_context.cc @@ -187,6 +187,7 @@ InlinePassContext::RenderPassResult InlinePassContext::GetRenderPass( " Count=" + std::to_string(pass_count_)); result.pass = pass_; + result.just_created = true; if (!renderer_.GetContext()->GetCapabilities()->SupportsReadFromResolve() && result.backdrop_texture == diff --git a/engine/src/flutter/impeller/entity/inline_pass_context.h b/engine/src/flutter/impeller/entity/inline_pass_context.h index 43ee0f6b98..93e69ff173 100644 --- a/engine/src/flutter/impeller/entity/inline_pass_context.h +++ b/engine/src/flutter/impeller/entity/inline_pass_context.h @@ -17,6 +17,7 @@ namespace impeller { class InlinePassContext { public: struct RenderPassResult { + bool just_created = false; std::shared_ptr pass; std::shared_ptr backdrop_texture; };