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

[Impeller] Treat SubOptimalKHR as rotated. #43214

Merged
merged 2 commits into from
Jun 26, 2023

Conversation

jonahwilliams
Copy link
Member

@jonahwilliams jonahwilliams commented Jun 26, 2023

If we don't follow the guidelines at https://developer.android.com/games/optimize/vulkan-prerotation , then any presentations while the screen is rotated will result in suboptimalKHR. Use a change in state across presentations from sucess -> suboptimal or suboptimal -> sucess to detect whether the swapchain needs to be recreated.

Fixes flutter/flutter#129459 (mostly)

@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

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

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

I filed flutter/flutter#129580 to followup. But LGTM otherwise.

@chinmaygarde chinmaygarde changed the title [Impeller] treat suboptimalkhr as rotated. [Impeller] Treat SubOptimalKHR as rotated. Jun 26, 2023
@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 26, 2023
@auto-submit auto-submit bot merged commit e32f60a into flutter:main Jun 26, 2023
@jonahwilliams jonahwilliams deleted the rotate branch June 26, 2023 21:52
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 26, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 26, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jun 26, 2023
…129593)

flutter/engine@0da06de...715eff2

2023-06-26 58529443+srujzs@users.noreply.github.com Refactor JSNumber.toDart and Object.toJS (flutter/engine#43149)
2023-06-26 jonahwilliams@google.com [Impeller] Treat SubOptimalKHR as rotated. (flutter/engine#43214)
2023-06-26 skia-flutter-autoroll@skia.org Roll ANGLE from f6c7dc891859 to 4a4b13cc6931 (12 revisions) (flutter/engine#43213)
2023-06-26 skia-flutter-autoroll@skia.org Roll Skia from 632fa401098d to 4ae209493390 (3 revisions) (flutter/engine#43212)

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 jsimmons@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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
kjlubick pushed a commit to kjlubick/engine that referenced this pull request Jul 14, 2023
If we don't follow the guidelines at https://developer.android.com/games/optimize/vulkan-prerotation , then any presentations while the screen is rotated will result in suboptimalKHR. Use a change in state across presentations from sucess -> suboptimal or suboptimal -> sucess to detect whether the swapchain needs to be recreated.

Fixes flutter/flutter#129459 (mostly)
matanlurey added a commit to matanlurey/engine that referenced this pull request Aug 3, 2023
matanlurey added a commit that referenced this pull request Aug 10, 2023
tl;dr: Reverts #43214. closes
flutter/flutter#129459.


![7v5zfd](https://github.com/flutter/engine/assets/168174/b87a0726-cddd-415e-a46c-2c65d6f5c9d5)

---

In #43214, @jonahwilliams used
`vkQueuePresentKHR`[^1] [to
check](https://github.com/jonahwilliams/engine/blob/a0df46add166202fe68a853391d379e69ddc7c18/impeller/renderer/backend/vulkan/swapchain_impl_vk.cc#L465-L467)
if device orientations had changed, and if so, the swap-chain was torn
down and replaced with a new instance (that would now have a correct
rotation for ... compositing reasons I don't quite understand).

Unfortunately `vkQueuePresentKHR` is (a) only present on Android 10+
_and_ (b) ... isn't implemented consistently across Android devices. For
example, the popular Samsung Galaxy S10 doesn't return
`VK_SUBOPTIMAL_KHR`, leading to the same rotation bugs described in
flutter/flutter#129459 (i.e. even with
#43214).

This PR implements the polling technique recommended by Android[^2], in
this case on every frame. We should expect this to have a performance
penalty of ~`0.2`ms per frame, but should at least give us consistent
fidelity on Vulkan + Android for the time-being.


![flutter_04](https://github.com/flutter/engine/assets/168174/969f5c5e-7f6a-4156-8de8-1351b32f2a2f)

<details>
<summary>
Some additional screenshots generated while debugging
</summary>
<img src
="https://github.com/flutter/engine/assets/168174/900e02a8-aa51-4592-9690-c650092130a2"
/>
<img
src="https://github.com/flutter/engine/assets/168174/e7b9e5c0-86b0-407f-aa51-2f76afda4f03)"
/>
<img
src="https://github.com/flutter/engine/assets/168174/6b611090-97f5-4589-9ef9-6ba778efc6b7"
/>
</details>


[^1]:
https://developer.android.com/games/optimize/vulkan-prerotation#detect_device_orientation_changes
[^2]:
https://developer.android.com/games/optimize/vulkan-prerotation#using_polling
gaaclarke pushed a commit to gaaclarke/engine that referenced this pull request Aug 30, 2023
tl;dr: Reverts flutter#43214. closes
flutter/flutter#129459.


![7v5zfd](https://github.com/flutter/engine/assets/168174/b87a0726-cddd-415e-a46c-2c65d6f5c9d5)

---

In flutter#43214, @jonahwilliams used
`vkQueuePresentKHR`[^1] [to
check](https://github.com/jonahwilliams/engine/blob/a0df46add166202fe68a853391d379e69ddc7c18/impeller/renderer/backend/vulkan/swapchain_impl_vk.cc#L465-L467)
if device orientations had changed, and if so, the swap-chain was torn
down and replaced with a new instance (that would now have a correct
rotation for ... compositing reasons I don't quite understand).

Unfortunately `vkQueuePresentKHR` is (a) only present on Android 10+
_and_ (b) ... isn't implemented consistently across Android devices. For
example, the popular Samsung Galaxy S10 doesn't return
`VK_SUBOPTIMAL_KHR`, leading to the same rotation bugs described in
flutter/flutter#129459 (i.e. even with
flutter#43214).

This PR implements the polling technique recommended by Android[^2], in
this case on every frame. We should expect this to have a performance
penalty of ~`0.2`ms per frame, but should at least give us consistent
fidelity on Vulkan + Android for the time-being.


![flutter_04](https://github.com/flutter/engine/assets/168174/969f5c5e-7f6a-4156-8de8-1351b32f2a2f)

<details>
<summary>
Some additional screenshots generated while debugging
</summary>
<img src
="https://github.com/flutter/engine/assets/168174/900e02a8-aa51-4592-9690-c650092130a2"
/>
<img
src="https://github.com/flutter/engine/assets/168174/e7b9e5c0-86b0-407f-aa51-2f76afda4f03)"
/>
<img
src="https://github.com/flutter/engine/assets/168174/6b611090-97f5-4589-9ef9-6ba778efc6b7"
/>
</details>


[^1]:
https://developer.android.com/games/optimize/vulkan-prerotation#detect_device_orientation_changes
[^2]:
https://developer.android.com/games/optimize/vulkan-prerotation#using_polling
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.

[Impeller] Vulkan swapchain recreation is incorrect when rotating screen.
2 participants