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

Open
opened 2026-11-27 04:36:28 +00:00 by github-bot · 0 comments
Owner

@⁠tiagonleal on GitHub · 2026-11-27 04:35 UTC · original

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. Claude Opus 5.5 read the XCL code and the Mesa source; a second pass re-read the Mesa comment; Claude Fable 5.2 wrote this. I checked it.

**@⁠tiagonleal** on GitHub · 2026-11-27 04:35 UTC · [original](https://github.com/xcl-dev/xcl/issues/2954) 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. Claude Opus 5.5 read the XCL code and the Mesa source; a second pass re-read the Mesa comment; Claude Fable 5.2 wrote this. I checked it.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 04:36:29 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.