Skip to content

Recompiler: SDWA register uses come from the extension dword - #811

Open
upipibi wants to merge 1 commit into
xcl-dev:mainfrom
upipibi:rdna2-sdwa-register-uses
Open

upipibi wants to merge 1 commit into
xcl-dev:mainfrom
upipibi:rdna2-sdwa-register-uses

Conversation

@upipibi

@upipibi upipibi commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

rdna2::sgpr_uses and rdna2::vgpr_uses read an SDWA instruction as its base dword only. A source whose S bit is set (an SGPR) is no SGPR read; the second one is reported as a VGPR read of the register with the same number; and the SGPR pair a v_cmp_*_sdwa writes instead of VCC (SD) is no write. For v_cmp_lt_f32_sdwa s5, v1, s2, main gives no SGPR at all and a read of v1 and v2.

What that reaches (all on main e50836b):

  • constant_samplers (recomp/mod.rs, used by translate) keeps a constant in an SGPR the compare has overwritten, so an image instruction after it still gets static sampler words.
  • geometry_wave32_hazards and mesh_wave's mask state do not take the compare's result for a mask (s_bcnt1_i32_b32 of it is no "whole-wave mask reduction").
  • the first-use lines of the shader report (shaders.rs).

x64_masks.rs reads the extension dword itself (x64_masks::uses) and is unchanged: it builds register bit sets per operand with its own per-lane rules, so using the shared function there would be a rewrite, not a small change.

Independent of #790 / #791 (other hunks of rdna2.rs; the three merge cleanly in any order).

What is in it

  • crates/xcl/src/gpu/rdna2.rs: sgpr_uses adds the SDWA scalar sources (S0 / S1; an inline constant or NULL is no register) and the compare's SDST pair (not for v_cmpx, which writes EXEC); vgpr_uses does not count a VSRC1 whose S1 is set. Test sdwa_register_uses_come_from_the_extension_dword (7 words).
  • crates/xcl/src/gpu/recomp/tests.rs: sdwa_compare_destination_is_a_write_to_the_analyses – the two caller-visible effects above on hand-built programs.

Tested

  • NVIDIA GeForce RTX 3070 8 GB, driver 616.56 (32.0.16.1656), 32-lane waves only; Ryzen 9 5950X; Windows 11 Pro 26100; Rust 1.100.0 MSVC, debug.
  • The two new tests on main's rdna2.rs: both fail – (([], []), ([1, 2], [])) where (([2], [5, 6]), ([1], [])) is expected; no "whole-wave mask reduction"; and constant_samplers returns the sampler words for the image instruction after the compare too ([(16, [1, 2, 3, 4]), (32, [1, 2, 3, 4])]). With the change both pass.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 204f4b9: two runs. Run 2: 706 passed, 0 failed, 41 ignored (xcl lib: 665 passed, 0 failed, 21 ignored). Run 1: 703 passed, 3 failed, 41 ignored – placed_title_textures_share_vram_and_preserve_pixels ("cubemap extra_pages must be reused at same va") and the two tests its poisoned lock takes with it: the failure of Tests: placed_title_textures_share_vram_and_preserve_pixels fails now and then at its cubemap reuse check (main 9ce2070) #718, which main shows on this machine too.
  • SKIPPED GPU tests: 2, both no wave64: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.

Regression run

From eizispark's run (#811 (comment)), thanks:

main:

xcl-smoke v1
commit: beaa245ca04e212f064efc7cafcdce104bc5c0a2
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1660 (PresentX 1660)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14862 MB

PR:

xcl-smoke v1
commit: 204f4b91f12204b0c386e9c1599999d76b428f51
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1661 (PresentX 1661)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14859 MB

Not tested

  • No retail title, no XCL_SAMPLE_* data: the game-data tests passed without running. Whether a retail shader has an SDWA compare into an SGPR is not known to me.
  • AMD / Intel GPUs, wave64 hardware.
  • No D3D12 debug layer on this machine (Graphics Tools not installed): test_title_draws_with_a_root_signature_under_the_debug_layer and uploads_start_from_each_subresources_state return early.
  • The SDWA compare's implicit VCC write (SD clear) is still not reported, as for the plain VOPC form.

AI use

🤖 Generated with Claude Code

@mastrr9

mastrr9 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Independent native Windows NVIDIA RTX 5080 (wave32) + D3D12 debug layer build/test run and code review at head 204f4b91f12204b0c386e9c1599999d76b428f51.

Code Review

  • Clean fix in rdna2::{sgpr_uses, vgpr_uses}: reads SDWA S0 (bit 23) and S1 (bit 31) from the extension dword so SGPR operands are tracked in sgpr_uses (and excluded from vgpr_uses when VSRC1 has S1=1), and tracks ENC_VOPC SDST pairs (ext[14:8] when SD=1 and not V_CMPX / NULL). Both unit tests cleanly verify decoder and downstream recompiler analyses. No issues found.

Tested

  • Environment: NVIDIA GeForce RTX 5080 (16 GB, wave32, driver 617.42 / 32.0.16.1742), Windows 11 Pro 25H2 (26200.9974), D3D12 debug layer installed (d3d12SDKLayers.dll), rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC from Windows SDK 10.0.26100.0, debug build.
  • Command: cargo build --workspace && cargo test --workspace -- --test-threads=4
  • Result: 706 passed, 0 failed, 41 ignored (0 new warnings).
  • PR-specific tests (2/2 ok):
    • gpu::rdna2::tests::sdwa_register_uses_come_from_the_extension_dword
    • gpu::recomp::tests::sdwa_compare_destination_is_a_write_to_the_analyses
  • SKIPPED (2):
    • gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask (no wave64)
    • gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64)

Not tested

  • AMD/wave64 hardware, release build, and retail titles.

AI use: Antigravity (Gemini 4 Neon reviewed the diff; Gemini 4 Hydrogen ran the RTX 5080 workspace tests) drafted this report.

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 204f4b91f12204b0c386e9c1599999d76b428f51 on AMD RDNA4. I merged it onto current main beaa245 locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 715 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 674 passed, 0 failed, 21 ignored
  • 0 SKIPPED; sdwa_register_uses_come_from_the_extension_dword passes.

Review: src0 now comes from the extension dword's bits [7:0] with S0 at bit 23, src1's S1 at bit 31, and a v_cmp_*_sdwa with SD set writes its SGPR pair instead of VCC (not for v_cmpx), with null (125) left out. That matches the SDWA layout in the RDNA2 ISA. I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@Anon64

Anon64 commented Nov 24, 2026

Copy link
Copy Markdown

Regression runs for this PR's head 204f4b9 and for its base main e50836b, on a retail title (same title, 60 s each), made with scripts/smoke.ps1 (release, clean tree at each commit) and pasted unedited, for Regression run.

main:

xcl-smoke v1
commit: e50836bdf6f5c026f281d545ed86fb2f07ba6e6a
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1648 (PresentX 1648)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16639 MB

this PR:

xcl-smoke v1
commit: 204f4b91f12204b0c386e9c1599999d76b428f51
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1642 (PresentX 1642)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16607 MB

Tested

  • NVIDIA GeForce RTX 3060 12 GB (driver 581.80, wave32), Intel Core i9-14900KF, Windows 11 25H2 26200.9974, Rust 1.90.0

Not tested

  • the unit tests on this machine
  • whether the title reaches the changed code; this is a regression check only

Report written with Claude Code (Claude Opus 5.5) from runs on this machine.

@SlopTart

Copy link
Copy Markdown

2|
3|AMD + release-build datapoint - the axes your row lists as not tested.
4|
5|Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Wine = Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust 1.100.0 cross x86_64-pc-windows-gnu, release profile, XCL_NETWORK=0, native wave64. Same rig as my Linux rows in #42 / #718.
6|
7|Merged state: head 204f4b9 onto main beaa245, clean merge.
8|
9|Full suite, cargo test --workspace --release --no-fail-fast -- --test-threads=4: 705 passed, 10 failed, 41 ignored (17 suites). The 10 = this rig's 7 stable Wine-lane failures (my #42 row) + the #718 flaky trio firing that run (~2/5 rate, PR-independent). Nothing new fails. Your tests pass: gpu::rdna2::tests::sdwa_register_uses_come_from_the_extension_dword ok, sdwa_compare_destination_is_a_write_to_the_analyses ok.
10|
11|Not tested: retail titles (none here), Windows, RDNA4.
12|Counts only, no game data.
13|AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

@eizispark

Copy link
Copy Markdown
Contributor

Hardware check of 204f4b91f12204b0c386e9c1599999d76b428f51 (verified clean merge with main beaa245): pass.

Tested

  • Hardware: AMD Radeon RX 9070 XT (RDNA4, driver 32.0.32015.16001), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11, rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profile
  • cargo test --workspace -- --test-threads=4: 706 passed, 0 failed, 41 ignored (GPU tests skipped on this adapter: none)
  • sdwa_register_uses_come_from_the_extension_dword and sdwa_compare_destination_is_a_write_to_the_analyses: 2 passed, 0 failed

Regression run
main (beaa245):

xcl-smoke v1
commit: beaa245ca04e212f064efc7cafcdce104bc5c0a2
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1660 (PresentX 1660)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14862 MB

PR (204f4b9):

xcl-smoke v1
commit: 204f4b91f12204b0c386e9c1599999d76b428f51
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1661 (PresentX 1661)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14859 MB

Not tested

  • wave32-only GPUs (NVIDIA / Intel); gameplay past the menus

AI use

  • Antigravity (Gemini 4 Carbon) ran the build, test suite, and scripts/smoke.ps1 harness on this machine and formatted this report.

@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 26, 2026
…cl-dev#811)

Live head 204f4b9 still OPEN vs upstream/main. WHOLE fix: sgpr_uses
SDWA ext-dword legs (S-bit scalar source, scalar VSRC1, SDST pair for
VOPC compares with SD set except V_CMPX, v_cmpx writes EXEC not SGPR),
vgpr_uses VSRC1 S-bit exclusion, both doc comments; upstream rdna2 test
as-is plus the caller-reach test in recomp/tests.rs as-is (Windows-gated
mod tests on linux: compiles/runs on Windows only).

Failing-first: grafted rdna2 test onto pre-fix HEAD in /tmp/xcl-pref811
RED (v_cmp_lt_f32_sdwa s5,v1,s2 gave no SGPR + read of v2, exact
upstream symptom); temp caller-reach probe (geometry_wave32_hazards on
the SDWA-compare+BCSNT sequence) RED pre-fix; both GREEN post-fix.
recomp test unrunnable on Linux (mod tests is cfg(all(test, windows))).

Gates: both cargo checks 0 errors, rdna2:: 24/24, lib 753/0/1 (+1),
title e2e 12 unique FAILs all D3D12.X GPU-only 0 non-GPU, retail
fresh-root exit 139 SIGSEGV +0x2237320 stubs 20 xgr 3 apis unmapped [].
Lock audit 0 new lock().
@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 29, 2026
@relativespace2K

relativespace2K commented Nov 30, 2026 •

Copy link
Copy Markdown

merge-check
base: 53e85fb
head: 204f4b9
merge: clean
build: cargo build --workspace -> failed
tests: not run, the build fails first: error[E0061]: this function takes 3 arguments but 2 arguments were supplied at crates/xcl/src/gpu/recomp/tests.rs:174, where the PR calls super::constant_samplers(&insts, &Default::default()) and main's constant_samplers (crates/xcl/src/gpu/recomp/mod.rs:1804) now takes (insts, leaders, follow: bool).
review: no finding on the change itself on its own base; the problem is that the base moved. git merge --no-ff is clean because the signature change landed elsewhere in the tree, so the merge looks fine and the compile is what catches it. The PR needs a rebase onto current main (the third argument is the follow flag that was added to constant_samplers), after which this should be re-checked on the new head.
performance: not applicable, it does not build.
verdict: not yet: does not build against current main; crates/xcl/src/gpu/recomp/tests.rs:174 calls constant_samplers with 2 arguments where main now takes 3 (the follow flag). Rebase onto main and it can be checked again.
hardware / tool and model: AMD Radeon RX 6800 XT 16 GB (RDNA2, wave64), driver 32.0.21045.29003; Ryzen 5 5600, 32 GB RAM; Windows 10 IoT Enterprise LTSC 2024, 10.0.26100 build 26100.9974; Rust 1.100.0; DXC 1.9.2602.17; debug build. DeepSeek Harness coding agent, model DeepSeek V4.1 Flash.

@github-actions github-actions Bot added area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle 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 Nov 30, 2026
@github-actions github-actions Bot removed 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 Nov 30, 2026
@tiagonleal

tiagonleal commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: cfb9753
head: 204f4b9
merge: clean (no textual conflict)
build: cargo build --workspace -> ok, but the lib test target does not compile on this base
tests: cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4 -> not run: error[E0061]: this function takes 3 arguments but 2 arguments were supplied at crates/xcl/src/gpu/recomp/tests.rs:174, where the new test calls super::constant_samplers(&insts, &Default::default()). On current main constant_samplers takes a third argument, follow: bool (gpu/recomp/mod.rs:1804). Base alone on this PC: 2834 passed, 0 failed, 51 ignored.
review: whole diff read (+74/-4, gpu/rdna2.rs and the test). The decoder change itself raised no finding in the read: with an SDWA extension dword, a source marked as scalar is reported as an SGPR use and no longer as a VGPR use, and a compare with the SD bit reports its SDST as the mask destination. It could not be confirmed by its tests here because of the build error above. The fix is one argument in the test's call; after a rebase this needs a fresh check.
performance: decoder metadata only. scripts/smoke.ps1 on the merged release build (which does compile), 60 s of a retail title: 1684 frames and 15574 MB peak commit against 1678 and 1677 frames on the base. No device removal, no crash.
verdict: not yet: the test target does not compile on current main (one missing argument at tests.rs:174); needs a rebase
hardware / tool and model: RTX 5070 Ti 16 GB (617.42, wave32), Ryzen 7 9800X3D, 32 GB, Windows 11 26300, rustc 1.100.0 / Claude Code (Claude Fable 5.2 ran the build and wrote this; Claude Opus 5.5 read the diff first)

  • Tiago

rdna2::sgpr_uses and vgpr_uses read an SDWA instruction as its base
dword: a source whose S bit is set (an SGPR) was no SGPR read, the
second one was a VGPR read of the register with the same number, and
the SGPR pair a v_cmp_*_sdwa writes instead of VCC (SD) was no write.
`v_cmp_lt_f32_sdwa s5, v1, s2` gave no SGPR at all and a read of v2.

What that reached: constant_samplers kept a constant in an SGPR the
compare had overwritten, so an image instruction after it still got
static sampler words; geometry_wave32_hazards and mesh_wave's mask
state did not take the compare's result for a mask. x64_masks reads
the extension dword itself and is unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@upipibi
upipibi force-pushed the rdna2-sdwa-register-uses branch from 204f4b9 to c9ef0b8 Compare December 1, 2026 00:14
@upipibi

upipibi commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased onto main d0832e6 (c9ef0b8). The only change is in the test: constant_samplers takes follow now, and it passes false, since the test's code is one straight block.

It still fixes the same thing: on main, rdna2::sgpr_uses/vgpr_uses still read an SDWA instruction as its base dword. So v_cmp_lt_f32_sdwa s5, v1, s2 reports no SGPR write and a read of v2, which reaches constant_samplers and geometry_wave32_hazards.

Windows, Ryzen 9 5950X: cargo build --workspace ok; cargo test -p xcl --lib 2744 passed, 0 failed, 31 ignored. The PR's two tests pass. With rdna2.rs as on main, sdwa_compare_destination_is_a_write_to_the_analyses fails (whole-wave mask reduction not found), so the test still catches it.

For merging it still needs the two xcl-smoke blocks (CONTRIBUTING.md, "Regression run"). I can't make those here, so anyone who can run scripts/smoke.ps1 on a title from main and from c9ef0b8 is welcome to post them.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head c9ef0b8

No open or merged PR makes the same change. On main, rdna2::sgpr_uses ignores an SDWA instruction's S0/S1 bits and the VOPC SD destination, and vgpr_uses counts an S1-selected VSRC1 as a VGPR. #2068 touches SDWA VSRC1 only in the direct-DXIL lowering (lower_valu.rs), and #2479 (merged) covers reload::changes, not these helpers. The bit positions (S0 bit 23, SDST 14:8, SD bit 15, S1 bit 31) and the encoded test words check out.
The failing check is PR description; Build and test passes.
Recommendation: keep open.

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

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 area:tests Unit, integration, e2e tests, or testtitle gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) 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.

10 participants