Skip to content

[upstream #1146] Recompiler: widen 1-window raw MUBUF bounds checks to 64-bit to prevent wrap - #16

Closed
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1146
Closed

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1146

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

In mubuf, buffer_atomic, and mubuf_d16, the single-window (mem_windows == 1) path computed t_off = voff + OFFSET and checked t_off + bytes <= d2 in 32-bit uint, unlike the multi-window path which already uses uint64_t. A large/negative voff (e.g. 0xFFFFFFFC with bytes = 4, or 0xFFFFFFF0 with OFFSET = 16) wrapped past 2^32 to 0 <= d2, reading or writing out of bounds instead of treating the access as out of bounds.

This hoists uint64_t t_off and uses the 64-bit raw bounds check in both single- and multi-window modes across mubuf, buffer_atomic, and mubuf_d16.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: compute t_off and raw STRIDE == 0 bounds comparisons in uint64_t for mubuf, buffer_atomic, and mubuf_d16 regardless of mem_windows.
  • crates/xcl/src/gpu/recomp/tests.rs: add GPU test gpu_mubuf_raw_bounds_do_not_wrap_32bit covering BUFFER_LOAD_DWORD, BUFFER_STORE_DWORD, BUFFER_ATOMIC_ADD, and BUFFER_LOAD_SHORT_D16 (verified failing before the fix); update the HLSL text check in atomic_fcmpswap_x2_is_a_bitwise_64_bit_cas for the widened comparison.

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 742 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 no wave64 — gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)
  • cargo test -p xcl --lib gpu_mubuf_raw_bounds_do_not_wrap_32bit: 1 passed, 0 failed (failed on the GPU before the fix, reading 0xDEAD_BEEF from base - 4)

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 5080
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1226 (PresentX 1226)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15341 MB

PR:

xcl-smoke v1
commit: 9e43be57c295938915ae2dd4e458e113d1d3e89c
gpu: NVIDIA GeForce RTX 5080
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1645 (PresentX 1645)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14452 MB

Not tested

  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Gemini 4 Neon: audited emit.rs, wrote the fix and GPU test, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.

Mirror of xcl-dev#1146 (auto-synced, do not edit).

…nt wrap

In mubuf, buffer_atomic, and mubuf_d16, the mem_windows == 1 path
computed t_off = voff + OFFSET and checked t_off + bytes <= d2 in
32-bit uint, unlike the multi-window path which already uses uint64_t.
A large/negative voff (e.g. 0xFFFFFFFC with bytes=4, or 0xFFFFFFF0 with
OFFSET=16) wrapped past 2^32 to 0 <= d2 and performed an out-of-bounds
load, store, or atomic instead of treating the access as out of bounds.

Compute t_off and the raw bounds comparison in uint64_t for both
single- and multi-window modes, with a GPU regression test covering
BUFFER_LOAD_DWORD, BUFFER_STORE_DWORD, BUFFER_ATOMIC_ADD, and
BUFFER_LOAD_SHORT_D16.

Assisted-by: OpenCode (Gemini 4 Neon)
@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#1146 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/1146 branch November 25, 2026 00:15
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.

2 participants