Skip to content

D3D-97 follow-up: retire submissions in completion order - #1654

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
kovaaper:codex/d3d97-retirement
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
kovaaper:codex/d3d97-retirement

Conversation

@kovaaper

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #1548 (comment)
Depends on: #1404 (merged)

What and why

The separate Vulkan queues added by #1404 can complete in a different order from their host submissions. The old device-wide retirement timeline gave each submission a consecutive signal value; a later queue could signal its higher value first, making a deferred resource appear safe to destroy while an earlier queue still uses it. A subsequent lower signal could also violate Vulkan timeline ordering.

Each queue now signals only its own monotonic progress timeline. The device tracks accepted submissions in host order and retires only the contiguous prefix whose per-queue progress has completed. Queue destruction marks its submitted work complete after waiting idle, before its progress semaphore is destroyed. Deferred deletions take the submission lock while assigning their safe ticket so the deletion queue remains ordered.

A CPU-only regression test simulates queue 2 completing before queue 1 and verifies ticket 2 cannot retire ticket 1's resources. It also checks that a destroyed queue's semaphore is never queried.

Tested

Windows 11, NVIDIA GeForce RTX 3060 (driver 621.01), MSVC 19.44/Ninja, Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1: built the new test and four relevant D3D12 test targets; CTest retire_tickets, d3d12_com, d3d12_queue_wait, d3d12_vulkan_device, d3d12_multithread: 5/5 passed. The CPU test forces reverse completion order; the GPU tests exercise normal hardware scheduling.

Checklist

  • No game data, keys or decryption, including logs or reports quoted here.
  • No new shader translator rule (contract table not applicable).
  • AI-assisted (Codex).

Separate review concerns about the finite queue pool, staging handle reuse, and the timeout cleanup path remain outside this change.

@dcastell1 dcastell1 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 it on this machine (Windows 11, MSVC 19.44, Ninja):

1/1 Test #1: retire_tickets ... Passed 0.05 sec

The structure is right: only the contiguous prefix advances, and queue_idle() marking entries rather than erasing them keeps the FIFO intact for the other queues. Two assumptions worth stating in the header, since the type cannot enforce them: tickets must be recorded in increasing order on the calling thread (a duplicate or a ticket going backwards leaves the prefix stuck forever), and queue_idle() must be called with the queue actually idle — otherwise an entry is retired before its semaphore value is signalled. If the callers already guarantee both, ignore me.

@kovaaper

Copy link
Copy Markdown
Contributor Author

Follow-up for @dcastell1’s review: commit 73311ed documents both preconditions in retire_tickets.h. I also fixed the queue destructor to call queue_idle() only when vkQueueWaitIdle returns VK_SUCCESS; on failure it marks the device lost, and retirement stops querying progress semaphores. This prevents a failed wait from advancing the resource-retirement prefix. Rebuilt retire_tickets_test and d3d12_queue_wait_test on Windows 11 / RTX 3060 (driver 621.01), MSVC 19.44, Vulkan SDK 1.4.363.0; with LEONIDA_VK_VALIDATION=1, focused CTest 2/2 passed. Device-loss injection was not exercised; the new failure branch is reviewed by code inspection. No game files. AI-assisted (Codex).

ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51): pass. ctest: 90/90 on the RTX 4080 SUPER. The Intel UHD 770 failures are the known ones, all reported in #1548: d3d12_vulkan_device (line 3768), d3d12_descriptor (min-LOD), d3d12_present, d3d12_copy_xfmt.

@dcastell1

Copy link
Copy Markdown
Contributor

Re-ran retire_tickets on 73311ed (RTX 5090, MSVC 19.44, Ninja): Passed. The destructor checking vkQueueWaitIdle before calling queue_idle() closes exactly the window the review pointed at, and the two preconditions are now written down in the header. Nothing else needed from me.

@dracbat

dracbat commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 73311ed0 on AMD Radeon RX 5700 (RDNA1), AMD Adrenalin 26.11.2 (Vulkan driver 2.0.353), Windows 11: pass.

  • Full runtime ctest (MSVC 14.44, Ninja, RelWithDebInfo, Vulkan SDK 1.4.363.1): 91/91 pass, 1 skipped (d3d12_rgb9e5_rtv: no RGB9E5 colour attachment on this GPU). That includes queue_proxy, d3d12_multithread and the fence and queue tests.

AI-assisted (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit 3ed1912 into ItsNotRexed:main Nov 22, 2026
2 of 4 checks passed
@requiemsnkrp

Copy link
Copy Markdown

Tested 73311ed on NVIDIA GeForce RTX 3060 (driver 32.0.16.1714), Windows 11, MSVC 19.51, Windows SDK 10.0.26100: pass.

Built runtime/ (RelWithDebInfo) and ran ctest -E "present|swapchain|frame_pacer": 86/86 passed. The window tests (d3d12_present, xbox_present, dxgi_swapchain, frame_pacer) were not run for this PR. No Vulkan validation layers on this machine. No game files.

AI-assisted (Claude).

Raxstreams pushed a commit to Raxstreams/Leonida that referenced this pull request Nov 23, 2026
…submitted (D3D-203)

Since ItsNotRexed#1654 the deletion queue retires a released resource's Vulkan objects on the completed prefix of
device-wide submission tickets, so queues that complete out of submission order no longer free early. Work a
queue holds on the CPU (Wait-before-Signal, queue_holds.h) has no ticket and names resources by ID, resolved
when it is replayed: a resource released after B's later work completed was destroyed (and unregistered at
once), and the held batch then failed with result 2 (unresolved resource), or resolved a reused address.

- queue_holds.h: every held operation takes a place (held_added / held_removed, replacing held_changed);
  after_held() parks a release until every operation held at that moment, on any queue, has run or been
  dropped (later holds do not delay it); run_released() runs ready releases with no queue lock held, at the
  end of pump_ready() and from ~VulkanQueue. One atomic load when nothing is held.
- vulkan_backend.h: VulkanQueue gives each Deferred op its place, returns it after run() (so the submission is
  recorded first), on fence release and at teardown; DeferredDeletionQueue::size() and
  VulkanContext::deferred_destructions() for tests.
- d3d12_com_object.h: Object::Release calls Derived::final_release (default: delete). Resource::final_release
  parks the whole object through after_held(), so its ID, binding and Vulkan objects stay; ~Resource then runs
  as before and its objects take tickets after the held submissions.
- d3d12_com.h / d3d12_vulkan_device.cpp: rt::d3d12::deferred_destruction(device) {kept, waiting} for tests.
- queue_holds_test (CPU): out-of-order removal across queues, later holds ignored, runs once.
- d3d12_queue_handover_test: queue A holds stage[0] -> readback behind a CPU-signalled Wait, queue B's later
  work completes four times, stage[0] is released in between: kept 2, waiting 0; the CPU Signal submits A's
  batch (kept 0, waiting 2), the readback is exact, two more B rounds destroy the objects (0/0). The
  never-signalled and released-fence cases check a resource only the dropped batch names is kept, then
  destroyed with it. With the parking disabled the case finds both destroyed before the Signal and the batch
  fails with result 2. RTX 3060 / 617.14, LEONIDA_VK_VALIDATION=1 (sync validation): 372 layer cases, 0 errors.
- docs/d3d12_vulkan.md 4.4: deferred destruction across queues, what is still not covered.

AI-assisted.
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.

7 participants