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] adds a plus advanced blend for f16 pixel formats #51589

Merged
merged 25 commits into from Mar 27, 2024

Conversation

gaaclarke
Copy link
Member

@gaaclarke gaaclarke commented Mar 21, 2024

fixes flutter/flutter#142549

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.

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.

Plus should be an advanced blend only conditionally when we are in a colorspace that does not correctly clamp. There is a loss of performance and rendering fidelity when moving something to an advanced blend that should be avoided if possible.

@gaaclarke
Copy link
Member Author

Plus should be an advanced blend only conditionally when we are in a colorspace that does not correctly clamp. There is a loss of performance and rendering fidelity when moving something to an advanced blend that should be avoided if possible.

I can resurrect the old Plus and make this AdvancedPlus and swap it over in the canvas. The reason I didn't do that is because every branch in logic incurs a maintenance cost. A bug that only shows up in particular setups is more difficult to find and fix. The performance of Plus didn't seem worth that cost.

@jonahwilliams
Copy link
Member

If the maintainence cost of branching is too high then we shouldn't have added support for wide gamut imo. Given that we're always going to be an a world we don't know at runtime whether a not a particular device supports wide gamut this is just the cost we've chosen to bear. I don't think its a reasonable argument to say that doing it right isn't worth it.

@gaaclarke
Copy link
Member Author

If the maintainence cost of branching is too high then we shouldn't have added support for wide gamut imo. Given that we're always going to be an a world we don't know at runtime whether a not a particular device supports wide gamut this is just the cost we've chosen to bear. I don't think its a reasonable argument to say that doing it right isn't worth it.

Fair point, in wide gamut's case though we are getting a lot of value for the effort. I'll add an agenda item to the next sync and we can decide as a team. There's no rush, this is hung up on the golden tests question anyway.

@gaaclarke
Copy link
Member Author

If we decide to keep around the old blend, the EntityPass looks like the proper place to map kPlus to kPlusAdvanced. That's where we are setting up advanced blends and branching on framebuffer fetch or not:

--- a/impeller/entity/entity_pass.cc
+++ b/impeller/entity/entity_pass.cc
@@ -996,6 +996,14 @@ bool EntityPass::OnRender(
     /// Setup advanced blends.
     ///
 
+    BlendMode adjusted_blend_mode = result.entity.GetBlendMode();
+    if (adjusted_blend_mode == BlendMode::kPlus &&
+        !IsAlphaClampedToOne(renderer.GetContext()
+                                 ->GetCapabilities()
+                                 ->GetDefaultColorFormat())) {
+      adjusted_blend_mode = BlendMode::kPlusAdvanced;
+    }
+
     if (result.entity.GetBlendMode() > Entity::kLastPipelineBlendMode) {
       if (renderer.GetDeviceCapabilities().SupportsFramebufferFetch()) {
         auto src_contents = result.entity.GetContents();

@jonahwilliams
Copy link
Member

That seems like a reasonable way to do it. I think instead of a separate capability state, you'd want a check of the onscreen/offscreen PixelFormat which tells you if you need the advanced blend.

impeller/entity/shaders/blending/framebuffer_blend.frag Outdated Show resolved Hide resolved

f16vec3 blend_result = AdvancedBlend(dst.rgb, src.rgb, int(blend_type));
if (nblend_type == /*BlendSelectValues::kPlusAdvanced*/ 14) {
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be OK to put this in its own shader.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm in the middle of still refactoring this. I'll ping you when it's ready to review =)

Copy link
Member Author

Choose a reason for hiding this comment

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

I see benefits and disadvantages both ways. What we shouldn't have is the code duplicated in 2 different parts. I've unified them with a shared function since this comment was made.

impeller/entity/entity_pass.cc Outdated Show resolved Hide resolved
@gaaclarke gaaclarke changed the title [Impeller] made plus an advanced blend [Impeller] adds a plus advanced blend for f16 pixel formats Mar 27, 2024
@gaaclarke
Copy link
Member Author

Let's see now if the golden bot malfunctions this time. I haven't force pushed since the last full ci cycle.

@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 #51589 at sha 202f56d

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 27, 2024
@auto-submit auto-submit bot merged commit 467b801 into flutter:main Mar 27, 2024
29 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 28, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Mar 28, 2024
…145877)

flutter/engine@c602abd...922c7b1

2024-03-28 skia-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from Lk8KBU-c97ROj-YHm... to uzI3wnbEGlZ_dtO0Z... (flutter/engine#51737)
2024-03-28 skia-flutter-autoroll@skia.org Roll Skia from b6160ffc0b96 to 66241be7c81c (16 revisions) (flutter/engine#51733)
2024-03-28 bdero@google.com [Impeller] Reland: Use the scissor to limit all draws by clip coverage.  (flutter/engine#51731)
2024-03-27 30870216+gaaclarke@users.noreply.github.com [Impeller] adds a `plus` advanced blend for f16 pixel formats (flutter/engine#51589)
2024-03-27 maRci002@users.noreply.github.com Platform channel for predictive back in route transitions on android (flutter/engine#49093)
2024-03-27 jonahwilliams@google.com [Impeller] render empty filled paths without crashing. (flutter/engine#51713)
2024-03-27 jonahwilliams@google.com [Impeller] use optimal depth attachment, remove useless barrier. (flutter/engine#51723)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from Lk8KBU-c97RO to uzI3wnbEGlZ_

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
@jonahwilliams jonahwilliams added the revert Label used to revert changes in a closed and merged pull request. label Mar 28, 2024
Copy link
Contributor

auto-submit bot commented Mar 28, 2024

A reason for requesting a revert of flutter/engine/51589 could
not be found or the reason was not properly formatted. Begin a comment with 'Reason for revert:' to tell the bot why
this issue is being reverted.

@auto-submit auto-submit bot removed the revert Label used to revert changes in a closed and merged pull request. label Mar 28, 2024
@jonahwilliams
Copy link
Member

Reason for revert: draw vertices devicelab test is crashing due to SIGABRT in blend contents

image

@jonahwilliams jonahwilliams added the revert Label used to revert changes in a closed and merged pull request. label Mar 28, 2024
auto-submit bot pushed a commit that referenced this pull request Mar 28, 2024
@auto-submit auto-submit bot removed the revert Label used to revert changes in a closed and merged pull request. label Mar 28, 2024
auto-submit bot added a commit that referenced this pull request Mar 28, 2024
#51589)" (#51741)

Reverts: #51589
Initiated by: jonahwilliams
Reason for reverting: draw vertices devicelab test is crashing due to SIGABRT in blend contents

![image](https://github.com/flutter/engine/assets/8975114/8bfaec63-29e9-43c2-8954-181d0ad1c413)

Original PR Author: gaaclarke

Reviewed By: {jonahwilliams}

This change reverts the following previous change:
fixes flutter/flutter#142549

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
auto-submit bot added a commit to flutter/flutter that referenced this pull request Mar 28, 2024
…isions) (#145877)" (#145901)

Reverts: #145877
Initiated by: zanderso
Reason for reverting: #145899
Original PR Author: engine-flutter-autoroll

Reviewed By: {fluttergithubbot}

This change reverts the following previous change:

flutter/engine@c602abd...922c7b1

2024-03-28 skia-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from Lk8KBU-c97ROj-YHm... to uzI3wnbEGlZ_dtO0Z... (flutter/engine#51737)
2024-03-28 skia-flutter-autoroll@skia.org Roll Skia from b6160ffc0b96 to 66241be7c81c (16 revisions) (flutter/engine#51733)
2024-03-28 bdero@google.com [Impeller] Reland: Use the scissor to limit all draws by clip coverage.  (flutter/engine#51731)
2024-03-27 30870216+gaaclarke@users.noreply.github.com [Impeller] adds a `plus` advanced blend for f16 pixel formats (flutter/engine#51589)
2024-03-27 maRci002@users.noreply.github.com Platform channel for predictive back in route transitions on android (flutter/engine#49093)
2024-03-27 jonahwilliams@google.com [Impeller] render empty filled paths without crashing. (flutter/engine#51713)
2024-03-27 jonahwilliams@google.com [Impeller] use optimal depth attachment, remove useless barrier. (flutter/engine#51723)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from Lk8KBU-c97RO to uzI3wnbEGlZ_

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
@eyebrowsoffire
Copy link
Contributor

Reverting due to: flutter/flutter#145899

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 28, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Mar 28, 2024
…sions) (#145903)

Manual roll requested by zra@google.com

flutter/engine@c602abd...9df2d3a

2024-03-28 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[Impeller] adds a `plus` advanced blend for f16 pixel formats (#51589)" (flutter/engine#51741)
2024-03-28 jonahwilliams@google.com [Impeller] correct multisample resolve/store configuration for Vulkan. (flutter/engine#51740)
2024-03-28 matanlurey@users.noreply.github.com Remove Impeller/OpenGLES from CI branch for Android e2e tests. (flutter/engine#51734)
2024-03-28 skia-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from Lk8KBU-c97ROj-YHm... to uzI3wnbEGlZ_dtO0Z... (flutter/engine#51737)
2024-03-28 skia-flutter-autoroll@skia.org Roll Skia from b6160ffc0b96 to 66241be7c81c (16 revisions) (flutter/engine#51733)
2024-03-28 bdero@google.com [Impeller] Reland: Use the scissor to limit all draws by clip coverage.  (flutter/engine#51731)
2024-03-27 30870216+gaaclarke@users.noreply.github.com [Impeller] adds a `plus` advanced blend for f16 pixel formats (flutter/engine#51589)
2024-03-27 maRci002@users.noreply.github.com Platform channel for predictive back in route transitions on android (flutter/engine#49093)
2024-03-27 jonahwilliams@google.com [Impeller] render empty filled paths without crashing. (flutter/engine#51713)
2024-03-27 jonahwilliams@google.com [Impeller] use optimal depth attachment, remove useless barrier. (flutter/engine#51723)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from Lk8KBU-c97RO to uzI3wnbEGlZ_

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

There is extra state that is getting setup when switching the blend mode that the override isn't catching, namely advanced_blend_proc_. Surprising that the test didn't catch that.

@gaaclarke
Copy link
Member Author

The test failed to catch this because the test is going through the CreateForegroundAdvancedBlend path.

gaaclarke added a commit to gaaclarke/engine that referenced this pull request Mar 28, 2024
gaaclarke added a commit that referenced this pull request Mar 28, 2024
…51756)

Relands #51589

The fix is in 74397bc. I couldn't
figure out how to get a test in the engine to cover it. The test is in
the devicelab.

Here's what I attempted:
```c++
TEST_P(AiksTest, BlendModePlusAlphaColorFilterAlphaWideGamut) {
  if (GetParam() != PlaygroundBackend::kMetal) {
    GTEST_SKIP_("This backend doesn't yet support wide gamut.");
  }
  EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
            PixelFormat::kR16G16B16A16Float);

  Canvas canvas;
  canvas.Scale(GetContentScale());
  canvas.DrawPaint({.color = Color(0.1, 0.2, 0.1, 0.5)});
  canvas.SaveLayer({
      .color_filter = ColorFilter::MakeBlend(BlendMode::kPlus,
                                             Color(Vector4{1, 0, 0, 0.5})),
  });
  Paint paint;
  paint.color = Color(1, 0, 0, 0.5);
  canvas.DrawRect(Rect::MakeXYWH(100, 100, 400, 400), paint);
  paint.color = Color::White();
  canvas.Restore();
  ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}
```

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] 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.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I signed the [CLA].
- [x] All existing and new tests are passing.

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

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
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