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

Open
github-bot wants to merge 1 commit from github-bot/gh-1298 into main AGit
Owner

@⁠KainanP on GitHub · 2026-11-26 12:31 UTC · original
KainanP:perf/rehash-joined-default → main · +541 −33 · 2 files · 1 commits · open

Problem

With VICTORY_CARD_REHASH_RUNS unset (the default), Host::card_before gives every range sent up to a copy in the card's memory its own CARD_COMPARE hash 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.

=1 joins the passes. The fork's own diagnostic runs all set it, and #867 (item 4) proposes making it the default. But =1 also joins pieces that only touch. The narrow CARD_COMPARE (the default; VICTORY_CARD_HASH_WIDE is 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_RUNS now has three ways:

value passes
unset (new default) runs of pieces 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 sent up (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.

Measurements

Synthetic host::rehash_tests::rehash_bench, release build, on main e4245f3 (re-measured after the rebase; nine unrelated single-threaded CPU jobs were running), card time from timestamps around card_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:

pages × runs hash passes RTX 4060 Laptop Intel UHD (8086:a78b) WARP
1 × 1 1 / 1 / 1 197 / 201 / 196 1,077 / 1,083 / 1,083 172 / 212 / 246
1 × 16 16 / 1 / 1 202 / 199 / 199 1,133 / 1,120 / 1,116 622 / 166 / 181
1 × 256 256 / 1 / 1 365 / 204 / 203 6,088 / 1,657 / 1,647 3,559 / 341 / 318
1 × 4096 4096 / 1 / 1 3,929 / 236 / 235 91,473 / 10,849 / 10,869 46,694 / 2,996 / 2,786
1 × 16384 16384 / 1 / 1 13,674 / 398 / 396 364,119 / 40,130 / 39,944 177,754 / 12,216 / 12,037
4 × 16384 65536 / 1 / 4 60,668 / 1,237 / 1,172 1,458,592 / 158,642 / 157,685 726,443 / 49,618 / 52,764
2 × 1 2 / 1 / 2 180 / 186 / 179 1,116 / 1,131 / 1,112 520 / 276 / 521
4 × 1 4 / 1 / 4 180 / 209 / 188 1,303 / 1,362 / 1,521 495 / 270 / 479
16 × 1 16 / 1 / 16 187 / 272 / 182 1,830 / 2,108 / 1,821 656 / 848 / 690
16 × 16 256 / 1 / 16 373 / 278 / 185 7,462 / 2,093 / 1,923 3,667 / 1,056 / 848
16 × 256 4096 / 1 / 16 4,296 / 324 / 236 91,781 / 11,188 / 10,965 47,137 / 3,470 / 3,589

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:

  • Against =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 =0 and the default record the same passes (2/4/16 × 1), the cells differ only by noise (Intel 4 × 1: 1303 / 1521).
  • Against =1: the new default is never slower beyond noise on RTX and Intel, and it is faster wherever neighbouring pieces each hold few ranges.
  • WARP: it prefers fewer dispatches, so =1 is ahead there on 2/4/16 × 1. WARP is not a target for play.
  • VICTORY_CARD_HASH_WIDE=1 (one group per piece; e4245f3 measured 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 =1 are 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:
pages × runs hash passes RTX 4060 Laptop Intel UHD (8086:a78b) WARP
1 × 1 1 / 1 / 1 29 / 27 / 30 73 / 70 / 74 77 / 79 / 68
1 × 16 16 / 1 / 1 34 / 26 / 34 203 / 199 / 201 267 / 88 / 92
1 × 256 256 / 1 / 1 43 / 34 / 33 1,092 / 834 / 837 1,535 / 231 / 212
1 × 4096 4096 / 1 / 1 282 / 93 / 94 12,650 / 9,643 / 9,616 19,902 / 2,588 / 2,663
1 × 16384 16384 / 1 / 1 1,038 / 278 / 280 50,870 / 38,765 / 38,660 81,930 / 10,539 / 10,048
4 × 16384 65536 / 1 / 4 4,226 / 965 / 982 205,182 / 154,577 / 154,682 348,779 / 49,472 / 43,466
2 × 1 2 / 1 / 2 28 / 28 / 27 71 / 73 / 71 170 / 121 / 181
4 × 1 4 / 1 / 4 27 / 28 / 28 92 / 85 / 76 216 / 154 / 213
16 × 1 16 / 1 / 16 28 / 29 / 28 113 / 114 / 117 260 / 214 / 275
16 × 16 256 / 1 / 16 45 / 33 / 34 850 / 632 / 638 1,806 / 483 / 550
16 × 256 4096 / 1 / 16 278 / 116 / 88 14,882 / 11,153 / 11,169 20,726 / 3,458 / 3,436
Raw logs

The tables were produced by cargo test --release -p victory-gpu --lib rehash_tests::rehash_bench -- --ignored --nocapture (REHASH_BENCH_ROUNDS=9 on 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=unset

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 39.0 196.6
1 x 1 touching joined (=1) 1 1 36.8 200.7
1 x 1 each piece once (default) 1 1 41.7 195.7
1 x 16 a pass a range (=0) 16 16 50.0 201.9
1 x 16 touching joined (=1) 16 1 49.7 198.7
1 x 16 each piece once (default) 16 1 46.4 198.7
1 x 256 a pass a range (=0) 256 256 156.0 364.7
1 x 256 touching joined (=1) 256 1 131.2 203.8
1 x 256 each piece once (default) 256 1 127.8 203.0
1 x 4096 a pass a range (=0) 4096 4096 1761.8 3929.1
1 x 4096 touching joined (=1) 4096 1 1347.3 235.5
1 x 4096 each piece once (default) 4096 1 1338.0 234.8
1 x 16384 a pass a range (=0) 16384 16384 6894.8 13673.7
1 x 16384 touching joined (=1) 16384 1 5085.4 398.3
1 x 16384 each piece once (default) 16384 1 5170.7 396.5
4 x 16384 a pass a range (=0) 65536 65536 28467.3 60668.0
4 x 16384 touching joined (=1) 65536 1 22617.9 1237.0
4 x 16384 each piece once (default) 65536 4 22024.0 1171.5
2 x 1 a pass a range (=0) 2 2 62.8 180.2
2 x 1 touching joined (=1) 2 1 55.3 185.5
2 x 1 each piece once (default) 2 2 61.4 179.2
4 x 1 a pass a range (=0) 4 4 59.9 180.2
4 x 1 touching joined (=1) 4 1 62.1 209.2
4 x 1 each piece once (default) 4 4 63.6 188.4
16 x 1 a pass a range (=0) 16 16 71.2 186.7
16 x 1 touching joined (=1) 16 1 63.8 272.5
16 x 1 each piece once (default) 16 16 70.7 181.5
16 x 16 a pass a range (=0) 256 256 213.2 373.1
16 x 16 touching joined (=1) 256 1 179.3 277.5
16 x 16 each piece once (default) 256 16 189.8 185.3
16 x 256 a pass a range (=0) 4096 4096 2657.1 4295.7
16 x 256 touching joined (=1) 4096 1 1870.0 323.6
16 x 256 each piece once (default) 4096 16 1974.1 235.6

RTX, VICTORY_CARD_HASH_WIDE=1

rehash_bench: median of 15 rounds; VICTORY_CARD_HASH_WIDE=1
pages x runs way ranges sent hash passes submitting thread (us) card (us)
1 x 1 a pass a range (=0) 1 1 39.1 28.7
1 x 1 touching joined (=1) 1 1 36.6 26.6
1 x 1 each piece once (default) 1 1 36.7 29.7
1 x 16 a pass a range (=0) 16 16 45.1 33.9
1 x 16 touching joined (=1) 16 1 47.0 25.8
1 x 16 each piece once (default) 16 1 47.7 34.0
1 x 256 a pass a range (=0) 256 256 147.6 43.0
1 x 256 touching joined (=1) 256 1 123.1 33.8
1 x 256 each piece once (default) 256 1 124.0 32.9
1 x 4096 a pass a range (=0) 4096 4096 1906.9 281.6
1 x 4096 touching joined (=1) 4096 1 1535.6 93.2
1 x 4096 each piece once (default) 4096 1 1492.2 94.2
1 x 16384 a pass a range (=0) 16384 16384 6564.6 1038.3
1 x 16384 touching joined (=1) 16384 1 5247.6 277.5
1 x 16384 each piece once (default) 16384 1 5184.4 279.6
4 x 16384 a pass a range (=0) 65536 65536 27920.7 4226.0
4 x 16384 touching joined (=1) 65536 1 21515.1 964.6
4 x 16384 each piece once (default) 65536 4 21330.0 982.1
2 x 1 a pass a range (=0) 2 2 35.2 27.6
2 x 1 touching joined (=1) 2 1 35.8 27.7
2 x 1 each piece once (default) 2 2 35.1 26.6
4 x 1 a pass a range (=0) 4 4 34.5 26.7
4 x 1 touching joined (=1) 4 1 34.9 27.9
4 x 1 each piece once (default) 4 4 35.9 27.6
16 x 1 a pass a range (=0) 16 16 41.1 27.6
16 x 1 touching joined (=1) 16 1 39.9 28.7
16 x 1 each piece once (default) 16 16 41.9 27.8
16 x 16 a pass a range (=0) 256 256 144.3 45.1
16 x 16 touching joined (=1) 256 1 115.9 32.8
16 x 16 each piece once (default) 256 16 119.5 33.8
16 x 256 a pass a range (=0) 4096 4096 1752.7 277.5
16 x 256 touching joined (=1) 4096 1 1314.0 115.7
16 x 256 each piece once (default) 4096 16 1306.3 88.1

Intel, VICTORY_CARD_HASH_WIDE=unset

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.0 1077.4
1 x 1 touching joined (=1) 1 1 31.4 1082.9
1 x 1 each piece once (default) 1 1 30.5 1083.3
1 x 16 a pass a range (=0) 16 16 50.8 1132.9
1 x 16 touching joined (=1) 16 1 48.7 1119.5
1 x 16 each piece once (default) 16 1 47.0 1116.3
1 x 256 a pass a range (=0) 256 256 203.0 6088.1
1 x 256 touching joined (=1) 256 1 194.9 1656.9
1 x 256 each piece once (default) 256 1 193.7 1647.4
1 x 4096 a pass a range (=0) 4096 4096 2637.5 91473.1
1 x 4096 touching joined (=1) 4096 1 2560.3 10848.8
1 x 4096 each piece once (default) 4096 1 2467.5 10869.2
1 x 16384 a pass a range (=0) 16384 16384 14657.2 364118.8
1 x 16384 touching joined (=1) 16384 1 13895.1 40130.5
1 x 16384 each piece once (default) 16384 1 11602.8 39943.5
4 x 16384 a pass a range (=0) 65536 65536 63394.9 1458591.6
4 x 16384 touching joined (=1) 65536 1 59748.8 158642.1
4 x 16384 each piece once (default) 65536 4 62116.4 157685.4
2 x 1 a pass a range (=0) 2 2 134.3 1115.8
2 x 1 touching joined (=1) 2 1 133.7 1130.8
2 x 1 each piece once (default) 2 2 136.9 1111.9
4 x 1 a pass a range (=0) 4 4 166.6 1303.1
4 x 1 touching joined (=1) 4 1 143.8 1362.2
4 x 1 each piece once (default) 4 4 163.2 1521.4
16 x 1 a pass a range (=0) 16 16 160.1 1830.2
16 x 1 touching joined (=1) 16 1 168.9 2108.5
16 x 1 each piece once (default) 16 16 149.6 1821.1
16 x 16 a pass a range (=0) 256 256 449.7 7462.3
16 x 16 touching joined (=1) 256 1 433.1 2093.3
16 x 16 each piece once (default) 256 16 427.6 1923.3
16 x 256 a pass a range (=0) 4096 4096 4609.9 91780.7
16 x 256 touching joined (=1) 4096 1 4212.8 11188.1
16 x 256 each piece once (default) 4096 16 4124.1 10965.2

Intel, VICTORY_CARD_HASH_WIDE=1

rehash_bench: median of 15 rounds; VICTORY_CARD_HASH_WIDE=1
pages x runs way ranges sent hash passes submitting thread (us) card (us)
1 x 1 a pass a range (=0) 1 1 32.8 73.0
1 x 1 touching joined (=1) 1 1 31.5 70.1
1 x 1 each piece once (default) 1 1 29.4 74.3
1 x 16 a pass a range (=0) 16 16 47.1 203.2
1 x 16 touching joined (=1) 16 1 45.3 199.4
1 x 16 each piece once (default) 16 1 44.5 201.2
1 x 256 a pass a range (=0) 256 256 205.0 1092.4
1 x 256 touching joined (=1) 256 1 201.5 833.8
1 x 256 each piece once (default) 256 1 198.2 836.8
1 x 4096 a pass a range (=0) 4096 4096 2772.6 12650.5
1 x 4096 touching joined (=1) 4096 1 2525.8 9643.4
1 x 4096 each piece once (default) 4096 1 2611.2 9615.9
1 x 16384 a pass a range (=0) 16384 16384 11425.1 50870.5
1 x 16384 touching joined (=1) 16384 1 10430.1 38764.8
1 x 16384 each piece once (default) 16384 1 10400.2 38659.9
4 x 16384 a pass a range (=0) 65536 65536 59051.1 205181.9
4 x 16384 touching joined (=1) 65536 1 58831.9 154576.8
4 x 16384 each piece once (default) 65536 4 60898.2 154681.6
2 x 1 a pass a range (=0) 2 2 73.8 71.4
2 x 1 touching joined (=1) 2 1 65.1 73.3
2 x 1 each piece once (default) 2 2 62.5 70.9
4 x 1 a pass a range (=0) 4 4 99.5 91.7
4 x 1 touching joined (=1) 4 1 94.4 85.4
4 x 1 each piece once (default) 4 4 99.4 75.8
16 x 1 a pass a range (=0) 16 16 126.9 113.2
16 x 1 touching joined (=1) 16 1 99.7 114.4
16 x 1 each piece once (default) 16 16 125.9 116.8
16 x 16 a pass a range (=0) 256 256 410.8 850.2
16 x 16 touching joined (=1) 256 1 400.8 632.3
16 x 16 each piece once (default) 256 16 380.5 638.3
16 x 256 a pass a range (=0) 4096 4096 4373.3 14881.5
16 x 256 touching joined (=1) 4096 1 4084.3 11152.6
16 x 256 each piece once (default) 4096 16 4031.8 11168.9

WARP, VICTORY_CARD_HASH_WIDE=unset

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 25.3 172.4
1 x 1 touching joined (=1) 1 1 21.2 212.4
1 x 1 each piece once (default) 1 1 21.0 246.4
1 x 16 a pass a range (=0) 16 16 43.7 622.5
1 x 16 touching joined (=1) 16 1 26.5 165.9
1 x 16 each piece once (default) 16 1 25.9 181.4
1 x 256 a pass a range (=0) 256 256 448.1 3558.8
1 x 256 touching joined (=1) 256 1 124.2 341.3
1 x 256 each piece once (default) 256 1 114.2 318.0
1 x 4096 a pass a range (=0) 4096 4096 10405.3 46693.5
1 x 4096 touching joined (=1) 4096 1 2111.0 2995.7
1 x 4096 each piece once (default) 4096 1 1542.8 2785.5
1 x 16384 a pass a range (=0) 16384 16384 67852.0 177754.4
1 x 16384 touching joined (=1) 16384 1 7984.1 12216.0
1 x 16384 each piece once (default) 16384 1 8293.6 12036.8
4 x 16384 a pass a range (=0) 65536 65536 360687.8 726442.6
4 x 16384 touching joined (=1) 65536 1 40872.5 49618.3
4 x 16384 each piece once (default) 65536 4 38869.0 52764.1
2 x 1 a pass a range (=0) 2 2 37.4 519.7
2 x 1 touching joined (=1) 2 1 34.8 276.4
2 x 1 each piece once (default) 2 2 36.0 520.6
4 x 1 a pass a range (=0) 4 4 36.0 494.6
4 x 1 touching joined (=1) 4 1 31.0 270.0
4 x 1 each piece once (default) 4 4 35.7 479.4
16 x 1 a pass a range (=0) 16 16 58.0 656.0
16 x 1 touching joined (=1) 16 1 38.3 847.9
16 x 1 each piece once (default) 16 16 59.4 690.1
16 x 16 a pass a range (=0) 256 256 745.4 3667.3
16 x 16 touching joined (=1) 256 1 180.9 1056.0
16 x 16 each piece once (default) 256 16 206.1 847.8
16 x 256 a pass a range (=0) 4096 4096 10117.4 47137.0
16 x 256 touching joined (=1) 4096 1 2060.1 3470.3
16 x 256 each piece once (default) 4096 16 2197.3 3588.9

WARP, VICTORY_CARD_HASH_WIDE=1

rehash_bench: median of 9 rounds; VICTORY_CARD_HASH_WIDE=1
pages x runs way ranges sent hash passes submitting thread (us) card (us)
1 x 1 a pass a range (=0) 1 1 16.5 77.1
1 x 1 touching joined (=1) 1 1 16.3 78.8
1 x 1 each piece once (default) 1 1 16.6 67.7
1 x 16 a pass a range (=0) 16 16 40.1 266.7
1 x 16 touching joined (=1) 16 1 24.5 87.6
1 x 16 each piece once (default) 16 1 27.0 92.0
1 x 256 a pass a range (=0) 256 256 407.3 1534.8
1 x 256 touching joined (=1) 256 1 111.4 230.9
1 x 256 each piece once (default) 256 1 110.7 212.5
1 x 4096 a pass a range (=0) 4096 4096 10629.6 19902.3
1 x 4096 touching joined (=1) 4096 1 1774.7 2587.6
1 x 4096 each piece once (default) 4096 1 1539.1 2662.8
1 x 16384 a pass a range (=0) 16384 16384 60394.0 81929.5
1 x 16384 touching joined (=1) 16384 1 7098.0 10539.1
1 x 16384 each piece once (default) 16384 1 6062.0 10047.8
4 x 16384 a pass a range (=0) 65536 65536 375717.0 348779.4
4 x 16384 touching joined (=1) 65536 1 37816.5 49472.3
4 x 16384 each piece once (default) 65536 4 37118.0 43465.5
2 x 1 a pass a range (=0) 2 2 29.7 170.2
2 x 1 touching joined (=1) 2 1 27.5 120.7
2 x 1 each piece once (default) 2 2 29.5 180.8
4 x 1 a pass a range (=0) 4 4 28.2 216.5
4 x 1 touching joined (=1) 4 1 23.6 154.4
4 x 1 each piece once (default) 4 4 28.4 212.7
16 x 1 a pass a range (=0) 16 16 56.9 260.0
16 x 1 touching joined (=1) 16 1 35.0 214.0
16 x 1 each piece once (default) 16 16 57.1 275.0
16 x 16 a pass a range (=0) 256 256 637.6 1806.0
16 x 16 touching joined (=1) 256 1 164.2 483.1
16 x 16 each piece once (default) 256 16 176.6 549.7
16 x 256 a pass a range (=0) 4096 4096 12134.0 20726.5
16 x 256 touching joined (=1) 4096 1 2418.0 3457.5
16 x 256 each piece once (default) 4096 16 2395.2 3436.0

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.

The test was run on:

  • RTX 4060 Laptop and Intel UHD: passes.
  • WARP (--features diagnostics, single-threaded): passes.
  • RTX with 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_pieces now checks both touching values.

Suite and lints.

  • cargo test -p victory-gpu (on e4245f3): 222 passed on RTX and on Intel. WARP, --features diagnostics --test-threads=1, release: 238 passed; 3 profile::tests fail, and the same three fail on unmodified main e4245f3 in the same build (this PR does not touch profile). The GPU test above passes again on RTX, Intel and WARP on e4245f3.
  • cargo clippy -p victory-gpu --all-targets [--features diagnostics] -- -D warnings: clean.
  • rustfmt: the lines I added or changed are rustfmt-clean. Remaining rustfmt --check differences 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

  • In-game. No in-game frame time: I have no game here.
  • Unknown range mix. The real mix of ranges per piece is unknown. The fork's timing run with =1 shows 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.
  • Discrete card only. Card times are for 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 three times:

  1. with VICTORY_CARD_REHASH_RUNS=0 (the old default);
  2. with it unset (this PR);
  3. with it set to 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

**@⁠KainanP** on GitHub · 2026-11-26 12:31 UTC · [original](https://github.com/fxceless/victory-fork/pull/1298) `KainanP:perf/rehash-joined-default` → `main` · +541 −33 · 2 files · 1 commits · open ## Problem With `VICTORY_CARD_REHASH_RUNS` unset (the default), `Host::card_before` gives every range sent up to a copy in the card's memory its own `CARD_COMPARE` hash 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. `=1` joins the passes. The fork's own diagnostic runs all set it, and #867 (item 4) proposes making it the default. But `=1` also joins pieces that only *touch*. The narrow `CARD_COMPARE` (the default; `VICTORY_CARD_HASH_WIDE` is 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_RUNS` now has three ways: | value | passes | | |---|---|---| | unset (**new default**) | runs of pieces 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 sent up (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. ## Measurements Synthetic `host::rehash_tests::rehash_bench`, release build, on `main` e4245f3 (re-measured after the rebase; nine unrelated single-threaded CPU jobs were running), card time from timestamps around `card_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: | pages × runs | hash passes | RTX 4060 Laptop | Intel UHD (8086:a78b) | WARP | |---|---|---|---|---| | 1 × 1 | 1 / 1 / 1 | 197 / 201 / 196 | 1,077 / 1,083 / 1,083 | 172 / 212 / 246 | | 1 × 16 | 16 / 1 / 1 | 202 / 199 / 199 | 1,133 / 1,120 / 1,116 | 622 / 166 / 181 | | 1 × 256 | 256 / 1 / 1 | 365 / 204 / 203 | 6,088 / 1,657 / 1,647 | 3,559 / 341 / 318 | | 1 × 4096 | 4096 / 1 / 1 | 3,929 / 236 / 235 | 91,473 / 10,849 / 10,869 | 46,694 / 2,996 / 2,786 | | 1 × 16384 | 16384 / 1 / 1 | 13,674 / 398 / 396 | 364,119 / 40,130 / 39,944 | 177,754 / 12,216 / 12,037 | | 4 × 16384 | 65536 / 1 / 4 | 60,668 / 1,237 / 1,172 | 1,458,592 / 158,642 / 157,685 | 726,443 / 49,618 / 52,764 | | 2 × 1 | 2 / 1 / 2 | 180 / 186 / 179 | 1,116 / 1,131 / 1,112 | 520 / 276 / 521 | | 4 × 1 | 4 / 1 / 4 | 180 / 209 / 188 | 1,303 / 1,362 / 1,521 | 495 / 270 / 479 | | 16 × 1 | 16 / 1 / 16 | 187 / 272 / 182 | 1,830 / 2,108 / 1,821 | 656 / 848 / 690 | | 16 × 16 | 256 / 1 / 16 | 373 / 278 / 185 | 7,462 / 2,093 / 1,923 | 3,667 / 1,056 / 848 | | 16 × 256 | 4096 / 1 / 16 | 4,296 / 324 / 236 | 91,781 / 11,188 / 10,965 | 47,137 / 3,470 / 3,589 | 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: - **Against `=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 `=0` and the default record the same passes (2/4/16 × 1), the cells differ only by noise (Intel 4 × 1: 1303 / 1521). - **Against `=1`:** the new default is never slower beyond noise on RTX and Intel, and it is faster wherever neighbouring pieces each hold few ranges. - **WARP:** it prefers fewer dispatches, so `=1` is ahead there on 2/4/16 × 1. WARP is not a target for play. - **`VICTORY_CARD_HASH_WIDE=1`** (one group per piece; e4245f3 measured 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 `=1` are 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: | pages × runs | hash passes | RTX 4060 Laptop | Intel UHD (8086:a78b) | WARP | |---|---|---|---|---| | 1 × 1 | 1 / 1 / 1 | 29 / 27 / 30 | 73 / 70 / 74 | 77 / 79 / 68 | | 1 × 16 | 16 / 1 / 1 | 34 / 26 / 34 | 203 / 199 / 201 | 267 / 88 / 92 | | 1 × 256 | 256 / 1 / 1 | 43 / 34 / 33 | 1,092 / 834 / 837 | 1,535 / 231 / 212 | | 1 × 4096 | 4096 / 1 / 1 | 282 / 93 / 94 | 12,650 / 9,643 / 9,616 | 19,902 / 2,588 / 2,663 | | 1 × 16384 | 16384 / 1 / 1 | 1,038 / 278 / 280 | 50,870 / 38,765 / 38,660 | 81,930 / 10,539 / 10,048 | | 4 × 16384 | 65536 / 1 / 4 | 4,226 / 965 / 982 | 205,182 / 154,577 / 154,682 | 348,779 / 49,472 / 43,466 | | 2 × 1 | 2 / 1 / 2 | 28 / 28 / 27 | 71 / 73 / 71 | 170 / 121 / 181 | | 4 × 1 | 4 / 1 / 4 | 27 / 28 / 28 | 92 / 85 / 76 | 216 / 154 / 213 | | 16 × 1 | 16 / 1 / 16 | 28 / 29 / 28 | 113 / 114 / 117 | 260 / 214 / 275 | | 16 × 16 | 256 / 1 / 16 | 45 / 33 / 34 | 850 / 632 / 638 | 1,806 / 483 / 550 | | 16 × 256 | 4096 / 1 / 16 | 278 / 116 / 88 | 14,882 / 11,153 / 11,169 | 20,726 / 3,458 / 3,436 | <details><summary>Raw logs</summary> The tables were produced by `cargo test --release -p victory-gpu --lib rehash_tests::rehash_bench -- --ignored --nocapture` (`REHASH_BENCH_ROUNDS=9` on 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=unset` 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 | 39.0 | 196.6 | | 1 x 1 | touching joined (=1) | 1 | 1 | 36.8 | 200.7 | | 1 x 1 | each piece once (default) | 1 | 1 | 41.7 | 195.7 | | 1 x 16 | a pass a range (=0) | 16 | 16 | 50.0 | 201.9 | | 1 x 16 | touching joined (=1) | 16 | 1 | 49.7 | 198.7 | | 1 x 16 | each piece once (default) | 16 | 1 | 46.4 | 198.7 | | 1 x 256 | a pass a range (=0) | 256 | 256 | 156.0 | 364.7 | | 1 x 256 | touching joined (=1) | 256 | 1 | 131.2 | 203.8 | | 1 x 256 | each piece once (default) | 256 | 1 | 127.8 | 203.0 | | 1 x 4096 | a pass a range (=0) | 4096 | 4096 | 1761.8 | 3929.1 | | 1 x 4096 | touching joined (=1) | 4096 | 1 | 1347.3 | 235.5 | | 1 x 4096 | each piece once (default) | 4096 | 1 | 1338.0 | 234.8 | | 1 x 16384 | a pass a range (=0) | 16384 | 16384 | 6894.8 | 13673.7 | | 1 x 16384 | touching joined (=1) | 16384 | 1 | 5085.4 | 398.3 | | 1 x 16384 | each piece once (default) | 16384 | 1 | 5170.7 | 396.5 | | 4 x 16384 | a pass a range (=0) | 65536 | 65536 | 28467.3 | 60668.0 | | 4 x 16384 | touching joined (=1) | 65536 | 1 | 22617.9 | 1237.0 | | 4 x 16384 | each piece once (default) | 65536 | 4 | 22024.0 | 1171.5 | | 2 x 1 | a pass a range (=0) | 2 | 2 | 62.8 | 180.2 | | 2 x 1 | touching joined (=1) | 2 | 1 | 55.3 | 185.5 | | 2 x 1 | each piece once (default) | 2 | 2 | 61.4 | 179.2 | | 4 x 1 | a pass a range (=0) | 4 | 4 | 59.9 | 180.2 | | 4 x 1 | touching joined (=1) | 4 | 1 | 62.1 | 209.2 | | 4 x 1 | each piece once (default) | 4 | 4 | 63.6 | 188.4 | | 16 x 1 | a pass a range (=0) | 16 | 16 | 71.2 | 186.7 | | 16 x 1 | touching joined (=1) | 16 | 1 | 63.8 | 272.5 | | 16 x 1 | each piece once (default) | 16 | 16 | 70.7 | 181.5 | | 16 x 16 | a pass a range (=0) | 256 | 256 | 213.2 | 373.1 | | 16 x 16 | touching joined (=1) | 256 | 1 | 179.3 | 277.5 | | 16 x 16 | each piece once (default) | 256 | 16 | 189.8 | 185.3 | | 16 x 256 | a pass a range (=0) | 4096 | 4096 | 2657.1 | 4295.7 | | 16 x 256 | touching joined (=1) | 4096 | 1 | 1870.0 | 323.6 | | 16 x 256 | each piece once (default) | 4096 | 16 | 1974.1 | 235.6 | `RTX, VICTORY_CARD_HASH_WIDE=1` rehash_bench: median of 15 rounds; VICTORY_CARD_HASH_WIDE=1 | pages x runs | way | ranges sent | hash passes | submitting thread (us) | card (us) | |---|---|---:|---:|---:|---:| | 1 x 1 | a pass a range (=0) | 1 | 1 | 39.1 | 28.7 | | 1 x 1 | touching joined (=1) | 1 | 1 | 36.6 | 26.6 | | 1 x 1 | each piece once (default) | 1 | 1 | 36.7 | 29.7 | | 1 x 16 | a pass a range (=0) | 16 | 16 | 45.1 | 33.9 | | 1 x 16 | touching joined (=1) | 16 | 1 | 47.0 | 25.8 | | 1 x 16 | each piece once (default) | 16 | 1 | 47.7 | 34.0 | | 1 x 256 | a pass a range (=0) | 256 | 256 | 147.6 | 43.0 | | 1 x 256 | touching joined (=1) | 256 | 1 | 123.1 | 33.8 | | 1 x 256 | each piece once (default) | 256 | 1 | 124.0 | 32.9 | | 1 x 4096 | a pass a range (=0) | 4096 | 4096 | 1906.9 | 281.6 | | 1 x 4096 | touching joined (=1) | 4096 | 1 | 1535.6 | 93.2 | | 1 x 4096 | each piece once (default) | 4096 | 1 | 1492.2 | 94.2 | | 1 x 16384 | a pass a range (=0) | 16384 | 16384 | 6564.6 | 1038.3 | | 1 x 16384 | touching joined (=1) | 16384 | 1 | 5247.6 | 277.5 | | 1 x 16384 | each piece once (default) | 16384 | 1 | 5184.4 | 279.6 | | 4 x 16384 | a pass a range (=0) | 65536 | 65536 | 27920.7 | 4226.0 | | 4 x 16384 | touching joined (=1) | 65536 | 1 | 21515.1 | 964.6 | | 4 x 16384 | each piece once (default) | 65536 | 4 | 21330.0 | 982.1 | | 2 x 1 | a pass a range (=0) | 2 | 2 | 35.2 | 27.6 | | 2 x 1 | touching joined (=1) | 2 | 1 | 35.8 | 27.7 | | 2 x 1 | each piece once (default) | 2 | 2 | 35.1 | 26.6 | | 4 x 1 | a pass a range (=0) | 4 | 4 | 34.5 | 26.7 | | 4 x 1 | touching joined (=1) | 4 | 1 | 34.9 | 27.9 | | 4 x 1 | each piece once (default) | 4 | 4 | 35.9 | 27.6 | | 16 x 1 | a pass a range (=0) | 16 | 16 | 41.1 | 27.6 | | 16 x 1 | touching joined (=1) | 16 | 1 | 39.9 | 28.7 | | 16 x 1 | each piece once (default) | 16 | 16 | 41.9 | 27.8 | | 16 x 16 | a pass a range (=0) | 256 | 256 | 144.3 | 45.1 | | 16 x 16 | touching joined (=1) | 256 | 1 | 115.9 | 32.8 | | 16 x 16 | each piece once (default) | 256 | 16 | 119.5 | 33.8 | | 16 x 256 | a pass a range (=0) | 4096 | 4096 | 1752.7 | 277.5 | | 16 x 256 | touching joined (=1) | 4096 | 1 | 1314.0 | 115.7 | | 16 x 256 | each piece once (default) | 4096 | 16 | 1306.3 | 88.1 | `Intel, VICTORY_CARD_HASH_WIDE=unset` 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.0 | 1077.4 | | 1 x 1 | touching joined (=1) | 1 | 1 | 31.4 | 1082.9 | | 1 x 1 | each piece once (default) | 1 | 1 | 30.5 | 1083.3 | | 1 x 16 | a pass a range (=0) | 16 | 16 | 50.8 | 1132.9 | | 1 x 16 | touching joined (=1) | 16 | 1 | 48.7 | 1119.5 | | 1 x 16 | each piece once (default) | 16 | 1 | 47.0 | 1116.3 | | 1 x 256 | a pass a range (=0) | 256 | 256 | 203.0 | 6088.1 | | 1 x 256 | touching joined (=1) | 256 | 1 | 194.9 | 1656.9 | | 1 x 256 | each piece once (default) | 256 | 1 | 193.7 | 1647.4 | | 1 x 4096 | a pass a range (=0) | 4096 | 4096 | 2637.5 | 91473.1 | | 1 x 4096 | touching joined (=1) | 4096 | 1 | 2560.3 | 10848.8 | | 1 x 4096 | each piece once (default) | 4096 | 1 | 2467.5 | 10869.2 | | 1 x 16384 | a pass a range (=0) | 16384 | 16384 | 14657.2 | 364118.8 | | 1 x 16384 | touching joined (=1) | 16384 | 1 | 13895.1 | 40130.5 | | 1 x 16384 | each piece once (default) | 16384 | 1 | 11602.8 | 39943.5 | | 4 x 16384 | a pass a range (=0) | 65536 | 65536 | 63394.9 | 1458591.6 | | 4 x 16384 | touching joined (=1) | 65536 | 1 | 59748.8 | 158642.1 | | 4 x 16384 | each piece once (default) | 65536 | 4 | 62116.4 | 157685.4 | | 2 x 1 | a pass a range (=0) | 2 | 2 | 134.3 | 1115.8 | | 2 x 1 | touching joined (=1) | 2 | 1 | 133.7 | 1130.8 | | 2 x 1 | each piece once (default) | 2 | 2 | 136.9 | 1111.9 | | 4 x 1 | a pass a range (=0) | 4 | 4 | 166.6 | 1303.1 | | 4 x 1 | touching joined (=1) | 4 | 1 | 143.8 | 1362.2 | | 4 x 1 | each piece once (default) | 4 | 4 | 163.2 | 1521.4 | | 16 x 1 | a pass a range (=0) | 16 | 16 | 160.1 | 1830.2 | | 16 x 1 | touching joined (=1) | 16 | 1 | 168.9 | 2108.5 | | 16 x 1 | each piece once (default) | 16 | 16 | 149.6 | 1821.1 | | 16 x 16 | a pass a range (=0) | 256 | 256 | 449.7 | 7462.3 | | 16 x 16 | touching joined (=1) | 256 | 1 | 433.1 | 2093.3 | | 16 x 16 | each piece once (default) | 256 | 16 | 427.6 | 1923.3 | | 16 x 256 | a pass a range (=0) | 4096 | 4096 | 4609.9 | 91780.7 | | 16 x 256 | touching joined (=1) | 4096 | 1 | 4212.8 | 11188.1 | | 16 x 256 | each piece once (default) | 4096 | 16 | 4124.1 | 10965.2 | `Intel, VICTORY_CARD_HASH_WIDE=1` rehash_bench: median of 15 rounds; VICTORY_CARD_HASH_WIDE=1 | pages x runs | way | ranges sent | hash passes | submitting thread (us) | card (us) | |---|---|---:|---:|---:|---:| | 1 x 1 | a pass a range (=0) | 1 | 1 | 32.8 | 73.0 | | 1 x 1 | touching joined (=1) | 1 | 1 | 31.5 | 70.1 | | 1 x 1 | each piece once (default) | 1 | 1 | 29.4 | 74.3 | | 1 x 16 | a pass a range (=0) | 16 | 16 | 47.1 | 203.2 | | 1 x 16 | touching joined (=1) | 16 | 1 | 45.3 | 199.4 | | 1 x 16 | each piece once (default) | 16 | 1 | 44.5 | 201.2 | | 1 x 256 | a pass a range (=0) | 256 | 256 | 205.0 | 1092.4 | | 1 x 256 | touching joined (=1) | 256 | 1 | 201.5 | 833.8 | | 1 x 256 | each piece once (default) | 256 | 1 | 198.2 | 836.8 | | 1 x 4096 | a pass a range (=0) | 4096 | 4096 | 2772.6 | 12650.5 | | 1 x 4096 | touching joined (=1) | 4096 | 1 | 2525.8 | 9643.4 | | 1 x 4096 | each piece once (default) | 4096 | 1 | 2611.2 | 9615.9 | | 1 x 16384 | a pass a range (=0) | 16384 | 16384 | 11425.1 | 50870.5 | | 1 x 16384 | touching joined (=1) | 16384 | 1 | 10430.1 | 38764.8 | | 1 x 16384 | each piece once (default) | 16384 | 1 | 10400.2 | 38659.9 | | 4 x 16384 | a pass a range (=0) | 65536 | 65536 | 59051.1 | 205181.9 | | 4 x 16384 | touching joined (=1) | 65536 | 1 | 58831.9 | 154576.8 | | 4 x 16384 | each piece once (default) | 65536 | 4 | 60898.2 | 154681.6 | | 2 x 1 | a pass a range (=0) | 2 | 2 | 73.8 | 71.4 | | 2 x 1 | touching joined (=1) | 2 | 1 | 65.1 | 73.3 | | 2 x 1 | each piece once (default) | 2 | 2 | 62.5 | 70.9 | | 4 x 1 | a pass a range (=0) | 4 | 4 | 99.5 | 91.7 | | 4 x 1 | touching joined (=1) | 4 | 1 | 94.4 | 85.4 | | 4 x 1 | each piece once (default) | 4 | 4 | 99.4 | 75.8 | | 16 x 1 | a pass a range (=0) | 16 | 16 | 126.9 | 113.2 | | 16 x 1 | touching joined (=1) | 16 | 1 | 99.7 | 114.4 | | 16 x 1 | each piece once (default) | 16 | 16 | 125.9 | 116.8 | | 16 x 16 | a pass a range (=0) | 256 | 256 | 410.8 | 850.2 | | 16 x 16 | touching joined (=1) | 256 | 1 | 400.8 | 632.3 | | 16 x 16 | each piece once (default) | 256 | 16 | 380.5 | 638.3 | | 16 x 256 | a pass a range (=0) | 4096 | 4096 | 4373.3 | 14881.5 | | 16 x 256 | touching joined (=1) | 4096 | 1 | 4084.3 | 11152.6 | | 16 x 256 | each piece once (default) | 4096 | 16 | 4031.8 | 11168.9 | `WARP, VICTORY_CARD_HASH_WIDE=unset` 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 | 25.3 | 172.4 | | 1 x 1 | touching joined (=1) | 1 | 1 | 21.2 | 212.4 | | 1 x 1 | each piece once (default) | 1 | 1 | 21.0 | 246.4 | | 1 x 16 | a pass a range (=0) | 16 | 16 | 43.7 | 622.5 | | 1 x 16 | touching joined (=1) | 16 | 1 | 26.5 | 165.9 | | 1 x 16 | each piece once (default) | 16 | 1 | 25.9 | 181.4 | | 1 x 256 | a pass a range (=0) | 256 | 256 | 448.1 | 3558.8 | | 1 x 256 | touching joined (=1) | 256 | 1 | 124.2 | 341.3 | | 1 x 256 | each piece once (default) | 256 | 1 | 114.2 | 318.0 | | 1 x 4096 | a pass a range (=0) | 4096 | 4096 | 10405.3 | 46693.5 | | 1 x 4096 | touching joined (=1) | 4096 | 1 | 2111.0 | 2995.7 | | 1 x 4096 | each piece once (default) | 4096 | 1 | 1542.8 | 2785.5 | | 1 x 16384 | a pass a range (=0) | 16384 | 16384 | 67852.0 | 177754.4 | | 1 x 16384 | touching joined (=1) | 16384 | 1 | 7984.1 | 12216.0 | | 1 x 16384 | each piece once (default) | 16384 | 1 | 8293.6 | 12036.8 | | 4 x 16384 | a pass a range (=0) | 65536 | 65536 | 360687.8 | 726442.6 | | 4 x 16384 | touching joined (=1) | 65536 | 1 | 40872.5 | 49618.3 | | 4 x 16384 | each piece once (default) | 65536 | 4 | 38869.0 | 52764.1 | | 2 x 1 | a pass a range (=0) | 2 | 2 | 37.4 | 519.7 | | 2 x 1 | touching joined (=1) | 2 | 1 | 34.8 | 276.4 | | 2 x 1 | each piece once (default) | 2 | 2 | 36.0 | 520.6 | | 4 x 1 | a pass a range (=0) | 4 | 4 | 36.0 | 494.6 | | 4 x 1 | touching joined (=1) | 4 | 1 | 31.0 | 270.0 | | 4 x 1 | each piece once (default) | 4 | 4 | 35.7 | 479.4 | | 16 x 1 | a pass a range (=0) | 16 | 16 | 58.0 | 656.0 | | 16 x 1 | touching joined (=1) | 16 | 1 | 38.3 | 847.9 | | 16 x 1 | each piece once (default) | 16 | 16 | 59.4 | 690.1 | | 16 x 16 | a pass a range (=0) | 256 | 256 | 745.4 | 3667.3 | | 16 x 16 | touching joined (=1) | 256 | 1 | 180.9 | 1056.0 | | 16 x 16 | each piece once (default) | 256 | 16 | 206.1 | 847.8 | | 16 x 256 | a pass a range (=0) | 4096 | 4096 | 10117.4 | 47137.0 | | 16 x 256 | touching joined (=1) | 4096 | 1 | 2060.1 | 3470.3 | | 16 x 256 | each piece once (default) | 4096 | 16 | 2197.3 | 3588.9 | `WARP, VICTORY_CARD_HASH_WIDE=1` rehash_bench: median of 9 rounds; VICTORY_CARD_HASH_WIDE=1 | pages x runs | way | ranges sent | hash passes | submitting thread (us) | card (us) | |---|---|---:|---:|---:|---:| | 1 x 1 | a pass a range (=0) | 1 | 1 | 16.5 | 77.1 | | 1 x 1 | touching joined (=1) | 1 | 1 | 16.3 | 78.8 | | 1 x 1 | each piece once (default) | 1 | 1 | 16.6 | 67.7 | | 1 x 16 | a pass a range (=0) | 16 | 16 | 40.1 | 266.7 | | 1 x 16 | touching joined (=1) | 16 | 1 | 24.5 | 87.6 | | 1 x 16 | each piece once (default) | 16 | 1 | 27.0 | 92.0 | | 1 x 256 | a pass a range (=0) | 256 | 256 | 407.3 | 1534.8 | | 1 x 256 | touching joined (=1) | 256 | 1 | 111.4 | 230.9 | | 1 x 256 | each piece once (default) | 256 | 1 | 110.7 | 212.5 | | 1 x 4096 | a pass a range (=0) | 4096 | 4096 | 10629.6 | 19902.3 | | 1 x 4096 | touching joined (=1) | 4096 | 1 | 1774.7 | 2587.6 | | 1 x 4096 | each piece once (default) | 4096 | 1 | 1539.1 | 2662.8 | | 1 x 16384 | a pass a range (=0) | 16384 | 16384 | 60394.0 | 81929.5 | | 1 x 16384 | touching joined (=1) | 16384 | 1 | 7098.0 | 10539.1 | | 1 x 16384 | each piece once (default) | 16384 | 1 | 6062.0 | 10047.8 | | 4 x 16384 | a pass a range (=0) | 65536 | 65536 | 375717.0 | 348779.4 | | 4 x 16384 | touching joined (=1) | 65536 | 1 | 37816.5 | 49472.3 | | 4 x 16384 | each piece once (default) | 65536 | 4 | 37118.0 | 43465.5 | | 2 x 1 | a pass a range (=0) | 2 | 2 | 29.7 | 170.2 | | 2 x 1 | touching joined (=1) | 2 | 1 | 27.5 | 120.7 | | 2 x 1 | each piece once (default) | 2 | 2 | 29.5 | 180.8 | | 4 x 1 | a pass a range (=0) | 4 | 4 | 28.2 | 216.5 | | 4 x 1 | touching joined (=1) | 4 | 1 | 23.6 | 154.4 | | 4 x 1 | each piece once (default) | 4 | 4 | 28.4 | 212.7 | | 16 x 1 | a pass a range (=0) | 16 | 16 | 56.9 | 260.0 | | 16 x 1 | touching joined (=1) | 16 | 1 | 35.0 | 214.0 | | 16 x 1 | each piece once (default) | 16 | 16 | 57.1 | 275.0 | | 16 x 16 | a pass a range (=0) | 256 | 256 | 637.6 | 1806.0 | | 16 x 16 | touching joined (=1) | 256 | 1 | 164.2 | 483.1 | | 16 x 16 | each piece once (default) | 256 | 16 | 176.6 | 549.7 | | 16 x 256 | a pass a range (=0) | 4096 | 4096 | 12134.0 | 20726.5 | | 16 x 256 | touching joined (=1) | 4096 | 1 | 2418.0 | 3457.5 | | 16 x 256 | each piece once (default) | 4096 | 16 | 2395.2 | 3436.0 | </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. The test was run on: - RTX 4060 Laptop and Intel UHD: passes. - WARP (`--features diagnostics`, single-threaded): passes. - RTX with `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_pieces` now checks both `touching` values. **Suite and lints.** - `cargo test -p victory-gpu` (on e4245f3): 222 passed on RTX and on Intel. WARP, `--features diagnostics --test-threads=1`, release: 238 passed; 3 `profile::tests` fail, and the same three fail on unmodified `main` e4245f3 in the same build (this PR does not touch `profile`). The GPU test above passes again on RTX, Intel and WARP on e4245f3. - `cargo clippy -p victory-gpu --all-targets [--features diagnostics] -- -D warnings`: clean. - rustfmt: the lines I added or changed are rustfmt-clean. Remaining `rustfmt --check` differences 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 - **In-game.** No in-game frame time: I have no game here. - **Unknown range mix.** The real mix of ranges per piece is unknown. The fork's timing run with `=1` shows 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. - **Discrete card only.** Card times are for 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 three times: 1. with `VICTORY_CARD_REHASH_RUNS=0` (the old default); 2. with it unset (this PR); 3. with it set to `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](https://claude.com/claude-code)
With VICTORY_CARD_REHASH_RUNS unset, every range sent up to a copy in the
card's memory had a hash pass of its own, so a 64 KiB piece holding 16,384
changed runs (fork issue #1083) was hashed 16,384 times: 14-15 ms of an RTX
4060 Laptop's time, 362 ms of an Intel UHD's (synthetic, card alone).

- Unset (the new default): runs of pieces that share a piece are one pass
  (Rehash::Sharing), so each piece is hashed once: 0.43 / 36.5 ms for that page.
- =1 keeps the touching join (Rehash::Touching). It is not the default because
  CARD_COMPARE gives a pass's pieces one thread each in a single group: 16
  touching pieces with one range each took 179 us of the RTX's time as 16
  passes and 266 us as one (Intel 1.15 / 1.23 ms).
- =0 is the old pass a range; alt still alternates =1 and =0.
- joined_piece_runs takes `touching`; the frame-rate line names the way.

Tests: rehash_tests::joined_rehash_leaves_the_hashes_a_pass_a_range_does
(GPU, ignored) runs 56 random cases on three copies, one per way, and checks
the card bytes and every piece hash are identical across ways, equal to a CPU
model of CARD_COMPARE for touched pieces and unchanged for the others (RTX,
Intel UHD, WARP; also with VICTORY_CARD_HASH_WIDE=1). rehash_bench (ignored)
prints the table. Host::card_sync_timed and Shadow::card_put_runs are test
only (card_sync_timed is the same helper as in PR #1295).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:35:12 +00:00
Author
Owner

@⁠HLVM04 on GitHub · 2026-11-26 12:56 UTC · original

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.

**@⁠HLVM04** on GitHub · 2026-11-26 12:56 UTC · [original](https://github.com/fxceless/victory-fork/pull/1298#issuecomment-7192660054) 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.
Author
Owner

@⁠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_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

**@⁠KainanP** on GitHub · 2026-11-26 13:07 UTC · [original](https://github.com/fxceless/victory-fork/pull/1298#issuecomment-7192908209) 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)
Author
Owner

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

AI use: Claude Code (Claude Opus 5.5).

**@⁠KainanP** on GitHub · 2026-11-26 13:48 UTC · [original](https://github.com/fxceless/victory-fork/pull/1298#issuecomment-7193873396) 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)._
Author
Owner

@⁠CuteBooty on GitHub · 2026-11-26 16:00 UTC · original

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** on GitHub · 2026-11-26 16:00 UTC · [original](https://github.com/fxceless/victory-fork/pull/1298#issuecomment-7197056652) 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.
Author
Owner

@⁠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.

**@⁠CuteBooty** on GitHub · 2026-11-26 16:31 UTC · [original](https://github.com/fxceless/victory-fork/pull/1298#issuecomment-7197766738) 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.
github-bot force-pushed github-bot/gh-1298 from 08a4e9be07 to 2e575c2c86 2026-11-26 17:15:26 +00:00 Compare
Author
Owner

@⁠KainanP on GitHub · 2026-11-26 17:15 UTC · original

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** on GitHub · 2026-11-26 17:15 UTC · [original](https://github.com/fxceless/victory-fork/pull/1298#issuecomment-7198739216) 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)._
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1298/head:github-bot/gh-1298'
git switch 'github-bot/gh-1298'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1298'
git switch 'github-bot/gh-1298'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1298'
git switch 'github-bot/gh-1298'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1298'
git switch 'main'
git merge --squash 'github-bot/gh-1298'
git switch 'main'
git merge --ff-only 'github-bot/gh-1298'
git switch 'main'
git merge 'github-bot/gh-1298'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.