Skip to content

Recompiler: treat raw buffer offsets that wrap past 2^32 as out of range - #1933

Open
PracticalStudios wants to merge 2 commits into
xcl-dev:mainfrom
PracticalStudios:dxil/raw-bounds-wrap
Open

PracticalStudios wants to merge 2 commits into
xcl-dev:mainfrom
PracticalStudios:dxil/raw-bounds-wrap

Conversation

@PracticalStudios

@PracticalStudios PracticalStudios commented Nov 24, 2026 •

Copy link
Copy Markdown

Direct-DXIL raw buffer loads, stores and atomics now treat an offset that wraps past 2^32 as out of range. Part of #1893 (the raw-buffer part; the s_buffer_load part is not changed).

Why: voff + OFFSET and off + bytes were added in 32 bits, so a wrapped sum passed the bounds check. On main, a buffer_load_dword at voff 0xFFFF_FFF0 + OFFSET 0x20 on a 0x100-byte buffer returned another dword of the buffer (4116) instead of 0.

What is in it

  • lower_mem.rs: mubuf's in_range and buffer_atomic also require the sums not to wrap.
  • Test gpu_direct_raw_buffer_offsets_that_wrap_are_out_of_range: wrapped loads read 0, a wrapped store and wrapped atomics (also with a non-zero OFFSET) are dropped; an in-range lane is the control.

Tested

  • RTX 3090 24 GB (driver 621.24), Ryzen 7 9800X3D, 62 GB RAM, Windows 11 26200, Rust 1.89.0, debug.
  • The new test fails on main (left: 4116, right: 0) and passes here; removing each of the two checks fails it.
  • cargo test --workspace --no-fail-fast -- --test-threads=2 on aa16bda: 1154 passed, 1 failed, 46 ignored. The failure (kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory) fails the same way on main (fixed by Tests: align XMemVirtualQuery buffers and verify CPU flags #650).

Regression run
.\scripts\smoke.ps1 -Game <retail title> -Seconds 60, no input, main (this PR's base) first, same machine:

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: NVIDIA GeForce RTX 3090
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1498 (PresentX 1498)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16250 MB
xcl-smoke v1
commit: aa16bdaf07f3bafbf0266fbacd8bac5aab831a80
gpu: NVIDIA GeForce RTX 3090
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1616 (PresentX 1616)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16641 MB

Not tested

AI use

  • Claude Code (Claude Opus 5.5, with Claude Sonnet subagents) wrote the fix, the test and this text. The test runs are real runs on the hardware above.

@upipibi

upipibi commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

The HLSL path has the same wrap in one of its two forms, from reading recomp/emit.rs on main (not run). In MUBUF's range check:

  • with several memory windows (mem_windows > 1), _off = (uint64_t)voff + OFFSET and _off + bytes <= num_records are 64-bit, so a wrapped sum stays out of range (fine);
  • with one window (around line 1717), uint _off = voff + OFFSET; and in_range = _off + bytes <= num_records are 32-bit. voff = 0xFFFF_FFF0 with OFFSET = 0x20 gives _off = 0x10, which passes on a 0x100-byte buffer, as on the direct path before this PR.

Measured (edited; this replaces my earlier "should"). I ran this PR's program through the HLSL path on main 20cf130 with one window (runner::run_code, XCL_DIRECT_DXIL unset), on an RTX 3070, driver 616.56:

  • lane 0 load at voff 0xFFFF_FFF0 + OFFSET 0x20: 0x1014 (4116), want 0;
  • lane 0 load at voff 0xFFFF_FFFC, no OFFSET: 0x100f, want 0. So _off + bytes wraps as well, not only voff + OFFSET;
  • the store at voff 0xFFFF_FFF0 + 0x20 wrote mem[0x50 / 4] (0xC0DE0000), which should be untouched.

Widening the one-window _off and the in_range sum to 64 bits, as the multi-window branch already does, would cover both.

AI-assisted (Claude Code).

@PracticalStudios

Copy link
Copy Markdown
Author

@upipibi thanks, confirmed: the same wrap shows on the HLSL path's one-window form here too. #1146 (b3IKK) already widens those mubuf / buffer_atomic / mubuf_d16 checks to 64 bits, so I've left that path to it and kept this PR to direct DXIL.

AI use: Claude Code (Claude Opus 5.5) wrote this reply.

@PracticalStudios
PracticalStudios marked this pull request as ready for review November 25, 2026 00:43
@futurepro62

futurepro62 commented Nov 25, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head bb5e0b7 (on its base 689f2db).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 966 passed, 0 failed, 43 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: gpu_direct_raw_buffer_offsets_that_wrap_are_out_of_range.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 975 passed, 0 failed, 45 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 7994cd1 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests and const_and_null_mask_operands_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@raylitebull

Copy link
Copy Markdown
Member

Diff audit passed (lower_mem.rs 32-bit wrap checks off >= voff and e >= off in mubuf and buffer_atomic, plus GPU test gpu_direct_raw_buffer_offsets_that_wrap_are_out_of_range), Build and test + PR description are green on bb5e0b7, and NVIDIA (RTX 3090, RTX 5070 Ti) verified it.

Remaining before merge: one independent AMD GPU pass on bb5e0b7.

@PracticalStudios

PracticalStudios commented Nov 25, 2026 •

Copy link
Copy Markdown
Author

Rebased onto main 8f5fca5 to resolve a conflict at the end of recomp/tests.rs (#1990's test landed in the same spot). The lower_mem.rs change and the test are unchanged, so the runs on bb5e0b7 above still apply; the regression blocks for the new head follow.

Rebased again onto cbc296a (same tests.rs end-of-file conflict): the test now sits next to the other raw-buffer bounds tests instead of at the end of the file, so later appends don't collide with it. Code and test unchanged; new head aa16bda, its blocks are in the description.

AI use: Claude Code (Claude Opus 5.5) wrote this note.

@raylitebull

Copy link
Copy Markdown
Member

Build and test (Windows, no GPU) just passed on 7946c96! Two small items remain before merge:

  1. Refresh the PR xcl-smoke v1 block in the PR description (commit: still points to bb5e0b7 instead of 7946c96, causing the PR description check to fail).
  2. One independent AMD GPU run confirming gpu_direct_raw_buffer_offsets_that_wrap_are_out_of_range on 7946c96.

@PracticalStudios

PracticalStudios commented Nov 25, 2026 •

Copy link
Copy Markdown
Author

@philip-roy-jones would you have a few minutes for this PR's remaining check, an AMD run? Your RX 580 (native 64-lane waves) would cover what the NVIDIA runs couldn't. On head 7946c96:

cargo test -p xcl --lib -- gpu_direct_raw_buffer_offsets_that_wrap_are_out_of_range --nocapture

(and the full cargo test --workspace if you have the time). No worries if not.
As additional verification (my own run, so not the independent one): on this machine's AMD Radeon iGPU (Ryzen 7 9800X3D, RDNA2, driver 32.0.21042.62, XCL_ADAPTER=radeon), head 7946c96: gpu_direct_raw_buffer_offsets_that_wrap_are_out_of_range 1 passed; gpu::dxil 108 passed, 1 failed — fuzz_validate_and_gpu_1 seed 540 (res[833] = 0x7, CPU 0x6), the AMD failure already seen on main.

AI use: Claude Code (Claude Opus 5.5) wrote this request.

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Re-checked 7946c96 on the RTX 3070 (driver 616.56): the new gpu_direct_raw_buffer_offsets_that_wrap_are_out_of_range passes with XCL_DIRECT_DXIL=0 and 1.

AI-assisted (Claude Code).

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

Direct DXIL's buffer bounds check added voff + OFFSET + bytes in 32 bits, so a wrapped
sum passed it (xcl-dev#1893); loads read memory, stores and atomics wrote it.
IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
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.

5 participants