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

Closed
opened 2026-11-21 18:58:23 +00:00 by SchmashinPrunes · 1 comment
SchmashinPrunes commented 2026-11-21 18:58:23 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by SchmashinPrunes on 2026-11-21T18:58:23Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6533070390 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/issues/42). Originally posted by [SchmashinPrunes](https://github.com/SchmashinPrunes) on 2026-11-21T18:58:23Z. --- 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.
omonkeyz commented 2026-11-22 13:20:21 +00:00 (Migrated from github.com)
Author

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T13:20:21Z.


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!

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7079737383 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/issues/42#issuecomment-7079737383). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-22T13:20:21Z. --- 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!
Sign in to join this conversation.
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#42
No description provided.