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

Closed
azerioxfr wants to merge 1 commit from upstream-pr/263 into main
azerioxfr commented 2026-11-23 08:34:40 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by azerioxfr on 2026-11-23T08:34:40Z.


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
<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6555425734 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/263). Originally posted by [azerioxfr](https://github.com/azerioxfr) on 2026-11-23T08:34:40Z. --- **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
omonkeyz commented 2026-11-23 14:08:09 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-23T14:08:09Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7103532676 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/263#issuecomment-7103532676). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-23T14:08:09Z. --- 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.
SchmashinPrunes commented 2026-11-24 14:34:51 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


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

<!-- greyfinch-sync:omonkeyz/xbox-emulator:review:6041180951 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/263#pullrequestreview-6041180951). Originally posted by [SchmashinPrunes](https://github.com/SchmashinPrunes) on 2026-11-24T14:34:51Z. **Review:** CHANGES_REQUESTED --- 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.)
omonkeyz commented 2026-11-25 13:08:05 +00:00 (Migrated from github.com)

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


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

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7163339421 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/263#issuecomment-7163339421). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-25T13:08:05Z. --- Applied on main in 8b15fe5 (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!263
No description provided.