-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Fix mipmap generation for Vulkan render target textures. #49848
Conversation
This new blur should perform faster since it scales down the image before blurring it. Jonah did early testing of it and found it to be faster. Scrolling around with the blur perf bug it seems faster. It also has a wider test bed and is hopefully easier to maintain since it contains all of its logic for both directions. testing: There are existing blur tests and we've backfilled more as we've added features to this blur. fixes flutter/flutter#131580 fixes flutter/flutter#138259 - [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
This reverts commit cae5c50.
This reverts commit 590a245.
This reverts commit 3d8682e.
4a0b890 to
84f6856
Compare
|
(I rebased this onto upstream/main) |
gaaclarke
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.
@jonahwilliams I ran this locally and found that it passed our tests and rendered everything correctly. Now that we have our golden's setup correctly you can test this yourself with impeller_golden_tests --working_dir=<path> --gtest_filter="*GaussianBlur*Vulkan".
We have tests that are asserting that the blur is being executed with mipmaps (example AiksTest.GaussianBlurMipMapImageFilter).
The only thing I wasn't able to verify is to visually check to make sure it looks good when animating the blur. Given that it passes the aforementioned checks though I have no reason to believe it looks different than the metal rendering.
I also gave the PR a review and this approach sounds good to me.
|
Thanks @gaaclarke , I'll get this cleaned up. I think I can verify the flicker on some of the blur examples we have |
Ah yea, just running it on an Android device, sounds good. |
impeller/entity/entity_pass.cc
Outdated
| // generation on opengles. | ||
| mip_count = 1; | ||
| } | ||
| // if (context->GetBackendType() != Context::BackendType::kMetal) { |
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.
friendly note, switch this to mip_count 1 for opengles until we can verify that is working.
|
Bad news: this still has more validation errors: |
|
It looks like the miplevels aren't getting set to the correct state |
|
@jonahwilliams how did you get those? It seems like we aren't getting validation errors in our golden test runner? |
|
This with my patching running the example in flutter/flutter#132735 It looks like the problem might be the image layout is per-mip level? I need to do more research, that would blow my mind. |
|
Added a bit of a hack to get to zero validation errors. Right now the usage flags for our render targes are incorrect for the backdrop filters. If I fix that I can make this behavior less manual. |
|
Hey @jonahwilliams, I'm just circling back to this today. Where are we at, how can I help? Now that we have the allow list for validations, I think we should turn on validations for one of the tests where we had problems as part of this PR, for example |
|
I have all the validation errors fixed locally, but I'm re-arranging this patch a bit to remove the blit pass changes. ETA EOD. |
|
I think I found the best example of the jittering. The macrobenchmarks app --> animated backdrop filter. Beforevideo.mp4Afterpatch.mp4 |
|
I think there is less shaking? but its still pretty shaky. If this is caused by the misalignment, then fixing that would be the next thing to do. |
|
on iOS there is still some shaking but its less bad. |
|
Yea, I don't see much difference there. I think the more important case is shaky when not animating the sigma, but contents under the blur. |
gaaclarke
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.
Can you please turn on the validation for GaussianBlurMipMapNestedLayer in golden_playground_test_mac.cc as part of the PR?
|
|
||
| if (command_buffer_) { | ||
| if (!command_buffer_->EncodeAndSubmit(pass_)) { | ||
| if (!pass_->EncodeCommands()) { |
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.
This is kind of weird now, it isn't obvious why there is a if (command_buffer_) check here. Is that still necessary?
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.
Should be handled by isActive check, added D_CHECK
| if (GetBackend() != PlaygroundBackend::kMetal && | ||
| GetBackend() != PlaygroundBackend::kVulkan) { |
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.
This should be turning off vulkan golden images, which isn't what we want.
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.
Fixed?
| } | ||
| // Create a specialized view for render target attachments. | ||
| view_info.subresourceRange.levelCount = 1u; | ||
| auto [result_2, rt_image_view] = device.createImageViewUnique(view_info); |
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.
Can you give result_2 a more meaningful name? rt_image_view_result? It looks like you are n't checking it below, you are checking result.
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.
Done
| ImageResource(ImageResource&& o) { | ||
| std::swap(image, o.image); | ||
| std::swap(image_view, o.image_view); | ||
| std::swap(rt_image_view, o.rt_image_view); |
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.
Can't this just be ImageResource(ImageResource&&) = default?
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.
Done
| ); | ||
|
|
||
| return true; | ||
| // If this is not an onscreen, convert back to shader read. |
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.
This comment doesn't match the code (it's the negation of what's written). It's more correct to say "If it's on screen, don't convert it to shader read".
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.
Done
| /// @brief Retrieve the image view used for render target attachments | ||
| /// with this texture source. | ||
| /// | ||
| /// image views used as render target attachments cannot have any mip levels. |
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.
| /// image views used as render target attachments cannot have any mip levels. | |
| /// ImageViews used as render target attachments cannot have any mip levels. |
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.
Done
| vk::ImageLayout GetLayout() const; | ||
|
|
||
| /// Whether or not this is a swapchain image. | ||
| virtual bool IsOnscreen() const = 0; |
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.
Maybe this should read "IsSwapchainImage()"?
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.
Done
|
I think I turned on validation correctly, lets see if it blends |
gaaclarke
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, the test name just needs to be fixed. Once this becomes a deny list or is on across the board it will be better.
Co-authored-by: gaaclarke <[email protected]>
gaaclarke
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, thanks for looking into this. This would have taken me quite a while to work out.
|
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. |
Yay, further validation that we got this right. It's weird it didn't show up in more tests but it's hard to draw conclusions with a fuzzy matcher though. |
|
Something is definitely different! |
…142256) flutter/engine@b2167a9...4b145d0 2024-01-25 [email protected] [Impeller] Fix mipmap generation for Vulkan render target textures. (flutter/engine#49848) 2024-01-25 [email protected] [Impeller] Do not emit metadata for structs that are not part of the shader's interface (flutter/engine#50029) 2024-01-25 [email protected] Roll Skia from de46a989e0ca to 29b545e4356b (1 revision) (flutter/engine#50047) 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 [email protected],[email protected],[email protected] 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
Potentially fixes flutter/flutter#141495
The texture used as a render target attachment can have miplevels, but the image view cannot. Unconditionally create two image views per texture (this could be optimized in some cases), where the specific "render target texture view" always sets a mipcount of 1.
In theory this should allow us to generate mipmaps for textures that are used as render target attachments, including toImage and toImageSync textures which are currently missing this functionality.