tombox-xshader: 32-bit tbuffer_store partial stores and snorm ties differ from RDNA2 hardware #42

Closed
opened 2026-11-26 06:08:13 +00:00 by github-bot · 1 comment
Owner

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

While measuring MTBUF d16 on real RDNA2 hardware (gfx1036, tools/rdna2-hwprobe from #41), I found that the 32-bit tbuffer_store_format_* model disagrees with the hardware in two ways. Both instructions are currently marked verified (on WARP, against the existing model).

1. Partial stores write the whole element. A store with fewer components than the format writes every component; the missing ones become 0. The translator (mtbuf.rs, len = end_bits / 8 when w < nc) writes only the stored components' bytes and leaves the rest untouched. It also refuses sub-byte formats with "writes part of a byte", which the hardware has no trouble with.

Hardware, each thread storing (0.25, 0.5, 0.75, 1.0) as fp32. The output buffer starts as 0xAA bytes, so untouched bytes would show as aa:

fmt 56 8_8_8_8_UNORM   x: 40000000 | xy: 40800000 | xyz: 4080bf00 | xyzw: 4080bfff
fmt 60 8_8_8_8_UINT    x: ff000000 | xy: ffff0000 | xyz: ffffff00 | xyzw: ffffffff
fmt 65 16x4_UNORM      x: 0040000000000000 | xy: 0040008000000000 | ...
fmt 44 2_10_10_10_UNORM x: 01000000 | xy: 01080000 | xyz: 01f82f00

The translator would produce 40aaaaaa for the first one, for example. Reproduce with tools/rdna2-hwprobe/partial_store32.py.

2. snorm stores round halves away from zero. In the 2-bit snorm field (formats 45 and 51), ±0.5 is stored as ±1 on hardware. pack() uses round() (nearest-even), which gives 0. Wider snorm fields have no reachable exact ties from fp32 inputs, so in practice only the 2-bit field is affected. (Measured via the d16 stores; the conversion stage is shared.)

Happy to send a fix PR for both, with WARP tests built against the hardware results, if you'd like the 32-bit path to follow the hardware. I've left it alone in #41 so that PR doesn't change already-verified behaviour.

**@⁠SchmashinPrunes** on GitHub · 2026-11-21 18:58 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/42) While measuring MTBUF d16 on real RDNA2 hardware (gfx1036, `tools/rdna2-hwprobe` from #41), I found that the **32-bit** `tbuffer_store_format_*` model disagrees with the hardware in two ways. Both instructions are currently marked verified (on WARP, against the existing model). **1. Partial stores write the whole element.** A store with fewer components than the format writes every component; the missing ones become 0. The translator (`mtbuf.rs`, `len = end_bits / 8` when `w < nc`) writes only the stored components' bytes and leaves the rest untouched. It also refuses sub-byte formats with "writes part of a byte", which the hardware has no trouble with. Hardware, each thread storing (0.25, 0.5, 0.75, 1.0) as fp32. The output buffer starts as 0xAA bytes, so untouched bytes would show as `aa`: ``` fmt 56 8_8_8_8_UNORM x: 40000000 | xy: 40800000 | xyz: 4080bf00 | xyzw: 4080bfff fmt 60 8_8_8_8_UINT x: ff000000 | xy: ffff0000 | xyz: ffffff00 | xyzw: ffffffff fmt 65 16x4_UNORM x: 0040000000000000 | xy: 0040008000000000 | ... fmt 44 2_10_10_10_UNORM x: 01000000 | xy: 01080000 | xyz: 01f82f00 ``` The translator would produce `40aaaaaa` for the first one, for example. Reproduce with `tools/rdna2-hwprobe/partial_store32.py`. **2. snorm stores round halves away from zero.** In the 2-bit snorm field (formats 45 and 51), ±0.5 is stored as ±1 on hardware. `pack()` uses `round()` (nearest-even), which gives 0. Wider snorm fields have no reachable exact ties from fp32 inputs, so in practice only the 2-bit field is affected. (Measured via the d16 stores; the conversion stage is shared.) Happy to send a fix PR for both, with WARP tests built against the hardware results, if you'd like the 32-bit path to follow the hardware. I've left it alone in #41 so that PR doesn't change already-verified behaviour.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:08:13 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 13:20 UTC · original

Fixed on main in b72625c: partial 32-bit tbuffer stores zero-fill the element (len = format bytes), and snorm ties round away from zero. Tests: mtbuf_partial_store_zero_fills_like_rdna2 and mtbuf_snorm2_ties_round_away. Thanks for the hardware measurements!

**@⁠omonkeyz** on GitHub · 2026-11-22 13:20 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/42#issuecomment-7079737383) Fixed on main in b72625c: partial 32-bit tbuffer stores zero-fill the element (len = format bytes), and snorm ties round away from zero. Tests: mtbuf_partial_store_zero_fills_like_rdna2 and mtbuf_snorm2_ties_round_away. Thanks for the hardware measurements!
This discussion has been locked. Commenting is limited to contributors.
No description provided.