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

Open
KLeek5 wants to merge 17 commits from upstream-pr/1023 into main
KLeek5 commented 2026-11-24 15:09:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KLeek5 on 2026-11-24T15:09:26Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6584921995 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1023). Originally posted by [KLeek5](https://github.com/KLeek5) on 2026-11-24T15:09:26Z. --- ## 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).
MichaelSmithAI commented 2026-11-24 16:05:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T15:18:35Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7135807561 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1023#issuecomment-7135807561). Originally posted by [MichaelSmithAI](https://github.com/MichaelSmithAI) on 2026-11-24T15:18:35Z. --- 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.
Zipettte commented 2026-11-24 16:05:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T15:40:14Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7136415545 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1023#issuecomment-7136415545). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T15:40:14Z. --- 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)._
NuraadGit commented 2026-11-24 17:04:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by NuraadGit on 2026-11-24T16:23:58Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7137604014 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1023#issuecomment-7137604014). Originally posted by [NuraadGit](https://github.com/NuraadGit) on 2026-11-24T16:23:58Z. --- 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.*
AgneyaK commented 2026-11-24 21:03:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AgneyaK on 2026-11-24T20:55:34Z.


Tested in the title on a 6 GB / 16 GB laptop as KLeek5 asked; the full table is at https://github.com/Marvisak/VIctory/issues/700#issuecomment-7144235622.

  • 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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7144240250 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1023#issuecomment-7144240250). Originally posted by [AgneyaK](https://github.com/AgneyaK) on 2026-11-24T20:55:34Z. --- Tested in the title on a 6 GB / 16 GB laptop as KLeek5 asked; the full table is at https://github.com/Marvisak/VIctory/issues/700#issuecomment-7144235622. - 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.
Marvisak commented 2026-11-25 01:08:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:33:32Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148634675 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1023#issuecomment-7148634675). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:33:32Z. --- <!-- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1023:upstream-pr/1023'
git switch 'upstream-pr/1023'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1023'
git switch 'upstream-pr/1023'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1023'
git switch 'upstream-pr/1023'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1023'
git switch 'main'
git merge --squash 'upstream-pr/1023'
git switch 'main'
git merge --ff-only 'upstream-pr/1023'
git switch 'main'
git merge 'upstream-pr/1023'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!1023
No description provided.