Card hash passes after ranges go up: each piece once by default (VICTORY_CARD_REHASH_RUNS=0 as before, =1 touching pieces joined) #1298
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!1298
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@KainanP on GitHub · 2026-11-26 12:31 UTC · original
KainanP:perf/rehash-joined-default→main· +541 −33 · 2 files · 1 commits · openProblem
With
VICTORY_CARD_REHASH_RUNSunset (the default),Host::card_beforegives every range sent up to a copy in the card's memory its ownCARD_COMPAREhash pass. A 64 KiB page with thousands of changed runs, as in #1083 (up to about 16,000), gets one pass per run over the same piece. In a synthetic test that is 14–15 ms of an RTX 4060 Laptop's time for one page, and 362 ms on an Intel UHD.=1joins the passes. The fork's own diagnostic runs all set it, and #867 (item 4) proposes making it the default. But=1also joins pieces that only touch. The narrowCARD_COMPARE(the default;VICTORY_CARD_HASH_WIDEis off) gives each of a pass's pieces one thread in a single group. So 16 neighbouring pieces with one range each run as one wave instead of 16, and that is slower: 179 → 266 µs on the 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.Measurements
Synthetic
host::rehash_tests::rehash_bench, release build, onmaine4245f3(re-measured after the rebase; nine unrelated single-threaded CPU jobs were running), card time from timestamps aroundcard_before's lists, median of 15 rounds (9 on WARP). 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. Values are=0 / =1 / new default.Card time, µs:
Submitting thread (
card_before), µs, RTX: 1 × 16384 6895 / 5085 / 5171; 4 × 16384 28467 / 22618 / 22024. Small cases are within ±10 µs. Intel and WARP follow the same pattern (raw tables below).What the numbers show:
=0: on RTX and Intel, the new default is never slower beyond noise, and it is 35× (RTX) and 9× (Intel) faster on the #1083-like page. Where=0and the default record the same passes (2/4/16 × 1), the cells differ only by noise (Intel 4 × 1: 1303 / 1521).=1: the new default is never slower beyond noise on RTX and Intel, and it is faster wherever neighbouring pieces each hold few ranges.=1is ahead there on 2/4/16 × 1. WARP is not a target for play.VICTORY_CARD_HASH_WIDE=1(one group per piece;e4245f3measured it in game with=alt, card -10 ms a frame, but kept it off by default): every pass is cheaper, but the pass count is the same, so joining still pays. The new default and=1are equal within noise, and both beat=0: RTX 1 × 16384 1038 / 278 / 280 µs, Intel 50870 / 38765 / 38660 µs. The touching penalty of=1(16 × 1) is gone with this hash form. Table:Raw logs
The tables were produced by
cargo test --release -p victory-gpu --lib rehash_tests::rehash_bench -- --ignored --nocapture(REHASH_BENCH_ROUNDS=9on WARP). On WARP:--features diagnostics,VICTORY_D3D12_WARP=1,--test-threads=1. The Intel adapter was picked with a local-only adapter-selection hook (not in this PR).RTX, VICTORY_CARD_HASH_WIDE=unsetRTX, VICTORY_CARD_HASH_WIDE=1Intel, VICTORY_CARD_HASH_WIDE=unsetIntel, VICTORY_CARD_HASH_WIDE=1WARP, VICTORY_CARD_HASH_WIDE=unsetWARP, VICTORY_CARD_HASH_WIDE=1Correctness
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.The test was run on:
--features diagnostics, single-threaded): passes.VICTORY_CARD_HASH_WIDE=1: passes (the CPU model check is skipped there; the cross-way equality is not).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_piecesnow checks bothtouchingvalues.Suite and lints.
cargo test -p victory-gpu(one4245f3): 222 passed on RTX and on Intel. WARP,--features diagnostics --test-threads=1, release: 238 passed; 3profile::testsfail, and the same three fail on unmodifiedmaine4245f3in the same build (this PR does not touchprofile). The GPU test above passes again on RTX, Intel and WARP one4245f3.cargo clippy -p victory-gpu --all-targets [--features diagnostics] -- -D warnings: clean.rustfmt --checkdifferences are pre-existing neighbouring lines.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
=1shows about 457 passes over 1,169 pieces per frame. With the new default that becomes somewhere between 457 and 1,169 dispatches, each covering fewer pieces.Request for an A/B
@MKmajster, @CuteBooty (#1083): could you run your opening scene three times:
VICTORY_CARD_REHASH_RUNS=0(the old default);1?Please compare the frame log's card meter "send-and-hash lists" and the frame time. The line "our passes over copies in the card's memory per frame" shows the pass count for each way.
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
@HLVM04 on GitHub · 2026-11-26 12:56 UTC · original
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.@KainanP on GitHub · 2026-11-26 13:07 UTC · original
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
@KainanP on GitHub · 2026-11-26 13:48 UTC · original
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).
@CuteBooty on GitHub · 2026-11-26 16:00 UTC · original
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.@CuteBooty on GitHub · 2026-11-26 16:31 UTC · original
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.
08a4e9be07to2e575c2c86@KainanP on GitHub · 2026-11-26 17:15 UTC · original
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).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.