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] Use the scissor to limit all draws by clip coverage. #51698

Merged
merged 5 commits into from
Mar 27, 2024

Conversation

bdero
Copy link
Member

@bdero bdero commented Mar 27, 2024

Attempts to improve flutter/flutter#145274.

Our new clipping technique paints walls on the depth buffer "in front" of the Entities that will be affected by said clips. So when an intersect clip is drawn (the common case), the clip will cover the whole framebuffer.

Depth is divvied up such that deeper clips get drawn behind shallower clips, and so many clips actually don't end up drawing depth across the whole framebuffer. However, if the app does a lot of transitioning from a huge clips to a small clips, a lot of unnecessary depth churn occurs (very common in Flutter -- this happens with both the app bar and floating action button in the counter template, for example).

Since progressively deeper layers in the clip coverage stack always subset their parent layers, we can reduce waste for small intersect clips by setting the scissor to the clip coverage rect instead of drawing the clip to the whole screen.

Note that this change does not help much with huge/fullscreen clips.

Also, we could potentially improve this further by computing much stricter bounds. Rather than just using clip coverage for the scissor, we could intersect it with the union of all draws affected by the clip at the cost of a bit more CPU churn per draw. I don't think that's enough juice for the squeeze though.

Before (Play/AiksTest.CanRenderNestedClips/Metal):

Screen.Recording.2024-03-26.at.7.34.29.PM.mov

After (Play/AiksTest.CanRenderNestedClips/Metal):

Screen.Recording.2024-03-26.at.7.38.33.PM.mov

Comment on lines 767 to 770
scissor = IRect::MakeLTRB(std::floor(clip_coverage->GetLeft()),
std::floor(clip_coverage->GetTop()),
std::ceil(clip_coverage->GetRight()),
std::ceil(clip_coverage->GetBottom()));
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this IRect::RoundOut?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! Done.


struct ClipStateResult {
bool should_render = false;
bool clip_did_change = false;
Copy link
Member

Choose a reason for hiding this comment

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

should_render is sort of documemted on the method body, can you document what clip_did_change means?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM with nits

@bdero bdero added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 27, 2024
@auto-submit auto-submit bot merged commit e0f86b2 into flutter:main Mar 27, 2024
26 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 27, 2024
@bdero
Copy link
Member Author

bdero commented Mar 27, 2024

Reason for revert: Golden breakage on framework tree -- https://flutter-gold.skia.org/search?issue=145855&crs=github&patchsets=4&corpus=flutter

@bdero bdero added the revert Label used to revert changes in a closed and merged pull request. label Mar 27, 2024
auto-submit bot pushed a commit that referenced this pull request Mar 27, 2024
@auto-submit auto-submit bot removed the revert Label used to revert changes in a closed and merged pull request. label Mar 27, 2024
auto-submit bot added a commit that referenced this pull request Mar 27, 2024
…ge. (#51698)" (#51728)

Reverts: #51698
Initiated by: bdero
Reason for reverting: Golden breakage on framework tree -- https://flutter-gold.skia.org/search?issue=145855&crs=github&patchsets=4&corpus=flutter
Original PR Author: bdero

Reviewed By: {jonahwilliams}

This change reverts the following previous change:
Attempts to improve flutter/flutter#145274.

Our new clipping technique paints walls on the depth buffer "in front" of the Entities that will be affected by said clips. So when an intersect clip is drawn (the common case), the clip will cover the whole framebuffer.

Depth is divvied up such that deeper clips get drawn _behind_ shallower clips, and so many clips actually don't end up drawing depth across the whole framebuffer. However, if the app does a lot of transitioning from a huge clips to a small clips, a lot of unnecessary depth churn occurs (very common in Flutter -- this happens with both the app bar and floating action button in the counter template, for example).

Since progressively deeper layers in the clip coverage stack always subset their parent layers, we can reduce waste for small intersect clips by setting the scissor to the clip coverage rect instead of drawing the clip to the whole screen.

Note that this change _does not_ help much with huge/fullscreen clips.

Also, we could potentially improve this further by computing much stricter bounds. Rather than just using clip coverage for the scissor, we could intersect it with the union of all draws affected by the clip at the cost of a bit more CPU churn per draw. I don't think that's enough juice for the squeeze though.

Before (`Play/AiksTest.CanRenderNestedClips/Metal`):

https://github.com/flutter/engine/assets/919017/7858400f-793a-4f7b-a0e4-fa3581198beb

After (`Play/AiksTest.CanRenderNestedClips/Metal`):

https://github.com/flutter/engine/assets/919017/b2f7c96d-a820-454d-91df-f5fae4976e91
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 27, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 27, 2024
bdero added a commit to bdero/flutter-engine that referenced this pull request Mar 27, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Mar 27, 2024
…145862)

flutter/engine@d656625...73c145c

2024-03-27 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[Impeller] Use the scissor to limit all draws by clip coverage. (#51698)" (flutter/engine#51728)
2024-03-27 jacksongardner@google.com [Skwasm] Correctly handle paragraphs with empty text. (flutter/engine#51695)
2024-03-27 skia-flutter-autoroll@skia.org Roll Dart SDK from a600b67424a8 to 291217c1d399 (4 revisions) (flutter/engine#51716)
2024-03-27 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Fail pre-submit if a negative image is encountered as part of `goldctl imgtest add`. (#51685)" (flutter/engine#51718)
2024-03-27 bdero@google.com [Impeller] Use the scissor to limit all draws by clip coverage. (flutter/engine#51698)
2024-03-27 1961493+harryterkelsen@users.noreply.github.com [canvaskit] Fix color filter for dst and dstIn (flutter/engine#51693)
2024-03-27 jonahwilliams@google.com [Impeller] add missing null check. (flutter/engine#51711)
2024-03-27 jonahwilliams@google.com [Impeller] fix remaining Validation errors. (flutter/engine#51692)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC jacksongardner@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
auto-submit bot pushed a commit that referenced this pull request Mar 28, 2024
…e. (#51731)

Reland #51698.

This reverts commit 73c145c.

Attempts to improve flutter/flutter#145274.

Our new clipping technique paints walls on the depth buffer "in front" of the Entities that will be affected by said clips. So when an intersect clip is drawn (the common case), the clip will cover the whole framebuffer.

Depth is divvied up such that deeper clips get drawn _behind_ shallower clips, and so many clips actually don't end up drawing depth across the whole framebuffer. However, if the app does a lot of transitioning from a huge clips to a small clips, a lot of unnecessary depth churn occurs (very common in Flutter -- this happens with both the app bar and floating action button in the counter template, for example).

Since progressively deeper layers in the clip coverage stack always subset their parent layers, we can reduce waste for small intersect clips by setting the scissor to the clip coverage rect instead of drawing the clip to the whole screen.

Note that this change _does not_ help much with huge/fullscreen clips.

Also, we could potentially improve this further by computing much stricter bounds. Rather than just using clip coverage for the scissor, we could intersect it with the union of all draws affected by the clip at the cost of a bit more CPU churn per draw. I don't think that's enough juice for the squeeze though.

Before (`Play/AiksTest.CanRenderNestedClips/Metal`):

https://github.com/flutter/engine/assets/919017/7858400f-793a-4f7b-a0e4-fa3581198beb

After (`Play/AiksTest.CanRenderNestedClips/Metal`):

https://github.com/flutter/engine/assets/919017/b2f7c96d-a820-454d-91df-f5fae4976e91
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants