tombox-xshader: decode and translate the MUBUF 64-bit integer buffer … #251

Closed
azerioxfr wants to merge 1 commit from upstream-pr/251 into main
azerioxfr commented 2026-11-23 07:53:21 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by azerioxfr on 2026-11-23T07:53:21Z.


Library / area: tombox-xshader, MUBUF atomics (hlsl.rs emit_mubuf / buffer resolution, new hlsl/atomic.rs helper)

Exports changed (exports.txt rows): none

Source of the behaviour: opcodes from tests/isa_table/gfx1013.txt (MUBUF 0x50..0x5d). Semantics from the RDNA2 ISA (64-bit value at the 8-byte address; the vdata pair is the operand; GLC=1 returns the old value), on the SM 6.6 64-bit atomic support already used for image atomics (b17ef2c, OPTIONS9 gate).

One topic, +194 / -30: 5 lines in rdna2/mnem.rs, hlsl.rs +76 / -30, hlsl/atomic.rs +43, tests +56.

What was missing

buffer_atomic_{swap,cmpswap,add,sub,smin,umin,smax,umax,and,or,xor,inc,dec}_x2 were not decoded ("mubuf: gfx1013 opcodes not named by the decoder").

The change

part change
decoder names MUBUF 0x50..0x5d
buffer declaration a slot used by _x2 atomics is declared RWBuffer<uint64_t> / RWStructuredBuffer<uint64_t>, gated through uses_typed_atomic64 like the 64-bit image atomics. A slot that mixes 32-bit and 64-bit atomics is refused with an explicit error.
addressing 8-byte elements ((offset) >> 3). Unaligned constant offsets fall through to the existing "unresolved atomic target" refusal. Like the 32-bit path, this assumes the declared element matches the view's stride.
ops 64-bit Interlocked*. smin/smax, inc/dec and cmpswap are lowered in atomic_rmw64. GLC=1 writes the old value to vdata / vdata+1.
32-bit atomics unchanged (the same match, moved into the non-_x2 branch)

Tests

New mubuf_atomic_x2 (typed and raw groups): all 13 ops with carries across the halves, the sign bit in the high dword for smin/smax, inc/dec wrap, cmpswap hit and miss, and GLC 0 and 1.

run (WARP, --release, DXC 1.9.2609) result
mubuf_atomic_x2_typed / _raw 13 mnemonics verified, 0 failing, 208 cases each
mutation: add_x2 adds a constant 12 verified, 1 failing
regressions: mubuf_atomic_soffset_typed / _raw, buffer_mubuf, image_mimg_atomics_64bit 3 / 3 / 18 / 9 verified, 0 failing
--test isa_table / opcodes / synthetic 3 / 26 / 24 passed

Run on x86_64-pc-windows-gnu (no MSVC linker here). Hosts without 64-bit typed/raw UAV atomic support go through the existing OPTIONS9 gate.

  • cargo test -p tombox-xshader --test exec -- mubuf_atomic passes
  • No game or console files and no binaries included
  • No fake success; anything not possible is left missing with a note
<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6554808521 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/251). Originally posted by [azerioxfr](https://github.com/azerioxfr) on 2026-11-23T07:53:21Z. --- **Library / area:** tombox-xshader, MUBUF atomics (`hlsl.rs` `emit_mubuf` / buffer resolution, new `hlsl/atomic.rs` helper) **Exports changed (exports.txt rows):** none **Source of the behaviour:** opcodes from `tests/isa_table/gfx1013.txt` (MUBUF 0x50..0x5d). Semantics from the RDNA2 ISA (64-bit value at the 8-byte address; the vdata pair is the operand; GLC=1 returns the old value), on the SM 6.6 64-bit atomic support already used for image atomics (b17ef2c, OPTIONS9 gate). One topic, +194 / -30: 5 lines in `rdna2/mnem.rs`, `hlsl.rs` +76 / -30, `hlsl/atomic.rs` +43, tests +56. ### What was missing `buffer_atomic_{swap,cmpswap,add,sub,smin,umin,smax,umax,and,or,xor,inc,dec}_x2` were not decoded ("mubuf: gfx1013 opcodes not named by the decoder"). ### The change | part | change | |---|---| | decoder | names MUBUF 0x50..0x5d | | buffer declaration | a slot used by `_x2` atomics is declared `RWBuffer<uint64_t>` / `RWStructuredBuffer<uint64_t>`, gated through `uses_typed_atomic64` like the 64-bit image atomics. A slot that mixes 32-bit and 64-bit atomics is refused with an explicit error. | | addressing | 8-byte elements (`(offset) >> 3`). Unaligned constant offsets fall through to the existing "unresolved atomic target" refusal. Like the 32-bit path, this assumes the declared element matches the view's stride. | | ops | 64-bit `Interlocked*`. smin/smax, inc/dec and cmpswap are lowered in `atomic_rmw64`. GLC=1 writes the old value to vdata / vdata+1. | | 32-bit atomics | unchanged (the same match, moved into the non-`_x2` branch) | ### Tests New `mubuf_atomic_x2` (typed and raw groups): all 13 ops with carries across the halves, the sign bit in the high dword for smin/smax, inc/dec wrap, cmpswap hit and miss, and GLC 0 and 1. | run (WARP, `--release`, DXC 1.9.2609) | result | |---|---| | `mubuf_atomic_x2_typed` / `_raw` | **13 mnemonics verified, 0 failing, 208 cases** each | | mutation: `add_x2` adds a constant | 12 verified, 1 failing | | regressions: `mubuf_atomic_soffset_typed` / `_raw`, `buffer_mubuf`, `image_mimg_atomics_64bit` | 3 / 3 / 18 / 9 verified, 0 failing | | `--test isa_table` / `opcodes` / `synthetic` | 3 / 26 / 24 passed | Run on `x86_64-pc-windows-gnu` (no MSVC linker here). Hosts without 64-bit typed/raw UAV atomic support go through the existing OPTIONS9 gate. - [x] `cargo test -p tombox-xshader --test exec -- mubuf_atomic` passes - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note
omonkeyz commented 2026-11-23 13:31:17 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-23T13:31:17Z.


Review, changes needed: (1) on structured slots the constant offset is used as imm/8 with no %8 check, so an unaligned offset hits the wrong address; (2) indexed access assumes an 8-byte stride, not the guest stride; (3) a slot that also has plain loads or stores is declared uint64_t and then fails in DXC; (4) only the test harness knows the RWBuffer<uint64_t> view (R32G32_UINT, stride 8), d3d12_xs has no equivalent; (5) uses_typed_atomic64 is set for structured buffers, which don't need typed 64-bit atomics. Please rebase on #199 when you update.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7102653979 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/251#issuecomment-7102653979). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-23T13:31:17Z. --- Review, changes needed: (1) on structured slots the constant offset is used as imm/8 with no %8 check, so an unaligned offset hits the wrong address; (2) indexed access assumes an 8-byte stride, not the guest stride; (3) a slot that also has plain loads or stores is declared uint64_t and then fails in DXC; (4) only the test harness knows the RWBuffer<uint64_t> view (R32G32_UINT, stride 8), d3d12_xs has no equivalent; (5) uses_typed_atomic64 is set for structured buffers, which don't need typed 64-bit atomics. Please rebase on #199 when you update.
SchmashinPrunes commented 2026-11-24 14:34:49 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by SchmashinPrunes on 2026-11-24T14:34:49Z.

Review: APPROVED


Scope: silicon semantics only. This is not a merge recommendation. The integration issues in omonkeyz's review still need the changes requested there: offset alignment, guest stride, mixed plain/atomic slots, the d3d12_xs view and uses_typed_atomic64. GitHub doesn't let a reviewer without write access withdraw an approval, so please read this one as a comment.

I checked the op semantics on RDNA2 silicon: a gfx1036 iGPU (Ryzen 5 9600X), ROCm/HIP 5.7.1, raw wave32 kernels, so RDNA2, not gfx1013. Each kernel ran twice with identical results, and I compared against the semantics this PR implements (my own port; I didn't run the PR's code).

All 13 buffer_atomic_*_x2 ops match on 2,048 cases each, with GLC 1, raw offen addressing and random 64-bit memory, data and compare values:

  • the returned value is the old 64-bit word;
  • the memory after the op is swap, cmpswap (data in vdata[0:1], compare in vdata[2:3]), add, sub, smin, umin, smax, umax, and, or or xor;
  • inc gives (m >= d ? 0 : m + 1), and dec gives (m == 0 || m > d ? d : m - 1).

That's the same as your model, including the carries across the halves and the signed compares on the high dword.

(Measured with an AI assistant, Claude.)

<!-- greyfinch-sync:omonkeyz/xbox-emulator:review:6041180090 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/251#pullrequestreview-6041180090). Originally posted by [SchmashinPrunes](https://github.com/SchmashinPrunes) on 2026-11-24T14:34:49Z. **Review:** APPROVED --- **Scope: silicon semantics only. This is not a merge recommendation.** The integration issues in omonkeyz's review still need the changes requested there: offset alignment, guest stride, mixed plain/atomic slots, the d3d12_xs view and `uses_typed_atomic64`. GitHub doesn't let a reviewer without write access withdraw an approval, so please read this one as a comment. I checked the op semantics on RDNA2 silicon: a gfx1036 iGPU (Ryzen 5 9600X), ROCm/HIP 5.7.1, raw wave32 kernels, so RDNA2, not gfx1013. Each kernel ran twice with identical results, and I compared against the semantics this PR implements (my own port; I didn't run the PR's code). All 13 `buffer_atomic_*_x2` ops match on 2,048 cases each, with GLC 1, raw offen addressing and random 64-bit memory, data and compare values: - the returned value is the old 64-bit word; - the memory after the op is `swap`, `cmpswap` (data in vdata[0:1], compare in vdata[2:3]), `add`, `sub`, `smin`, `umin`, `smax`, `umax`, `and`, `or` or `xor`; - `inc` gives (m >= d ? 0 : m + 1), and `dec` gives (m == 0 || m > d ? d : m - 1). That's the same as your model, including the carries across the halves and the signed compares on the high dword. (Measured with an AI assistant, Claude.)
omonkeyz commented 2026-11-25 13:48:39 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-25T13:48:39Z.


Applied on main in e086d23 (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7164323028 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/251#issuecomment-7164323028). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-25T13:48:39Z. --- Applied on main in e086d23 (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

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!251
No description provided.