GPU: fence waits, direct memory-write wakes, queue timeline and host list pool #32

Open
github-bot wants to merge 13 commits from github-bot/gh-32 into main AGit
Owner

@⁠AndyLatimer on GitHub · 2026-11-23 23:27 UTC · original
AndyLatimer:fix/gpu-fence-and-queue-waits → main · +1415 −95 · 9 files · 13 commits · open

Closes the GPU fence and command-queue synchronization gaps:

  1. Blocking null-event fence waits and bottom-of-pipe wakes (fence.rs, queue.rs):
    • ID3D12Fence::SetEventOnCompletion(value, NULL) previously returned E_NOTIMPL immediately instead of blocking until the fence reached value. It now blocks on a condition variable, re-checking every 100 ms and warning every 5 s while stuck.
    • Live fences are registered by their value address so a command list's bottom-of-pipe write (Written::write, now using atomic Release stores when aligned) wakes any waiting events, blocking waits, or held queues on that fence.
  2. Queue-side fence waits (timeline.rs, queue.rs, fence.rs, list.rs, host.rs, draw.rs):
    • ID3D12CommandQueue::Wait was previously a no-op, so work submitted after a wait for a value signalled later by another queue ran too early.
    • Each queue now runs Wait, Signal, ExecuteCommandLists, Present and CopyPageMappingsBatchX in submission order through a Timeline. When not held back, work executes inline on the submitting thread as before; behind an unreached wait, the call returns immediately and the pending work runs once the fence moves (after fence locks are released).
    • If a command list is reset or dropped while a submission of it is still queued behind a wait, recording moves to a pooled or new host list (Host::acquire_list / Host::recycle_list, bounded at 64 lists), and the pending HostList keeps both its allocate_upload blocks (keep_uploads) and its dynamic descriptor slots (keep_dynamic) until execution completes. If acquiring a replacement list fails, the in-flight HostList is left untouched instead of being reset.
  3. Timeline-ordered Present and CopyPageMappingsBatchX (queue.rs, object.rs, fence.rs):
    • present snapshots plane parameters at call time, retains the presented resource via a shared object::Held wrapper (also reused by fence::Held), and presents through the queue's timeline.
    • copy_page_mappings snapshots caller-owned batch/range arrays at submission time (with checked address arithmetic) and applies mappings through the queue's timeline.
  4. Direct fence memory writes (fence.rs):
    • A lazy background watcher thread (victory-fence-watch) polls live fences every 10 ms only while at least one event or queue wait is pending and parks on a Condvar when idle, so direct CPU/shader writes to a fence's GPU address also wake registered Win32 events and held-back queues without waiting for another submission.

Left out of this PR

  • list.rs's wait_value remains a no-op until the console's comparison enum encoding and trailing parameter layout are verified against a title/SDK (to avoid introducing deadlocks).

Testing

  • cargo test -p victory-gpu: 47 passed, 0 failed (including 11 new synthetic tests covering blocking null-event waits, bottom-of-pipe wakes, direct memory-write wakes for events and held queues, two-queue Wait/Signal, held-back Present, held-back CopyPageMappingsBatchX, and pending list reset/drop/pooling).
  • cargo clippy -p victory-gpu --all-targets: 0 warnings.
  • cargo check -p victory-gpu --features diagnostics --all-targets: pass.
  • cargo xtask policy: pass (149 files).
  • Tested with synthetic unit tests only (not run against a title; no game files or console SDK used).
**@⁠AndyLatimer** on GitHub · 2026-11-23 23:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/32) `AndyLatimer:fix/gpu-fence-and-queue-waits` → `main` · +1415 −95 · 9 files · 13 commits · open Closes the GPU fence and command-queue synchronization gaps: 1. **Blocking null-event fence waits and bottom-of-pipe wakes** (`fence.rs`, `queue.rs`): - `ID3D12Fence::SetEventOnCompletion(value, NULL)` previously returned `E_NOTIMPL` immediately instead of blocking until the fence reached `value`. It now blocks on a condition variable, re-checking every 100 ms and warning every 5 s while stuck. - Live fences are registered by their value address so a command list's bottom-of-pipe write (`Written::write`, now using atomic `Release` stores when aligned) wakes any waiting events, blocking waits, or held queues on that fence. 2. **Queue-side fence waits** (`timeline.rs`, `queue.rs`, `fence.rs`, `list.rs`, `host.rs`, `draw.rs`): - `ID3D12CommandQueue::Wait` was previously a no-op, so work submitted after a wait for a value signalled later by another queue ran too early. - Each queue now runs `Wait`, `Signal`, `ExecuteCommandLists`, `Present` and `CopyPageMappingsBatchX` in submission order through a `Timeline`. When not held back, work executes inline on the submitting thread as before; behind an unreached wait, the call returns immediately and the pending work runs once the fence moves (after fence locks are released). - If a command list is reset or dropped while a submission of it is still queued behind a wait, recording moves to a pooled or new host list (`Host::acquire_list` / `Host::recycle_list`, bounded at 64 lists), and the pending `HostList` keeps both its `allocate_upload` blocks (`keep_uploads`) and its dynamic descriptor slots (`keep_dynamic`) until execution completes. If acquiring a replacement list fails, the in-flight `HostList` is left untouched instead of being reset. 3. **Timeline-ordered `Present` and `CopyPageMappingsBatchX`** (`queue.rs`, `object.rs`, `fence.rs`): - `present` snapshots plane parameters at call time, retains the presented resource via a shared `object::Held` wrapper (also reused by `fence::Held`), and presents through the queue's timeline. - `copy_page_mappings` snapshots caller-owned batch/range arrays at submission time (with checked address arithmetic) and applies mappings through the queue's timeline. 4. **Direct fence memory writes** (`fence.rs`): - A lazy background watcher thread (`victory-fence-watch`) polls live fences every 10 ms only while at least one event or queue wait is pending and parks on a `Condvar` when idle, so direct CPU/shader writes to a fence's GPU address also wake registered Win32 events and held-back queues without waiting for another submission. ### Left out of this PR - `list.rs`'s `wait_value` remains a no-op until the console's comparison enum encoding and trailing parameter layout are verified against a title/SDK (to avoid introducing deadlocks). ## Testing - `cargo test -p victory-gpu`: 47 passed, 0 failed (including 11 new synthetic tests covering blocking null-event waits, bottom-of-pipe wakes, direct memory-write wakes for events and held queues, two-queue `Wait`/`Signal`, held-back `Present`, held-back `CopyPageMappingsBatchX`, and pending list reset/drop/pooling). - `cargo clippy -p victory-gpu --all-targets`: 0 warnings. - `cargo check -p victory-gpu --features diagnostics --all-targets`: pass. - `cargo xtask policy`: pass (149 files). - Tested with synthetic unit tests only (not run against a title; no game files or console SDK used).
SetEventOnCompletion(value, NULL) must block until the fence reaches the
value. It answered E_NOTIMPL at once (from when no GPU work ran), so a
title that waits this way went on before the value was reached.

A command list's bottom-of-pipe write at a fence's GPU address moved the
value without setting the events waiting for it. Live fences are now
registered by value address; Written::write wakes the fence it touched.

Blocking waits re-check the value every 100 ms and warn every 5 s while
stuck. New tests cover both paths; three of them fail on the old code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ID3D12CommandQueue::Wait did nothing, so work submitted after a wait for a value another queue signals later ran too early. Each queue now has a timeline that Wait, Signal and ExecuteCommandLists go through in order. Not held back, work runs on the submitting thread as before; behind a wait not reached yet, the call returns and the work runs on the thread that moves the fence. A list reset or dropped while a submission of it is still to run keeps its host list and upload memory until that submission completes. One synthetic two-queue test.
A present on a queue held back by a wait ran immediately, before the work preceding it. present() now reads its plane parameters at call time, holds a reference to the presented resource via a shared object::Held wrapper (also reused by fence::Held), and submits the present through the queue's timeline. One synthetic two-queue test.
CopyPageMappingsBatchX previously ran immediately even on a queue held back behind a fence wait, updating page mappings ahead of earlier queued work. It now snapshots the caller's batch and range arrays at submission time (with checked address arithmetic) and runs through the queue's timeline. One synthetic two-queue test.
Previously, moving a fence's value via a direct write to its GPU address (outside Signal or Written::write) only woke blocking null-event waits; registered Win32 events stayed unset and held-back queues waited until their next submission. A lazy background watcher thread (victory-fence-watch) now polls live fences every 10 ms only while at least one event or queue wait is pending and parks on a condvar when idle. Also switches aligned Written::write stores to atomic Release stores. Two new synthetic tests.
Detached HostLists whose submissions finished on a held-back queue are now returned to a bounded pool on Host (up to 64) and reused on subsequent list creations or pending resets. Dropping or resetting a list while a submission of it is still queued now transfers both its allocate_upload blocks and dynamic descriptor slots to the pending HostList until execution completes, and reset failure no longer resets an in-flight HostList. One new synthetic test.
The merge of main (6e88bc0) kept only the last 126 lines of
crates/victory-gpu/src/host.rs, so the crate did not build. This is the
file as the merge should have left it: both sides' additions kept (the
held lists' kept uploads and descriptor slots, Send and Sync, and main's
diagnostics timestamps).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Host::execute did the lists' bottom-of-pipe writes holding its
`submitted` lock and the lists' `deferred` guards. A write at a fence a
held-back queue waits for ran that queue's work inline (fence::written ->
Timeline::wake), and the work calls Host::execute again: a deadlock on
`submitted` (std's Mutex is not re-entrant), in the case the queue
timeline is for (a graphics queue waiting on a compute list's write).

Written::write and fence::written now return the woken queues (Woken,
must_use); execute collects them and runs them after dropping its locks.
Without a host GPU, list writes still run them at once (no lock held).
Reported in review by Sunkiller-qc. 1 new test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	crates/victory-gpu/src/list.rs
# Conflicts:
#	crates/victory-gpu/src/host.rs
#	crates/victory-gpu/src/list.rs
`wake_locked` took a satisfied queue's registration off the fence, but
the queue resumed later (`run_held`, with no lock held) and checked the
fence's value again in `wait_on_gpu`. A signal that set the fence back
below the value in between registered the wait again, and the work
behind it waited for a value already reached. D3D12: a wait a signal
satisfied stays satisfied; new waits use the lower value.

Each wait now has a ticket, its place in the queue's submission order,
kept with its registration. The fence releases the ticket under its lock
(`Timeline::release`, a `fetch_max`), and `wait_on_gpu` takes a released
ticket as reached under the same lock. Later waits have later tickets,
so a stale or repeated wake releases none of them. New waits still
compare with the current value.

Test by contatopablow-spec (review on #32): fails without the latch
(left: 0, right: 1), passes with it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:47:17 +00:00
Author
Owner

@⁠Sunkiller-qc on GitHub · 2026-11-23 23:46 UTC · original

Thanks for this, the timeline design is nice and the lock-order notes help a lot. I think there's a re-entrancy problem on the bottom-of-pipe path though. In Host::execute (crates/victory-gpu/src/host.rs:447) the submitted guard lives until the end of the function, and the deferred writes run at host.rs:510 while it's still held (as is the list.deferred() guard of the loop). Written::write now calls crate::fence::written (queue.rs:240), which goes wake → run_held (fence.rs:198/238) → Timeline::wake → run, and runs the held queue's Op::Run closure inline. That closure calls host.execute again, which locks self.submitted on the same thread. So a graphics queue that Waits on a fence that a compute list moves with a bottom-of-pipe write would deadlock (or panic, since std Mutex isn't re-entrant). That's exactly the case the PR targets. One fix: have written return the timelines to wake instead of running them, collect them in execute, and call run_held after submitted and the deferred() guards are dropped. A test that submits a list with a bottom-of-pipe write to a fence another queue waits on would catch it. Static review, not built or run.

**@⁠Sunkiller-qc** on GitHub · 2026-11-23 23:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/32#issuecomment-7117352288) Thanks for this, the timeline design is nice and the lock-order notes help a lot. I think there's a re-entrancy problem on the bottom-of-pipe path though. In `Host::execute` (`crates/victory-gpu/src/host.rs:447`) the `submitted` guard lives until the end of the function, and the deferred writes run at `host.rs:510` while it's still held (as is the `list.deferred()` guard of the loop). `Written::write` now calls `crate::fence::written` (`queue.rs:240`), which goes `wake` → `run_held` (`fence.rs:198/238`) → `Timeline::wake` → `run`, and runs the held queue's `Op::Run` closure inline. That closure calls `host.execute` again, which locks `self.submitted` on the same thread. So a graphics queue that `Wait`s on a fence that a compute list moves with a bottom-of-pipe write would deadlock (or panic, since std `Mutex` isn't re-entrant). That's exactly the case the PR targets. One fix: have `written` return the timelines to wake instead of running them, collect them in `execute`, and call `run_held` after `submitted` and the `deferred()` guards are dropped. A test that submits a list with a bottom-of-pipe write to a fence another queue waits on would catch it. Static review, not built or run.
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 01:04 UTC · original

The head 6e88bc0 does not compile: the merge into main left crates/victory-gpu/src/host.rs with only the last 126 lines (git shows 1 919 lines deleted against main). mod host; is present in lib.rs and the file exists, but the top of the module is gone, so everything that imports from it fails:

error[E0432]: unresolved import `crate::host::host`
  --> crates/victory-gpu/src/descriptor/host.rs:14:5
error[E0432]: unresolved import `crate::host::HostList`
  --> crates/victory-gpu/src/draw.rs:22:5
error: could not compile `victory-gpu` (lib) due to 88 previous errors
error: could not compile `victory-gpu` (lib test) due to 91 previous errors

The merge needs to be redone keeping both sides of host.rs; the timeline module is fine. I can run the fence/queue tests here (Wine + vkd3d-proton) once it builds.

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

**@⁠DaviTostes** on GitHub · 2026-11-24 01:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/32#issuecomment-7118719584) The head `6e88bc0` **does not compile**: the merge into `main` left `crates/victory-gpu/src/host.rs` with only the **last 126 lines** (git shows 1 919 lines deleted against `main`). `mod host;` is present in `lib.rs` and the file exists, but the top of the module is gone, so everything that imports from it fails: ``` error[E0432]: unresolved import `crate::host::host` --> crates/victory-gpu/src/descriptor/host.rs:14:5 error[E0432]: unresolved import `crate::host::HostList` --> crates/victory-gpu/src/draw.rs:22:5 error: could not compile `victory-gpu` (lib) due to 88 previous errors error: could not compile `victory-gpu` (lib test) due to 91 previous errors ``` The merge needs to be redone keeping both sides of `host.rs`; the `timeline` module is fine. I can run the fence/queue tests here (Wine + vkd3d-proton) once it builds. No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
Author
Owner

@⁠Sunkiller-qc on GitHub · 2026-11-24 01:05 UTC · original

Two things on the current head (6e88bc0):

  1. The merge from main looks like it went wrong for crates/victory-gpu/src/host.rs. At 80443e8 the file has about 1,830 lines; after the merge it has 126, so Host, HostList, execute and the rest are gone (git show --stat 6e88bc0 shows host.rs | 1701 -----). That's where the -1835 in the PR stats comes from, and the crate can't build like this. Redoing the merge, or git checkout 80443e8 -- crates/victory-gpu/src/host.rs and then reapplying main's changes to that file, should fix it.

  2. The re-entrancy from my earlier comment is still there at 80443e8: Host::execute takes submitted at host.rs:499 and still runs what.write(...) at host.rs:562 with that guard and list.deferred() held. fence::written (fence.rs:335) still wakes held queues inline, and the woken work calls host.execute again. Collecting the timelines to wake and running them after both guards drop would avoid this.

Static review, not built or run.

**@⁠Sunkiller-qc** on GitHub · 2026-11-24 01:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/32#issuecomment-7118748248) Two things on the current head (`6e88bc0`): 1. The merge from main looks like it went wrong for `crates/victory-gpu/src/host.rs`. At `80443e8` the file has about 1,830 lines; after the merge it has 126, so `Host`, `HostList`, `execute` and the rest are gone (`git show --stat 6e88bc0` shows `host.rs | 1701 -----`). That's where the -1835 in the PR stats comes from, and the crate can't build like this. Redoing the merge, or `git checkout 80443e8 -- crates/victory-gpu/src/host.rs` and then reapplying main's changes to that file, should fix it. 2. The re-entrancy from my earlier comment is still there at `80443e8`: `Host::execute` takes `submitted` at `host.rs:499` and still runs `what.write(...)` at `host.rs:562` with that guard and `list.deferred()` held. `fence::written` (`fence.rs:335`) still wakes held queues inline, and the woken work calls `host.execute` again. Collecting the timelines to wake and running them after both guards drop would avoid this. Static review, not built or run.
Author
Owner

@⁠AndyLatimer on GitHub · 2026-11-24 01:21 UTC · original

Thanks for both reviews. Both points are fixed on the new head 8fd82c9:

  1. Broken merge (6e88bc0 kept only the last 126 lines of host.rs): b14bac3 restores the file as the merge should have left it, keeping both sides' additions (this PR's kept uploads/descriptor slots and Send/Sync, and main's diagnostics timestamps). d2da283 then merges current main (d2a4bae) with no conflicts.
  2. Re-entrancy on the bottom-of-pipe path (8fd82c9): Written::write and fence::written now return the woken queues instead of running them, as a #[must_use] Woken. Host::execute collects them while it does the writes and runs them after dropping submitted and the deferred() guards. Without a host GPU, defer_write writes at once and runs them right away, with no lock held there. The new test bottom_of_pipe_writes_leave_woken_work_to_the_writer holds a lock that the woken work takes. It fails on the old code ("ran inside the write").

Testing on 8fd82c9 (Windows 11):

  • cargo test --workspace: 276 passed, 4 ignored.
  • cargo clippy --workspace --all-targets: no new warnings (the two left, in xmem.rs and host.rs:267, are on main).
  • cargo clippy -p victory --features diagnostics: clean.
  • cargo xtask policy: pass.

Synthetic tests only, not run against a title.

**@⁠AndyLatimer** on GitHub · 2026-11-24 01:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/32#issuecomment-7119020092) Thanks for both reviews. Both points are fixed on the new head `8fd82c9`: 1. **Broken merge** (`6e88bc0` kept only the last 126 lines of `host.rs`): `b14bac3` restores the file as the merge should have left it, keeping both sides' additions (this PR's kept uploads/descriptor slots and `Send`/`Sync`, and main's diagnostics timestamps). `d2da283` then merges current `main` (`d2a4bae`) with no conflicts. 2. **Re-entrancy on the bottom-of-pipe path** (`8fd82c9`): `Written::write` and `fence::written` now return the woken queues instead of running them, as a `#[must_use]` `Woken`. `Host::execute` collects them while it does the writes and runs them after dropping `submitted` and the `deferred()` guards. Without a host GPU, `defer_write` writes at once and runs them right away, with no lock held there. The new test `bottom_of_pipe_writes_leave_woken_work_to_the_writer` holds a lock that the woken work takes. It fails on the old code ("ran inside the write"). Testing on `8fd82c9` (Windows 11): - `cargo test --workspace`: 276 passed, 4 ignored. - `cargo clippy --workspace --all-targets`: no new warnings (the two left, in `xmem.rs` and `host.rs:267`, are on `main`). - `cargo clippy -p victory --features diagnostics`: clean. - `cargo xtask policy`: pass. Synthetic tests only, not run against a title.
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 01:22 UTC · original

Re-checked the new head 8fd82c9 after the repair merge: the build is fixed and the suite runs.

  • host.rs is back to 2 151 lines (it was 126 on 6e88bc0), and the Windows test build compiles.
  • Under Wine 11.22 + vkd3d-proton 3.1 (AMD RX 9060 XT, RADV 26.3.1) with a native Microsoft d3dcompiler_47: 53 passed, 2 failed, 1 ignored.
  • The two failures are environment-only: a_rejected_blob_gives_an_empty_library (vkd3d needs a non-empty blob) and #128 (VirtualQuery sees vkd3d-mapped memory as MEM_FREE). The ignored test is a benchmark.
  • The fence/queue paths this PR changes are exercised by that run.

No game data used.

**@⁠DaviTostes** on GitHub · 2026-11-24 01:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/32#issuecomment-7119035023) Re-checked the new head `8fd82c9` after the repair merge: **the build is fixed and the suite runs**. - `host.rs` is back to 2 151 lines (it was 126 on `6e88bc0`), and the Windows test build compiles. - Under **Wine 11.22 + vkd3d-proton 3.1** (AMD RX 9060 XT, RADV 26.3.1) with a native Microsoft `d3dcompiler_47`: **53 passed, 2 failed, 1 ignored**. - The two failures are environment-only: `a_rejected_blob_gives_an_empty_library` (vkd3d needs a non-empty blob) and #128 (`VirtualQuery` sees vkd3d-mapped memory as `MEM_FREE`). The ignored test is a benchmark. - The fence/queue paths this PR changes are exercised by that run. No game data used.
Author
Owner

@⁠aycow on GitHub · 2026-11-24 06:50 UTC · original

@⁠AndyLatimer All eight fence-module tests passed here at 8fd82c9. For a future #595 composition, I think the guest queue timeline and native submission completion should stay separate. Your Woken handoff is relevant because a queue wake can re-enter Host::execute. #595 currently runs completion callbacks under its entries and finishing locks. Deferring the public wake until those locks and the submitting guard are released would avoid a re-entrant lock path. I checked the source path and the standalone tests. A merged test remains open. #595 compatibility results

**@⁠aycow** on GitHub · 2026-11-24 06:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/32#issuecomment-7124347270) @⁠AndyLatimer All eight fence-module tests passed here at `8fd82c9`. For a future #595 composition, I think the guest queue timeline and native submission completion should stay separate. Your Woken handoff is relevant because a queue wake can re-enter `Host::execute`. #595 currently runs completion callbacks under its entries and finishing locks. Deferring the public wake until those locks and the submitting guard are released would avoid a re-entrant lock path. I checked the source path and the standalone tests. A merged test remains open. [#595 compatibility results](https://github.com/aycow/VIctory/tree/test/async-submission-compatibility)
Author
Owner

@⁠AndyLatimer on GitHub · 2026-11-24 08:51 UTC · original

I merged current main (58fed37) into the branch; the new head is 9c5328d. The only conflict was in list.rs, in two copy paths that main gave a texture upload (#671/#680). I kept main's code, with &list because host_list returns an Arc on this branch. Results:

  • cargo test -p victory-gpu --lib: 61 passed, 1 ignored.
  • cargo check -p victory-gpu --features diagnostics --all-targets passes.
  • cargo test --workspace --exclude victory-shader --no-fail-fast: 230 passed, 0 failed.

victory-shader is left out because its tests do not compile on main itself: lower.rs:6963 calls lowers(&words) with one argument where it now takes two. That breakage is on main and has nothing to do with this branch.

**@⁠AndyLatimer** on GitHub · 2026-11-24 08:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/32#issuecomment-7126660969) I merged current `main` (`58fed37`) into the branch; the new head is `9c5328d`. The only conflict was in `list.rs`, in two copy paths that `main` gave a texture upload (#671/#680). I kept `main`'s code, with `&list` because `host_list` returns an `Arc` on this branch. Results: - `cargo test -p victory-gpu --lib`: 61 passed, 1 ignored. - `cargo check -p victory-gpu --features diagnostics --all-targets` passes. - `cargo test --workspace --exclude victory-shader --no-fail-fast`: 230 passed, 0 failed. `victory-shader` is left out because its tests do not compile on `main` itself: `lower.rs:6963` calls `lowers(&words)` with one argument where it now takes two. That breakage is on `main` and has nothing to do with this branch.
Author
Owner

@⁠DeerSilver on GitHub · 2026-11-24 11:01 UTC · original

Tested head 9c5328d merged onto main ffe310e (clean merge) on NVIDIA GeForce RTX 5060 Laptop GPU (Blackwell), driver 621.24, Windows 11 26300, Rust 1.98.1: pass. No game files: the test suite only.

  • The PR's new tests pass. The ones that use the host GPU ran on the RTX 5060 (DXGI adapter 0 on this laptop, so the host-device helpers return a device and the tests don't take their early return):
    • blocking_wait_returns_at_once_when_reached
    • blocking_wait_blocks_until_signalled
    • bottom_of_pipe_write_releases_blocking_wait
    • bottom_of_pipe_write_sets_waiting_event
    • direct_memory_write_sets_waiting_event
    • released_fences_leave_the_registry
    • bottom_of_pipe_writes_leave_woken_work_to_the_writer
    • pending_list_reset_and_drop_keep_uploads_and_recycle_host_list
    • work_after_a_wait_runs_once_the_other_queue_signals
    • present_runs_after_a_queues_wait
    • page_mappings_run_after_a_queues_wait
    • direct_memory_write_wakes_held_queue
  • cargo test --workspace --locked: 354 passed, 0 failed, 6 ignored, against 342 passed / 6 ignored on main.
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean.

AI-assisted (Claude Code).

**@⁠DeerSilver** on GitHub · 2026-11-24 11:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/32#issuecomment-7129557680) Tested head `9c5328d` merged onto `main` `ffe310e` (clean merge) on **NVIDIA GeForce RTX 5060 Laptop GPU** (Blackwell), driver 621.24, Windows 11 26300, Rust 1.98.1: **pass.** No game files: the test suite only. - The PR's new tests pass. The ones that use the host GPU ran on the RTX 5060 (DXGI adapter 0 on this laptop, so the host-device helpers return a device and the tests don't take their early return): - `blocking_wait_returns_at_once_when_reached` - `blocking_wait_blocks_until_signalled` - `bottom_of_pipe_write_releases_blocking_wait` - `bottom_of_pipe_write_sets_waiting_event` - `direct_memory_write_sets_waiting_event` - `released_fences_leave_the_registry` - `bottom_of_pipe_writes_leave_woken_work_to_the_writer` - `pending_list_reset_and_drop_keep_uploads_and_recycle_host_list` - `work_after_a_wait_runs_once_the_other_queue_signals` - `present_runs_after_a_queues_wait` - `page_mappings_run_after_a_queues_wait` - `direct_memory_write_wakes_held_queue` - `cargo test --workspace --locked`: **354 passed, 0 failed, 6 ignored**, against 342 passed / 6 ignored on `main`. - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean. AI-assisted (Claude Code).
Author
Owner

@⁠sash2kk on GitHub · 2026-11-24 11:01 UTC · original

Tested 9c5328d merged with current main (8e79c80, merges cleanly) on Windows 11 Pro 23H2 (22631), RTX 4090 (driver 32.0.16.1088), i7-13700K, Rust 1.98.1 MSVC:

  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
  • same with --all-features: clean
  • cargo test --workspace --locked: all pass (victory-gpu 62 passed / 1 ignored, up from 50 on main)
  • the 16 fence/queue/timeline tests: 50 runs back to back, 0 failures

Read through fence.rs and timeline.rs: I found no lost wakeup. signal stores under waiters before taking queues, and wait_on_gpu checks the value under queues, so a signal racing a queue Wait either is seen or wakes it. The documented lock order (LIVE → waiters → queues, timeline state before fence locks, queue work run with no lock) holds in the paths I traced.

Also ran the title (release build, --execute) with this PR merged into main, then with plain main as a control:

  • PR 32 + main, first boot: boot screens and menus at a steady 30 fps, into the world load; then host device removed (0x887A0006, "no breadcrumbs", after one 4.9 s submission of 28 lists), about 5.5 min in.
  • plain main, second boot (save present, so straight into the world load): the same device removal (0x887A0006, submission of 30 lists), about 3 min in.

So the device removal is the known world-load one (#653), not caused by this PR. With the PR: no "blocking fence wait still waiting" warnings and no hang up to the removal. The world itself was not reached in either run, so the PR's queue waits are not exercised past the load.

AI-assisted (Claude Code).

**@⁠sash2kk** on GitHub · 2026-11-24 11:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/32#issuecomment-7129563197) Tested `9c5328d` merged with current `main` (`8e79c80`, merges cleanly) on Windows 11 Pro 23H2 (22631), RTX 4090 (driver 32.0.16.1088), i7-13700K, Rust 1.98.1 MSVC: - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean - same with `--all-features`: clean - `cargo test --workspace --locked`: all pass (victory-gpu 62 passed / 1 ignored, up from 50 on `main`) - the 16 fence/queue/timeline tests: 50 runs back to back, 0 failures Read through `fence.rs` and `timeline.rs`: I found no lost wakeup. `signal` stores under `waiters` before taking `queues`, and `wait_on_gpu` checks the value under `queues`, so a signal racing a queue `Wait` either is seen or wakes it. The documented lock order (`LIVE` → `waiters` → `queues`, timeline state before fence locks, queue work run with no lock) holds in the paths I traced. Also ran the title (release build, `--execute`) with this PR merged into `main`, then with plain `main` as a control: - PR 32 + `main`, first boot: boot screens and menus at a steady 30 fps, into the world load; then host device removed (0x887A0006, "no breadcrumbs", after one 4.9 s submission of 28 lists), about 5.5 min in. - plain `main`, second boot (save present, so straight into the world load): the same device removal (0x887A0006, submission of 30 lists), about 3 min in. So the device removal is the known world-load one (#653), not caused by this PR. With the PR: no "blocking fence wait still waiting" warnings and no hang up to the removal. The world itself was not reached in either run, so the PR's queue waits are not exercised past the load. AI-assisted (Claude Code).
Author
Owner

@⁠contatopablow-spec on GitHub · 2026-11-24 20:33 UTC · original · edited 2026-11-24 22:16 UTC

CPU-only regression: a satisfied queue wait is lost if the fence is rewound before its deferred wake.

Verified at PR head 9c5328d4ef91c56bb10bea6474f6f802b9d4d652. Microsoft's Multi-engine synchronization / Fences explicitly states that an outstanding wait satisfied by one signal stays satisfied even when a racing lower signal leaves the fence below the requested value. New waits should still use the new lower value.

wake_locked removes a satisfied queue registration and returns its timeline, but Timeline::run rechecks the current value via wait_on_gpu. If the value is rewound between these steps, the already satisfied wait is registered again. The deferred-wake path makes the interleaving particularly easy to reproduce without threads, sleeps or GPU work.

Add this test inside fence.rs's existing mod tests (uses its existing imports):

#[test]
fn queue_wait_survives_rewind_before_deferred_wake() {
    use crate::timeline::{Op, Timeline};
    let f = new_fence(0);
    let queue = Arc::new(Timeline::default());
    let ran = Arc::new(AtomicU64::new(0));
    queue.submit(Op::Wait(Held::new(f), 1));
    let seen = ran.clone();
    queue.submit(Op::Run(Box::new(move || {
        seen.fetch_add(1, Ordering::SeqCst);
    })));
    assert_eq!(ran.load(Ordering::SeqCst), 0);
    let woken = {
        let obj = fence(f);
        let waiters = obj.waiters.lock().unwrap();
        obj.value.store(1, Ordering::Release);
        wake(obj, waiters)
    };
    assert_eq!(woken.len(), 1);
    assert_eq!(signal(f, 0), S_OK);
    run_held(woken);
    let observed = ran.load(Ordering::SeqCst);
    // Drain even on the buggy path before asserting.
    assert_eq!(signal(f, 1), S_OK);
    drop(queue);
    release_fence(f);
    assert_eq!(observed, 1, "satisfied wait was lost on rewind");
}

Command: cargo test --offline --locked -p victory-gpu --lib queue_wait_survives_rewind_before_deferred_wake -- --nocapture --test-threads=1

Observed left: 0, right: 1, exit 101. Both existing controls (work_after_a_wait_runs_once_the_other_queue_signals, bottom_of_pipe_writes_leave_woken_work_to_the_writer) passed, exit 0. Windows 11, Rust 1.98.1. Only a 33-line test addition; no production change or GPU dispatch.

Suggested direction: latch satisfaction per registered wait under the fence lock, separate from resuming a timeline outside locks. Do not replace the fence's current value with a historical maximum, as that would incorrectly satisfy new waits after a rewind. The null-event CPU wait path deserves a separate review. No claim this interleaving occurs in a title or causes #1317; this is an API-semantics regression. No game data. AI-assisted review/test (ChatGPT).


Follow-up: queue-wait completion latch implementation and tests. Published exact incremental commit on 9c5328d4ef91c56bb10bea6474f6f802b9d4d652: github.com/contatopablow-spec/VIctory@8d870653b6

Each registered front wait has a per-wait completion latch; the registry holds weak references to both latch and timeline. The fence scan marks that exact wait satisfied under the registration mutex before removing it. Signal serializes its value store and scan with registration, and the timeline consumes the front wait's latch or the current fence value under that lock. Delayed/repeated wakes cannot release a later wait. Work still runs outside fence/host locks; existing deferred Woken interface and lock ordering are retained. No dependencies or new unsafe code.

Validation at the pinned PR head: original regression RED (exit 101) -> GREEN (0). Added controls for a fresh wait after rewind, repeated/stale wake with another pending wait on the same fence, and dropping a held queue. Fence tests 12/12, queue tests 8/8 (independently repeated in the publication worktree), GPU crate library 65 passed, one existing benchmark ignored. Default and diagnostics GPU Clippy with -D warnings, changed-file rustfmt, diff and asset policy (153 files), staged policy all passed. Windows, Rust 1.98.1. Full workspace test compilation was blocked by existing victory-shader/src/emit/lower.rs:6963 E0061 (missing rsrc2 argument to lowers), reproduced separately with unchanged shader sources.

Independent review checked exact wait identity, queue lifetime and lock order. Scope limitations: transient raw/bottom-of-pipe writes may still be missed between observation scans; null-event CPU waits and mixed-width accesses are outside this patch. No gameplay or new GPU dispatch, and no claim that this defect explains #1317. AI-assisted implementation, tests and review (ChatGPT/Codex). Sharing the incremental commit here rather than opening a competing PR against main.

**@⁠contatopablow-spec** on GitHub · 2026-11-24 20:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/32#issuecomment-7143721817) · edited 2026-11-24 22:16 UTC **CPU-only regression: a satisfied queue wait is lost if the fence is rewound before its deferred wake.** Verified at PR head `9c5328d4ef91c56bb10bea6474f6f802b9d4d652`. Microsoft's [Multi-engine synchronization / Fences](https://learn.microsoft.com/en-us/windows/win32/direct3d12/user-mode-heap-synchronization#fences) explicitly states that an outstanding wait satisfied by one signal stays satisfied even when a racing lower signal leaves the fence below the requested value. New waits should still use the new lower value. `wake_locked` removes a satisfied queue registration and returns its timeline, but `Timeline::run` rechecks the current value via `wait_on_gpu`. If the value is rewound between these steps, the already satisfied wait is registered again. The deferred-wake path makes the interleaving particularly easy to reproduce without threads, sleeps or GPU work. Add this test inside `fence.rs`'s existing `mod tests` (uses its existing imports): ```rust #[test] fn queue_wait_survives_rewind_before_deferred_wake() { use crate::timeline::{Op, Timeline}; let f = new_fence(0); let queue = Arc::new(Timeline::default()); let ran = Arc::new(AtomicU64::new(0)); queue.submit(Op::Wait(Held::new(f), 1)); let seen = ran.clone(); queue.submit(Op::Run(Box::new(move || { seen.fetch_add(1, Ordering::SeqCst); }))); assert_eq!(ran.load(Ordering::SeqCst), 0); let woken = { let obj = fence(f); let waiters = obj.waiters.lock().unwrap(); obj.value.store(1, Ordering::Release); wake(obj, waiters) }; assert_eq!(woken.len(), 1); assert_eq!(signal(f, 0), S_OK); run_held(woken); let observed = ran.load(Ordering::SeqCst); // Drain even on the buggy path before asserting. assert_eq!(signal(f, 1), S_OK); drop(queue); release_fence(f); assert_eq!(observed, 1, "satisfied wait was lost on rewind"); } ``` Command: `cargo test --offline --locked -p victory-gpu --lib queue_wait_survives_rewind_before_deferred_wake -- --nocapture --test-threads=1` Observed `left: 0, right: 1`, exit 101. Both existing controls (`work_after_a_wait_runs_once_the_other_queue_signals`, `bottom_of_pipe_writes_leave_woken_work_to_the_writer`) passed, exit 0. Windows 11, Rust 1.98.1. Only a 33-line test addition; no production change or GPU dispatch. Suggested direction: latch satisfaction per registered wait under the fence lock, separate from resuming a timeline outside locks. Do not replace the fence's current value with a historical maximum, as that would incorrectly satisfy new waits after a rewind. The null-event CPU wait path deserves a separate review. No claim this interleaving occurs in a title or causes #1317; this is an API-semantics regression. No game data. AI-assisted review/test (ChatGPT). --- **Follow-up: queue-wait completion latch implementation and tests.** Published exact incremental commit on `9c5328d4ef91c56bb10bea6474f6f802b9d4d652`: https://github.com/contatopablow-spec/VIctory/commit/8d870653b6f74a36d5163ea2d88f0c60aef3ebe7 Each registered front wait has a per-wait completion latch; the registry holds weak references to both latch and timeline. The fence scan marks that exact wait satisfied under the registration mutex before removing it. `Signal` serializes its value store and scan with registration, and the timeline consumes the front wait's latch or the current fence value under that lock. Delayed/repeated wakes cannot release a later wait. Work still runs outside fence/host locks; existing deferred `Woken` interface and lock ordering are retained. No dependencies or new unsafe code. Validation at the pinned PR head: original regression RED (exit 101) -> GREEN (0). Added controls for a fresh wait after rewind, repeated/stale wake with another pending wait on the same fence, and dropping a held queue. Fence tests 12/12, queue tests 8/8 (independently repeated in the publication worktree), GPU crate library 65 passed, one existing benchmark ignored. Default and diagnostics GPU Clippy with `-D warnings`, changed-file rustfmt, diff and asset policy (153 files), staged policy all passed. Windows, Rust 1.98.1. Full workspace test compilation was blocked by existing `victory-shader/src/emit/lower.rs:6963` E0061 (missing `rsrc2` argument to `lowers`), reproduced separately with unchanged shader sources. Independent review checked exact wait identity, queue lifetime and lock order. Scope limitations: transient raw/bottom-of-pipe writes may still be missed between observation scans; null-event CPU waits and mixed-width accesses are outside this patch. No gameplay or new GPU dispatch, and no claim that this defect explains #1317. AI-assisted implementation, tests and review (ChatGPT/Codex). Sharing the incremental commit here rather than opening a competing PR against main.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:14 UTC · original · edited 2026-11-25 15:54 UTC

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-gpu/src/fence.rs, crates/victory-gpu/src/host.rs, crates/victory-gpu/src/list.rs, crates/victory-gpu/src/queue.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (merge-candidate) was for an older state of main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/32#issuecomment-7148298447) · edited 2026-11-25 15:54 UTC <!-- victory-triage v1 head=b48fbc6d81833134fb43f71b8354416e5a865b67 verdict=needs-rebase at=2026-11-25T15:54:30Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-gpu/src/fence.rs`, `crates/victory-gpu/src/host.rs`, `crates/victory-gpu/src/list.rs`, `crates/victory-gpu/src/queue.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (merge-candidate) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠AndyLatimer on GitHub · 2026-11-25 09:38 UTC · original

Merged main (940d32f) at e980aa3 and fixed the rewind regression @⁠contatopablow-spec found, in b48fbc6.

Merge. host.rs takes main's Presentation. The diagnostics frame dump runs after submitted is dropped and before the woken queues run, so it still shows what this submission drew. Kept upload blocks are list::Upload now, since main moved list upload memory into [4 GiB, 2^40). external.rs passes &host.

Fix. Each queue wait has a ticket (its place in the queue's submission order), kept with its fence registration. wake_locked releases the ticket under the fence's lock (Timeline::release, a fetch_max), and wait_on_gpu treats a released ticket as reached under the same lock. Later waits have later tickets, so a stale or repeated wake releases none of them. New waits still compare with the current value. This is smaller than the latch in 8d87065: no per-wait Arc, and no change to Signal's locking. The semantics are the same for your test, which is in fence.rs with credit. It fails without the check (left 0, right 1) and passes with it.

Not changed: the blocking wait (SetEventOnCompletion with a null event) still compares the current value in its loop. That is the separate case you pointed out.

Checks (Windows 11, NVIDIA, Rust 1.98.1):

  • clippy -D warnings, default and --all-features: clean.
  • cargo test --workspace --locked --no-fail-fast: 709 passed, 5 failed. The 5 are the ones #1744 lists (NVIDIA's 1,000,000-view heap cap). The 2 in victory-gpu fail the same way on main here, and the 3 in victory-shader are in a crate this PR doesn't touch.
  • Upstream CI passes on b48fbc6.

For #1023, which builds on this: wait_on_gpu now takes the wait's ticket (fence.wait_on_gpu(value, s.done + 1, self) in Timeline::run).

**@⁠AndyLatimer** on GitHub · 2026-11-25 09:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/32#issuecomment-7158597091) Merged `main` (`940d32f`) at `e980aa3` and fixed the rewind regression @⁠contatopablow-spec found, in `b48fbc6`. **Merge.** `host.rs` takes `main`'s `Presentation`. The diagnostics frame dump runs after `submitted` is dropped and before the woken queues run, so it still shows what this submission drew. Kept upload blocks are `list::Upload` now, since `main` moved list upload memory into [4 GiB, 2^40). `external.rs` passes `&host`. **Fix.** Each queue wait has a ticket (its place in the queue's submission order), kept with its fence registration. `wake_locked` releases the ticket under the fence's lock (`Timeline::release`, a `fetch_max`), and `wait_on_gpu` treats a released ticket as reached under the same lock. Later waits have later tickets, so a stale or repeated wake releases none of them. New waits still compare with the current value. This is smaller than the latch in `8d87065`: no per-wait `Arc`, and no change to `Signal`'s locking. The semantics are the same for your test, which is in `fence.rs` with credit. It fails without the check (left 0, right 1) and passes with it. Not changed: the blocking wait (`SetEventOnCompletion` with a null event) still compares the current value in its loop. That is the separate case you pointed out. **Checks** (Windows 11, NVIDIA, Rust 1.98.1): - clippy `-D warnings`, default and `--all-features`: clean. - `cargo test --workspace --locked --no-fail-fast`: 709 passed, 5 failed. The 5 are the ones #1744 lists (NVIDIA's 1,000,000-view heap cap). The 2 in `victory-gpu` fail the same way on `main` here, and the 3 in `victory-shader` are in a crate this PR doesn't touch. - Upstream CI passes on `b48fbc6`. For #1023, which builds on this: `wait_on_gpu` now takes the wait's ticket (`fence.wait_on_gpu(value, s.done + 1, self)` in `Timeline::run`).
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/fence.rs
  • crates/victory-gpu/src/host.rs
  • crates/victory-gpu/src/list.rs
  • crates/victory-gpu/src/queue.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/32/head:github-bot/gh-32'
git switch 'github-bot/gh-32'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-32'
git switch 'github-bot/gh-32'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-32'
git switch 'github-bot/gh-32'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-32'
git switch 'main'
git merge --squash 'github-bot/gh-32'
git switch 'main'
git merge --ff-only 'github-bot/gh-32'
git switch 'main'
git merge 'github-bot/gh-32'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!32
No description provided.