Skip to content

Runtime: serialize presenter swapchain destruction with queue submissions - #3551

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
pmilewsskiedu-gif:fix/presenter-wsi-destroy-host-sync-20261122
Nov 23, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
pmilewsskiedu-gif:fix/presenter-wsi-destroy-host-sync-20261122

Conversation

@pmilewsskiedu-gif

Copy link
Copy Markdown
Contributor

Root cause

VulkanPresenter::recreate serialized its explicit vkQueueWaitIdle through VulkanContext::submit_mutex() but released that mutex before release(old) called vkDestroySwapchainKHR. An installed Vulkan capture layer may itself call vkDeviceWaitIdle from its swapchain-destruction hook. That hidden device-idle operation overlapped VulkanQueue::submit on another thread and triggered Vulkan validation's external-host-sync THREADING ERROR. This is distinct from #3481, which concerns scratch/depth24 helper generations.

Fix

Serialize retired swapchain destruction with submit_mutex() (including resize/minimized window, destructor, and failed new-swapchain discard), matching the queue-submit lock already used by Leonida. No warning filters or changes to unrelated helpers; keep queue idle and swapchain release ordering.

Synthetic negative/positive regression

Extend vk_presenter_sync_test with an original WSI-like dispatch hook which parks vkDestroySwapchainKHR, allows a competing real VulkanQueue::execute to attempt submission, and emulates hidden vkDeviceWaitIdle on release. Assert that no vkQueueSubmit reaches the intercepted Vulkan entry point during swapchain destruction. The synthetic hook is game-independent and uses no proprietary files. On clean f847748c with test-only hook: 8/8 deterministic FAIL at !driver::overlap_detected. With this production fix: 20/20 PASS with Medal active, 12/12 PASS with Medal disabled; the targeted baseline/post-fix negative control used the same test source. Further 80/80 PASS with Medal active and validation enabled.

Original intermittent validation reproduction and layer attribution

Windows 11 / RTX 4060 Ti / Vulkan SDK 1.4.363 / LEONIDA_VK_VALIDATION=1. An older unmodified presenter test showed 7/15 FAIL this round. Independent 100-run original binary stress: 17/100 exact THREADING ERROR failures with VK_LAYER_MEDAL_CAPTURE_V2 active, 0/100 failures with DISABLE_VULKAN_MEDAL_CAPTURE_V2=1. API dump without validation: with Medal active, 6 device-idle calls / 4 swapchain destroys, four extra device-idles nested in destroy; with Medal disabled, 1 idle / 4 destroys (the one legitimate post-test vktest::Device destructor wait). OBS hook disabled alone did not remove the extra idles. This is a third-party-layer-triggered host-sync robustness defect; no symbolic Medal DLL frames were captured. Do not generalize this to intrinsic Vulkan driver behavior.

Verification

  • MSVC compiled vk_presenter_sync_test and vk_queue_query_sync_test successfully (focused build).
  • LEONIDA_VK_VALIDATION=1, RTX 4060 Ti: vk_presenter_sync, vk_queue_query_sync 2/2 PASS, zero Vulkan errors.
  • Synthetic isolated baseline 8/8 FAIL; patched test 20/20 PASS, separate native GPU stress 80/80 PASS with Medal active, and 12/12 PASS with Medal disabled.
  • git diff --check clean. No full suite was rerun, no game corpus used.

Commit: 3ff15669c2f221d1e310b888b0574f73bcaecbdf (2 files, +99/-3).

Ownership: #3381 comment #3381 (comment), claimed before PR.

AI assistance disclosure: Development, source review, synthetic regression design and testing were AI-assisted, with independently run native Vulkan validation and original-vs-fixed negative controls. No proprietary game-derived code, shaders, assets, executables or results are included.

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

At 3ff1566, RTX 5070 / 616.56 on native Windows with Vulkan validation: presenter sync passed 10/10 and queue query sync passed 3/3. Parent f847748 with identical regression source failed the intended overlap assertion 3/3. The concurrency hook exercises recreation; minimized and failed replacement paths were source-reviewed only. A sufficiently delayed worker could miss the 50 ms overlap window. No #3481 dependency found. AI-assisted synthetic validation.

@crastinator

Copy link
Copy Markdown
Contributor

Tested 3ff1566 merged into main f847748c (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • Whole run_gpu_tests.py: 185/199 native, 185/199 with LEONIDA_W64_EMULATE=1 (the skips are the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 41/41.

No game files. AI-assisted (Claude Code).

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 3ff1566 merged onto main aa2988c on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:

  • Full ctest: 154/154.
  • vk_presenter_sync: passes 20 of 20 runs, and passes under LEONIDA_VK_VALIDATION=1 with 0 validation messages.
  • Warnings: none new in the files this PR changes.

AI-assisted (Claude Code).

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.

5 participants