Card compare: a group of 256 threads per piece (VICTORY_CARD_HASH_WIDE=1) #493

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

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


The hash pass over copies in the card's memory (CARD_COMPARE in host.rs) walks each 64 KiB piece on one thread: 4,096 dependent 16-byte steps, with neighbouring threads 64 KiB apart. A pass over a few pieces therefore takes the time of a whole piece on one lane, and run 102 had 514 such passes a frame (the comment on rehash_runs notes no timing names them yet).

What this adds

crates/victory-gpu/src/card_hash.rs, a wide form of the same shader, behind VICTORY_CARD_HASH_WIDE=1 (off by default):

  • One group of 256 threads per piece. Lane l takes the piece's blocks l, l+256, ...: 16 steps for a whole piece, with each step's loads 4 KiB side by side.
  • The 256 lane hashes are joined in a fixed tree.
  • Same root signature, constants and outputs. The hash values differ, but nothing outside the shader reads them and one form is used per run.
  • Dispatched in rows of 32,768 groups, which stays under the 65,535-per-dimension limit.
  • Every thread reaches every barrier (no early return), for FXC cs_5_1.
  • If the wide shader fails to compile, the narrow one is used and a warning logged, so the switch cannot turn card copies off.

A change confined to one 16-byte block always changes the hash, as before: the lane round is bijective in its state and in the block, and the join is bijective in each side.

host.rs: picks the shader once in make_card_work; both dispatch sites use card_hash::groups.

Checked

  • Windows target builds and passes clippy.
  • The HLSL compiles with DXC (cs_6_0); FXC was not available.
  • A Rust model of the shader's arithmetic is tested: every block is read once, any one changed byte shows, swapped blocks show, and the dispatch covers every piece within the group limits.

Not checked

Not yet run on a card or measured in the game. To compare, run a diag build with VICTORY_GPU_TIMING=1, with and without VICTORY_CARD_HASH_WIDE=1. Look for card compare: a group per piece in the log, and watch for stale or flickering geometry, which would mean missed shader writes.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6595094276 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/493). Originally posted by [NickJBc](https://github.com/NickJBc) on 2026-11-25T01:35:00Z. --- The hash pass over copies in the card's memory (`CARD_COMPARE` in `host.rs`) walks each 64 KiB piece on **one thread**: 4,096 dependent 16-byte steps, with neighbouring threads 64 KiB apart. A pass over a few pieces therefore takes the time of a whole piece on one lane, and run 102 had 514 such passes a frame (the comment on `rehash_runs` notes no timing names them yet). ## What this adds `crates/victory-gpu/src/card_hash.rs`, a wide form of the same shader, behind `VICTORY_CARD_HASH_WIDE=1` (**off by default**): - One group of 256 threads per piece. Lane `l` takes the piece's blocks `l, l+256, ...`: 16 steps for a whole piece, with each step's loads 4 KiB side by side. - The 256 lane hashes are joined in a fixed tree. - Same root signature, constants and outputs. The hash values differ, but nothing outside the shader reads them and one form is used per run. - Dispatched in rows of 32,768 groups, which stays under the 65,535-per-dimension limit. - Every thread reaches every barrier (no early return), for FXC `cs_5_1`. - If the wide shader fails to compile, the narrow one is used and a warning logged, so the switch cannot turn card copies off. A change confined to one 16-byte block always changes the hash, as before: the lane round is bijective in its state and in the block, and the join is bijective in each side. `host.rs`: picks the shader once in `make_card_work`; both dispatch sites use `card_hash::groups`. ## Checked - Windows target builds and passes clippy. - The HLSL compiles with DXC (`cs_6_0`); FXC was not available. - A Rust model of the shader's arithmetic is tested: every block is read once, any one changed byte shows, swapped blocks show, and the dispatch covers every piece within the group limits. ## Not checked **Not yet run on a card or measured in the game.** To compare, run a `diag` build with `VICTORY_GPU_TIMING=1`, with and without `VICTORY_CARD_HASH_WIDE=1`. Look for `card compare: a group per piece` in the log, and watch for stale or flickering geometry, which would mean missed shader writes.
upstream-sync closed this pull request 2026-11-25 02:09:46 +00:00
kaayzouee commented 2026-11-25 02:10:10 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by kaayzouee on 2026-11-25T01:41:32Z.


Is this a duplicate of #253?

Both parallelize CARD_COMPARE hashing across a thread group per 64 KiB piece. The group size and default differ; please clarify whether this is intended as an alternative or a superseding implementation.

This is an automated message. If you believe it is incorrect, please reply with the relevant technical differences.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7149844243 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/493#issuecomment-7149844243). Originally posted by [kaayzouee](https://github.com/kaayzouee) on 2026-11-25T01:41:32Z. --- Is this a duplicate of #253? Both parallelize CARD_COMPARE hashing across a thread group per 64 KiB piece. The group size and default differ; please clarify whether this is intended as an alternative or a superseding implementation. This is an automated message. If you believe it is incorrect, please reply with the relevant technical differences.

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