Skip to content

Recompiler: split-wave64 EXEC is exchanged only where it is read whole - #1596

Open
MiguelMachado-dev wants to merge 2 commits into
xcl-dev:mainfrom
MiguelMachado-dev:recomp/x64-mask-opt
Open

MiguelMachado-dev wants to merge 2 commits into
xcl-dev:mainfrom
MiguelMachado-dev:recomp/x64-mask-opt

Conversation

@MiguelMachado-dev

@MiguelMachado-dev MiguelMachado-dev commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #1111; only the top commit (524b25c) belongs here. #1111 is in this branch as a cherry-pick onto main 9e3831e (ce0eeec, its head is 02d65c8), so this branch is rebased once #1111 merges. Part of #1269.

In the split wave64 form, x64_masks kept EXEC whole-live at every instruction, so every v_cmpx* and every s_*_saveexec_b64 / s_*_wrexec_b64 exchanged the two halves' masks, and so did the compares feeding them. Every VALU reads EXEC lane by lane (lanebit), and DPP, ds_swizzle and v_permlane(x)16 read it for a source lane in the reader's own half. EXEC needs its whole value only where the program reads it whole: s_cbranch_exec(n)z, src_execz, a scalar operand, v_readfirstlane and ds_(b)permute. This change treats EXEC like the other masks.

What is in it

  • crates/xcl/src/gpu/recomp/x64_masks.rs:
    • EXEC is no longer live at every instruction or at the end of a compute program. The kernel runner still reads every SGPR at the end.
    • An even-aligned saveexec / wrexec needs whole inputs only when the new EXEC or its scc is read whole. When only the saved old EXEC is read whole, it needs whole EXEC alone. Odd pairs keep reading their operands whole.
    • uses() adds the EXEC reads the operand tables leave out: v_readfirstlane_b32, ds_bpermute_b32 and ds_permute_b32.
  • crates/xcl/src/gpu/recomp/emit.rs: EXEC (s126) can take the local ballot. Recompiler: propagate split-wave64 lane-local masks through 64-bit bitwise SALU ops #1111's even-alignment check is kept.
  • Tests:
    • unit tests exec_is_exchanged_only_when_read_whole (replaces exec_is_always_exchanged) and saveexec_needs_whole_inputs_only_for_a_whole_read;
    • GPU test gpu_split_wave64_predicated_exec_masks: a v_cmpx region and an s_and_saveexec_b64 region stay local, and a v_cmpx read by v_readfirstlane is still exchanged and gives the first active lane in both halves;
    • three of Recompiler: propagate split-wave64 lane-local masks through 64-bit bitwise SALU ops #1111's tests used a saveexec or an EXEC write with nothing after it as the whole reader. They now read EXEC whole after the write (s_cbranch_execz).

Measured with a temporary local test, not in this PR. It translates every wave64 CS / MS program of the retail 1.0.2.1 shaders.rpf in the split form with 4 memory windows and counts mask writes that use xcl_x_ballot:

commit programs exchanged mask writes
main 9e3831e 10 490 210 324
#1111 ce0eeec 10 490 170 561
this PR 524b25c 10 490 153 728 (−9.9 % on #1111)

docs/wave64-on-wave32.md:123 says "EXEC is always whole-live". After this change that is no longer true. The doc is not edited here.

Tested

  • NVIDIA GeForce RTX 5080 (32-lane waves, so the split form), driver 621.24; Intel Core i7-14700KF, 64 GB; Windows 11 build 26300; rustc 1.97.1; DXC 1.8.2502.11; debug for tests, release for the smoke run.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 at 524b25c: 785 passed, 0 failed, 41 ignored.
  • SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • gpu_split_wave64_predicated_exec_masks ran in the split form, and its HLSL counts were checked: 2 local, 1 exchanged.

Regression run
Each block is the second of two back-to-back 60 s runs of the same build (the first one filled the shader and driver caches).

main:

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: NVIDIA GeForce RTX 5080
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1629 (PresentX 1630)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14558 MB

PR:

xcl-smoke v1
commit: 524b25c1b7daaac3d131e5f9dce1661b8c35916d
gpu: NVIDIA GeForce RTX 5080
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1632 (PresentX 1632)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14564 MB

Not tested

  • AMD and native wave64 GPUs, where the split form is not used.
  • DXC and driver compile times before and after; only the exchange counts were measured.
  • Whether the smoke run reaches the changed code: in 60 s it built 26 compute pipelines from translated console CS, and the log does not say how many of them are wave64 programs in the split form. The exchange counts above cover the whole pack.

AI use

  • Claude Code, Claude Opus 5.5: wrote the code, the tests, the measurement script and this description, and ran the tests, the smoke runs and the measurement on the hardware above.

Zondybtw and others added 2 commits November 24, 2026 14:46
x64_masks kept EXEC whole-live everywhere, so every v_cmpx and every
s_*_saveexec_b64 / s_*_wrexec_b64 exchanged the two halves' masks, and so
did the compares feeding them. Every VALU reads EXEC lane by lane (the
emitter's lanebit), and DPP, ds_swizzle and v_permlane(x)16 read it for a
source lane in the reader's own half, so EXEC needs the whole value only
where the program reads it whole: s_cbranch_exec(n)z, src_execz, a scalar
operand, v_readfirstlane (first active lane) and ds_(b)permute (lanes of
the other half). The last three are not in the operand tables and are now
added in uses().

EXEC is now a mask like the others in the liveness: no longer live at
every instruction or at the end of a compute program (the kernel runner
still reads every SGPR at the end). An even-aligned saveexec / wrexec
needs whole inputs only when the new EXEC or its scc is read whole, and
whole EXEC alone when only the saved old EXEC is; odd pairs keep reading
their operands whole. The emitter lets EXEC (s126) take the local ballot.

Three tests from the bitwise-mask change relied on EXEC being always
live; they now read EXEC whole after the write.

Assisted-by: Claude Code (Claude Opus 5.5)
@rGillyazanov

Copy link
Copy Markdown

Tested PR #1596 at 524b25c. The targeted test passed on an RTX 3060 Ti (8 GB, driver 621.40) with Windows 11 build 26300, Rust 1.100.0 MSVC, and DXC 1.8.2505.32. PR #1596

cargo test --locked -p xcl --lib gpu::recomp::tests::gpu_split_wave64_predicated_exec_masks -- --exact --nocapture

1 passed, 0 failed, 0 skipped. With XCL_ADAPTER="RTX 3060 Ti" and XCL_REQUIRE_GPU=wave64, the test exercised split wave64 on 32-lane hardware. Both local ballot assertions, the cross-half ballot assertion, and GPU readback passed. This run covered the single synthetic test.

AI use — OpenAI Codex ran the test and drafted this report. Exact model version unavailable.

@futurepro62

Copy link
Copy Markdown

Full suite on NVIDIA plus native wave64 on an AMD RDNA2 iGPU, to go with the targeted split-wave64 check above. Tested exact head 524b25c (on its base 9e3831e).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form: 784 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: gpu_split_wave64_bitwise_lane_masks, gpu_split_wave64_predicated_exec_masks, saveexec_needs_whole_inputs_only_for_a_whole_read, bitwise_mask_chain_for_selector_needs_no_exchange, bitwise_mask_with_live_scc_keeps_exchange, bitwise_mask_feeding_whole_read_keeps_exchange, cselect_and_cmov_b64_propagate_lane_masks_and_keep_scc_uniform, vccz_operand_and_odd_alignment_in_bitwise_ops_keep_exchange, loop_exit_reading_scc_keeps_exchange_inside_loop.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 785 passed, 0 failed, 41 ignored. SKIPPED: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • heap_window_out_of_memory_falls_back_to_the_switch_form was skipped with --skip. It fails on main 9e3831e too, not because of this PR: under XCL_REQUIRE_GPU=mesh, runner::skip_test turns every skip except "no wave64" into a failure, including this test's opt-in "no heap windows" skip (XCL_HEAP_WINDOWS unset). Reported as Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

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

Copy link
Copy Markdown

@MiguelMachado-dev this PR carried onto current main, for you to take or leave: Raghav314/xcl x64/exec-local-on-main (81cf0fc, on main ed95117). It is #1111's commit (7c92fcf, unchanged, zondy1i's) and this PR's change as one commit with you as co-author. With it, the direct DXIL path's cold driver build of a split wave64 program is 26 % shorter than on main.

Why it needed more than a rebase: main rewrote x64_masks.rs (operand plans per encoding, liveness solved per basic block, and the same analysis now feeds pixel shaders, #1111 aside). So the change is re-implemented on that structure rather than conflict-resolved:

  • InstFlow gets save_exec, and one transfer function, gen_of, now serves the per-block, per-instruction and reference solvers alike, with your rule for the saved / new EXEC.
  • EXEC-local liveness is a mode, whole_live_out_split / by_pc_split, used only for the split form: the HLSL emitter's split compute, mesh and kernel programs, and the direct DXIL kernel (dxil/kernel.rs). Pixel shaders keep EXEC whole-live as before, since their ballot_px_local holds only the lane's own bit, and DPP / ds_swizzle read another lane's EXEC bit in the quad.
  • v_readfirstlane and ds_(b)permute read EXEC whole in that mode. That is added in the flows, not in uses(), so the per-lane form's use of uses() is unchanged.
  • In the direct path: Lw::write_mask takes EXEC (s126) as local too, and dxil/compact.rs's block key includes EXEC's liveness bits, so two blocks that differ only there are not merged.

Tests (RTX 4090, 617.14, Windows 11, release):

  • Your liveness tests, in the split mode, plus a check that outside it EXEC stays whole-live; your GPU test gpu_split_wave64_predicated_exec_masks (passes on the 4090). The block solver against the reference now runs in both modes, and the synthetic shader gains saveexec / v_cmpx regions.
  • cargo test --release -p xcl --lib -- --test-threads=4: 1235 passed, 1 failed, 26 ignored. The failure, lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier (3 group barriers, 1 expected), fails the same way on plain main ed95117.

Cold driver time, xcl shaders --time-forms (#1830; ShaderCacheControl with the three implicit caches off), direct DXIL, split wave64, heap windows with 4 windows, one cold CreateComputePipelineState per process:

062468c09af883b9 (wave64) DXIL driver build
main ed95117 1,387,708 B 19.9 / 20.0 / 20.0 s
+ #1111 1,337,976 B 17.9 / 18.3 s
+ #1111 + this PR (81cf0fc) 1,253,904 B 14.8 / 14.9 s
76b0a8c7541c6c91 (no half exchanges), + both 636,668 B (unchanged) 7.1 s

For scale, @Kalmarv's upper bound for this program with no exchange at all was 56 → 7.8 s on #2088, so more is left there. I'm looking at #1597 next. Its tree sync (xcl_x_sync_mask) is HLSL-emitter code, so the direct path needs its own version of it.

Not tested: a title run; AMD (native wave64 is not affected: the mode is split-only); the HLSL path's driver time.

AI use: Claude Code (Claude Opus 5.5) ported the change, ran the tests and 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.

6 participants