tombox-xshader: keep the RDNA2 NaN payload in buffer_load_format_d16 (follow-up to #263) #382
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/382"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from omonkeyz/xbox-emulator. Originally posted by SchmashinPrunes on 2026-11-25T15:30:38Z.
This is a follow-up to #263 that also corrects my review there.
Correction to my #263 review
I wrote that
buffer_load_format_d16_xdoesn't round the wayf32tof16does, and that 1,014 of 2,048 recorded cases differ. That was wrong. My comparison used a round-to-nearest-even model off32tof16, but D3D doesn't define it that way. The D3D11.3 functional spec, §3.2.2, says:That is the rounding and overflow rule gfx1036 follows. So #263 as applied already rounds the same as the hardware, on any conformant host. Both hosts here confirm it: the recorded rounding and overflow cases below pass on WARP and on an RX 9060 XT with today's
f32tof16. Sorry for the noise.What is still different: NaN payloads
The spec leaves the NaN payload open, and hosts differ there:
f32tof16f32tof160xffbfffff0xfdff0xffff0xfdff0x7f8000010x7c010x7fff0x7c010x7fc000000x7e000x7fff0x7e000x7f8100000x7c080x7fff0x7c08The hardware keeps the truncated payload,
sign | 0x7c00 | max(mant >> 13, 1). This is the same rule the MTBUF d16 path already implements intb_f16_rtz(hlsl/mtbuf.rs), and it matched all 40 NaN inputs in the 2,048-case recording. WARP collapses every NaN to0x7fff/0xffff.Change
The MUBUF format d16 loads now use
tb_f16_rtz(asuint(x))instead off32tof16(x), and setuses_d16so the helper is emitted. For non-NaN values the result is the same as before.The rule is measured for 32_FLOAT elements only. For other source formats this keeps today's approach (the view converts to f32, then f32 → f16), and the NaN handling now follows the hardware rule.
Tests
New
buffer_mubuf_format_d16_load_keeps_the_rdna2_nan_payload, with 16 elements:Each case also checks that vdst[31:16] is kept.
Results (Windows 11, DXC from
TOMBOX_DXC_DIR):hlsl.rschange0x7fff/0xffff); the 8 rounding, overflow and infinity cases passtombox-xshadersuitetests/exec.rs190/190TOMBOX_EXEC_HW=1), execThe PR gate is clean.
🤖 Generated with Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.