Recompiler: close four mask-taint soundness holes in mesh_wave::transfer #2147

Open
github-bot wants to merge 1 commit from github-bot/gh-2147 into main AGit
Owner

@⁠Decodere on GitHub · 2026-11-25 06:16 UTC · original
Decodere:fix-336-mesh-wave-taint → main · +231 −11 · 1 files · 1 commits · open

What is in it
Closes four mask-taint soundness holes in mesh_wave::transfer() (crates/xcl/src/gpu/recomp/mesh_wave.rs, called by recomp::geometry_wave32_hazards()):

  • VALU 64-bit lane-mask producers (writes_lane_mask): Treats V_ADD_CO_U32, V_ADD_CO_CI_U32, V_SUB_CO_U32, V_SUB_CO_CI_U32, V_SUBREV_CO_U32, V_SUBREV_CO_CI_U32, V_DIV_SCALE_F32, V_DIV_SCALE_F64, V_MAD_U64_U32, and V_MAD_I64_I32 as lane-mask writers alongside V_CMP*, SAVEEXEC, and WREXEC (leaving 32-bit lane readers like V_READFIRSTLANE_B32/V_READLANE_B32 excluded).
  • SCC-reading and RMW/conditional scalar ops (reads_scc, keeps_destination): Propagates state.scc taint through SCC-reading SALU instructions (S_CSELECT_B32/B64, S_CMOV*, S_ADDC_U32, S_SUBB_U32), and for destination-preserving scalar ops (S_CMOV*, S_ADDK_I32, S_MULK_I32, S_BITSET0_B32/B64, S_BITSET1_B32/B64) folds any existing taint on writes into reads_mask and skips clearing writes.
  • Special scalar mask sources (reads_special_mask): Scans non-implicit scalar input operands for SRC_VCCZ (251), SRC_EXECZ (252), and tainted SRC_SCC (253) (skipping SRC0 on non-plain SDWA/DPP encodings) so mask checks via special inline codes are not dropped.
  • Indirect S_MOVREL* scalar moves: Handles S_MOVRELS_B32/B64 (definite overwrite of SDST with M0 or src..124 taint), S_MOVRELD_B32/B64 (never clears SDST; taints dst..124 if source or M0 is tainted), and S_MOVRELSD_2_B32 (never clears SDST; taints dst..124 if M0 or src..124 is tainted), matching emit.rs and x64_masks.rs.
  • Adds 4 unit tests in gpu::recomp::mesh_wave::tests covering all 4 holes (plus negative controls and geometry_wave32_hazards checks).

Part of #336

Tested
Environment: Windows 11 Home 26200, Intel Core i5-11400F, 32 GB RAM, NVIDIA GeForce RTX 4060 8 GB (driver 621.14, wave32), Rust 1.100.0, DXC 1.9.2609.5 (01b62ad4).

  • Failing-first pre-fix check (cargo test -j 4 -p xcl --lib gpu::recomp::mesh_wave::tests -- --nocapture): 13 passed, 4 failed — all 4 new tests (valu_carry_and_div_scale_sdst_outputs_are_masks, scc_reading_and_rmw_scalar_ops_preserve_mask_taint, special_mask_sources_vccz_execz_and_scc_are_tainted, movrel_preserves_dst_and_tracks_indirect_sgpr_ranges) returned empty mask_scc_branches pre-fix.
  • Post-fix targeted tests (cargo test --release -p xcl --lib gpu::recomp::mesh_wave::tests -- --nocapture): 17 passed, 0 failed (pure CPU unit tests, CI WARP-safe).
  • Full release workspace build & test (cargo build --release --workspace and cargo test --release --workspace -- --test-threads=4 --nocapture): 1,158 passed, 0 failed, 46 ignored across 21 test binaries (1102 in xcl lib, 56 across the remaining 20 binaries), with 27 SKIPPED lines on this RTX 4060:
    • 20 no wave64 (RTX 4060 is wave32-only)
    • 3 per-lane form: refused (wave32 f16 arithmetic, f16 packed, f32 conversions)
    • 2 no d3d12SDKLayers.dll / no D3D12 debug layer
    • 1 cannot disable the driver cache (Windows Developer Mode not enabled)
    • 1 no heap windows

Regression run
Paired 60 s runs via scripts/smoke.ps1 on clean origin/main (6e1e2bef) and clean PR head (a614d310):

Main (6e1e2befc7430126b1e7b98b5c3fe93813c866b6):

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

PR (a614d310d5fdfe14df504f63d0a9ab7e04008913):

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

Not tested

  • Native wave64 GPU execution (20 no wave64 skips on RTX 4060), D3D12 debug layer tests (2 skips without d3d12SDKLayers.dll), driver cache disable toggle (1 skip without Windows Developer Mode), and heap-window OOM fallback (1 skip without XCL_HEAP_WINDOWS).
  • Retail titles other than title: 29640639, and mesh_wave::analyze is a static analysis pass (used for hazard diagnostics, not runtime code generation).

AI use
Google Antigravity (Gemini 4 Neon) wrote the mesh_wave::transfer() fixes, unit tests, and this PR description. All pre-fix/post-fix unit tests, full release workspace tests, paired 60 s smoke runs, and scripts/pr_check.py --local validation were run locally on this machine.

**@⁠Decodere** on GitHub · 2026-11-25 06:16 UTC · [original](https://github.com/xcl-dev/xcl/pull/2147) `Decodere:fix-336-mesh-wave-taint` → `main` · +231 −11 · 1 files · 1 commits · open **What is in it** Closes four mask-taint soundness holes in `mesh_wave::transfer()` (`crates/xcl/src/gpu/recomp/mesh_wave.rs`, called by `recomp::geometry_wave32_hazards()`): - **VALU 64-bit lane-mask producers (`writes_lane_mask`):** Treats `V_ADD_CO_U32`, `V_ADD_CO_CI_U32`, `V_SUB_CO_U32`, `V_SUB_CO_CI_U32`, `V_SUBREV_CO_U32`, `V_SUBREV_CO_CI_U32`, `V_DIV_SCALE_F32`, `V_DIV_SCALE_F64`, `V_MAD_U64_U32`, and `V_MAD_I64_I32` as lane-mask writers alongside `V_CMP*`, `SAVEEXEC`, and `WREXEC` (leaving 32-bit lane readers like `V_READFIRSTLANE_B32`/`V_READLANE_B32` excluded). - **SCC-reading and RMW/conditional scalar ops (`reads_scc`, `keeps_destination`):** Propagates `state.scc` taint through SCC-reading SALU instructions (`S_CSELECT_B32/B64`, `S_CMOV*`, `S_ADDC_U32`, `S_SUBB_U32`), and for destination-preserving scalar ops (`S_CMOV*`, `S_ADDK_I32`, `S_MULK_I32`, `S_BITSET0_B32/B64`, `S_BITSET1_B32/B64`) folds any existing taint on `writes` into `reads_mask` and skips clearing `writes`. - **Special scalar mask sources (`reads_special_mask`):** Scans non-implicit scalar input operands for `SRC_VCCZ` (`251`), `SRC_EXECZ` (`252`), and tainted `SRC_SCC` (`253`) (skipping `SRC0` on non-plain SDWA/DPP encodings) so mask checks via special inline codes are not dropped. - **Indirect `S_MOVREL*` scalar moves:** Handles `S_MOVRELS_B32/B64` (definite overwrite of `SDST` with `M0` or `src..124` taint), `S_MOVRELD_B32/B64` (never clears `SDST`; taints `dst..124` if source or `M0` is tainted), and `S_MOVRELSD_2_B32` (never clears `SDST`; taints `dst..124` if `M0` or `src..124` is tainted), matching `emit.rs` and `x64_masks.rs`. - Adds 4 unit tests in `gpu::recomp::mesh_wave::tests` covering all 4 holes (plus negative controls and `geometry_wave32_hazards` checks). Part of #336 **Tested** Environment: Windows 11 Home 26200, Intel Core i5-11400F, 32 GB RAM, NVIDIA GeForce RTX 4060 8 GB (driver 621.14, wave32), Rust 1.100.0, DXC `1.9.2609.5` (`01b62ad4`). - Failing-first pre-fix check (`cargo test -j 4 -p xcl --lib gpu::recomp::mesh_wave::tests -- --nocapture`): 13 passed, 4 failed — all 4 new tests (`valu_carry_and_div_scale_sdst_outputs_are_masks`, `scc_reading_and_rmw_scalar_ops_preserve_mask_taint`, `special_mask_sources_vccz_execz_and_scc_are_tainted`, `movrel_preserves_dst_and_tracks_indirect_sgpr_ranges`) returned empty `mask_scc_branches` pre-fix. - Post-fix targeted tests (`cargo test --release -p xcl --lib gpu::recomp::mesh_wave::tests -- --nocapture`): 17 passed, 0 failed (pure CPU unit tests, CI WARP-safe). - Full release workspace build & test (`cargo build --release --workspace` and `cargo test --release --workspace -- --test-threads=4 --nocapture`): 1,158 passed, 0 failed, 46 ignored across 21 test binaries (`1102` in `xcl` lib, `56` across the remaining 20 binaries), with 27 `SKIPPED` lines on this RTX 4060: - 20 `no wave64` (RTX 4060 is wave32-only) - 3 `per-lane form: refused` (wave32 f16 arithmetic, f16 packed, f32 conversions) - 2 `no d3d12SDKLayers.dll` / `no D3D12 debug layer` - 1 `cannot disable the driver cache` (Windows Developer Mode not enabled) - 1 `no heap windows` **Regression run** Paired 60 s runs via `scripts/smoke.ps1` on clean `origin/main` (`6e1e2bef`) and clean PR head (`a614d310`): Main (`6e1e2befc7430126b1e7b98b5c3fe93813c866b6`): ``` xcl-smoke v1 commit: 6e1e2befc7430126b1e7b98b5c3fe93813c866b6 gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1529 (PresentX 1529) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14521 MB ``` PR (`a614d310d5fdfe14df504f63d0a9ab7e04008913`): ``` xcl-smoke v1 commit: a614d310d5fdfe14df504f63d0a9ab7e04008913 gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1494 (PresentX 1494) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14519 MB ``` **Not tested** - Native wave64 GPU execution (20 `no wave64` skips on RTX 4060), D3D12 debug layer tests (2 skips without `d3d12SDKLayers.dll`), driver cache disable toggle (1 skip without Windows Developer Mode), and heap-window OOM fallback (1 skip without `XCL_HEAP_WINDOWS`). - Retail titles other than `title: 29640639`, and `mesh_wave::analyze` is a static analysis pass (used for hazard diagnostics, not runtime code generation). **AI use** Google Antigravity (Gemini 4 Neon) wrote the `mesh_wave::transfer()` fixes, unit tests, and this PR description. All pre-fix/post-fix unit tests, full release workspace tests, paired 60 s smoke runs, and `scripts/pr_check.py --local` validation were run locally on this machine.
Fix four cases where crates/xcl/src/gpu/recomp/mesh_wave.rs dropped
wave64 mask taint on scalar registers or SCC:
- Treat 64-bit VALU lane-mask producers (V_ADD/SUB/SUBREV_CO*,
  V_DIV_SCALE_F32/F64, V_MAD_U64_U32/I64_I32) as mask writers alongside
  V_CMP*, SAVEEXEC, and WREXEC.
- Propagate state.scc taint through SCC-reading SALU ops (e.g.
  S_CSELECT_B32/B64, S_CMOV*, S_ADDC_U32, S_SUBB_U32) and preserve prior
  SDST taint on RMW/conditional scalar ops (S_CMOV*, S_ADDK_I32,
  S_MULK_I32, S_BITSET0/1_B32/B64).
- Recognize explicit SRC_VCCZ (251), SRC_EXECZ (252), and tainted
  SRC_SCC (253) scalar operands.
- Handle S_MOVRELS_B32/B64, S_MOVRELD_B32/B64, and S_MOVRELSD_2_B32
  across their indirect M0-indexed SGPR ranges (..124) without clearing
  SDST on indirect writes.

Part of #336

Assisted-by: Google Antigravity (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:20:29 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 06:49 UTC · original

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!

**@⁠DavidM1911** on GitHub · 2026-11-25 06:49 UTC · [original](https://github.com/xcl-dev/xcl/pull/2147#issuecomment-7155196429) 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!
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2147/head:github-bot/gh-2147'
git switch 'github-bot/gh-2147'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2147'
git switch 'github-bot/gh-2147'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2147'
git switch 'github-bot/gh-2147'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2147'
git switch 'main'
git merge --squash 'github-bot/gh-2147'
git switch 'main'
git merge --ff-only 'github-bot/gh-2147'
git switch 'main'
git merge 'github-bot/gh-2147'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.