Skip to content

Recompiler: elide EXEC masking where all lanes are active and cache lane active bit - #1356

Open
XaviFortes wants to merge 1 commit into
xcl-dev:mainfrom
XaviFortes:recomp-exec-active
Open

XaviFortes wants to merge 1 commit into
xcl-dev:mainfrom
XaviFortes:recomp-exec-active

Conversation

@XaviFortes

Copy link
Copy Markdown
Contributor

Addresses #1269 (EXEC emulation optimization).

What changed

  1. All-active EXEC elision (exec_active.rs, emit.rs, mod.rs):
    • Adds a forward must-dataflow pass (exec_active::all_active_pcs) over decoded RDNA2 instructions that proves which PCs have EXEC == entry_exec (ballot(true) at entry, so every executing lane is active).
    • Tracks EXEC and saved-EXEC SGPRs across s_*_saveexec_b64/_b32, s_mov_b64/_b32 (save/copy/restore), s_or_b64/_b32 restores, s_wqm_b64/_b32, wave64 pair clobbering, s_movrel*, and LOOP_GUARD loop-head exit edges. Any non-fetch F_INDIRECT branch makes the whole shader conservative.
    • Enabled for Vertex, Pixel, Compute, and Mesh shaders (Kernel and Geometry stay conservative; XCL_NO_EXEC_ELIDE=1 disables elision for A/B debugging).
    • At proven all-active PCs:
      • VGPR writes emit vN = val; directly instead of vN = select(lanebit(exec_lo, exec_hi), val, vN);, eliminating both the per-instruction select/lanebit IR and the false read dependency on the old VGPR value.
      • Lane-mask writes emit ballot(cond) instead of ballot(and(lanebit(...), cond)).
      • DPP writes emit select(en, val, v) instead of select(and(act, en), val, v).
  2. Cached lane-active predicate bool ea (emit.rs):
    • Where EXEC may be narrowed (divergent regions, Kernel, Geometry), caches the current lane's EXEC bit in a local bool ea refreshed only when exec_lo/exec_hi is written (sync_ea()), instead of recomputing lanebit(exec_lo, exec_hi) on every VALU instruction.

Benchmark (retail_translation_survey, 1-in-50 sample of retail shaders.rpf, 4 DXC threads, release build)

533 FSSM variants (54 CS, 4 GS, 183 MS/NGG, 242 PS, 2 VS/ES, 48 VS; 917,308 RDNA2 instructions), DXC 1.8.2502.11:

Metric main (930e8b4) This PR (621e6ab) Delta
Wall time 230.0 s 172.3 s -25.1% (1.33× faster)
Total DXC CPU time 860 s 638 s -25.8% (-222 s)
Median DXC time 0.51 s 0.35 s -31.4% (1.46× faster)
p90 DXC time 4.25 s 2.98 s -29.9% (1.43× faster)
Structured mean (531 shaders) 1.53 s 1.13 s -26.1%
Max (CS_RaytracingResolve_b1139868) 35.81 s 30.87 s -13.8%
DXC errors 0 / 533 0 / 533 100% pass
Tested
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 on Windows 11 (10.0.26200.0), AMD Radeon RX 7900 XT, DXC 1.8.2502.11: 756 passed, 0 failed, 41 ignored, 0 SKIPPED.
  • Added 4 unit tests in gpu::recomp::exec_active::tests (straight-line all-active, s_and_saveexec_b64 + s_or_b64 restore, wave32 s_and_saveexec_b32 + s_mov_b32 restore, and clobbering the high half of a saved wave64 pair) plus end-to-end GPU test gpu_exec_elide_divergent_and_restored_compute verifying both HLSL shape and per-lane GPU output.
  • retail_translation_survey with XCL_SURVEY_EVERY=50 and XCL_SURVEY_DXC=1: 533/533 variants translated and compiled with 0 DXC errors.
    Regression run
    Baseline (main ancestor 4017f8ff8faaae6007fd83910d230a027dd85a33):
xcl-smoke v1
commit: 4017f8ff8faaae6007fd83910d230a027dd85a33
gpu: AMD Radeon RX 7900 XT
seconds: 60
exit: 0x0
frames shown: 1195 (PresentX 1195)
presents per 2 s (last 3): 56 54 57
device removals: 0
crashes: 0
peak commit: 14950 MB

PR (recomp-exec-active 621e6abad1075703fe74cce3961df439637917ee):

xcl-smoke v1
commit: 621e6abad1075703fe74cce3961df439637917ee
gpu: AMD Radeon RX 7900 XT
seconds: 60
exit: 0x0
frames shown: 1458 (PresentX 1458)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17273 MB

Not tested

  • NVIDIA or Intel GPUs (tested on AMD Radeon RX 7900 XT with native wave64; split-wave64 paths were exercised by unit/GPU tests).
  • Full 100% shaders.rpf DXC sweep (sampled 1-in-50 = 533 shaders across all stages).
    AI use
  • Implemented, tested, and benchmarked with Antigravity with Gemini 4 Neon.

…ane active bit

Add a forward must-dataflow pass (exec_active) that proves which PCs in Vertex/Pixel/Compute/Mesh shaders have EXEC equal to its entry value (ballot(true), so every executing lane is active).

- Where all lanes are proven active, VGPR writes emit direct assignments (vN = val;) instead of vN = select(lanebit(exec_lo, exec_hi), val, vN);, eliminating per-instruction select/lanebit IR and false read dependencies on the previous VGPR value; lane-mask writes emit ballot(cond) directly.
- Where EXEC may be narrowed, cache the per-lane active predicate in a local bool ea refreshed only when EXEC is written, instead of recomputing lanebit(exec_lo, exec_hi) on every VALU instruction.
- Mode::Kernel and Mode::Geometry stay conservative (cached ea only); XCL_NO_EXEC_ELIDE=1 disables all-active elision for A/B debugging.

Assisted-by: Antigravity (Gemini 4 Neon)
@DarkPanda69

Copy link
Copy Markdown

NVIDIA run, which this PR lists as not tested: one existing split-wave64 test fails with this PR.

Tested: head 621e6ab applied on its base main 930e8b4, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17.
cargo test -p xcl --lib -- gpu::recomp --test-threads=4:

  • NVIDIA RTX 3060, driver 32.0.16.1088, waves 32 only (split form): 193 passed, 1 failed, 18 ignored, 2 SKIPPED (no wave64). gpu_exec_elide_divergent_and_restored_compute ok.
  • AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010, native wave64: 194 passed, 0 failed, 18 ignored, 0 SKIPPED.

The failure, gpu::recomp::tests::gpu_split_wave64_local_and_exchanged_masks_in_diverging_waves:

panicked at crates\xcl\src\gpu\recomp\tests.rs:5951:13:
assertion `left == right` failed: the v_cmp: read whole by the odd waves
  left: 0
 right: 1
  • cargo test -p xcl --lib -- gpu_split_wave64_local_and_exchanged_masks_in_diverging_waves on the RTX 3060: main 930e8b4 passes 3/3, with this PR it fails 3/3.
  • On the RX 9070 XT it fails the same way with XCL_SPLIT_WAVE64=1, so it looks like the split wave64 form, not the adapter.

Not tested: the whole workspace suite; a title.

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

@futurepro62

futurepro62 commented Nov 24, 2026 •

Copy link
Copy Markdown

Following up on @DarkPanda69's split-wave64 failure: same result here (RTX 5070 Ti, driver 616.64, waves 32 only, head 621e6ab; fails 3 of 3, main 930e8b4 passes 3 of 3), and it looks like the test's expected HLSL text is out of date, not a wrong result.

  • The two if runner::split_wave64() asserts count = xcl_x_ballot(and( (1) and = xcl_x_ballot_local(and( (2). With EXEC known to be full in that program, this PR emits uint2 t9 = xcl_x_ballot(s13 > v2);, xcl_x_ballot_local(t13 < v8) and xcl_x_ballot_local((t15w >> 32) != 0ull) with no and(lanebit(exec_lo, exec_hi), ...), so both counts are 0. That's the masking this PR is meant to drop.
  • With just those two asserts removed locally, the rest of the test (the per-lane counts, odd-wave sums and 64-bit carries against the reference, both dispatch shapes) passes 2 of 2 on this card.
  • So counting = xcl_x_ballot( / = xcl_x_ballot_local( instead should make it pass while still checking which ballots are local.
  • AMD Radeon iGPU of the 9800X3D (RDNA2, native wave64, XCL_ADAPTER=radeon), full workspace suite: 756 passed, 0 failed, 41 ignored, no skips.
  • On NVIDIA, the full workspace suite otherwise: 711 passed in the xcl lib before that failure stopped cargo, the 2 usual wave64 skips.

AI use

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

@ArturoWolff

Copy link
Copy Markdown

Split-wave64 Compute, RTX 4060 / Proton: inactive lanes kept their previous values after independently narrowing and restoring the two EXEC halves. This is a separate generated shader, not a rerun of the ballot-text assertion reported above.

Tested 930e8b49c1c2ec683d22c724a398b39111cd0e56 and 621e6abad1075703fe74cce3961df439637917ee. Three 64-lane workgroups reached the same join with different masks: all lanes, upper half only, lower half only. Head kept the guard there and updated exactly those lanes. After restoring an intact saved mask pair, head emitted a direct assignment, and all 64 lanes in each group updated. Restoring just one half earlier preserved the sparse mask in the other half. Base guarded all 13 vector writes; head elided six. Both real emitters' unedited output was compiled and dispatched.

Tested: one dispatch per revision; each matched an independent CPU reference for all 192 lane outputs and 80 untouched sentinel words. Ryzen 5 5600, RTX 4060, NVIDIA 620.73.04, GE-Proton11-14, vkd3d-proton 4522cc1a8b1347f+, DXC 1.9.2609.5. Offline Windows-target release builds: cargo build --offline --locked -j1 --release --target x86_64-pc-windows-gnullvm -p xcl --lib; linked the same private fixture to each build and ran emit, compile, pso_readback with --exact --nocapture --test-threads=1. Six invocations passed, none failed/ignored/skipped, two filtered per invocation.

Not tested: native wave64, graphics stages, other control flow, full suite, retail loading or performance. This does not clear the separately reported suite failure.

AI use: Hermes Agent, gpt-6.2-astra (fixture, execution, verification and report).

@HKEY-Funk-Machine

Copy link
Copy Markdown

Test report: #1356 at 621e6ab on AMD RDNA4 (Windows), full-title intro: driver time, not DXC time

Your numbers cover DXC. I checked the other half on AMD, since @Sr-0w saw the AMD driver get slower when exec selects were removed (#1269).

Tested

main 930e8b4 #1356 621e6ab
Result watchdog +0x23cf683 at 2m22s same watchdog at 1m37s
Compute PSOs created 250 242
Total CreateComputePipelineState time 204.1 s 218.3 s
Mean per PSO 0.82 s 0.90 s (+10 %)
PSOs ≥ 1 s 35 42
Slowest PSO 27.6 s (360 KB) 18.6 s (362 KB)
Total DXIL 12.5 MB 14.1 MB (+13 %)

On this path the AMD driver doesn't get faster with #1356. Mean PSO time is up about 10 %, and the total DXIL from the intro's compute programs is about 13 % larger, which I didn't expect. The slowest single PSO did drop, from 27.6 s to 18.6 s. The intro still hits the same watchdog; crash time varies between runs, so I wouldn't read much into 1m37s vs 2m22s.

Not tested

  • Per-program matched comparison: the logs don't name the program next to each PSO time, so these are per-run totals.
  • Only one run per build; no DXC timings on this machine; no GPU output or correctness checks; the test suite wasn't run.

AI use: Claude Code (Claude Opus 5.5) ran the builds and the game, extracted the timings from the XCL logs, and drafted this report.

@mastrr9

mastrr9 commented Nov 24, 2026

Copy link
Copy Markdown

RTX 5080 (wave32 / split-wave64) test report for head 621e6abad1075703fe74cce3961df439637917ee (Windows 11, DXC 1.9.2602.17, Rust MSVC, debug build, clean worktree):

  • cargo test -p xcl --lib -- gpu::recomp --test-threads=4: 193 passed, 1 failed, 18 ignored (0 new compiler warnings).
  • Failure: gpu::recomp::tests::gpu_split_wave64_local_and_exchanged_masks_in_diverging_waves panicked at crates\xcl\src\gpu\recomp\tests.rs:5951 (single run with 4 threads; flagging in case the cached ea / EXEC elision interacts with split-wave64 diverging mask exchanges).

Not tested: AMD native wave64, retail smoke (scripts/smoke.ps1).
AI use: T3 Code (Antigravity / Claude Sonnet 5.5) built the worktree, ran the test suite on our RTX 5080, and drafted this comment from the output.

@Creaa

Creaa commented Nov 24, 2026

Copy link
Copy Markdown

Test report: 621e6ab on an RTX 4070 (32-lane waves, so the split wave64 form). The EXEC elision hangs the GPU when the lib tests run in parallel; one split-wave64 test also fails on its HLSL pattern.

Setup: RTX 4070 12 GB (driver 617.14), i7-13700F, 32 GB RAM, Windows 11 build 26300, Rust 1.100.0, DXC 1.9.2602.17, debug build. main 930e8b4 run the same way for comparison.

1. GPU hang (0x887A0006) with parallel tests, caused by the elision

cargo test -p xcl --lib -- --test-threads=4, runs alternated on the same machine:

tree runs device hung
main 930e8b4 3 0
#1356 621e6ab 6 4
#1356, XCL_NO_EXEC_ELIDE=1 4 0
#1356, --skip gpu_sparse_vram_descriptors_buffers_and_xmem 4 0
#1356, --test-threads=1 2 0
  • In every hung run gpu_sparse_vram_descriptors_buffers_and_xmem fails first (submit 1 lane 0 mismatch, left 0, right 1077: the output was not written within its 5 s fence wait). The test the device removal lands on varies (gpu_wave32_and_wave64_src_vccz_execz, gpu_valu_16_and_64_bit), and 8–9 later GPU tests fail with 0x887A0005 after it.
  • Run alone, that test passes (3/3 on both trees).
  • Its HLSL (split wave64, 64 threads, 4 windows) differs from main in three lines only: t8_act, the v_add_nc_u32 write and the buffer_store_dword guard become true / a plain assignment. With 64 threads all lanes are active, so the change looks right by itself; I did not find why the shader then does not finish under concurrent GPU load. One guess, not checked: with no guard left, exec_lo/exec_hi are dead after the entry xcl_x_ballot(true), and DXC may compile that cross-half exchange differently. The DXIL of both versions would tell.

2. gpu_split_wave64_local_and_exchanged_masks_in_diverging_waves fails (every run)

The assertion t.hlsl.matches("= xcl_x_ballot(and(").count() == 1 gets 0: the v_cmp is now uint2 t9 = xcl_x_ballot(s13 > v2);. This branch only runs when runner::split_wave64(), so it does not run on a 64-lane AMD GPU. With the pattern changed locally to accept the unguarded form, the test passes, including its GPU results; the exchanged/local split is unchanged (one xcl_x_ballot, two xcl_x_ballot_local).

3. Compile cost on a sample (67 compute programs, every 40th of a retail pack's 2 689, xcl shaders <folder> --precompile --only cs [--pipelines], release, 4 windows, split wave64, empty XCL caches, one run each)

translate + DXC DXIL total driver (--pipelines)
main 67.5 s 24 182 100 B 346.0 s
#1356 64.9 s 24 188 956 B 324.6 s

On this sample the difference is within what I would expect from run-to-run noise; one run each, so no claim either way. The sample has few programs large enough for -O1/-O0, where your survey found the gain.

Full suite: cargo test --workspace --no-fail-fast -- --test-threads=4: 745 passed, 11 failed, 41 ignored (the hang above); SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64), plus six "no GPU" after the device was lost.

Not tested: AMD, other NVIDIA cards, a title run.

AI use: Claude Code (Claude Opus 5.5) ran the tests and measurements on my machine and drafted this comment; I checked it before posting.

@upipibi

upipibi commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

@Creaa I think I found the cause of the parallel-run failure of gpu_sparse_vram_descriptors_buffers_and_xmem, and it is not this PR's elision. It is a bug in the test that this PR's extra tests expose.

The test encodes its three S_LOADs without SOFFSET, so the field is 0. That is s0, not NULL (0x7D), and the translation shows it: … + (uint64_t)(int64_t)(int)0x00000000u + (uint64_t)s0 on every scalar load. s0 is the low dword of arg_table. So each load reads at its base plus arg_table's low bits, which is right only while arg_table happens to sit at a 4 GiB-aligned offset of window 3, i.e. when no other test allocated there first. In a parallel run it can land elsewhere: the descriptors come from the wrong place, and the output is never written.

Reproduced on main 930e8b4 alone (RTX 3070, the test run by itself): with one extra u.alloc(0x1_0000, 256) in window 3 before arg_table, it fails with exactly your message, submit 1 lane 0 mismatch, left 0, right 1077. Without the extra allocation it passes. With SOFFSET set to 0x7D it passes both ways. This PR adds tests that allocate in parallel, which would explain why it shows up here and not on main. I have not reproduced the 0x887A0006 that followed, but loads and stores through garbage descriptors into the sparse windows fit it.

Fix in #1456: SOFFSET NULL on the three loads, and a block allocated ahead of the table so a load that adds s0 fails on every run, not only in parallel ones. The HLSL diff you listed (t8_act, the write, the store guard) is the same as here and harmless with 64 active lanes.

AI-assisted (Claude Code).

@DavidM1911

Copy link
Copy Markdown
Contributor

Test report — RTX 3060 Ti (Windows 11), branch merged with current main (b7aa9f3):

cargo test -p xcl --lib -- --test-threads=1: 1 failure (726 passed, 1 failed, 21 ignored):

gpu::recomp::tests::gpu_split_wave64_local_and_exchanged_masks_in_diverging_waves
assertion `left == right` failed: the v_cmp: read whole by the odd waves
  left: 0
 right: 1

The failing test is pre-existing on main — the EXEC-masking elision / lane-active caching appears to drop a mask update that a v_cmp in diverging split-wave64 waves relies on. Reproduces consistently single-threaded and standalone (cargo test -p xcl --lib gpu_split_wave64_local_and_exchanged_masks_in_diverging_waves).

@LocranKing

Copy link
Copy Markdown

Independent Windows 11 + NVIDIA GeForce RTX 3060 Ti (8 GB, wave32) test and retail smoke report on clean head 621e6abad1075703fe74cce3961df439637917ee.

Confirms the known wave32 / split-wave64 test failure (gpu::recomp::tests::gpu_split_wave64_local_and_exchanged_masks_in_diverging_waves, tests.rs:5951, left: 0, right: 1 on the v_cmp: read whole by the odd waves) reported by @DarkPanda69, @futurepro62, @Creaa, and @DavidM1911. All other 755 workspace tests passed, and the 60 s retail smoke run completed cleanly with no crashes or device removals.

Tested

  • Commit: 621e6abad1075703fe74cce3961df439637917ee (clean tree, merge-base 930e8b4)
  • Hardware / software: Windows 11 Home Build 26200, AMD Ryzen 5 5500, 31.8 GB RAM, NVIDIA GeForce RTX 3060 Ti (8024 MiB VRAM, driver 32.0.16.2101), rustc 1.100.0 (x86_64-pc-windows-msvc, MSVC 14.44.35207), DXC 1.9.2602.17 (SDK 10.0.26100.0), --release
  • cargo build --release --workspace: ok (exit 0)
  • cargo test --workspace --release --no-fail-fast -- --test-threads=4: 755 passed, 1 failed, 41 ignored, exit 101
    • Failed: gpu::recomp::tests::gpu_split_wave64_local_and_exchanged_masks_in_diverging_waves (crates\xcl\src\gpu\recomp\tests.rs:5951:13, left: 0, right: 1)
    • SKIPPED (no wave64): gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware

Regression run
main baseline (b7aa9f3bd212088e0d927439284dc5ed325ce3c7):

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

PR head (621e6abad1075703fe74cce3961df439637917ee):

xcl-smoke v1
commit: 621e6abad1075703fe74cce3961df439637917ee
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1577 (PresentX 1577)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14724 MB

Not tested: debug build, AMD / native wave64 hardware, extended gameplay past 60 s.

AI use: Antigravity (Gemini 4 Neon) ran the build, tests, and smoke runs and drafted this report from the command outputs.

@Creaa

Creaa commented Nov 24, 2026

Copy link
Copy Markdown

Follow-up to my report above: the GPU hang is not your elision's logic. The elision exposes it, and main shows the same failure when that test's shader changes in any equivalent way. I wrote "caused by the elision" above; that was too strong.

Same machine (RTX 4070, driver 617.14, split wave64). cargo test -p xcl --lib -- --test-threads=8, which fails gpu_sparse_vram_descriptors_buffers_and_xmem more often than 4 threads:

tree sparse test failed device hung
main 930e8b4 0 / 3 (16 threads) 0
main, that test's HLSL with your three changed lines (t8_act = true, the plain v2 write, if (true) store guard) 3 / 4 1
main, only one of the three lines changed, for each of the three 2/4, 1/4, 2/4 0, 1, 0
main, a comment appended to the HLSL instead (same DXIL) 0 / 4 0
this PR, XCL_WAVE64_SPIN=0 2 / 6 0
this PR, default 3 / 6 1
  • Any change of that program's DXIL is enough, including ones that keep its meaning; the same DXIL is not. Alone, the test passes on every tree.
  • In a failing run the test's own dispatch does not finish: with a timer around its fence wait, one run returned after 2.098 s with GetCompletedValue() = u64::MAX, so the device was removed under it (TDR).
  • With XCL_WAVE64_SPIN=0 (a group barrier instead of the arrival counters) there was no hang in 6 runs, but the test still failed in 2 of them.
  • What makes that 64-thread split-wave64 dispatch not finish when other tests use the GPU, I have not found. It looks like a fragility of that test's path (the real D3D12.X device, sparse windows, the exchange) that is there on main too, so it probably deserves its own issue rather than blocking this PR.

The other point of my report stands: gpu_split_wave64_local_and_exchanged_masks_in_diverging_waves still looks for = xcl_x_ballot(and(, which the elided v_cmp no longer has, so it fails on every 32-lane GPU.

Separately, on the 31 compute programs of my #680 report, replacing every EXEC guard by true (an upper bound, not your change) cut the cold NVIDIA driver time by 29 % (#1269 (comment)), so on this card the guards are worth removing.

AI use: Claude Code (Claude Opus 5.5) ran the experiments on my machine and drafted this comment; I checked it before posting.

@ivall ivall added the goal:world-load Bears on the retail title getting past world loading label Nov 24, 2026
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.