Skip to content

Recompiler: solve split-wave64 mask liveness per basic block with precomputed operand plans - #1090

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
TG0000:perf/x64-masks-block-liveness
Nov 25, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
TG0000:perf/x64-masks-block-liveness

Conversation

@TG0000

@TG0000 TG0000 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

What is in it

Accelerate split-wave64 SGPR mask liveness analysis (crates/xcl/src/gpu/recomp/x64_masks.rs), which runs during shader translation for wave64 compute, mesh, and geometry programs on 32-lane-wave GPUs:

  • Basic-block liveness solver: Partition instructions into basic blocks (splitting at branch targets, after terminators/branches, and at loop boundaries so every instruction in a block shares the exact same enclosing loops and LOOP_GUARD exit mask). Because (X & !k) | X == X for bitmasks, the constant per-block exit mask collapses out of intra-block composition, reducing the backward fixpoint from instruction granularity (O(iters * N)) to basic-block granularity (O(iters * B)) with a single linear backward pass per block to reconstruct live_out.
  • Zero per-instruction heap allocations: Replace the BTreeMap<u64, usize> PC table, per-instruction Vec<usize> successor lists, and per-instruction Vec<Option<usize>> loop-exit lists with binary search on sorted PCs, an inline BlockSucc enum, and a single flat exit_targets buffer populated via an O(B * depth + L log B) sweep.
  • O(L log L) nested loop-range fast path: Detect properly nested backward-jump intervals in a single stack sweep, falling back to the exact original merge only for rare irreducible CFGs with partial overlaps.
  • Precomputed per-encoding operand plans (UsePlanTable): Lazily precompute static bit-range descriptors and fixed register masks per (InstEnc, Encoding) in a flat open-addressed table, eliminating per-instruction string .contains() scans and linear Encoding::field lookups in uses().

Release benchmark (cargo test --release --lib gpu::recomp::x64_masks::tests::bench_whole_live_out -- --ignored --nocapture, synthetic multi-loop shaders with nested loops, diamond branches, compares, v_cndmask, and carry chains; bit-for-bit verified against the original solver):

Synthetic shader Original (whole_live_out_reference) Optimized (whole_live_out) Speedup
928 insts (8 outer loops) 669.7 us 28.7 us 23.37x
4,635 insts (40 outer loops) 2,890.1 us 238.5 us 12.12x
9,268 insts (80 outer loops) 6,198.4 us 556.8 us 11.13x

Tested

  • Hardware / toolchain: AMD Radeon RX 6800, Windows x64, rustc 1.100.0 (0ef1bc386 2026-11-09) (stable-x86_64-pc-windows-msvc), debug and release.
  • cargo test --lib gpu::recomp::x64_masks: 19 passed, 0 failed, 1 ignored (manual release benchmark). Includes exhaustive equivalence check of uses() vs uses_fallback() across every RDNA2 instruction and encoding, 200-case fuzz check of nested_loop_ranges() against the quadratic merge, and bit-for-bit whole_live_out() equivalence across synthetic multi-loop shaders for both end_reads_all = false and true.
  • cargo test --release --lib gpu::recomp::x64_masks::tests::bench_whole_live_out -- --ignored --nocapture: 1 passed, 0 failed (11.13x–23.37x speedup).
  • cargo build --release -p xcl: succeeded cleanly.

Regression run

Baseline (origin/main):

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 954 (PresentX 954)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15118 MB

PR (7bea019319cc08a54cdb3c9e49a0941d88b35283):

xcl-smoke v1
commit: 7bea019319cc08a54cdb3c9e49a0941d88b35283
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 1034 (PresentX 1034)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15103 MB

Not tested

  • Full cargo test --workspace and live split-wave64 shader compilation on an NVIDIA (wave32-only) GPU; covered by the exhaustive unit and bit-for-bit equivalence tests above.

AI use

  • Assisted by Gemini 4 Neon: designed and implemented the basic-block liveness solver, precomputed UsePlanTable, equivalence tests, and release benchmark, and ran local builds, unit tests, and the retail smoke run.

…computed operand plans

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
@fromthemoonx

Copy link
Copy Markdown

NVIDIA (32-lane) run, since Not tested lists the full suite and live split-wave64 compilation on a wave32-only GPU.

Tested

  • NVIDIA GeForce RTX 3060 12 GB (32-lane waves only, so the translator uses split wave64), driver 32.0.16.1088; AMD Ryzen 7 5700X; native Windows 11 Pro 26H2 (build 26300.9974), Graphics Tools installed; rustc 1.100.0 stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17

  • Exact head 7bea019319cc08a54cdb3c9e49a0941d88b35283, which is on current main 47efa2e (so this is also the merged result): cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4, debug: 744 passed, 0 failed, 42 ignored (lib 701 / 0 / 22; the extra ignored test is the new benchmark)

  • cargo test -p xcl --lib gpu::recomp::x64_masks: 19 passed, 1 ignored. The three new equivalence tests passed: use_plan_matches_fallback_across_all_rdna2_instructions, nested_loop_ranges_matches_quadratic_merge_on_overlapping_intervals, block_liveness_matches_reference_bit_for_bit.

  • Live split-wave64 translation on this GPU: x64_masks::by_pc feeds x64_whole_live in recomp/mod.rs. I ran the three new tests together with every gpu_split_wave64_* and gpu_wave64_* GPU test (wave64 programs translated with this liveness, compiled by DXC and run on the RTX 3060), 10 runs: 10 of 10 passed (11 tests each time)

  • Release benchmark, your command (cargo test --release --lib gpu::recomp::x64_masks::tests::bench_whole_live_out -- --ignored --nocapture), 3 runs:

    insts ref (µs) opt (µs) speed-up
    928 456–468 28.1–28.9 16.1–16.6×
    4 635 2 537–2 680 212–252 10.6–12.0×
    9 268 5 493–5 589 506–527 10.4–11.0×

    Same order as your 11–23×, a bit lower on this CPU.

  • SKIPPED (no wave64 on this adapter): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware

Not tested

  • A retail shader pack (none here), so the effect on real translation time is not measured; the speed-up above is the synthetic benchmark's.

AI use

  • Claude Code (Claude Opus 5.5) ran the builds, tests and benchmark on the machine above and wrote this report from the output.

@towiice towiice left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested:

  • Hardware: NVIDIA GeForce GTX 1650 SUPER (Turing TU116, 4 GB VRAM, wave32, driver 610.88), Windows 11 x64 (26H2 / build 26300), DXC v1.9.2609 (01b62ad4), toolchain stable-x86_64-pc-windows-gnullvm (llvm-mingw 23.1.6), debug build.
  • cargo test -p xcl --lib gpu::recomp::x64_masks: 19 passed, 0 failed, 1 ignored (0.09 s), including block_liveness_matches_reference_bit_for_bit, use_plan_matches_fallback_across_all_rdna2_instructions, and nested_loop_ranges_matches_quadratic_merge_on_overlapping_intervals.
  • cargo test -p xcl --lib gpu_split_wave64: 5 passed, 0 failed (1.50 s) on wave32 hardware:
    • gpu_split_wave64_lane_local_masks
    • gpu_split_wave64_cross_half_operations
    • gpu_split_wave64_local_and_exchanged_masks_in_diverging_waves
    • gpu_split_wave64_waves_diverge
    • gpu_split_wave64_masks_read_whole_after_partial_writes

Not tested: release benchmark (bench_whole_live_out), full workspace suite, retail titles (smoke.ps1).

@SlopTart

Copy link
Copy Markdown

Wine/RDNA3 datapoint: merged this head (lane merge 7bea019 = head, fast-forward onto 47efa2e) and ran the forced-split cluster (XCL_SPLIT_WAVE64=1, --test-threads=1, release) for 3 reps, plain-main control in the same session.

  • gpu_split_wave64_local_and_exchanged_masks_in_diverging_waves - 0/3 (control 0/3)
  • gpu_split_wave64_masks_read_whole_after_partial_writes - 0/3 (control 0/3)
  • gpu_split_wave64_waves_diverge - 1/3 (control 0/3; inside this rig's flake band for that test)
  • gpu_split_wave64_lane_local_masks - 6/6 total both lanes

Per-block mask liveness reads fine on native wave64 hardware, but it does not move the nondeterministic exchange cluster documented in my #772 follow-up. One mechanical note: this head and #1111 both rewrite x64_masks.rs and conflict when merged together, so whoever lands second needs a rebase, and the two fixes cannot be validated in combination yet.

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.

@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 7bea019 (base 47efa2e) 744 0 42 2 (no wave64)
Head merged into main 930e8b4 754 0 42 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
  • use_plan_matches_fallback_across_all_rdna2_instructions, nested_loop_ranges_matches_quadratic_merge_on_overlapping_intervals, block_liveness_matches_reference_bit_for_bit: ok (bench_whole_live_out ignored, not run)
  • 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.

@tatazildo

Copy link
Copy Markdown

Independently tested the Wave64 mask-liveness optimization on commit 1a0bbe3.

Environment:

  • Intel Core i9-13900K
  • NVIDIA RTX 3080 Ti
  • 64 GB DDR4
  • Windows 11 Pro
Instructions Reference Optimized Speedup
928 309.3 us 18.7 us 16.57x
4635 1769.1 us 131.6 us 13.45x
9268 3883.5 us 296.1 us 13.12x

The benchmark passed, including the equality assertions between the reference and optimized implementations.

ChatGPT assisted with the testing procedure and report preparation.

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.

7 participants