-
Notifications
You must be signed in to change notification settings - Fork 29.7k
[Engine] Fast blurring algorithm for RSuperellipse #169187
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
Conversation
engine/src/flutter/impeller/entity/contents/solid_rrect_like_blur_contents.h
Show resolved
Hide resolved
engine/src/flutter/impeller/entity/shaders/rsuperellipse_blur.frag
Outdated
Show resolved
Hide resolved
| vec2 center; | ||
| vec2 adjust; | ||
| float minEdge; | ||
| float r1; | ||
| float exponent; | ||
| float sInv; | ||
| float exponentInv; | ||
| float scale; | ||
|
|
||
| float octantOffset; |
There was a problem hiding this comment.
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;
...
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
engine/src/flutter/impeller/entity/shaders/rsuperellipse_blur.frag
Outdated
Show resolved
Hide resolved
engine/src/flutter/impeller/entity/shaders/rsuperellipse_blur.vert
Outdated
Show resolved
Hide resolved
jonahwilliams
left a comment
There was a problem hiding this 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.
jonahwilliams
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
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. |
|
This has failed in the merge queue multiple times. The errors recently are: The merge group will rerun failures multiple times, which can block the queue for > 1 hour. We should:
|
|
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. |
|
The error was right. A PR I merged last night caused this compilation error. I'll fix it. #167977 changed the signature of |
|
I've fixed the error and verified that it builds and works when updated with the latest main. Sorry for the trouble. |
|
Thankyou @dkwingsmt! |
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
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
* 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) ...
…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
…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
This PR adds a fast blurring algorithm for
RSuperellipses with uniform corner radius, similar toAttemptDrawBlurredRRect.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
RoundSuperellipseShadowComparisonto 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
RoundSuperellipseShadowComparisonplayground, which compares the fast algorithm (left) against the bruteforce algorithm (right).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.)
Open questions
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.