Skip to content

Recompiler: track SMEM register offsets as scalar reads - #1540

Open
oni-swr wants to merge 1 commit into
xcl-dev:mainfrom
oni-swr:recompiler/smem-offset-uses
Open

oni-swr wants to merge 1 commit into
xcl-dev:mainfrom
oni-swr:recompiler/smem-offset-uses

Conversation

@oni-swr

@oni-swr oni-swr commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

SMEM's register offset has operand type OPR_SMEM_OFFSET, which sgpr_uses omitted. A register used only as SOFFSET was therefore absent from the read set; the per-lane lowering on gefydev's branch could reject such a load because its initial SGPR value was not loaded. Part of #1269.

What is in it

  • rdna2.rs: include SMEM register offsets in scalar reads; test s4, s7 and NULL offsets, preserving the destination write set.

Tested

  • RX 7800 XT, driver 32.0.31035.1003; Ryzen 7 5700X3D; Windows 11 Pro build 26200; Rust 1.100.0 MSVC; debug.
  • cargo test -p xcl --lib gpu::rdna2::tests::scalar_memory_register_offset_is_a_read -- --exact: on main 9e3831e with only the test added, 0 passed / 1 failed / 0 ignored. The fixed test passes in the full suite below.
  • cargo build --workspace: passed at a8683ef.
  • cargo test --workspace -- --test-threads=4 --nocapture: 777 passed / 0 failed / 41 ignored. One SKIPPED test (included in the harness's passed count): heap_window_out_of_memory_falls_back_to_the_switch_form, reason no heap windows; this is not coverage.
  • 60-second title regression runs below use the debug binary built separately from each commit.

Regression run

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: AMD Radeon RX 7800 XT
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 744 (PresentX 744)
presents per 2 s (last 3): 55 24 0
device removals: 0
crashes: 0
peak commit: 15435 MB
xcl-smoke v1
commit: a8683ef45d1a38e0200558e6666ec965476e5e6b
gpu: AMD Radeon RX 7800 XT
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 820 (PresentX 820)
presents per 2 s (last 3): 45 12 7
device removals: 0
crashes: 0
peak commit: 16226 MB

Not tested

  • NVIDIA, Wine, release builds. The smoke runs do not exercise the unmerged per-lane DXIL backend; they check the current runtime. No claim of title performance improvement.

AI use

  • T3 Code through Codex, gpt-6.1-sol: investigated the issue and coordination thread, wrote the fix and test, ran validation, and wrote this description.

SMEM SOFFSET has operand type OPR_SMEM_OFFSET, which sgpr_uses omitted. Include it so clients such as the per-lane lowering initialize the offset register. Test SGPR offsets and NULL; the test fails on main without this change.

Assisted-by: T3 Code / Codex (gpt-6.1-sol)
@oni-swr
oni-swr marked this pull request as ready for review November 24, 2026 18:09
@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Read the diff against the ISA tables: the scope is right. In rdna2_spec.rs the only field typed OPR_SMEM_OFFSET is SMEM's SOFFSET (all the S_LOAD / S_BUFFER_LOAD / store / atomic forms). The 21-bit immediate OFFSET is not an operand there, so this can't make an immediate look like an SGPR read. SOFFSET 0 is s0, not NULL (0x7D), so a load with an unset SOFFSET now reads s0, which is right (the same distinction as #1456's test fix). M0 (124) as SOFFSET is a read too, as it should be. I haven't run it.

AI use: Claude Code (Claude Opus 5.5) read the change and wrote this.

@nnonno91

Copy link
Copy Markdown

Independent NVIDIA and per-lane lowering test for a8683ef45d1a38e0200558e6666ec965476e5e6b.

Tested

  • Windows 11 25H2 (26200.9974), Ryzen 7 9800X3D, NVIDIA GeForce RTX 5090 (32.0.16.1742), Rust 1.100.0 MSVC, DXC 1.9.2609.5, debug. cargo build --workspace --locked passed. cargo test --locked -p xcl --lib -- --exact gpu::rdna2::tests::scalar_memory_register_offset_is_a_read --test-threads=1 passed.
  • cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --show-output reported 777 passed, 0 failed, and 41 ignored. Three reported GPU skips in that pass count: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no wave64), plus heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows). The bundled title passed.
  • In a separate worktree at gefydev/xcl:direct-on-1426 revision c391dbf9dedcd87e4e6968a70c0280d5d88aa7dd, I ran cargo test --locked -p xcl --test smem_offset_probe -- --exact register_offset_reaches_per_lane_dxil --nocapture --test-threads=1 with a temporary three-instruction shader before and after applying just the PR’s production change. Before, S_LOAD_DWORD listed s0 and s1 as reads and per-lane lowering refused with s4: a mask read as a number. After, it also listed s4, validated the directly generated DXIL, and executed it on the RTX 5090. Register offsets of 0, 4, and 12 bytes selected the expected three memory words across all 32 lanes each time. Both versions listed s16 as the destination.

Not tested

Retail titles, Wine, or release builds. The per-lane run used a synthetic kernel on the pinned experimental revision with the one-line fix applied locally.

AI use

OpenAI Codex (GPT-6 family, exact variant unavailable) wrote the temporary probe, ran the checks, and drafted this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

@ivall ivall added the goal:world-load Bears on the retail title getting past world loading label Nov 24, 2026
@vakaobr

vakaobr commented Nov 25, 2026

Copy link
Copy Markdown

Test report from a Mac (D3DMetal), #1540 at a8683ef merged into main c4d37be.

The per-lane form refuses every kernel whose s_load_dword names an SGPR as SOFFSET that the program didn't write first: s_load_dword s4, s[2:3], s0, 0x8 and the same with s1 both give s0 / s1: a mask read as a number on main. With the same register as an s_add_u32 source, or after an s_mov_b32 writes it, it's accepted, which fits your reading (the prologue never loads a register sgpr_uses doesn't list). In my differential harness that was 995 of 1000 generated programs refused on main.

Tested

  • MacBook Pro M5 Pro (20-core GPU, 32-lane waves), macOS 27.2.1, CrossOver 26.3 with D3DMetal 3.0, Rosetta 2, Rust 1.100.0 x86_64-pc-windows-gnu, debug, DXC 1.9.2609. Each test in its own process.
  • gpu::rdna2::tests::scalar_memory_register_offset_is_a_read: 1 passed.
  • 9 single-instruction kernels through lower_dxil::kernel_split (SOFFSET s0, s1, null, s0 after s_mov_b32, and s0 / s1 as ALU sources): refused 2 on main, all 9 accepted with this PR.
  • 1000 generated programs, HLSL path against gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426's per-instruction form: 0 differences with this PR, as on main.
  • 1000 generated programs without divergent ifs, HLSL path against the per-lane form: 996 identical and 0 refused with this PR (995 refused on main). The other 4 differ in the HLSL path only; the per-lane and per-instruction forms agree with each other there (details on [OFFICIAL] Looking for PRs with shaders optimization #1269).

Not tested

  • Windows, the whole suite, a title; compute mode (lower_dxil::compute*), where the same sgpr_uses list may decide which user SGPRs are loaded.

AI use: Claude Code, Claude Opus 5.5 found the refusals with the harness, ran the tests above on this machine and wrote this report.

@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Test report for exact head a8683ef.

Tested

  • Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 4080 (driver 610.88, 32-lane waves), Intel i9-12900K, 64 GB; Rust 1.100.0 MSVC; DXC 1.9.2602.17; tests in debug, title runs in release.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 on a8683ef as it is (its own base): 777 passed, 0 failed, 41 ignored. SKIPPED: 3 lines (no wave64 on this adapter, and the like).
  • scripts/smoke.ps1, the retail title, 60 s, release builds, main 568e7db first, then this head. Both runs started without the preload list newer builds leave behind (used-pipelines.txt in the DXIL cache), which makes builds on an older base run out of memory at start:

main:

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 4080
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1608 (PresentX 1608)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14538 MB

PR:

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

Not tested: AMD, the head merged onto current main, a world load.

AI use: Claude Code (Claude Opus 5.5) ran this and wrote the report; the diff was read for safety by a Claude Opus 5.5 sub-agent before it was built.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants