tombox-xshader: decode and translate buffer_load/store_format_d16_x and _d16_hi_x #263

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

@⁠azerioxfr on GitHub · 2026-11-23 08:34 UTC · original
azerioxfr:xshader-mubuf-format-d16 → main · +91 −2 · 3 files · 1 commits · closed without merging

Library / area: tombox-xshader, MUBUF typed-buffer D16 forms (hlsl.rs typed-buffer path)

Exports changed (exports.txt rows): none

Source of the behaviour: opcodes from tests/isa_table/gfx1013.txt (MUBUF 0x80, 0x84, 0x26, 0x27). Semantics from the RDNA2 ISA, on the existing typed-buffer path, which declares the element float4 because the view format is not visible (#105).

One topic, +91 / -2: 2 lines in rdna2/mnem.rs, about 50 in hlsl.rs, the rest tests.

What was missing

tests/isa_table.rs lists these under "mubuf: gfx1013 opcodes not named by the decoder".

The change

opcode lowering
buffer_load_format_d16_x (0x80) f32tof16(.x) into vdst[15:0]; vdst[31:16] kept
buffer_load_format_d16_hi_x (0x26) the same half into vdst[31:16]; vdst[15:0] kept
buffer_store_format_d16_x / _hi_x (0x84 / 0x27) f16tof32 of vdata[15:0] / [31:16], stored as .x

The kept half matches the other D16 loads (LDS, MUBUF byte/short, FLAT). A slot whose element type the translator infers as integer (tbuf_ty, or an atomic uint slot) refuses the D16 forms explicitly instead of guessing a type, following your answer on #105.

Left out: the multi-component forms (_xy, _xyz, _xyzw, 0x81..0x83 / 0x85..0x87) stay unnamed. The exec harness binds the typed buffer as a single R32_FLOAT channel, so their .y/.z/.w cannot be checked bit-exact.

Tests

run (WARP, --release, DXC 1.9.2609) result
new buffer_mubuf_format_d16: four ops over eight values (exact in f16 and ones that need rounding); vdst preloaded with 0x5a5aa5a5 for the loads 4 mnemonics verified, 0 failing, 32 cases
new mubuf_format_d16_refuses_integer_slots passes
mutation: kept half zeroed 2 verified, 2 failing (both loads)
buffer_mubuf (shared harness gains run_buf_cases_buf) 18 mnemonics verified, 0 failing, 143 cases
--test isa_table / --test opcodes 3 / 26 passed
  • tests pass (x86_64-pc-windows-gnu)
  • 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 08:34 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/263) `azerioxfr:xshader-mubuf-format-d16` → `main` · +91 −2 · 3 files · 1 commits · closed without merging **Library / area:** tombox-xshader, MUBUF typed-buffer D16 forms (`hlsl.rs` typed-buffer path) **Exports changed (exports.txt rows):** none **Source of the behaviour:** opcodes from `tests/isa_table/gfx1013.txt` (MUBUF 0x80, 0x84, 0x26, 0x27). Semantics from the RDNA2 ISA, on the existing typed-buffer path, which declares the element float4 because the view format is not visible (#105). One topic, +91 / -2: 2 lines in `rdna2/mnem.rs`, about 50 in `hlsl.rs`, the rest tests. ### What was missing `tests/isa_table.rs` lists these under "mubuf: gfx1013 opcodes not named by the decoder". ### The change | opcode | lowering | |---|---| | `buffer_load_format_d16_x` (0x80) | `f32tof16(.x)` into vdst[15:0]; vdst[31:16] kept | | `buffer_load_format_d16_hi_x` (0x26) | the same half into vdst[31:16]; vdst[15:0] kept | | `buffer_store_format_d16_x` / `_hi_x` (0x84 / 0x27) | `f16tof32` of vdata[15:0] / [31:16], stored as `.x` | The kept half matches the other D16 loads (LDS, MUBUF byte/short, FLAT). A slot whose element type the translator infers as integer (`tbuf_ty`, or an atomic uint slot) refuses the D16 forms explicitly instead of guessing a type, following your answer on #105. **Left out:** the multi-component forms (`_xy`, `_xyz`, `_xyzw`, 0x81..0x83 / 0x85..0x87) stay unnamed. The exec harness binds the typed buffer as a single R32_FLOAT channel, so their .y/.z/.w cannot be checked bit-exact. ### Tests | run (WARP, `--release`, DXC 1.9.2609) | result | |---|---| | new `buffer_mubuf_format_d16`: four ops over eight values (exact in f16 and ones that need rounding); vdst preloaded with `0x5a5aa5a5` for the loads | **4 mnemonics verified, 0 failing, 32 cases** | | new `mubuf_format_d16_refuses_integer_slots` | passes | | mutation: kept half zeroed | 2 verified, 2 failing (both loads) | | `buffer_mubuf` (shared harness gains `run_buf_cases_buf`) | 18 mnemonics verified, 0 failing, 143 cases | | `--test isa_table` / `--test opcodes` | 3 / 26 passed | - [x] tests pass (`x86_64-pc-windows-gnu`) - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note
MUBUF opcodes 0x80, 0x84, 0x26 and 0x27 were not decoded (the isa_table
test lists them under "mubuf: gfx1013 opcodes not named by the
decoder"). They now decode and are lowered on the existing typed-buffer
path, which declares the element float4 because the view format is not
visible in the shader (issue #105):
- buffer_load_format_d16_x: f32tof16 of .x into vdst[15:0], vdst[31:16]
  kept;
- buffer_load_format_d16_hi_x: the same half into vdst[31:16],
  vdst[15:0] kept;
- buffer_store_format_d16_x / _hi_x: f16tof32 of vdata[15:0] / [31:16]
  stored as .x.
The kept half follows the other D16 loads (LDS, MUBUF byte/short,
FLAT), so the loads also read vdst. A slot whose element type the
translator infers as integer (tbuf_ty, or an atomic uint slot) refuses
the D16 forms explicitly instead of guessing a type.

The multi-component forms (_xy, _xyz, _xyzw, 0x81-0x83 and 0x85-0x87)
stay unnamed: the exec harness binds the typed buffer as a single
R32_FLOAT channel, so their .y/.z/.w could not be checked bit-exact.

Tests: buffer_mubuf_format_d16 runs the four ops over eight values
(exactly representable in f16 and ones that need rounding), with vdst
preloaded with 0x5a5aa5a5 for the loads: 4 mnemonics verified, 0
failing, 32 cases on WARP. Zeroing the kept half fails both loads.
mubuf_format_d16_refuses_integer_slots pins the integer-slot refusal.
The buffer test harness gains run_buf_cases_buf for a custom buffer;
buffer_mubuf is unchanged (18 mnemonics, 143 cases).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:16:25 +00:00
github-bot closed this pull request 2026-11-26 06:16:25 +00:00
Author
Owner

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

Applied locally on main with your authorship kept (cherry-picked, 8b15fe5); 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/263#issuecomment-7103532676) Applied locally on main with your authorship kept (cherry-picked, 8b15fe5); 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:08 UTC · original

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

**@⁠omonkeyz** on GitHub · 2026-11-25 13:08 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/263#issuecomment-7163339421) Applied on main in 8b15fe5 (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 · requested 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).

buffer_load_format_d16_x doesn't round the way f32tof16 does. I loaded 2,048 32_FLOAT elements: edge values (ties, the fp16 overflow boundary, subnormals, NaNs with payloads) plus random values. The hardware matched the rule this repo already measured for MTBUF d16 on every case (tools/rdna2-hwprobe/README.txt, hlsl/mtbuf.rs):

  • rounding is toward zero;
  • finite overflow gives ±65504, and infinity stays infinity;
  • a NaN becomes sign | 0x7c00 | ((mant >> 13) or 1), truncated and not quieted;
  • vdst[31:16] is kept.

Effect: 1,014 of the 2,048 cases differ from round-to-nearest-even. For example, on hardware:

  • 0xb94fb51a gives 0x8a7d, where RNE gives 0x8a7e;
  • 0xfb35c593 gives 0xfbff, where RNE gives 0xfc00;
  • 0xffbfffff gives 0xfdff, where the canonical NaN is 0x7e00.

The 8 values in buffer_mubuf_format_d16 don't separate the two rules: 0.1, 1000.5 and 1.0000001 give the same half either way. So the test passes with either one.

Suggested fix: reuse the MTBUF d16 conversion for 32-bit float elements, and add cases that need rounding, overflow and NaN. buffer_store_format_d16_x widens exactly, and NaN keeps its payload; that matched on all 2,048 cases.

The _hi_x forms (0x26 / 0x27). LLVM 18 doesn't accept buffer_load_format_d16_hi_x / buffer_store_format_d16_hi_x for any gfx10 target, gfx1013 included. Its disassembler reports those encodings as invalid on gfx1013, and they assemble only for GFX9. The repo's gfx1013 table lists them, so one of the two sources is wrong. I didn't run them: an unsupported DS opcode hung this GPU earlier today. It may be safer to leave 0x26/0x27 unnamed until there's a gfx101x source for them.

(Measured with an AI assistant, Claude.)

**@⁠SchmashinPrunes** on GitHub · 2026-11-24 14:34 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/263#pullrequestreview-6041180951) · **requested 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). **`buffer_load_format_d16_x` doesn't round the way `f32tof16` does.** I loaded 2,048 32_FLOAT elements: edge values (ties, the fp16 overflow boundary, subnormals, NaNs with payloads) plus random values. The hardware matched the rule this repo already measured for MTBUF d16 on every case (tools/rdna2-hwprobe/README.txt, hlsl/mtbuf.rs): - rounding is toward zero; - finite overflow gives ±65504, and infinity stays infinity; - a NaN becomes sign | 0x7c00 | ((mant >> 13) or 1), truncated and not quieted; - vdst[31:16] is kept. **Effect:** 1,014 of the 2,048 cases differ from round-to-nearest-even. For example, on hardware: - `0xb94fb51a` gives `0x8a7d`, where RNE gives `0x8a7e`; - `0xfb35c593` gives `0xfbff`, where RNE gives `0xfc00`; - `0xffbfffff` gives `0xfdff`, where the canonical NaN is `0x7e00`. The 8 values in `buffer_mubuf_format_d16` don't separate the two rules: 0.1, 1000.5 and 1.0000001 give the same half either way. So the test passes with either one. **Suggested fix:** reuse the MTBUF d16 conversion for 32-bit float elements, and add cases that need rounding, overflow and NaN. `buffer_store_format_d16_x` widens exactly, and NaN keeps its payload; that matched on all 2,048 cases. **The `_hi_x` forms (0x26 / 0x27).** LLVM 18 doesn't accept `buffer_load_format_d16_hi_x` / `buffer_store_format_d16_hi_x` for any gfx10 target, gfx1013 included. Its disassembler reports those encodings as invalid on gfx1013, and they assemble only for GFX9. The repo's gfx1013 table lists them, so one of the two sources is wrong. I didn't run them: an unsupported DS opcode hung this GPU earlier today. It may be safer to leave 0x26/0x27 unnamed until there's a gfx101x source for them. (Measured with an AI assistant, Claude.)

Pull request closed

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