GPU: fence waits, direct memory-write wakes, queue timeline and host list pool #32
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!32
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-32"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@AndyLatimer on GitHub · 2026-11-23 23:27 UTC · original
AndyLatimer:fix/gpu-fence-and-queue-waits→main· +1415 −95 · 9 files · 13 commits · openCloses 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).@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) thesubmittedguard lives until the end of the function, and the deferred writes run athost.rs:510while it's still held (as is thelist.deferred()guard of the loop).Written::writenow callscrate::fence::written(queue.rs:240), which goeswake→run_held(fence.rs:198/238) →Timeline::wake→run, and runs the held queue'sOp::Runclosure inline. That closure callshost.executeagain, which locksself.submittedon the same thread. So a graphics queue thatWaits on a fence that a compute list moves with a bottom-of-pipe write would deadlock (or panic, since stdMutexisn't re-entrant). That's exactly the case the PR targets. One fix: havewrittenreturn the timelines to wake instead of running them, collect them inexecute, and callrun_heldaftersubmittedand thedeferred()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.@DaviTostes on GitHub · 2026-11-24 01:04 UTC · original
The head
6e88bc0does not compile: the merge intomainleftcrates/victory-gpu/src/host.rswith only the last 126 lines (git shows 1 919 lines deleted againstmain).mod host;is present inlib.rsand the file exists, but the top of the module is gone, so everything that imports from it fails:The merge needs to be redone keeping both sides of
host.rs; thetimelinemodule 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).
@Sunkiller-qc on GitHub · 2026-11-24 01:05 UTC · original
Two things on the current head (
6e88bc0):The merge from main looks like it went wrong for
crates/victory-gpu/src/host.rs. At80443e8the file has about 1,830 lines; after the merge it has 126, soHost,HostList,executeand the rest are gone (git show --stat 6e88bc0showshost.rs | 1701 -----). That's where the -1835 in the PR stats comes from, and the crate can't build like this. Redoing the merge, orgit checkout 80443e8 -- crates/victory-gpu/src/host.rsand then reapplying main's changes to that file, should fix it.The re-entrancy from my earlier comment is still there at
80443e8:Host::executetakessubmittedathost.rs:499and still runswhat.write(...)athost.rs:562with that guard andlist.deferred()held.fence::written(fence.rs:335) still wakes held queues inline, and the woken work callshost.executeagain. Collecting the timelines to wake and running them after both guards drop would avoid this.Static review, not built or run.
@AndyLatimer on GitHub · 2026-11-24 01:21 UTC · original
Thanks for both reviews. Both points are fixed on the new head
8fd82c9:6e88bc0kept only the last 126 lines ofhost.rs):b14bac3restores the file as the merge should have left it, keeping both sides' additions (this PR's kept uploads/descriptor slots andSend/Sync, and main's diagnostics timestamps).d2da283then merges currentmain(d2a4bae) with no conflicts.8fd82c9):Written::writeandfence::writtennow return the woken queues instead of running them, as a#[must_use]Woken.Host::executecollects them while it does the writes and runs them after droppingsubmittedand thedeferred()guards. Without a host GPU,defer_writewrites at once and runs them right away, with no lock held there. The new testbottom_of_pipe_writes_leave_woken_work_to_the_writerholds 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, inxmem.rsandhost.rs:267, are onmain).cargo clippy -p victory --features diagnostics: clean.cargo xtask policy: pass.Synthetic tests only, not run against a title.
@DaviTostes on GitHub · 2026-11-24 01:22 UTC · original
Re-checked the new head
8fd82c9after the repair merge: the build is fixed and the suite runs.host.rsis back to 2 151 lines (it was 126 on6e88bc0), and the Windows test build compiles.d3dcompiler_47: 53 passed, 2 failed, 1 ignored.a_rejected_blob_gives_an_empty_library(vkd3d needs a non-empty blob) and #128 (VirtualQuerysees vkd3d-mapped memory asMEM_FREE). The ignored test is a benchmark.No game data used.
@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-enterHost::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@AndyLatimer on GitHub · 2026-11-24 08:51 UTC · original
I merged current
main(58fed37) into the branch; the new head is9c5328d. The only conflict was inlist.rs, in two copy paths thatmaingave a texture upload (#671/#680). I keptmain's code, with&listbecausehost_listreturns anArcon this branch. Results:cargo test -p victory-gpu --lib: 61 passed, 1 ignored.cargo check -p victory-gpu --features diagnostics --all-targetspasses.cargo test --workspace --exclude victory-shader --no-fail-fast: 230 passed, 0 failed.victory-shaderis left out because its tests do not compile onmainitself:lower.rs:6963callslowers(&words)with one argument where it now takes two. That breakage is onmainand has nothing to do with this branch.@DeerSilver on GitHub · 2026-11-24 11:01 UTC · original
Tested head
9c5328dmerged ontomainffe310e(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.blocking_wait_returns_at_once_when_reachedblocking_wait_blocks_until_signalledbottom_of_pipe_write_releases_blocking_waitbottom_of_pipe_write_sets_waiting_eventdirect_memory_write_sets_waiting_eventreleased_fences_leave_the_registrybottom_of_pipe_writes_leave_woken_work_to_the_writerpending_list_reset_and_drop_keep_uploads_and_recycle_host_listwork_after_a_wait_runs_once_the_other_queue_signalspresent_runs_after_a_queues_waitpage_mappings_run_after_a_queues_waitdirect_memory_write_wakes_held_queuecargo test --workspace --locked: 354 passed, 0 failed, 6 ignored, against 342 passed / 6 ignored onmain.cargo clippy --workspace --all-targets --locked -- -D warnings: clean.AI-assisted (Claude Code).
@sash2kk on GitHub · 2026-11-24 11:01 UTC · original
Tested
9c5328dmerged with currentmain(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--all-features: cleancargo test --workspace --locked: all pass (victory-gpu 62 passed / 1 ignored, up from 50 onmain)Read through
fence.rsandtimeline.rs: I found no lost wakeup.signalstores underwaitersbefore takingqueues, andwait_on_gpuchecks the value underqueues, so a signal racing a queueWaiteither 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 intomain, then with plainmainas a control: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.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).
@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_lockedremoves a satisfied queue registration and returns its timeline, butTimeline::runrechecks the current value viawait_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 existingmod tests(uses its existing imports):Command:
cargo test --offline --locked -p victory-gpu --lib queue_wait_survives_rewind_before_deferred_wake -- --nocapture --test-threads=1Observed
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@8d870653b6Each 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.
Signalserializes 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 deferredWokeninterface 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 existingvictory-shader/src/emit/lower.rs:6963E0061 (missingrsrc2argument tolowers), 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.
@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 incrates/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 currentmain. The earlier verdict (merge-candidate) was for an older state ofmain.Generated by Claude Code
@AndyLatimer on GitHub · 2026-11-25 09:38 UTC · original
Merged
main(940d32f) ate980aa3and fixed the rewind regression @contatopablow-spec found, inb48fbc6.Merge.
host.rstakesmain'sPresentation. The diagnostics frame dump runs aftersubmittedis dropped and before the woken queues run, so it still shows what this submission drew. Kept upload blocks arelist::Uploadnow, sincemainmoved list upload memory into [4 GiB, 2^40).external.rspasses&host.Fix. Each queue wait has a ticket (its place in the queue's submission order), kept with its fence registration.
wake_lockedreleases the ticket under the fence's lock (Timeline::release, afetch_max), andwait_on_gputreats 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 in8d87065: no per-waitArc, and no change toSignal's locking. The semantics are the same for your test, which is infence.rswith credit. It fails without the check (left 0, right 1) and passes with it.Not changed: the blocking wait (
SetEventOnCompletionwith 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):
-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 invictory-gpufail the same way onmainhere, and the 3 invictory-shaderare in a crate this PR doesn't touch.b48fbc6.For #1023, which builds on this:
wait_on_gpunow takes the wait's ticket (fence.wait_on_gpu(value, s.done + 1, self)inTimeline::run).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.Merge
Merge the changes and update on Forgejo.