Skip to content

Recompiler: include RMW destination reads in rdna2::vgpr_uses and sgpr_uses - #2134

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-336-rdna2-rmw-uses
Open

Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-336-rdna2-rmw-uses

Conversation

@Decodere

Copy link
Copy Markdown
Contributor

What is in it
Tracks implicit read-modify-write (RMW) destination reads in rdna2::vgpr_uses() and rdna2::sgpr_uses() (crates/xcl/src/gpu/rdna2.rs) for RDNA2 instructions whose ISA table marks VDST/SDST as input: false, output: true:

  • In vgpr_uses(): extends the RMW accumulator list (V_FMAC_F32 / V_MAC_F32 / V_FMAC_LEGACY_F32) to include V_FMAC_F16, V_PK_FMAC_F16, V_DOT2C_F32_F16, and V_DOT4C_I32_I8. Previously, recomp::partition::classify wiped LANE_ID taint accumulated into VDST by those four instructions and falsely classified wave-cut-dependent shaders as Tier::Exact. (V_WRITELANE_B32 is intentionally not added, preserving mesh_wave.rs's vgpr_reads.first() == None expectation.)
  • In sgpr_uses(): appends w to r for S_CMOV* (S_CMOV_B32, S_CMOV_B64, S_CMOVK_I32), S_ADDK_I32, S_MULK_I32, S_BITSET0_B32, S_BITSET0_B64, S_BITSET1_B32, and S_BITSET1_B64 (matching x64_masks::keeps_destination, with NULL 125 already excluded from w). Previously, recomp::mesh_wave::analyze wiped mask taint on SDST across those scalar RMW ops and dropped mask-derived S_CBRANCH_SCC* branches from mask_scc_branches.
  • Adds 3 unit tests in gpu::rdna2::tests covering direct vgpr_uses (all 4 vector accumulators + negative controls including V_DOT2_F32_F16, V_ADD_NC_U32, V_WRITELANE_B32), direct sgpr_uses (all 9 scalar RMW ops, NULL 125, and plain overwrites), and end-to-end taint propagation through recomp::partition::classify and recomp::mesh_wave::analyze.

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::rdna2::tests::rmw_ -- --nocapture): 0 passed, 3 failed (V_FMAC_F16 omitted VDST from vgpr_uses reads, S_ADDK_I32 omitted SDST from sgpr_uses reads, and partition::classify returned Tier::Exact on V_MBCNT_LO_U32_B32 -> V_FMAC_F16 -> EXP).
  • Post-fix targeted CPU tests: gpu::rdna2::tests 20 passed / 0 failed (debug & --release), gpu::recomp::partition::tests 44 passed / 0 failed, gpu::recomp::mesh_wave::tests 13 passed / 0 failed (pure CPU tests, CI WARP-safe).
  • Full release workspace build & test (cargo build --release --workspace and cargo test --release --workspace -- --test-threads=4 --nocapture): 1,157 passed, 0 failed, 46 ignored across 21 test binaries (1101 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 (6020a33b) and clean PR head (5ea738c9):

Main (6020a33b16ba2de25b3aef5947552f2dc1831f09):

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

PR (5ea738c9377b677733621fa33e85f11f386b962c):

xcl-smoke v1
commit: 5ea738c9377b677733621fa33e85f11f386b962c
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1556 (PresentX 1557)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14523 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 partition::classify / mesh_wave::analyze are analysis passes not yet wired into runtime translation).

AI use
Google Antigravity (Gemini 4 Neon) wrote the rdna2::vgpr_uses/sgpr_uses 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.

…r_uses

Track implicit destination reads for RDNA2 read-modify-write instructions
whose ISA spec marks VDST/SDST as output-only:
- In vgpr_uses(), include V_FMAC_F16, V_PK_FMAC_F16, V_DOT2C_F32_F16,
  and V_DOT4C_I32_I8 alongside V_FMAC_F32 / V_MAC_F32 / V_FMAC_LEGACY_F32
  so partition::classify preserves accumulator taint.
- In sgpr_uses(), include S_CMOV* (S_CMOV_B32/B64, S_CMOVK_I32),
  S_ADDK_I32, S_MULK_I32, and S_BITSET0/1_B32/B64 (matching
  x64_masks::keeps_destination) so mesh_wave::analyze preserves mask
  taint on RMW scalar destinations (while keeping NULL 125 excluded).

Part of xcl-dev#336

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

Copy link
Copy Markdown
Contributor

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

Thanks!

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 25, 2026
rdna2.rs analysis soundness, verbatim from upstream head 5ea738c:
vector FMA/DOT accumulators (V_FMAC_F16, V_PK_FMAC_F16, V_DOT2C_F32_F16,
V_DOT4C_I32_I8) read VDST; scalar conditional/RMW ops (S_CMOV*,
S_ADDK_I32, S_MULK_I32, S_BITSET0/1_B32/B64) read SDST (NULL 125 stays
excluded). Feeds partition/mesh_wave/x64 taint soundness. Adds the
three upstream regression tests verbatim (all fail pre-fix).
@github-actions

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the stale No activity for 3 days; closed 4 days later unless something happens label Nov 28, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 5ea738c

No open PR changes rdna2::sgpr_uses / vgpr_uses this way, and main does not have it: only the three FMAC/MAC accumulators read VDST there. The commit "DXIL: fix compact SGPR liveness for RMW/CMOV SALU" (carried by #2604 and the amd-dev merge #3547) treats the same S_CMOV/S_ADDK/S_MULK/S_BITSET ops as read-modify-write, but in dxil/compact.rs's own use/def table. It is a different function, so it is not a duplicate.
No problems found in the diff.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@BBareth

BBareth commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check claim
head: 5ea738c

@github-actions github-actions Bot added area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026
@BBareth

BBareth commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 493dbd3
head: 5ea738c
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2903 passed, 0 failed, 51 ignored; 28 SKIPPED lines, as on the base; failing: none. The base alone, same machine, same commit: 2900 passed, 0 failed, 51 ignored, 28 SKIPPED lines (22 no wave64, 2 no heap windows, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 cannot disable the driver cache). The three new tests ran and passed: rmw_vector_accumulators_read_vdst, rmw_scalar_ops_read_sdst, rmw_uses_propagate_taint_in_partition_and_mesh_wave.
review: no blocking finding; one file (+124/-1), every line read. rdna2::sgpr_uses now lists SDST among the reads of the conditional moves (S_CMOV*) and of S_ADDK_I32, S_MULK_I32 and S_BITSET0/1_B32/B64, and vgpr_uses lists VDST among the reads of V_FMAC_F16, V_PK_FMAC_F16, V_DOT2C_F32_F16 and V_DOT4C_I32_I8; these instructions keep or accumulate into their destination. The analyses that use these lists (the new test covers partition and mesh_wave) see more reads, which should only make them more conservative. main already has tests for the scalar cases in two analyses (cmov_and_rmw_salu_read_sdst_..., scc_reading_and_rmw_scalar_ops_preserve_mask_taint); they still pass on the merge. Not tested here: a retail shader whose classification changes with this; no GPU test is involved.
performance: none at run time; a program that was classified too optimistically may now take the more conservative form (not measured).
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 621.24 (32.0.16.2124); i7-12700K; Windows 11 26200. Claude Code, Claude Fable 5.2 read the diff, ran the build and the suite and wrote this check.

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) needs:amd-test Needs a test report or merge-check on an AMD GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) stale No activity for 3 days; closed 4 days later unless something happens

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants