Skip to content

Recompiler: the buffer range check ignores OOB_SELECT, so a store past the stride is performed where the console drops it #2954

Backlog

Description

@tiagonleal

The range check the recompiler emits for buffer accesses does not follow the descriptor's OOB_SELECT mode. For a descriptor with a stride it only tests index < num_records, so a store whose byte offset is at or past the stride is performed on the PC where the console drops it. Since a memory window is one UAV here, such a store lands on whatever title data follows the element.

Found by reading the code against the public GFX10 rule. I have not seen a title do this: I looked for it in one retail title's shaders and found no store that depends on it (details at the end). I am reporting it because the check is weaker than the hardware's in the direction that writes memory.

The hardware rule

Mesa documents it in src/amd/common/ac_descriptors.c, in ac_set_buf_desc_word3, for GFX10 (the generation of the console's GPU). Paraphrased:

OOB_SELECT out of range when
0 index >= NUM_RECORDS or offset >= STRIDE
1 index >= NUM_RECORDS
2 NUM_RECORDS == 0
3 offset >= NUM_RECORDS (or the swizzled address, with swizzle on)

GFX11 adds the access size to modes 0 and 3; the GFX10 text has no size term.

What XCL does (main 8b957bec)

  • gpu/desc.rs:700, buffer_words: the descriptors XCL builds itself carry mode 3 for raw buffers (stride 0) and mode 0 for everything else.
  • gpu/recomp/emit.rs:2148, the in_range closure in mubuf: stride == 0 ? off + bytes <= num_records : index < num_records. The same rule is used for byte and short forms, format stores and the atomics (buffer_atomic), and in the direct DXIL backend (gpu/dxil/lower_mem.rs:1263).
  • No shader path reads bits 29:28 of word 3.
  • SOFFSET is added to the address and is not part of the check.

Where the two differ

case console XCL
mode 0, index in range, offset >= stride dropped stored, in the next element or past the end for the last one
title-written descriptor, mode 3 with a stride checked by byte offset checked by index, so up to (stride - 1) * num_records bytes too far
title-written descriptor, mode 2 only num_records == 0 fails checked by index or offset, so valid accesses can be dropped
title-written descriptor, mode 1 with stride 0 checked by index checked by offset
raw access where SOFFSET pushes the address past num_records not settled (see below) stored

The first row is the one that XCL can hit with its own descriptors: it writes "mode 0" into word 3 and then does not apply the offset half of mode 0.

Not settled

  • Whether SOFFSET counts toward offset on GFX10. The Mesa comment does not say.
  • Whether a multi-dword store that starts below the stride and ends past it is split or dropped as a whole on GFX10.
  • What offset means in mode 3 when the descriptor has a stride and no swizzle.

A possible fix

Read (word3 >> 28) & 3 in the emitted check and apply the table above, in one helper shared by both backends, leaving SOFFSET as it is until the hardware behaviour is known. I have not written it: constant-buffer loads by byte offset go through stride-16 descriptors (cbv_words) and would be dropped under a strict mode 0, so the descriptors XCL builds may need mode 1 where the title addresses by byte offset. That needs someone who knows which modes the console's own views use.

What I checked in a title

In the retail title of #505 I decoded all 26,503 shader records of the pack and looked for stores at 12-byte spacing inside a 0x40-byte element, for an unrelated memory-corruption hunt. None of the title's shaders, in any stage, has that shape, so this report is not the explanation of that corruption. I did not check every store of the title against the offset-versus-stride rule.

Related: #1893 (wraparound in the raw-buffer check), #1241, #1737, #2325.

AI use: Claude Code with Claude Fable 5.2 and Anthropic subagents (Claude Opus 5.5, Claude Sonnet 5.5) helped developing with the supervision of @tiagonleal.

Activity

  1. ending3729 commented on Nov 27, 2026

    @ending3729

    Note: This fix, GPU regression test, and summary were prepared with Google Antigravity (Neon (extra high) orchestrator + Hydrogen (extra high) executor) and verified locally on an AMD Radeon RX 6600 XT; human reviewed the plan, test output, and diff.

    I have a minimal fix + GPU regression test for #2954 ready on a clean branch based on origin/main (f9a0cb80f9decb41d6f6315f6cf4e06270ba2bda):

    • Commit: ending3729@b690915 (5 files changed, 309 insertions(+), 50 deletions(-))
    • Branch: https://github.com/ending3729/xcl.git (recompiler-oob-select)

    What changed

    • HLSL emitter (crates/xcl/src/gpu/recomp/emit.rs): Added shared OOB_SELECT (SRSRC word3[29:28]) range checks (emit_buffer_oob / buffer_in_range) across mubuf, buffer_atomic, and mubuf_d16, honoring all four GFX10/RDNA2 modes:
      • Mode 0: index < num_records && off + bytes <= stride (per-dword for multi-dword ops, wrap-safe)
      • Mode 1: index < num_records
      • Mode 2: num_records != 0
      • Mode 3 (unswizzled): off + soffset + bytes <= num_records (wrap-safe; index * stride shifts EA only)
    • Direct DXIL lowering (crates/xcl/src/gpu/dxil/lower_mem.rs): Implemented the matching wrap-safe 32-bit OOB_SELECT helpers (buffer_oob / buffer_in_range) in mubuf (including D16, small, and format ops) and buffer_atomic.
    • CBV descriptors (crates/xcl/src/gpu/desc.rs): Switched cbv_words from OOB_SELECT = 0 to OOB_SELECT = 1 (1 << 28) so byte-offset CBV loads past 16 bytes remain valid while row-indexed loads stay bounded by num_records.
    • Tests (crates/xcl/src/gpu/recomp/tests.rs, crates/xcl/src/gpu/dxil/core_tests.rs, crates/xcl/src/gpu/desc.rs): Added gpu_mubuf_oob_select_modes covering modes 0..=3, DWORD/DWORDX4, atomics, BYTE/SHORT_D16_HI, MUBUF/MTBUF format stores, cbv_words, Mode 3 SOFFSET, and 32-bit offset wraparound across both HLSL and Direct DXIL with 1 and 2 memory windows; updated legacy raw-buffer (stride = 0) test descriptors from word3[29:28] = 0 to 3 << 28.
    • Left out of scope: s_buffer_load_* (SMEM), ld_raw address clamping (#1241), and swizzled V#s (#2325).

    Local verification

    • Hardware / toolchain: Windows 11 Build 26100, Ryzen 5 7500F, AMD Radeon RX 6600 XT (8 GB, RDNA2, driver 32.0.21045.29003, native wave64 + mesh shaders), rustc 1.100.0, DXC 1.9.2602.17.
    • Red -> Green: cbv_is_float4_rows and gpu_mubuf_oob_select_modes both failed before the fix and pass after.
    • cargo test --workspace --no-fail-fast -- --test-threads=4 (38 targets):
      • With XCL_REQUIRE_GPU=wave64,mesh: 1462 passed; 3 failed; 47 ignored (6 #1426 skips; 0 wave64/mesh skips; xcl --lib = 1334 passed; 2 failed; 27 ignored, exact +1 over f9a0cb80).
      • Default (XCL_REQUIRE_GPU unset): 1464 passed; 1 failed; 47 ignored (8 skips; xcl --lib = 1335 passed; 1 failed; 27 ignored).
      • Pre-existing baseline failures identical to unmodified origin/main f9a0cb80: gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, plus (under XCL_REQUIRE_GPU only) shaders::tests::pso_measurement_compiles_an_exact_synthetic_record (Windows Developer Mode disabled, 0x887A002D) and heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
    • Release build & Clippy: cargo build --release --workspace passes; 0 new Clippy warnings in touched lines.

    Request for paired retail scripts/smoke.ps1 run

    I do not have a retail Xbox Series title unpacked locally to produce the paired xcl-smoke v1 blocks required by scripts/pr_check.py. If an independent runner with a retail title can run scripts/smoke.ps1 on clean base f9a0cb80f9decb41d6f6315f6cf4e06270ba2bda and clean head b6909154e5682254d16209bdb3279a1e8b875ba1 and post the two raw xcl-smoke v1 blocks here, I will open the PR immediately (crediting the runner under Tested / Regression run).

    To make testing easy without modifying your local branches (from an xcl checkout with a clean working tree):

    $Game = 'D:\Games\YourTitle'   # replace with your unpacked title folder
    $Seconds = 60                  # add -Xcl <path> below if you override CARGO_TARGET_DIR
    
    git fetch https://github.com/ending3729/xcl.git recompiler-oob-select
    $orig = (git symbolic-ref --short -q HEAD)
    if (-not $orig) { $orig = (git rev-parse HEAD).Trim() }
    try {
        git checkout --detach f9a0cb80f9decb41d6f6315f6cf4e06270ba2bda
        if ($LASTEXITCODE -ne 0) { throw "checkout base failed" }
        cargo build --release -p xcl
        if ($LASTEXITCODE -ne 0) { throw "build base failed" }
        .\scripts\smoke.ps1 -Game $Game -Seconds $Seconds
    
        git checkout --detach b6909154e5682254d16209bdb3279a1e8b875ba1
        if ($LASTEXITCODE -ne 0) { throw "checkout fix failed" }
        cargo build --release -p xcl
        if ($LASTEXITCODE -ne 0) { throw "build fix failed" }
        .\scripts\smoke.ps1 -Game $Game -Seconds $Seconds
    } finally {
        git checkout $orig
    }

    AI use

    • Google Antigravity (Neon (extra high) orchestrator + Hydrogen (extra high) executor) implemented the fix, wrote gpu_mubuf_oob_select_modes, ran the local test suite on RX 6600 XT, and drafted this comment; human reviewed the plan, test results, and diff.
  2. thehollowedone commented on Nov 28, 2026

    @thehollowedone
    Contributor

    I checked the candidate commit against AMD's RDNA2 ISA, Table 35 and note 1. One formatted-load case needs a correction before the paired smoke run.

    For a valid 32_FLOAT buffer descriptor with OOB_SELECT=0, STRIDE=16, NUM_RECORDS=1, index=0, offset=16, and DST_SEL_X=SEL_1, BUFFER_LOAD_FORMAT_X is out of range, but its selected X result is 1.0f (0x3f800000). The RDNA2 guide explicitly exempts SEL_1 components from the usual zero result for an out-of-range read. On this commit, the new predicate is false and both HLSL emission and Direct DXIL lowering select a final zero after applying DST_SEL. The previous index-only check happened to retain 1.0f for this mode-0 case because it missed the offset bound. The new test uses ordinary component selectors, so it does not distinguish this behavior.

    The range failure should zero the fetched/decoded components before DST_SEL; SEL_1 must still select its constant. Keep format validity separate, and apply the same ordering to the D16 format-load paths before packing. A focused regression with the descriptor above should expect 0x3f800000 in both translated backends; pair it with DST_SEL_X=SEL_0 expecting zero. A native RDNA2 comparison would also check the guide against hardware.

    This is a source and specification check. I have not run the candidate or a GPU test. AI use: Codex (GPT-6.2 Sol) checked the candidate and drafted this finding; Codex (GPT-6.2 Astra) independently traced the selector paths.

  3. ending3729 commented on Nov 28, 2026

    @ending3729

    Note: This update, regression test, and summary were prepared with Google Antigravity (Neon (extra high) orchestrator + Hydrogen (extra high) executor) and verified locally on an AMD Radeon RX 6600 XT; human reviewed the test output and diff.

    @thehollowedone confirmed your RDNA2 ISA Table 35 Note 1 finding against both FormatLoad translators and updated the candidate branch rebased onto main (e429936c10a5b8aa09470ff99dfc8c8d3d8c56fd):

    • Updated commit: ending3729@aae2672 (recompiler-oob-select, 5 files changed, 387 insertions(+), 62 deletions(-))

    Fix in FormatLoad

    • HLSL emitter (crates/xcl/src/gpu/recomp/emit.rs): Separated format validity (bool {t}_ok = ({t}_info & 7u) != 0u;) from the OOB_SELECT range check (bool {t}_in = ...), zeroing the decoded component vector {t}_c when !{t}_in before dst_sel (and before D16 conversion/packing).
    • Direct DXIL lowering (crates/xcl/src/gpu/dxil/lower_mem.rs): Applied the same ordering across all three BufKind::FormatLoad paths (single_comp, num_comp < 4, num_comp == 4, including D16 and _HI_X low-half preservation) by zeroing the decoded component value(s) with rng prior to DST_SEL while keeping desc.has on the outside so BUF_FMT_INVALID (fmt = 0) still yields 0. Zeroing after component decode (rather than raw bytes) also prevents SEL_W on a 1-component format such as 32_FLOAT from leaking 1.0f when out of range.

    Verification (RX 6600 XT — translated HLSL & Direct DXIL)

    (Note: local GPU tests validate XCL's translated HLSL and Direct DXIL execution on RX 6600 XT, not raw native RDNA2 ISA execution.)

    • Red -> Green (gpu_mubuf_oob_format_dst_sel):
      • Before fix: failed on hlsl: x sel1 (v10) (left: 0, right: 1065353216 / 0x3F800000) with OOB_SELECT=0, STRIDE=16, NUM_RECORDS=1, index=0, OFFSET=16, DST_SEL_X=SEL_1.
      • After fix (clean commit aae26728): cbv_is_float4_rows, gpu_mubuf_oob_select_modes, gpu_mubuf_oob_format_dst_sel (covering X/XY/XYZW, D16_X/D16_HI_X/D16_XY/D16_XYZW, TBUFFER_LOAD_FORMAT_X, 32_UINT SEL_1 -> 1, SEL_0 -> 0, SEL_W on 32_FLOAT OOB -> 0, and BUF_FMT_INVALID -> 0 on both HLSL and Direct DXIL), gpu_typed_buffer_loads_and_stores, buffer_format_d16_packs_and_unpacks_halves, and submit_marking_calls_out_unlocked_and_revalidates_the_queue_marker all pass (6 passed; 0 failed).
    • cargo test --workspace --no-fail-fast -- --test-threads=4 (40 targets, Windows 11 Build 26100, Ryzen 5 7500F, RX 6600 XT driver 32.0.21045.29003, rustc 1.100.0, DXC 1.9.2602.17):
      • Default (XCL_REQUIRE_GPU unset): 2129 passed; 9 failed; 48 ignored (8 SKIPPED lines: 6 #1426 f16/f32 skips + pso_measurement_compiles_an_exact_synthetic_record [Developer Mode off] + heap_window_out_of_memory_falls_back_to_the_switch_form [no heap windows]). Every one of those failures reproduces on unmodified origin/main e429936c (fuzz_validate_and_gpu_1, dispatch_chain_wave32_live_loops, dispatch_chain_oversized_loop_matches_whole, dispatch_chain_wave64_live_loops_and_exchange, gpu_heap_flat_reads_match_guarded_and_root_output, gpu_compute_mode_dispatch_abi, test_title_runs_and_game_folder_is_untouched, two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs).
      • XCL_REQUIRE_GPU=wave64,mesh: 2125 passed; 13 failed; 48 ignored (6 #1426 skips; 0 wave64/mesh skips; adds the 2 non-wave/mesh capability skips above plus 2 parallel alloc_pool tests that both pass when run in isolation and in the default run above).
    • Build & Clippy: cargo build --workspace and cargo build --release --workspace both exit 0; cargo clippy -p xcl --all-targets --locked --no-deps shows 0 new warnings in any added or modified lines.

    Updated paired scripts/smoke.ps1 snippet (main e429936c -> fix aae26728)

    $Game = 'D:\Games\YourTitle'   # replace with your unpacked title folder
    $Seconds = 60                  # add -Xcl <path> below if you override CARGO_TARGET_DIR
    
    git fetch https://github.com/ending3729/xcl.git recompiler-oob-select
    $orig = (git symbolic-ref --short -q HEAD)
    if (-not $orig) { $orig = (git rev-parse HEAD).Trim() }
    try {
        git checkout --detach e429936c10a5b8aa09470ff99dfc8c8d3d8c56fd
        if ($LASTEXITCODE -ne 0) { throw "checkout base failed" }
        cargo build --release -p xcl
        if ($LASTEXITCODE -ne 0) { throw "build base failed" }
        .\scripts\smoke.ps1 -Game $Game -Seconds $Seconds
    
        git checkout --detach aae26728504cd3dbbc5cc302611d99e200ba4dee
        if ($LASTEXITCODE -ne 0) { throw "checkout fix failed" }
        cargo build --release -p xcl
        if ($LASTEXITCODE -ne 0) { throw "build fix failed" }
        .\scripts\smoke.ps1 -Game $Game -Seconds $Seconds
    } finally {
        git checkout $orig
    }

    AI use

    • Google Antigravity (Neon (extra high) orchestrator + Hydrogen (extra high) executor) implemented the FormatLoad fix, added gpu_mubuf_oob_format_dst_sel, rebased onto e429936c, ran the local RX 6600 XT test suite and Clippy, and drafted this reply; human reviewed the test output and diff.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions