Card hash passes after ranges go up: each piece once by default (VICTORY_CARD_REHASH_RUNS=0 as before, =1 touching pieces joined) #1295

Closed
KainanP wants to merge 1 commit from upstream-pr/1298 into main
KainanP commented 2026-11-26 12:31:52 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by KainanP on 2026-11-26T12:31:52Z.


Problem

With VICTORY_CARD_REHASH_RUNS unset (the default, still on main 9a9091d), Host::card_before gives every range sent up to a copy in the card's memory its own CARD_COMPARE hash pass, even when many ranges lie in the same 64 KiB piece. Two sources feed that loop:

  • Changed ranges. Up to VICTORY_MERGE_RUNS (4,096 by default) runs a submission, each a range of a few bytes (#1083: pages with thousands of changed runs).
  • The masked patch's runs. Since 0e006f0 (VICTORY_MASKED_PATCH on 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.

=1 joins 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_RUNS now has three ways:

value passes
unset (new default) runs that share a piece are one pass: each piece is hashed once Rehash::Sharing
1 runs that share or touch a piece are one pass (unchanged) Rehash::Touching
0 one pass per range or patched run (the old default) Rehash::Apart
alt alternates 1 and 0 every 20 s (unchanged)

joined_piece_runs takes a touching flag. 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 whether VICTORY_PATCH_LEAN is on or not.

Measurements

Synthetic host::rehash_tests::rehash_bench, release build, on main 9a9091d (rebased 2026-11-27). Card time comes from timestamps around card_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):

pages × runs hash passes RTX 4060 Laptop Intel UHD (8086:a78b) WARP
1 × 1 1 / 1 / 1 25 / 25 / 25 84 / 84 / 83 57 / 55 / 55
1 × 16 16 / 1 / 1 25 / 25 / 26 90 / 90 / 89 195 / 63 / 60
1 × 256 256 / 1 / 1 40 / 30 / 32 712 / 555 / 558 1,311 / 159 / 154
1 × 4096 4096 / 1 / 1 273 / 84 / 85 11,230 / 7,925 / 8,028 16,370 / 1,267 / 1,250
1 × 16384 16384 / 1 / 1 1,033 / 270 / 270 49,782 / 37,348 / 37,597 67,496 / 5,222 / 4,902
4 × 16384 65536 / 1 / 4 4,020 / 981 / 982 203,200 / 155,426 / 155,440 265,875 / 23,982 / 25,242
2 × 1 2 / 1 / 2 26 / 26 / 26 67 / 66 / 66 150 / 105 / 153
4 × 1 4 / 1 / 4 26 / 25 / 25 71 / 70 / 71 175 / 130 / 138
16 × 1 16 / 1 / 16 26 / 26 / 26 98 / 98 / 98 210 / 158 / 209
16 × 16 256 / 1 / 16 43 / 31 / 30 762 / 589 / 595 1,367 / 293 / 331
16 × 256 4096 / 1 / 16 276 / 87 / 88 11,773 / 8,697 / 8,924 19,056 / 2,169 / 2,807

Submitting thread (card_before), µs, same runs:

pages × runs hash passes RTX 4060 Laptop Intel UHD WARP
1 × 1 1 / 1 / 1 31 / 30 / 29 21 / 20 / 20 12 / 12 / 11
1 × 16 16 / 1 / 1 35 / 34 / 37 31 / 31 / 31 27 / 16 / 16
1 × 256 256 / 1 / 1 115 / 96 / 97 157 / 148 / 146 291 / 81 / 78
1 × 4096 4096 / 1 / 1 1,365 / 1,044 / 1,065 2,418 / 2,379 / 2,450 7,860 / 1,213 / 1,074
1 × 16384 16384 / 1 / 1 5,289 / 4,086 / 4,000 9,520 / 9,991 / 9,355 51,104 / 4,900 / 4,194
4 × 16384 65536 / 1 / 4 21,084 / 16,361 / 16,173 53,012 / 41,468 / 42,973 320,328 / 35,225 / 20,846
2 × 1 2 / 1 / 2 30 / 29 / 30 42 / 42 / 39 25 / 24 / 26
4 × 1 4 / 1 / 4 29 / 29 / 32 42 / 40 / 43 26 / 22 / 22
16 × 1 16 / 1 / 16 35 / 34 / 36 55 / 53 / 56 31 / 20 / 32
16 × 16 256 / 1 / 16 115 / 94 / 99 202 / 188 / 174 303 / 87 / 99
16 × 256 4096 / 1 / 16 1,346 / 1,031 / 1,036 2,382 / 2,501 / 2,556 10,182 / 1,915 / 1,946

What the numbers show:

  • The wide hash shrinks the gain, but does not remove it. On the #1083-like page (1 × 16,384), the RTX goes from 1,033 to 270 µs of card time, and the submitting thread from 5.3 to 4.0 ms. At the merge cap (1 × 4,096), the RTX goes from 273 to 85 µs and from 1.36 to 1.06 ms. On Intel, card time goes from 49.8 to 37.6 ms (−25%). On WARP the gain is 10× or more.
  • Per pass saved, on the RTX: about 0.047 µs of card time and 0.08 µs of the submitting thread. Applied to the ~130,000 patch runs a frame of run 362, that would be about 6 ms of card time and 10 ms of the submitting thread per frame. That is an extrapolation, not a measurement.
  • Against =1, with the wide hash: the two are equal within noise on RTX and Intel. With VICTORY_CARD_HASH_WIDE=0, =1 loses 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 =1 on 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 before 0a40a00):

pages × runs hash passes RTX 4060 Laptop Intel UHD
1 × 1 1 / 1 / 1 194 / 192 / 194 1,025 / 1,025 / 1,024
1 × 16 16 / 1 / 1 199 / 194 / 193 1,059 / 1,052 / 1,055
1 × 256 256 / 1 / 1 362 / 200 / 198 5,981 / 1,535 / 1,527
1 × 4096 4096 / 1 / 1 3,954 / 252 / 253 90,859 / 10,237 / 9,977
1 × 16384 16384 / 1 / 1 13,649 / 423 / 433 363,737 / 39,017 / 39,080
4 × 16384 65536 / 1 / 4 54,577 / 1,207 / 1,098 1,462,822 / 156,260 / 155,933
2 × 1 2 / 1 / 2 173 / 180 / 177 1,027 / 1,035 / 1,028
4 × 1 4 / 1 / 4 178 / 204 / 177 1,097 / 1,119 / 1,100
16 × 1 16 / 1 / 16 177 / 264 / 178 1,162 / 1,245 / 1,161
16 × 16 256 / 1 / 16 362 / 268 / 181 6,753 / 1,857 / 1,734
16 × 256 4096 / 1 / 16 4,272 / 325 / 234 90,791 / 10,339 / 9,948
Raw logs

Run with cargo test --release -p victory-gpu --lib rehash_tests::rehash_bench -- --ignored --nocapture --test-threads=1 (REHASH_BENCH_ROUNDS=9 on WARP, with --features diagnostics and VICTORY_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)

rehash_bench: median of 15 rounds; VICTORY_CARD_HASH_WIDE=unset
pages x runs way ranges sent hash passes submitting thread (us) card (us)
1 x 1 a pass a range (=0) 1 1 31.1 24.6
1 x 1 touching joined (=1) 1 1 30.3 24.6
1 x 1 each piece once (default) 1 1 28.9 24.6
1 x 16 a pass a range (=0) 16 16 35.2 24.7
1 x 16 touching joined (=1) 16 1 33.8 24.6
1 x 16 each piece once (default) 16 1 36.7 25.6
1 x 256 a pass a range (=0) 256 256 115.2 39.9
1 x 256 touching joined (=1) 256 1 95.6 29.7
1 x 256 each piece once (default) 256 1 96.7 31.7
1 x 4096 a pass a range (=0) 4096 4096 1364.7 273.4
1 x 4096 touching joined (=1) 4096 1 1043.9 84.0
1 x 4096 each piece once (default) 4096 1 1064.7 85.0
1 x 16384 a pass a range (=0) 16384 16384 5288.9 1033.2
1 x 16384 touching joined (=1) 16384 1 4085.8 270.3
1 x 16384 each piece once (default) 16384 1 3999.5 270.3
4 x 16384 a pass a range (=0) 65536 65536 21083.5 4020.2
4 x 16384 touching joined (=1) 65536 1 16361.0 981.0
4 x 16384 each piece once (default) 65536 4 16173.0 982.0
2 x 1 a pass a range (=0) 2 2 30.0 25.6
2 x 1 touching joined (=1) 2 1 29.2 25.6
2 x 1 each piece once (default) 2 2 29.9 25.6
4 x 1 a pass a range (=0) 4 4 29.1 25.6
4 x 1 touching joined (=1) 4 1 28.9 24.9
4 x 1 each piece once (default) 4 4 31.7 24.7
16 x 1 a pass a range (=0) 16 16 34.8 25.6
16 x 1 touching joined (=1) 16 1 33.5 25.6
16 x 1 each piece once (default) 16 16 36.1 25.6
16 x 16 a pass a range (=0) 256 256 115.4 43.1
16 x 16 touching joined (=1) 256 1 94.2 30.7
16 x 16 each piece once (default) 256 16 99.1 29.8
16 x 256 a pass a range (=0) 4096 4096 1346.2 276.5
16 x 256 touching joined (=1) 4096 1 1031.2 87.0
16 x 256 each piece once (default) 4096 16 1035.6 88.1

RTX, VICTORY_CARD_HASH_WIDE=0

rehash_bench: median of 15 rounds; VICTORY_CARD_HASH_WIDE=0
pages x runs way ranges sent hash passes submitting thread (us) card (us)
1 x 1 a pass a range (=0) 1 1 29.3 193.5
1 x 1 touching joined (=1) 1 1 29.5 191.7
1 x 1 each piece once (default) 1 1 28.3 193.5
1 x 16 a pass a range (=0) 16 16 34.3 198.7
1 x 16 touching joined (=1) 16 1 34.8 193.5
1 x 16 each piece once (default) 16 1 33.8 192.7
1 x 256 a pass a range (=0) 256 256 118.1 362.5
1 x 256 touching joined (=1) 256 1 95.7 199.7
1 x 256 each piece once (default) 256 1 95.8 197.6
1 x 4096 a pass a range (=0) 4096 4096 1344.9 3953.7
1 x 4096 touching joined (=1) 4096 1 1029.6 251.9
1 x 4096 each piece once (default) 4096 1 1046.8 252.9
1 x 16384 a pass a range (=0) 16384 16384 5300.2 13649.2
1 x 16384 touching joined (=1) 16384 1 4001.4 423.2
1 x 16384 each piece once (default) 16384 1 4049.1 433.1
4 x 16384 a pass a range (=0) 65536 65536 21131.9 54577.2
4 x 16384 touching joined (=1) 65536 1 16882.7 1207.3
4 x 16384 each piece once (default) 65536 4 16615.8 1097.7
2 x 1 a pass a range (=0) 2 2 28.6 173.1
2 x 1 touching joined (=1) 2 1 30.0 179.6
2 x 1 each piece once (default) 2 2 32.2 177.2
4 x 1 a pass a range (=0) 4 4 27.0 178.2
4 x 1 touching joined (=1) 4 1 26.8 204.1
4 x 1 each piece once (default) 4 4 28.3 177.2
16 x 1 a pass a range (=0) 16 16 32.5 177.2
16 x 1 touching joined (=1) 16 1 29.5 264.2
16 x 1 each piece once (default) 16 16 32.5 178.2
16 x 16 a pass a range (=0) 256 256 114.9 362.5
16 x 16 touching joined (=1) 256 1 94.2 268.3
16 x 16 each piece once (default) 256 16 94.7 181.2
16 x 256 a pass a range (=0) 4096 4096 1482.4 4272.1
16 x 256 touching joined (=1) 4096 1 1069.3 324.6
16 x 256 each piece once (default) 4096 16 1072.9 233.5

Intel, VICTORY_CARD_HASH_WIDE unset (wide)

rehash_bench: median of 15 rounds; VICTORY_CARD_HASH_WIDE=unset
pages x runs way ranges sent hash passes submitting thread (us) card (us)
1 x 1 a pass a range (=0) 1 1 21.1 83.8
1 x 1 touching joined (=1) 1 1 20.2 83.9
1 x 1 each piece once (default) 1 1 19.8 83.0
1 x 16 a pass a range (=0) 16 16 31.0 89.6
1 x 16 touching joined (=1) 16 1 30.9 89.5
1 x 16 each piece once (default) 16 1 31.4 89.4
1 x 256 a pass a range (=0) 256 256 156.6 712.3
1 x 256 touching joined (=1) 256 1 147.7 554.6
1 x 256 each piece once (default) 256 1 146.1 557.6
1 x 4096 a pass a range (=0) 4096 4096 2417.9 11230.4
1 x 4096 touching joined (=1) 4096 1 2378.9 7925.4
1 x 4096 each piece once (default) 4096 1 2450.0 8027.9
1 x 16384 a pass a range (=0) 16384 16384 9520.1 49782.3
1 x 16384 touching joined (=1) 16384 1 9990.7 37348.5
1 x 16384 each piece once (default) 16384 1 9355.1 37596.7
4 x 16384 a pass a range (=0) 65536 65536 53011.7 203200.1
4 x 16384 touching joined (=1) 65536 1 41467.9 155425.5
4 x 16384 each piece once (default) 65536 4 42973.3 155440.2
2 x 1 a pass a range (=0) 2 2 42.1 66.6
2 x 1 touching joined (=1) 2 1 42.2 66.4
2 x 1 each piece once (default) 2 2 39.1 66.4
4 x 1 a pass a range (=0) 4 4 42.4 70.8
4 x 1 touching joined (=1) 4 1 40.5 70.5
4 x 1 each piece once (default) 4 4 42.7 70.6
16 x 1 a pass a range (=0) 16 16 54.9 98.3
16 x 1 touching joined (=1) 16 1 53.1 97.8
16 x 1 each piece once (default) 16 16 55.6 97.8
16 x 16 a pass a range (=0) 256 256 202.3 761.5
16 x 16 touching joined (=1) 256 1 187.9 588.6
16 x 16 each piece once (default) 256 16 173.7 595.4
16 x 256 a pass a range (=0) 4096 4096 2381.8 11772.7
16 x 256 touching joined (=1) 4096 1 2501.4 8697.1
16 x 256 each piece once (default) 4096 16 2556.1 8923.6

Intel, VICTORY_CARD_HASH_WIDE=0

rehash_bench: median of 15 rounds; VICTORY_CARD_HASH_WIDE=0
pages x runs way ranges sent hash passes submitting thread (us) card (us)
1 x 1 a pass a range (=0) 1 1 21.9 1024.6
1 x 1 touching joined (=1) 1 1 21.9 1025.4
1 x 1 each piece once (default) 1 1 21.6 1024.5
1 x 16 a pass a range (=0) 16 16 33.6 1059.4
1 x 16 touching joined (=1) 16 1 33.5 1051.8
1 x 16 each piece once (default) 16 1 32.6 1055.2
1 x 256 a pass a range (=0) 256 256 160.6 5981.2
1 x 256 touching joined (=1) 256 1 154.9 1534.6
1 x 256 each piece once (default) 256 1 153.9 1526.9
1 x 4096 a pass a range (=0) 4096 4096 2342.8 90859.1
1 x 4096 touching joined (=1) 4096 1 2126.0 10237.0
1 x 4096 each piece once (default) 4096 1 2333.7 9977.0
1 x 16384 a pass a range (=0) 16384 16384 9391.4 363737.3
1 x 16384 touching joined (=1) 16384 1 9251.9 39017.2
1 x 16384 each piece once (default) 16384 1 9570.5 39079.8
4 x 16384 a pass a range (=0) 65536 65536 40083.8 1462821.8
4 x 16384 touching joined (=1) 65536 1 40691.9 156260.1
4 x 16384 each piece once (default) 65536 4 42850.5 155933.0
2 x 1 a pass a range (=0) 2 2 34.3 1027.4
2 x 1 touching joined (=1) 2 1 34.8 1035.1
2 x 1 each piece once (default) 2 2 34.4 1027.6
4 x 1 a pass a range (=0) 4 4 37.1 1097.4
4 x 1 touching joined (=1) 4 1 37.1 1119.0
4 x 1 each piece once (default) 4 4 36.3 1100.0
16 x 1 a pass a range (=0) 16 16 45.5 1161.9
16 x 1 touching joined (=1) 16 1 43.7 1244.7
16 x 1 each piece once (default) 16 16 46.5 1160.7
16 x 16 a pass a range (=0) 256 256 222.9 6753.2
16 x 16 touching joined (=1) 256 1 254.7 1857.1
16 x 16 each piece once (default) 256 16 276.4 1733.6
16 x 256 a pass a range (=0) 4096 4096 2941.6 90790.7
16 x 256 touching joined (=1) 4096 1 3046.6 10339.2
16 x 256 each piece once (default) 4096 16 3009.0 9947.7

WARP, VICTORY_CARD_HASH_WIDE unset (wide)

rehash_bench: median of 9 rounds; VICTORY_CARD_HASH_WIDE=unset
pages x runs way ranges sent hash passes submitting thread (us) card (us)
1 x 1 a pass a range (=0) 1 1 11.5 56.6
1 x 1 touching joined (=1) 1 1 11.5 55.3
1 x 1 each piece once (default) 1 1 11.4 55.2
1 x 16 a pass a range (=0) 16 16 26.7 195.3
1 x 16 touching joined (=1) 16 1 16.1 62.8
1 x 16 each piece once (default) 16 1 16.0 60.3
1 x 256 a pass a range (=0) 256 256 291.3 1311.4
1 x 256 touching joined (=1) 256 1 80.8 159.1
1 x 256 each piece once (default) 256 1 78.4 154.1
1 x 4096 a pass a range (=0) 4096 4096 7860.4 16370.4
1 x 4096 touching joined (=1) 4096 1 1213.4 1267.3
1 x 4096 each piece once (default) 4096 1 1074.1 1249.5
1 x 16384 a pass a range (=0) 16384 16384 51104.5 67495.8
1 x 16384 touching joined (=1) 16384 1 4900.2 5221.7
1 x 16384 each piece once (default) 16384 1 4194.1 4901.8
4 x 16384 a pass a range (=0) 65536 65536 320328.5 265875.3
4 x 16384 touching joined (=1) 65536 1 35225.3 23982.5
4 x 16384 each piece once (default) 65536 4 20846.4 25242.2
2 x 1 a pass a range (=0) 2 2 25.4 150.3
2 x 1 touching joined (=1) 2 1 24.2 104.7
2 x 1 each piece once (default) 2 2 26.0 153.3
4 x 1 a pass a range (=0) 4 4 25.5 175.3
4 x 1 touching joined (=1) 4 1 22.3 130.2
4 x 1 each piece once (default) 4 4 21.6 137.5
16 x 1 a pass a range (=0) 16 16 30.8 209.6
16 x 1 touching joined (=1) 16 1 20.0 157.6
16 x 1 each piece once (default) 16 16 31.6 209.2
16 x 16 a pass a range (=0) 256 256 303.3 1366.6
16 x 16 touching joined (=1) 256 1 87.1 292.9
16 x 16 each piece once (default) 256 16 99.2 330.9
16 x 256 a pass a range (=0) 4096 4096 10181.9 19056.5
16 x 256 touching joined (=1) 4096 1 1915.4 2169.2
16 x 256 each piece once (default) 4096 16 1946.0 2807.2

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:

  • the card side equals the title bytes, and all three copies hold the same bytes;
  • the 16-byte piece hashes are identical across the three ways;
  • touched pieces equal a CPU model of CARD_COMPARE (narrow hash), and untouched pieces keep their earlier hash.

On 9a9091d it 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_pieces checks both touching values.

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_offset fails, or the parallel run crashes. Unmodified main does the same on this machine: 3 failures and 1 crash in 8 runs, against 3 and 1 for this PR.
  • WARP (--features diagnostics --test-threads=1, release): 259 passed. The 3 profile::tests fail, and the same 3 fail on unmodified main.
  • cargo clippy -p victory-gpu --all-targets [--all-features] -- -D warnings: clean.
  • rustfmt: clean on the lines this PR adds or changes.

Rebase. The only conflict was textual: the test-only Shadow::card_put_runs and main's new Shadow::card_patched were 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

  • In-game. I have no game here, so there is no frame time.
  • The game's range mix. How runs and patched runs are spread over pieces in a real frame is not known. The frame line "our passes over copies in the card's memory" gives passes and pieces per frame for each way.
  • Discrete card only. Card times cover the hash passes and copies alone, on a laptop RTX. The UHD keeps the card side in shared memory.

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

<!-- greyfinch-sync:fxceless/victory-fork:issue:5510069238 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1298). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-26T12:31:52Z. --- ## Problem With `VICTORY_CARD_REHASH_RUNS` unset (the default, still on `main` 9a9091d), `Host::card_before` gives every range sent up to a copy in the card's memory its own `CARD_COMPARE` hash pass, even when many ranges lie in the same 64 KiB piece. Two sources feed that loop: - **Changed ranges.** Up to `VICTORY_MERGE_RUNS` (4,096 by default) runs a submission, each a range of a few bytes (#1083: pages with thousands of changed runs). - **The masked patch's runs.** Since 0e006f0 (`VICTORY_MASKED_PATCH` on 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. `=1` joins 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_RUNS` now has three ways: | value | passes | | |---|---|---| | unset (**new default**) | runs that **share** a piece are one pass: each piece is hashed once | `Rehash::Sharing` | | `1` | runs that share **or touch** a piece are one pass (unchanged) | `Rehash::Touching` | | `0` | one pass per range or patched run (the old default) | `Rehash::Apart` | | `alt` | alternates `1` and `0` every 20 s (unchanged) | | `joined_piece_runs` takes a `touching` flag. 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 whether `VICTORY_PATCH_LEAN` is on or not. ## Measurements Synthetic `host::rehash_tests::rehash_bench`, release build, on `main` 9a9091d (rebased 2026-11-27). Card time comes from timestamps around `card_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):** | pages × runs | hash passes | RTX 4060 Laptop | Intel UHD (8086:a78b) | WARP | |---|---|---|---|---| | 1 × 1 | 1 / 1 / 1 | 25 / 25 / 25 | 84 / 84 / 83 | 57 / 55 / 55 | | 1 × 16 | 16 / 1 / 1 | 25 / 25 / 26 | 90 / 90 / 89 | 195 / 63 / 60 | | 1 × 256 | 256 / 1 / 1 | 40 / 30 / 32 | 712 / 555 / 558 | 1,311 / 159 / 154 | | 1 × 4096 | 4096 / 1 / 1 | 273 / 84 / 85 | 11,230 / 7,925 / 8,028 | 16,370 / 1,267 / 1,250 | | 1 × 16384 | 16384 / 1 / 1 | 1,033 / 270 / 270 | 49,782 / 37,348 / 37,597 | 67,496 / 5,222 / 4,902 | | 4 × 16384 | 65536 / 1 / 4 | 4,020 / 981 / 982 | 203,200 / 155,426 / 155,440 | 265,875 / 23,982 / 25,242 | | 2 × 1 | 2 / 1 / 2 | 26 / 26 / 26 | 67 / 66 / 66 | 150 / 105 / 153 | | 4 × 1 | 4 / 1 / 4 | 26 / 25 / 25 | 71 / 70 / 71 | 175 / 130 / 138 | | 16 × 1 | 16 / 1 / 16 | 26 / 26 / 26 | 98 / 98 / 98 | 210 / 158 / 209 | | 16 × 16 | 256 / 1 / 16 | 43 / 31 / 30 | 762 / 589 / 595 | 1,367 / 293 / 331 | | 16 × 256 | 4096 / 1 / 16 | 276 / 87 / 88 | 11,773 / 8,697 / 8,924 | 19,056 / 2,169 / 2,807 | **Submitting thread (`card_before`), µs, same runs:** | pages × runs | hash passes | RTX 4060 Laptop | Intel UHD | WARP | |---|---|---|---|---| | 1 × 1 | 1 / 1 / 1 | 31 / 30 / 29 | 21 / 20 / 20 | 12 / 12 / 11 | | 1 × 16 | 16 / 1 / 1 | 35 / 34 / 37 | 31 / 31 / 31 | 27 / 16 / 16 | | 1 × 256 | 256 / 1 / 1 | 115 / 96 / 97 | 157 / 148 / 146 | 291 / 81 / 78 | | 1 × 4096 | 4096 / 1 / 1 | 1,365 / 1,044 / 1,065 | 2,418 / 2,379 / 2,450 | 7,860 / 1,213 / 1,074 | | 1 × 16384 | 16384 / 1 / 1 | 5,289 / 4,086 / 4,000 | 9,520 / 9,991 / 9,355 | 51,104 / 4,900 / 4,194 | | 4 × 16384 | 65536 / 1 / 4 | 21,084 / 16,361 / 16,173 | 53,012 / 41,468 / 42,973 | 320,328 / 35,225 / 20,846 | | 2 × 1 | 2 / 1 / 2 | 30 / 29 / 30 | 42 / 42 / 39 | 25 / 24 / 26 | | 4 × 1 | 4 / 1 / 4 | 29 / 29 / 32 | 42 / 40 / 43 | 26 / 22 / 22 | | 16 × 1 | 16 / 1 / 16 | 35 / 34 / 36 | 55 / 53 / 56 | 31 / 20 / 32 | | 16 × 16 | 256 / 1 / 16 | 115 / 94 / 99 | 202 / 188 / 174 | 303 / 87 / 99 | | 16 × 256 | 4096 / 1 / 16 | 1,346 / 1,031 / 1,036 | 2,382 / 2,501 / 2,556 | 10,182 / 1,915 / 1,946 | What the numbers show: - **The wide hash shrinks the gain, but does not remove it.** On the #1083-like page (1 × 16,384), the RTX goes from 1,033 to 270 µs of card time, and the submitting thread from 5.3 to 4.0 ms. At the merge cap (1 × 4,096), the RTX goes from 273 to 85 µs and from 1.36 to 1.06 ms. On Intel, card time goes from 49.8 to 37.6 ms (−25%). On WARP the gain is 10× or more. - **Per pass saved**, on the RTX: about 0.047 µs of card time and 0.08 µs of the submitting thread. Applied to the ~130,000 patch runs a frame of run 362, that would be about 6 ms of card time and 10 ms of the submitting thread per frame. That is an extrapolation, not a measurement. - **Against `=1`**, with the wide hash: the two are equal within noise on RTX and Intel. With `VICTORY_CARD_HASH_WIDE=0`, `=1` loses 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 `=1` on 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 before 0a40a00): | pages × runs | hash passes | RTX 4060 Laptop | Intel UHD | |---|---|---|---| | 1 × 1 | 1 / 1 / 1 | 194 / 192 / 194 | 1,025 / 1,025 / 1,024 | | 1 × 16 | 16 / 1 / 1 | 199 / 194 / 193 | 1,059 / 1,052 / 1,055 | | 1 × 256 | 256 / 1 / 1 | 362 / 200 / 198 | 5,981 / 1,535 / 1,527 | | 1 × 4096 | 4096 / 1 / 1 | 3,954 / 252 / 253 | 90,859 / 10,237 / 9,977 | | 1 × 16384 | 16384 / 1 / 1 | 13,649 / 423 / 433 | 363,737 / 39,017 / 39,080 | | 4 × 16384 | 65536 / 1 / 4 | 54,577 / 1,207 / 1,098 | 1,462,822 / 156,260 / 155,933 | | 2 × 1 | 2 / 1 / 2 | 173 / 180 / 177 | 1,027 / 1,035 / 1,028 | | 4 × 1 | 4 / 1 / 4 | 178 / 204 / 177 | 1,097 / 1,119 / 1,100 | | 16 × 1 | 16 / 1 / 16 | 177 / 264 / 178 | 1,162 / 1,245 / 1,161 | | 16 × 16 | 256 / 1 / 16 | 362 / 268 / 181 | 6,753 / 1,857 / 1,734 | | 16 × 256 | 4096 / 1 / 16 | 4,272 / 325 / 234 | 90,791 / 10,339 / 9,948 | <details><summary>Raw logs</summary> Run with `cargo test --release -p victory-gpu --lib rehash_tests::rehash_bench -- --ignored --nocapture --test-threads=1` (`REHASH_BENCH_ROUNDS=9` on WARP, with `--features diagnostics` and `VICTORY_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)` rehash_bench: median of 15 rounds; VICTORY_CARD_HASH_WIDE=unset | pages x runs | way | ranges sent | hash passes | submitting thread (us) | card (us) | |---|---|---:|---:|---:|---:| | 1 x 1 | a pass a range (=0) | 1 | 1 | 31.1 | 24.6 | | 1 x 1 | touching joined (=1) | 1 | 1 | 30.3 | 24.6 | | 1 x 1 | each piece once (default) | 1 | 1 | 28.9 | 24.6 | | 1 x 16 | a pass a range (=0) | 16 | 16 | 35.2 | 24.7 | | 1 x 16 | touching joined (=1) | 16 | 1 | 33.8 | 24.6 | | 1 x 16 | each piece once (default) | 16 | 1 | 36.7 | 25.6 | | 1 x 256 | a pass a range (=0) | 256 | 256 | 115.2 | 39.9 | | 1 x 256 | touching joined (=1) | 256 | 1 | 95.6 | 29.7 | | 1 x 256 | each piece once (default) | 256 | 1 | 96.7 | 31.7 | | 1 x 4096 | a pass a range (=0) | 4096 | 4096 | 1364.7 | 273.4 | | 1 x 4096 | touching joined (=1) | 4096 | 1 | 1043.9 | 84.0 | | 1 x 4096 | each piece once (default) | 4096 | 1 | 1064.7 | 85.0 | | 1 x 16384 | a pass a range (=0) | 16384 | 16384 | 5288.9 | 1033.2 | | 1 x 16384 | touching joined (=1) | 16384 | 1 | 4085.8 | 270.3 | | 1 x 16384 | each piece once (default) | 16384 | 1 | 3999.5 | 270.3 | | 4 x 16384 | a pass a range (=0) | 65536 | 65536 | 21083.5 | 4020.2 | | 4 x 16384 | touching joined (=1) | 65536 | 1 | 16361.0 | 981.0 | | 4 x 16384 | each piece once (default) | 65536 | 4 | 16173.0 | 982.0 | | 2 x 1 | a pass a range (=0) | 2 | 2 | 30.0 | 25.6 | | 2 x 1 | touching joined (=1) | 2 | 1 | 29.2 | 25.6 | | 2 x 1 | each piece once (default) | 2 | 2 | 29.9 | 25.6 | | 4 x 1 | a pass a range (=0) | 4 | 4 | 29.1 | 25.6 | | 4 x 1 | touching joined (=1) | 4 | 1 | 28.9 | 24.9 | | 4 x 1 | each piece once (default) | 4 | 4 | 31.7 | 24.7 | | 16 x 1 | a pass a range (=0) | 16 | 16 | 34.8 | 25.6 | | 16 x 1 | touching joined (=1) | 16 | 1 | 33.5 | 25.6 | | 16 x 1 | each piece once (default) | 16 | 16 | 36.1 | 25.6 | | 16 x 16 | a pass a range (=0) | 256 | 256 | 115.4 | 43.1 | | 16 x 16 | touching joined (=1) | 256 | 1 | 94.2 | 30.7 | | 16 x 16 | each piece once (default) | 256 | 16 | 99.1 | 29.8 | | 16 x 256 | a pass a range (=0) | 4096 | 4096 | 1346.2 | 276.5 | | 16 x 256 | touching joined (=1) | 4096 | 1 | 1031.2 | 87.0 | | 16 x 256 | each piece once (default) | 4096 | 16 | 1035.6 | 88.1 | `RTX, VICTORY_CARD_HASH_WIDE=0` rehash_bench: median of 15 rounds; VICTORY_CARD_HASH_WIDE=0 | pages x runs | way | ranges sent | hash passes | submitting thread (us) | card (us) | |---|---|---:|---:|---:|---:| | 1 x 1 | a pass a range (=0) | 1 | 1 | 29.3 | 193.5 | | 1 x 1 | touching joined (=1) | 1 | 1 | 29.5 | 191.7 | | 1 x 1 | each piece once (default) | 1 | 1 | 28.3 | 193.5 | | 1 x 16 | a pass a range (=0) | 16 | 16 | 34.3 | 198.7 | | 1 x 16 | touching joined (=1) | 16 | 1 | 34.8 | 193.5 | | 1 x 16 | each piece once (default) | 16 | 1 | 33.8 | 192.7 | | 1 x 256 | a pass a range (=0) | 256 | 256 | 118.1 | 362.5 | | 1 x 256 | touching joined (=1) | 256 | 1 | 95.7 | 199.7 | | 1 x 256 | each piece once (default) | 256 | 1 | 95.8 | 197.6 | | 1 x 4096 | a pass a range (=0) | 4096 | 4096 | 1344.9 | 3953.7 | | 1 x 4096 | touching joined (=1) | 4096 | 1 | 1029.6 | 251.9 | | 1 x 4096 | each piece once (default) | 4096 | 1 | 1046.8 | 252.9 | | 1 x 16384 | a pass a range (=0) | 16384 | 16384 | 5300.2 | 13649.2 | | 1 x 16384 | touching joined (=1) | 16384 | 1 | 4001.4 | 423.2 | | 1 x 16384 | each piece once (default) | 16384 | 1 | 4049.1 | 433.1 | | 4 x 16384 | a pass a range (=0) | 65536 | 65536 | 21131.9 | 54577.2 | | 4 x 16384 | touching joined (=1) | 65536 | 1 | 16882.7 | 1207.3 | | 4 x 16384 | each piece once (default) | 65536 | 4 | 16615.8 | 1097.7 | | 2 x 1 | a pass a range (=0) | 2 | 2 | 28.6 | 173.1 | | 2 x 1 | touching joined (=1) | 2 | 1 | 30.0 | 179.6 | | 2 x 1 | each piece once (default) | 2 | 2 | 32.2 | 177.2 | | 4 x 1 | a pass a range (=0) | 4 | 4 | 27.0 | 178.2 | | 4 x 1 | touching joined (=1) | 4 | 1 | 26.8 | 204.1 | | 4 x 1 | each piece once (default) | 4 | 4 | 28.3 | 177.2 | | 16 x 1 | a pass a range (=0) | 16 | 16 | 32.5 | 177.2 | | 16 x 1 | touching joined (=1) | 16 | 1 | 29.5 | 264.2 | | 16 x 1 | each piece once (default) | 16 | 16 | 32.5 | 178.2 | | 16 x 16 | a pass a range (=0) | 256 | 256 | 114.9 | 362.5 | | 16 x 16 | touching joined (=1) | 256 | 1 | 94.2 | 268.3 | | 16 x 16 | each piece once (default) | 256 | 16 | 94.7 | 181.2 | | 16 x 256 | a pass a range (=0) | 4096 | 4096 | 1482.4 | 4272.1 | | 16 x 256 | touching joined (=1) | 4096 | 1 | 1069.3 | 324.6 | | 16 x 256 | each piece once (default) | 4096 | 16 | 1072.9 | 233.5 | `Intel, VICTORY_CARD_HASH_WIDE unset (wide)` rehash_bench: median of 15 rounds; VICTORY_CARD_HASH_WIDE=unset | pages x runs | way | ranges sent | hash passes | submitting thread (us) | card (us) | |---|---|---:|---:|---:|---:| | 1 x 1 | a pass a range (=0) | 1 | 1 | 21.1 | 83.8 | | 1 x 1 | touching joined (=1) | 1 | 1 | 20.2 | 83.9 | | 1 x 1 | each piece once (default) | 1 | 1 | 19.8 | 83.0 | | 1 x 16 | a pass a range (=0) | 16 | 16 | 31.0 | 89.6 | | 1 x 16 | touching joined (=1) | 16 | 1 | 30.9 | 89.5 | | 1 x 16 | each piece once (default) | 16 | 1 | 31.4 | 89.4 | | 1 x 256 | a pass a range (=0) | 256 | 256 | 156.6 | 712.3 | | 1 x 256 | touching joined (=1) | 256 | 1 | 147.7 | 554.6 | | 1 x 256 | each piece once (default) | 256 | 1 | 146.1 | 557.6 | | 1 x 4096 | a pass a range (=0) | 4096 | 4096 | 2417.9 | 11230.4 | | 1 x 4096 | touching joined (=1) | 4096 | 1 | 2378.9 | 7925.4 | | 1 x 4096 | each piece once (default) | 4096 | 1 | 2450.0 | 8027.9 | | 1 x 16384 | a pass a range (=0) | 16384 | 16384 | 9520.1 | 49782.3 | | 1 x 16384 | touching joined (=1) | 16384 | 1 | 9990.7 | 37348.5 | | 1 x 16384 | each piece once (default) | 16384 | 1 | 9355.1 | 37596.7 | | 4 x 16384 | a pass a range (=0) | 65536 | 65536 | 53011.7 | 203200.1 | | 4 x 16384 | touching joined (=1) | 65536 | 1 | 41467.9 | 155425.5 | | 4 x 16384 | each piece once (default) | 65536 | 4 | 42973.3 | 155440.2 | | 2 x 1 | a pass a range (=0) | 2 | 2 | 42.1 | 66.6 | | 2 x 1 | touching joined (=1) | 2 | 1 | 42.2 | 66.4 | | 2 x 1 | each piece once (default) | 2 | 2 | 39.1 | 66.4 | | 4 x 1 | a pass a range (=0) | 4 | 4 | 42.4 | 70.8 | | 4 x 1 | touching joined (=1) | 4 | 1 | 40.5 | 70.5 | | 4 x 1 | each piece once (default) | 4 | 4 | 42.7 | 70.6 | | 16 x 1 | a pass a range (=0) | 16 | 16 | 54.9 | 98.3 | | 16 x 1 | touching joined (=1) | 16 | 1 | 53.1 | 97.8 | | 16 x 1 | each piece once (default) | 16 | 16 | 55.6 | 97.8 | | 16 x 16 | a pass a range (=0) | 256 | 256 | 202.3 | 761.5 | | 16 x 16 | touching joined (=1) | 256 | 1 | 187.9 | 588.6 | | 16 x 16 | each piece once (default) | 256 | 16 | 173.7 | 595.4 | | 16 x 256 | a pass a range (=0) | 4096 | 4096 | 2381.8 | 11772.7 | | 16 x 256 | touching joined (=1) | 4096 | 1 | 2501.4 | 8697.1 | | 16 x 256 | each piece once (default) | 4096 | 16 | 2556.1 | 8923.6 | `Intel, VICTORY_CARD_HASH_WIDE=0` rehash_bench: median of 15 rounds; VICTORY_CARD_HASH_WIDE=0 | pages x runs | way | ranges sent | hash passes | submitting thread (us) | card (us) | |---|---|---:|---:|---:|---:| | 1 x 1 | a pass a range (=0) | 1 | 1 | 21.9 | 1024.6 | | 1 x 1 | touching joined (=1) | 1 | 1 | 21.9 | 1025.4 | | 1 x 1 | each piece once (default) | 1 | 1 | 21.6 | 1024.5 | | 1 x 16 | a pass a range (=0) | 16 | 16 | 33.6 | 1059.4 | | 1 x 16 | touching joined (=1) | 16 | 1 | 33.5 | 1051.8 | | 1 x 16 | each piece once (default) | 16 | 1 | 32.6 | 1055.2 | | 1 x 256 | a pass a range (=0) | 256 | 256 | 160.6 | 5981.2 | | 1 x 256 | touching joined (=1) | 256 | 1 | 154.9 | 1534.6 | | 1 x 256 | each piece once (default) | 256 | 1 | 153.9 | 1526.9 | | 1 x 4096 | a pass a range (=0) | 4096 | 4096 | 2342.8 | 90859.1 | | 1 x 4096 | touching joined (=1) | 4096 | 1 | 2126.0 | 10237.0 | | 1 x 4096 | each piece once (default) | 4096 | 1 | 2333.7 | 9977.0 | | 1 x 16384 | a pass a range (=0) | 16384 | 16384 | 9391.4 | 363737.3 | | 1 x 16384 | touching joined (=1) | 16384 | 1 | 9251.9 | 39017.2 | | 1 x 16384 | each piece once (default) | 16384 | 1 | 9570.5 | 39079.8 | | 4 x 16384 | a pass a range (=0) | 65536 | 65536 | 40083.8 | 1462821.8 | | 4 x 16384 | touching joined (=1) | 65536 | 1 | 40691.9 | 156260.1 | | 4 x 16384 | each piece once (default) | 65536 | 4 | 42850.5 | 155933.0 | | 2 x 1 | a pass a range (=0) | 2 | 2 | 34.3 | 1027.4 | | 2 x 1 | touching joined (=1) | 2 | 1 | 34.8 | 1035.1 | | 2 x 1 | each piece once (default) | 2 | 2 | 34.4 | 1027.6 | | 4 x 1 | a pass a range (=0) | 4 | 4 | 37.1 | 1097.4 | | 4 x 1 | touching joined (=1) | 4 | 1 | 37.1 | 1119.0 | | 4 x 1 | each piece once (default) | 4 | 4 | 36.3 | 1100.0 | | 16 x 1 | a pass a range (=0) | 16 | 16 | 45.5 | 1161.9 | | 16 x 1 | touching joined (=1) | 16 | 1 | 43.7 | 1244.7 | | 16 x 1 | each piece once (default) | 16 | 16 | 46.5 | 1160.7 | | 16 x 16 | a pass a range (=0) | 256 | 256 | 222.9 | 6753.2 | | 16 x 16 | touching joined (=1) | 256 | 1 | 254.7 | 1857.1 | | 16 x 16 | each piece once (default) | 256 | 16 | 276.4 | 1733.6 | | 16 x 256 | a pass a range (=0) | 4096 | 4096 | 2941.6 | 90790.7 | | 16 x 256 | touching joined (=1) | 4096 | 1 | 3046.6 | 10339.2 | | 16 x 256 | each piece once (default) | 4096 | 16 | 3009.0 | 9947.7 | `WARP, VICTORY_CARD_HASH_WIDE unset (wide)` rehash_bench: median of 9 rounds; VICTORY_CARD_HASH_WIDE=unset | pages x runs | way | ranges sent | hash passes | submitting thread (us) | card (us) | |---|---|---:|---:|---:|---:| | 1 x 1 | a pass a range (=0) | 1 | 1 | 11.5 | 56.6 | | 1 x 1 | touching joined (=1) | 1 | 1 | 11.5 | 55.3 | | 1 x 1 | each piece once (default) | 1 | 1 | 11.4 | 55.2 | | 1 x 16 | a pass a range (=0) | 16 | 16 | 26.7 | 195.3 | | 1 x 16 | touching joined (=1) | 16 | 1 | 16.1 | 62.8 | | 1 x 16 | each piece once (default) | 16 | 1 | 16.0 | 60.3 | | 1 x 256 | a pass a range (=0) | 256 | 256 | 291.3 | 1311.4 | | 1 x 256 | touching joined (=1) | 256 | 1 | 80.8 | 159.1 | | 1 x 256 | each piece once (default) | 256 | 1 | 78.4 | 154.1 | | 1 x 4096 | a pass a range (=0) | 4096 | 4096 | 7860.4 | 16370.4 | | 1 x 4096 | touching joined (=1) | 4096 | 1 | 1213.4 | 1267.3 | | 1 x 4096 | each piece once (default) | 4096 | 1 | 1074.1 | 1249.5 | | 1 x 16384 | a pass a range (=0) | 16384 | 16384 | 51104.5 | 67495.8 | | 1 x 16384 | touching joined (=1) | 16384 | 1 | 4900.2 | 5221.7 | | 1 x 16384 | each piece once (default) | 16384 | 1 | 4194.1 | 4901.8 | | 4 x 16384 | a pass a range (=0) | 65536 | 65536 | 320328.5 | 265875.3 | | 4 x 16384 | touching joined (=1) | 65536 | 1 | 35225.3 | 23982.5 | | 4 x 16384 | each piece once (default) | 65536 | 4 | 20846.4 | 25242.2 | | 2 x 1 | a pass a range (=0) | 2 | 2 | 25.4 | 150.3 | | 2 x 1 | touching joined (=1) | 2 | 1 | 24.2 | 104.7 | | 2 x 1 | each piece once (default) | 2 | 2 | 26.0 | 153.3 | | 4 x 1 | a pass a range (=0) | 4 | 4 | 25.5 | 175.3 | | 4 x 1 | touching joined (=1) | 4 | 1 | 22.3 | 130.2 | | 4 x 1 | each piece once (default) | 4 | 4 | 21.6 | 137.5 | | 16 x 1 | a pass a range (=0) | 16 | 16 | 30.8 | 209.6 | | 16 x 1 | touching joined (=1) | 16 | 1 | 20.0 | 157.6 | | 16 x 1 | each piece once (default) | 16 | 16 | 31.6 | 209.2 | | 16 x 16 | a pass a range (=0) | 256 | 256 | 303.3 | 1366.6 | | 16 x 16 | touching joined (=1) | 256 | 1 | 87.1 | 292.9 | | 16 x 16 | each piece once (default) | 256 | 16 | 99.2 | 330.9 | | 16 x 256 | a pass a range (=0) | 4096 | 4096 | 10181.9 | 19056.5 | | 16 x 256 | touching joined (=1) | 4096 | 1 | 1915.4 | 2169.2 | | 16 x 256 | each piece once (default) | 4096 | 16 | 1946.0 | 2807.2 | </details> ## 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: - the card side equals the title bytes, and all three copies hold the same bytes; - **the 16-byte piece hashes are identical across the three ways**; - touched pieces equal a CPU model of `CARD_COMPARE` (narrow hash), and untouched pieces keep their earlier hash. On 9a9091d it 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_pieces` checks both `touching` values. **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_offset` fails, or the parallel run crashes. Unmodified `main` does the same on this machine: 3 failures and 1 crash in 8 runs, against 3 and 1 for this PR. - WARP (`--features diagnostics --test-threads=1`, release): 259 passed. The 3 `profile::tests` fail, and the same 3 fail on unmodified `main`. - `cargo clippy -p victory-gpu --all-targets [--all-features] -- -D warnings`: clean. - rustfmt: clean on the lines this PR adds or changes. **Rebase.** The only conflict was textual: the test-only `Shadow::card_put_runs` and `main`'s new `Shadow::card_patched` were 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 - **In-game.** I have no game here, so there is no frame time. - **The game's range mix.** How runs and patched runs are spread over pieces in a real frame is not known. The frame line "our passes over copies in the card's memory" gives passes and pieces per frame for each way. - **Discrete card only.** Card times cover the hash passes and copies alone, on a laptop RTX. The UHD keeps the card side in shared memory. ## 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](https://claude.com/claude-code)
HLVM04 commented 2026-11-26 13:05:53 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by HLVM04 on 2026-11-26T12:56:26Z.


One in-game data point for =0 vs =1, though on an old tree: fork 9376fd6, Series X profile, RTX 5070 Ti 16 GB, Ryzen 7 9800X3D, Windows, in the world.

VICTORY_CARD_REHASH_RUNS hash passes a frame median frame
unset (one pass a range, the old default) 1,071 258 ms
1 316 264 ms

So 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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7192660054 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1298#issuecomment-7192660054). Originally posted by [HLVM04](https://github.com/HLVM04) on 2026-11-26T12:56:26Z. --- One in-game data point for `=0` vs `=1`, though on an old tree: fork 9376fd6, Series X profile, RTX 5070 Ti 16 GB, Ryzen 7 9800X3D, Windows, in the world. | `VICTORY_CARD_REHASH_RUNS` | hash passes a frame | median frame | |---|---|---| | unset (one pass a range, the old default) | 1,071 | 258 ms | | `1` | 316 | 264 ms | So 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 commented 2026-11-26 14:03:29 +00:00 (Migrated from github.com)

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_bench on the RTX 4060 Laptop and the Intel UHD with those processes gone. Someone else's cargo build was still running, so the Intel run was not fully quiet either.

The card times match the published ones:

  • RTX: within 0–6 % per row.
  • Intel UHD: within 1–11 % per row, and each re-run row is a little slower.

The ordering is the same in every row. A few rows from the re-run (card µs, =0 / =1 / new default):

pages × runs RTX re-run Intel re-run
1 × 16384 14235 / 420 / 414 364833 / 39286 / 39131
16 × 1 179 / 267 / 179 1219 / 1364 / 1217
16 × 16 365 / 271 / 183 7245 / 2111 / 1940
16 × 256 4303 / 325 / 235 91373 / 10587 / 10490

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

<!-- greyfinch-sync:fxceless/victory-fork:comment:7192908209 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1298#issuecomment-7192908209). Originally posted by [KainanP](https://github.com/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_bench` on the RTX 4060 Laptop and the Intel UHD with those processes gone. Someone else's `cargo` build was still running, so the Intel run was not fully quiet either. The card times match the published ones: - RTX: within 0–6 % per row. - Intel UHD: within 1–11 % per row, and each re-run row is a little slower. The ordering is the same in every row. A few rows from the re-run (card µs, `=0` / `=1` / new default): | pages × runs | RTX re-run | Intel re-run | |---|---|---| | 1 × 16384 | 14235 / 420 / 414 | 364833 / 39286 / 39131 | | 16 × 1 | 179 / 267 / 179 | 1219 / 1364 / 1217 | | 16 × 16 | 365 / 271 / 183 | 7245 / 2111 / 1940 | | 16 × 256 | 4303 / 325 / 235 | 91373 / 10587 / 10490 | 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](https://claude.com/claude-code)
KainanP commented 2026-11-26 14:03:31 +00:00 (Migrated from github.com)

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 =0 run would show that.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7193873396 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1298#issuecomment-7193873396). Originally posted by [KainanP](https://github.com/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 `=0` run would show that. _AI use: Claude Code (Claude Opus 5.5)._
CuteBooty commented 2026-11-26 16:06:38 +00:00 (Migrated from github.com)

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 =0 run 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 last ExecuteCommandLists is 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 =0 here if that still helps.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7197056652 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1298#issuecomment-7197056652). Originally posted by [CuteBooty](https://github.com/CuteBooty) on 2026-11-26T16:00:37Z. --- A data point from a lower-end card, though not the unset vs `=0` run 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 last `ExecuteCommandLists` is 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 `=0` here if that still helps.
CuteBooty commented 2026-11-26 16:31:53 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7197766738 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1298#issuecomment-7197766738). Originally posted by [CuteBooty](https://github.com/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.
KainanP commented 2026-11-26 17:15:54 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by KainanP on 2026-11-26T17:15:54Z.


Rebased on main e4245f3 (now 2e575c2). It applied cleanly and builds unchanged.

Does e4245f3 supersede it? No.

  • e4245f3's "card hashing a group of threads a piece" chooses how each piece is hashed (VICTORY_CARD_HASH_WIDE=1|alt, still off by default). This PR chooses how many hash passes card_before records after ranges go up.
  • VICTORY_CARD_REHASH_RUNS is untouched on main, so the default is still a pass per range.
  • VICTORY_DIRTY_4K narrows 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 the VICTORY_CARD_HASH_WIDE=1 table is new. Card time on the #1083-like page (1 × 16,384), =0 / =1 / new default, µs:

hash form RTX Intel UHD
default (a thread a piece) 13,674 / 398 / 396 364,119 / 40,130 / 39,944
VICTORY_CARD_HASH_WIDE=1 1,038 / 278 / 280 50,870 / 38,765 / 38,660

So 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), 3 profile::tests fail, and the same 3 fail on unmodified e4245f3. clippy -D warnings is 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).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7198739216 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1298#issuecomment-7198739216). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-26T17:15:54Z. --- Rebased on `main` e4245f3 (now 2e575c2). It applied cleanly and builds unchanged. **Does e4245f3 supersede it? No.** - e4245f3's "card hashing a group of threads a piece" chooses *how* each piece is hashed (`VICTORY_CARD_HASH_WIDE=1|alt`, still off by default). This PR chooses *how many* hash passes `card_before` records after ranges go up. - `VICTORY_CARD_REHASH_RUNS` is untouched on `main`, so the default is still a pass per range. - `VICTORY_DIRTY_4K` narrows 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 the `VICTORY_CARD_HASH_WIDE=1` table is new. Card time on the #1083-like page (1 × 16,384), `=0 / =1 / new default`, µs: | hash form | RTX | Intel UHD | |---|---|---| | default (a thread a piece) | 13,674 / 398 / 396 | 364,119 / 40,130 / 39,944 | | `VICTORY_CARD_HASH_WIDE=1` | 1,038 / 278 / 280 | 50,870 / 38,765 / 38,660 | So 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), 3 `profile::tests` fail, and the same 3 fail on unmodified e4245f3. clippy `-D warnings` is 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)._
KainanP commented 2026-11-27 11:32:53 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by KainanP on 2026-11-27T11:32:53Z.


Rebased on main 9a9091d (now c89462c). The only conflict was textual: the test-only card_put_runs and the new card_patched were 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.

  • Pass count. The default VICTORY_CARD_REHASH_RUNS is 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 unless VICTORY_PATCH_LEAN is on. With this PR, each piece is hashed once.
  • Pass cost. The wide hash makes each pass about 13× cheaper on the RTX. Joining still pays: card 1,033 → 270 µs on the #1083-like page (1 × 16,384), and the submitting thread 5.3 → 4.0 ms. At the 4,096-run cap: 273 → 85 µs and 1.36 → 1.06 ms. On the Intel UHD, card time goes from 49.8 to 37.6 ms.
  • Sharing vs =1. With the wide hash, =1 and the new default are equal. With VICTORY_CARD_HASH_WIDE=0, =1 still 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 Intel inplace flake and the 3 WARP profile failures. clippy -D warnings is clean with and without --all-features. The description has new tables, including one with VICTORY_CARD_HASH_WIDE=0.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7217200123 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1298#issuecomment-7217200123). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-27T11:32:53Z. --- Rebased on `main` 9a9091d (now c89462c). The only conflict was textual: the test-only `card_put_runs` and the new `card_patched` were 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.** - **Pass count.** The default `VICTORY_CARD_REHASH_RUNS` is 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 unless `VICTORY_PATCH_LEAN` is on. With this PR, each piece is hashed once. - **Pass cost.** The wide hash makes each pass about 13× cheaper on the RTX. Joining still pays: card 1,033 → 270 µs on the #1083-like page (1 × 16,384), and the submitting thread 5.3 → 4.0 ms. At the 4,096-run cap: 273 → 85 µs and 1.36 → 1.06 ms. On the Intel UHD, card time goes from 49.8 to 37.6 ms. - **Sharing vs `=1`.** With the wide hash, `=1` and the new default are equal. With `VICTORY_CARD_HASH_WIDE=0`, `=1` still 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 Intel `inplace` flake and the 3 WARP `profile` failures. clippy `-D warnings` is clean with and without `--all-features`. The description has new tables, including one with `VICTORY_CARD_HASH_WIDE=0`. _AI use: Claude Code (Claude Opus 5.5)._
KainanP commented 2026-11-27 15:35:26 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by KainanP on 2026-11-27T15:35:26Z.


Closing this: main 5dbf5ce (the VIctory-NVIDIA tree) already hashes each piece once by default, by another route.

  • With our own sends on, which is the default (VICTORY_SEND_OWN), card_before joins the runs whether or not VICTORY_CARD_REHASH_RUNS is set: let joins = rehash_runs() || own.is_some();.
  • CARD_COMPARE now 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) onto 5dbf5ce. 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).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7222242076 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1298#issuecomment-7222242076). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-27T15:35:26Z. --- Closing this: `main` 5dbf5ce (the VIctory-NVIDIA tree) already hashes each piece once by default, by another route. - With our own sends on, which is the default ([`VICTORY_SEND_OWN`](https://github.com/fxceless/victory-fork/blob/5dbf5ce226690bb0f1b2949dc8ef822617ae81ea/crates/victory-gpu/src/host/send.rs#L25-L28)), `card_before` joins the runs whether or not `VICTORY_CARD_REHASH_RUNS` is set: [`let joins = rehash_runs() || own.is_some();`](https://github.com/fxceless/victory-fork/blob/5dbf5ce226690bb0f1b2949dc8ef822617ae81ea/crates/victory-gpu/src/host.rs#L4529). - [`CARD_COMPARE`](https://github.com/fxceless/victory-fork/blob/5dbf5ce226690bb0f1b2949dc8ef822617ae81ea/crates/victory-gpu/src/host.rs#L2125-L2137) now 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) onto 5dbf5ce. 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

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!1295
No description provided.