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

Fixes MatrixFilterContents rendering/coverage #52880

Merged
merged 23 commits into from
May 18, 2024

Conversation

gaaclarke
Copy link
Member

@gaaclarke gaaclarke commented May 16, 2024

fixes: flutter/flutter#147807
relands #43943 (with fixes that hopefully avoid it being reverted again)

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@gaaclarke gaaclarke changed the title Bug 147807 Fixes MatrixFilterContents rendering/coverage May 16, 2024
gaaclarke and others added 17 commits May 16, 2024 13:59
…lutter#43943)

Resolves flutter/flutter#130355.

When drawing a backdrop filter, we offset the backdrop entity with
`-local_pass_position` in order to align the backdrop texture with the
position of the pass it's being drawn to. When rendering the filter,
this transform propagates to the filter snapshot. Prior to this change,
that offset was being applied within the space of the backdrop filter's
matrix, which is wrong! It needs to be applied in screen space.

We didn't notice this prior to the coverage hint optimization because we
were previously forcing subpass sizes to match the parent whenever a
backdrop filter was present.

This one was very difficult to reason through at first, and so I added a
detailed comment to explain the rationale behind the behavioral
differences between the backdrop filter and non-backdrop filter cases of
the matrix filter.
@gaaclarke gaaclarke marked this pull request as ready for review May 16, 2024 22:32
@@ -28,6 +28,17 @@ void MatrixFilterContents::SetSamplerDescriptor(SamplerDescriptor desc) {
sampler_descriptor_ = std::move(desc);
}

namespace {
Matrix CalculateSubpassTransform(const Matrix& entity_transform,
Copy link
Member Author

Choose a reason for hiding this comment

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

@bdero this is what I was talking about the other day. We should be sharing the math between rendering and coverage.

Copy link
Member

@bdero bdero left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for looking through this.

@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 #52880 at sha 4097c92

@gaaclarke
Copy link
Member Author

The PR has some unexpected golden changes I'll have to audit:

example

Screenshot 2024-05-16 at 3 54 56 PM

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

Changes reported for pull request #52880 at sha 4f4845b

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

Changes reported for pull request #52880 at sha 49b23cb

@gaaclarke
Copy link
Member Author

This passes all tests, but @bdero and I are auditing it to make sure it's correct. So don't land this yet.

@gaaclarke
Copy link
Member Author

I think the check for translation hack works because it is by proxy detecting the Canvas::Save flow as opposed to the ImageFilter flow. In the Canvas::Save path the effect_transform is truncated to its basis before it is passed down (

subpass->transform_.Basis(), Entity::RenderingMode::kSubpass);
)

@gaaclarke
Copy link
Member Author

@bdero I made that change we discussed, can you please take a look.

We decided offline that we are clearly seeing 3 different cases that need to be handled at the MatrixImageFilterContents level. So we expanded the RenderMode to reflect those 3 cases. I suspect maybe we are misusing the effect transform where we get it meaning 3 different things in 3 different contexts. Hopefully we can clear that up in the future.

Copy link
Member

@bdero bdero left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label May 18, 2024
@auto-submit auto-submit bot merged commit 2f80d28 into flutter:main May 18, 2024
31 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 18, 2024
@jonahwilliams
Copy link
Member

This looks like its working incorrectly with some magnifier goldens in the framework:

https://flutter-gold.skia.org/search?crs=github&issue=148593&left_filter=name%3Dwidgets.widgets.magnifier.styled&master=true&patchsets=3&positive=true

Top is the Impeller golden diff and bottom is current Skia (which is unchanged)

image

@jonahwilliams
Copy link
Member

reason for revert: unexpected framework golden change

@jonahwilliams jonahwilliams added the revert Label used to revert changes in a closed and merged pull request. label May 18, 2024
auto-submit bot pushed a commit that referenced this pull request May 18, 2024
@auto-submit auto-submit bot removed the revert Label used to revert changes in a closed and merged pull request. label May 18, 2024
auto-submit bot added a commit that referenced this pull request May 18, 2024
)

Reverts: #52880
Initiated by: jonahwilliams
Reason for reverting: unexpected framework golden change
Original PR Author: gaaclarke

Reviewed By: {bdero}

This change reverts the following previous change:
fixes: flutter/flutter#147807
relands #43943 (with fixes that hopefully avoid it being reverted again)

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 18, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request May 18, 2024
…148595)

flutter/engine@93f1b5a...552a965

2024-05-18 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Fixes MatrixFilterContents rendering/coverage (#52880)" (flutter/engine#52918)
2024-05-18 30870216+gaaclarke@users.noreply.github.com Fixes MatrixFilterContents rendering/coverage (flutter/engine#52880)
2024-05-17 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[macOS] Generate universal gen_snapshots (#52885)" (flutter/engine#52913)
2024-05-17 chris@bracken.jp [macOS] Generate universal gen_snapshots (flutter/engine#52885)

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 bdero@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
@gaaclarke
Copy link
Member Author

gaaclarke commented May 20, 2024

Here are the matrices for the magnifier.styled test:

  • snapshot: translate(-600,-600)
  • effect: scale(3,3,1)
  • matrix: translate(-150, -150) * scale(2, 2, 1)

It's going through the kBackdropSubpass flow here. Backing out the backdrop flow fixes all tests except Bug147807 (the current state of the code.

All engine and frameworks tests pass with the following patch:

diff --git a/impeller/entity/entity_pass.cc b/impeller/entity/entity_pass.cc
index ee28a0dd4f..1cc997d5cc 100644
--- a/impeller/entity/entity_pass.cc
+++ b/impeller/entity/entity_pass.cc
@@ -585,9 +586,10 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
       auto texture = pass_context.GetTexture();
       // Render the backdrop texture before any of the pass elements.
       const auto& proc = subpass->backdrop_filter_proc_;
       subpass_backdrop_filter_contents = proc(
           FilterInput::Make(std::move(texture)), subpass->transform_.Basis(),
-          Entity::RenderingMode::kBackdropSubpass);
+          Entity::RenderingMode::kImageFilterSubpass);

So the concept is right, there is a third state, the EntityPass::GetElementsCoverage flow for backdrop filters isn't passing in the basis of the transform, whereas the EntityPass::GetEntityForElement is. That appears to be the detection we need to differentiate the different cases. I plan on relanding this with the above patch and more apropos names for the different math than BackdropSubpass vs ImageFilterSubpass.

Edit: I was mistaken, that leaves us in the same state as before we landed this (everything works but Bug147807.

@gaaclarke
Copy link
Member Author

As an experiment I tried to remove the Basis() call in EntityPass::GetEntityForElement (here) with Brandon's original patch. It get's the same results as this PR, all the engine tests pass but the framework one fails. It seems like we still need that (barring some sort of deeper refactoring).

@gaaclarke
Copy link
Member Author

This patch seems to make the engine and framework tests happy. I'm not familiar with ContentBoundsPromise but it roughly sounds like it could effect the contents we get from the snapshot and determines how we should be performing the math:

diff --git a/impeller/entity/entity_pass.cc b/impeller/entity/entity_pass.cc
index 984403629c..13e99b3ced 100644
--- a/impeller/entity/entity_pass.cc
+++ b/impeller/entity/entity_pass.cc
@@ -585,9 +585,17 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
       auto texture = pass_context.GetTexture();
       // Render the backdrop texture before any of the pass elements.
       const auto& proc = subpass->backdrop_filter_proc_;
       subpass_backdrop_filter_contents = proc(
           FilterInput::Make(std::move(texture)), subpass->transform_.Basis(),
-          Entity::RenderingMode::kImageFilterSubpass);
+          subpass->bounds_promise_ == ContentBoundsPromise::kContainsContents ?
+          Entity::RenderingMode::kImageFilterSubpass :
+          Entity::RenderingMode::kBackdropSubpass);
 
       // If the very first thing we render in this EntityPass is a subpass that
       // happens to have a backdrop filter, than that backdrop filter will end

If this is the correct latch we can rename the render modes accordingly.

gaaclarke added a commit to gaaclarke/engine that referenced this pull request May 20, 2024
fixes: flutter/flutter#147807
relands flutter#43943 (with fixes that hopefully avoid it being reverted again)

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
auto-submit bot pushed a commit that referenced this pull request May 21, 2024
fixes flutter/flutter#147807
relands #52880
relands #43943

This was previously reverted because of the golden test failure `widgets.widgets.magnifier.styled`.  This fixes that problem by instead of focusing on ImageFilter and BackdropFilter subpasses, instead focuses on wether a subpass is clipped or not and by extension how the math should be handled.

`widgets.widgets.magnifier.styled` after diff:

![widgets widgets magnifier styled](https://github.com/flutter/engine/assets/30870216/d4611586-90f7-4d3e-90d8-018dd678d028)

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
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
3 participants