d3d12: LEONIDA_RELEASE_WORKER=1 releases a queue's held work on its own worker, not on the signalling thread (RT-RELEASER-HELD-REPLAY) #2541

Closed
leonida/mandy
tiguan26 wants to merge 0 commits from rt-releaser-held-replay into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

tiguan26 commented 2026-11-28 01:35:16 +00:00

Item: RT-RELEASER-HELD-REPLAY (claimed in #1608). Builds on main alone; no dependencies.

What it changes and why

A D3D12 Wait whose value has not been signalled holds the queue's work; the Signal that makes it ready records and
submits that held work inline, on the thread that signalled. The list values' releaser signals the gates of every
queue from one thread, so one queue's replay, with its first-use pipeline builds (38-93 s each when cold with
LEONIDA_ASYNC_PIPELINES off), holds every other queue's release behind it: djrolfes measured one release taking
26 minutes, with the other queues idle and waiting.

With LEONIDA_RELEASE_WORKER=1, the Signal only asks: the held queue's own worker records and submits its held
work, and the signalling thread goes on at once. Each queue's replay cost stays with that queue. This removes the
cause of that stall (one thread doing every queue's replay) rather than shortening it.

Off by default, as #2464 asks for new settings until game runs on two vendors show it right. Unset, held work is
released on the signalling thread exactly as on main.

Files

This touches only VulkanQueue's held-work and worker code in runtime/src/vulkan_backend.h (release_ready,
release_held, run, async_worker, flush_async, submit, discard_waiting_on) and QueueHolds::pump_now in
runtime/src/queue_holds.h. It does not touch the title upload and wait parts of vulkan_backend.h or any file
#2464 lists as off limits; the releaser it helps lives in d3d12_xs_list_values.h, which is unchanged.

Change

  • VulkanQueue::release_ready (with the setting on) hands the release to the queue's own worker: the
    LEONIDA_SUBMIT_ASYNC worker, or one started for releases alone on the queue's first release. The worker replays,
    then pumps the other queues.
  • A worker that is itself inside the pump asks for its own queue's release instead of running it there, so another
    queue's request is not left waiting behind that replay. flush_async also waits for a requested release and for the
    worker's pump after it.
  • QueueHolds::pump_now: a pass run after any pass in progress, with no "nothing to do" shortcut (a pass on another
    thread takes a queued Present off the list before running it, so an empty list can still mean a Present in
    progress). VulkanQueue::idle() and the queue destructor use it, so the Presents queued behind released or dropped
    work have run when they return.
  • A queue being destroyed starts no worker: stop_async() closes the door under the lock start_release_worker()
    takes. Without that, another thread's pump could ask a queue to release until its destructor detaches it, and the
    worker started then would outlive the queue (queue_proxy's 8-thread test aborted on exactly that during
    development).
  • An exception in a worker's replay is recorded as a held failure and marks the device lost instead of ending the
    process.
  • LEONIDA_HELD_RUN_DELAY_MS=<n> sleeps before each held operation, for tests only; it costs nothing when unset.
  • docs/d3d12_vulkan.md: the Wait-before-Signal paragraph describes the default and the setting.

Tests

  • New d3d12_held_release_worker_test, two CTest entries. Two queues each hold two Signals behind a gate; one thread
    signals both gates, as the releaser does; each held operation waits 1.5 s.
    • d3d12_held_release_worker (LEONIDA_RELEASE_WORKER=1): both Signals return at once, each queue's held work
      takes its 3 s, and the two queues finish side by side, in order on each queue.
    • d3d12_held_release_on_signaller (the default): the signalling thread runs A's held work before it reaches B's
      gate, as on main.
    • Fails on main: the test built against main's vulkan_backend.h and queue_holds.h, run with
      LEONIDA_RELEASE_WORKER=1, fails at the check that the held work took its time (main has neither the worker nor
      the delay hook: "held work done at 1 ms").
  • New CTest entries vk_presenter_sync_release_worker and vk_queue_query_sync_release_worker run those two tests
    with the setting on, since the Present and failed-Signal races above only occur with it. Both tests now wait the way
    an application does (a fence behind the held batch, idle()) instead of assuming the release is synchronous.

What I ran: cross-built with clang-cl 19 + xwin, run under Wine 11.22 on llvmpipe (Mesa, LLVM 20.1.2), 2 cores, on
main d442851972 (after the port/d3d12-nvidia merge), one commit. It merges cleanly onto the current main
431ceba4f4, whose three newer commits change none of these files.

Test Result
d3d12_held_release_worker, d3d12_held_release_on_signaller 3/3 each
vk_presenter_sync, vk_presenter_sparse_capture, vk_presenter_sync_release_worker 3/3 each
vk_queue_query_sync, vk_queue_query_sync_release_worker 3/3 each
queue_proxy, default / LEONIDA_RELEASE_WORKER=1 3/3 / 4/4 (12/12 before the rebase)
d3d12_staged_copy_wait (main's, uses wait_submitted), default / LEONIDA_RELEASE_WORKER=1 3/3 / 4/4
full ctest (509 tests) 488 pass; the 21 failures are not this change's (see below)

The 21 full-ctest failures under Wine/llvmpipe here: the 18 that failed on main in this same setup when I last ran
main's full suite (d1dff7949): gameinput_host, root_sig, the three xmem, file_system, both bcrypt_rng,
vk_device_filter_tools, d3d12_descriptor, pipeline_cache_seed, d3d12_clear, d3d12_view_slices, both
d3d12_indirect_rt, d3d12_subgroup, d3d12_clear_formats, d3d12_set_descriptor_heaps; module_names and
xgameruntime, whose binaries do not include the files this change touches; and run_tiny_game_console_paths, where
this Wine prefix's locale turns the test's Unicode overlay folder name into ? (ERROR_INVALID_NAME), the same cause
as file_system.

python -I scripts/check_no_game_data.py on the changed files is clean, and the doc tests pass except
test_docs_links, which fails on main for README.md's assets/mandy.png. The translator is untouched.

Not tested: any GPU but llvmpipe, and any game run. The real check is a retail boot with cold pipeline compiles
and LEONIDA_RELEASE_WORKER=1, compared with the same run without it (Snooozs, djrolfes: your stall snapshots from
the list-values work are what this targets).

GPUs tested: llvmpipe (Mesa, LLVM 20.1.2) under Wine 11.22 on Linux.

AI-assisted (Claude Code, Claude Opus 5.5).

🤖 Generated with Claude Code

**Item:** RT-RELEASER-HELD-REPLAY (claimed in #1608). Builds on main alone; no dependencies. ## What it changes and why A D3D12 `Wait` whose value has not been signalled holds the queue's work; the `Signal` that makes it ready records and submits that held work **inline, on the thread that signalled**. The list values' releaser signals the gates of every queue from one thread, so one queue's replay, with its first-use pipeline builds (38-93 s each when cold with `LEONIDA_ASYNC_PIPELINES` off), holds every other queue's release behind it: djrolfes measured one release taking 26 minutes, with the other queues idle and waiting. With `LEONIDA_RELEASE_WORKER=1`, the `Signal` only asks: the held queue's own worker records and submits its held work, and the signalling thread goes on at once. Each queue's replay cost stays with that queue. This removes the cause of that stall (one thread doing every queue's replay) rather than shortening it. **Off by default**, as #2464 asks for new settings until game runs on two vendors show it right. Unset, held work is released on the signalling thread exactly as on main. ## Files This touches only `VulkanQueue`'s held-work and worker code in `runtime/src/vulkan_backend.h` (`release_ready`, `release_held`, `run`, `async_worker`, `flush_async`, `submit`, `discard_waiting_on`) and `QueueHolds::pump_now` in `runtime/src/queue_holds.h`. It does not touch the title upload and wait parts of `vulkan_backend.h` or any file #2464 lists as off limits; the releaser it helps lives in `d3d12_xs_list_values.h`, which is unchanged. ## Change - `VulkanQueue::release_ready` (with the setting on) hands the release to the queue's own worker: the `LEONIDA_SUBMIT_ASYNC` worker, or one started for releases alone on the queue's first release. The worker replays, then pumps the other queues. - A worker that is itself inside the pump asks for its own queue's release instead of running it there, so another queue's request is not left waiting behind that replay. `flush_async` also waits for a requested release and for the worker's pump after it. - `QueueHolds::pump_now`: a pass run after any pass in progress, with no "nothing to do" shortcut (a pass on another thread takes a queued Present off the list before running it, so an empty list can still mean a Present in progress). `VulkanQueue::idle()` and the queue destructor use it, so the Presents queued behind released or dropped work have run when they return. - A queue being destroyed starts no worker: `stop_async()` closes the door under the lock `start_release_worker()` takes. Without that, another thread's pump could ask a queue to release until its destructor detaches it, and the worker started then would outlive the queue (`queue_proxy`'s 8-thread test aborted on exactly that during development). - An exception in a worker's replay is recorded as a held failure and marks the device lost instead of ending the process. - `LEONIDA_HELD_RUN_DELAY_MS=<n>` sleeps before each held operation, for tests only; it costs nothing when unset. - `docs/d3d12_vulkan.md`: the Wait-before-Signal paragraph describes the default and the setting. ## Tests - New `d3d12_held_release_worker_test`, two CTest entries. Two queues each hold two Signals behind a gate; one thread signals both gates, as the releaser does; each held operation waits 1.5 s. - `d3d12_held_release_worker` (`LEONIDA_RELEASE_WORKER=1`): both Signals return at once, each queue's held work takes its 3 s, and the two queues finish side by side, in order on each queue. - `d3d12_held_release_on_signaller` (the default): the signalling thread runs A's held work before it reaches B's gate, as on main. - **Fails on main:** the test built against main's `vulkan_backend.h` and `queue_holds.h`, run with `LEONIDA_RELEASE_WORKER=1`, fails at the check that the held work took its time (main has neither the worker nor the delay hook: "held work done at 1 ms"). - New CTest entries `vk_presenter_sync_release_worker` and `vk_queue_query_sync_release_worker` run those two tests with the setting on, since the Present and failed-Signal races above only occur with it. Both tests now wait the way an application does (a fence behind the held batch, `idle()`) instead of assuming the release is synchronous. What I ran: cross-built with clang-cl 19 + xwin, run under Wine 11.22 on llvmpipe (Mesa, LLVM 20.1.2), 2 cores, on main `d442851972` (after the `port/d3d12-nvidia` merge), one commit. It merges cleanly onto the current main `431ceba4f4`, whose three newer commits change none of these files. | Test | Result | |---|---| | `d3d12_held_release_worker`, `d3d12_held_release_on_signaller` | 3/3 each | | `vk_presenter_sync`, `vk_presenter_sparse_capture`, `vk_presenter_sync_release_worker` | 3/3 each | | `vk_queue_query_sync`, `vk_queue_query_sync_release_worker` | 3/3 each | | `queue_proxy`, default / `LEONIDA_RELEASE_WORKER=1` | 3/3 / 4/4 (12/12 before the rebase) | | `d3d12_staged_copy_wait` (main's, uses `wait_submitted`), default / `LEONIDA_RELEASE_WORKER=1` | 3/3 / 4/4 | | full ctest (509 tests) | 488 pass; the 21 failures are not this change's (see below) | The 21 full-ctest failures under Wine/llvmpipe here: the 18 that failed on main in this same setup when I last ran main's full suite (`d1dff7949`): `gameinput_host`, `root_sig`, the three `xmem`, `file_system`, both `bcrypt_rng`, `vk_device_filter_tools`, `d3d12_descriptor`, `pipeline_cache_seed`, `d3d12_clear`, `d3d12_view_slices`, both `d3d12_indirect_rt`, `d3d12_subgroup`, `d3d12_clear_formats`, `d3d12_set_descriptor_heaps`; `module_names` and `xgameruntime`, whose binaries do not include the files this change touches; and `run_tiny_game_console_paths`, where this Wine prefix's locale turns the test's Unicode overlay folder name into `?` (`ERROR_INVALID_NAME`), the same cause as `file_system`. `python -I scripts/check_no_game_data.py` on the changed files is clean, and the doc tests pass except `test_docs_links`, which fails on main for `README.md`'s `assets/mandy.png`. The translator is untouched. **Not tested:** any GPU but llvmpipe, and any game run. The real check is a retail boot with cold pipeline compiles and `LEONIDA_RELEASE_WORKER=1`, compared with the same run without it (Snooozs, djrolfes: your stall snapshots from the list-values work are what this targets). GPUs tested: llvmpipe (Mesa, LLVM 20.1.2) under Wine 11.22 on Linux. AI-assisted (Claude Code, Claude Opus 5.5). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
akimfomin commented 2026-11-28 01:59:52 +00:00

XCL #2965 separates queue submission from observed GPU completion in its receipts. For the release worker, an independent check would signal one completion and immediately quiesce the worker while another resource is still held. Assert the signaller stays free, the completed resource is released once, and the outstanding resource keeps its lifetime contract. This is a source comparison, without a performance claim.

[XCL #2965](https://github.com/xcl-dev/xcl/pull/2965) separates queue submission from observed GPU completion in its receipts. For the release worker, an independent check would signal one completion and immediately quiesce the worker while another resource is still held. Assert the signaller stays free, the completed resource is released once, and the outstanding resource keeps its lifetime contract. This is a source comparison, without a performance claim.
timbot103 commented 2026-11-28 02:01:31 +00:00

Reviewed at head 25d460ccb on Windows 11 (MSVC 2022 19.44) with dual-GPU Vulkan validation (LEONIDA_VK_VALIDATION=1, Vulkan SDK 1.4.363.0).

Verification

  • Built d3d12_held_release_worker_test, vk_queue_query_sync_test, and vk_presenter_sync_test.
  • All 3 suites passed with 0 validation errors on both NVIDIA GeForce RTX 5080 (616.64) and AMD Radeon(TM) Graphics (25.10.30.02), both with default settings and with LEONIDA_RELEASE_WORKER=1.

Findings (Request changes)

  1. Unsignalled fence causes release/async workers to spin indefinitely (queue_holds.h:168-183; vulkan_backend.h:4030-4045, 4083-4088, 4681-4730, 4841-4854):
    QueueHolds invokes every holder whenever any held operation or queued barrier remains. release_ready() unconditionally sets release_requested_ = true on every worker-backed holder — including when on_worker is already true — without checking whether the queue's front operation can actually advance. The worker consumes release_requested_, sees the front still blocked at release_held(), and pumps again at the end of its pass, re-arming release_requested_ in a tight loop. Because the flag is set before the worker publishes idle, flush_async() can also stall until its 60 s timeout on a queue whose front cannot run (even under LEONIDA_SUBMIT_ASYNC with LEONIDA_RELEASE_WORKER unset). Only request another worker pass on an actual readiness transition or release progress, letting a blocked front go idle.
  2. Slow release can outlive VulkanQueue destruction (vulkan_backend.h:2608-2652, 4061-4067, 4700-4730, 4857-4883):
    start_release_worker() captures this by raw pointer, and teardown detaches worker_ after the 60 s drain timeout. QueueHolds::detach only serializes holder callbacks under pump_mutex_, whereas release_held_guarded() and post-replay bookkeeping run outside pump_mutex_ and can still touch inbox_mutex_ / queue members after ~VulkanQueue() finishes. Keep queue/context state alive until the worker exits (or join cleanly).
  3. Dropping a held fence pin under state_mutex_ can deadlock on device loss (vulkan_backend.h:2462-2477, 4083-4118; queue_holds.h:61-73):
    When context_.is_device_lost() skips run(op) inside release_held(), the local Deferred op (owning a COM fence pin) is destroyed while state_mutex_ is still held. If that drops the last reference to the fence while another operation remains held, ~VulkanFence -> remove_fence() takes pump_mutex_ and calls discard_waiting_on() on all holders, re-acquiring state_mutex_ on the same queue. Move dropped operations into a vector and destroy them after releasing state_mutex_ (matching teardown at 4169-4174).
  4. Minor (vulkan_backend.h:4061-4067; queue_holds.h:168-210):
    If std::thread creation throws inside release_ready() during a pump, thread-local in_pump is never reset; an RAII scope guard for in_pump and catching thread-start failure prevents future pumps on that thread from silently skipping.

AI-assisted review + local MSVC/dual-GPU verification.

Reviewed at head `25d460ccb` on Windows 11 (MSVC 2022 `19.44`) with dual-GPU Vulkan validation (`LEONIDA_VK_VALIDATION=1`, Vulkan SDK `1.4.363.0`). ### Verification - Built `d3d12_held_release_worker_test`, `vk_queue_query_sync_test`, and `vk_presenter_sync_test`. - All 3 suites **passed** with 0 validation errors on both **NVIDIA GeForce RTX 5080** (`616.64`) and **AMD Radeon(TM) Graphics** (`25.10.30.02`), both with default settings and with `LEONIDA_RELEASE_WORKER=1`. ### Findings (Request changes) 1. **Unsignalled fence causes release/async workers to spin indefinitely (`queue_holds.h:168-183`; `vulkan_backend.h:4030-4045`, `4083-4088`, `4681-4730`, `4841-4854`):** `QueueHolds` invokes every holder whenever any held operation or queued barrier remains. `release_ready()` unconditionally sets `release_requested_ = true` on every worker-backed holder — including when `on_worker` is already true — without checking whether the queue's front operation can actually advance. The worker consumes `release_requested_`, sees the front still blocked at `release_held()`, and pumps again at the end of its pass, re-arming `release_requested_` in a tight loop. Because the flag is set before the worker publishes idle, `flush_async()` can also stall until its 60 s timeout on a queue whose front cannot run (even under `LEONIDA_SUBMIT_ASYNC` with `LEONIDA_RELEASE_WORKER` unset). Only request another worker pass on an actual readiness transition or release progress, letting a blocked front go idle. 2. **Slow release can outlive `VulkanQueue` destruction (`vulkan_backend.h:2608-2652`, `4061-4067`, `4700-4730`, `4857-4883`):** `start_release_worker()` captures `this` by raw pointer, and teardown detaches `worker_` after the 60 s drain timeout. `QueueHolds::detach` only serializes holder callbacks under `pump_mutex_`, whereas `release_held_guarded()` and post-replay bookkeeping run outside `pump_mutex_` and can still touch `inbox_mutex_` / queue members after `~VulkanQueue()` finishes. Keep queue/context state alive until the worker exits (or join cleanly). 3. **Dropping a held fence pin under `state_mutex_` can deadlock on device loss (`vulkan_backend.h:2462-2477`, `4083-4118`; `queue_holds.h:61-73`):** When `context_.is_device_lost()` skips `run(op)` inside `release_held()`, the local `Deferred op` (owning a COM fence pin) is destroyed while `state_mutex_` is still held. If that drops the last reference to the fence while another operation remains held, `~VulkanFence` -> `remove_fence()` takes `pump_mutex_` and calls `discard_waiting_on()` on all holders, re-acquiring `state_mutex_` on the same queue. Move dropped operations into a vector and destroy them after releasing `state_mutex_` (matching teardown at `4169-4174`). 4. **Minor (`vulkan_backend.h:4061-4067`; `queue_holds.h:168-210`):** If `std::thread` creation throws inside `release_ready()` during a pump, thread-local `in_pump` is never reset; an RAII scope guard for `in_pump` and catching thread-start failure prevents future pumps on that thread from silently skipping. AI-assisted review + local MSVC/dual-GPU verification.
Tyrannys commented 2026-11-28 03:04:13 +00:00

#2541 | head 25d460ccb7a895351591a31ba2c6b87f656da245 | ctest -C RelWithDebInfo -R "d3d12_held_release|vk_queue_query_sync|vk_presenter_sync" (MSVC RelWithDebInfo, GPU tests) | red: clean main + the PR's test files and test registrations: d3d12_held_release_worker and d3d12_held_release_on_signaller fail on assertions (lines 90/94 and 125: the held work finishes at 0 ms, as main has no LEONIDA_HELD_RUN_DELAY_MS and no release worker); the 4 vk_* entries pass on main too | green: main 02f71ccfe merged into the head, 6/6 passed, 2 of 2 runs (held_release_worker 3.5 s, on_signaller 6.4 s) | full suite: not run (a game boot was using the machine) | Windows 11, RTX 4070 SUPER, NVIDIA 621.01, Python 3.14 | AI-assisted: yes, Claude Code

#2541 | head 25d460ccb7a895351591a31ba2c6b87f656da245 | ctest -C RelWithDebInfo -R "d3d12_held_release|vk_queue_query_sync|vk_presenter_sync" (MSVC RelWithDebInfo, GPU tests) | red: clean main + the PR's test files and test registrations: d3d12_held_release_worker and d3d12_held_release_on_signaller fail on assertions (lines 90/94 and 125: the held work finishes at 0 ms, as main has no LEONIDA_HELD_RUN_DELAY_MS and no release worker); the 4 vk_* entries pass on main too | green: main 02f71ccfe merged into the head, 6/6 passed, 2 of 2 runs (held_release_worker 3.5 s, on_signaller 6.4 s) | full suite: not run (a game boot was using the machine) | Windows 11, RTX 4070 SUPER, NVIDIA 621.01, Python 3.14 | AI-assisted: yes, Claude Code
tiguan26 commented 2026-11-28 05:16:10 +00:00

@timbot103 thank you, all four were right; and thanks for the RTX 5080 + AMD runs. Fixed in 99308202d (a separate commit so the changes are easy to see). AI-assisted (Claude Code, Claude Opus 5.5).

1. Spin on a blocked front. Confirmed: the worker's own pump re-armed release_requested_ on every pass. release_ready now asks only when the held front can run (front_may_run, the same ready(held_.front()) test release_held uses). The signalling thread does not wait for the state lock: if it is busy, a release is running, so it asks (once per Signal); the worker never re-arms itself on a busy lock, and a front that a Signal makes ready meanwhile is asked for by that Signal's own pass. New check in d3d12_held_release_worker (worker on): a front held on an unsignalled fence, process CPU over 1 s. With the fix 0 ms of 1001; with the old release_ready (check disabled) 990 ms of 1000, and the test fails. That also covers the flush_async stall under LEONIDA_SUBMIT_ASYNC.

2. Release outliving the queue. The detach after flush_async's minute was main's, but you're right that the release worker makes it reachable, since one held batch's cold builds can take longer than a minute. stop_async now waits for a worker still busy; only on a lost device (where a release runs nothing) is a still-stuck worker detached. That last case keeps a narrow window, which I'd rather leave than risk hanging teardown on a dead device; say if you'd prefer joining there too.

3. Fence pin dropped under state_mutex_. Confirmed (this one is on main too). release_held now moves every operation it ran or skipped into a local vector destroyed after the state lock, as teardown does.

4. in_pump on a throw. QueueHolds marks a pass with a scope guard (PumpScope) in all three places; a failure to start the worker thread falls back to the release on the signalling thread.

Retested under Wine 11.22 on llvmpipe: d3d12_held_release_worker, d3d12_held_release_on_signaller, both vk_presenter_sync entries plus vk_presenter_sparse_capture, both vk_queue_query_sync entries, queue_proxy and d3d12_staged_copy_wait, 3/3 each; queue_proxy and d3d12_staged_copy_wait with LEONIDA_RELEASE_WORKER=1 4/4. Full ctest 487/509: the same 21 as before plus d3d12_compile_pool, which passes 5/5 on its own and doesn't touch the holds (the load flake Tyrannys claimed as TEST-COMPILE-POOL-LOAD-FLAKE).

@Tyrannys thanks for the red/green on the RTX 4070 SUPER; that is the first check of these tests on Windows with a real GPU. Your run was at the first commit, so the new blocked-front check isn't in it yet.

@akimfomin: the case you describe (one release completed, another front still held, the worker going quiet) is what the new blocked-front check exercises, measured through the worker's CPU time rather than a receipt.

@timbot103 thank you, all four were right; and thanks for the RTX 5080 + AMD runs. Fixed in 99308202d (a separate commit so the changes are easy to see). AI-assisted (Claude Code, Claude Opus 5.5). **1. Spin on a blocked front.** Confirmed: the worker's own pump re-armed `release_requested_` on every pass. `release_ready` now asks only when the held front can run (`front_may_run`, the same `ready(held_.front())` test `release_held` uses). The signalling thread does not wait for the state lock: if it is busy, a release is running, so it asks (once per Signal); the worker never re-arms itself on a busy lock, and a front that a Signal makes ready meanwhile is asked for by that Signal's own pass. New check in `d3d12_held_release_worker` (worker on): a front held on an unsignalled fence, process CPU over 1 s. With the fix 0 ms of 1001; with the old `release_ready` (check disabled) 990 ms of 1000, and the test fails. That also covers the `flush_async` stall under `LEONIDA_SUBMIT_ASYNC`. **2. Release outliving the queue.** The detach after `flush_async`'s minute was main's, but you're right that the release worker makes it reachable, since one held batch's cold builds can take longer than a minute. `stop_async` now waits for a worker still busy; only on a lost device (where a release runs nothing) is a still-stuck worker detached. That last case keeps a narrow window, which I'd rather leave than risk hanging teardown on a dead device; say if you'd prefer joining there too. **3. Fence pin dropped under `state_mutex_`.** Confirmed (this one is on main too). `release_held` now moves every operation it ran or skipped into a local vector destroyed after the state lock, as teardown does. **4. `in_pump` on a throw.** `QueueHolds` marks a pass with a scope guard (`PumpScope`) in all three places; a failure to start the worker thread falls back to the release on the signalling thread. Retested under Wine 11.22 on llvmpipe: `d3d12_held_release_worker`, `d3d12_held_release_on_signaller`, both `vk_presenter_sync` entries plus `vk_presenter_sparse_capture`, both `vk_queue_query_sync` entries, `queue_proxy` and `d3d12_staged_copy_wait`, 3/3 each; `queue_proxy` and `d3d12_staged_copy_wait` with `LEONIDA_RELEASE_WORKER=1` 4/4. Full ctest 487/509: the same 21 as before plus `d3d12_compile_pool`, which passes 5/5 on its own and doesn't touch the holds (the load flake Tyrannys claimed as TEST-COMPILE-POOL-LOAD-FLAKE). @Tyrannys thanks for the red/green on the RTX 4070 SUPER; that is the first check of these tests on Windows with a real GPU. Your run was at the first commit, so the new blocked-front check isn't in it yet. @akimfomin: the case you describe (one release completed, another front still held, the worker going quiet) is what the new blocked-front check exercises, measured through the worker's CPU time rather than a receipt.
lixonik approved these changes 2026-11-28 08:51:57 +00:00
lixonik left a comment

Reviewed the diff and tested merged onto main (493867366) with Ninja Release (MSVC).

The LEONIDA_RELEASE_WORKER lifecycle in queue_holds.h / vulkan_backend.h looks solid: PumpScope, front_may_run(), destroying completed done entries outside state_mutex_, and clearing worker_busy_ only after pump_ready() avoid lock-inversion and premature-idle races. Both default (on-signaller) and worker-thread modes pass on real Vulkan hardware.

Tests run

  • ctest --output-on-failure -R "^(d3d12_held_release_worker|d3d12_held_release_on_signaller|vk_queue_query_sync|vk_queue_query_sync_release_worker|vk_presenter_sync|vk_presenter_sync_release_worker)$": 6/6 passed (vk_queue_query_sync 0.27 s, vk_queue_query_sync_release_worker 0.24 s, vk_presenter_sync 0.71 s, vk_presenter_sync_release_worker 0.59 s, d3d12_held_release_worker 7.41 s, d3d12_held_release_on_signaller 6.16 s).
  • python -m unittest tests/test_ctest_registration.py -v: 7/7 passed (0.26 s).

GPUs tested: NVIDIA GeForce RTX 5070 12 GB (Windows 11, driver 610.88, Vulkan 1.4.341; VK_LAYER_KHRONOS_validation not installed locally).

AI-assisted (Antigravity, Gemini).

Reviewed the diff and tested merged onto `main` (`493867366`) with Ninja Release (MSVC). The `LEONIDA_RELEASE_WORKER` lifecycle in `queue_holds.h` / `vulkan_backend.h` looks solid: `PumpScope`, `front_may_run()`, destroying completed `done` entries outside `state_mutex_`, and clearing `worker_busy_` only after `pump_ready()` avoid lock-inversion and premature-idle races. Both default (on-signaller) and worker-thread modes pass on real Vulkan hardware. ### Tests run - `ctest --output-on-failure -R "^(d3d12_held_release_worker|d3d12_held_release_on_signaller|vk_queue_query_sync|vk_queue_query_sync_release_worker|vk_presenter_sync|vk_presenter_sync_release_worker)$"`: **6/6 passed** (`vk_queue_query_sync` 0.27 s, `vk_queue_query_sync_release_worker` 0.24 s, `vk_presenter_sync` 0.71 s, `vk_presenter_sync_release_worker` 0.59 s, `d3d12_held_release_worker` 7.41 s, `d3d12_held_release_on_signaller` 6.16 s). - `python -m unittest tests/test_ctest_registration.py -v`: **7/7 passed** (0.26 s). GPUs tested: NVIDIA GeForce RTX 5070 12 GB (Windows 11, driver 610.88, Vulkan 1.4.341; VK_LAYER_KHRONOS_validation not installed locally). AI-assisted (Antigravity, Gemini).
zmasi commented 2026-11-28 23:02:15 +00:00

#2541 | head 99308202dd09b0efcd1a5c55f7b082c4a03e5cd2 (merged cleanly with main adfb3821a23612263c1c5b195453ed01c4c114db — includes the second commit's front_may_run idle check, stop_async join, post-lock fence-pin drop, and PumpScope RAII) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(d3d12_held_release_worker|d3d12_held_release_on_signaller|vk_presenter_sync|vk_presenter_sparse_capture|vk_presenter_sync_release_worker|vk_queue_query_sync|vk_queue_query_sync_release_worker|queue_proxy|d3d12_staged_copy_wait)$" --output-on-failure + LEONIDA_RELEASE_WORKER=1 on queue_proxy and d3d12_staged_copy_wait (LEONIDA_VK_VALIDATION=1) | red on main: building d3d12_held_release_worker_test against main's queue_holds.h and vulkan_backend.h fails (line 90: b_ms >= 2.0 * kDelayMs - 50 && a_ms >= 2.0 * kDelayMs - 50, held work done at 1 ms) | green on PR+main: 9/9 CTests (including d3d12_held_release_worker's new check_blocked_front_idles spin check, d3d12_held_release_on_signaller, both vk_presenter_sync and vk_queue_query_sync _release_worker modes, queue_proxy, and d3d12_staged_copy_wait) pass in 35.28 s, and queue_proxy + d3d12_staged_copy_wait pass under LEONIDA_RELEASE_WORKER=1 in 15.95 s, all on physical RTX 3090 hardware with 0 Khronos validation errors; test_docs_encoding.py, test_docs_repo_paths.py, and check_no_game_data.py 0 violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes

#2541 | head 99308202dd09b0efcd1a5c55f7b082c4a03e5cd2 (merged cleanly with main adfb3821a23612263c1c5b195453ed01c4c114db — includes the second commit's `front_may_run` idle check, `stop_async` join, post-lock fence-pin drop, and `PumpScope` RAII) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(d3d12_held_release_worker|d3d12_held_release_on_signaller|vk_presenter_sync|vk_presenter_sparse_capture|vk_presenter_sync_release_worker|vk_queue_query_sync|vk_queue_query_sync_release_worker|queue_proxy|d3d12_staged_copy_wait)$" --output-on-failure` + `LEONIDA_RELEASE_WORKER=1` on `queue_proxy` and `d3d12_staged_copy_wait` (`LEONIDA_VK_VALIDATION=1`) | red on main: building `d3d12_held_release_worker_test` against `main`'s `queue_holds.h` and `vulkan_backend.h` fails (`line 90: b_ms >= 2.0 * kDelayMs - 50 && a_ms >= 2.0 * kDelayMs - 50`, `held work done at 1 ms`) | green on PR+main: `9/9` CTests (including `d3d12_held_release_worker`'s new `check_blocked_front_idles` spin check, `d3d12_held_release_on_signaller`, both `vk_presenter_sync` and `vk_queue_query_sync` `_release_worker` modes, `queue_proxy`, and `d3d12_staged_copy_wait`) pass in `35.28 s`, and `queue_proxy` + `d3d12_staged_copy_wait` pass under `LEONIDA_RELEASE_WORKER=1` in `15.95 s`, all on physical RTX 3090 hardware with `0` Khronos validation errors; `test_docs_encoding.py`, `test_docs_repo_paths.py`, and `check_no_game_data.py` `0` violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes
timbot103 reviewed 2026-11-29 01:05:55 +00:00
timbot103 left a comment
No description provided.
Static audit of `99308202d` against `48bae6cad`. Request changes. - `runtime/src/vulkan_backend.h:4917` — Device-loss teardown can detach a worker that still accesses queue members. Keep the queue alive through worker exit and join before destruction. - `runtime/src/vulkan_backend.h:4063` — The worker's pump can consume another thread's Signal while a concurrent Wait holds `state_mutex_`, then discard the only release request. Retry after contention outside the pump lock. - `runtime/src/vulkan_backend.h:4115` — The held count reaches zero before the final render submits. A new Present can bypass deferral and read the old frame. Keep the count through replay. - `runtime/src/vulkan_backend.h:4128` — Allocation failure can unwind the last fence pin under `state_mutex_` and re-enter that lock through `remove_fence()`. Put the in-flight operation in storage that survives unlocking. - `runtime/src/vulkan_backend.h:4037` — A pump starts release workers even on empty queues. Check for held work before starting a thread. - `runtime/CMakeLists.txt:3017` — The inline CTest can inherit worker mode and pass as a duplicate. Set both worker-related flags explicitly in each entry. AI-assisted.
tiguan26 commented 2026-11-30 06:46:25 +00:00

Closing this. The worker is off by default and shows no frame-rate gain, #1783 already made the QueueHolds pump handoff safe (and is why this now conflicts), and timbot103's second audit (device-loss teardown, the held count reaching zero before the final render) would need a rework larger than the change is worth. Thank you @lixonik for the review, @zmasi for the hardware red/green run, and @timbot103 for both audits. AI-assisted (Claude).

Closing this. The worker is off by default and shows no frame-rate gain, #1783 already made the QueueHolds pump handoff safe (and is why this now conflicts), and timbot103's second audit (device-loss teardown, the held count reaching zero before the final render) would need a rework larger than the change is worth. Thank you @lixonik for the review, @zmasi for the hardware red/green run, and @timbot103 for both audits. AI-assisted (Claude).
Sign in to join this conversation.
No description provided.