Repository navigation
Runtime: serialize presenter swapchain destruction with queue submissions - #3551
Conversation
kacper-serewis
left a comment
There was a problem hiding this comment.
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.
|
Tested
No game files. AI-assisted (Claude Code). |
|
Tested 3ff1566 merged onto main aa2988c on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:
AI-assisted (Claude Code). |
Root cause
VulkanPresenter::recreateserialized its explicitvkQueueWaitIdlethroughVulkanContext::submit_mutex()but released that mutex beforerelease(old)calledvkDestroySwapchainKHR. An installed Vulkan capture layer may itself callvkDeviceWaitIdlefrom its swapchain-destruction hook. That hidden device-idle operation overlappedVulkanQueue::submiton 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_testwith an original WSI-like dispatch hook which parksvkDestroySwapchainKHR, allows a competing realVulkanQueue::executeto attempt submission, and emulates hiddenvkDeviceWaitIdleon release. Assert that novkQueueSubmitreaches the intercepted Vulkan entry point during swapchain destruction. The synthetic hook is game-independent and uses no proprietary files. On cleanf847748cwith 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 withVK_LAYER_MEDAL_CAPTURE_V2active, 0/100 failures withDISABLE_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-testvktest::Devicedestructor 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
vk_presenter_sync_testandvk_queue_query_sync_testsuccessfully (focused build).LEONIDA_VK_VALIDATION=1, RTX 4060 Ti:vk_presenter_sync,vk_queue_query_sync2/2 PASS, zero Vulkan errors.git diff --checkclean. 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.