Repository navigation
GPU: fence waits, direct memory-write wakes, queue timeline and host list pool - #32
AndyLatimer wants to merge 13 commits into
Conversation
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 <noreply@anthropic.com>
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.
|
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 |
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 head The merge needs to be redone keeping both sides of No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent). |
|
Two things on the current head (
Static review, not built or run. |
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
|
Thanks for both reviews. Both points are fixed on the new head
Testing on
Synthetic tests only, not run against a title. |
|
Re-checked the new head
No game data used. |
|
@AndyLatimer All eight fence-module tests passed here at |
LAKSHYA-cmd-tech
left a comment
There was a problem hiding this comment.
Tested on Windows 11 MSVC (rustc 1.98.1):
- cargo test -p victory-gpu: 55 passed, 0 failed, 1 ignored (all 11 new queue timeline, fence blocking wait, and bottom-of-pipe wake tests pass cleanly)
- cargo xtask policy: 152 files ok
Confirmed: the Woken handoff successfully resolves the re-entrancy issue on the bottom-of-pipe path by collecting timelines and running woken work only after the submitting mutex and deferred write guards are dropped.
# Conflicts: # crates/victory-gpu/src/list.rs
|
I merged current
|
|
Tested head
AI-assisted (Claude Code). |
… timeline and host list pool
|
CPU-only regression: a satisfied queue wait is lost if the fence is rewound before its deferred wake. Verified at PR head
Add this test inside #[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: Observed 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 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. 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 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. |
… timeline and host list pool
|
Automated triage for the maintainers. This pull request no longer merges cleanly into Generated by Claude Code |
In its Series S mode the title renders at 1280x720 and calls the console's
FidelityFX upscaler (`ffxDispatch` of amd_fidelityfx_loader_xbox.dll) to make
the 1920x1080 output. The loader and upscaler are the title's own DLLs and
run, but the upscaler's passes are compute pipelines in a container that is
not translated ("falling back to NewBE" in the title's log), so the output
was never written: the world was black behind the interface.
The executable's import of `ffxDispatch` is now bound to ours. An upscale
dispatch (type 0x10001, the public FidelityFX API's layout) is recorded as
`victory_gpu::list::upscale_stretch` of its colour input into its output;
any other dispatch, and an upscale that could not be stretched, goes to the
title's DLL. The DLL is not registered as an HLE module: that kept the
title's own from loading and left its other three entry points missing.
Measured on an RTX 3050 8 GB, Windows 11, release build, on top of the
R9G9B9E5 stand-in (Marvisak#32): the Series S world renders (opening cutscene), 0.4
to 1.2 s a frame with peaks of 3 s, the card about a quarter busy, 7 GB of
video memory, no host error in a five-minute run. Series X is not affected
in the run made (it does not dispatch the upscaler).
Not done: temporal accumulation, sharpening, use of the depth and motion
inputs. No test yet. Only the opening cutscene was looked at.
Code tree of fxceless/victory-fork 4e17478 (all rendering work by its author and the VIctory contributors) with, on top: - AMD fixes: skip of 39f0e9aeb156a61c, 32-lane programs per half wave and NaN/Inf filter, configurable texture upload queue, VIctory Marvisak#1599 - upstream VIctory Marvisak#334 (buffer-state tracking) and Marvisak#1271 (globally coherent glc UAVs) - fork PRs Marvisak#95, Marvisak#71, Marvisak#32, Marvisak#86; VIctory Marvisak#1696, Marvisak#1338, Marvisak#1291, Marvisak#1732 - DirectStorage page lists read at the title's submit (analysis by JappertjeV, klbf-lab#3) - offline pipeline pre-build that saves as it goes and skips driver-crashing pipelines - Series S plane composition, VICTORY_FFX_SIMPLE, scripted keys in release builds - docs/klbf/skip-amd.txt: AMD skip list used for our runs
In its Series S mode the title renders at 1280x720 and calls the console's
FidelityFX upscaler (`ffxDispatch` of amd_fidelityfx_loader_xbox.dll) to make
the 1920x1080 output. The loader and upscaler are the title's own DLLs and
run, but the upscaler's passes are compute pipelines in a container that is
not translated ("falling back to NewBE" in the title's log), so the output
was never written: the world was black behind the interface.
The executable's import of `ffxDispatch` is now bound to ours. An upscale
dispatch (type 0x10001, the public FidelityFX API's layout) is recorded as
`victory_gpu::list::upscale_stretch` of its colour input into its output;
any other dispatch, and an upscale that could not be stretched, goes to the
title's DLL. The DLL is not registered as an HLE module: that kept the
title's own from loading and left its other three entry points missing.
Measured on an RTX 3050 8 GB, Windows 11, release build, on top of the
R9G9B9E5 stand-in (Marvisak#32): the Series S world renders (opening cutscene), 0.4
to 1.2 s a frame with peaks of 3 s, the card about a quarter busy, 7 GB of
video memory, no host error in a five-minute run. Series X is not affected
in the run made (it does not dispatch the upscaler).
Not done: temporal accumulation, sharpening, use of the depth and motion
inputs. No test yet. Only the opening cutscene was looked at.
# 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 Marvisak#32): fails without the latch (left: 0, right: 1), passes with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merged Merge. Fix. Each queue wait has a ticket (its place in the queue's submission order), kept with its fence registration. Not changed: the blocking wait ( Checks (Windows 11, NVIDIA, Rust 1.98.1):
For #1023, which builds on this: |
…arvisak#32) (Marvisak#43) Host::new logs the DXGI adapter (name, vendor) once per adapter. Tests that lack a compiler or device now go through test_skip::skip, which prints a VICTORY TEST SKIPPED line and, with VICTORY_STRICT_TESTS=1, fails instead. (cherry picked from commit b4180ea)
Closes the GPU fence and command-queue synchronization gaps:
fence.rs,queue.rs):ID3D12Fence::SetEventOnCompletion(value, NULL)previously returnedE_NOTIMPLimmediately instead of blocking until the fence reachedvalue. It now blocks on a condition variable, re-checking every 100 ms and warning every 5 s while stuck.Written::write, now using atomicReleasestores when aligned) wakes any waiting events, blocking waits, or held queues on that fence.timeline.rs,queue.rs,fence.rs,list.rs,host.rs,draw.rs):ID3D12CommandQueue::Waitwas previously a no-op, so work submitted after a wait for a value signalled later by another queue ran too early.Wait,Signal,ExecuteCommandLists,PresentandCopyPageMappingsBatchXin submission order through aTimeline. 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).Host::acquire_list/Host::recycle_list, bounded at 64 lists), and the pendingHostListkeeps both itsallocate_uploadblocks (keep_uploads) and its dynamic descriptor slots (keep_dynamic) until execution completes. If acquiring a replacement list fails, the in-flightHostListis left untouched instead of being reset.PresentandCopyPageMappingsBatchX(queue.rs,object.rs,fence.rs):presentsnapshots plane parameters at call time, retains the presented resource via a sharedobject::Heldwrapper (also reused byfence::Held), and presents through the queue's timeline.copy_page_mappingssnapshots caller-owned batch/range arrays at submission time (with checked address arithmetic) and applies mappings through the queue's timeline.fence.rs):victory-fence-watch) polls live fences every 10 ms only while at least one event or queue wait is pending and parks on aCondvarwhen 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'swait_valueremains 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-queueWait/Signal, held-backPresent, held-backCopyPageMappingsBatchX, 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).