Skip to content

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

Open
xunbreakablex wants to merge 1 commit into
fxceless:mainfrom
xunbreakablex:card-verify-pr
Open

xunbreakablex wants to merge 1 commit into
fxceless:mainfrom
xunbreakablex:card-verify-pr

Conversation

@xunbreakablex

Copy link
Copy Markdown

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: RTX 4070 12 GB + Ryzen 5 5600: steady-state world 361 → 263 ms/frame with CARD_BUFFERS_MIN_MB=1 on RELAY=1 (313 → 285 on RELAY=2); page faults 66k → 0.5k #418.

Not tested

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

…CPU side

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 <noreply@anthropic.com>
RecompLive pushed a commit to RecompLive/victory-fork that referenced this pull request Nov 25, 2026
Windows command lines quote only with double quotes. split_args treated an apostrophe as a quote too, so -name=O'Brien swallowed the following argument. Only toggle on ", and add the apostrophe case to the relaunch test (review note on fxceless#455).
RecompLive pushed a commit to RecompLive/victory-fork that referenced this pull request Nov 25, 2026
HLE: honor the requested executable on relaunch
@deepdev237

deepdev237 commented Nov 25, 2026 •

Copy link
Copy Markdown

🤖 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; GPU: avoid re-uploading card data after a waited fetch #496's head: b7d8c444e14f950a6afd9f5ae1e1b32765091522. GPU: avoid re-uploading card data after a waited fetch #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

oceansde012 pushed a commit to oceansde012/victory-gta6 that referenced this pull request Nov 25, 2026
HLE: honor the requested executable on relaunch
(cherry picked from commit e686512)
coderanonymus pushed a commit to coderanonymus/victory-fork that referenced this pull request Nov 25, 2026
Windows command lines quote only with double quotes. split_args treated an apostrophe as a quote too, so -name=O'Brien swallowed the following argument. Only toggle on ", and add the apostrophe case to the relaunch test (review note on fxceless#455).

(cherry picked from commit eb8067f)
@xunbreakablex

Copy link
Copy Markdown
Author

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.

e4glevlr pushed a commit to e4glevlr/victory-fork that referenced this pull request Nov 25, 2026
Windows command lines quote only with double quotes. split_args treated an apostrophe as a quote too, so -name=O'Brien swallowed the following argument. Only toggle on ", and add the apostrophe case to the relaunch test (review note on fxceless#455).

(cherry picked from commit eb8067f)
(cherry picked from commit c94adc0)
wolfattack199 pushed a commit to wolfattack199/victory-fork that referenced this pull request Nov 25, 2026
Windows command lines quote only with double quotes. split_args treated an apostrophe as a quote too, so -name=O'Brien swallowed the following argument. Only toggle on ", and add the apostrophe case to the relaunch test (review note on fxceless#455).

(cherry picked from commit eb8067f)
PiloteCode pushed a commit to PiloteCode/victory-fork that referenced this pull request Nov 25, 2026
Windows command lines quote only with double quotes. split_args treated an apostrophe as a quote too, so -name=O'Brien swallowed the following argument. Only toggle on ", and add the apostrophe case to the relaunch test (review note on fxceless#455).

(cherry picked from commit eb8067f)
tuffn3ss pushed a commit to tuffn3ss/victory-plus that referenced this pull request Nov 26, 2026
Windows command lines quote only with double quotes. split_args treated an apostrophe as a quote too, so -name=O'Brien swallowed the following argument. Only toggle on ", and add the apostrophe case to the relaunch test (review note on fxceless#455).

(cherry picked from commit eb8067f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants