Skip to content

fix(vulkan): destroy old swapchains in the background once the driver is slow - #148

Merged
CoderDayton merged 1 commit into
mainfrom
fix/swapchain-destroy-stall
Nov 29, 2026
Merged

CoderDayton merged 1 commit into
mainfrom
fix/swapchain-destroy-stall

Conversation

@CoderDayton

Copy link
Copy Markdown
Owner

On some NVIDIA setups (a reporter on an MX230 + Iris laptop, X11) vkDestroySwapchainKHR on the old swapchain blocks the render thread for about 22 s on every resize.

Destroys stay inline and are timed. The first one that takes 1 s or more switches the session to destroying old swapchains on the teardown worker, so later resizes don't freeze. Drivers that destroy promptly keep the old path unchanged.

  • The swapchain being destroyed is held until the next create on the same surface and passed as oldSwapchain, so the driver doesn't refuse the new one with NATIVE_WINDOW_IN_USE. If that error still happens, it drains the worker and retries.
  • Surface and device destroys wait for pending swapchain destroys when needed.
  • vkCreateSwapchainKHR is now covered by the hang watchdog.

Tested with a test layer that makes every destroy take 3 s: the first one blocks and turns the switch on, after that resizes don't stall (the render thread continues 2 ms after the new create), and quitting exits cleanly with destroys pending. Unit tests cover the retirement bookkeeping.

… is slow

After an inline vkDestroySwapchainKHR takes 1 s or more, later destroys go to the teardown worker so resizes stop freezing the render thread.
@CoderDayton
CoderDayton merged commit 82a0afc into main Nov 29, 2026
6 checks passed
@CoderDayton
CoderDayton deleted the fix/swapchain-destroy-stall branch November 29, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant