From df1248e088d6ef4684ae14ebb03ea5ec9db0a167 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Wed, 17 Apr 2024 11:43:17 -0700 Subject: [PATCH] [Impeller] Use booleans instead of counting backdrop reads. (flutter/engine#52181) We don't need to track the actual number of reads anymore now that clips are replayed (since we no longer ever store the stencil or depth buffers). Also, we don't need to pass this into `InlinePassContext` anymore. --- .../flutter/impeller/entity/entity_pass.cc | 22 +++++++++---------- .../src/flutter/impeller/entity/entity_pass.h | 14 ++++++------ .../impeller/entity/inline_pass_context.cc | 1 - .../impeller/entity/inline_pass_context.h | 1 - 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/engine/src/flutter/impeller/entity/entity_pass.cc b/engine/src/flutter/impeller/entity/entity_pass.cc index ff6327a8a0d..89a2d90c27c 100644 --- a/engine/src/flutter/impeller/entity/entity_pass.cc +++ b/engine/src/flutter/impeller/entity/entity_pass.cc @@ -110,7 +110,7 @@ void EntityPass::AddEntity(Entity entity) { } if (entity.GetBlendMode() > Entity::kLastPipelineBlendMode) { - advanced_blend_reads_from_pass_texture_ += 1; + advanced_blend_reads_from_pass_texture_ = true; } elements_.emplace_back(std::move(entity)); } @@ -277,10 +277,10 @@ EntityPass* EntityPass::AddSubpass(std::unique_ptr pass) { pass->superpass_ = this; if (pass->backdrop_filter_proc_) { - backdrop_filter_reads_from_pass_texture_ += 1; + backdrop_filter_reads_from_pass_texture_ = true; } if (pass->blend_mode_ > Entity::kLastPipelineBlendMode) { - advanced_blend_reads_from_pass_texture_ += 1; + advanced_blend_reads_from_pass_texture_ = true; } auto subpass_pointer = pass.get(); @@ -299,9 +299,11 @@ void EntityPass::AddSubpassInline(std::unique_ptr pass) { elements_.emplace_back(std::move(elements[i])); } - backdrop_filter_reads_from_pass_texture_ += + backdrop_filter_reads_from_pass_texture_ = + backdrop_filter_reads_from_pass_texture_ || pass->backdrop_filter_reads_from_pass_texture_; - advanced_blend_reads_from_pass_texture_ += + advanced_blend_reads_from_pass_texture_ = + advanced_blend_reads_from_pass_texture_ || pass->advanced_blend_reads_from_pass_texture_; } @@ -366,10 +368,10 @@ static EntityPassTarget CreateRenderTarget(ContentContext& renderer, renderer.GetDeviceCapabilities().SupportsImplicitResolvingMSAA()); } -uint32_t EntityPass::GetTotalPassReads(ContentContext& renderer) const { +bool EntityPass::DoesBackdropGetRead(ContentContext& renderer) const { return renderer.GetDeviceCapabilities().SupportsFramebufferFetch() ? backdrop_filter_reads_from_pass_texture_ - : backdrop_filter_reads_from_pass_texture_ + + : backdrop_filter_reads_from_pass_texture_ || advanced_blend_reads_from_pass_texture_; } @@ -413,11 +415,10 @@ bool EntityPass::Render(ContentContext& renderer, EntityPassClipStack clip_stack = EntityPassClipStack( Rect::MakeSize(root_render_target.GetRenderTargetSize())); - bool reads_from_onscreen_backdrop = GetTotalPassReads(renderer) > 0; // In this branch path, we need to render everything to an offscreen texture // and then blit the results onto the onscreen texture. If using this branch, // there's no need to set up a stencil attachment on the root render target. - if (reads_from_onscreen_backdrop) { + if (DoesBackdropGetRead(renderer)) { EntityPassTarget offscreen_target = CreateRenderTarget( renderer, root_render_target.GetRenderTargetSize(), GetRequiredMipCount(), @@ -889,8 +890,7 @@ bool EntityPass::OnRender( pass_depth); } - InlinePassContext pass_context(renderer, pass_target, - GetTotalPassReads(renderer), GetElementCount(), + InlinePassContext pass_context(renderer, pass_target, GetElementCount(), collapsed_parent_pass); if (!pass_context.IsValid()) { VALIDATION_LOG << SPrintF("Pass context invalid (Depth=%d)", pass_depth); diff --git a/engine/src/flutter/impeller/entity/entity_pass.h b/engine/src/flutter/impeller/entity/entity_pass.h index 5fc017b873e..555921bdce1 100644 --- a/engine/src/flutter/impeller/entity/entity_pass.h +++ b/engine/src/flutter/impeller/entity/entity_pass.h @@ -346,18 +346,18 @@ class EntityPass { ContentBoundsPromise bounds_promise_ = ContentBoundsPromise::kUnknown; int32_t required_mip_count_ = 1; - /// These values are incremented whenever something is added to the pass that - /// requires reading from the backdrop texture. Currently, this can happen in - /// the following scenarios: + /// These values indicate whether something has been added to the EntityPass + /// that requires reading from the backdrop texture. Currently, this can + /// happen in the following scenarios: /// 1. An entity with an "advanced blend" is added to the pass. /// 2. A subpass with a backdrop filter is added to the pass. /// These are tracked as separate values because we may ignore - /// blend_reads_from_pass_texture_ if the device supports framebuffer based + /// `blend_reads_from_pass_texture_` if the device supports framebuffer based /// advanced blends. - uint32_t advanced_blend_reads_from_pass_texture_ = 0; - uint32_t backdrop_filter_reads_from_pass_texture_ = 0; + bool advanced_blend_reads_from_pass_texture_ = false; + bool backdrop_filter_reads_from_pass_texture_ = false; - uint32_t GetTotalPassReads(ContentContext& renderer) const; + bool DoesBackdropGetRead(ContentContext& renderer) const; BackdropFilterProc backdrop_filter_proc_ = nullptr; diff --git a/engine/src/flutter/impeller/entity/inline_pass_context.cc b/engine/src/flutter/impeller/entity/inline_pass_context.cc index 616d4f95437..1a1e2a92d88 100644 --- a/engine/src/flutter/impeller/entity/inline_pass_context.cc +++ b/engine/src/flutter/impeller/entity/inline_pass_context.cc @@ -20,7 +20,6 @@ namespace impeller { InlinePassContext::InlinePassContext( const ContentContext& renderer, EntityPassTarget& pass_target, - uint32_t pass_texture_reads, uint32_t entity_count, std::optional collapsed_parent_pass) : renderer_(renderer), diff --git a/engine/src/flutter/impeller/entity/inline_pass_context.h b/engine/src/flutter/impeller/entity/inline_pass_context.h index 93e69ff1737..a1cc84645a5 100644 --- a/engine/src/flutter/impeller/entity/inline_pass_context.h +++ b/engine/src/flutter/impeller/entity/inline_pass_context.h @@ -25,7 +25,6 @@ class InlinePassContext { InlinePassContext( const ContentContext& renderer, EntityPassTarget& pass_target, - uint32_t pass_texture_reads, uint32_t entity_count, std::optional collapsed_parent_pass = std::nullopt);