Skip to content

[upstream #944] Recompiler: batch consecutive v_readfirstlane/v_readlane exchanges in… - #151

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

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

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

In split-wave64 mode (two hardware wave32 halves per console wave64), consecutive independent v_readfirstlane_b32 and v_readlane_b32 instructions (for example, 4-dword V# or 8-dword T# descriptor waterfalls in wave64 mesh and compute shaders) previously each emitted a separate xcl_x_rla_uniform call — inlining a full cross-half xcl_x_meet() barrier/spin-wait exchange per instruction.

PRELUDE_X64 already supports multi-word exchanges (xcl_x_put(i, ...) / xcl_x_meet() / xcl_x_get(i), as used by coherent s_load_dwordx4 and ds_bpermute). This batches consecutive dependency-free v_readfirstlane_b32 / v_readlane_b32 instructions inside each basic block into a single multi-word xcl_x_meet() (sharing one first_lane(exec_lo, exec_hi) call across the batch), reducing DXIL size, DXC compile time, and NVIDIA driver (nvgpucomp64.dll) pipeline compile time. Native wave64 and wave32 HLSL are unchanged, and this is orthogonal to xcl-dev#917 (v_writelane_b32 spill shadows).

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: add Em::emit_insts and split-wave64 batching for consecutive plain v_readfirstlane_b32 / v_readlane_b32 instructions within a basic block. Splits on any SGPR/EXEC read-after-write dependency, skips reads already resolved by upper_lanes, and caps batch width at (64 / waves).clamp(2, 8) so per-wave exchange storage stays <= 256 dwords (1 KiB).
  • 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_readlane_batching_rules (unit test covering 4-word batching, SGPR and EXEC dependency splits, jump-target splits, 64- and 1024-thread slot caps, and native wave64 invariance) and gpu_split_wave64_batched_readlanes (GPU test verifying upper-half active lanes, mixed lower/upper lane batches, SGPR dependency split, and EXEC-modifying split).

Across 10,447 wave64 CS/MS programs in a retail shader pack, this removes 19,334 xcl_x_meet() exchanges (18,049 from consecutive v_readfirstlane_b32 and 1,281 from consecutive v_readlane_b32).

Measured on four retail wave64 shaders on origin/main (09940bb) → this commit (e7199ca) (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_readlane_batching_rules, gpu_split_wave64_batched_readlanes) ran and passed.

Regression run
(local folder name redacted to retail-title in both blocks; 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: e7199ca3f4fd985969b73bd17d5108866c93a679
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1635 (PresentX 1635)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14662 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 mesh and 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#944 (auto-synced, do not edit).

@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

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

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