Skip to content

Recompiler: clamp out-of-range format and sub-dword buffer loads - #1241

Open
eizispark wants to merge 1 commit into
xcl-dev:mainfrom
eizispark:fix/916-buffer-load-bounds
Open

eizispark wants to merge 1 commit into
xcl-dev:mainfrom
eizispark:fix/916-buffer-load-bounds

Conversation

@eizispark

@eizispark eizispark commented Nov 24, 2026 •

Copy link
Copy Markdown

BufKind::Load clamps inactive (!act) and out-of-range (!ok) MUBUF addresses to 0u before reading the memory window, whereas BufKind::FormatLoad, mubuf_d16, and sub-dword MUBUF loads still passed unclamped 32-bit {t}_a offsets into ld_raw (whose arguments HLSL 2021 select() evaluates eagerly). When an inactive or out-of-range lane holds a large or negative/sentinel offset past a 512 MiB or 4095 MiB window while xcl_w still selects that window, storage-buffer translation under vkd3d-proton on NVIDIA Vulkan can fault the GPU MMU (NVRM: Xid 13 … MMU Fault, #916).

Part of #916.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: clamp ld_raw addresses to 0u via select(and({t}_act, {t}_ok), {t}_a, 0u) in BufKind::FormatLoad, mubuf_d16 loads, and sub-dword MUBUF loads (buffer_load_ubyte / sbyte / ushort / sshort).
  • crates/xcl/src/gpu/recomp/tests.rs: add format_and_subdword_buffer_loads_clamp_out_of_range_offsets checking generated 1-window and 4-window HLSL and GPU execution across in-range, out-of-range, and EXEC-masked lanes for buffer_load_format_xyzw, tbuffer_load_format_xyzw, buffer_load_ubyte, buffer_load_short_d16, and buffer_load_format_d16_xy.

Tested

  • Windows 11 x64, AMD Ryzen 7 9800X3D, AMD Radeon RX 9070 XT (driver 32.0.32015.16001), rustc 1.100.0 (0ef1bc386 2026-11-09), debug and release.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 752 passed, 0 failed, 41 ignored, 0 SKIPPED GPU capability skips (the 2 optional d3d12SDKLayers.dll tests return early because Windows Graphics Tools is not installed on this host).
  • format_and_subdword_buffer_loads_clamp_out_of_range_offsets failed before the emit.rs changes (FormatLoad and sub-dword loads emitted unclamped ld_raw(tN_a) calls) and passes after them (gpu::recomp: 190 passed, 0 failed, 18 ignored).

Regression run

main:

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

PR head:

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

Not tested

AI use

  • Antigravity (Google DeepMind, Gemini 4 Carbon) — audited MUBUF format and sub-dword load address clamping in emit.rs, wrote the fix and GPU test, and ran the test suite and 60 s smoke check.

@dcastell1

Copy link
Copy Markdown

Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on main@930e8b4 (baseline 751 passed, 0 failed, 41 ignored on this box):

patch -p1 < this PR            # clean, no fuzz
cargo test --workspace -- --test-threads=4
753 passed; 0 failed; 41 ignored   (exit 0)

Two more than the baseline: clamping out-of-range buffer loads and 64-bit cases are covered and green.

Tree restored afterwards (full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib lib recomp: 190 passed, 0 failed.

Thanks!

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

The vector-load half looks right to me. ld_raw(select(and(act, ok), a, 0u)) removes the eager out-of-range read that HLSL 2021's select evaluated, and v = select(act, select(ok, val, 0u), v) is the old if (act) v = ok ? val : 0u.

The s_buffer_load half changes behaviour, not only overflow handling, and I don't know which side RDNA2 is on:

  • With imm + soff widened to 64 bits, an offset whose sum passes 2^32 is now out of range (0). Before, it wrapped to a low, in-range offset. Whether the scalar unit forms the buffer offset as a 32-bit sum, so that it wraps, is the question. The range check is against a 32-bit num_records.
  • The same goes for num_records * stride past 2^32: is the hardware's limit the full product or a 32-bit one?

gpu_s_buffer_load_64bit_bounds_and_offset checks this PR's model, so it would pass either way the hardware went. A raw-ISA run on an RDNA2 card would settle both: an s_buffer_load_dword with soff = 0xFFFFFFFC, imm = 8, and num_records covering offset 4. Lyrnc and luckyteagirl have run probes like that for #605 and #772. Until then, the two parts could go separately so the clamping isn't held up. Read from the diff, not run.

AI-assisted (Claude Code).

BufKind::Load clamps inactive and out-of-range MUBUF addresses to 0u
before reading the memory window, whereas BufKind::FormatLoad,
mubuf_d16, and sub-dword MUBUF loads passed unclamped 32-bit offsets
into ld_raw (whose arguments are evaluated eagerly by HLSL 2021
select()). When a lane's offset lies past a 512 MiB or 4095 MiB window
while xcl_w still names that window, Vulkan storage-buffer translation
under vkd3d-proton can fault the GPU MMU (ivall#916).

Clamp ld_raw addresses to 0u on !act || !ok across FormatLoad,
mubuf_d16, and sub-dword MUBUF loads.

Part of ivall#916.

Assisted-by: Antigravity (Google DeepMind, Gemini 4 Carbon)
@eizispark
eizispark force-pushed the fix/916-buffer-load-bounds branch from a4fd6c8 to 7b7c853 Compare November 24, 2026 15:08
@eizispark eizispark changed the title Recompiler: clamp out-of-range buffer loads and 64-bit s_buffer_load Recompiler: clamp out-of-range format and sub-dword buffer loads Nov 24, 2026
@eizispark

Copy link
Copy Markdown
Author

Thanks @upipibi for catching that s_buffer_load imm + soff and num_records * stride wrapping vs 64-bit bounds has not been measured on live RDNA2 hardware yet, and thanks @dcastell1 and @DavidM1911 for the test reports.

I split the s_buffer_load change and test out of this PR pending a raw-ISA probe on RDNA2, rebased onto current main (930e8b4) keeping only the FormatLoad, d16, and sub-dword MUBUF ld_raw clamping and its test as a single commit (7b7c853), and updated the PR description with fresh workspace test counts and a fresh 60 s xcl-smoke run on 7b7c853.

AI use: Antigravity (Gemini 4 Carbon)

@ivall ivall added the goal:world-load Bears on the retail title getting past world loading label Nov 24, 2026
IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Test report for exact head 7b7c853.

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 7b7c853 as it is (its own base): 752 passed, 0 failed, 41 ignored. SKIPPED: 2 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:

main:

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

PR:

xcl-smoke v1
commit: 7b7c85359bec868c2b75fe0d078e6973e1c70b4c
gpu: NVIDIA GeForce RTX 4080
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1581 (PresentX 1581)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15901 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.

@xpatfussy69x

Copy link
Copy Markdown

Test report for head 7b7c853 as pushed (not merged onto current main) – Windows, NVIDIA, wave32-only adapter (both listed under Not tested).

Tested

  • NVIDIA GeForce RTX 3060 12 GB (Ampere, 32-lane waves only), driver 32.0.16.2124; AMD Ryzen 5 7500F; Windows NT 10.0.26300; Rust 1.100.0 (stable-x86_64-pc-windows-msvc); debug; DXC 1.9.2609.5
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 752 passed, 0 failed, 41 ignored
  • SKIPPED GPU tests on this adapter: 2 (no wave64)
  • this PR's test format_and_subdword_buffer_loads_clamp_out_of_range_offsets ran and passed; the existing GPU buffer tests (gpu_global_atomics_and_sub_dword_access, gpu_more_atomics_sub_dword_scratch_valu, …) pass too
  • no XCL_SAMPLE_* data set (game-data tests not run)

Not tested

  • AMD GPUs / native wave64; release build; a smoke run on a title; Linux + vkd3d-proton; the head merged onto current main

AI use

  • Claude (Claude Opus 5.5) wrote the script that ran the suite on my PC, read the log and wrote and posted this report with my approval; the run is mine.

@4usphs

4usphs commented Nov 25, 2026

Copy link
Copy Markdown

AMD run on the exact head 7b7c853 (7b7c853), as pushed on its base 930e8b4 (not merged onto current main), on two AMD adapters with native 64-lane waves: RDNA4 and the console's generation, RDNA2.

Tested

  • Ryzen 7 9800X3D, Windows 11 Pro 26200, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug, clean checkout, XCL_TRANSLATED_CACHE=0; adapter picked with XCL_ADAPTER.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4:
    • AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: 752 passed, 0 failed, 41 ignored
    • AMD Radeon(TM) Graphics, the 9800X3D's iGPU (RDNA2, gfx1036), driver 32.0.21045.29003: 752 passed, 0 failed, 41 ignored
  • No SKIPPED tests on either adapter.
  • This PR's test format_and_subdword_buffer_loads_clamp_out_of_range_offsets runs and passes on both adapters.

Not tested

  • smoke or a retail title (I have none), a release build, Linux.

AI use

  • Claude Code (Claude Opus 5.5) read the diff, ran the tests and the base-commit controls on my PC and wrote this report. I have not reviewed the code.

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.

8 participants