Card compare: one thread group per 64 KiB piece instead of one thread #451

Closed
tightfall wants to merge 1 commit from upstream-pr/451 into main
tightfall commented 2026-11-25 01:01:21 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by tightfall on 2026-11-25T01:01:21Z.


CARD_COMPARE hashes the pieces of copies in the card's memory, after ranges are sent up and after the lists. It ran one thread per 64 KiB piece, and that thread walked its piece alone in 4,096 dependent 16-byte steps. So every pass took the time of one whole piece, however few pieces it had. The comment on rehash_runs already says so.

A Radeon GPU Profiler capture on an RX 9070 (Windows 11, Adrenalin 26.11.2) in the prison yard showed it as the most expensive pipeline of the capture: 295 dispatches of 1 to 44 groups, each 0.39 to 0.77 ms whatever its group count, 8.0 ms in all; one wave of 64 threads each. The log at the same time: about 600 hash passes a frame over about 1,600 pieces. RGP also put the GPU idle at 66% of the capture, so the time these passes take at the start of each submission is time the CPU waits.

With this change a group of 64 threads hashes one piece. Thread i takes the 16-byte blocks i, i + 64, ..., so neighbouring threads read neighbouring blocks, and thread 0 folds the 64 hashes in thread order. That is 64 steps per thread instead of 4,096. Each thread's seed includes its index, so two blocks that swap places still change the hash. The hash is only ever made and compared by this shader, so its new form needs nothing else to change. card_compare_dispatch records a pass as one group per piece, in dispatches of at most 65,535 groups, and both call sites and the existing WARP test use it.

Measured (same settings, scripted input, prison yard; medians over the world frames of the fps lines):

before after
fps 3.0-3.1 3.8
ms/frame 317-334 266
"on the GPU" 158-181 135

The runs used VICTORY_INPLACE=2 and a tree of this fork's main from 2119b0e plus some local changes; this branch is the same change on top of a803c87.

Tested:

  • New WARP test warp_card_compare_sees_a_change_in_every_part_of_a_piece: a byte changed at the first and last byte of a piece and in every thread's share, also with a copy that starts inside its first piece, flags that piece only; two swapped blocks are flagged too. warp_card_compare_stores_the_hash_it_made_when_told passes unchanged except for its dispatch size.
  • cargo test -p victory-gpu (113 passed) and with --features diagnostics (120 passed); cargo clippy -p victory-gpu --all-targets -D warnings with and without diagnostics; cargo xtask policy --staged.
  • In the game: the measured run above, about 4 minutes in the world, no device loss, the picture as before. That run was on the tree named above, not on this exact branch.

AI-assisted: found with RGP and written with Claude Code; tested on one machine (RX 9070, Windows 11, Adrenalin 26.11.2).

🤖 Generated with Claude Code

<!-- greyfinch-sync:fxceless/victory-fork:issue:6594685852 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/451). Originally posted by [tightfall](https://github.com/tightfall) on 2026-11-25T01:01:21Z. --- `CARD_COMPARE` hashes the pieces of copies in the card's memory, after ranges are sent up and after the lists. It ran one thread per 64 KiB piece, and that thread walked its piece alone in 4,096 dependent 16-byte steps. So every pass took the time of one whole piece, however few pieces it had. The comment on `rehash_runs` already says so. A Radeon GPU Profiler capture on an RX 9070 (Windows 11, Adrenalin 26.11.2) in the prison yard showed it as the most expensive pipeline of the capture: 295 dispatches of 1 to 44 groups, each 0.39 to 0.77 ms whatever its group count, 8.0 ms in all; one wave of 64 threads each. The log at the same time: about 600 hash passes a frame over about 1,600 pieces. RGP also put the GPU idle at 66% of the capture, so the time these passes take at the start of each submission is time the CPU waits. With this change a group of 64 threads hashes one piece. Thread `i` takes the 16-byte blocks `i`, `i + 64`, ..., so neighbouring threads read neighbouring blocks, and thread 0 folds the 64 hashes in thread order. That is 64 steps per thread instead of 4,096. Each thread's seed includes its index, so two blocks that swap places still change the hash. The hash is only ever made and compared by this shader, so its new form needs nothing else to change. `card_compare_dispatch` records a pass as one group per piece, in dispatches of at most 65,535 groups, and both call sites and the existing WARP test use it. Measured (same settings, scripted input, prison yard; medians over the world frames of the fps lines): | | before | after | |---|---|---| | fps | 3.0-3.1 | 3.8 | | ms/frame | 317-334 | 266 | | "on the GPU" | 158-181 | 135 | The runs used `VICTORY_INPLACE=2` and a tree of this fork's main from 2119b0e plus some local changes; this branch is the same change on top of a803c87. Tested: - New WARP test `warp_card_compare_sees_a_change_in_every_part_of_a_piece`: a byte changed at the first and last byte of a piece and in every thread's share, also with a copy that starts inside its first piece, flags that piece only; two swapped blocks are flagged too. `warp_card_compare_stores_the_hash_it_made_when_told` passes unchanged except for its dispatch size. - `cargo test -p victory-gpu` (113 passed) and with `--features diagnostics` (120 passed); `cargo clippy -p victory-gpu --all-targets -D warnings` with and without `diagnostics`; `cargo xtask policy --staged`. - In the game: the measured run above, about 4 minutes in the world, no device loss, the picture as before. That run was on the tree named above, not on this exact branch. AI-assisted: found with RGP and written with Claude Code; tested on one machine (RX 9070, Windows 11, Adrenalin 26.11.2). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-25 01:11:54 +00:00
tightfall commented 2026-11-25 01:12:08 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by tightfall on 2026-11-25T01:10:35Z.


Closing in favour of #253, which makes the same change to the compare pass and also to the hash passes before the lists (and puts the copies ahead of one barrier). It is older and covers more. My RX 9070 measurements with this compare-only version are on #253.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7149282527 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/451#issuecomment-7149282527). Originally posted by [tightfall](https://github.com/tightfall) on 2026-11-25T01:10:35Z. --- Closing in favour of #253, which makes the same change to the compare pass and also to the hash passes before the lists (and puts the copies ahead of one barrier). It is older and covers more. My RX 9070 measurements with this compare-only version are on #253.

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!451
No description provided.