GPU diagnostics: VICTORY_CARD_VERIFY compares card copies with their CPU side #455

Open
github-bot wants to merge 1 commit from github-bot/gh-455 into main AGit
Owner

@⁠xunbreakablex on GitHub · 2026-11-25 01:02 UTC · original
xunbreakablex:card-verify-pr → main · +722 −0 · 5 files · 1 commits · open

Needs human attention: this is a diagnostics-only change, but it settles every flight and takes the submission lock on the frames it checks, so please read the "when the sides are comparable" part of docs/card-verify.md before enabling it on a build you care about. The three-way classification and the live read of title memory have been compiled and unit-tested but not run in game; only the earlier two-way comparison was run (below).

Why

Title buffers of VICTORY_CARD_BUFFERS_MIN_MB or more are held in the card's memory with a CPU side (what title memory is copied into, and the reference the card's writes are found against). card_before, card_back, card_merge and the relay's merge exist to keep the two equal, but nothing checks that end to end, and VICTORY_CARD_BUFFERS_MIN_MB=1 (recommended in the README) moves ~87 more copies to this path. This adds a way to check it.

What

With VICTORY_CARD_VERIFY=N (diagnostics builds only; off by default, one OnceLock read per present when off), every N-th presented frame each copy in the card's memory is read back and compared with its CPU side by 64 KiB piece, after every flight has been settled and with the submission lock held. One card verify: line per copy (ok / MISMATCH with pieces, bytes and the first eight differing title addresses / skipped) and one summary line per frame. VICTORY_CARD_VERIFY_MAX_MB (256) bounds the bytes read back per checked frame; copies that do not fit are taken first at the next check.

For pieces that differ, each differing byte is also compared with the title's own memory read live, which says which side is newer: card newer (shaders wrote it and it did not come back), CPU side stale (a merge missed it), or neither has it. A second line per copy gives pieces per class and whether the differing bytes lie inside a range declared as written in the last two frames (an undeclared shader write is a real mismatch of a different kind).

Docs: docs/card-verify.md. Nothing changes in builds without the diagnostics feature.

Tested

  • cargo check -p victory-gpu and --features diagnostics (--locked): clean
  • cargo clippy -p victory-gpu --all-targets -- -D warnings, default and --all-features (as in CI): clean
  • cargo test -p victory-gpu --lib --features diagnostics -- verify_tests classify_tests: 2/2 passed (piece counting and the A/B/C/D classification; no GPU). The workspace tests and the xtask policy test were not run locally
  • In game, earlier two-way version (card vs CPU side only), RTX 4070 12 GB / Ryzen 5 5600, VICTORY_RELAY=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024 VICTORY_CARD_VERIFY=10, world: 233 rounds, 98 copies, every copy checked at least once, 1,311 copy checks: 0 mismatches in 97 copies (1,302 checks); 9 checks mismatched in one 24 MiB copy (140 of its 384 pieces, the same pieces every time), which is already in the card's memory with the default 16 MB limit. Measurements around this: #418.

Not tested

  • The three-way classes against a real mismatch in game (the 24 MiB copy above is the case I would run it on).
  • Other GPUs; builds on top of 1582757/#191-style changes beyond what main already has.

AI-assisted (Claude); the in-game run was done on my machine.

**@⁠xunbreakablex** on GitHub · 2026-11-25 01:02 UTC · [original](https://github.com/fxceless/victory-fork/pull/455) `xunbreakablex:card-verify-pr` → `main` · +722 −0 · 5 files · 1 commits · open **Needs human attention:** this is a diagnostics-only change, but it settles every flight and takes the submission lock on the frames it checks, so please read the "when the sides are comparable" part of `docs/card-verify.md` before enabling it on a build you care about. The three-way classification and the live read of title memory have been compiled and unit-tested but **not run in game**; only the earlier two-way comparison was run (below). ### Why Title buffers of `VICTORY_CARD_BUFFERS_MIN_MB` or more are held in the card's memory with a CPU side (what title memory is copied into, and the reference the card's writes are found against). `card_before`, `card_back`, `card_merge` and the relay's merge exist to keep the two equal, but nothing checks that end to end, and `VICTORY_CARD_BUFFERS_MIN_MB=1` (recommended in the README) moves ~87 more copies to this path. This adds a way to check it. ### What With `VICTORY_CARD_VERIFY=N` (`diagnostics` builds only; off by default, one `OnceLock` read per present when off), every N-th presented frame each copy in the card's memory is read back and compared with its CPU side by 64 KiB piece, after every flight has been settled and with the submission lock held. One `card verify:` line per copy (ok / MISMATCH with pieces, bytes and the first eight differing title addresses / skipped) and one summary line per frame. `VICTORY_CARD_VERIFY_MAX_MB` (256) bounds the bytes read back per checked frame; copies that do not fit are taken first at the next check. For pieces that differ, each differing byte is also compared with the title's own memory read live, which says which side is newer: card newer (shaders wrote it and it did not come back), CPU side stale (a merge missed it), or neither has it. A second line per copy gives pieces per class and whether the differing bytes lie inside a range declared as written in the last two frames (an undeclared shader write is a real mismatch of a different kind). Docs: `docs/card-verify.md`. Nothing changes in builds without the `diagnostics` feature. ### Tested - `cargo check -p victory-gpu` and `--features diagnostics` (`--locked`): clean - `cargo clippy -p victory-gpu --all-targets -- -D warnings`, default and `--all-features` (as in CI): clean - `cargo test -p victory-gpu --lib --features diagnostics -- verify_tests classify_tests`: 2/2 passed (piece counting and the A/B/C/D classification; no GPU). The workspace tests and the `xtask` policy test were not run locally - In game, earlier two-way version (card vs CPU side only), RTX 4070 12 GB / Ryzen 5 5600, `VICTORY_RELAY=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024 VICTORY_CARD_VERIFY=10`, world: 233 rounds, 98 copies, every copy checked at least once, 1,311 copy checks: 0 mismatches in 97 copies (1,302 checks); 9 checks mismatched in one 24 MiB copy (140 of its 384 pieces, the same pieces every time), which is already in the card's memory with the default 16 MB limit. Measurements around this: #418. ### Not tested - The three-way classes against a real mismatch in game (the 24 MiB copy above is the case I would run it on). - Other GPUs; builds on top of `1582757`/#191-style changes beyond what `main` already has. AI-assisted (Claude); the in-game run was done on my machine.
Title buffers of VICTORY_CARD_BUFFERS_MIN_MB or more are held in the card's
memory with a CPU side (what title memory is copied into, and the reference
the card's writes are found against). card_before, card_back, card_merge
and the relay's merge exist to keep the two equal; nothing checked that
end to end. With VICTORY_CARD_VERIFY=N (diagnostics builds only), every
N-th presented frame each such copy, windows included, is read back from
the card and compared with its CPU side by 64 KiB piece. One `card verify:`
line per copy (ok / MISMATCH with the pieces, bytes and the first eight
differing title addresses / skipped) and one summary line per frame.

When the sides are comparable: at the start of the present, with the
submission lock held and after every flight has been settled (with
VICTORY_RELAY the landing thread's work, waited for), so no shader of ours
runs, every fetch has been merged and card_done has run. A copy that still
names a pending shader write is skipped ("skipped: in flight"). Offsets
the CPU side holds that have not gone up to the card yet (Card::dirty) are
left out and counted, since they differ by design until the next
submission.

For the pieces that differ, each differing byte is also compared with the
title's own memory, read live: title == CPU != card (the card's byte is
newer), title == card != CPU (the CPU side is stale), neither (the title
wrote it and neither side has it); a second line per copy gives pieces per
class, how many hold a byte inside a range declared as written in the last
two frames, and the first samples.

False positives to know of: the title's other threads keep running, so the
live read of title memory is a snapshot; a write by a shader outside every
declared range is a real mismatch (an undeclared write), not a fault of the
card path; the card's side is read without a barrier, as the existing
fetches are.

Cost: off (the variable unset or 0, or any build without the
`diagnostics` feature) it is one OnceLock read per present, and the
declared-range history is not kept. On, a checked frame settles every
flight, takes the submission lock and reads up to
VICTORY_CARD_VERIFY_MAX_MB (256; 0: all) of copies back through a 64 MiB
buffer; copies that do not fit are taken first at the next check.
Unit tests cover the per-piece counting and the classification (no GPU).

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

@⁠deepdev237 on GitHub · 2026-11-25 04:03 UTC · original · edited 2026-11-25 05:11 UTC

🤖 AI-generated. This comment was written by Claude Opus 5.5 (Anthropic, model claude-opus-5-5), running as an autonomous agent in Claude Code. The AI did the work it reports: it merged the branches, built, ran the commands, tests and game runs, and read the logs. A person asked for this testing; this text was not reviewed by them before posting. Please verify anything you rely on.

Full test environment
  • OS: Windows 11 Pro, version 10.0.26300 (build 26300)
  • CPU: AMD Ryzen 9 5950X, 16 cores / 32 threads
  • RAM: 24 GB DDR4 at 2666 MT/s; page file 32 GiB on the system drive, Windows commit limit 55.92 GiB
  • GPU: AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32015.7029 (dated 2026-10-18); D3D12 reports host wave lanes min 32 / max 64; DXGI local video memory budget 15,419 MB; mesh shaders and shader model 6.6 available
  • Also installed: a virtual display adapter (Parsec Virtual Display Adapter 0.45). VIctory ran on the RX 9060 XT.
  • Toolchain: rustc 1.98.1 (48a229cea 2026-09-01), cargo 1.98.1 (797e8a9bc 2026-08-05), LLVM 22.1.8, host x86_64-pc-windows-msvc
  • Build: cargo build --profile diag -p victory --features diagnostics (diag = release + debug info)
  • Base: victory-fork main 310c6eb6c16822ab95076aad61fce19bba86bb98
  • Game files: Series X build 1.0.2.1. This copy has zero-filled holes in 11 archives (about 338 MiB in all: levels.rpf, audio.rpf, pack/story000/story000.rpf, navmeshes.rpf and six data/ttdb/*.ttpf), so failures that depend on those bytes are not emulator bugs.
  • Full logs (local paths shortened): https://gist.github.com/deepdev237/785e05b02d0dcece7aac1303f7fe4ba8

Integration note: this PR and #496 ("GPU: avoid re-uploading card data after a waited fetch") both merge onto main 310c6eb, but together they do not compile:

error[E0599]: no method named `clone` found for struct `std::sync::MutexGuard<'_, CardUpdates>` in the current scope
    --> crates\victory-gpu\src\shadow.rs  (Shadow::card_verify_view)

#496 changes Card::dirty from Mutex<Vec<(usize, usize)>> to Mutex<CardUpdates>, where the pending ranges are split into upload and hash_only. card_verify_view still does card.dirty.lock()...clone(). This is what I used, which leaves both kinds of pending range out of the comparison (bytes the card has not received yet, and bytes whose hash only needs refreshing):

        // Since #496 the pending ranges are split into uploads and hash-only
        // refreshes; both are left out of the comparison.
        let mut dirty: Vec<(usize, usize)> = {
            let updates = card.dirty.lock().unwrap_or_else(|e| e.into_inner());
            let mut all = updates.upload.clone();
            all.extend_from_slice(&updates.hash_only);
            all
        };

The conflict in Host::present with main (which now takes &Arc<HostTexture> and moves the texture to COPY_SOURCE through the copy list's prelude) resolves by putting the two card_verify::frame(self, frame) lines at the top of main's version.

With both changes, the full unit and hardware test run (598 passed, 0 failed, 6 ignored) passes on 310c6eb plus about 100 open PRs, on an RX 9060 XT (RDNA4, driver 32.0.32015.7029). I have not yet run with VICTORY_CARD_VERIFY set; I will add the results here when I do.

Exact state tested
  • This PR's head: 4de64fd0eb52243b1a5c145e4a877a867ef06ffe; #496's head: b7d8c444e14f950a6afd9f5ae1e1b32765091522. #496 was merged first, then this PR, both with git merge --no-ff onto the integration branch.
  • Merge conflict (1 hunk, 36 diff lines) in crates/victory-gpu/src/host.rs, impl Host { fn present }: main now has present(&self, texture: &Arc<HostTexture>, frame: u64) -> Option<bool> and moves the texture to COPY_SOURCE through the copy list's prelude under self.submitted. Resolved by keeping main's function and adding the PR's #[cfg(feature = "diagnostics")] card_verify::frame(self, frame); at its start.
  • Compile error after the merge (before the fix above): no method named clone found for struct std::sync::MutexGuard<'_, CardUpdates> at crates/victory-gpu/src/shadow.rs:3103.
  • Not run yet: a game run with VICTORY_CARD_VERIFY set. Game runs with this build had it unset.
Integration test run, every test binary

Command: cargo test --profile diag -p victory -p victory-game -p victory-gpu -p victory-hle -p victory-loader -p victory-shader --features victory/diagnostics, on main 310c6eb plus about 110 open PRs merged in order (list with outcomes: integration-merge-log.tsv in the gist). PR #445 is reverted there.

test binary passed failed ignored
victory (unit) 14 0 0
victory-game 16 0 0
victory-gpu (includes tests on the real D3D12 device) 186 0 3
victory-hle 112 0 0
victory-loader unit / no_dll_planting / load_probe / title_dlls 30 / 1 / 2 / 1 0 0
victory-shader (includes the hardware shader tests, 29.9 s) 236 0 3
total 598 0 6

Full output: integration-test-all.log in https://gist.github.com/deepdev237/785e05b02d0dcece7aac1303f7fe4ba8

**@⁠deepdev237** on GitHub · 2026-11-25 04:03 UTC · [original](https://github.com/fxceless/victory-fork/pull/455#issuecomment-7152492156) · edited 2026-11-25 05:11 UTC > 🤖 **AI-generated.** This comment was written by **Claude Opus 5.5** (Anthropic, model `claude-opus-5-5`), running as an autonomous agent in **Claude Code**. The AI did the work it reports: it merged the branches, built, ran the commands, tests and game runs, and read the logs. A person asked for this testing; this text was not reviewed by them before posting. Please verify anything you rely on. <details><summary>Full test environment</summary> - OS: Windows 11 Pro, version 10.0.26300 (build 26300) - CPU: AMD Ryzen 9 5950X, 16 cores / 32 threads - RAM: 24 GB DDR4 at 2666 MT/s; page file 32 GiB on the system drive, Windows commit limit 55.92 GiB - GPU: AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32015.7029 (dated 2026-10-18); D3D12 reports host wave lanes min 32 / max 64; DXGI local video memory budget 15,419 MB; mesh shaders and shader model 6.6 available - Also installed: a virtual display adapter (Parsec Virtual Display Adapter 0.45). VIctory ran on the RX 9060 XT. - Toolchain: rustc 1.98.1 (48a229cea 2026-09-01), cargo 1.98.1 (797e8a9bc 2026-08-05), LLVM 22.1.8, host `x86_64-pc-windows-msvc` - Build: `cargo build --profile diag -p victory --features diagnostics` (`diag` = release + debug info) - Base: victory-fork `main` `310c6eb6c16822ab95076aad61fce19bba86bb98` - Game files: Series X build 1.0.2.1. This copy has zero-filled holes in 11 archives (about 338 MiB in all: `levels.rpf`, `audio.rpf`, `pack/story000/story000.rpf`, `navmeshes.rpf` and six `data/ttdb/*.ttpf`), so failures that depend on those bytes are not emulator bugs. - Full logs (local paths shortened): https://gist.github.com/deepdev237/785e05b02d0dcece7aac1303f7fe4ba8 </details> Integration note: this PR and #496 ("GPU: avoid re-uploading card data after a waited fetch") both merge onto `main` `310c6eb`, but together they do not compile: ``` error[E0599]: no method named `clone` found for struct `std::sync::MutexGuard<'_, CardUpdates>` in the current scope --> crates\victory-gpu\src\shadow.rs (Shadow::card_verify_view) ``` #496 changes `Card::dirty` from `Mutex<Vec<(usize, usize)>>` to `Mutex<CardUpdates>`, where the pending ranges are split into `upload` and `hash_only`. `card_verify_view` still does `card.dirty.lock()...clone()`. This is what I used, which leaves both kinds of pending range out of the comparison (bytes the card has not received yet, and bytes whose hash only needs refreshing): ```rust // Since #496 the pending ranges are split into uploads and hash-only // refreshes; both are left out of the comparison. let mut dirty: Vec<(usize, usize)> = { let updates = card.dirty.lock().unwrap_or_else(|e| e.into_inner()); let mut all = updates.upload.clone(); all.extend_from_slice(&updates.hash_only); all }; ``` The conflict in `Host::present` with `main` (which now takes `&Arc<HostTexture>` and moves the texture to `COPY_SOURCE` through the copy list's prelude) resolves by putting the two `card_verify::frame(self, frame)` lines at the top of `main`'s version. With both changes, the full unit and hardware test run (598 passed, 0 failed, 6 ignored) passes on `310c6eb` plus about 100 open PRs, on an RX 9060 XT (RDNA4, driver 32.0.32015.7029). I have not yet run with `VICTORY_CARD_VERIFY` set; I will add the results here when I do. <details><summary>Exact state tested</summary> - This PR's head: `4de64fd0eb52243b1a5c145e4a877a867ef06ffe`; #496's head: `b7d8c444e14f950a6afd9f5ae1e1b32765091522`. #496 was merged first, then this PR, both with `git merge --no-ff` onto the integration branch. - Merge conflict (1 hunk, 36 diff lines) in `crates/victory-gpu/src/host.rs`, `impl Host { fn present }`: `main` now has `present(&self, texture: &Arc<HostTexture>, frame: u64) -> Option<bool>` and moves the texture to `COPY_SOURCE` through the copy list's prelude under `self.submitted`. Resolved by keeping `main`'s function and adding the PR's `#[cfg(feature = "diagnostics")] card_verify::frame(self, frame);` at its start. - Compile error after the merge (before the fix above): `no method named clone found for struct std::sync::MutexGuard<'_, CardUpdates>` at `crates/victory-gpu/src/shadow.rs:3103`. - Not run yet: a game run with `VICTORY_CARD_VERIFY` set. Game runs with this build had it unset. </details> <details><summary>Integration test run, every test binary</summary> Command: `cargo test --profile diag -p victory -p victory-game -p victory-gpu -p victory-hle -p victory-loader -p victory-shader --features victory/diagnostics`, on `main` `310c6eb` plus about 110 open PRs merged in order (list with outcomes: `integration-merge-log.tsv` in the gist). PR #445 is reverted there. | test binary | passed | failed | ignored | |---|---|---|---| | `victory` (unit) | 14 | 0 | 0 | | `victory-game` | 16 | 0 | 0 | | `victory-gpu` (includes tests on the real D3D12 device) | 186 | 0 | 3 | | `victory-hle` | 112 | 0 | 0 | | `victory-loader` unit / `no_dll_planting` / `load_probe` / `title_dlls` | 30 / 1 / 2 / 1 | 0 | 0 | | `victory-shader` (includes the hardware shader tests, 29.9 s) | 236 | 0 | 3 | | **total** | **598** | **0** | **6** | Full output: `integration-test-all.log` in https://gist.github.com/deepdev237/785e05b02d0dcece7aac1303f7fe4ba8 </details>
Author
Owner

@⁠xunbreakablex on GitHub · 2026-11-25 07:27 UTC · original

Thank you for building this together with #496 and for writing down the fix. Leaving both kinds of pending range (upload and hash_only) out of the comparison is the right reading: the comparison should skip bytes the card has not received yet, and a hash-only refresh does not change the bytes. Your snippet looks correct to me, but I have not compiled it against #496.

I will not be able to follow this PR, so if you or anyone wants it, please take the diagnostic as it is and apply your adjustment (or open a PR of your own with it); if it is not wanted, closing it is fine. What is untested in game: the three-way classification (which side is newer). The two-way comparison I ran earlier is described in the PR body and in #418.

**@⁠xunbreakablex** on GitHub · 2026-11-25 07:27 UTC · [original](https://github.com/fxceless/victory-fork/pull/455#issuecomment-7155888438) Thank you for building this together with #496 and for writing down the fix. Leaving both kinds of pending range (`upload` and `hash_only`) out of the comparison is the right reading: the comparison should skip bytes the card has not received yet, and a hash-only refresh does not change the bytes. Your snippet looks correct to me, but I have not compiled it against #496. I will not be able to follow this PR, so if you or anyone wants it, please take the diagnostic as it is and apply your adjustment (or open a PR of your own with it); if it is not wanted, closing it is fine. What is untested in game: the three-way classification (which side is newer). The two-way comparison I ran earlier is described in the PR body and in #418.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/host.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/455/head:github-bot/gh-455'
git switch 'github-bot/gh-455'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-455'
git switch 'github-bot/gh-455'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-455'
git switch 'github-bot/gh-455'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-455'
git switch 'main'
git merge --squash 'github-bot/gh-455'
git switch 'main'
git merge --ff-only 'github-bot/gh-455'
git switch 'main'
git merge 'github-bot/gh-455'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.