vkback: present touches its fence and swapchain only after the submission thread is done #39
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/vktory6--VKtory!39
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-39"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@tmalik1116 on GitHub · 2026-12-01 03:11 UTC · original
tmalik1116:vkback-thread-safety→main· +28 −6 · 3 files · 1 commits · merged 2026-12-01 08:12 UTCFixes the "Thread safety" line of the docs/TASKS.md item "Vulkan validation errors" (swapchain and fence).
What was wrong
show()(greenfield/vkback/src/present.rs) setin_flightas soon as it handed the blit to the submission thread (Queued::run), before that thread had calledvkQueueSubmit(.., fence)andvkQueuePresentKHR(swapchain). The nextshow()then calledvkGetFenceStatus/vkResetFencesandvkAcquireNextImageKHR, which could run while the other thread was still inside those calls. Both parameters must be externally synchronized (Vulkan spec, "Threading Behavior"), and a signaled fence does not mean the present call has returned.The change
show()returns without showing the frame while aQueuedpresent is left (Out::queued > 0). That is the same not-waiting choice the fence check already makes, so the live thread never blocks on the submission thread. While a present is queued its fence cannot be signaled yet, so the only extra skip is the short time between its submit and its present's return.recreate()already waits for the queue (settle) and is unchanged. In all, 12 lines of code plus theQueueddoc comment. A learning goes indocs/learnings/present.md(rule 28).No D3D12-path counterpart: victory-gpu presents through vkd3d-proton's swapchain. The rule followed is the Vulkan spec's, not a reference behaviour.
Verification (rules 27 and 30)
RX 6800 XT (RDNA2, RADV NAVI21), Mesa 26.3.1,
vulkan-validation-layers1.4.363.1, core, thread-safety and shader checks, errors only.ac9badbUNASSIGNED-Threading-MultipleThreads-Readx3: VkFence,vkback-livevkGetFenceStatusvsvkback-submitvkQueueSubmitac9badb+ this19862d4+ this-Writeon VkQueue,vkDeviceWaitIdlevsvkQueueBindSparse(#38, code this change does not touch)73ee0ab-Readx3, VkFence, the same pair as above73ee0ab+ thisDistinct errors in the
73ee0abfix run:RuntimeSpirv-meshAndTaskShaderDerivatives-10153,vkBindImageMemory-memory-02728,VkBufferCreateInfo-size-06409,vkCmdDraw-dynamicRenderingUnusedAttachments-08910,VkComputePipelineCreateInfo-layout-01687,VkExportMemoryAllocateInfo-handleTypes-09860,VkGraphicsPipelineCreateInfo-layout-01688,VkRayTracingPipelineCreateInfoKHR-layout-03428,VkRenderingInfo-pNext-06079,VkRenderingInfo-pNext-06080,VkShaderModuleCreateInfo-pCode-08740,-08742. All are on the list except 08910, 06079 and 06080. Those also show on the base commit, so they are reported in #37 (rule 30).tools/play.shinto the world, 900 s, base and fix in the same scene.cargo test -p vkback --lib: 150 passed, 3 ignored.cargo test -p vkback --test policy: 6 passed.cargo xtask policy: ok.73ee0aband73ee0ab+ this: every kind is already owned in TASKS.md ("Loud-fail counters"). Nothing new.Why this is enough: the change only decides whether a frame is shown, and the thread-safety checks of the validation layer are the tool that sees this race. The picture is not changed beyond an occasional skipped frame, which the fence check already does.
Reported outside this change (rule 29)
vkDeviceWaitIdleonvkback-livevsvkQueueBindSparseonumem-binds.🤖 Generated with Claude Code
https://claude.ai/code/session_013Ci8ajhytjZ3vRHasVhzrB
@vktory6 on GitHub · 2026-12-01 08:11 UTC · original
Merged, thanks! The approach is the right one: skipping the frame while a present is still queued covers both the fence and the swapchain and never blocks the renderer.
Out::queueddrops only after the present call has returned, so the ordering holds. Check on the reference system (RX 9070 XT): tests pass, and the house-scene validation run shows no new error and no threading report. The thread-safety line for this pair is off the validation list. #38 (the device-idle pair) stays on it.