Skip to content

Runtime: a queue waiting on a released fence goes on, as on the host (D3D-496, case 2) - #4740

Open
0klavair wants to merge 2 commits into
ItsNotRexed:mainfrom
0klavair:runtime/released-fence-wait-continues
Open

0klavair wants to merge 2 commits into
ItsNotRexed:mainfrom
0klavair:runtime/released-fence-wait-continues

Conversation

@0klavair

Copy link
Copy Markdown

D3D-496, case 2. Claimed in the coordination issue as: #4683 (comment) (from @Exopus-0x65f7ad0's finding)

Depends on: #4663 (D3D-486, @requiemsnkrp). This branch is stacked on its head 0cc958d0. Only the last commit is this PR's.

What and why

When an ID3D12Fence is released while a queue holds a batch that waits on it, remove_fence → VulkanQueue::discard_waiting_on drops the batch ([rt] d3d12: a fence was released while a queue still held work waiting on it; that work is dropped). The host runtime lets the queue go on: the batch runs and the Signal after it is reached. An app may release a fence right after using it (a queue Wait takes no COM reference), so dropped batches mean missing GPU work and signals that never arrive.

The change

  • VulkanQueue::discard_waiting_on takes only the released fence's wait (semaphore + value) off each held operation, instead of erasing the operation. Runtime: keep a released fence's semaphore until the GPU is done with it (D3D-486) #4663 already does this for a Wait not yet attached to a submission. remove_fence's pump_ready() then releases the operation in queue order once its other waits are met. The semaphore is never waited on after the release, so Runtime: keep a released fence's semaphore until the GPU is done with it (D3D-486) #4663's deferred retirement stays valid.
  • Comments in queue_holds.h / vulkan_backend.h and the docs/d3d12_vulkan.md edge-case sentence describe the new behaviour.
  • d3d12_queue_handover_test, case "fence released while a batch waits", now runs on the layer and on the host runtime. The held batch copies the upload data to stage[1] and signals 101. The test checks the Signal is not reached before the release, that nothing is reported dropped, that after Release() the Signal reaches 101, and that a second submission reads stage[1] back exact.

Tested

On NVIDIA GeForce RTX 5060, driver 621.01, Windows 11 23H2 22631.6199, MSVC 19.44, Vulkan SDK 1.4.363:

Case 1 of D3D-496 (a postponed CPU Signal lost in ~Fence → cancel_fence_waits) is not in this PR. It builds on #4282 and will be a follow-up.

No game files. AI-assisted.

requiemsnkrp and others added 2 commits November 23, 2026 04:50
…kets (D3D-486)

~VulkanFence destroyed its timeline semaphore at once, though submissions made before (a queue Signal behind
other work, a GPU Wait for it) may still signal or wait for it: VUID-vkDestroySemaphore-semaphore-05149. A
queue Wait not yet attached to a batch, or a held Signal of the fence, would also be submitted later with the
destroyed handle.

- vulkan_backend.h: DeferredDeletionQueue::Kind::semaphore; ~VulkanFence calls remove_fence, then defers the
  semaphore (retired once every submission made before the release has completed).
  VulkanQueue::discard_waiting_on also forgets the semaphore: a Wait not yet attached counts as reached (as a
  released fence does for the CPU), a held Signal of it signals nothing; held batches waiting on it are still
  dropped and reported.
- queue_holds.h: remove_fence asks every queue, not only when something is held (a pending Wait names the
  fence too).
- d3d12_queue_handover_test: case on the layer and the host runtime, behind a ~300 ms GPU gate on the COPY
  queue: A a Signal and a DIRECT Wait in flight, B a Wait not yet attached, C a held Signal; each fence is
  released right away, readbacks exact. With the semaphore destroyed at once (origin/main behaviour) the layer
  gave VUID-vkDestroySemaphore-semaphore-05149 (A, B), VUID-VkSubmitInfo-pWaitSemaphores-parameter (B) and an
  access violation.
- docs/d3d12_vulkan.md 4.4.

RTX 3060 / 617.14, LEONIDA_VK_VALIDATION=1 with sync validation: 374 layer cases, 372 host, 0 messages.

AI-assisted.
…(D3D-496)

When an ID3D12Fence was released while a queue held a batch waiting on it,
VulkanQueue::discard_waiting_on dropped the batch and printed "that work is
dropped". The host runtime lets the queue go on: the batch runs and a Signal
after it is reached (measured on an RTX 5060 host, and by @Exopus-0x65f7ad0
on an RTX 5060 Ti with the debug layer on).

discard_waiting_on now takes only the released fence's wait off each held
operation, as ItsNotRexed#4663 already does for a Wait not yet attached to a
submission; remove_fence's pump_ready then releases the operation in queue
order once its other waits are met. No batch is dropped.

d3d12_queue_handover_test's "fence released while a batch waits" now checks
that behaviour on the layer and on the host runtime: the held batch copies
data to stage[1] and signals 101, and after the release the Signal is
reached and stage[1] reads back exact. Without the change the layer drops
the batch and the case fails.

@Kam471 Kam471 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.

Built and ran d3d12_queue_handover_test at d7e534067 on Windows 11, RTX 5070 Ti: exit 0.

  • fence released while a batch waits: the batch ran and its Signal was reached (the new D3D-496 case 2)
  • fences released while in use (gate of 265 copies): A Signal and Wait in flight, B Wait not yet attached, C held Signal: every readback exact
  • Vulkan layer 374 cases, every one exact; Host D3D12 373 cases, every one exact.

The change lets a queue that is waiting on a released fence continue (releasing the wait) instead of stalling, matching the host; the added scenario covers the batch finishing and signalling.

Merge check: clean with #4663 (exit 0), which is the natural pair; conflicts with #4681 (vulkan_backend.h), #4557 (vulkan_backend.h, handover test), #4570 (queue_holds.h) and #4577 (docs, handover test). git diff --check clean. No blocking issue.

@shdann

shdann commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested d7e53406 on Windows 11 with the RTX 4090 and AMD Radeon iGPU. The fence release test passes on both adapters.

I built d3d12_queue_handover_test in RelWithDebInfo. I ran the executable with LEONIDA_VK_DEVICE=4090 and then with LEONIDA_VK_DEVICE=Radeon. The device log confirms each Vulkan adapter. Each layer run passes all 374 cases. The native D3D12 run uses the RTX 4090 both times and passes all 373 cases. After fence release, the held batch completes its copy and the queue reaches signal value 101.

For the negative control, I used runtime/src/vulkan_backend.h from parent 0cc958d0 with the new test. I rebuilt the target. On the RTX 4090, the fence release case (seed 472) reports that the queue dropped the batch. The executable exits with code 1.

NVIDIA driver 32.0.16.2101. AMD driver 32.0.21043.5001. Vulkan validation was off.

AI-assisted.

@Atomic258

Copy link
Copy Markdown

Tested d7e53406 on Windows 11, NVIDIA GeForce RTX 5090 (driver 617.42), MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo.

Stacking: as declared, the branch is #4663 (0cc958d0, D3D-486) + this PR's commit on top; git log origin/main..HEAD shows exactly those two commits.

  • d3d12_queue_handover_test -> exit 0, 5/5 runs: fence released while a batch waits: the batch ran and its Signal was reached on both the Vulkan layer and the host runtime every time; layer 374 cases, host 373 cases, every one exact on each run.
  • One additional run with LEONIDA_VK_VALIDATION=1 -> exit 0, no VUIDs.
  • Related tests sharing queue_holds.h/vulkan_backend.h: d3d12_fence_timing_test, d3d12_queue_wait_test, d3d12_fence_waiter_test, d3d12_fence_events_test -> all exit 0.
  • git diff --check clean.

No blocking issue. AI-assisted.

@Exopus-0x65f7ad0

Copy link
Copy Markdown

Tested d7e53406 (stacked on #4663) on Windows 11 (26300), RTX 5060 Ti / 621.14, MSVC 14.51, Vulkan SDK 1.4.363.0, RelWithDebInfo, clean build with -DLEONIDA_LLVM_MC: full LEONIDA_VK_VALIDATION=1 ctest -j4 145/145, 0 VUIDs. With #4756 on top, my release-race probe runs B's batch 200/200 with 0 VUIDs in both orders, as the host does; numbers on #4756. 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.

6 participants