Recompiler: scratch SADDR 0x7F addresses the offset alone (ST form) #2514

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

@⁠oni-swr on GitHub · 2026-11-25 21:15 UTC · original
oni-swr:t3/xcl-fix-2400-dxil-scratch-addr → main · +104 −9 · 4 files · 1 commits · draft

On RDNA2, scratch_* picks its address form from SADDR alone:

  • an SGPR is SS (SGPR + offset),
  • NULL (0x7D) is SV (VADDR + offset),
  • 0x7F (EXEC_HI) is ST (the offset alone).

Both lowerings took 0x7F for the SV form and added ADDR's VGPR. So an ST access landed on whatever per-lane address that VGPR held. Now 0x7F gives a zero base, and ADDR is read only for 0x7D.

The issue also proposed checking an SVE bit and adding SGPR + VGPR. RDNA2 has neither: the RDNA2 ENC_FLAT_SCRATCH spec in rdna2_spec.rs has no SVE field, and both SVE and the SVS form arrived with GFX11 / GFX940. The source for the GFX10 encoding is LLVM:

  • FLAT_Real_gfx10 sets Inst{54-48} to EXEC_HI for a scratch op without vaddr and to SGPR_NULL otherwise, and sets Inst{55} to 0.
  • The gfx1030 MC test encodes scratch_load_dword v1, off, off with byte 6 = 0x7f.

So only the ST half of the issue applies, and that is what this fixes.

Fixes #2400
Part of #1269

What is in it

  • crates/xcl/src/gpu/dxil/lower_mem.rs (scratch): the base is 0 for SADDR 0x7F, VADDR for 0x7D and the SGPR otherwise (direct DXIL).
  • crates/xcl/src/gpu/recomp/emit.rs (scratch): the same in the HLSL emitter, which had the same bug.
  • Tests:
    • dxil/core_tests.rs::scratch_reads_addr_only_in_the_sv_form: ST and SS containers do not change with ADDR, SV ones do.
    • recomp/tests.rs::scratch_address_forms_follow_saddr: the HLSL address of each form.
    • recomp/tests.rs::gpu_scratch_address_forms: GPU test of the three forms.
    • The existing gpu_more_atomics_sub_dword_scratch_valu now encodes the SV form (0x7D) its comment describes ("2 · lane + 16").

Tested

  • Windows 11 Pro build 26200, AMD Ryzen 7 5700X3D, rustc 1.100.0, debug.
  • CPU only: XCL_ADAPTER=NONE_CPU_ONLY, so no D3D12 device was created. DXC 1.8.2502.11 and the dxil.dll validator from the Windows SDK were used.
  • cargo test --workspace -j 4 -- --test-threads=4 on 57853e01: 1426 passed, 0 failed, 46 ignored. 218 GPU tests SKIPPED: no GPU and adapter-selection skips because of XCL_ADAPTER, including the new gpu_scratch_address_forms.
  • The two CPU tests fail without the fix: "ST: the offset alone" and "ST (SADDR 0x7f) must not read ADDR". They pass with it.
  • cargo clippy -p xcl --lib --tests: no findings on the changed lines. The lib already fails clippy on main, on lower_valu.rs:560 and lower_wide.rs:568 (approximate TAU).
  • cargo fmt --check: the tree is not rustfmt-clean, so it reports 8536 existing diffs. The added code is formatted the way rustfmt wants.

Regression run

  • Not run yet. The GPU on this machine is in use, so scripts/smoke.ps1 was not run on main or on this head. This PR stays a draft until both xcl-smoke blocks are added.

Not tested

  • Any GPU run: the new gpu_scratch_address_forms and every other GPU test were skipped. No HLSL or direct DXIL kernel was run on hardware, and no NVIDIA, Intel or wave32-only GPU was tried.
  • A retail title (no smoke run, see above).
  • How common the ST form is in retail shaders.

AI use

  • Claude Code (Claude Opus 5.5) wrote the fix, the tests and this description. It also checked the GFX10 encoding against LLVM's FLATInstructions.td and MC tests, and ran the commands above.

🤖 Generated with Claude Code

**@⁠oni-swr** on GitHub · 2026-11-25 21:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/2514) `oni-swr:t3/xcl-fix-2400-dxil-scratch-addr` → `main` · +104 −9 · 4 files · 1 commits · draft On RDNA2, `scratch_*` picks its address form from SADDR alone: - an SGPR is SS (SGPR + offset), - NULL (`0x7D`) is SV (VADDR + offset), - `0x7F` (EXEC_HI) is ST (the offset alone). Both lowerings took `0x7F` for the SV form and added ADDR's VGPR. So an ST access landed on whatever per-lane address that VGPR held. Now `0x7F` gives a zero base, and ADDR is read only for `0x7D`. The issue also proposed checking an SVE bit and adding SGPR + VGPR. RDNA2 has neither: the RDNA2 `ENC_FLAT_SCRATCH` spec in `rdna2_spec.rs` has no SVE field, and both SVE and the SVS form arrived with GFX11 / GFX940. The source for the GFX10 encoding is LLVM: - `FLAT_Real_gfx10` sets `Inst{54-48}` to EXEC_HI for a scratch op without vaddr and to SGPR_NULL otherwise, and sets `Inst{55}` to 0. - The gfx1030 MC test encodes `scratch_load_dword v1, off, off` with byte 6 = `0x7f`. So only the ST half of the issue applies, and that is what this fixes. Fixes #2400 Part of #1269 **What is in it** - `crates/xcl/src/gpu/dxil/lower_mem.rs` (`scratch`): the base is 0 for SADDR `0x7F`, VADDR for `0x7D` and the SGPR otherwise (direct DXIL). - `crates/xcl/src/gpu/recomp/emit.rs` (`scratch`): the same in the HLSL emitter, which had the same bug. - Tests: - `dxil/core_tests.rs::scratch_reads_addr_only_in_the_sv_form`: ST and SS containers do not change with ADDR, SV ones do. - `recomp/tests.rs::scratch_address_forms_follow_saddr`: the HLSL address of each form. - `recomp/tests.rs::gpu_scratch_address_forms`: GPU test of the three forms. - The existing `gpu_more_atomics_sub_dword_scratch_valu` now encodes the SV form (`0x7D`) its comment describes ("2 · lane + 16"). **Tested** - Windows 11 Pro build 26200, AMD Ryzen 7 5700X3D, rustc 1.100.0, debug. - CPU only: `XCL_ADAPTER=NONE_CPU_ONLY`, so no D3D12 device was created. DXC 1.8.2502.11 and the dxil.dll validator from the Windows SDK were used. - `cargo test --workspace -j 4 -- --test-threads=4` on 57853e01: 1426 passed, 0 failed, 46 ignored. 218 GPU tests SKIPPED: `no GPU` and adapter-selection skips because of `XCL_ADAPTER`, including the new `gpu_scratch_address_forms`. - The two CPU tests fail without the fix: "ST: the offset alone" and "ST (SADDR 0x7f) must not read ADDR". They pass with it. - `cargo clippy -p xcl --lib --tests`: no findings on the changed lines. The lib already fails clippy on main, on `lower_valu.rs:560` and `lower_wide.rs:568` (approximate TAU). - `cargo fmt --check`: the tree is not rustfmt-clean, so it reports 8536 existing diffs. The added code is formatted the way rustfmt wants. **Regression run** - Not run yet. The GPU on this machine is in use, so `scripts/smoke.ps1` was not run on main or on this head. This PR stays a draft until both `xcl-smoke` blocks are added. **Not tested** - Any GPU run: the new `gpu_scratch_address_forms` and every other GPU test were skipped. No HLSL or direct DXIL kernel was run on hardware, and no NVIDIA, Intel or wave32-only GPU was tried. - A retail title (no smoke run, see above). - How common the ST form is in retail shaders. **AI use** - Claude Code (Claude Opus 5.5) wrote the fix, the tests and this description. It also checked the GFX10 encoding against LLVM's `FLATInstructions.td` and MC tests, and ran the commands above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
RDNA2 scratch_* has three address forms, chosen by SADDR alone: an
SGPR is SS (SGPR + offset), NULL (0x7D) is SV (VADDR + offset) and
0x7F (EXEC_HI) is ST (the offset alone). There is no SGPR + VGPR form
and no SVE bit on RDNA2; both came with GFX11 / GFX940. This is how
LLVM encodes GFX10 scratch (FLAT_Real_gfx10 sets Inst{54-48} to EXEC_HI
for a scratch op without vaddr and to SGPR_NULL otherwise, and Inst{55}
to 0), and its gfx1030 MC tests encode `scratch_load_dword v1, off, off`
with byte 6 = 0x7f.

Both lowerings (direct DXIL lower_mem.rs and the HLSL emitter) took
0x7F for the SV form and added ADDR's VGPR, so an ST access went to a
per-lane address that its value happened to hold. They now use 0 as the
base for 0x7F, so ADDR is read only for 0x7D.

Issue #2400 proposed checking an SVE bit and adding SGPR + VGPR. The
RDNA2 ENC_FLAT_SCRATCH spec has no SVE field (bit 55 is not decoded),
so that half does not apply; the ST case it describes is real and is
the one fixed here.

Tests: an HLSL text check of the three forms and a direct DXIL check
that ST and SS containers do not change with ADDR while SV ones do
(both fail without the fix), a GPU test of the three forms, and the
existing scratch GPU test now encodes the SV form it describes.

Fixes #2400

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:32:35 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 21:32 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 21:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/2514#issuecomment-7175203899) 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!
Author
Owner

@⁠ahmetbagci8 on GitHub · 2026-11-25 22:22 UTC · original

Tested

  • Commit: 57853e017054d715cd46cd3c07cb70e58eddddc8
  • Hardware / OS: Intel Core i7-11800H, NVIDIA GeForce RTX 3070 Laptop GPU (driver 32.0.16.1714), Windows 11 Pro (Build 26300), DXC v1.9.2609
  • cargo test -j 2 -p xcl --lib scratch -- --test-threads=4: 8 passed; 0 failed; 0 ignored (2.03s)

Not tested

  • Full workspace suite and scripts/smoke.ps1 (no unpacked title locally).

AI use

  • Antigravity harness (Gemini 4 Neon) ran the targeted unit tests on this commit and drafted this report; the author reviewed it before posting.
**@⁠ahmetbagci8** on GitHub · 2026-11-25 22:22 UTC · [original](https://github.com/xcl-dev/xcl/pull/2514#issuecomment-7176278074) ### Tested - **Commit:** `57853e017054d715cd46cd3c07cb70e58eddddc8` - **Hardware / OS:** Intel Core i7-11800H, NVIDIA GeForce RTX 3070 Laptop GPU (driver `32.0.16.1714`), Windows 11 Pro (Build 26300), DXC `v1.9.2609` - `cargo test -j 2 -p xcl --lib scratch -- --test-threads=4`: `8 passed; 0 failed; 0 ignored (2.03s)` ### Not tested - Full workspace suite and `scripts/smoke.ps1` (no unpacked title locally). ### AI use - Antigravity harness (Gemini 4 Neon) ran the targeted unit tests on this commit and drafted this report; the author reviewed it before posting.
Author
Owner

@⁠SlopTart on GitHub · 2026-11-25 22:33 UTC · original

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 target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).

gpu_ suite (cold cache): 165 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR.
No new test functions in the diff; the SADDR 0x7F ST-form change is exercised end to end by the existing suite, clean here.

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.

**@⁠SlopTart** on GitHub · 2026-11-25 22:33 UTC · [original](https://github.com/xcl-dev/xcl/pull/2514#issuecomment-7176502876) **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 target `x86_64-pc-windows-gnu` run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29). `gpu_` suite (cold cache): 165 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR. No new test functions in the diff; the SADDR 0x7F ST-form change is exercised end to end by the existing suite, clean here. **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.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-25 23:17 UTC · original

Native RX 6800M validation on exact PR head 57853e017054d715cd46cd3c07cb70e58eddddc8 (Windows 11 build 26200, Radeon RX 6800M driver 30.0.13002.13003, Rust 1.99.0 MSVC, DXC/DXIL 1.8.2502.11):

  • XCL_ADAPTER=6800M XCL_REQUIRE_GPU=1 XCL_DIRECT_DXIL=1 cargo test --locked -p xcl --lib -j 1 gpu_scratch_address_forms -- --test-threads=1 --show-output: 1 passed, 0 failed, 0 ignored, 0 SKIPPED (1,326 filtered out). The test ran on the RX 6800M; runner::run_code selects the direct kernel path for XCL_DIRECT_DXIL=1.
  • Repeated the same exact-head fixture with XCL_DIRECT_DXIL=0 to exercise HLSL + DXC lowering: 1 passed, 0 failed, 0 ignored, 0 SKIPPED (1,326 filtered out).
  • Both completed runs used the memory guard, which did not stop them. Two earlier compilation attempts stopped at the guard before any test executed and are excluded from these counts.

Not tested: the full GPU workspace suite, release binary, paired retail smoke runs, other adapters/drivers, and whether the title encounters ST-form scratch instructions. This is focused hardware coverage of the new fixture, not a merge-ready regression run. No game data was uploaded.

AI use: OpenAI Codex (GPT-6; exact variant unavailable) ran the guarded focused tests, checked the exact head and runner selection, reviewed the logs, and drafted this report.

**@⁠luckyteagirl** on GitHub · 2026-11-25 23:17 UTC · [original](https://github.com/xcl-dev/xcl/pull/2514#issuecomment-7177360473) **Native RX 6800M validation on exact PR head `57853e017054d715cd46cd3c07cb70e58eddddc8`** (Windows 11 build 26200, Radeon RX 6800M driver `30.0.13002.13003`, Rust 1.99.0 MSVC, DXC/DXIL 1.8.2502.11): - `XCL_ADAPTER=6800M XCL_REQUIRE_GPU=1 XCL_DIRECT_DXIL=1 cargo test --locked -p xcl --lib -j 1 gpu_scratch_address_forms -- --test-threads=1 --show-output`: **1 passed, 0 failed, 0 ignored, 0 SKIPPED** (1,326 filtered out). The test ran on the RX 6800M; `runner::run_code` selects the direct kernel path for `XCL_DIRECT_DXIL=1`. - Repeated the same exact-head fixture with `XCL_DIRECT_DXIL=0` to exercise HLSL + DXC lowering: **1 passed, 0 failed, 0 ignored, 0 SKIPPED** (1,326 filtered out). - Both completed runs used the memory guard, which did not stop them. Two earlier compilation attempts stopped at the guard before any test executed and are excluded from these counts. **Not tested:** the full GPU workspace suite, release binary, paired retail smoke runs, other adapters/drivers, and whether the title encounters ST-form scratch instructions. This is focused hardware coverage of the new fixture, not a merge-ready regression run. No game data was uploaded. **AI use:** OpenAI Codex (GPT-6; exact variant unavailable) ran the guarded focused tests, checked the exact head and runner selection, reviewed the logs, and drafted this report.
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/2514/head:github-bot/gh-2514'
git switch 'github-bot/gh-2514'

Merge

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