Skip to content

[upstream #981] Recompiler: fold split-wave64 reduction tail v_readlane exchanges - #134

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

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

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

In split-wave64 mode (two hardware wave32 halves per console wave64), wave64 reductions end with a cross-half tail such as v_readlane_b32 s_tmp, v, 32 → v_<op> v, s_tmp, v → v_readlane_b32 s_out, v, 0 (or four v_readlane_b32 reads around v_add_f64 for 64-bit reductions). Previously, every v_readlane_b32 emitted its own xcl_x_rla_uniform call — running 2 (or 4 for f64) full cross-half xcl_x_meet() barrier/spin-wait exchanges even though the first exchange already hands both halves both v[L] and v[L^32].

This folds split-wave64 cross-half reduction tails (and direct (v, L) / (v, L^32) pairs) inside each basic block into a single xcl_x_meet() exchange: both halves keep both lane values from the first exchange, run the middle VALU instruction normally so all 64 lanes of v remain exact, and compute the updated target lane locally under its EXEC bit for the trailing v_readlane_b32 without a second exchange. Native wave64, wave32, and PRELUDE_X64 are unchanged; this is orthogonal to xcl-dev#917 (v_writelane_b32 spill shadows) and xcl-dev#944 (consecutive uniform readlane batching).

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: add Em::emit_insts and try_emit_x64_reduction_tail for split-wave64 mode covering:
    • 32-bit reduction tails (v_add_nc_u32, v_add_f32, v_min/max_f32/u32/i32, v_and/or/xor_b32, and v_add_f16 preserving the upper 16 bits) with modifier-free plain VALU ops, exact operand ordering, and EXEC-bit gating on the target lane;
    • 64-bit v_add_f64 reduction tails (4 v_readlane_b32 exchanges collapsed into 1 two-word xcl_x_meet());
    • direct (v, L) + (v, L^32) pairs.
  • crates/xcl/src/gpu/recomp/mod.rs: route the three basic-block emission loops (emit_block, emit_range, and straight-line branches == 0) through em.emit_insts(...).
  • crates/xcl/src/gpu/recomp/tests.rs: add split_wave64_reduction_tail_rules (unit test covering 32-bit, 64-bit v_add_f64, direct pair, CLAMP/mismatched-lane/jump-target negative guards, and native wave64 invariance) and gpu_split_wave64_reduction_tails (GPU test verifying v_min_u32, v_add_f32 swapped order, v_add_f16 high-16 preservation, 64-bit v_add_f64, direct pair, and inactive lane 0 under EXEC).

Across 10,447 wave64 CS/MS programs in a retail shader pack, this removes 869 xcl_x_meet() exchanges (773 × 32-bit tails, 32 × 3 from 64-bit v_add_f64 tails, and 3 direct pairs) and cuts wave64 reduction cross-half barrier syncs by 2x (32-bit) and 4x (64-bit f64) at runtime.

Measured on three reduction-heavy retail wave64 compute shaders on origin/main (077ce40) → this commit (9e2c7a5) (RTX 3060 Ti, DXC 1.9.2609.5):

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 --workspace -- --test-threads=1: 718 passed, 0 failed, 41 ignored (2 SKIPPED GPU tests: gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64)). Both new tests (split_wave64_reduction_tail_rules, gpu_split_wave64_reduction_tails) ran and passed.

Regression run
(local folder name redacted to retail-title in both blocks; main baseline 09940bb has an identical Rust tree to 077ce40, which only updated README.md; all metrics are exact output of the 60 s runs with XCL_NETWORK=0)

main:

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

PR:

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

Not tested

  • Native wave64 GPU (AMD RDNA): hardware not available here (split_wave64 is false there so emitted HLSL is unchanged).
  • Retail gameplay past menus (smoke run covers boot through menus; heavy compute shaders were benchmarked offline via DXC + CreateComputePipelineState).

AI use

  • Antigravity (Gemini 4 Neon): scanned the retail shader corpus, wrote the implementation, unit/GPU tests, and PR description; all tests, benchmarks, and smoke runs were executed locally on the hardware above and the diff was reviewed line by line.

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

@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

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

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