Skip to content

Conversation

@dkwingsmt
Copy link
Contributor

@dkwingsmt dkwingsmt commented May 21, 2025

This PR adds a fast blurring algorithm for RSuperellipses with uniform corner radius, similar to AttemptDrawBlurredRRect.

Fixes #163893. Fixes #167366.

This approximate algorithm is implemented by adding additional retraction to RRect's algorithm. Since they share most the logic, much effort is made to ensure reasonable code share.

I've also built a playground test RoundSuperellipseShadowComparison to compare the effect between the fast algorithm and the bruteforce algorithm, and added a macrobenchmark "rsuperellipse_blur".

Result

The following video shows the reproduction app from #167366, which shows much better framerate on RSE after the PR, almost the same as RRect. (I've verified that it was much worse without the PR.)

Screen.Recording.2025-05-20.at.11.59.38.PM.mp4

The following video shows the RoundSuperellipseShadowComparison playground, which compares the fast algorithm (left) against the bruteforce algorithm (right).

  • Pay attention to the cases with small but non zero sigma. They should be of almost the same shape as those with zero sigma, which skips the blurring altogether. With this algorithm, the difference between the two cases are about 1~2 pixel at most.
Screen.Recording.2025-05-21.at.12.57.02.AM.mp4

The following images compare macrobenchmarks "rrect_blur" against the new "rsuperellipse_blur". (Notice that the avg frame time fluctuates a lot but at least it shows that they're on par.)

image image

Open questions

  • Should I improve the code share of shader files? Currently they're not shared mostly because I'm not sure about its gain and cost.

Pre-launch Checklist

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

@github-actions github-actions bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels May 21, 2025
@dkwingsmt dkwingsmt marked this pull request as ready for review May 21, 2025 08:03
@dkwingsmt dkwingsmt requested a review from jonahwilliams May 21, 2025 08:03
Comment on lines 46 to 55
vec2 center;
vec2 adjust;
float minEdge;
float r1;
float exponent;
float sInv;
float exponentInv;
float scale;

float octantOffset;
Copy link
Contributor

Choose a reason for hiding this comment

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

RE: ordering. every uniform will take up a vec4 regardless of specified size. Since we have a lot of individual floats here, it will be better to pack them manually (similar to C structs, compilers won't do this automatically).

uniform FragInfo {
  vec4 abcd;
} frag_info;

float a = frag_info.a;
float b = frag_info.b;
...

Copy link
Contributor Author

@dkwingsmt dkwingsmt May 22, 2025

Choose a reason for hiding this comment

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

Do you mean that the RRect parameters (such as minEdge and r1) should be grouped like this as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

You don't have to do all of them, but yeah - if you have a loooot floats (which this one does) it would be good to group them in the UBO.

Copy link
Contributor

@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.

Overall LGTM but I'd like to see the shader code tidied up a bit first.

Copy link
Contributor

@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

@dkwingsmt dkwingsmt added the autosubmit Merge PR when tree becomes green via auto submit App label May 22, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented May 22, 2025

autosubmit label was removed for flutter/flutter/169187, because - The status or check suite Linux analyzer_benchmark has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label May 22, 2025
@dkwingsmt dkwingsmt added the autosubmit Merge PR when tree becomes green via auto submit App label May 23, 2025
@jtmcdole
Copy link
Member

This has failed in the merge queue multiple times. The errors recently are:

../../../flutter/impeller/geometry/round_superellipse_param.cc:477:20: error: no matching function for call to 'ComputeQuadrant'
  477 |       .top_right = ComputeQuadrant(bounds.GetCenter(), bounds.GetRightTop(),
      |                    ^~~~~~~~~~~~~~~
../../../flutter/impeller/geometry/round_superellipse_param.cc:204:34: note: candidate function not viable: requires 4 arguments, but 3 were provided
  204 | RoundSuperellipseParam::Quadrant ComputeQuadrant(Point center,
      |                                  ^               ~~~~~~~~~~~~~
  205 |                                                  Point corner,
      |                                                  ~~~~~~~~~~~~~
  206 |                                                  Size in_radii,
      |                                                  ~~~~~~~~~~~~~~
  207 |                                                  Size sign) {

The merge group will rerun failures multiple times, which can block the queue for > 1 hour.

We should:

  1. Figure out what is going on between presubmits and postsubmits
  2. Revisit retrying in the merge group.

@jonahwilliams
Copy link
Contributor

why is it building correctly in presubmit? maybe there are more changes stacked in master?

@jtmcdole
Copy link
Member

why is it building correctly in presubmit? maybe there are more changes stacked in master?

Either stacked in master, or stacked under this pr in the queue. I'll look and see.

@dkwingsmt
Copy link
Contributor Author

dkwingsmt commented May 23, 2025

The error was right. A PR I merged last night caused this compilation error. I'll fix it.

#167977 changed the signature of ComputeQuadrant, and this PR called ComputeQuadrant in a new place. It was not caught in presubmit probably because its base commit was not updated.

@dkwingsmt
Copy link
Contributor Author

I've fixed the error and verified that it builds and works when updated with the latest main. Sorry for the trouble.

@dkwingsmt dkwingsmt added the autosubmit Merge PR when tree becomes green via auto submit App label May 23, 2025
@auto-submit auto-submit bot added this pull request to the merge queue May 23, 2025
@jtmcdole
Copy link
Member

Thankyou @dkwingsmt!

Merged via the queue into flutter:master with commit ea1c1ba May 23, 2025
181 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label May 23, 2025
@dkwingsmt dkwingsmt deleted the rse-fast-shadow branch May 23, 2025 21:32
jtmcdole added a commit to jtmcdole/cocoon that referenced this pull request May 23, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 24, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request May 24, 2025
flutter/flutter@85564cb...60050a0

2025-05-24 [email protected] Roll Skia from 0834eea9de33 to 91dc88dc70e5 (1 revision) (flutter/flutter#169414)
2025-05-24 [email protected] Roll Dart SDK from 0a6b16a55b9e to 7dab9bffe1f7 (1 revision) (flutter/flutter#169406)
2025-05-24 [email protected] Correct calculation for CupertinoTextSelectionToolbar vertical position (flutter/flutter#169308)
2025-05-24 [email protected] Baseline-align CupertinoTextField placeholder (flutter/flutter#166952)
2025-05-24 [email protected] Roll Dart SDK from 8354914ef97b to 0a6b16a55b9e (3 revisions) (flutter/flutter#169403)
2025-05-24 [email protected] Start removing Observatory support and references (flutter/flutter#169216)
2025-05-23 [email protected] Roll Skia from f42bb59753fe to 0834eea9de33 (3 revisions) (flutter/flutter#169393)
2025-05-23 [email protected] Roll Skia from 956fd8b14e22 to f42bb59753fe (2 revisions) (flutter/flutter#169379)
2025-05-23 [email protected] [Engine] Fast blurring algorithm for RSuperellipse (flutter/flutter#169187)
2025-05-23 [email protected] Add a page describing best CI practices for `flutter`-org repos (flutter/flutter#169364)
2025-05-23 [email protected] Revert "Mark web_tool_tests_1_2 as bringup." (flutter/flutter#169361)
2025-05-23 [email protected] Add changelog section for 3.32.0 and 3.32.1, and add note for ndk checking cherry pick (flutter/flutter#169369)
2025-05-23 [email protected] Roll Dart SDK from 085f110ecf33 to 8354914ef97b (1 revision) (flutter/flutter#169349)
2025-05-23 [email protected] Remove handling of the legacy `.flutter-plugins` file in `PluginHandler.kt`. (flutter/flutter#169317)
2025-05-23 [email protected] Use baseUri of WebAssetServer for reload_scripts.json (flutter/flutter#169267)
2025-05-23 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Use pub workspace (#168662)" (flutter/flutter#169357)
2025-05-23 [email protected] Use pub workspace (flutter/flutter#168662)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: 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
stan-at-work pushed a commit to stan-at-work/flutter that referenced this pull request May 26, 2025
This PR adds a fast blurring algorithm for `RSuperellipse`s with uniform
corner radius, similar to `AttemptDrawBlurredRRect`.

Fixes flutter#163893. Fixes
flutter#167366.

This approximate algorithm is implemented by adding additional
retraction to RRect's algorithm. Since they share most the logic, much
effort is made to ensure reasonable code share.

I've also built a playground test `RoundSuperellipseShadowComparison` to
compare the effect between the fast algorithm and the bruteforce
algorithm, and added a macrobenchmark "rsuperellipse_blur".

### Result

The following video shows the reproduction app from
flutter#167366, which shows much
better framerate on RSE after the PR, almost the same as RRect. (I've
verified that it was much worse without the PR.)


https://github.com/user-attachments/assets/5433af91-c0a1-4b15-9161-cf2280543e27

The following video shows the `RoundSuperellipseShadowComparison`
playground, which compares the fast algorithm (left) against the
bruteforce algorithm (right).

* Pay attention to the cases with small but non zero sigma. They should
be of almost the same shape as those with zero sigma, which skips the
blurring altogether. With this algorithm, the difference between the two
cases are about 1~2 pixel at most.


https://github.com/user-attachments/assets/e26d2d8f-d29e-4db8-9c20-67103d77891c

The following images compare macrobenchmarks "rrect_blur" against the
new "rsuperellipse_blur". (Notice that the avg frame time fluctuates a
lot but at least it shows that they're on par.)

<img width="389" alt="image"
src="https://github.com/user-attachments/assets/67cf4b10-f13f-4e55-bdfd-35d358617f38"
/>

<img width="365" alt="image"
src="https://github.com/user-attachments/assets/6869fa9c-5752-4a11-babe-b6a2d590ebc9"
/>



### Open questions
* Should I improve the code share of shader files? Currently they're not
shared mostly because I'm not sure about its gain and cost.

## 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], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] 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/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
zeqinjie pushed a commit to zeqinjie/flutter that referenced this pull request Jun 5, 2025
* master: (125 commits)
  Roll Fuchsia Linux SDK from XtPp9bBW49iDJ0wbA... to -eo2JqnJBauuGSzoW... (flutter#169424)
  Roll Skia from 91dc88dc70e5 to 443f5257f382 (1 revision) (flutter#169422)
  Roll Skia from 0834eea9de33 to 91dc88dc70e5 (1 revision) (flutter#169414)
  Roll Dart SDK from 0a6b16a55b9e to 7dab9bffe1f7 (1 revision) (flutter#169406)
  Correct calculation for CupertinoTextSelectionToolbar vertical position (flutter#169308)
  Baseline-align CupertinoTextField placeholder (flutter#166952)
  Roll Dart SDK from 8354914ef97b to 0a6b16a55b9e (3 revisions) (flutter#169403)
  Start removing Observatory support and references (flutter#169216)
  Roll Skia from f42bb59753fe to 0834eea9de33 (3 revisions) (flutter#169393)
  Roll Skia from 956fd8b14e22 to f42bb59753fe (2 revisions) (flutter#169379)
  [Engine] Fast blurring algorithm for RSuperellipse (flutter#169187)
  Add a page describing best CI practices for `flutter`-org repos (flutter#169364)
  Revert "Mark web_tool_tests_1_2 as bringup." (flutter#169361)
  Add changelog section for 3.32.0 and 3.32.1, and add note for ndk checking cherry pick (flutter#169369)
  Roll Dart SDK from 085f110ecf33 to 8354914ef97b (1 revision) (flutter#169349)
  Remove handling of the legacy `.flutter-plugins` file in `PluginHandler.kt`. (flutter#169317)
  Use baseUri of WebAssetServer for reload_scripts.json (flutter#169267)
  Reverts "Use pub workspace (flutter#168662)" (flutter#169357)
  Use pub workspace (flutter#168662)
  Reverts "[Reland2] Implements UISceneDelegate dynamically w/ FlutterLaunchEngine (flutter#169276)" (flutter#169347)
  ...
FMorschel pushed a commit to FMorschel/packages that referenced this pull request Jun 9, 2025
…r#9318)

flutter/flutter@85564cb...60050a0

2025-05-24 [email protected] Roll Skia from 0834eea9de33 to 91dc88dc70e5 (1 revision) (flutter/flutter#169414)
2025-05-24 [email protected] Roll Dart SDK from 0a6b16a55b9e to 7dab9bffe1f7 (1 revision) (flutter/flutter#169406)
2025-05-24 [email protected] Correct calculation for CupertinoTextSelectionToolbar vertical position (flutter/flutter#169308)
2025-05-24 [email protected] Baseline-align CupertinoTextField placeholder (flutter/flutter#166952)
2025-05-24 [email protected] Roll Dart SDK from 8354914ef97b to 0a6b16a55b9e (3 revisions) (flutter/flutter#169403)
2025-05-24 [email protected] Start removing Observatory support and references (flutter/flutter#169216)
2025-05-23 [email protected] Roll Skia from f42bb59753fe to 0834eea9de33 (3 revisions) (flutter/flutter#169393)
2025-05-23 [email protected] Roll Skia from 956fd8b14e22 to f42bb59753fe (2 revisions) (flutter/flutter#169379)
2025-05-23 [email protected] [Engine] Fast blurring algorithm for RSuperellipse (flutter/flutter#169187)
2025-05-23 [email protected] Add a page describing best CI practices for `flutter`-org repos (flutter/flutter#169364)
2025-05-23 [email protected] Revert "Mark web_tool_tests_1_2 as bringup." (flutter/flutter#169361)
2025-05-23 [email protected] Add changelog section for 3.32.0 and 3.32.1, and add note for ndk checking cherry pick (flutter/flutter#169369)
2025-05-23 [email protected] Roll Dart SDK from 085f110ecf33 to 8354914ef97b (1 revision) (flutter/flutter#169349)
2025-05-23 [email protected] Remove handling of the legacy `.flutter-plugins` file in `PluginHandler.kt`. (flutter/flutter#169317)
2025-05-23 [email protected] Use baseUri of WebAssetServer for reload_scripts.json (flutter/flutter#169267)
2025-05-23 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Use pub workspace (#168662)" (flutter/flutter#169357)
2025-05-23 [email protected] Use pub workspace (flutter/flutter#168662)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: 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
Ortes pushed a commit to Ortes/packages that referenced this pull request Jun 25, 2025
…r#9318)

flutter/flutter@85564cb...60050a0

2025-05-24 [email protected] Roll Skia from 0834eea9de33 to 91dc88dc70e5 (1 revision) (flutter/flutter#169414)
2025-05-24 [email protected] Roll Dart SDK from 0a6b16a55b9e to 7dab9bffe1f7 (1 revision) (flutter/flutter#169406)
2025-05-24 [email protected] Correct calculation for CupertinoTextSelectionToolbar vertical position (flutter/flutter#169308)
2025-05-24 [email protected] Baseline-align CupertinoTextField placeholder (flutter/flutter#166952)
2025-05-24 [email protected] Roll Dart SDK from 8354914ef97b to 0a6b16a55b9e (3 revisions) (flutter/flutter#169403)
2025-05-24 [email protected] Start removing Observatory support and references (flutter/flutter#169216)
2025-05-23 [email protected] Roll Skia from f42bb59753fe to 0834eea9de33 (3 revisions) (flutter/flutter#169393)
2025-05-23 [email protected] Roll Skia from 956fd8b14e22 to f42bb59753fe (2 revisions) (flutter/flutter#169379)
2025-05-23 [email protected] [Engine] Fast blurring algorithm for RSuperellipse (flutter/flutter#169187)
2025-05-23 [email protected] Add a page describing best CI practices for `flutter`-org repos (flutter/flutter#169364)
2025-05-23 [email protected] Revert "Mark web_tool_tests_1_2 as bringup." (flutter/flutter#169361)
2025-05-23 [email protected] Add changelog section for 3.32.0 and 3.32.1, and add note for ndk checking cherry pick (flutter/flutter#169369)
2025-05-23 [email protected] Roll Dart SDK from 085f110ecf33 to 8354914ef97b (1 revision) (flutter/flutter#169349)
2025-05-23 [email protected] Remove handling of the legacy `.flutter-plugins` file in `PluginHandler.kt`. (flutter/flutter#169317)
2025-05-23 [email protected] Use baseUri of WebAssetServer for reload_scripts.json (flutter/flutter#169267)
2025-05-23 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Use pub workspace (#168662)" (flutter/flutter#169357)
2025-05-23 [email protected] Use pub workspace (flutter/flutter#168662)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: 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
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels.

Projects

None yet

4 participants