gpu: implement ordered 32-bit and 64-bit command-list memory waits #1023

Open
github-bot wants to merge 17 commits from github-bot/gh-1023 into main AGit
Owner

@⁠KLeek5 on GitHub · 2026-11-24 15:09 UTC · original
KLeek5:fix/gpu-wait64-v3 → main · +2627 −153 · 10 files · 17 commits · open

Summary

Addresses #700 by implementing ordered, non-blocking command-list memory waits.

  • Preserves execution of commands before a wait while deferring subsequent work until the predicate is satisfied.
  • Supports masked 32-bit and full-width 64-bit comparisons.
  • Supports all eight D3D12 comparison functions.
  • Avoids unnecessary native command-list allocations for consecutive waits.
  • Handles CPU and queue fence signals without losing transient satisfied predicates.
  • Preserves pending work across command-list resets and releases.
  • Uses checked guest-memory reads.
  • Never treats an unsatisfied wait as completed due to a timeout.

Validation

Tested on NVIDIA RTX 3050 and WARP:

  • Shared regression scenarios: 14/14 passed on each adapter.
  • GPU diagnostic tests: 79/79 passed on each adapter.
  • Wake-up stress tests: 400/400 passed on each adapter.
  • Transient equality tests: 16/16 passed per tested signal path.
  • Clippy passed.

Dependencies and limitations

This branch incorporates the source changes from #32 at 9c5328d.

Non-zero wait flags, transient external memory writes between polls, and end-to-end shader UAV/copy-back behavior remain unverified.

Full workspace validation and cargo xtask policy were blocked by an unavailable dependency.

No in-game validation has been performed. Independent testing is welcome.

Thanks to AndyLatimer and AlanQiang0418 for their alternative implementations and useful comparison points.

AI-assisted development (OpenAI Codex).

**@⁠KLeek5** on GitHub · 2026-11-24 15:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/1023) `KLeek5:fix/gpu-wait64-v3` → `main` · +2627 −153 · 10 files · 17 commits · open ## Summary Addresses #700 by implementing ordered, non-blocking command-list memory waits. - Preserves execution of commands before a wait while deferring subsequent work until the predicate is satisfied. - Supports masked 32-bit and full-width 64-bit comparisons. - Supports all eight D3D12 comparison functions. - Avoids unnecessary native command-list allocations for consecutive waits. - Handles CPU and queue fence signals without losing transient satisfied predicates. - Preserves pending work across command-list resets and releases. - Uses checked guest-memory reads. - Never treats an unsatisfied wait as completed due to a timeout. ## Validation Tested on NVIDIA RTX 3050 and WARP: - Shared regression scenarios: 14/14 passed on each adapter. - GPU diagnostic tests: 79/79 passed on each adapter. - Wake-up stress tests: 400/400 passed on each adapter. - Transient equality tests: 16/16 passed per tested signal path. - Clippy passed. ## Dependencies and limitations This branch incorporates the source changes from #32 at `9c5328d`. Non-zero wait flags, transient external memory writes between polls, and end-to-end shader UAV/copy-back behavior remain unverified. Full workspace validation and `cargo xtask policy` were blocked by an unavailable dependency. No in-game validation has been performed. Independent testing is welcome. Thanks to AndyLatimer and AlanQiang0418 for their alternative implementations and useful comparison points. AI-assisted development (OpenAI Codex).
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]>
Keep memory waits in timeline order and retain closed native segments only where earlier commands need to run. Recycle idle segments and warn on long waits without advancing the queue.

The masked Wait32 coverage builds on AlanQiang0418’s comparison in issue #700. Implementation and synthetic validation assisted by Codex.
PR #32 by AndyLatimer, head 9c5328d4ef. Source tree verified against the public integration merge plus the latest main change. Reconstructed locally with Codex.
Keep possible waits alive and release impossible waits with the guest queue. Use checked Windows reads for guest operands, following AndyLatimer’s approach in a9a7985. Developed with Codex.
Developed and tested locally using Codex.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:17:30 +00:00
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 15:18 UTC · original

We checked the shader UAV/copyback case on 836490b with an RTX 4090 under Wine/vkd3d-proton 3.2. A guest compute dispatch updated two UAV records, followed in the same guest command list by a masked 32-bit wait for the low byte of the first output to equal 20 (flags zero), then a copy. After submission the two shader output bytes were 20 and 44, and the copy after the wait returned 0x01010114_01010101.

Removing only the wait left the final shader outputs intact, but the subsequent copy captured the old CPU value 0x01010101_01010101. This distinguishes visibility at the point of the copy from eventual copyback at the end of submission. Both existing wait64 GPU tests also passed. The shader-produced predicate test covers this one same-list path; nonzero flags, external transient writes and title behavior remain open.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 15:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/1023#issuecomment-7135807561) We checked the shader UAV/copyback case on 836490b with an RTX 4090 under Wine/vkd3d-proton 3.2. A guest compute dispatch updated two UAV records, followed in the same guest command list by a masked 32-bit wait for the low byte of the first output to equal 20 (flags zero), then a copy. After submission the two shader output bytes were 20 and 44, and the copy after the wait returned `0x01010114_01010101`. Removing only the wait left the final shader outputs intact, but the subsequent copy captured the old CPU value `0x01010101_01010101`. This distinguishes visibility at the point of the copy from eventual copyback at the end of submission. Both existing wait64 GPU tests also passed. The shader-produced predicate test covers this one same-list path; nonzero flags, external transient writes and title behavior remain open.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 15:40 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 836490b: cargo test -p victory-gpu passes, 70 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 15:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/1023#issuecomment-7136415545) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 836490b: `cargo test -p victory-gpu` passes, 70 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠NuraadGit on GitHub · 2026-11-24 16:23 UTC · original

In-title numbers for the waits this handles, from an RTX 2080 (measured on #700 with other branches, not with this one). They bear on one choice here: a wait never completes by timeout.

  • How often: of the first 4,096 64-bit list waits, 1,193 (29%) were unmet when the list was submitted. None of the first 1,024 (menus and loading) were. None was produced by an earlier write in the same list. All use comparison 7 with a full 64-bit reference.
  • Which: 16 counters with an 8-byte stride (not contiguous), each waiting for reference = now + 1 (rarely + 2).
  • The risk: AlanQiang0418's 8dc74b6 plus my reset fix (8168962) gives up after 2 s. That fired 234 times in ~5.5 minutes in the world. So with that implementation many of these counters weren't satisfied by any write it modelled. Without a timeout, the same case would hold a queue for good.

Your copy-back wakes waits, so some of those 234 may resolve here; @⁠MichaelSmithAI's shader-written test passes. Only a title run can say. The line to look for is your 5-s GPU queue still waiting for memory warning in the world.

For that run, two things would help:

  1. An opt-in give-up (an environment switch, off by default), so that one stuck counter doesn't end the test.
  2. The waiting address in that warning, if it isn't already in the wait it prints, so it can be matched to the 16 counters.

The other failure I hit on 8dc74b6 was held lists that the title resets and records again: DXGI_ERROR_INVALID_CALL at world entry, 2 of 2 runs. You handle that case. My test for it, a_held_list_the_title_resets_runs_first (https://github.com/NuraadGit/VIctory/tree/gpu/held-list-reset), may be useful as an extra one.

I wouldn't expect a picture change from the waits alone. With 8dc74b6 + 8168962 the presented world frame stayed near black, max 2 of 255, as without.

AI-assisted (Claude Code): the probe, runs and log summary were automated. The hardware, title copy and runs are the user's.

**@⁠NuraadGit** on GitHub · 2026-11-24 16:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/1023#issuecomment-7137604014) In-title numbers for the waits this handles, from an RTX 2080 (measured on #700 with other branches, not with this one). They bear on one choice here: **a wait never completes by timeout.** - **How often:** of the first 4,096 64-bit list waits, 1,193 (29%) were unmet when the list was submitted. None of the first 1,024 (menus and loading) were. None was produced by an earlier write in the same list. All use comparison 7 with a full 64-bit reference. - **Which:** 16 counters with an 8-byte stride (not contiguous), each waiting for `reference = now + 1` (rarely + 2). - **The risk:** AlanQiang0418's `8dc74b6` plus my reset fix (`8168962`) gives up after 2 s. That fired **234 times in ~5.5 minutes** in the world. So with that implementation many of these counters weren't satisfied by any write it modelled. Without a timeout, the same case would hold a queue for good. Your copy-back wakes waits, so some of those 234 may resolve here; @⁠MichaelSmithAI's shader-written test passes. Only a title run can say. The line to look for is your 5-s `GPU queue still waiting for memory` warning in the world. For that run, two things would help: 1. An opt-in give-up (an environment switch, off by default), so that one stuck counter doesn't end the test. 2. The waiting address in that warning, if it isn't already in the `wait` it prints, so it can be matched to the 16 counters. The other failure I hit on `8dc74b6` was held lists that the title resets and records again: `DXGI_ERROR_INVALID_CALL` at world entry, 2 of 2 runs. You handle that case. My test for it, `a_held_list_the_title_resets_runs_first` (https://github.com/NuraadGit/VIctory/tree/gpu/held-list-reset), may be useful as an extra one. I wouldn't expect a picture change from the waits alone. With `8dc74b6` + `8168962` the presented world frame stayed near black, max 2 of 255, as without. *AI-assisted (Claude Code): the probe, runs and log summary were automated. The hardware, title copy and runs are the user's.*
Author
Owner

@⁠AgneyaK on GitHub · 2026-11-24 20:55 UTC · original

Tested in the title on a 6 GB / 16 GB laptop as KLeek5 asked; the full table is at #700.

  • Merges cleanly onto main ffe310e + #208 + the wave64 stack + #452 + #579 + #431.
  • In 8.5 minutes of the story load: no GPU queue still waiting for memory warning, so every wait resolved within 5 s. No stalled queue. Frame time about 13% above the same tree without this PR.
  • Without #431 (less memory headroom), one run ended at 1:39 with host GPU failure: wait segment: Not enough memory resources (0x8007000E) from acquire_list in wait_value. The machine was at its commit limit. A fallback there instead of host::fail would keep low-memory machines running.

AI use: Claude Code (Claude Opus 5.5) ran the title on my machine and drafted this.

**@⁠AgneyaK** on GitHub · 2026-11-24 20:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/1023#issuecomment-7144240250) Tested in the title on a 6 GB / 16 GB laptop as KLeek5 asked; the full table is at https://git.gtahub.st/github/Marvisak--VIctory/issues/700. - Merges cleanly onto `main` `ffe310e` + #208 + the wave64 stack + #452 + #579 + #431. - In 8.5 minutes of the story load: no `GPU queue still waiting for memory` warning, so every wait resolved within 5 s. No stalled queue. Frame time about 13% above the same tree without this PR. - Without #431 (less memory headroom), one run ended at 1:39 with `host GPU failure: wait segment: Not enough memory resources (0x8007000E)` from `acquire_list` in `wait_value`. The machine was at its commit limit. A fallback there instead of `host::fail` would keep low-memory machines running. AI use: Claude Code (Claude Opus 5.5) ran the title on my machine and drafted this.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:33 UTC · original

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-gpu/src/draw.rs, crates/victory-gpu/src/host.rs, crates/victory-gpu/src/list.rs, crates/victory-gpu/src/shadow.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1023#issuecomment-7148634675) <!-- victory-triage v1 head=836490b9690c0215a66914f47269783bc12aa86e verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-gpu/src/draw.rs`, `crates/victory-gpu/src/host.rs`, `crates/victory-gpu/src/list.rs`, `crates/victory-gpu/src/shadow.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/draw.rs
  • crates/victory-gpu/src/fence.rs
  • crates/victory-gpu/src/host.rs
  • crates/victory-gpu/src/list.rs
  • crates/victory-gpu/src/queue.rs
  • crates/victory-gpu/src/shadow.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/1023/head:github-bot/gh-1023'
git switch 'github-bot/gh-1023'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1023'
git switch 'github-bot/gh-1023'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1023'
git switch 'github-bot/gh-1023'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1023'
git switch 'main'
git merge --squash 'github-bot/gh-1023'
git switch 'main'
git merge --ff-only 'github-bot/gh-1023'
git switch 'main'
git merge 'github-bot/gh-1023'
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!1023
No description provided.