Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
conditionally save stencil
  • Loading branch information
jonahwilliams committed Oct 27, 2023
commit fa8ebf8e057381693ad2a31a6088e68553885003
1 change: 1 addition & 0 deletions impeller/aiks/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ void Canvas::ClipGeometry(std::unique_ptr<Geometry> geometry,
entity.SetClipDepth(GetClipDepth());

GetCurrentPass().AddEntity(entity);
GetCurrentPass().ContainsClip();

++xformation_stack_.back().clip_depth;
xformation_stack_.back().contains_clips = true;
Expand Down
22 changes: 10 additions & 12 deletions impeller/entity/entity_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ bool EntityPass::Render(ContentContext& renderer,
// there's no need to set up a stencil attachment on the root render target.
if (!supports_onscreen_backdrop_reads && reads_from_onscreen_backdrop) {
auto offscreen_target = CreateRenderTarget(
renderer, root_render_target.GetRenderTargetSize(), true,
renderer, root_render_target.GetRenderTargetSize(), clips_applied_,
GetClearColor(render_target.GetRenderTargetSize()));

if (!OnRender(renderer, // renderer
Expand Down Expand Up @@ -500,7 +500,6 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
//--------------------------------------------------------------------------
/// Setup entity element.
///

if (const auto& entity = std::get_if<Entity>(&element)) {
element_entity = *entity;
element_entity.SetCapture(capture.CreateChild("Entity"));
Expand All @@ -512,16 +511,15 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
Matrix::MakeTranslation(Vector3(-global_pass_position)) *
element_entity.GetTransformation());
}
return EntityPass::EntityResult::Success(element_entity);
}

//--------------------------------------------------------------------------
/// Setup subpass element.
///

else if (const auto& subpass_ptr =
std::get_if<std::unique_ptr<EntityPass>>(&element)) {
if (const auto& subpass_ptr =
std::get_if<std::unique_ptr<EntityPass>>(&element)) {
auto subpass = subpass_ptr->get();

if (subpass->delegate_->CanElide()) {
return EntityPass::EntityResult::Skip();
}
Expand Down Expand Up @@ -691,11 +689,10 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
element_entity.SetTransformation(subpass_texture_capture.AddMatrix(
"Transform", Matrix::MakeTranslation(Vector3(subpass_coverage->origin -
global_pass_position))));
} else {
FML_UNREACHABLE();
}

return EntityPass::EntityResult::Success(element_entity);
return EntityPass::EntityResult::Success(element_entity);
}
FML_UNREACHABLE();
}

bool EntityPass::RenderElement(Entity& element_entity,
Expand Down Expand Up @@ -854,8 +851,9 @@ bool EntityPass::OnRender(
TRACE_EVENT0("impeller", "EntityPass::OnRender");

auto context = renderer.GetContext();
InlinePassContext pass_context(
context, pass_target, GetTotalPassReads(renderer), collapsed_parent_pass);
InlinePassContext pass_context(context, pass_target,
GetTotalPassReads(renderer), clips_applied_,
collapsed_parent_pass);
if (!pass_context.IsValid()) {
VALIDATION_LOG << SPrintF("Pass context invalid (Depth=%d)", pass_depth);
return false;
Expand Down
10 changes: 10 additions & 0 deletions impeller/entity/entity_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ class EntityPass {
std::optional<Rect> GetElementsCoverage(
std::optional<Rect> coverage_limit) const;

void ContainsClip() {
clips_applied_ = true;
}

private:
struct EntityResult {
enum Status {
Expand Down Expand Up @@ -297,6 +301,12 @@ class EntityPass {
uint32_t advanced_blend_reads_from_pass_texture_ = 0;
uint32_t backdrop_filter_reads_from_pass_texture_ = 0;

/// The number of clips applied in the current entity pass.
///
/// If this value is zero, then the stencil buffer does not have to be stored
/// between backdrop filters.
bool clips_applied_ = false;

uint32_t GetTotalPassReads(ContentContext& renderer) const;

BackdropFilterProc backdrop_filter_proc_ = nullptr;
Expand Down
10 changes: 6 additions & 4 deletions impeller/entity/inline_pass_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ InlinePassContext::InlinePassContext(
std::shared_ptr<Context> context,
EntityPassTarget& pass_target,
uint32_t pass_texture_reads,
bool contains_clips,
std::optional<RenderPassResult> collapsed_parent_pass)
: context_(std::move(context)),
pass_target_(pass_target),
total_pass_reads_(pass_texture_reads),
contains_clips_(contains_clips),
is_collapsed_(collapsed_parent_pass.has_value()) {
if (collapsed_parent_pass.has_value()) {
pass_ = collapsed_parent_pass.value().pass;
Expand Down Expand Up @@ -142,15 +144,15 @@ InlinePassContext::RenderPassResult InlinePassContext::GetRenderPass(

// Only clear the stencil if this is the very first pass of the
// layer.
stencil->load_action =
pass_count_ > 0 ? LoadAction::kLoad : LoadAction::kClear;
stencil->load_action = (pass_count_ > 0 && contains_clips_)
? LoadAction::kLoad
: LoadAction::kClear;
// If we're on the last pass of the layer, there's no need to store the
// stencil because nothing needs to read it.
stencil->store_action = pass_count_ == total_pass_reads_
stencil->store_action = (pass_count_ == total_pass_reads_ || !contains_clips_)
? StoreAction::kDontCare
: StoreAction::kStore;
pass_target_.target_.SetStencilAttachment(stencil.value());

pass_target_.target_.SetColorAttachment(color0, 0);

pass_ = command_buffer_->CreateRenderPass(pass_target_.GetRenderTarget());
Expand Down
2 changes: 2 additions & 0 deletions impeller/entity/inline_pass_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class InlinePassContext {
std::shared_ptr<Context> context,
EntityPassTarget& pass_target,
uint32_t pass_texture_reads,
bool contains_clips,
std::optional<RenderPassResult> collapsed_parent_pass = std::nullopt);
~InlinePassContext();

Expand All @@ -41,6 +42,7 @@ class InlinePassContext {
std::shared_ptr<RenderPass> pass_;
uint32_t pass_count_ = 0;
uint32_t total_pass_reads_ = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good riddance...

bool contains_clips_ = false;
// Whether this context is collapsed into a parent entity pass.
bool is_collapsed_ = false;

Expand Down