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

[Impeller] Fix a race between SwapchainImplVK::Present and WaitForFence #49777

Merged
merged 1 commit into from
Jan 16, 2024

Conversation

jason-simmons
Copy link
Member

The previous implementation used an fml::CountDownLatch to synchronize between FrameSynchronizer::WaitForFence and the task queued by SwapchainImplVK::Present.

fml::CountDownLatch:Wait always waits, even if the count is already zero. So the raster thread would deadlock if the present task signals the latch before FrameSynchronizer::WaitForFence enters the wait.

This PR instead uses a semaphore that is set each time SwapchainImplVK::Present is called. FrameSynchronizer::WaitForFence will check the semaphore to determine whether a present task is pending and if so wait for its completion.

@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 "@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.

The previous implementation used an fml::CountDownLatch to synchronize between FrameSynchronizer::WaitForFence and the task queued by SwapchainImplVK::Present.

fml::CountDownLatch:Wait always waits, even if the count is already zero.  So the raster thread would deadlock if the present task signals the latch before FrameSynchronizer::WaitForFence enters the wait.

This PR instead uses a semaphore that is set each time SwapchainImplVK::Present is called.  FrameSynchronizer::WaitForFence will check the semaphore to determine whether a present task is pending and if so wait for its completion.
@jason-simmons jason-simmons force-pushed the iplr_vk_present_latch_race branch from 2f80d6b to 13e1e3f Compare January 16, 2024 21:24
@Hixie
Copy link
Contributor

Hixie commented Jan 16, 2024

test-exempt: not really testable

@Hixie
Copy link
Contributor

Hixie commented Jan 16, 2024

(bonus points for figuring out a way to reliably trigger the deadlock though!)

@jason-simmons
Copy link
Member Author

I had originally noticed this while running the Lottie animation example from flutter/flutter#139796 with Impeller/Vulkan.

On a Pixel 6a the app typically hangs within a few minutes. With this PR I have not seen the hang.

@jason-simmons jason-simmons added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 16, 2024
@auto-submit auto-submit bot merged commit 8478c2f into flutter:main Jan 16, 2024
26 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 16, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jan 17, 2024
…141651)

flutter/engine@d4b6b7e...021a5ff

2024-01-16 [email protected] [web] Leave blob URLs untouched in TT policy. (flutter/engine#49782)
2024-01-16 [email protected] [Impeller] Fix a race between SwapchainImplVK::Present and WaitForFence (flutter/engine#49777)
2024-01-16 [email protected] Reland "[Windows] Move to FlutterCompositor for rendering" (flutter/engine#49726)
2024-01-16 [email protected] [Impeller] Add an API for sampling strictly within the bounds of the source rect in DrawImageRect (flutter/engine#49696)
2024-01-16 [email protected] [Impeller] Encode directly to command buffer for Vulkan. (flutter/engine#49780)

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
auto-submit bot added a commit to flutter/flutter that referenced this pull request Jan 17, 2024
…isions)" (#141659)

Reverts #141651
Initiated by: jonahwilliams
This change reverts the following previous change:
Original Description:

flutter/engine@d4b6b7e...021a5ff

2024-01-16 [email protected] [web] Leave blob URLs untouched in TT policy. (flutter/engine#49782)
2024-01-16 [email protected] [Impeller] Fix a race between SwapchainImplVK::Present and WaitForFence (flutter/engine#49777)
2024-01-16 [email protected] Reland "[Windows] Move to FlutterCompositor for rendering" (flutter/engine#49726)
2024-01-16 [email protected] [Impeller] Add an API for sampling strictly within the bounds of the source rect in DrawImageRect (flutter/engine#49696)
2024-01-16 [email protected] [Impeller] Encode directly to command buffer for Vulkan. (flutter/engine#49780)

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
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 17, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 17, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jan 17, 2024
…141664)

flutter/engine@d4b6b7e...1382ff7

2024-01-16 [email protected] Remove iOS 12 availability checks (flutter/engine#49771)
2024-01-16 [email protected] [Impeller] generate mipmaps for imagefilters (flutter/engine#49794)
2024-01-16 [email protected] [web] Leave blob URLs untouched in TT policy. (flutter/engine#49782)
2024-01-16 [email protected] [Impeller] Fix a race between SwapchainImplVK::Present and WaitForFence (flutter/engine#49777)
2024-01-16 [email protected] Reland "[Windows] Move to FlutterCompositor for rendering" (flutter/engine#49726)
2024-01-16 [email protected] [Impeller] Add an API for sampling strictly within the bounds of the source rect in DrawImageRect (flutter/engine#49696)
2024-01-16 [email protected] [Impeller] Encode directly to command buffer for Vulkan. (flutter/engine#49780)

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
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
Projects
No open projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

3 participants