Skip to content

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

Open
zondy1i wants to merge 1 commit into
xcl-dev:mainfrom
zondy1i:recomp/x64-bitwise-mask-liveness
Open

zondy1i wants to merge 1 commit into
xcl-dev:mainfrom
zondy1i:recomp/x64-bitwise-mask-liveness

Conversation

@zondy1i

@zondy1i zondy1i commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

��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) before feeding v_cndmask_b32 (s_wqm_b64 is excluded because it combines 4-lane quads and requires quad helper bits in pixel shaders). 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)

  • Across 10,490 translated wave64 compute/mesh programs from a retail shader corpus: xcl_x_ballot() calls drop from 210,324 �! 170,561 (�"39,763 exchanges, �"18.9%).
  • Cold DXC (cs_6_6) and NVIDIA D3D12 PSO compile benchmarks on three retail compute shaders (before 384f7f7 �! after 02d65c8):

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.
  • Rebased head c29bbad (onto main 0cdc896 with #1090):
    • cargo test -p xcl --lib -- gpu::recomp::x64_masks --test-threads=1: 25 passed, 0 failed, 1 ignored (including use_plan_matches_fallback_across_all_rdna2_instructions and block_liveness_matches_reference_bit_for_bit).
    • cargo test -p xcl --lib -- gpu_split_wave64 --test-threads=1: 7 passed, 0 failed (including gpu_split_wave64_bitwise_lane_masks).
  • Earlier full-workspace run on 02d65c8: 744 passed, 0 failed, 41 ignored.

Regression run

main:

xcl-smoke v1
commit: 80f4819098e921f2e1ab371144d4832f68ffedd6
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1622 (PresentX 1622)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16539 MB

PR:

xcl-smoke v1
commit: c29bbad8cafbbfddbb72bb32e93a7e3165aa5d88
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1528 (PresentX 1528)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 15821 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.

@Aniseto

Aniseto commented Nov 24, 2026

Copy link
Copy Markdown

Ran the mask tests on an NVIDIA Blackwell part at 02d65c8:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC 14.44.35207, DXC 1.9.2609.5, debug build.

XCL_ADAPTER=nvidia cargo test -p xcl --lib x64_masks -- --test-threads=1
22 passed; 0 failed; 0 ignored      (exit 0)

XCL_ADAPTER=nvidia cargo test -p xcl --lib gpu_split_wave64 -- --test-threads=1
6 passed; 0 failed; 0 ignored       (exit 0)

All six split-wave64 GPU tests pass here, including the new gpu_split_wave64_bitwise_lane_masks. This adapter has no native wave64, so every wave64 console program runs in the split form and exercises the changed path directly. The author's run was on an Ampere RTX 3060 Ti; this adds a Blackwell part with driver 32.0.16.2124.

Not tested: native wave64 (not available on this GPU), RDNA2/RDNA4 and Intel GPUs, Wine, release profile, retail titles.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash 1017 - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified.

@bjarngard

bjarngard commented Nov 24, 2026 •

Copy link
Copy Markdown

Test report for head 02d65c8 (AMD, native wave64)

Tested

  • AMD Radeon(TM) Graphics (Ryzen 9 9950X iGPU, RDNA2, native wave64), driver 32.0.21043.5001; Windows 11 build 26300; Rust 1.99.1 MSVC; DXC 1.9.2602.17; debug
  • XCL_ADAPTER=radeon cargo test --workspace --no-fail-fast -- --test-threads=4: 744 passed, 0 failed, 41 ignored, no SKIPPED
  • With XCL_REQUIRE_GPU=wave64: --lib x64_masks 22 passed, --lib gpu_split_wave64 6 passed

Not tested: retail titles, benchmarks, RDNA3/RDNA4.

AI use: the tests were run and this report was written by an AI agent, Claude Code (Claude Opus 5.5), on the hardware above. The numbers are copied from the actual test output.

@SlopTart

Copy link
Copy Markdown

Wine/RDNA3 datapoint for this fix: merged head 02d65c8 onto main 47efa2e (lane merge b97b44d) and ran the forced-split cluster (XCL_SPLIT_WAVE64=1, --test-threads=1, release) for 6 reps, against a plain-main control lane in the same session (3 reps).

Aggregate pass counts on this rig:

  • gpu_split_wave64_waves_diverge - 2/6 on your head, 0/3 control
  • gpu_split_wave64_local_and_exchanged_masks_in_diverging_waves - 1/6, control 0/3
  • gpu_split_wave64_masks_read_whole_after_partial_writes - 0/6, control 0/3
  • gpu_split_wave64_cross_half_operations - 0/6, control 0/3
  • gpu_split_wave64_lane_local_masks - 6/6 both

No cure observed on this axis: the exchange cluster from my #772 follow-up stays red, and the odd ok in waves_diverge sits inside the flake band this rig shows for that test. (Your new gpu_split_wave64_bitwise_lane_masks status line interleaves with Wine's CreateDXGIFactory2 warning in my capture, so I am not quoting a number for it; it did not error out.)

Also worth knowing: this head and #1090 both rewrite x64_masks.rs and conflict when merged together, so combined behavior is untestable until they reconcile. Full elimination list (not ACO, not a regression, timing-sensitive) is in my #772 comment.

Counts only, no game data.

Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross x86_64-pc-windows-gnu, XCL_NETWORK=0, release profile. My Linux rows: #42 / #718.

AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

@testclanker

Copy link
Copy Markdown

Tested on NVIDIA RTX 5060 Ti (Blackwell, wave32 only, split wave64) at 02d65c8

Tested

  • RTX 5060 Ti 16 GB, driver 32.0.16.2124; Ryzen 5 5600X, 32 GB; Windows 11 Pro 26300.10075; rustc 1.100.0; DXC 1.8.2502.11 (SDK 10.0.26100.0); debug; XCL_SAMPLE_RPF and XCL_SAMPLE_DLLS set.
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: 744 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • gpu_split_wave64_bitwise_lane_masks ran (no SKIPPED line) and passes, as do the other 5 gpu_split_wave64_* tests and all x64_masks unit tests. gpu_pso_e2e on the sample pack: 7 passed.

Regression run (60 s, networking off, no input). One warm-up run of the PR build came first so that both builds started with a warm DXIL cache (exit 0x0, no removal, no crash). That run compiled 38 shaders main's cache didn't have, so the title runs code this PR changes. Then main and this PR ran back to back. Main is at 47efa2e, 9 commits past this PR's base 384f7f7; none of them touch gpu/recomp.

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 5060 Ti
title: dumped
seconds: 60
exit: 0x0
frames shown: 1489 (PresentX 1489)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14479 MB

this PR:

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

Frames 102 % of main, peak commit 100.1 % of main.

Not tested: native wave64 (no AMD GPU), a release-build test run, this PR merged onto current main.

AI use: Claude Code (Claude Opus 5.5) ran the builds, tests and smoke runs and wrote this comment.

@Cecerw

Cecerw commented Nov 24, 2026

Copy link
Copy Markdown

Tested on NVIDIA Ampere (32-lane waves, split wave64): passes

Tree Passed Failed Ignored SKIPPED
Head 02d65c8 (base 384f7f7) 744 0 41 2 (no wave64)
Head merged into main 930e8b4 758 0 41 2 (no wave64)
  • RTX 3060 Ti 8 GB, driver 32.0.16.1088; i5-14600K; Windows 11 26300.9818; Rust 1.100.0, debug; DXC 1.9.2602.17
  • .\scripts\test.ps1 (cargo test --workspace -- --test-threads=4), no local changes; the merge was done locally, no conflicts
  • gpu_split_wave64_bitwise_lane_masks (runs split on this GPU) and the six mask-liveness unit tests (bitwise_mask_chain_for_selector_needs_no_exchange … loop_exit_reading_scc_keeps_exchange_inside_loop): ok
  • SKIPPED: the usual two on this adapter (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware)

Not tested: AMD, any title (no smoke run).

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

@MiguelMachado-dev

Copy link
Copy Markdown
Contributor

I'm stacking two split-wave64 changes on top of this PR. Your commit is cherry-picked onto main 9e3831e unchanged, with your authorship:

  1. Recompiler: split-wave64 EXEC is exchanged only where it is read whole #1596: EXEC is exchanged only where it is read whole (v_cmpx, even-aligned s_*_saveexec_b64 / s_*_wrexec_b64).
  2. Recompiler: a split-wave64 bitwise mask tree exchanges once, at its end #1597: a bitwise tree of two or more compares in one basic block exchanges once, at its last op (xcl_x_sync_mask), instead of once per compare.

Both build on your flow() / lane_op and your scc liveness. Neither changes the logic in your commit. Each of them edits some of your tests, and the reasons are in its description:

  • A: three tests used a saveexec or an EXEC write with nothing after it as the whole reader. They now read EXEC whole after the write.
  • B: gpu_split_wave64_bitwise_lane_masks part 2 now expects local compares plus one exchange at the s_and_b64.

On the retail pack (all wave64 CS / MS programs, split form, 4 windows) the exchanged mask writes go 210 324 (main) → 170 561 (this PR, the same count as in your description) → 153 728 (A) → 138 438 (B, including the 10 473 tree exchanges).

AI use: Claude Code (Claude Opus 5.5) wrote both PRs and this comment.

@raylitebull

Copy link
Copy Markdown
Member

Both AMD (RDNA2 iGPU + RDNA3 Wine) and NVIDIA (RTX 5070 Ti, RTX 5060 Ti, RTX 3060 Ti) test reports look solid on 02d65c8.

Remaining before merge: #1090 just merged into main with basic-block liveness in crates/xcl/src/gpu/recomp/x64_masks.rs, so please rebase #1111 onto main (folding flow() / scc liveness onto the block solver) and let Build and test (Windows, no GPU) run cleanly.

@zondy1i
zondy1i force-pushed the recomp/x64-bitwise-mask-liveness branch from 02d65c8 to c29bbad Compare November 25, 2026 01:23
@zondy1i

zondy1i commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main (0cdc896) at c29bbad, folding InstFlow / scc liveness onto #1090's precomputed UsePlanTable and basic-block liveness solver (blocks without lane-wise 64-bit SALU ops stay O(1) per iteration; blocks with lane-wise ops recompute only when (out, sout, left, sleft) changes). Also excluded S_WQM_B64 from lane_wise_salu64 since x64_masks is now shared with pixel shaders (ballot_px_local), where 4-lane quad WQM still needs quad helper bits.

Verified locally on RTX 3060 Ti:

  • gpu::recomp::x64_masks: 25/25 passed (including use_plan_matches_fallback_across_all_rdna2_instructions and block_liveness_matches_reference_bit_for_bit).
  • gpu_split_wave64: 7/7 passed (including gpu_split_wave64_bitwise_lane_masks).
  • Updated the 60 s smoke block in the PR description for c29bbad.

(AI use: Antigravity (Gemini 4 Neon) performed the rebase onto #1090, ran the tests/smoke, and drafted this reply.)

@raylitebull

Copy link
Copy Markdown
Member

Rebased head c29bbad cleanly folds InstFlow/scc liveness onto #1090's UsePlanTable and basic-block solver, excludes S_WQM_B64 from lane_wise_salu64, and passes Build and test (Windows, no GPU) + PR description (UsePlanTable / block-reference tests + gpu_split_wave64_bitwise_lane_masks on RTX 3060 Ti).

Remaining before merge: one independent AMD (or second-vendor) verification pass on c29bbad confirming the rebased #1090 integration before merging.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@Raghav314

Copy link
Copy Markdown

Test report for #1111 in the direct DXIL path, whose kernel uses the same x64_masks analysis (gpu/dxil/kernel.rs:595, x64_masks::by_pc): the driver's cold build of a split-wave64 program is about 9 % shorter.

Setup: RTX 4090 24 GB (617.14), Windows 11, Developer Mode on, release. main 68a284a with this PR at c29bbad merged (no conflicts), plus #1830's --time-forms for the timing. --time-forms --idx <record> --split 1 --windows 4 --heap --no-hlsl: direct DXIL, split wave64, heap windows; one cold CreateComputePipelineState per process, with the driver's three implicit caches off (ShaderCacheControl).

program tree DXIL driver build
062468c09af883b9 (wave64, split) main 1,387,708 B 19.9 / 20.0 / 20.0 s
+ #1111 1,337,976 B (−3.6 %) 17.9 / 18.3 s
76b0a8c7541c6c91 (no half exchanges) + #1111 unchanged, 636,668 B 4.8 s

Not tested: GPU output of the merged tree (no suite run; timing only), AMD, the HLSL path, a title run.

AI use: Claude Code (Claude Opus 5.5) merged the PR, ran the timings and wrote this for @Raghav314.

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

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.