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

Closed
github-bot wants to merge 1 commit from gh-pr/251/head into gh-pr/251/base
Owner

@⁠azerioxfr on GitHub · 2026-11-23 07:53 UTC · original
azerioxfr:xshader-mubuf-atomic-x2 → main · +194 −30 · 4 files · 1 commits · closed without merging

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
**@⁠azerioxfr** on GitHub · 2026-11-23 07:53 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/251) `azerioxfr:xshader-mubuf-atomic-x2` → `main` · +194 −30 · 4 files · 1 commits · closed without merging **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
Decode buffer_atomic_*_x2 (MUBUF 0x50-0x5d) and lower them to SM 6.6 64-bit Interlocked* on RWBuffer<uint64_t> / RWStructuredBuffer<uint64_t>, mirroring the 64-bit image atomics (b17ef2c). GLC returns the old value into the vdata pair.

The 13 64-bit forms previously decoded as Mubuf<0x50..0x5d> and failed translation. They share the 32-bit semantics (0x30-0x3d) offset by 0x20: swap, cmpswap, add, sub, smin, umin, smax, umax, and, or, xor, inc, dec. Opcode values follow LLVM gfx10_asm_mubuf.s. smin/smax use a sign-bit-flipped compare-exchange loop; inc/dec use a compare-exchange loop for the wrap semantics.

A buffer slot is declared uint64_t when used with x2 atomics and refused when mixed with 32-bit atomics on the same slot.

Tests: exec.rs mubuf_atomic_x2 runs all 13 ops on typed and raw buffers with carries, sign bits, inc/dec wrap, cmpswap hit/miss and GLC 0/1. Mutation: forcing add_x2 to add a constant fails 28 cases; restored.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:15:53 +00:00
github-bot closed this pull request 2026-11-26 06:15:53 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-23 13:31 UTC · original

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.

**@⁠omonkeyz** on GitHub · 2026-11-23 13:31 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/251#issuecomment-7102653979) 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.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-25 13:48 UTC · original

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

**@⁠omonkeyz** on GitHub · 2026-11-25 13:48 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/251#issuecomment-7164323028) Applied on main in e086d23 (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.
Author
Owner

@⁠SchmashinPrunes on GitHub · 2026-11-24 14:34 UTC · original · approved these changes

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.)

**@⁠SchmashinPrunes** on GitHub · 2026-11-24 14:34 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/251#pullrequestreview-6041180090) · **approved these changes** **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.)

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.