tombox-xshader: decode and translate the FLAT/GLOBAL D16 sub-dword loads #249

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

@⁠azerioxfr on GitHub · 2026-11-23 07:22 UTC · original
azerioxfr:xshader-flat-global-d16-loads → main · +64 −4 · 3 files · 1 commits · closed without merging

Library / area: tombox-xshader, FLAT / GLOBAL sub-dword loads (hlsl/global.rs)

Exports changed (exports.txt rows): none

Source of the behaviour: opcodes from tests/isa_table/gfx1013.txt (FLAT / GLOBAL 0x20..0x25). Semantics from the RDNA2 ISA descriptions, lowered like the LDS D16 reads (28f54b2) and the MUBUF D16 loads (#235).

One topic, +64 / -4: 6 lines in rdna2/mnem.rs, 18 in hlsl/global.rs, 44 lines of test.

What was missing

tests/isa_table.rs lists flat_load_{ubyte,sbyte,short}_d16{,_hi} and the matching global_ forms under "gfx1013 opcodes not named by the decoder" (global decodes as flat_ with a segment).

The change

opcode lowering
*_load_ubyte_d16 / *_load_sbyte_d16 (0x20 / 0x22) the byte, zero- or sign-extended to 16 bits, replaces vdst[15:0]; vdst[31:16] kept
*_load_ubyte_d16_hi / *_load_sbyte_d16_hi (0x21 / 0x23) the same into vdst[31:16]; vdst[15:0] kept
*_load_short_d16 / _hi (0x24 / 0x25) the halfword into vdst[15:0] / [31:16]

These go through the existing width() / global_load_expr path, so window bounds and faults behave as for flat_load_ubyte. The loads read vdst for the kept half. The scratch segment is unchanged: the translator still refuses scratch access.

Tests

New exec_mem::global::flat_global_d16_loads: 6 mnemonics × 5 address modes, vdst preloaded with 0x5a5aa5a5.

run (WARP, --release, DXC 1.9.2609) result
flat_global_d16_loads 6 mnemonics verified, 0 failing, 30 cases (+30 runtime-input reruns)
flat_global_mem (regression) 16 mnemonics verified, 0 failing, 78 cases
all exec_mem::global tests 5 passed
mutation: keep-half merge removed 0 verified, 6 failing
--test isa_table / --test opcodes 3 / 26 passed

Run on x86_64-pc-windows-gnu (no MSVC linker here). Integer only.

  • cargo test -p tombox-xshader --test exec -- exec_mem::global 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:22 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/249) `azerioxfr:xshader-flat-global-d16-loads` → `main` · +64 −4 · 3 files · 1 commits · closed without merging **Library / area:** tombox-xshader, FLAT / GLOBAL sub-dword loads (`hlsl/global.rs`) **Exports changed (exports.txt rows):** none **Source of the behaviour:** opcodes from `tests/isa_table/gfx1013.txt` (FLAT / GLOBAL 0x20..0x25). Semantics from the RDNA2 ISA descriptions, lowered like the LDS D16 reads (28f54b2) and the MUBUF D16 loads (#235). One topic, +64 / -4: 6 lines in `rdna2/mnem.rs`, 18 in `hlsl/global.rs`, 44 lines of test. ### What was missing `tests/isa_table.rs` lists `flat_load_{ubyte,sbyte,short}_d16{,_hi}` and the matching `global_` forms under "gfx1013 opcodes not named by the decoder" (global decodes as `flat_` with a segment). ### The change | opcode | lowering | |---|---| | `*_load_ubyte_d16` / `*_load_sbyte_d16` (0x20 / 0x22) | the byte, zero- or sign-extended to 16 bits, replaces vdst[15:0]; vdst[31:16] kept | | `*_load_ubyte_d16_hi` / `*_load_sbyte_d16_hi` (0x21 / 0x23) | the same into vdst[31:16]; vdst[15:0] kept | | `*_load_short_d16` / `_hi` (0x24 / 0x25) | the halfword into vdst[15:0] / [31:16] | These go through the existing `width()` / `global_load_expr` path, so window bounds and faults behave as for `flat_load_ubyte`. The loads read vdst for the kept half. The scratch segment is unchanged: the translator still refuses scratch access. ### Tests New `exec_mem::global::flat_global_d16_loads`: 6 mnemonics × 5 address modes, vdst preloaded with `0x5a5aa5a5`. | run (WARP, `--release`, DXC 1.9.2609) | result | |---|---| | `flat_global_d16_loads` | **6 mnemonics verified, 0 failing, 30 cases** (+30 runtime-input reruns) | | `flat_global_mem` (regression) | 16 mnemonics verified, 0 failing, 78 cases | | all `exec_mem::global` tests | 5 passed | | mutation: keep-half merge removed | 0 verified, 6 failing | | `--test isa_table` / `--test opcodes` | 3 / 26 passed | Run on `x86_64-pc-windows-gnu` (no MSVC linker here). Integer only. - [x] `cargo test -p tombox-xshader --test exec -- exec_mem::global` passes - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note
FLAT/GLOBAL/SCRATCH opcodes 0x20..0x25 were not decoded (the isa_table
test lists them under "gfx1013 opcodes not named by the decoder"). They
now decode and are lowered next to the other sub-dword flat/global
accesses:
- flat_load_ubyte_d16 / flat_load_sbyte_d16 (0x20 / 0x22): the byte,
  zero- or sign-extended to 16 bits, replaces bits [15:0] of vdst;
- flat_load_ubyte_d16_hi / flat_load_sbyte_d16_hi (0x21 / 0x23): the
  same into bits [31:16];
- flat_load_short_d16 / flat_load_short_d16_hi (0x24 / 0x25): the
  halfword into bits [15:0] / [31:16].
The other half of vdst is kept, so these loads also read vdst, with the
same merge as the LDS D16 forms (28f54b2) and the MUBUF D16 forms.
Scratch-segment loads stay refused: routes() only accepts scratch
stores, so a scratch D16 load still falls through to "unsupported
encoding" (pinned by the routing test). Semantics follow the RDNA2 ISA
descriptions of these opcodes.

Tests: flat_global_d16_loads gains the six loads (vdst preloaded with
0x5a5aa5a5 so the kept half is checked) over the five flat/global
address modes; global_routing_and_refusals pins the mnemonic decode and
the scratch-segment refusal. Dropping the kept half fails the 6 loads.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:15:48 +00:00
github-bot closed this pull request 2026-11-26 06:15:48 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-23 14:08 UTC · original

Applied locally on main with your authorship kept (cherry-picked, 3b3028b); the tombox-xshader suite passes in a sandbox (exec 155/155 on WARP). It ships in the next release; this PR will be closed when that is pushed. Thanks.

**@⁠omonkeyz** on GitHub · 2026-11-23 14:08 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/249#issuecomment-7103530002) Applied locally on main with your authorship kept (cherry-picked, 3b3028b); the tombox-xshader suite passes in a sandbox (exec 155/155 on WARP). It ships in the next release; this PR will be closed when that is pushed. Thanks.
Author
Owner

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

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

**@⁠omonkeyz** on GitHub · 2026-11-25 13:07 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/249#issuecomment-7163333780) Applied on main in 3b3028b (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

I checked this 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 six global forms match on 2,048 cases each: global_load_ubyte_d16, _ubyte_d16_hi, _sbyte_d16, _sbyte_d16_hi, _short_d16 and _short_d16_hi. The cases used random memory, every byte offset 0..3 (0 and 2 for the shorts) and random preloaded vdst values.

  • The byte is zero- or sign-extended to 16 bits.
  • The loaded half replaces vdst[15:0], or [31:16] for _hi.
  • The other half is kept.

I checked the global_ encodings, not flat_.

(Measured with an AI assistant, Claude.)

**@⁠SchmashinPrunes** on GitHub · 2026-11-24 14:34 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/249#pullrequestreview-6041179417) · **approved these changes** I checked this 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 six global forms match on 2,048 cases each: `global_load_ubyte_d16`, `_ubyte_d16_hi`, `_sbyte_d16`, `_sbyte_d16_hi`, `_short_d16` and `_short_d16_hi`. The cases used random memory, every byte offset 0..3 (0 and 2 for the shorts) and random preloaded vdst values. - The byte is zero- or sign-extended to 16 bits. - The loaded half replaces vdst[15:0], or [31:16] for `_hi`. - The other half is kept. I checked the `global_` encodings, not `flat_`. (Measured with an AI assistant, Claude.)

Pull request closed

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