Skip to content

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

Closed
tightfall wants to merge 1 commit into
fxceless:mainfrom
tightfall:card-compare-groups
Closed

tightfall wants to merge 1 commit into
fxceless:mainfrom
tightfall:card-compare-groups

Conversation

@tightfall

Copy link
Copy Markdown

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

The compare's single thread per piece walked 4,096 dependent 16-byte
steps, so every pass took the time of a whole piece (0.4-0.77 ms on an
RX 9070 whatever its group count) and several hundred passes ran a
frame. Now 64 threads hash a piece together, each taking every 64th
16-byte block, and thread 0 folds their hashes in thread order.
card_compare_dispatch records a pass as a group per piece, in
dispatches of at most 65,535 groups. New WARP test: a change in every
part of a piece is flagged, also with a skewed copy and swapped blocks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tightfall

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant