Skip to content

Recompiler: tighten operand and EXEC checks in wave32_reductions - #2365

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-12f25f1-wave32-reductions
Open

Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-12f25f1-wave32-reductions

Conversation

@Decodere

Copy link
Copy Markdown
Contributor

Part of #1401

Follow-up to 12f25f1 (crates/xcl/src/gpu/recomp/mod.rs).

wave32_reductions replaces the console compiler's wave32 whole-wave reduction sequence with xcl_red_<op>(xcl_seed_<pc>) so waves that are not full still reduce every live lane. Several operand, mask, and EXEC-clobber checks were too loose and could rewrite non-reduction code or sequences whose EXEC was modified mid-section.

What is in it

  • wave32_reductions (crates/xcl/src/gpu/recomp/mod.rs):
    • Require both VGPR operands of each DPP8 (a, b, c) and DPP16 (mirror) step to be v (r == [v, v]), plus mirror ROW_MASK & 0x3 == 0x3 and BANK_MASK == 0xF.
    • Require cross (V_PERMLANEX16_B32) to be Variant::Plain with SRC0 == 256 + v and single destination cw != v; require last to be Variant::Plain writing [v] with inputs strictly {v, cw} (lr == [v, cw] || lr == [cw, v]); and require read (V_READLANE_B32) to be Variant::Plain with SRC0 == 256 + v and SRC1 == 128.
    • Reject open (S_OR_SAVEEXEC_B32) when SDST is in 126..=127 (EXEC_LO / EXEC_HI), and reject any instruction in open + 1..=end that branches/jumps/terminates (F_TERMINATOR | F_BRANCH | F_INDIRECT) or writes EXEC — including implicit OPR_EXEC / OPR_SDST_EXEC outputs (V_CMPX_*, S_*_SAVEEXEC_*, S_ANDN{1,2}_WREXEC_*, S_SUBVECTOR_LOOP_*), explicit SGPR/VOP3/SMEM destinations in 126..=127 (sgpr_uses + ENC_SMEM SDATA), and ENC_VOPC SDWA compare writes to 126..=127.
  • wave32_reduction_tests (crates/xcl/src/gpu/recomp/mod.rs): 2 pure-CPU unit tests covering all 4 valid reduction ops (or / max / and / min) across ROW_MASK 0xF/0x3, both last operand orders, and wave32 PS/VS translate() emission, plus 19 invalid/clobbered shapes verified to be rejected by both wave32_reductions and translate().

Tested

  • Hardware / toolchain: NVIDIA GeForce RTX 4060 8 GB (driver 621.14), Intel Core i5-11400F, 32 GB RAM, Windows 11 build 26200, rustc 1.100.0, DXC 1.9.2609.5, release profile (--release).
  • Failing-first (before fix): cargo test --release -p xcl --lib gpu::recomp::wave32_reduction_tests:: -- --nocapture: 1 passed, 1 failed (invalid_wave32_reduction_shapes_and_exec_writes_are_rejected failed on origin/main).
  • Targeted unit tests (after fix): cargo test --release -p xcl --lib gpu::recomp::wave32_reduction_tests:: -- --nocapture: 2 passed, 0 failed, 0 ignored (0.01 s).
  • cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture: 1286 passed, 0 failed, 46 ignored across 23 test binaries (28 pre-existing SKIPPED lines: 21 no wave64 on RTX 4060, 3 per-lane wave32 refused, 2 no D3D12 debug layer, 1 no heap windows, 1 cannot disable driver cache; 0 skipped in gpu::recomp::wave32_reduction_tests).

Regression run

main:

xcl-smoke v1
commit: 55d64c277be137cb6b47d7528dc6a88082bf573e
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1523 (PresentX 1523)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 14000 MB

PR:

xcl-smoke v1
commit: f5ac68e2c6bcb81a59f8340b5292dc7d6357a4ca
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1429 (PresentX 1429)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14033 MB

Not tested

  • AMD / native wave64 hardware and D3D12 debug-layer test subsets (skipped on this RTX 4060 / non-debug-layer host; wave32_reductions is pure-CPU static RDNA2 analysis in the recompiler).
  • Retail titles other than title: 29640639.

AI use

  • Google Antigravity (Gemini 4 Neon) — audited wave32_reductions, rdna2_spec.rs, and emit.rs, implemented the tightened operand/mask/EXEC checks and failing-first unit tests, and ran the workspace and paired smoke verification.

`wave32_reductions` previously accepted several non-reduction shapes
and mid-section `EXEC` mutations in wave32 VS/PS shaders:

- DPP8 (`a, b, c`) and DPP16 (`mirror`) steps checked `r.contains(&v)`
  instead of requiring both operands to be `v` (`r == [v, v]`), and
  `mirror` did not verify `ROW_MASK & 0x3 == 0x3` and `BANK_MASK == 0xF`.
- `V_PERMLANEX16_B32` (`cross`) did not check `Variant::Plain`,
  `SRC0 == 256 + v`, or `dst != v`; `last` checked `r.contains(&v)`
  instead of requiring inputs `{v, cross_dst}`; and `V_READLANE_B32`
  did not check `Variant::Plain` and `SRC0 == 256 + v`.
- `S_OR_SAVEEXEC_B32` (`open`) accepted `SDST` in `126..=127` (writing
  the saved mask back into `EXEC`), and the `EXEC`-clobber check inside
  `open + 1..=end` missed implicit/SMEM/VOP3/SDWA `EXEC` writers such
  as `V_CMPX_*`, `S_ANDN{1,2}_WREXEC_*`, `S_SUBVECTOR_LOOP_*`, and
  `ENC_SMEM` loads targeting `EXEC_LO`/`EXEC_HI`.

Enforce exact operand/mask matching across every reduction step and
reject any `EXEC` write or branch/indirect transfer inside the section.

Part of xcl-dev#1401

Assisted-by: Google Antigravity (Gemini 4 Neon)
@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) test report on exact head f5ac68e2c6bcb81a59f8340b5292dc7d6357a4ca (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1284 passed, 2 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record). All native wave64 GPU tests ran and passed.
    • Both PR tests passed: gpu::recomp::wave32_reduction_tests::valid_wave32_reductions_match_and_translate and invalid_wave32_reduction_shapes_and_exec_writes_are_rejected.
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599) are pre-existing on unmodified main on this GPU.

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release)

xcl-smoke v1
commit: f5ac68e2c6bcb81a59f8340b5292dc7d6357a4ca
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1619 (PresentX 1619)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14455 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • D3D12 debug layer; Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@Decodere Decodere closed this Nov 25, 2026
@Decodere Decodere reopened this Nov 25, 2026
@Decodere Decodere closed this Nov 25, 2026
@Decodere Decodere reopened this Nov 25, 2026
@SlopTart

Copy link
Copy Markdown

Tested: current PR head merged onto current origin/main (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).
suite: 145/3 = the three known baseline failures on this lane (fuzz_validate_and_gpu_2 seed 1003, gpu_nonfused_mad_and_mac_prevent_fma_contraction, gpu_depth_buffer_created_for_unordered_access_is_placed) (this head's new gpu_ wave32 f16/f32 min/max reduction tests are among the passes). Targeted run of the new invalid-wave32-reduction fuzz: passed.

Not tested: retail titles (no title data on this lane, counts only).

AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No concrete defect found. The recognizer validates the relevant DPP/permlane/readlane shapes and expanded EXEC-write cases; unit coverage is broad and current Windows CI plus the RTX smoke pair are green. Residual validation is the disclosed lack of AMD/native-wave64 testing, but the changed recognizer is CPU-side static analysis. I found no blocker.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 26, 2026
@upipibi

upipibi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

NVIDIA test report for f5ac68e: RTX 3070 8 GB (Ampere, driver 616.56), Windows 11 26100, Rust 1.100.0, debug.

  • cargo test -p xcl --lib -- --skip hle::xaudio2 --test-threads=4 (the hle::xaudio2 tests hang on this machine, on main too):
  • this PR: 1208 passed, 0 failed, 26 ignored; 25 SKIPPED lines (21 "no wave64", 3 f16/f32 per-lane forms refused for gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics, 1 PSO measurement needing Developer Mode), the same lines as on the base.
  • base 55d64c2: 1206 passed, 0 failed, 26 ignored; the same 25 SKIPPED lines. The two extra passes are this PR's new tests.
  • gpu::recomp::wave32_reduction_tests (valid_wave32_reductions_match_and_translate, invalid_wave32_reduction_shapes_and_exec_writes_are_rejected) 3 times with --test-threads=1 --nocapture: 2 passed, 0 failed each run.

Lib tests only; no title run.

AI-assisted (Claude Code, Claude Opus 5.5).

@LocranKing

Copy link
Copy Markdown

Independent NVIDIA test report on exact head f5ac68e2c6bcb81a59f8340b5292dc7d6357a4ca (clean detached checkout, no local changes).

Tested

  • Hardware: NVIDIA GeForce RTX 3060 Ti 8 GB (Ampere, wave32, driver 32.0.16.2140 / 621.40), AMD Ryzen 5 5500, 32 GB RAM, Windows 11 Home (build 26300), Rust 1.100.0 (stable-x86_64-pc-windows-msvc), Windows SDK 10.0.26100.0.
  • cargo build --workspace + cargo test --workspace --no-fail-fast -- --test-threads=4 (debug): 1286 passed, 0 failed, 46 ignored (xcl --lib: 1217 passed, 0 failed, 26 ignored).
  • 28 SKIPPED GPU tests on this adapter: 21 wave64-only (no wave64), 3 wave32 per-lane f16/f32 semantics, 1 no heap windows, 2 D3D12 debug layer (no d3d12SDKLayers.dll / 0x887A002D), 1 cannot disable driver cache without Developer Mode (0x887A002D).

Regression run
scripts/smoke.ps1 -Seconds 60, release builds of origin/main (b49be18) and this PR's head (f5ac68e):

main:

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

PR:

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

Not tested

  • AMD / Intel / Linux GPUs; XCL_SAMPLE_* tests; the 60 s smoke run covers boot/intro/menus and does not enter the 3D world.

AI use

  • Antigravity (Gemini 4 Hydrogen) ran the builds, test suite, and smoke.ps1 commands on this machine and drafted this report from the captured outputs.

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.

8 participants