GPU diagnostics: VICTORY_CARD_VERIFY compares card copies with their CPU side #455
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!455
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-455"
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?
@xunbreakablex on GitHub · 2026-11-25 01:02 UTC · original
xunbreakablex:card-verify-pr→main· +722 −0 · 5 files · 1 commits · openNeeds 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.mdbefore 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_MBor 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_mergeand the relay's merge exist to keep the two equal, but nothing checks that end to end, andVICTORY_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(diagnosticsbuilds only; off by default, oneOnceLockread 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. Onecard 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 thediagnosticsfeature.Tested
cargo check -p victory-gpuand--features diagnostics(--locked): cleancargo clippy -p victory-gpu --all-targets -- -D warnings, default and--all-features(as in CI): cleancargo 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 thextaskpolicy test were not run locallyVICTORY_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
1582757/#191-style changes beyond whatmainalready 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]>@deepdev237 on GitHub · 2026-11-25 04:03 UTC · original · edited 2026-11-25 05:11 UTC
Full test environment
x86_64-pc-windows-msvccargo build --profile diag -p victory --features diagnostics(diag= release + debug info)main310c6eb6c16822ab95076aad61fce19bba86bb98levels.rpf,audio.rpf,pack/story000/story000.rpf,navmeshes.rpfand sixdata/ttdb/*.ttpf), so failures that depend on those bytes are not emulator bugs.Integration note: this PR and #496 ("GPU: avoid re-uploading card data after a waited fetch") both merge onto
main310c6eb, but together they do not compile:#496 changes
Card::dirtyfromMutex<Vec<(usize, usize)>>toMutex<CardUpdates>, where the pending ranges are split intouploadandhash_only.card_verify_viewstill doescard.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):The conflict in
Host::presentwithmain(which now takes&Arc<HostTexture>and moves the texture toCOPY_SOURCEthrough the copy list's prelude) resolves by putting the twocard_verify::frame(self, frame)lines at the top ofmain's version.With both changes, the full unit and hardware test run (598 passed, 0 failed, 6 ignored) passes on
310c6ebplus about 100 open PRs, on an RX 9060 XT (RDNA4, driver 32.0.32015.7029). I have not yet run withVICTORY_CARD_VERIFYset; I will add the results here when I do.Exact state tested
4de64fd0eb52243b1a5c145e4a877a867ef06ffe; #496's head:b7d8c444e14f950a6afd9f5ae1e1b32765091522. #496 was merged first, then this PR, both withgit merge --no-ffonto the integration branch.crates/victory-gpu/src/host.rs,impl Host { fn present }:mainnow haspresent(&self, texture: &Arc<HostTexture>, frame: u64) -> Option<bool>and moves the texture toCOPY_SOURCEthrough the copy list's prelude underself.submitted. Resolved by keepingmain's function and adding the PR's#[cfg(feature = "diagnostics")] card_verify::frame(self, frame);at its start.no method named clone found for struct std::sync::MutexGuard<'_, CardUpdates>atcrates/victory-gpu/src/shadow.rs:3103.VICTORY_CARD_VERIFYset. 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, onmain310c6ebplus about 110 open PRs merged in order (list with outcomes:integration-merge-log.tsvin the gist). PR #445 is reverted there.victory(unit)victory-gamevictory-gpu(includes tests on the real D3D12 device)victory-hlevictory-loaderunit /no_dll_planting/load_probe/title_dllsvictory-shader(includes the hardware shader tests, 29.9 s)Full output:
integration-test-all.login https://gist.github.com/deepdev237/785e05b02d0dcece7aac1303f7fe4ba8@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 (
uploadandhash_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.
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.