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
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.

5 participants