Skip to content

Conversation

@remifontan
Copy link
Contributor

Hi,

this PR is more like a request for comments than an a proper actual fix.

I noticed on Mac OSX, some of the examples may crash when their windows is being resized. The example egui seems particularly prone to that issue.

the debugger shows that the segfault always happens in the following function:

; Symbol: MVKSwapchain::beginPresentation(MVKImagePresentInfo const&), mangled name=_ZN12MVKSwapchain17beginPresentationERK19MVKImagePresentInfo

I found this issue on MoltenVK's repo: KhronosGroup/MoltenVK#2031
which seems to imply that vkDeviceWaitIdle() should be called when a resize is being detected.

Therefore, I added a call to device.device_wait_idle() just before destroying the old swap_chain, and that seems quite successful on my side so far.

Another thing, perhaps related:
some of the examples are flickering quite a bit when their window is being resized:

  • font_bmp
  • image_sampler

Once I added that call to device_wait_idle, the amount of flickering got reduced, but unfortunately is still happening. So perhaps this is not the right fix or there is something else happening.

@attackgoat attackgoat added the bug Something isn't working label Apr 6, 2025
@attackgoat
Copy link
Owner

I'm not able to reproduce the segfault, but I do see the flickering. Oddly the flickering isn't present at all on my normal testing Mac (an M2 mini).

I borrowed two other Macs and both flicker during resize, making it impossible to see the rendered window contents while resizing. At first I thought maybe a queue_wait_idle(..) might be a more appropriate fix, but no, it has no effect, just like the MoltenVK issue suggests.

The fix in this PR does work (on all platforms, too) but it is probably not what you expect because that function is called every frame. Also I still see a small amount of flicker during resize. Moving the idle into the contained null-check made the flickering worse than this PR, but better than nothing.

I found that doing a device_wait_idle() right when the window detects a resize event (so inside the Swapchain::set_info(..) function) works well, but there still is a very small amount of flicker. Combining this with an idle inside the null-check of Swapchain::destroy_swapchain(..) eliminates the flicker for me.

Other things I tried:

  • Multiple repeated device_wait_idle() calls: Works and solves the flicker completely, but obviously that's just delaying the MoltenVK code from running which allows the bug to be fixed by timing
  • std::thread::yield_now() in various places: no effect

Windows and Linux don't seem to be affected by the presence of these fixes in any way, but it would be hygienic to wrap any changes in #[cfg(target_os = "macos")] or something.

I tested these variations on:

  • MacBook Pro 2016 Intel HD 530 & AMD Radeon Pro 450 (Monterey 12.7.6)
  • MacBook Pro 2023 M3 Max (Sequoia 15.4)
  • Mac mini 2023 M2 (Sonoma 14.4.1)
  • Windows 11 Intel Iris Xe
  • Windows 10 AMD Radeon Pro 6500 XT (also Ubuntu 25.04 X11 & Wayland)
  • Windows 10 NVIDIA GeForce RTX 3090 (also Ubuntu 24.04 X11 & Wayland)

How do these changes work for you? I can push up what I'm talking about if that helps. And thank you for the detailed report!!

@remifontan
Copy link
Contributor Author

I have added changes based on my understanding of your reply, let me know if you meant something else.

For reference, I have Macbook M1 Max wit OSX 15.3.2 - perhaps it behaves a little different from your machines.

the additional device.device_wait_idle() in Swapchaing::set_info is unfortunately not making much differences on my side. However, the crash is avoided as long as I have one of those two device.device_wait_idle().

@attackgoat attackgoat merged commit bff3363 into attackgoat:master Apr 7, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants