xshader: the SMEM immediate is signed, with RX 6800 vectors #206

Closed
QuentinDanblon wants to merge 1 commit from upstream-pr/206 into main
QuentinDanblon commented 2026-11-23 01:16:31 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-23T01:16:31Z.


Library / area: tombox-xshader (SMEM decode, s_buffer_load)

Exports changed (exports.txt rows): none

Source of the behaviour: LLVM AMDGPU (isInt<21> SMEM offset on GFX9+), and results an AMD Radeon RX 6800 (gfx1030) returned, published in the comments of the Leonida project's GPU test programs (GPL-3.0). Facts only, no code copied; encodings from llvm-mc -mcpu=gfx1013. The first Leonida line of THIRD_PARTY/CREDITS is extended to these cases in this PR.

Part of the split of #152: third group of translator fixes. Based on 2eda8b0, on top of your SMEM bounds work (smem_bounds.rs), 4 files, +24 / -4.

The version in #152 also truncated soffset and the immediate to a multiple of 4. Main does that now, so this PR keeps only what is still missing: the 21-bit SMEM immediate is signed. It was decoded unsigned, so s_buffer_load with a negative immediate and a SOFFSET register (soffset 0x10, imm -8) computed 0x10 + 0x1ffff8, was out of bounds and returned 0. The RX 6800 reads byte 8.

  • rdna2.rs: the immediate is sign extended.
  • hlsl.rs, both dynamic paths (structured buffer and cbuffer): the truncated immediate is added to the truncated soffset as before. For a negative immediate the carry test is inverted, so a sum below the start of the buffer sets the same t..c flag as a sum past 4 GiB and takes your out-of-bounds path. Nothing else in smem_bounds.rs changes.
  • A negative immediate without SOFFSET is refused at translation.

Not measured, so said plainly: what the hardware returns when soffset plus a negative immediate lands below the start of the buffer. This PR returns 0 for every dword of such a load, like any other out-of-bounds dword. The Leonida vectors only cover sums that stay inside the buffer.

Tests: 7 cases added to scalar_smem_loads (tests/exec.rs). On 2eda8b0 without the fix, the three cases with a negative immediate fail (soffset 8, imm -4; soffset 0xb, imm -1; soffset 0x10, imm -8 with dwordx2); the four alignment cases already pass and are kept as regression vectors.

Results

WARP, --release, this branch on 2eda8b0:

  • cargo test -p tombox-xshader, all targets: 0 failed. exec 113 passed (2 ignored), lib 97 (your six smem_bounds tests included), mesh 24, opcodes 24, synthetic 24, linkage 3, mixed_table 3, gcn_dims 3, isa_sweep 2.
  • exec_mem::smem_nr::smem_bounds_emission and smem_bounds_follow_num_records_on_warp pass unchanged.

Hardware: not run, the GPU of my machine is busy for now. The #152 version of this change passed on an RTX 5090, but that was before smem_bounds.rs, so it does not count for this code. I will post a hardware run of this branch when the card is free.

No comment lines added (PR gate: 4 files checked, 0 problems). Not run against a title.

  • cargo test -p tombox-xshader passes on WARP
  • No game or console files and no binaries included
  • No fake success; anything not possible is left missing with a note

🤖 Generated with Claude Code

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6550283199 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/206). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-23T01:16:31Z. --- **Library / area:** tombox-xshader (SMEM decode, `s_buffer_load`) **Exports changed (exports.txt rows):** none **Source of the behaviour:** LLVM AMDGPU (`isInt<21>` SMEM offset on GFX9+), and results an AMD Radeon RX 6800 (gfx1030) returned, published in the comments of the Leonida project's GPU test programs (GPL-3.0). Facts only, no code copied; encodings from `llvm-mc -mcpu=gfx1013`. The first Leonida line of `THIRD_PARTY/CREDITS` is extended to these cases in this PR. Part of the split of #152: third group of translator fixes. Based on `2eda8b0`, on top of your SMEM bounds work (`smem_bounds.rs`), 4 files, +24 / -4. The version in #152 also truncated soffset and the immediate to a multiple of 4. Main does that now, so this PR keeps only what is still missing: **the 21-bit SMEM immediate is signed**. It was decoded unsigned, so `s_buffer_load` with a negative immediate and a SOFFSET register (`soffset 0x10, imm -8`) computed `0x10 + 0x1ffff8`, was out of bounds and returned 0. The RX 6800 reads byte 8. - `rdna2.rs`: the immediate is sign extended. - `hlsl.rs`, both dynamic paths (structured buffer and cbuffer): the truncated immediate is added to the truncated soffset as before. For a negative immediate the carry test is inverted, so a sum below the start of the buffer sets the same `t..c` flag as a sum past 4 GiB and takes your out-of-bounds path. Nothing else in `smem_bounds.rs` changes. - A negative immediate without SOFFSET is refused at translation. Not measured, so said plainly: what the hardware returns when soffset plus a negative immediate lands below the start of the buffer. This PR returns 0 for every dword of such a load, like any other out-of-bounds dword. The Leonida vectors only cover sums that stay inside the buffer. Tests: 7 cases added to `scalar_smem_loads` (`tests/exec.rs`). On `2eda8b0` without the fix, the three cases with a negative immediate fail (`soffset 8, imm -4`; `soffset 0xb, imm -1`; `soffset 0x10, imm -8` with dwordx2); the four alignment cases already pass and are kept as regression vectors. ### Results WARP, `--release`, this branch on `2eda8b0`: - `cargo test -p tombox-xshader`, all targets: 0 failed. exec 113 passed (2 ignored), lib 97 (your six `smem_bounds` tests included), mesh 24, opcodes 24, synthetic 24, linkage 3, mixed_table 3, gcn_dims 3, isa_sweep 2. - `exec_mem::smem_nr::smem_bounds_emission` and `smem_bounds_follow_num_records_on_warp` pass unchanged. Hardware: not run, the GPU of my machine is busy for now. The #152 version of this change passed on an RTX 5090, but that was before `smem_bounds.rs`, so it does not count for this code. I will post a hardware run of this branch when the card is free. No comment lines added (PR gate: 4 files checked, 0 problems). Not run against a title. - [x] `cargo test -p tombox-xshader` passes on WARP - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note 🤖 Generated with [Claude Code](https://claude.com/claude-code)
omonkeyz commented 2026-11-23 01:57:37 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-23T01:57:37Z.


Applied in 3f728a6 (merged in ad24144) with your authorship kept, thanks. The trailing comment on the OFFSET decode line was dropped in f9c3ec5 (the project keeps code comment-free).

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7089548448 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/206#issuecomment-7089548448). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-23T01:57:37Z. --- Applied in 3f728a6 (merged in ad24144) with your authorship kept, thanks. The trailing comment on the OFFSET decode line was dropped in f9c3ec5 (the project keeps code comment-free).

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
omonkeyz/xbox-emulator!206
No description provided.