xshader: FLAT byte/short/d16_hi verified, FLAT offset decode fix (RDNA2 746/779) #25

Closed
github-bot wants to merge 4 commits from gh-pr/25/head into gh-pr/25/base
Owner

@⁠QuentinDanblon on GitHub · 2026-11-21 18:01 UTC · original
QuentinDanblon:feat/ds-flat-mtbuf-verify → main · +1588 −840 · 18 files · 4 commits · closed without merging

Library / area: tombox-xshader (FLAT), progress map

Exports changed (exports.txt rows): none

Source of the behaviour: AMD RDNA2 ISA (FLAT offset fields, FLAT_STORE_*_D16_HI)

Stacked on #22: review only the last two commits.

Scope change: LDS atomics (#23) and MTBUF d16 were claimed first in #17 by @⁠SchmashinPrunes, and the d16 PR is in progress. Both are removed here. This PR is now FLAT only.

FLAT

  • FLAT/global ubyte/sbyte/ushort/sshort loads with zero/sign extension; byte/short/dword(x2/x3/x4) stores; _d16_hi stores of S0[23:16] / S0[31:16]. Each is tested in three address forms: SGPR base + VGPR offset, 64-bit VGPR address, FLAT segment.
  • Decoder fix: the FLAT segment takes an 11-bit unsigned offset (MSB ignored) and ignores SADDR. Only scratch/global offsets are 12-bit signed. The old decoder sign-extended for every segment. This also changes the s_getpc code-table path for FLAT loads; the old negative-offset FLAT test case was not encodable and is replaced.
  • New refusal: FLAT with LDS=1 (memory→LDS transfer). This bit used to be silently ignored.
  • tests/exec_mem/mod.rs: a shared verified() writes the TOMBOX_EXEC_VERIFIED list for every runner.

Tests (WARP, DXC 1.9.2609, #22 + this)

  • Full --test exec (measured with the d16 commit still included): 64 pass, 4 fail. The 4 failures are the vop::basic ones present on main, fixed by #24.
  • New group flat_global: 16 mnemonics, 78 cases + 78 runtime reruns. All 24 exec_mem::* tests pass on this exact tree.
  • --lib 8, --test opcodes 22, --test synthetic 7: all pass.
  • Mutation check: shifting d16_hi stores by 8 instead of 16 makes flat_global fail.

Progress

12 more mnemonics verified. RDNA2 instructions 734/779 → 746/779.

  • cargo test -p tombox-xshader passes (except the vop::basic failures already on main, fixed in #24)
  • No game or console files and no binaries included
  • No fake success; anything not possible is left missing with a note
**@⁠QuentinDanblon** on GitHub · 2026-11-21 18:01 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/25) `QuentinDanblon:feat/ds-flat-mtbuf-verify` → `main` · +1588 −840 · 18 files · 4 commits · closed without merging **Library / area:** tombox-xshader (FLAT), progress map **Exports changed (exports.txt rows):** none **Source of the behaviour:** AMD RDNA2 ISA (FLAT offset fields, FLAT_STORE_*_D16_HI) **Stacked on #22**: review only the last two commits. **Scope change:** LDS atomics (#23) and MTBUF d16 were claimed first in #17 by @⁠SchmashinPrunes, and the d16 PR is in progress. Both are removed here. This PR is now FLAT only. ### FLAT - FLAT/global ubyte/sbyte/ushort/sshort loads with zero/sign extension; byte/short/dword(x2/x3/x4) stores; `_d16_hi` stores of S0[23:16] / S0[31:16]. Each is tested in three address forms: SGPR base + VGPR offset, 64-bit VGPR address, FLAT segment. - **Decoder fix:** the FLAT segment takes an 11-bit *unsigned* offset (MSB ignored) and ignores SADDR. Only scratch/global offsets are 12-bit signed. The old decoder sign-extended for every segment. This also changes the s_getpc code-table path for FLAT loads; the old negative-offset FLAT test case was not encodable and is replaced. - **New refusal:** FLAT with LDS=1 (memory→LDS transfer). This bit used to be silently ignored. - `tests/exec_mem/mod.rs`: a shared `verified()` writes the TOMBOX_EXEC_VERIFIED list for every runner. ### Tests (WARP, DXC 1.9.2609, #22 + this) - Full `--test exec` (measured with the d16 commit still included): 64 pass, 4 fail. The 4 failures are the `vop::basic` ones present on main, fixed by #24. - New group flat_global: 16 mnemonics, 78 cases + 78 runtime reruns. All 24 `exec_mem::*` tests pass on this exact tree. - `--lib` 8, `--test opcodes` 22, `--test synthetic` 7: all pass. - Mutation check: shifting d16_hi stores by 8 instead of 16 makes flat_global fail. ### Progress 12 more mnemonics verified. **RDNA2 instructions 734/779 → 746/779.** - [x] `cargo test -p tombox-xshader` passes (except the `vop::basic` failures already on main, fixed in #24) - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note
Decode the GFX10 VOPC opcodes 0x89-0x8f, 0x99-0x9f, 0xa0-0xa7, 0xa9-0xae,
0xb0-0xb7, 0xb9-0xbe, 0xe0-0xe7 and 0xf0-0xf7 (v_cmp/v_cmpx lt..ge i16/u16,
f..t i64/u64, class_f16), mapping verified against LLVM
llvm/lib/Target/AMDGPU/VOPCInstructions.td (GFX10 section).

Translation (all VOPC/VOP3 compares now go through one vcmp_cond):
- 16-bit integer compares read the low half (sign-extended for i16); VOP3
  OPSEL[12:11] selects the high half of a register source, as already done
  for f16 arithmetic; f16 compares now honour OPSEL too (incl. NaN test).
  OPSEL on a constant, inline float constants and abs/neg on integer
  compares are refused.
- 64-bit integer compares on register pairs (high dword decides, low dword
  unsigned); inline integers sign-extend, a 32-bit literal sign-extends for
  i64 and zero-extends for u64 (LLVM AMDGPUOperandSyntax, "Conversion of
  Integer Values").
- v_cmp_class_f16 via tb_cmp_class16; VOP3 abs/neg apply to src0 of every
  class compare (LLVM VOPC_Class_Profile: Src0Mod, no src1 modifiers).
- GFX10 v_cmpx writes EXEC only (unchanged).

SDWA operand selection already happens before the compare lowering and
s_cmpk_*_u32 already zero-extends SIMM16, so those parts need no change.

Ported/adapted from brcly/TomBox (MIT OR Apache-2.0):
- be622e8 (be622e8): 16-bit integer
  compare opcodes and operand extension.
- master crates/tuxbox-xshader/src/rdna2/mnem.rs (VOPC table) and
  src/hlsl/compare.rs (64-bit integer compares on register pairs, literal
  extension, class_f16 parameters):
  https://github.com/brcly/TomBox/blob/master/crates/tuxbox-xshader/src/hlsl/compare.rs

Tests: exec vop::vopc gains i16, u16, i64, u64 and class_f16 groups (e32,
e64, cmpx, SDST, masked lanes, inline/literal/SGPR-pair sources, OPSEL,
class abs/neg); opcodes.rs covers the new decode and HLSL forms.
mnem_groups.json regenerated from rdna2/mnem.rs (same rule as sync.py):
58 new VOPC mnemonics, all verified by the new vopc_{i16,u16,i64,u64,
class_f16} exec groups on WARP.
- FLAT/global ubyte/sbyte/ushort/sshort loads (zero/sign extension),
  byte/short/dword(x2/x3/x4) stores and the _d16_hi stores of S0[23:16] /
  S0[31:16] (RDNA2 ISA FLAT_STORE_*_D16_HI), tested in three address forms:
  global SGPR base + VGPR offset, global 64-bit VGPR address, FLAT segment.
- Decoder: the FLAT segment takes an 11-bit unsigned offset (MSB ignored)
  and ignores SADDR; only scratch/global offsets are 12-bit signed (RDNA2
  ISA FLAT field table). The old negative-offset FLAT test case was not
  encodable and is replaced by an encoded 0x810 (= +16) case.
- FLAT with LDS=1 (memory to LDS transfer) is now refused instead of the
  bit being ignored.
- tests/exec_mem/mod.rs: shared verified() writes the TOMBOX_EXEC_VERIFIED
  list for every runner; new group flat_global.
12 mnemonics verified by the new exec group flat_global.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:07:37 +00:00
github-bot closed this pull request 2026-11-26 06:07:37 +00:00
Author
Owner

@⁠SchmashinPrunes on GitHub · 2026-11-21 18:44 UTC · original

PR for the MTBUf d16 part of that claim is in progress, should be pushing soon

**@⁠SchmashinPrunes** on GitHub · 2026-11-21 18:44 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/25#issuecomment-7067479980) PR for the MTBUf d16 part of that claim is in progress, should be pushing soon
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-21 18:48 UTC · original

@⁠SchmashinPrunes thanks, I've removed MTBUF d16 from this PR, which is now FLAT only. For comparison, my d16 version is commit 40159df on QuentinDanblon:ref/mtbuf-d16. It refuses loads from UNORM/SNORM, 32-bit and 16-bit scaled formats, because the ISA gives no rounding/clamp rule for 'converted to 16 bits', and it has 813 d16 cases that pass on WARP. Use whatever helps.

**@⁠QuentinDanblon** on GitHub · 2026-11-21 18:48 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/25#issuecomment-7067523509) @⁠SchmashinPrunes thanks, I've removed MTBUF d16 from this PR, which is now FLAT only. For comparison, my d16 version is commit 40159df on [QuentinDanblon:ref/mtbuf-d16](https://github.com/QuentinDanblon/xbox-emulator/commit/40159df). It refuses loads from UNORM/SNORM, 32-bit and 16-bit scaled formats, because the ISA gives no rounding/clamp rule for 'converted to 16 bits', and it has 813 d16 cases that pass on WARP. Use whatever helps.
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-21 21:03 UTC · original

Merged in the source sync 1159c96 (adapted). Thanks! Closing.

**@⁠QuentinDanblon** on GitHub · 2026-11-21 21:03 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/25#issuecomment-7069202759) Merged in the source sync 1159c96 (adapted). Thanks! Closing.

Pull request closed

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