Skip to content

Commit 599a2be

Browse files
committed
Revert "[Impeller] stencil buffer record/replay instead of MSAA storage. (flutter#47397)"
This reverts commit 04329c5.
1 parent 2e4ba9c commit 599a2be

File tree

4 files changed

+35
-71
lines changed

4 files changed

+35
-71
lines changed

impeller/entity/entity_pass.cc

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,18 @@ void EntityPass::AddSubpassInline(std::unique_ptr<EntityPass> pass) {
238238
pass->advanced_blend_reads_from_pass_texture_;
239239
}
240240

241-
static const constexpr RenderTarget::AttachmentConfig kDefaultStencilConfig =
242-
RenderTarget::AttachmentConfig{
243-
.storage_mode = StorageMode::kDeviceTransient,
244-
.load_action = LoadAction::kDontCare,
245-
.store_action = StoreAction::kDontCare,
246-
};
241+
static RenderTarget::AttachmentConfig GetDefaultStencilConfig(bool readable) {
242+
return RenderTarget::AttachmentConfig{
243+
.storage_mode = readable ? StorageMode::kDevicePrivate
244+
: StorageMode::kDeviceTransient,
245+
.load_action = LoadAction::kDontCare,
246+
.store_action = StoreAction::kDontCare,
247+
};
248+
}
247249

248250
static EntityPassTarget CreateRenderTarget(ContentContext& renderer,
249251
ISize size,
252+
bool readable,
250253
const Color& clear_color) {
251254
auto context = renderer.GetContext();
252255

@@ -267,8 +270,8 @@ static EntityPassTarget CreateRenderTarget(ContentContext& renderer,
267270
.resolve_storage_mode = StorageMode::kDevicePrivate,
268271
.load_action = LoadAction::kDontCare,
269272
.store_action = StoreAction::kMultisampleResolve,
270-
.clear_color = clear_color}, // color_attachment_config
271-
kDefaultStencilConfig // stencil_attachment_config
273+
.clear_color = clear_color}, // color_attachment_config
274+
GetDefaultStencilConfig(readable) // stencil_attachment_config
272275
);
273276
} else {
274277
target = RenderTarget::CreateOffscreen(
@@ -281,8 +284,8 @@ static EntityPassTarget CreateRenderTarget(ContentContext& renderer,
281284
.load_action = LoadAction::kDontCare,
282285
.store_action = StoreAction::kDontCare,
283286
.clear_color = clear_color,
284-
}, // color_attachment_config
285-
kDefaultStencilConfig // stencil_attachment_config
287+
}, // color_attachment_config
288+
GetDefaultStencilConfig(readable) // stencil_attachment_config
286289
);
287290
}
288291

@@ -340,7 +343,7 @@ bool EntityPass::Render(ContentContext& renderer,
340343
// there's no need to set up a stencil attachment on the root render target.
341344
if (reads_from_onscreen_backdrop) {
342345
auto offscreen_target = CreateRenderTarget(
343-
renderer, root_render_target.GetRenderTargetSize(),
346+
renderer, root_render_target.GetRenderTargetSize(), true,
344347
GetClearColorOrDefault(render_target.GetRenderTargetSize()));
345348

346349
if (!OnRender(renderer, // renderer
@@ -442,7 +445,8 @@ bool EntityPass::Render(ContentContext& renderer,
442445
*renderer.GetContext(), *renderer.GetRenderTargetCache(),
443446
color0.texture->GetSize(),
444447
renderer.GetContext()->GetCapabilities()->SupportsOffscreenMSAA(),
445-
"ImpellerOnscreen", kDefaultStencilConfig);
448+
"ImpellerOnscreen",
449+
GetDefaultStencilConfig(reads_from_onscreen_backdrop));
446450
}
447451

448452
// Set up the clear color of the root pass.
@@ -479,10 +483,10 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
479483
//--------------------------------------------------------------------------
480484
/// Setup entity element.
481485
///
486+
482487
if (const auto& entity = std::get_if<Entity>(&element)) {
483488
Entity element_entity = entity->Clone();
484489
element_entity.SetCapture(capture.CreateChild("Entity"));
485-
486490
if (!global_pass_position.IsZero()) {
487491
// If the pass image is going to be rendered with a non-zero position,
488492
// apply the negative translation to entity copies before rendering them
@@ -497,9 +501,11 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
497501
//--------------------------------------------------------------------------
498502
/// Setup subpass element.
499503
///
500-
if (const auto& subpass_ptr =
501-
std::get_if<std::unique_ptr<EntityPass>>(&element)) {
504+
505+
else if (const auto& subpass_ptr =
506+
std::get_if<std::unique_ptr<EntityPass>>(&element)) {
502507
auto subpass = subpass_ptr->get();
508+
503509
if (subpass->delegate_->CanElide()) {
504510
return EntityPass::EntityResult::Skip();
505511
}
@@ -602,6 +608,7 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
602608
auto subpass_target = CreateRenderTarget(
603609
renderer, // renderer
604610
subpass_size, // size
611+
subpass->GetTotalPassReads(renderer) > 0, // readable
605612
subpass->GetClearColorOrDefault(subpass_size)); // clear_color
606613

607614
if (!subpass_target.IsValid()) {
@@ -675,6 +682,7 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
675682

676683
return EntityPass::EntityResult::Success(std::move(element_entity));
677684
}
685+
678686
FML_UNREACHABLE();
679687
}
680688

@@ -699,15 +707,6 @@ bool EntityPass::RenderElement(Entity& element_entity,
699707
// blit the non-MSAA resolve texture of the previous pass to MSAA textures
700708
// (let alone a transient one).
701709
if (result.backdrop_texture) {
702-
// Restore any clips that were recorded before the backdrop filter was
703-
// applied.
704-
auto& replay_entities = clip_replay_->GetReplayEntities();
705-
for (const auto& entity : replay_entities) {
706-
if (!entity.Render(renderer, *result.pass)) {
707-
VALIDATION_LOG << "Failed to render entity for clip restore.";
708-
}
709-
}
710-
711710
auto size_rect = Rect::MakeSize(result.pass->GetRenderTargetSize());
712711
auto msaa_backdrop_contents = TextureContents::MakeRect(size_rect);
713712
msaa_backdrop_contents->SetStencilEnabled(false);
@@ -815,7 +814,6 @@ bool EntityPass::RenderElement(Entity& element_entity,
815814
#endif
816815

817816
element_entity.SetClipDepth(element_entity.GetClipDepth() - clip_depth_floor);
818-
clip_replay_->RecordEntity(element_entity, clip_coverage.type);
819817
if (!element_entity.Render(renderer, *result.pass)) {
820818
VALIDATION_LOG << "Failed to render entity.";
821819
return false;
@@ -1167,24 +1165,4 @@ void EntityPass::SetEnableOffscreenCheckerboard(bool enabled) {
11671165
enable_offscreen_debug_checkerboard_ = enabled;
11681166
}
11691167

1170-
EntityPassClipRecorder::EntityPassClipRecorder() {}
1171-
1172-
void EntityPassClipRecorder::RecordEntity(const Entity& entity,
1173-
Contents::ClipCoverage::Type type) {
1174-
switch (type) {
1175-
case Contents::ClipCoverage::Type::kNoChange:
1176-
return;
1177-
case Contents::ClipCoverage::Type::kAppend:
1178-
rendered_clip_entities_.push_back(entity.Clone());
1179-
break;
1180-
case Contents::ClipCoverage::Type::kRestore:
1181-
rendered_clip_entities_.pop_back();
1182-
break;
1183-
}
1184-
}
1185-
1186-
const std::vector<Entity>& EntityPassClipRecorder::GetReplayEntities() const {
1187-
return rendered_clip_entities_;
1188-
}
1189-
11901168
} // namespace impeller

impeller/entity/entity_pass.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
namespace impeller {
2222

2323
class ContentContext;
24-
class EntityPassClipRecorder;
2524

2625
class EntityPass {
2726
public:
@@ -295,8 +294,6 @@ class EntityPass {
295294
bool flood_clip_ = false;
296295
bool enable_offscreen_debug_checkerboard_ = false;
297296
std::optional<Rect> bounds_limit_;
298-
std::unique_ptr<EntityPassClipRecorder> clip_replay_ =
299-
std::make_unique<EntityPassClipRecorder>();
300297

301298
/// These values are incremented whenever something is added to the pass that
302299
/// requires reading from the backdrop texture. Currently, this can happen in
@@ -321,26 +318,6 @@ class EntityPass {
321318
EntityPass& operator=(const EntityPass&) = delete;
322319
};
323320

324-
/// @brief A class that tracks all clips that have been recorded in the current
325-
/// entity pass stencil.
326-
///
327-
/// These clips are replayed when restoring the backdrop so that the
328-
/// stencil buffer is left in an identical state.
329-
class EntityPassClipRecorder {
330-
public:
331-
EntityPassClipRecorder();
332-
333-
~EntityPassClipRecorder() = default;
334-
335-
/// @brief Record the entity based on the provided coverage [type].
336-
void RecordEntity(const Entity& entity, Contents::ClipCoverage::Type type);
337-
338-
const std::vector<Entity>& GetReplayEntities() const;
339-
340-
private:
341-
std::vector<Entity> rendered_clip_entities_;
342-
};
343-
344321
} // namespace impeller
345322

346323
#endif // FLUTTER_IMPELLER_ENTITY_ENTITY_PASS_H_

impeller/entity/inline_pass_context.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ InlinePassContext::InlinePassContext(
2323
: context_(std::move(context)),
2424
pass_target_(pass_target),
2525
entity_count_(entity_count),
26+
total_pass_reads_(pass_texture_reads),
2627
is_collapsed_(collapsed_parent_pass.has_value()) {
2728
if (collapsed_parent_pass.has_value()) {
2829
pass_ = collapsed_parent_pass.value().pass;
@@ -141,9 +142,17 @@ InlinePassContext::RenderPassResult InlinePassContext::GetRenderPass(
141142
return {};
142143
}
143144

144-
stencil->load_action = LoadAction::kClear;
145-
stencil->store_action = StoreAction::kDontCare;
145+
// Only clear the stencil if this is the very first pass of the
146+
// layer.
147+
stencil->load_action =
148+
pass_count_ > 0 ? LoadAction::kLoad : LoadAction::kClear;
149+
// If we're on the last pass of the layer, there's no need to store the
150+
// stencil because nothing needs to read it.
151+
stencil->store_action = pass_count_ == total_pass_reads_
152+
? StoreAction::kDontCare
153+
: StoreAction::kStore;
146154
pass_target_.target_.SetStencilAttachment(stencil.value());
155+
147156
pass_target_.target_.SetColorAttachment(color0, 0);
148157

149158
pass_ = command_buffer_->CreateRenderPass(pass_target_.GetRenderTarget());

impeller/entity/inline_pass_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class InlinePassContext {
5151
std::shared_ptr<RenderPass> pass_;
5252
uint32_t pass_count_ = 0;
5353
uint32_t entity_count_ = 0;
54-
54+
uint32_t total_pass_reads_ = 0;
5555
// Whether this context is collapsed into a parent entity pass.
5656
bool is_collapsed_ = false;
5757

0 commit comments

Comments
 (0)