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

Merged
Decodere merged 1 commit from upstream-pr/2147 into main 2026-11-29 12:18:22 +00:00
Decodere commented 2026-11-25 06:16:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Decodere on 2026-11-25T06:16:13Z.


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.

<!-- greyfinch-sync:ivall/xcl:issue:5486231397 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2147). Originally posted by [Decodere](https://github.com/Decodere) on 2026-11-25T06:16:13Z. --- **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.
DavidM1911 commented 2026-11-25 07:05:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T06:49:28Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7155196429 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2147#issuecomment-7155196429). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T06:49:28Z. --- 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!
github-actions[bot] commented 2026-11-28 20:18:52 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-28T20:18:52Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7245194879 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2147#issuecomment-7245194879). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-28T20:18:52Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Kalmarv commented 2026-11-29 00:37:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T00:37:47Z.


merge-check
base: fa204595a4
head: a614d310d5
merge: clean (trial merge 36e75690aca370fed5de46b296222a47b0d705fb, local, not pushed; git diff --check clean)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 (XCL_DXC_DIR = DXC 1.9.2609) -> 2612 passed, 0 failed, 49 ignored; SKIPPED: 26 (21 no wave64 on this 32-lane GPU, 3 per-lane f16/f32 forms refused (#1426 semantics), 2 no heap windows); failing: none. All 17 mesh_wave::tests ran and passed, including the 4 new ones (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). These are CPU tests, so the GPU played no part.
review: none blocking; whole diff read (mesh_wave.rs only). Every change only adds taint, never removes it.

  1. VALU carry / div-scale / mad64 SDST outputs are lane masks, alongside V_CMP / SAVEEXEC / WREXEC.
  2. An SCC read (S_CSELECT, S_ADDC ...) carries SCC taint into the result.
  3. Read-modify-write scalar ops (S_CMOV*, S_ADDK, S_MULK, S_BITSET*) keep the destination's prior taint, where before the write cleared it.
  4. SRC_VCCZ / SRC_EXECZ taint the result, and so does SRC_SCC when SCC is tainted. The DPP/SDWA SRC0 field is skipped correctly, since it names a VGPR there.
  5. S_MOVREL* taints the indirect range src..124 / dst..124 together with M0. S_MOVRELD never clears.
    The negative controls (V_READFIRSTLANE_B32 output, S_MOVRELS over an untainted range) stay untainted.
    Note, not blocking: mesh_wave::analyze only feeds recomp::geometry_wave32_hazards, and nothing outside tests and benches/gpu_cpu.rs calls that (it describes a possible split-free fast path). So this PR has no runtime effect today. When that fast path is wired in, the extra taint will rule out more geometry programs. That will be the time to count, on a retail pack, how many more programs it marks. Not done here: no XCL_SAMPLE_RPF sample on this machine.
    performance: none at runtime (nothing in the runtime calls this analysis). No title run: Recompiler / Tier 1.
    verdict: safe to merge
    hardware / tool and model: NVIDIA GeForce RTX 5070 Ti 16 GB (driver 610.74, wave32 only), AMD Ryzen 9 9950X, Windows 11 build 26200; rustc 1.99.0, debug test profile, DXC 1.9.2609 via XCL_DXC_DIR. Claude Code, Claude Opus 5.5: merge, build, suite and full-diff review; this report.
<!-- greyfinch-sync:ivall/xcl:comment:7248244517 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2147#issuecomment-7248244517). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-29T00:37:47Z. --- merge-check base: fa204595a488c60c6c5f905244f0172072c9c2a9 head: a614d310d5fdfe14df504f63d0a9ab7e04008913 merge: clean (trial merge 36e75690aca370fed5de46b296222a47b0d705fb, local, not pushed; `git diff --check` clean) build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 (XCL_DXC_DIR = DXC 1.9.2609) -> 2612 passed, 0 failed, 49 ignored; SKIPPED: 26 (21 no wave64 on this 32-lane GPU, 3 per-lane f16/f32 forms refused (#1426 semantics), 2 no heap windows); failing: none. All 17 `mesh_wave::tests` ran and passed, including the 4 new ones (`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`). These are CPU tests, so the GPU played no part. review: none blocking; whole diff read (`mesh_wave.rs` only). Every change only adds taint, never removes it. 1. VALU carry / div-scale / mad64 SDST outputs are lane masks, alongside `V_CMP` / `SAVEEXEC` / `WREXEC`. 2. An SCC read (`S_CSELECT`, `S_ADDC` ...) carries SCC taint into the result. 3. Read-modify-write scalar ops (`S_CMOV*`, `S_ADDK`, `S_MULK`, `S_BITSET*`) keep the destination's prior taint, where before the write cleared it. 4. `SRC_VCCZ` / `SRC_EXECZ` taint the result, and so does `SRC_SCC` when SCC is tainted. The DPP/SDWA SRC0 field is skipped correctly, since it names a VGPR there. 5. `S_MOVREL*` taints the indirect range `src..124` / `dst..124` together with M0. `S_MOVRELD` never clears. The negative controls (`V_READFIRSTLANE_B32` output, `S_MOVRELS` over an untainted range) stay untainted. Note, not blocking: `mesh_wave::analyze` only feeds `recomp::geometry_wave32_hazards`, and nothing outside tests and `benches/gpu_cpu.rs` calls that (it describes a possible split-free fast path). So this PR has no runtime effect today. When that fast path is wired in, the extra taint will rule out more geometry programs. That will be the time to count, on a retail pack, how many more programs it marks. Not done here: no `XCL_SAMPLE_RPF` sample on this machine. performance: none at runtime (nothing in the runtime calls this analysis). No title run: Recompiler / Tier 1. verdict: safe to merge hardware / tool and model: NVIDIA GeForce RTX 5070 Ti 16 GB (driver 610.74, wave32 only), AMD Ryzen 9 9950X, Windows 11 build 26200; rustc 1.99.0, debug test profile, DXC 1.9.2609 via XCL_DXC_DIR. Claude Code, Claude Opus 5.5: merge, build, suite and full-diff review; this report.
throny commented 2026-11-29 07:50:39 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-29T07:50:39Z.


merge-check claim
head: a614d310d5

<!-- greyfinch-sync:ivall/xcl:comment:7252725905 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2147#issuecomment-7252725905). Originally posted by [throny](https://github.com/throny) on 2026-11-29T07:50:39Z. --- merge-check claim head: a614d310d5fdfe14df504f63d0a9ab7e04008913
throny commented 2026-11-29 08:09:35 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-29T08:09:35Z.


merge-check
base: fa204595
head: a614d310d5
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2612 passed, 0 failed, 49 ignored (27 SKIPPED lines). Base alone at fa204595: 2608 passed, 0 failed, 49 ignored.
review: no blocking finding. The taint now follows SCC readers, ops that keep their destination, the VCCZ / EXECZ / SCC sources, the second outputs of the carry / div_scale / mad64 forms and the MOVREL family; checked against the operand types of the spec table, and the index ranges are clamped. Minor: in the MOVRELS branch the scanned range runs up to 124 and so includes VCC, which is always tainted, so any source register up to s107 gives a tainted result. That is sound but coarser than needed (the test uses s108 to step around it). Expected effect: more programs get the wave32 hazard flag and take the fallback; how many was not measured.
performance: not measured.
verdict: safe to merge
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).

<!-- greyfinch-sync:ivall/xcl:comment:7252923801 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2147#issuecomment-7252923801). Originally posted by [throny](https://github.com/throny) on 2026-11-29T08:09:35Z. --- merge-check base: fa204595 head: a614d310d5fdfe14df504f63d0a9ab7e04008913 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2612 passed, 0 failed, 49 ignored (27 SKIPPED lines). Base alone at fa204595: 2608 passed, 0 failed, 49 ignored. review: no blocking finding. The taint now follows SCC readers, ops that keep their destination, the VCCZ / EXECZ / SCC sources, the second outputs of the carry / div_scale / mad64 forms and the MOVREL family; checked against the operand types of the spec table, and the index ranges are clamped. Minor: in the MOVRELS branch the scanned range runs up to 124 and so includes VCC, which is always tainted, so any source register up to s107 gives a tainted result. That is sound but coarser than needed (the test uses s108 to step around it). Expected effect: more programs get the wave32 hazard flag and take the fallback; how many was not measured. performance: not measured. verdict: safe to merge 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).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!2137
No description provided.