Skip to content

[upstream #1111] Recompiler: propagate split-wave64 lane-local masks through 64-bit bitwise SALU ops - #48

Closed
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1111
Closed

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1111

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Reduces xcl_x_ballot() cross-half exchanges in split-wave64 (docs/wave64-on-wave32.md) by propagating lane-local mask liveness through 64-bit bitwise SALU ops in x64_masks.rs.

Why

  • In x64_masks.rs, v_cmp* and carry outputs (v_add_co_u32 / v_sub*_co_u32) already avoid a cross-half xcl_x_ballot() exchange (xcl_x_ballot_local()) when they feed only per-lane readers (v_cndmask_b32, v_add_co_ci_u32, v_sub*_co_ci_u32).
  • However, real wave64 compute/mesh shaders frequently combine multiple compare masks with 64-bit bitwise SALU ops (s_and_b64, s_or_b64, s_xor_b64, s_andn2_b64, s_orn2_b64, s_nand_b64, s_nor_b64, s_xnor_b64, s_not_b64, s_mov_b64, s_cselect_b64, s_cmov_b64, s_wqm_b64) before feeding v_cndmask_b32. Previously, x64_masks treated every SALU instruction as reading its source SGPR pairs whole, forcing xcl_x_ballot() on all upstream compares even when neither the result mask nor scc was ever read whole.
  • Because xcl_x_ballot_local() leaves each 32-lane half's own word exact (low dword on half 0, high dword on half 1) and none of these 64-bit lane-wise ops crosses the 32-lane boundary, each half produces its own exact 32-lane result word without exchanging the inputs — provided:
    1. the destination pair is not whole-live afterward (EXEC is always whole-live, so writes to EXEC stay exchanged);
    2. if the op writes scc (all except s_mov_b64 / s_cmov_b64 / s_cselect_b64), scc is dead afterward (tracked jointly in the backward liveness pass, including LOOP_GUARD exits and kernel-mode end readback);
    3. destination and SGPR source operands are even-aligned 64-bit pairs (so low/high half words never cross-alias), and special scalar codes vccz (251) / execz (252) still mark VCC / EXEC whole-live.

What is in it

  • crates/xcl/src/gpu/recomp/x64_masks.rs: track scc liveness alongside whole-live SGPRs (reads_scc, conservative writes_scc matching emit.rs, lane_wise_salu64, and flow()), propagate non-whole-live masks through even-aligned 64-bit lane-wise SALU ops, update three existing tests that used a dead s_mov_b64 s[2:3], vcc as a dummy whole-reader, and add 6 unit tests covering bitwise chains, live vs overwritten scc, s_and_saveexec_b64 / EXEC writes, s_cselect_b64 / s_cmov_b64, vccz / odd alignment, and LOOP_GUARD exits reading scc.
  • crates/xcl/src/gpu/recomp/emit.rs: require n & 1 == 0 when emitting xcl_x_ballot_local into Dst::S(n) so low/high half alignment is guaranteed globally.
  • crates/xcl/src/gpu/recomp/tests.rs: add GPU test gpu_split_wave64_bitwise_lane_masks verifying both 0-exchange bitwise mask chains (s_and_b64, s_andn2_b64, s_not_b64, s_or_b64, s_mov_b64, s_cselect_b64 → v_cndmask_b32) and kept exchanges when scc is read (s_and_b64 matching upper half only → s_cselect_b32).

Measured impact (RTX 3060 Ti, split-wave64)

Tested

  • Hardware: NVIDIA GeForce RTX 3060 Ti 8 GB (driver 32.0.16.2101), Ryzen 5 7500F, 64 GB RAM, Windows 11 Build 26300, DXC 1.9.2609.5, Rust 1.100.0 (x86_64-pc-windows-msvc), debug + release.
  • cargo test -p xcl --lib x64_masks -- --test-threads=1: 22 passed, 0 failed.
  • cargo test -p xcl --lib gpu_split_wave64 -- --test-threads=1: 6 passed, 0 failed (including new gpu_split_wave64_bitwise_lane_masks).
  • cargo test --workspace -- --test-threads=1: 744 passed, 0 failed, 41 ignored (1 SKIPPED GPU test: gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64)).

Regression run
(local folder name redacted to retail-title in both blocks; all metrics are exact output of the warm-cache 60 s runs with XCL_NETWORK=0)

main:

xcl-smoke v1
commit: 384f7f7f8c79fa4d4dee59336d650a4021af4c7e
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1631 (PresentX 1631)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14885 MB

PR:

xcl-smoke v1
commit: 02d65c822e3c0e175e8da9c5bc14d141bdce0ffa
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1617 (PresentX 1617)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14863 MB

Not tested

  • AMD native wave64 GPUs (x64_masks only runs when split_wave64 is active on wave32-only GPUs or forced via XCL_SPLIT_WAVE64=1).
  • Linux / Wine.

AI use

  • Antigravity (Gemini 4 Neon): analyzed split-wave64 xcl_x_ballot consumers across the shader corpus, designed and implemented the x64_masks.rs scc + bitwise propagation pass, wrote unit/GPU tests, ran the DXC/PSO benchmarks, and drafted the PR description; all tests, benchmarks, and paired smoke runs were executed locally on the hardware above and the diff was reviewed line by line.

Mirror of xcl-dev#1111 (auto-synced, do not edit).

@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#1111 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/1111 branch November 25, 2026 00:13
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