Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] improve blur performance for Android and iPad Pro. #39291

Merged
merged 4 commits into from
Feb 1, 2023

Conversation

jonahwilliams
Copy link
Member

@jonahwilliams jonahwilliams commented Jan 31, 2023

Create a shader variant for blur that uses natively supported texture addressing modes, and a shader variant that emulates decal tile mode, removing the branch from the loop. I think this is legal? :)

Running some local experiments on wonderous on an iPad pro, the gaussian blur passes are currently taking around 8-16ms. With this change applied, they're more consistently 4-8ms - roughly doubling the performance. While I didn't see an improvement on iOS in my past investigation of this change, this was likely because we were always running below frame time + I wasn't using the frame debugger. I'll investigate this separately, but I believe we'll also see a performance improvment on iPhones - and on Android as well.

While this does increase the number of shaders, its only by 1 - and for the most expensive filter we have Its probably worth it. Note that even 2xing performance, we still need to find a way to make some more gains to stay within budget for the iPad, probably at least one more doubling.

#37927 (comment) contains details on the malioc output which confirm perfomance numbers for Android as well.

Before

image

After

image

@chinmaygarde chinmaygarde changed the title [Impeller] improve blur performance for Android and iPad pro [Impeller] improve blur performance for Android and iPad Pro. Jan 31, 2023
@jonahwilliams jonahwilliams marked this pull request as ready for review January 31, 2023 21:56
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

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 assuming all of the TileModes still behave properly in Play/EntityTest.GaussianBlurFilter/Metal.

(When checking, note that some of the rarely used "BlurStyles" have been known broken for a while due to the blur optimizations, we need to get around to fixing it)

For future onlookers: Note that times in frame captures are extremely inaccurate and can vary up to 5x in my experience. However, they're loosely precise, and so by normalizing results against the length of items in the capture which are expected to not be changed, loose performance comparisons can be made.
In the "before" screenshot, everything happens at ~half speed, and so at first glance, it appears that the first blur pass is 4x speed in the "after" screenshot, but it's actually closer to 2x. Another interesting observation is that the second blur pass is actually relatively slower in the "after" screenshot!

@@ -281,7 +308,7 @@ std::optional<Rect> DirectionalGaussianBlurFilterContents::GetFilterCoverage(

auto transform = inputs[0]->GetTransform(entity) * effect_transform;
auto transformed_blur_vector =
transform.TransformDirection(blur_direction_ * Radius{blur_sigma_}.radius)
transform.TransformDirection(blur_direction_* Radius{blur_sigma_}.radius)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Weird change. Is the formatter forcing this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup :(

input_descriptor.height_address_mode = SamplerAddressMode::kRepeat;
source_descriptor.width_address_mode = SamplerAddressMode::kRepeat;
source_descriptor.height_address_mode = SamplerAddressMode::kRepeat;
break;
Copy link
Member

Choose a reason for hiding this comment

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

Oh yeah, we should totally be doing this! This has come up a couple of times before when the blur was under pressure.

@jonahwilliams
Copy link
Member Author

I have visually verified the examples and they seem identical :)

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 1, 2023
@auto-submit auto-submit bot merged commit 4b77e77 into flutter:main Feb 1, 2023
@jonahwilliams jonahwilliams deleted the gaussian_blur branch February 1, 2023 23:14
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 2, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Feb 2, 2023
…119765)

* 4b77e7793 [Impeller] improve blur performance for Android and iPad Pro. (flutter/engine#39291)

* 97d27ff59 [Impeller] let images with opacity and filters passthrough. (flutter/engine#39237)
zanderso pushed a commit to zanderso/engine that referenced this pull request Feb 3, 2023
…r#39291)

* [Impeller] improve gaussian blur performance on Android

* ++

* ++
zanderso pushed a commit to zanderso/engine that referenced this pull request Feb 3, 2023
…r#39291)

* [Impeller] improve gaussian blur performance on Android

* ++

* ++
zanderso pushed a commit to zanderso/engine that referenced this pull request Feb 3, 2023
…r#39291)

* [Impeller] improve gaussian blur performance on Android

* ++

* ++
godofredoc pushed a commit that referenced this pull request Feb 8, 2023
#39367)

* [Impeller] improve gaussian blur performance on Android

* ++

* ++

Co-authored-by: Jonah Williams <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App e: impeller needs tests
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants