Skip to content

Recompiler: direct DXIL s_buffer_load offsets wrap within their window - #2062

Open
LucasHoepfner wants to merge 1 commit into
xcl-dev:mainfrom
LucasHoepfner:dxil-raw-buffer-bounds
Open

LucasHoepfner wants to merge 1 commit into
xcl-dev:mainfrom
LucasHoepfner:dxil-raw-buffer-bounds

Conversation

@LucasHoepfner

@LucasHoepfner LucasHoepfner commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

With two or more memory windows, the direct DXIL translator read an s_buffer_load whose 32-bit offset (OFFSET + soff) wraps from the next window, 4 GiB above the buffer. It used the wrapped sum for the range check and the address, but took the window from the two parts added in 64 bits. The HLSL path uses the 32-bit sum for all three. Part of #1893: #1933 has the MUBUF and atomic cases, and with it this is every case measured there where the two translators differ (#1893 (comment)), so the issue can be closed once both are in.

What is in it

  • Recompiler: direct DXIL s_buffer_load offsets wrap within their window: the window comes from the 32-bit offset (crates/xcl/src/gpu/dxil/lower_mem.rs, one line), with the GPU test gpu_scalar_buffer_load_offset_wraps_within_its_window (crates/xcl/src/gpu/recomp/tests.rs): s_buffer_load_dword and dwordx4 with OFFSET 0x20 and soff 0xFFFF_FFF0 on a two-window arena, through both translators and both window forms.

Tested

  • NVIDIA GeForce RTX 3060 Ti 8 GB (32-lane waves), driver 621.01; Intel Core i7-14700KF, 32 GB; Windows 11 Pro 26200; rustc 1.99.1 stable-x86_64-pc-windows-msvc; DXC 1.8.2502.11; debug. This head (7e2c923, on main aaa0936).
  • cargo test -p xcl --lib gpu_scalar_buffer_load_offset_wraps_within_its_window: without the lower_mem.rs line, 1 failed at direct true, heap windows false: dword (left 0xB000_0000, window 1's marker; right 0xA000_0000); with it, 1 passed.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1152 passed, 0 failed, 46 ignored. SKIPPED: 20 × no wave64, heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows), pso_measurement_compiles_an_exact_synthetic_record (Developer Mode is off), 3 per-lane programs with f16 instructions (refused (unsupported …)).

Regression run

main aaa0936:

xcl-smoke v1
commit: aaa093657bd96a146c05c0c1a9b61149fe761453
gpu: NVIDIA GeForce RTX 3070
title: 3d7db37d
seconds: 60
exit: 0x0
frames shown: 1410 (PresentX 1410)
presents per 2 s (last 3): 59 61 60
device removals: 0
crashes: 0
peak commit: 15274 MB

This head 7e2c923:

xcl-smoke v1
commit: 7e2c9235dfc6ab91dee9f85eaca03d50174506b6
gpu: NVIDIA GeForce RTX 3070
title: 3d7db37d
seconds: 60
exit: 0x0
frames shown: 1560 (PresentX 1560)
presents per 2 s (last 3): 61 60 51
device removals: 0
crashes: 0
peak commit: 15097 MB

Not tested

  • A retail title by me, or past the menus (the smoke run above does not show the title reaching an s_buffer_load that wraps); AMD / Intel GPUs; native wave64; a release build of the tests.
  • Whether a title ever has such an offset: the case is synthetic.
  • The issue's two other remarks (soff is not part of the MUBUF range check; num_records * stride can wrap) are the same on the HLSL path and are not changed here.

AI use

  • Claude Code (Claude Fable 5.2) found the case, wrote the change, the test and this description, and ran the tests.

A scalar buffer load's offset is OFFSET + soff in 32 bits. The direct
translator used that sum for the range check and the address, but took
the memory window from the two parts added in 64 bits. Where the sum
wraps, the check passed on the wrapped offset and the load read the
right low address in the next window, 4 GiB above the buffer. The HLSL
path uses the 32-bit sum for all three.

The window now comes from the 32-bit offset too.

Test: s_buffer_load_dword and dwordx4 with OFFSET 0x20 and soff
0xFFFF_FFF0 on a two-window arena, through both translators and both
window forms. Without the change the direct path returns window 1's
marker (0xB000_0000 where 0xA000_0000 is expected); the HLSL path
passes before and after.

Part of xcl-dev#1893; xcl-dev#1933 has the MUBUF and atomic cases.

Assisted-by: Claude Code (Claude Fable 5.2)
@JoaoPauluu

Copy link
Copy Markdown

A run with vkd3d-proton as the host D3D12. The DXIL goes through dxil-spirv and then the NVIDIA Vulkan driver, a different compiler from a native-Windows run: this PR's new test passes.

Tested

  • RTX 3060 12 GB (NVIDIA 620.70.06, 32-lane waves), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from Linux: docs/linux.md, scripts/linux and Wine start-up checks for vkd3d-proton and DXVK (#154, #241) #257, DXC 1.9.2609.5. Release, cross-built for x86_64-pc-windows-gnu. 7e2c923 as it is (merge base with main aaa0936), no uncommitted changes. The lib test binary runs under Wine, one test per process.
    • gpu_scalar_buffer_load_offset_wraps_within_its_window: ok, not skipped

Not tested

  • the whole suite on this head, a retail title, native Windows, AMD.

AI use

  • Claude Code (Claude Opus 5.5) built the commit, ran the tests and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.

@Parakeet-Wheat

Copy link
Copy Markdown

NVIDIA RTX 3070 on native Windows, head 7e2c923 on its base aaa0936: the new test fails without the lower_mem.rs line and passes with it, the whole suite passes, and the smoke pair is within the limits.

Tested

  • NVIDIA GeForce RTX 3070 8 GB (driver 610.88, 32-lane waves), Ryzen 5 5600X, 32 GB, Windows 11 26300, Rust 1.95.0 stable-x86_64-pc-windows-msvc, DXC 1.8.2502.11, retail 1.0.2.1. Head 7e2c923 (one commit on main aaa0936), checked out clean. Tests in the debug profile, smoke in release.
  • cargo test -p xcl --lib gpu_scalar_buffer_load_offset_wraps_within_its_window -- --nocapture --test-threads=1:
    • on aaa0936 with only the PR's tests.rs copied in: 1 failed, direct true, heap windows false: dword, left 2952790016 (0xB000_0000, window 1's marker), right 2684354560 (0xA000_0000);
    • on 7e2c923: 1 passed, 0 failed, not skipped.
  • .\scripts\test.ps1 (cargo build --workspace, then cargo test --workspace -- --test-threads=4) on 7e2c923: 1152 passed, 0 failed, 46 ignored across 20 test binaries, exit 0. SKIPPED, 25: 20 × no wave64, 3 × per-lane form refused (V_CVT_F16_F32, V_PK_MUL_F16, V_MUL_F16: "its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's"), 1 × no heap windows, 1 × cannot disable the driver cache (Windows Developer Mode required).

Regression run (scripts/smoke.ps1 -Game <folder> -Seconds 60, the same title, back to back, menus, no input; unedited). main aaa0936:

xcl-smoke v1
commit: aaa093657bd96a146c05c0c1a9b61149fe761453
gpu: NVIDIA GeForce RTX 3070
title: 3d7db37d
seconds: 60
exit: 0x0
frames shown: 1410 (PresentX 1410)
presents per 2 s (last 3): 59 61 60
device removals: 0
crashes: 0
peak commit: 15274 MB

PR head 7e2c923:

xcl-smoke v1
commit: 7e2c9235dfc6ab91dee9f85eaca03d50174506b6
gpu: NVIDIA GeForce RTX 3070
title: 3d7db37d
seconds: 60
exit: 0x0
frames shown: 1560 (PresentX 1560)
presents per 2 s (last 3): 61 60 51
device removals: 0
crashes: 0
peak commit: 15097 MB

That is 111 % of main's frames and 99 % of its peak commit.

Not tested

  • AMD, native wave64 (the 20 no wave64 skips above), a world run (the smoke stays in the menus, so it does not show whether the title reaches an s_buffer_load that wraps), the tests on game data (XCL_SAMPLE_* not set).

AI use

  • Claude Code (Claude Sonnet 5.5) ran the tests and wrote this report. The account owner has not reviewed it.

@LucasHoepfner
LucasHoepfner marked this pull request as ready for review November 25, 2026 03:33
@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants