-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
[Android] Cache GPU resources using HardwareBuffer's id as key #50028
Conversation
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 "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use 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. |
This is a bit crashy right now. I think the stack itself is probably bogus but potentially we're holding onto some of these resources for too long now:
|
One meta thought about this change: Does it need to be Vulkan specific? I wonder if we can just cache the DlImages in the base class and reuse the eglImageKHRs too. |
This appears to approximately work for GL too, with the same caveat that I still get crashes sometimes:
I suspect there is some lifecycle where the texture or dl_image is becoming invalid without the texture view becoming aware of it |
Ahh I need to clear the cache when we reset the dl image. |
Waiting to rebase on the other image reader patch. |
Open question is how many different images we'll get from an Image/Camera implementation. This code works fine with a different # of swapchain images than the cache, though if its too small we'll obviously be dropping images unnecessarily. |
I plan to pull the LRU code out into a helper so I can test it more easily, since getting that wrong makes the cache ineffective. |
The difference in behavior is due to the fact that impeller::Textures (which DlImages wrap) own their gl texture handle, whereas SkImages do not. The ImageExternalTextureGLSkia manages a texture handle and that needs to be 1-1 with the DlImage. |
there is a flicker issue that impacts all Flutter apps on resume. I need to dig into that. |
auto label is removed for flutter/engine/50028, due to - The status or check suite Linux linux_clang_tidy has failed. Please fix the issues identified (or deflake) before re-applying this label. |
…142362) flutter/engine@2687ddb...2adad88 2024-01-27 skia-flutter-autoroll@skia.org Roll Skia from 6279c88b9e29 to b9b80230c87b (4 revisions) (flutter/engine#50110) 2024-01-27 jonahwilliams@google.com [Impeller] add missing barrier to compute tessellator. (flutter/engine#50108) 2024-01-27 jonahwilliams@google.com [Android] Cache GPU resources using HardwareBuffer's id as key (flutter/engine#50028) 2024-01-27 54558023+keyonghan@users.noreply.github.com Move Mac builder_cache to prod (flutter/engine#50044) 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
…ey" (#50114) Reverts #50028 Initiated by: jonahwilliams This change reverts the following previous change: Original Description: Once a hardware buffer has been imported (a VkImage created for it), we don't ever need to re-create a VkImage, even when the contents change. The same hardware buffer can be identified by ID. Part of flutter/flutter#142153 Otherwise we spend a lot of time re-creating VkImages: ![image](https://github.com/flutter/flutter/assets/8975114/700bc0e2-ab00-417e-89c5-04abe7e1db96) Draft is here, but is currently leaky: #50028 We only need something like a LRU with the max image size (seems to be 3 for me). This does log locally that I'm not calling close correctly: ``` E/flutter ( 5580): [ERROR:flutter/shell/platform/android/image_external_texture_vk.cc(51)] Size: 3 W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. W/System ( 5580): A resource failed to call HardwareBuffer.close. ``` FYI @johnmccutchan
…isions)" (#142366) Reverts #142362 Initiated by: jonahwilliams This change reverts the following previous change: Original Description: flutter/engine@2687ddb...2adad88 2024-01-27 skia-flutter-autoroll@skia.org Roll Skia from 6279c88b9e29 to b9b80230c87b (4 revisions) (flutter/engine#50110) 2024-01-27 jonahwilliams@google.com [Impeller] add missing barrier to compute tessellator. (flutter/engine#50108) 2024-01-27 jonahwilliams@google.com [Android] Cache GPU resources using HardwareBuffer's id as key (flutter/engine#50028) 2024-01-27 54558023+keyonghan@users.noreply.github.com Move Mac builder_cache to prod (flutter/engine#50044) 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
…142369) flutter/engine@2687ddb...95e9a15 2024-01-27 flar@google.com Cache Impeller paths in the DisplayList to amortize conversion (flutter/engine#50076) 2024-01-27 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[Android] Cache GPU resources using HardwareBuffer's id as key" (flutter/engine#50114) 2024-01-27 skia-flutter-autoroll@skia.org Roll Dart SDK from 58665e3dee42 to 7ae508ee09a3 (1 revision) (flutter/engine#50112) 2024-01-27 skia-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from WHlwlOwznFknNm5IS... to GBTh3gOOgmndwT70X... (flutter/engine#50111) 2024-01-27 skia-flutter-autoroll@skia.org Roll Skia from 6279c88b9e29 to b9b80230c87b (4 revisions) (flutter/engine#50110) 2024-01-27 jonahwilliams@google.com [Impeller] add missing barrier to compute tessellator. (flutter/engine#50108) 2024-01-27 jonahwilliams@google.com [Android] Cache GPU resources using HardwareBuffer's id as key (flutter/engine#50028) 2024-01-27 54558023+keyonghan@users.noreply.github.com Move Mac builder_cache to prod (flutter/engine#50044) Also rolling transitive DEPS: fuchsia/sdk/core/linux-amd64 from WHlwlOwznFkn to GBTh3gOOgmnd 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
Reland of #50028 , which was reverted because I missed the different API level requirement of getId. getID now returns an optional which is nullopt on API level < 31. Fixes flutter/flutter#142365
Once a hardware buffer has been imported (a VkImage created for it), we don't ever need to re-create a VkImage, even when the contents change. The same hardware buffer can be identified by ID. Part of flutter/flutter#142153
Otherwise we spend a lot of time re-creating VkImages:
Draft is here, but is currently leaky: #50028
We only need something like a LRU with the max image size (seems to be 3 for me). This does log locally that I'm not calling close correctly:
FYI @johnmccutchan