Skip to content

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

Closed
NickJBc wants to merge 1 commit into
fxceless:mainfrom
NickJBc:card-hash-wide
Closed

NickJBc wants to merge 1 commit into
fxceless:mainfrom
NickJBc:card-hash-wide

Conversation

@NickJBc

@NickJBc NickJBc commented Nov 25, 2026

Copy link
Copy Markdown

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.

…E=1)

The hash pass over copies in the card's memory walked each 64 KiB piece
on one thread: 4,096 dependent steps, neighbouring threads 64 KiB apart,
so a pass over a few pieces took the time of a whole piece on one lane
(514 such passes a frame in run 102).

The wide form gives each piece a group of 256 threads: lane l takes the
piece's 16-byte blocks l, l + 256, ... (16 steps for a whole piece, 4 KiB
of side-by-side loads per step), and the lane hashes are joined in a
fixed tree. Same root signature, constants and results; the hash values
differ, but nothing outside the shader reads them and one form is used
per run. A change confined to one 16-byte block always changes the hash,
as before.

Off by default. If the wide shader does not compile, the narrow one is
used and a warning logged, so the switch cannot turn card copies off.

Checked: Windows target builds and passes clippy; the HLSL compiles with
DXC (cs_6_0); a Rust model of the shader's arithmetic is tested (every
block read once, any one changed byte shows, dispatch covers every piece
within the group limits). Not yet run on a card or measured in the game.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYNyBknqrxMVw1v7HYK6J4

Copy link
Copy Markdown

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.

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.

2 participants