Recompiler: the buffer range check ignores OOB_SELECT, so a store past the stride is performed where the console drops it #2954
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl#2954
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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_SELECTmode. For a descriptor with a stride it only testsindex < 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, inac_set_buf_desc_word3, for GFX10 (the generation of the console's GPU). Paraphrased:OOB_SELECTindex >= NUM_RECORDSoroffset >= STRIDEindex >= NUM_RECORDSNUM_RECORDS == 0offset >= 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 (
main8b957bec)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, thein_rangeclosure inmubuf: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).SOFFSETis added to the address and is not part of the check.Where the two differ
indexin range,offset >= stride(stride - 1) * num_recordsbytes too farnum_records == 0failsSOFFSETpushes the address pastnum_recordsThe 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
SOFFSETcounts towardoffseton GFX10. The Mesa comment does not say.offsetmeans in mode 3 when the descriptor has a stride and no swizzle.A possible fix
Read
(word3 >> 28) & 3in the emitted check and apply the table above, in one helper shared by both backends, leavingSOFFSETas 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.