Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] fix clip culling with exp canvas. #54701

Merged
merged 4 commits into from
Aug 28, 2024

Conversation

jonahwilliams
Copy link
Member

@jonahwilliams jonahwilliams commented Aug 22, 2024

Fixes performance problem where image filters break clip culling, and lack of clip culling stops the clear color optimization from firing.

on the current canvas the cull rect computation is slightly incorrect, as we drop it as soon as we get a image filter. With the new canvas, we have the actual render target sizes, so we can correctly cull without it.

After switching to experimental canvas, I will remove the cull rect field from the canvas stack entry - as the clip coverage stack already performs basically the same culling.

This fixes the performance issue on the uncached zoom page transition where we lose the clear color optimization too early.

// layers, and so sub-DisplayLists are getting culled as if no filters are
// applied.
// See also: https://github.com/flutter/flutter/issues/139294
if (paint.image_filter) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Once we switch to exp canvas we can delete the cull rect and just use the clip stack which is 99% the same data.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the intention here is that if something outside of a DL applies an image filter then you need to cull the sub-dl by the "GetSourceCoverage" of that filter. No, it doesn't take that into account, the caller specifying the cull rect was supposed to...

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, wait, layers. We do expand the bounds of sub-layers by a filter applied on a parent layer...

void DisplayListBuilder::TransferLayerBounds(const SkRect& content_bounds) {

If rtree, then here:

if (AdjustRTreeRects(rtree_data_.value(), *filter, matrix, clip,

And if no rtree, then here:

if (!filter->map_device_bounds(global_ibounds, matrix, global_ibounds)) {

Copy link
Member Author

Choose a reason for hiding this comment

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

This comment isn't really accurate. I updated it to document that the cull rect logic gets deleted with new canvas.

@jonahwilliams jonahwilliams marked this pull request as ready for review August 23, 2024 01:19
@jonahwilliams jonahwilliams requested a review from flar August 27, 2024 23:08
if (coverage.has_value() &&
coverage->Contains(Rect::MakeSize(render_pass_size))) {
// Skip axis-aligned intersect clips that cover the whole render target
// since they won't draw anything to the depth buffer.
Copy link
Contributor

Choose a reason for hiding this comment

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

The DL code can deal with non-axis alignment but unfortunately it doesn't have access to this information. If we are axis aligned then this is the fast answer, but if we aren't then a slightly slower answer is to reverse transform the existin clip bounds corners by the ctm and then see if they are inside the geometry.

See:

bool DisplayListMatrixClipState::rect_covers_cull(const DlRect& content) const {

Also, it uses a different test - IsAligned2D instead of IsTranslationScaleOnly. Aligned allows for 90 degree rotations I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, why only do this on the render pass size? Why not skip it if it covers the entire existing clip bounds?

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm, we actually are also checking the clip bounds. These should already include the render pass size.

https://github.com/flutter/engine/blob/main/impeller/aiks/experimental_canvas.cc#L769-L797

Maybe this logic isn't necessary at all

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh, so the problem is that we always report the clip coverage as changing:

https://github.com/flutter/engine/blob/main/impeller/entity/entity_pass_clip_stack.cc#L69-L82

Even if the new clip coverage is bigger than the old clip coverage. We could move this check into the clip coverage stack and simplify this everywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, lets just move this logic into the clip coverage stack

Copy link
Contributor

@flar flar left a comment

Choose a reason for hiding this comment

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

Some questions.

@jonahwilliams jonahwilliams requested a review from flar August 28, 2024 20:07
@jonahwilliams
Copy link
Member Author

Updated this to move the logic into clip coverage stack

@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

Changes reported for pull request #54701 at sha 9464c00

@jonahwilliams
Copy link
Member Author

Uh oh, seems very broken!

@jonahwilliams
Copy link
Member Author

Ahh okay:

  1. I forgot about difference clips.

  2. The clip_contents returns the outer coverage of the clip, whereas for culling we need the inner rect. For now I've hacked so we flag non-axis aligned rects, but we can update impeller:Geometry with this concept and use that too.

Copy link
Contributor

@flar flar left a comment

Choose a reason for hiding this comment

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

LGTM

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 28, 2024
@auto-submit auto-submit bot merged commit 218b416 into flutter:main Aug 28, 2024
30 checks passed
@jonahwilliams jonahwilliams deleted the fix_cull_rect branch August 28, 2024 23:39
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 29, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 29, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 29, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 29, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 29, 2024
zanderso added a commit to flutter/flutter that referenced this pull request Aug 29, 2024
…154316)

Roll Flutter Engine from 8d248aead383 to f48ecf5b49f6 (40 revisions)

flutter/engine@8d248ae...f48ecf5

2024-08-29 jonahwilliams@google.com [Impeller] Use multiple command
buffers for blur submission. (flutter/engine#54846)
2024-08-29 skia-flutter-autoroll@skia.org Roll Skia from 0d8d9d2974fa to
e37b6b198016 (1 revision) (flutter/engine#54854)
2024-08-29 matanlurey@users.noreply.github.com Remove
`--disable-dart-dev` across `flutter/engine`. (flutter/engine#54845)
2024-08-28 skia-flutter-autoroll@skia.org Roll Fuchsia Test Scripts from
vIJGWtHj4Rdku9Ayv... to NWpblL_DFACOx_Spi... (flutter/engine#54852)
2024-08-28 jonahwilliams@google.com [Impeller] fix clip culling with exp
canvas. (flutter/engine#54701)
2024-08-28 skia-flutter-autoroll@skia.org Roll Dart SDK from
bc3dad16b2d3 to fed5ce7ea2ad (2 revisions) (flutter/engine#54851)
2024-08-28 skia-flutter-autoroll@skia.org Roll Skia from d55406ca32e9 to
0d8d9d2974fa (4 revisions) (flutter/engine#54850)
2024-08-28 jacksongardner@google.com [skwasm] Always do backdrop filter
operation even if empty. (flutter/engine#54844)
2024-08-28 matanlurey@users.noreply.github.com
Migrate`header_guard_check` to `package:test`. (flutter/engine#54811)
2024-08-28 skia-flutter-autoroll@skia.org Roll Fuchsia GN SDK from
OKGFjciA5Vd0TQks4... to ALNKvSVWQSpw1uxPy... (flutter/engine#54848)
2024-08-28 skia-flutter-autoroll@skia.org Roll Skia from cd3d3daafe55 to
d55406ca32e9 (10 revisions) (flutter/engine#54847)
2024-08-28 jonahwilliams@google.com [Impeller] ensure that srcOver to
src conversion takes stroke coverage into account.
(flutter/engine#54817)
2024-08-28 skia-flutter-autoroll@skia.org Roll Fuchsia GN SDK from
ALNKvSVWQSpw1uxPy... to OKGFjciA5Vd0TQks4... (flutter/engine#54840)
2024-08-28 matanlurey@users.noreply.github.com Remove scorecards and
other bading we are no longer tracking/links are borked
(flutter/engine#54839)
2024-08-28 omersa@google.com Compile dart2wasm modules using the JS
runtime exported compileStreaming (flutter/engine#51488)
2024-08-28 skia-flutter-autoroll@skia.org Roll Dart SDK from
183b9e21b706 to bc3dad16b2d3 (1 revision) (flutter/engine#54838)
2024-08-28 matanlurey@users.noreply.github.com Ignore generated fixture
`.dill.deps` files. (flutter/engine#54836)
2024-08-28 6844906+zijiehe-google-com@users.noreply.github.com
[fuchsia] use the api-level from gn-sdk (flutter/engine#54740)
2024-08-28 jonahwilliams@google.com [Impeller] port clip stack fixes to
new canvas. (flutter/engine#54727)
2024-08-28 jonahwilliams@google.com [Impeller] fall back to path
rendering on thick paths. (flutter/engine#54822)
2024-08-28 skia-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from
BCqzoTS_Sz6-AaSii... to ZL8AvfXX5LFIH1LYN... (flutter/engine#54834)
2024-08-28 skia-flutter-autoroll@skia.org Roll Skia from ca108745b1de to
cd3d3daafe55 (1 revision) (flutter/engine#54832)
2024-08-28 skia-flutter-autoroll@skia.org Roll Dart SDK from
42ddf2278114 to 183b9e21b706 (1 revision) (flutter/engine#54830)
2024-08-28 skia-flutter-autoroll@skia.org Roll Dart SDK from
b519f85c3076 to 42ddf2278114 (1 revision) (flutter/engine#54829)
2024-08-28 skia-flutter-autoroll@skia.org Roll Fuchsia GN SDK from
OKGFjciA5Vd0TQks4... to ALNKvSVWQSpw1uxPy... (flutter/engine#54827)
2024-08-28 skia-flutter-autoroll@skia.org Roll Skia from 41cb13f65fe6 to
ca108745b1de (1 revision) (flutter/engine#54828)
2024-08-28 skia-flutter-autoroll@skia.org Roll Skia from 259010335a55 to
41cb13f65fe6 (2 revisions) (flutter/engine#54826)
2024-08-28 skia-flutter-autoroll@skia.org Roll Skia from 505fb55cd044 to
259010335a55 (1 revision) (flutter/engine#54823)
2024-08-28 skia-flutter-autoroll@skia.org Roll Dart SDK from
8334290a421b to b519f85c3076 (1 revision) (flutter/engine#54821)
2024-08-28 skia-flutter-autoroll@skia.org Roll Skia from 84e4a69da303 to
505fb55cd044 (1 revision) (flutter/engine#54819)
2024-08-27 jonahwilliams@google.com [Impeller] Increase host buffer
arena count to 4. (flutter/engine#54808)
2024-08-27 flar@google.com Synchronize accounting for render op depths
(flutter/engine#54794)
2024-08-27 34871572+gmackall@users.noreply.github.com Fix broken links
in `docs/` (flutter/engine#54815)
2024-08-27 chinmaygarde@google.com [Impeller] Don't override user
specification on Vulkan validation in unopt. (flutter/engine#54816)
2024-08-27 skia-flutter-autoroll@skia.org Manual roll Dart SDK from
b81b344a194f to 8334290a421b (12 revisions) (flutter/engine#54813)
2024-08-27 skia-flutter-autoroll@skia.org Roll Skia from 77017d30a455 to
84e4a69da303 (3 revisions) (flutter/engine#54812)
2024-08-27 chinmaygarde@google.com [Impeller] Clarify where to put the
metadata in the manifest. (flutter/engine#54814)
2024-08-27 chinmaygarde@google.com [Impeller] Use infinite swapchain
present timeouts to avoid logspam. (flutter/engine#54810)
2024-08-27 skia-flutter-autoroll@skia.org Roll Skia from 2e1eea538014 to
77017d30a455 (2 revisions) (flutter/engine#54809)
2024-08-27 skia-flutter-autoroll@skia.org Roll Skia from a2e2eb292492 to
2e1eea538014 (4 revisions) (flutter/engine#54806)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from BCqzoTS_Sz6- to ZL8AvfXX5LFI

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
...

---------

Co-authored-by: Zachary Anderson <zanderso@users.noreply.github.com>
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
…lutter#154316)

Roll Flutter Engine from 8d248aead383 to f48ecf5b49f6 (40 revisions)

flutter/engine@8d248ae...f48ecf5

2024-08-29 jonahwilliams@google.com [Impeller] Use multiple command
buffers for blur submission. (flutter/engine#54846)
2024-08-29 skia-flutter-autoroll@skia.org Roll Skia from 0d8d9d2974fa to
e37b6b198016 (1 revision) (flutter/engine#54854)
2024-08-29 matanlurey@users.noreply.github.com Remove
`--disable-dart-dev` across `flutter/engine`. (flutter/engine#54845)
2024-08-28 skia-flutter-autoroll@skia.org Roll Fuchsia Test Scripts from
vIJGWtHj4Rdku9Ayv... to NWpblL_DFACOx_Spi... (flutter/engine#54852)
2024-08-28 jonahwilliams@google.com [Impeller] fix clip culling with exp
canvas. (flutter/engine#54701)
2024-08-28 skia-flutter-autoroll@skia.org Roll Dart SDK from
bc3dad16b2d3 to fed5ce7ea2ad (2 revisions) (flutter/engine#54851)
2024-08-28 skia-flutter-autoroll@skia.org Roll Skia from d55406ca32e9 to
0d8d9d2974fa (4 revisions) (flutter/engine#54850)
2024-08-28 jacksongardner@google.com [skwasm] Always do backdrop filter
operation even if empty. (flutter/engine#54844)
2024-08-28 matanlurey@users.noreply.github.com
Migrate`header_guard_check` to `package:test`. (flutter/engine#54811)
2024-08-28 skia-flutter-autoroll@skia.org Roll Fuchsia GN SDK from
OKGFjciA5Vd0TQks4... to ALNKvSVWQSpw1uxPy... (flutter/engine#54848)
2024-08-28 skia-flutter-autoroll@skia.org Roll Skia from cd3d3daafe55 to
d55406ca32e9 (10 revisions) (flutter/engine#54847)
2024-08-28 jonahwilliams@google.com [Impeller] ensure that srcOver to
src conversion takes stroke coverage into account.
(flutter/engine#54817)
2024-08-28 skia-flutter-autoroll@skia.org Roll Fuchsia GN SDK from
ALNKvSVWQSpw1uxPy... to OKGFjciA5Vd0TQks4... (flutter/engine#54840)
2024-08-28 matanlurey@users.noreply.github.com Remove scorecards and
other bading we are no longer tracking/links are borked
(flutter/engine#54839)
2024-08-28 omersa@google.com Compile dart2wasm modules using the JS
runtime exported compileStreaming (flutter/engine#51488)
2024-08-28 skia-flutter-autoroll@skia.org Roll Dart SDK from
183b9e21b706 to bc3dad16b2d3 (1 revision) (flutter/engine#54838)
2024-08-28 matanlurey@users.noreply.github.com Ignore generated fixture
`.dill.deps` files. (flutter/engine#54836)
2024-08-28 6844906+zijiehe-google-com@users.noreply.github.com
[fuchsia] use the api-level from gn-sdk (flutter/engine#54740)
2024-08-28 jonahwilliams@google.com [Impeller] port clip stack fixes to
new canvas. (flutter/engine#54727)
2024-08-28 jonahwilliams@google.com [Impeller] fall back to path
rendering on thick paths. (flutter/engine#54822)
2024-08-28 skia-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from
BCqzoTS_Sz6-AaSii... to ZL8AvfXX5LFIH1LYN... (flutter/engine#54834)
2024-08-28 skia-flutter-autoroll@skia.org Roll Skia from ca108745b1de to
cd3d3daafe55 (1 revision) (flutter/engine#54832)
2024-08-28 skia-flutter-autoroll@skia.org Roll Dart SDK from
42ddf2278114 to 183b9e21b706 (1 revision) (flutter/engine#54830)
2024-08-28 skia-flutter-autoroll@skia.org Roll Dart SDK from
b519f85c3076 to 42ddf2278114 (1 revision) (flutter/engine#54829)
2024-08-28 skia-flutter-autoroll@skia.org Roll Fuchsia GN SDK from
OKGFjciA5Vd0TQks4... to ALNKvSVWQSpw1uxPy... (flutter/engine#54827)
2024-08-28 skia-flutter-autoroll@skia.org Roll Skia from 41cb13f65fe6 to
ca108745b1de (1 revision) (flutter/engine#54828)
2024-08-28 skia-flutter-autoroll@skia.org Roll Skia from 259010335a55 to
41cb13f65fe6 (2 revisions) (flutter/engine#54826)
2024-08-28 skia-flutter-autoroll@skia.org Roll Skia from 505fb55cd044 to
259010335a55 (1 revision) (flutter/engine#54823)
2024-08-28 skia-flutter-autoroll@skia.org Roll Dart SDK from
8334290a421b to b519f85c3076 (1 revision) (flutter/engine#54821)
2024-08-28 skia-flutter-autoroll@skia.org Roll Skia from 84e4a69da303 to
505fb55cd044 (1 revision) (flutter/engine#54819)
2024-08-27 jonahwilliams@google.com [Impeller] Increase host buffer
arena count to 4. (flutter/engine#54808)
2024-08-27 flar@google.com Synchronize accounting for render op depths
(flutter/engine#54794)
2024-08-27 34871572+gmackall@users.noreply.github.com Fix broken links
in `docs/` (flutter/engine#54815)
2024-08-27 chinmaygarde@google.com [Impeller] Don't override user
specification on Vulkan validation in unopt. (flutter/engine#54816)
2024-08-27 skia-flutter-autoroll@skia.org Manual roll Dart SDK from
b81b344a194f to 8334290a421b (12 revisions) (flutter/engine#54813)
2024-08-27 skia-flutter-autoroll@skia.org Roll Skia from 77017d30a455 to
84e4a69da303 (3 revisions) (flutter/engine#54812)
2024-08-27 chinmaygarde@google.com [Impeller] Clarify where to put the
metadata in the manifest. (flutter/engine#54814)
2024-08-27 chinmaygarde@google.com [Impeller] Use infinite swapchain
present timeouts to avoid logspam. (flutter/engine#54810)
2024-08-27 skia-flutter-autoroll@skia.org Roll Skia from 2e1eea538014 to
77017d30a455 (2 revisions) (flutter/engine#54809)
2024-08-27 skia-flutter-autoroll@skia.org Roll Skia from a2e2eb292492 to
2e1eea538014 (4 revisions) (flutter/engine#54806)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from BCqzoTS_Sz6- to ZL8AvfXX5LFI

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
...

---------

Co-authored-by: Zachary Anderson <zanderso@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App e: impeller will affect goldens
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants