vkback: check the present fence under the queue lock #50

Closed
github-bot wants to merge 1 commit from github-bot/gh-50 into main AGit
Owner

@⁠TheRifai on GitHub · 2026-12-01 05:20 UTC · original
TheRifai:vkback-present-fence-lock → main · +12 −4 · 1 files · 1 commits · closed without merging

What

The present blit's fence is submitted on the submission thread (Queued::run, under dev::queue_lock), but the renderer checked and reset that same fence on the live thread, so vkGetFenceStatus/vkResetFences raced the submission thread's vkQueueSubmit. The check now takes the same queue lock, serializing the two threads.

Evidence

Reproduced with the validation layer on a camera sweep of the house save:

Validation Error: [ UNASSIGNED-Threading-MultipleThreads-Read ]
vkGetFenceStatus(): ... thread "vkback-live" (vkGetFenceStatus) and thread "vkback-submit" (vkQueueSubmit)
Objects: 1
    [0] VkFence 0x5170000000517

After the change, the same sweep logs no UNASSIGNED-Threading-* line and no new VUID. (The VUID is timing-dependent, so the "before" run is the one that caught it; the "after" run is the same command on the patched tree.)

**@⁠TheRifai** on GitHub · 2026-12-01 05:20 UTC · [original](https://github.com/vktory6/VKtory/pull/50) `TheRifai:vkback-present-fence-lock` → `main` · +12 −4 · 1 files · 1 commits · closed without merging ## What The present blit's fence is submitted on the submission thread (`Queued::run`, under `dev::queue_lock`), but the renderer checked and reset that same fence on the live thread, so `vkGetFenceStatus`/`vkResetFences` raced the submission thread's `vkQueueSubmit`. The check now takes the same queue lock, serializing the two threads. ## Evidence Reproduced with the validation layer on a camera sweep of the house save: ``` Validation Error: [ UNASSIGNED-Threading-MultipleThreads-Read ] vkGetFenceStatus(): ... thread "vkback-live" (vkGetFenceStatus) and thread "vkback-submit" (vkQueueSubmit) Objects: 1 [0] VkFence 0x5170000000517 ``` After the change, the same sweep logs no `UNASSIGNED-Threading-*` line and no new VUID. (The VUID is timing-dependent, so the "before" run is the one that caught it; the "after" run is the same command on the patched tree.)
The present blit's fence is submitted on the submission thread (Queued::run,
under dev::queue_lock) but the renderer checked and reset it on the live
thread, so a get_fence_status/reset_fences raced a queue_submit on the same
fence. The validation layer reports it as
UNASSIGNED-Threading-MultipleThreads-Read. The check now takes the same queue
lock, serializing the two threads.

Reproduced with the validation layer on a camera sweep: vkGetFenceStatus on
vkback-live vs vkQueueSubmit on vkback-submit, fence 0x5170000000517.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 05:21:15 +00:00
github-bot closed this pull request 2026-12-01 07:38:36 +00:00
Author
Owner

@⁠vktory6 on GitHub · 2026-12-01 07:35 UTC · original

Thank you, and the validation report is right: the fence check raced the submission thread. I'm closing this in favour of #39, which fixes the same race differently, for two reasons:

  • Waiting: taking dev::queue_lock on the renderer thread makes the renderer wait whenever the submission thread holds the lock, and that thread holds it for every submit and present (and umem's binds take the same queue). The present path is built so that the renderer never waits there (see the comment above the fence check).
  • The swapchain: the other half of the race is the swapchain. vkAcquireNextImageKHR on the renderer can run while the submission thread is still inside vkQueuePresentKHR. A lock around the fence check doesn't cover that.

#39 skips the frame while a present is still queued (Out::queued > 0). That covers both objects and never blocks. Thanks for catching it!

**@⁠vktory6** on GitHub · 2026-12-01 07:35 UTC · [original](https://github.com/vktory6/VKtory/pull/50#issuecomment-7304241470) Thank you, and the validation report is right: the fence check raced the submission thread. I'm closing this in favour of #39, which fixes the same race differently, for two reasons: - **Waiting:** taking `dev::queue_lock` on the renderer thread makes the renderer wait whenever the submission thread holds the lock, and that thread holds it for every submit and present (and umem's binds take the same queue). The present path is built so that the renderer never waits there (see the comment above the fence check). - **The swapchain:** the other half of the race is the swapchain. `vkAcquireNextImageKHR` on the renderer can run while the submission thread is still inside `vkQueuePresentKHR`. A lock around the fence check doesn't cover that. #39 skips the frame while a present is still queued (`Out::queued > 0`). That covers both objects and never blocks. Thanks for catching it!
Author
Owner

@⁠TheRifai on GitHub · 2026-12-01 08:04 UTC · original

Makes sense — #39's skip-while-queued covers the swapchain half too and keeps the renderer off the lock entirely. Thanks for the clear write-up; closing this one is the right call.

**@⁠TheRifai** on GitHub · 2026-12-01 08:04 UTC · [original](https://github.com/vktory6/VKtory/pull/50#issuecomment-7304846495) Makes sense — #39's skip-while-queued covers the swapchain half too and keeps the renderer off the lock entirely. Thanks for the clear write-up; closing this one is the right call.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.