Repository navigation
Conversation
run() unlocked mutex_ before dispatching ready entries, while cancel() only waited for an active vkWaitSemaphores. A cancel could return and destroy the VkSemaphore while a callback for it was still running. Record each dispatched entry with its owning thread before unlocking; cancel waits for entries it does not own, so callbacks can still re-entrantly cancel their own semaphore. All four run() dispatch paths use the same helper. Adds a deterministic regression where cancel must block until a blocked callback has used the semaphore; reverting only the wait fails it. AI-assisted (OpenCode)
Kam471
left a comment
There was a problem hiding this comment.
Built vk_fence_dispatcher_sync_test at df99c891 and ran it 10 times on Windows 11: every run printed "fence dispatcher: cancel waits for an in-flight callback ok" / vk_fence_dispatcher_sync_test: ok, exit 0.
FenceWaitDispatcher::cancel() now waits for an in-flight ready callback as well as the vkWaitSemaphores, closing the window where it returned while a callback was still using the semantic. No blocking issue.
|
Tested
No game data. AI-assisted. |
Flyander
left a comment
There was a problem hiding this comment.
[P2] Exempt only the callback currently executing on this thread. dispatch_outside_lock records the entire ready batch with the same owner before dispatch_entries runs it, while in_flight() ignores every same-owner entry. Repro: callbacks for semaphores A and B are both ready; A re-enters cancel(B) and destroys B. The nested cancel treats B as its own callback and returns, although B is already removed from pending_ and will still run next from the batch, potentially using the destroyed semaphore. Track the active entry (or otherwise defer cancellation of later same-batch callbacks) and add a deterministic two-ready-callback regression.
|
Tested
Interaction with #4445 (also in (Measured with full rebuilds: rebuilding only the two test targets left the D3D12 library on the old header and gave misleading results.) AI-assisted (Claude Code). |
|
Update: #4445 now carries the |
FenceWaitDispatcher recorded every entry of a ready batch with the dispatching thread as owner, and in_flight() ignored all same-owner entries. A callback for semaphore A that re-entered cancel(B) therefore returned while B was still queued in the same batch and would run with a semaphore the caller had already destroyed. Give each batch entry its own dispatch slot. cancel() marks not-yet-started slots for that semaphore as cancelled so dispatch skips them, while a callback actually running on another thread is still waited for. The skipped entry's event is completed so no waiter is left behind. Regression: two ready callbacks in one batch; A cancels B and B must not run. Red before (B ran), green after.
|
[P2] addressed in dea6c38: per-callback dispatch slots; a re-entrant cancel() skips not-yet-started same-batch callbacks and still waits for callbacks on other threads. Two-ready-callback regression red before, green after. Targeted 1/1; full CTest 154 passed, 0 failed, 0 validation errors. AI-assisted (OpenCode) |
|
Tested This pull request is for item 6 of my audit note (#4257 (comment)). Result The change in
All the failures are in case 6. Cases 1 to 5 passed in all 200 runs. Cause of Case 6 expects that the callbacks of A and B are in one ready batch. But the test signals the two fences with two calls: EXPECT(fence_a.signal(1));
EXPECT(fence_b.signal(1));The dispatcher thread can wake up between these two calls. Then the ready batch contains only A, and B stays in Proof: I added Cause of The callback of A sets Suggestions
Negative control With the One more point from the code A callback that |
|
Tested dea6c38 merged with main d0835dd (merged tree 385f4db288) on Windows 11 with two GPUs (MSVC 14.51): built
Negative control: |
|
Re-tested the new head
Why it depends on timing:
So a cancelled wait's callback runs if it was still pending and doesn't if it was already in the batch. Two consistent options:
To make step 6 deterministic either way, signal B before A (or wait until both counters read 1 before the dispatcher can wake), so the test exercises the same-batch path every time. AI-assisted (Claude Code). No game files. |
Case 6 assumed both fences were in one ready batch. The dispatcher may wake after the first signal, leaving B in pending_ when A calls cancel(B); in that case cancel() correctly runs B's callback before it returns. Assert the real contract instead: B must not run after cancel(B) returns, whether it was pending or already in a ready batch. Set the A-side flags in one lock scope so the waiter cannot see them half-updated. Red control on the parent source: 0/100 pass; fixed: 100/100 pass. Shdann and Exopus independently reproduced the timing dependence; kapitche verified the fix on two GPUs.
|
Addressed in AI-assisted (OpenCode) |
|
Re-tested |
|
Tested 047b789 on Windows 11 (MSVC BuildTools 2022, Ninja, RelWithDebInfo, -j 4; no Vulkan validation layer installed), one GPU at a time, device line confirmed: AMD Radeon RDNA2 iGPU (driver 26.10.1) and NVIDIA RTX 5080 (driver 616.92). Ran AI-assisted. |
|
Tested 047b789 on NVIDIA GeForce RTX 3070 (Ampere), driver 610.88, Windows 11 Pro 10.0.26200: pass
Built with MSVC through |
Fixes shdann's unclaimed item 6 from the runtime audit.
FenceWaitDispatcher::run()unlocked its mutex before dispatching ready callbacks, butcancel()only waited for an activevkWaitSemaphores. A cancel could therefore return while a callback for that semaphore was still running, letting the caller destroy it underneath the callback. Each dispatch now records its entries and owning thread before unlocking;cancel()waits for entries owned by other threads, so a callback can still re-entrantly cancel its own semaphore. All fourrun()dispatch paths use the same helper.Synthetic Vulkan regression: a callback blocks while a second thread calls
cancel(); cancel must not return until the callback has used the semaphore. Reverting only the wait fails the new assertion.RTX 3090/621.24 with validation: targeted 1/1, 10/10 stress, full CTest 154 passed, 0 failed, 0 validation errors. No game files.
AI-assisted (OpenCode)