Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] Use booleans instead of counting backdrop reads. #52181

Merged
merged 1 commit into from
Apr 17, 2024
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
22 changes: 11 additions & 11 deletions impeller/entity/entity_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -277,10 +277,10 @@ EntityPass* EntityPass::AddSubpass(std::unique_ptr<EntityPass> 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();
Expand All @@ -299,9 +299,11 @@ void EntityPass::AddSubpassInline(std::unique_ptr<EntityPass> 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_;
}

Expand Down Expand Up @@ -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_;
}

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions impeller/entity/entity_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion impeller/entity/inline_pass_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<RenderPassResult> collapsed_parent_pass)
: renderer_(renderer),
Expand Down
1 change: 0 additions & 1 deletion impeller/entity/inline_pass_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class InlinePassContext {
InlinePassContext(
const ContentContext& renderer,
EntityPassTarget& pass_target,
uint32_t pass_texture_reads,
uint32_t entity_count,
std::optional<RenderPassResult> collapsed_parent_pass = std::nullopt);

Expand Down