gpu: coalesce card-memory piece hashing across 64 threads per piece #995

Open
UnkwnDev wants to merge 1 commit from upstream-pr/997 into main
UnkwnDev commented 2026-11-25 15:29:30 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by UnkwnDev on 2026-11-25T15:29:30Z.


Summary

  • Rewrote CARD_COMPARE in crates/victory-gpu/src/host.rs to dispatch one [numthreads(64, 1, 1)] threadgroup per 64 KiB piece (looping by 65,535 when pieces > 65535), replacing the 4,096-step serial loop per thread with 64 coalesced 16-byte loads striding 1,024 bytes (for (uint at = lo + t * 16u; at < hi; at += 1024u)).
  • Kept the exact root signature and 6-constant Span cbuffer (first, skew, size, pieces, out_at, compare), gave each lane a distinct seed, and reduced groupshared uint4 lane_h[64] via explicit GroupMemoryBarrierWithGroupSync() stages (64 -> 32 -> 16 -> 1) plus a loop-end barrier before the next iteration overwrites lane_h, avoiding any wave-size assumptions across Wave16/Wave32/Wave64/WARP.
  • Updated both CARD_COMPARE dispatch sites in crates/victory-gpu/src/host.rs and the doc comments on CARD_COMPARE and rehash_runs() to use pieces.min(65535).
  • Updated existing warp_card_* tests in crates/victory-gpu/src/indirect.rs for 1-group-per-piece dispatch and added warp_card_compare_coalesced_lanes_and_skew covering non-aligned skew, non-zero first/out_at, single-byte mutations across all 64 lanes, simultaneous identical MSB flips in paired lanes, compare = 0/1/2, and D3D12 debug-layer validation on both WARP and the hardware GPU.

Benchmark (Intel Arc A770, probe_7_coalesced_card_compare)

  • Baseline (1 thread per 64 KiB piece): 706-982 us per pass
  • Coalesced (64 threads per 64 KiB piece): 38.4 us for 1-64 pieces (18x+ faster), 220.9 us for 1024 pieces (4.4x faster)

Verification

  • $env:VICTORY_D3D12_DEBUG='1'; cargo test -p victory-gpu --features diagnostics --lib warp_card -- --test-threads=1: 3 passed, 0 failed (including zero D3D12 debug-layer warnings or errors on CARD_COMPARE).
  • cargo test -p victory-gpu --lib -- --test-threads=1: 170 passed, 5 ignored, 1 pre-existing unrelated failure (indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields).
  • cargo test -p xtask --locked: 4 passed, 0 failed.
  • cargo clippy --workspace --all-targets --locked -- -D warnings and --all-features: 0 warnings in touched files (host.rs and new code in indirect.rs); pre-existing upstream warnings remain in resource.rs:2553, draw.rs:2406, shadow.rs:2675, and indirect.rs:2356 (Rig::depth_written).
  • (Get-Item crates/victory-gpu/src/host.rs).Length: 399,234 bytes (< 524,288 bytes).

AI assistance: implemented and verified with Gemini 4 Hydrogen / Claude.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6607983307 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/997). Originally posted by [UnkwnDev](https://github.com/UnkwnDev) on 2026-11-25T15:29:30Z. --- ## Summary - Rewrote `CARD_COMPARE` in `crates/victory-gpu/src/host.rs` to dispatch one `[numthreads(64, 1, 1)]` threadgroup per 64 KiB piece (looping by 65,535 when `pieces > 65535`), replacing the 4,096-step serial loop per thread with 64 coalesced 16-byte loads striding 1,024 bytes (`for (uint at = lo + t * 16u; at < hi; at += 1024u)`). - Kept the exact root signature and 6-constant `Span` cbuffer (`first, skew, size, pieces, out_at, compare`), gave each lane a distinct seed, and reduced `groupshared uint4 lane_h[64]` via explicit `GroupMemoryBarrierWithGroupSync()` stages (64 -> 32 -> 16 -> 1) plus a loop-end barrier before the next iteration overwrites `lane_h`, avoiding any wave-size assumptions across Wave16/Wave32/Wave64/WARP. - Updated both `CARD_COMPARE` dispatch sites in `crates/victory-gpu/src/host.rs` and the doc comments on `CARD_COMPARE` and `rehash_runs()` to use `pieces.min(65535)`. - Updated existing `warp_card_*` tests in `crates/victory-gpu/src/indirect.rs` for 1-group-per-piece dispatch and added `warp_card_compare_coalesced_lanes_and_skew` covering non-aligned `skew`, non-zero `first`/`out_at`, single-byte mutations across all 64 lanes, simultaneous identical MSB flips in paired lanes, `compare = 0/1/2`, and D3D12 debug-layer validation on both WARP and the hardware GPU. ## Benchmark (Intel Arc A770, `probe_7_coalesced_card_compare`) - Baseline (1 thread per 64 KiB piece): 706-982 us per pass - Coalesced (64 threads per 64 KiB piece): 38.4 us for 1-64 pieces (18x+ faster), 220.9 us for 1024 pieces (4.4x faster) ## Verification - `$env:VICTORY_D3D12_DEBUG='1'; cargo test -p victory-gpu --features diagnostics --lib warp_card -- --test-threads=1`: 3 passed, 0 failed (including zero D3D12 debug-layer warnings or errors on `CARD_COMPARE`). - `cargo test -p victory-gpu --lib -- --test-threads=1`: 170 passed, 5 ignored, 1 pre-existing unrelated failure (`indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields`). - `cargo test -p xtask --locked`: 4 passed, 0 failed. - `cargo clippy --workspace --all-targets --locked -- -D warnings` and `--all-features`: 0 warnings in touched files (`host.rs` and new code in `indirect.rs`); pre-existing upstream warnings remain in `resource.rs:2553`, `draw.rs:2406`, `shadow.rs:2675`, and `indirect.rs:2356` (`Rig::depth_written`). - `(Get-Item crates/victory-gpu/src/host.rs).Length`: 399,234 bytes (< 524,288 bytes). AI assistance: implemented and verified with Gemini 4 Hydrogen / Claude.
UwUCammie commented 2026-11-25 17:08:04 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by UwUCammie on 2026-11-25T16:59:33Z.


Tested on RX 7900 XT (CachyOS Linux, Wine 11.22 + vkd3d-proton + RADV). Merged cleanly and ran through multiple 480–540 s gameplay passes (up to frame 4600) with our card compare lists down to ~1.4–1.5 ms/frame on the GPU clock and zero device removals or debug issues.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7168838366 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/997#issuecomment-7168838366). Originally posted by [UwUCammie](https://github.com/UwUCammie) on 2026-11-25T16:59:33Z. --- Tested on RX 7900 XT (CachyOS Linux, Wine 11.22 + vkd3d-proton + RADV). Merged cleanly and ran through multiple 480–540 s gameplay passes (up to frame 4600) with our card compare lists down to ~1.4–1.5 ms/frame on the GPU clock and zero device removals or debug issues.
UnkwnDev commented 2026-11-25 18:05:11 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by UnkwnDev on 2026-11-25T17:17:15Z.


@UwUCammie Thanks for verifying on RX 7900 XT (RADV / vkd3d-proton / Linux) across multiple 540 s runs. Glad to see the coalesced submit approach keeps GPU time at ~1.4 ms/frame with clean stability.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7169280749 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/997#issuecomment-7169280749). Originally posted by [UnkwnDev](https://github.com/UnkwnDev) on 2026-11-25T17:17:15Z. --- @UwUCammie Thanks for verifying on RX 7900 XT (RADV / vkd3d-proton / Linux) across multiple 540 s runs. Glad to see the coalesced submit approach keeps GPU time at ~1.4 ms/frame with clean stability.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/997:upstream-pr/997'
git switch 'upstream-pr/997'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/997'
git switch 'upstream-pr/997'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/997'
git switch 'upstream-pr/997'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/997'
git switch 'main'
git merge --squash 'upstream-pr/997'
git switch 'main'
git merge --ff-only 'upstream-pr/997'
git switch 'main'
git merge 'upstream-pr/997'
git push origin 'main'
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!995
No description provided.