Card hash passes after ranges go up: each piece once by default (VICTORY_CARD_REHASH_RUNS=0 as before, =1 touching pieces joined) #1295
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1298"
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?
Imported from fxceless/victory-fork. Originally posted by KainanP on 2026-11-26T12:31:52Z.
Problem
With
VICTORY_CARD_REHASH_RUNSunset (the default, still onmain9a9091d),Host::card_beforegives every range sent up to a copy in the card's memory its ownCARD_COMPAREhash pass, even when many ranges lie in the same 64 KiB piece. Two sources feed that loop:VICTORY_MERGE_RUNS(4,096 by default) runs a submission, each a range of a few bytes (#1083: pages with thousands of changed runs).0e006f0(VICTORY_MASKED_PATCHon by default), a page past the cap is patched, and its runs are hashed in the same loop (w.ranges.iter().chain(w.patched)). Each run is a pass of its own.VICTORY_PATCH_LEAN(off by default) joins them by piece; its doc counts about 130,000 such runs a frame in run 362.=1joins the passes, but it also joins pieces that only touch. With the narrow hash (VICTORY_CARD_HASH_WIDE=0), that is slower: 16 touching pieces with one range each take 178 µs as 16 passes and 264 µs as one (RTX).Change
VICTORY_CARD_REHASH_RUNSnow has three ways:Rehash::Sharing1Rehash::Touching0Rehash::Apartalt1and0every 20 s (unchanged)joined_piece_runstakes atouchingflag. The frame-rate line "our passes over copies in the card's memory" names the way in use. Nothing else changes: the same pieces are hashed with the same shader and constants. Only the number of dispatches they are split into changes. Patched runs join the changed ranges' passes, so with this PR a patched page costs one pass per piece whetherVICTORY_PATCH_LEANis on or not.Measurements
Synthetic
host::rehash_tests::rehash_bench, release build, onmain9a9091d(rebased 2026-11-27). Card time comes from timestamps aroundcard_before's lists. Values are the median of 15 rounds (9 on WARP), and the three ways run in rotating order inside each round. Cases are pages × runs: runs of 2 bytes, evenly spaced, in each of the first pages 64 KiB pieces of a 1 MiB copy. Cells are=0 / =1 / new default.Card time, µs, with the default hash form (wide since
0a40a00):Submitting thread (
card_before), µs, same runs:What the numbers show:
=1, with the wide hash: the two are equal within noise on RTX and Intel. WithVICTORY_CARD_HASH_WIDE=0,=1loses where touching pieces each hold few ranges (table below). So the new default is the one that is never worse with either hash form. (WARP prefers fewer dispatches and favours=1on 2/4/16 × 1; it is not a target for play.)Card time, µs, with
VICTORY_CARD_HASH_WIDE=0(the narrow form, the default before0a40a00):Raw logs
Run with
cargo test --release -p victory-gpu --lib rehash_tests::rehash_bench -- --ignored --nocapture --test-threads=1(REHASH_BENCH_ROUNDS=9on WARP, with--features diagnosticsandVICTORY_D3D12_WARP=1). The Intel adapter was picked with a local-only adapter-selection hook (not in this PR). Three unrelated single-threaded CPU jobs were running.RTX, VICTORY_CARD_HASH_WIDE unset (wide)RTX, VICTORY_CARD_HASH_WIDE=0Intel, VICTORY_CARD_HASH_WIDE unset (wide)Intel, VICTORY_CARD_HASH_WIDE=0WARP, VICTORY_CARD_HASH_WIDE unset (wide)Correctness
host::rehash_tests::joined_rehash_leaves_the_hashes_a_pass_a_range_does(GPU,#[ignore]) sets up three copies with the same bytes, one per way. Then, for 56 random cases (1 to 5,000 runs; lengths from 1 byte to just over a piece; sorted and unsorted; overlapping; crossing piece edges), it checks:CARD_COMPARE(narrow hash), and untouched pieces keep their earlier hash.On
9a9091dit passes on the RTX 4060 Laptop, the Intel UHD and WARP (--features diagnostics, single-threaded). Pass counts over the 56 cases: 30,950 a range each, 96 touching, 386 each piece once. A mutation that drops the last piece of a joined run fails at case 1.Unit test.
piece_runs_join_without_losing_or_adding_pieceschecks bothtouchingvalues.Suite and lints (
9a9091d).cargo test -p victory-gpu --lib: 242 passed on the RTX. On the Intel UHD, 242 passed in some runs. In others,inplace::tests::warp_a_title_buffer_in_place_shows_its_bytes_at_its_offsetfails, or the parallel run crashes. Unmodifiedmaindoes the same on this machine: 3 failures and 1 crash in 8 runs, against 3 and 1 for this PR.--features diagnostics --test-threads=1, release): 259 passed. The 3profile::testsfail, and the same 3 fail on unmodifiedmain.cargo clippy -p victory-gpu --all-targets [--all-features] -- -D warnings: clean.Rebase. The only conflict was textual: the test-only
Shadow::card_put_runsandmain's newShadow::card_patchedwere added at the same spot. Both are kept.Host::card_sync_timed(test-only) is the same helper as in #1295. If both land, the second one should drop its copy.What is not measured
Request for an A/B
@MKmajster, @CuteBooty (#1083): could you run your opening scene with
VICTORY_CARD_REHASH_RUNS=0(the old default) and with it unset (this PR)? Please compare the card meter "send-and-hash lists", the frame time, and the passes line.AI use: Claude Code (Claude Opus 5.5) read the code paths, wrote the change and tests, and ran the benchmarks and test suites on the hardware above. No game data was used.
🤖 Generated with Claude Code
Imported from fxceless/victory-fork. Originally posted by HLVM04 on 2026-11-26T12:56:26Z.
One in-game data point for
=0vs=1, though on an old tree: fork9376fd6, Series X profile, RTX 5070 Ti 16 GB, Ryzen 7 9800X3D, Windows, in the world.VICTORY_CARD_REHASH_RUNS1So joining cut the passes to about a third with no frame-time change. That fits the card not being the limit there: in a timing run on the same tree the card was about 53% busy, idle behind the submitting thread. One run per arm and scene variance applies. We haven't run this PR's new default, so the
=1"touching" slowdown you measured can't be seen or ruled out from this.Imported from fxceless/victory-fork. Originally posted by KainanP on 2026-11-26T13:07:30Z.
A note on how the tables above were measured. Four unrelated CPU-bound processes were running on the machine during those runs, so the machine was not quiet. I re-ran
rehash_benchon the RTX 4060 Laptop and the Intel UHD with those processes gone. Someone else'scargobuild was still running, so the Intel run was not fully quiet either.The card times match the published ones:
The ordering is the same in every row. A few rows from the re-run (card µs,
=0/=1/ new default):None of the conclusions change.
AI use: Claude Code (Claude Opus 5.5) ran the re-measurement and wrote this note.
🤖 Generated with Claude Code
Imported from fxceless/victory-fork. Originally posted by KainanP on 2026-11-26T13:48:51Z.
Thanks @HLVM04, that's a useful data point. It matches the benchmark: with the card ~53% busy and idle behind the submitting thread, cutting hash passes (1,071 → 316) can't move the median frame on a 5070 Ti. This PR mostly helps where the card is the limit: on the Intel UHD the per-page card time drops 363 → 36.5 ms, and on the RTX 4060 Laptop 15.1 → 0.43 ms. It also saves ~1.3 ms of submitting-thread time per 16k-run page on the RTX. So on fast cards I'd expect no frame change, and on smaller cards or iGPUs the frame should move. If anyone has a lower-end card (or an iGPU) in the world, an unset vs
=0run would show that.AI use: Claude Code (Claude Opus 5.5).
Imported from fxceless/victory-fork. Originally posted by CuteBooty on 2026-11-26T16:00:37Z.
A data point from a lower-end card, though not the unset vs
=0run you asked for: on an RTX 3070 8 GB (Series S, Ryzen 5 3600, 7,000-9,000 draws) the card does not idle behind the submitting thread. The submit worker's lastExecuteCommandListsis at about 133 ms from the present call and its fence is seen at about 227 ms, so roughly 90 ms of each 236 ms frame is the card finishing, with the worker idle. Numbers and limits: https://github.com/CuteBooty/victory-8gb/issues/1#issuecomment-7197056283. I can run unset vs=0here if that still helps.Imported from fxceless/victory-fork. Originally posted by CuteBooty on 2026-11-26T16:31:53Z.
Correction to my comment above: the 90 ms tail is the long-tail case on my machine (about one sample in five); the median tail is 28-40 ms, and the title's own phase after the present returns is usually the longer part. Details: https://github.com/CuteBooty/victory-8gb/issues/1#issuecomment-7197766362.
Imported from fxceless/victory-fork. Originally posted by KainanP on 2026-11-26T17:15:54Z.
Rebased on
maine4245f3(now2e575c2). It applied cleanly and builds unchanged.Does
e4245f3supersede it? No.VICTORY_CARD_HASH_WIDE=1|alt, still off by default). This PR chooses how many hash passescard_beforerecords after ranges go up.VICTORY_CARD_REHASH_RUNSis untouched onmain, so the default is still a pass per range.VICTORY_DIRTY_4Knarrows only the CPU refresh of write-watched pages, not the ranges sent to the card.Re-measured on
e4245f3(median of 15 rounds, 9 on WARP). The description's tables are updated, and theVICTORY_CARD_HASH_WIDE=1table is new. Card time on the #1083-like page (1 × 16,384),=0 / =1 / new default, µs:VICTORY_CARD_HASH_WIDE=1So the wide hash and this PR stack. With the wide hash,
=1's touching penalty (16 × 1) goes away, and the new default is never worse than=1.The GPU test passes again on RTX, Intel and WARP.
cargo test -p victory-gpu: 222 passed on RTX and on Intel. On WARP (diagnostics, serial), 3profile::testsfail, and the same 3 fail on unmodifiede4245f3. clippy-D warningsis clean with and without--all-features.Note for whoever merges: #1295 adds the same test-only helper
Host::card_sync_timed. Whichever of the two lands second should drop its copy.AI use: Claude Code (Claude Opus 5.5).
Imported from fxceless/victory-fork. Originally posted by KainanP on 2026-11-27T11:32:53Z.
Rebased on
main9a9091d(nowc89462c). The only conflict was textual: the test-onlycard_put_runsand the newcard_patchedwere added at the same spot, and both are kept.Is it still useful with the wide hash and the masked patch on by default? Yes, though the gain is smaller.
VICTORY_CARD_REHASH_RUNSis still one hash pass per range. The masked patch's runs now go through the same loop (chain(w.patched)), so they also cost a pass each unlessVICTORY_PATCH_LEANis on. With this PR, each piece is hashed once.=1. With the wide hash,=1and the new default are equal. WithVICTORY_CARD_HASH_WIDE=0,=1still loses on touching pieces, so I kept "share a piece" as the default.The GPU hash test passes on RTX, Intel and WARP. The victory-gpu lib suite matches
main, including the known Intelinplaceflake and the 3 WARPprofilefailures. clippy-D warningsis clean with and without--all-features. The description has new tables, including one withVICTORY_CARD_HASH_WIDE=0.AI use: Claude Code (Claude Opus 5.5).
Imported from fxceless/victory-fork. Originally posted by KainanP on 2026-11-27T15:35:26Z.
Closing this:
main5dbf5ce(the VIctory-NVIDIA tree) already hashes each piece once by default, by another route.VICTORY_SEND_OWN),card_beforejoins the runs whether or notVICTORY_CARD_REHASH_RUNSis set:let joins = rehash_runs() || own.is_some();.CARD_COMPAREnow gives each piece a group of its own. So joining pieces that only touch no longer costs the extra card time that made this PR choose "sharing" over "touching" as the default.I checked it on the RTX 4060 Laptop. I ported this PR's GPU test (
joined_rehash_leaves_the_hashes_a_pass_a_range_does, 56 random cases, a 16 MiB copy) onto5dbf5ce. With the variable unset, the default path took exactly the same number of passes as=1(for example, 1,000 runs → 4 passes and 5,000 runs → 1 pass). Its hashes matched the CPU model for every piece that was touched. A port would therefore only add the "sharing" way, which takes more passes than main's default here. Thanks for the reviews and the in-game data on this one.AI use: Claude Code (Claude Opus 5.5).
Pull request closed