xshader: honour MIMG UNORM and A16, and refuse MUBUF LDS/TFE #160

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

@⁠GDAgent on GitHub · 2026-11-22 16:49 UTC · original
GDAgent:port/xshader-mimg-unorm-refusals → main · +215 −23 · 3 files · 1 commits · closed without merging

Library / area: tombox-xshader (hlsl.rs, tests/exec_mem/mimg.rs)

Exports changed (exports.txt rows): none

Source of the behaviour: AMD RDNA2 ISA specification (§13.6.2 MUBUF Table 98, §13.7 MIMG Table 100) and Mesa ACO (aco_select_nir.cpp A16 operand packing). Ported from brcly/TomBox 97db52f and 9d3247a (MIT OR Apache-2.0); credit line extended in THIRD_PARTY/CREDITS.

Changes:

  • Honour MIMG UNORM (dword0[12]) on image_sample*, image_gather*, and image_get_lod by querying mip-0 dimensions via GetDimensions and dividing spatial coordinates (and derivatives, when present) by the mip-0 size while leaving array slices unscaled; explicitly refuse UNORM on cube images (dim == 3).
  • Honour MIMG A16 (dword1[30]) across texel-addressed ops (image_load*, image_store*, image_atomic_*, packed 16-bit uint coordinates), image_get_resinfo, image_get_lod, and image_sample*/image_gather* (bias f16 in low half of its dword; coordinates, LOD, and clamp packed as f16 two per VGPR).
  • Explicitly refuse MUBUF LDS (dword0[16]) and TFE (dword1[23]) instead of silently ignoring them. The MIMG R128/TFE/LWE refusal already exists on main (#114); this change reuses it and only keeps the UNORM and A16 decoding next to it.
  • Track image_store* data registers as live-in reads rather than writes in Emitter::live_in.
  • Add D3D12 execution tests for MIMG UNORM (2D, 2D-array, explicit LOD) and A16 (load, store, sample_lz, sample_l), plus explicit refusal checks (MIMG TFE and LWE through the existing refusal, MIMG UNORM on cube, MUBUF LDS, MUBUF TFE).

Tests (native Windows 11; not run under Proton):

  • cargo test --release -p tombox-xshader --lib --test opcodes --test synthetic: 116 passed, 0 failed, 2 ignored.

  • cargo test --release -p tombox-xshader --test exec -- image_mimg (D3D12 execution on hardware): 8 passed, including image_mimg_unorm_a16_and_refusals (UNORM and A16 cases, each rerun with runtime inputs, plus the refusal checks).

  • The full exec suite has 3 failures that also occur on plain main: scalar_smem_loads, exec_mem::mtbuf::mtbuf_d16_store_formats, vop::basic::vop2_basic. Nothing extra fails with this change.

  • Not verified in a title with this repo's build.

  • Related, not fixed here: #103 (MIMG load/store coverage). #114 (R128/TFE/LWE) is already fixed on main; this change reuses that refusal.

  • cargo test -p tombox-xshader tests pass

  • No game or console files and no binaries included

  • No fake success; unsupported LDS/TFE/UNORM-cube forms fail explicitly

**@⁠GDAgent** on GitHub · 2026-11-22 16:49 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/160) `GDAgent:port/xshader-mimg-unorm-refusals` → `main` · +215 −23 · 3 files · 1 commits · closed without merging **Library / area:** tombox-xshader (`hlsl.rs`, `tests/exec_mem/mimg.rs`) **Exports changed (exports.txt rows):** none **Source of the behaviour:** AMD RDNA2 ISA specification (§13.6.2 MUBUF Table 98, §13.7 MIMG Table 100) and Mesa ACO (`aco_select_nir.cpp` A16 operand packing). Ported from brcly/TomBox `97db52f` and `9d3247a` (MIT OR Apache-2.0); credit line extended in `THIRD_PARTY/CREDITS`. Changes: - Honour MIMG `UNORM` (`dword0[12]`) on `image_sample*`, `image_gather*`, and `image_get_lod` by querying mip-0 dimensions via `GetDimensions` and dividing spatial coordinates (and derivatives, when present) by the mip-0 size while leaving array slices unscaled; explicitly refuse `UNORM` on cube images (`dim == 3`). - Honour MIMG `A16` (`dword1[30]`) across texel-addressed ops (`image_load*`, `image_store*`, `image_atomic_*`, packed 16-bit uint coordinates), `image_get_resinfo`, `image_get_lod`, and `image_sample*`/`image_gather*` (bias f16 in low half of its dword; coordinates, LOD, and clamp packed as f16 two per VGPR). - Explicitly refuse MUBUF `LDS` (`dword0[16]`) and `TFE` (`dword1[23]`) instead of silently ignoring them. The MIMG `R128`/`TFE`/`LWE` refusal already exists on main (#114); this change reuses it and only keeps the UNORM and A16 decoding next to it. - Track `image_store*` data registers as live-in reads rather than writes in `Emitter::live_in`. - Add D3D12 execution tests for MIMG `UNORM` (2D, 2D-array, explicit LOD) and `A16` (load, store, `sample_lz`, `sample_l`), plus explicit refusal checks (MIMG TFE and LWE through the existing refusal, MIMG UNORM on cube, MUBUF LDS, MUBUF TFE). Tests (native Windows 11; not run under Proton): - `cargo test --release -p tombox-xshader --lib --test opcodes --test synthetic`: 116 passed, 0 failed, 2 ignored. - `cargo test --release -p tombox-xshader --test exec -- image_mimg` (D3D12 execution on hardware): 8 passed, including `image_mimg_unorm_a16_and_refusals` (UNORM and A16 cases, each rerun with runtime inputs, plus the refusal checks). - The full exec suite has 3 failures that also occur on plain `main`: `scalar_smem_loads`, `exec_mem::mtbuf::mtbuf_d16_store_formats`, `vop::basic::vop2_basic`. Nothing extra fails with this change. - Not verified in a title with this repo's build. - Related, not fixed here: #103 (MIMG load/store coverage). #114 (R128/TFE/LWE) is already fixed on `main`; this change reuses that refusal. - [x] `cargo test -p tombox-xshader` tests pass - [x] No game or console files and no binaries included - [x] No fake success; unsupported LDS/TFE/UNORM-cube forms fail explicitly
- Honour MIMG UNORM (dword0[12]) on sample/gather/get_lod by querying mip-0
  dimensions via GetDimensions and scaling spatial coordinates (leaving
  array slices unchanged); explicitly refuse UNORM on cube images.
- Honour MIMG A16 (dword1[30]) across texel loads/stores/atomics (packed
  16-bit uint coordinates), get_resinfo, get_lod, and sample/gather (bias
  f16 in low half; coords, lod, clamp packed f16 two per VGPR).
- Explicitly refuse MUBUF LDS (dword0[16]) and TFE (dword1[23]) forms
  instead of ignoring them. The MIMG R128/TFE/LWE refusal already on main
  is reused.
- Track image_store data registers as live-in reads rather than writes in
  Emitter::live_in.
- Add D3D12 execution tests for MIMG UNORM (2D, 2D-array, explicit LOD),
  MIMG A16 (load, store, sample_lz, sample_l) and the refusal paths.

Ported from brcly/TomBox 97db52f and 9d3247a (MIT OR Apache-2.0).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:12:12 +00:00
github-bot closed this pull request 2026-11-26 06:12:12 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 17:10 UTC · original

Applied in d7d72fe (merged in 43d17b0) with your authorship kept, thanks.

**@⁠omonkeyz** on GitHub · 2026-11-22 17:10 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/160#issuecomment-7082631580) Applied in d7d72fe (merged in 43d17b0) with your authorship kept, thanks.

Pull request closed

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