Recompiler: tighten operand and EXEC checks in wave32_reductions #2355
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2365"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-25T16:47:17Z.
Part of #1401
Follow-up to
12f25f1(crates/xcl/src/gpu/recomp/mod.rs).wave32_reductionsreplaces the console compiler's wave32 whole-wave reduction sequence withxcl_red_<op>(xcl_seed_<pc>)so waves that are not full still reduce every live lane. Several operand, mask, andEXEC-clobber checks were too loose and could rewrite non-reduction code or sequences whoseEXECwas modified mid-section.What is in it
wave32_reductions(crates/xcl/src/gpu/recomp/mod.rs):a,b,c) and DPP16 (mirror) step to bev(r == [v, v]), plusmirrorROW_MASK & 0x3 == 0x3andBANK_MASK == 0xF.cross(V_PERMLANEX16_B32) to beVariant::PlainwithSRC0 == 256 + vand single destinationcw != v; requirelastto beVariant::Plainwriting[v]with inputs strictly{v, cw}(lr == [v, cw] || lr == [cw, v]); and requireread(V_READLANE_B32) to beVariant::PlainwithSRC0 == 256 + vandSRC1 == 128.open(S_OR_SAVEEXEC_B32) whenSDSTis in126..=127(EXEC_LO/EXEC_HI), and reject any instruction inopen + 1..=endthat branches/jumps/terminates (F_TERMINATOR | F_BRANCH | F_INDIRECT) or writesEXEC— including implicitOPR_EXEC/OPR_SDST_EXECoutputs (V_CMPX_*,S_*_SAVEEXEC_*,S_ANDN{1,2}_WREXEC_*,S_SUBVECTOR_LOOP_*), explicit SGPR/VOP3/SMEM destinations in126..=127(sgpr_uses+ENC_SMEMSDATA), andENC_VOPCSDWA compare writes to126..=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) acrossROW_MASK0xF/0x3, bothlastoperand orders, and wave32 PS/VStranslate()emission, plus 19 invalid/clobbered shapes verified to be rejected by bothwave32_reductionsandtranslate().Tested
rustc 1.100.0, DXC1.9.2609.5, release profile (--release).cargo test --release -p xcl --lib gpu::recomp::wave32_reduction_tests:: -- --nocapture: 1 passed, 1 failed (invalid_wave32_reduction_shapes_and_exec_writes_are_rejectedfailed onorigin/main).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-existingSKIPPEDlines: 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 ingpu::recomp::wave32_reduction_tests).Regression run
main:
PR:
Not tested
wave32_reductionsis pure-CPU static RDNA2 analysis in the recompiler).title: 29640639.AI use
wave32_reductions,rdna2_spec.rs, andemit.rs, implemented the tightened operand/mask/EXECchecks and failing-first unit tests, and ran the workspace and paired smoke verification.Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-25T17:37:37Z.
Independent AMD RDNA4 (native wave64) test report on exact head
f5ac68e2c6bcb81a59f8340b5292dc7d6357a4ca(clean detached checkout, no local changes).Tested
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 inlower_dxil::tests::{f16,f32}_programs_on_the_gpurefused 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.gpu::recomp::wave32_reduction_tests::valid_wave32_reductions_match_and_translateandinvalid_wave32_reduction_shapes_and_exec_writes_are_rejected.gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1seed 722 andfuzz_validate_and_gpu_3seed 1599) are pre-existing on unmodifiedmainon this GPU.Regression run (60 s retail-title smoke,
XCL_NETWORK=0, release)(Matched
main68a284abaseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)Not tested
AI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T18:50:19Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-25T19:06:05Z.
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 targetx86_64-pc-windows-gnurun 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_2seed 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.
Imported from ivall/xcl. Originally posted by bmjask on 2026-11-25T20:24:38Z.
Review: COMMENTED
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.
Imported from ivall/xcl. Originally posted by upipibi on 2026-11-26T04:16:39Z.
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(thehle::xaudio2tests hang on this machine, onmaintoo):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).
Imported from ivall/xcl. Originally posted by LocranKing on 2026-11-26T04:48:48Z.
Independent NVIDIA test report on exact head
f5ac68e2c6bcb81a59f8340b5292dc7d6357a4ca(clean detached checkout, no local changes).Tested
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 SDK10.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).SKIPPEDGPU tests on this adapter: 21 wave64-only (no wave64), 3 wave32 per-lane f16/f32 semantics, 1no 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 oforigin/main(b49be18) and this PR's head (f5ac68e):main:
PR:
Not tested
XCL_SAMPLE_*tests; the 60 s smoke run covers boot/intro/menus and does not enter the 3D world.AI use
smoke.ps1commands on this machine and drafted this report from the captured outputs.Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-27T20:26:59Z.
merge-check
base:
6089122a1chead:
f5ac68e2c6merge: clean
build:
cargo build --workspace-> oktests:
XCL_ADAPTER=nvidia cargo test --workspace --no-fail-fast -- --test-threads=4on the untouched merge -> 1466 passed, 1 failed, 47 ignored; 25SKIPPEDnotices. Both newwave32_reduction_testspassed. The sole failure wasgpu::recomp::pso::shader_cache_tests::console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk(DXIL not compiled), also reproduced on untouchedmainat this base here.review: The new
BANK_MASK == 0xFcondition rejects a valid fixed-selector reduction. In this PR's ownSeqfixture,BANK_MASK=0x7,ROW_MASK=0x3, and zeroV_PERMLANEX16_B32selectors still update mirror lanes 0 and 16; the cross-row call reads lane 16 into lane 0, andV_READLANE_B32consumes lane 0. AMD's RDNA2 ISA specifies that the bank mask gates destination writes, not source reads, and describes the cross-row gather. The0x7case was moved into this PR's negative tests, so the current matcher drops the sparse-wave reduction replacement for that shape. This is a synthetic correctness boundary; I did not measure a title using it. I changed that case to a positive test and used0xE(bank 0 disabled) as the negative: the focused test failed 1/2 on the unchanged PR head, then passed 2/2 with the conditional matcher below. The candidate did not receive a full-suite rerun.performance: The stricter matcher may leave this valid reduction on the ordinary translated path instead of using
xcl_red_*; title frequency and frame-time impact were not measured.verdict: not yet: preserve the proven fixed-selector/bank-0 case, keep conservative full-bank matching for other selectors, and add the paired positive/negative regression before merge.
hardware / tool and model: NVIDIA RTX 3080 Ti 12 GiB, driver 621.35; Ryzen 7 9800X3D; Windows 11 build 26300; rustc 1.99.1 MSVC; DXC 1.8.2502.11. Codex (GPT-6.2 Sol) ran the tests, checked the ISA and wrote the candidate; Codex (GPT-6.2 Astra) independently traced the lane semantics.
Candidate matcher and regression diff (local, uncommitted)
Imported from ivall/xcl. Originally posted by throny on 2026-11-27T20:32:17Z.
merge-check claim
head:
f5ac68e2c6Imported from ivall/xcl. Originally posted by throny on 2026-11-27T20:52:25Z.
merge-check
base:
6089122ahead:
f5ac68e2c6merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1467 passed, 0 failed, 47 ignored (26 SKIPPED lines); base alone: 1465 passed, 0 failed, 47 ignored
review: one open point, raised earlier in the thread and confirmed by reading the code, not reproduced: the new requirement BANK_MASK == 0xF on the mirror step rejects a reduction that main matched and that looks valid (with a partial bank mask and zero permute selectors, lane 0 still reads a written lane, so the read-back is the full reduction). The PR's negative test asserts the rejection. A rejected shape falls back to the general translation; whether that is right for waves that are not full is the question to answer. No title is known to emit this shape. Everything else checks out (the EXEC-write checks, the operand checks; the other negative cases would match on main).
performance: it changes a translator source (recomp/mod.rs): every tester re-translates all shaders once. No runtime cost unless a real reduction is now rejected.
verdict: not yet: keep the partial-bank case or say why rejecting it is right (a test with a wave that is not full would settle it); small, I will re-check on a reply or a new head.
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:56:20Z.
Triage (#1607) – head
f5ac68ewave32_reductionsincrates/xcl/src/gpu/recomp/mod.rsno longer exists on main: commitfb0931da("Recompiler: rebuild partial-wave graphics reductions") replaced it withgraphics_reductions, which already requires exact operands on the DPP8/mirror/permlanex16/last steps,ROW_MASK/BANK_MASK= 0xf on the mirror, and rejects SAVEEXEC, WREXEC, V_CMPX and any SGPR 126/127 write inside the section.What this PR has beyond main: the opener's SDST not being EXEC, SMEM loads into EXEC, SDWA VOPC writing EXEC, and accepting ROW_MASK 0x3 (main is stricter there). If those cases matter, a small PR on top of
graphics_reductionswith the matching rejection tests fromwave32_reduction_testswould carry them.Recommendation: close (superseded by main commit
fb0931da).AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T07:49:03Z.
Closing as superseded by
maincommitfb0931da, which replacedwave32_reductionswithgraphics_reductionsincrates/xcl/src/gpu/recomp/mod.rswith strict operand, mask, and EXEC-write checks. Thanks @Foniass, @throny, and @thehollowedone for the reviews and checks. (AI note: verified with Antigravity, Gemini 4 Neon.)Pull request closed