MTBUF d16: RDNA2-measured conversions replace the ISA-only lowering (resubmit of #41) #133
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!133
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/133/head"
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?
@SchmashinPrunes on GitHub · 2026-11-22 14:30 UTC · original
SchmashinPrunes:mtbuf-d16-v2→main· +1596 −157 · 16 files · 1 commits · closed without mergingResubmission of #41 (closed by the history rewrite), rebuilt on
c8a8a8fas asked: cherry-picked onto main's current MTBUF code, comment lines stripped, and the probe notes moved fromREADME.mdtotools/rdna2-hwprobe/README.txt. #72 (@QuentinDanblon's VALU probe) stacks on this.Library / area: tombox-xshader (RDNA2 shader translator), MTBUF
tbuffer_{load,store}_format_d16_*, plustools/rdna2-hwprobe.Exports changed (exports.txt rows): none
Source of the behaviour: measurements on real RDNA2 hardware, the gfx1036 iGPU of a Ryzen 5 9600X under ROCm, using
tools/rdna2-hwprobe(hand-written kernels, synthetic inputs; no game or console files). gfx1036 is RDNA2 but not the console's gfx1013. The public ISA text only says "convert to packed 16-bit"; it doesn't specify the rounding, the int narrowing or the unused register half, so those were measured. Packed layout per LLVM's AMDGPU backend (HasPackedD16VMemon GFX9+).What changes compared with main
b72625c, whole element, missing components 0) is kept as is; d16 stores follow the same rule, which is what the hardware does for them too.Measured semantics (77 formats × 65536 elements, every 8/16-bit value)
vdatalo/hi, c2/c3 invdata+1._x/_xyzkeep the upper half of their last VGPR0x3bff, fp32-then-fp16 would give0x3c00sign|0x7c00|((mant>>13) or 1). Payload truncated, not quietedA missing w on d16 loads reads 1 (0x3c00 / 1), matching the 32-bit loads; on hardware that 1 comes from the descriptor's dst_sel (the probe used an identity swizzle, so it saw 0). Scaled and 11/10-bit-float stores follow no simple rule and stay unlowered, like the 32-bit forms.
Translator
src/hlsl/mtbuf.rs: loads reuse the existing fetch and field extraction, then narrow each component withD16_HELPERS; stores unpack the halves and pack them per format. All conversions are integer-only (exact rounding inuint64_t, fp16 → unorm/snorm as(M·max) >> sh), because a float/double version was wrong on WARP twice (DXC foldedx != x, and a double product was off by one).hlsl.rsgains auses_d16flag that emits the helpers.Tests (
tests/exec_mem/mtbuf.rs)mtbuf_d16_model_matches_rdna2pins it to 571 recorded vectors inmtbuf_hw.rs(regenerated bytools/rdna2-hwprobe/vectors.py), weighted to the cases where naive rules differ.mtbuf_d16_load_formats(539 cases, each rerun with runtime inputs; 64 threads, all four ops over all 77 formats, VGPRs preset to sentinels) andmtbuf_d16_store_formats(330 cases, output pre-filled with 0xAA) compare the translator with the model on WARP.mtbuf_d16_load_addressing(308) /mtbuf_d16_store_addressing(660): immediate, SGPR and unaligned addressing, adapted from main's earlier d16 tests (thanks @QuentinDanblon).mtbuf_refuses_unlowered: main's list minus the now-lowered d16 rows(8, 75)and(12, 9), plus d16 scaled / 11-bit float stores and an invalid d16 format._xzeroing the upper half, and snorm ties to even each make the tests fail.Results (Windows 11 Pro, WARP, DXC 1.9.2609)
Full
cargo test -p tombox-xshader --releaseonaa14bfa, then--test execagain ond585b94; rebased ontoc8a8a8fwithout conflicts.Every target passes apart from main's own
leonida_wave64_scalar_masks, which failed the same way on plainaa14bfa/d585b94(the exec lane-bit change thatbd880fchas since reverted).Probe (
tools/rdna2-hwprobe, Linux + ROCm)run.sh <outdir>buildsrunner.cppand the kernels fromgen.py, runs them on the GPU and checks both models (model.py,analyze_stores.py);analyze_loads.py,nan_rule.pyandvectors.pyanalyse a run and regeneratemtbuf_hw.rs.README.txthas the requirements, the input design and the full results. The scripts lost their comments for the gate; their outputs are unchanged (gen.pyandpartial_store32.pyproduce byte-identical kernels and inputs, and every script parses to the same AST as before apart fromvectors.py, which no longer prints comment lines intomtbuf_hw.rs).cargo test -p tombox-xshaderpasses🤖 Generated with Claude Code
Replaces the d16 tbuffer lowering with conversion rules measured on RDNA2 hardware (gfx1036 via ROCm, tools/rdna2-hwprobe): - loads: UNORM/SNORM/USCALED/SSCALED round once to nearest-even fp16, saturating at +-65504; 32-bit float rounds toward zero (overflow -> +-65504, inf kept, NaN payload kept); 32-bit ints clamp. These were refused before. - stores: fp16 widened exactly (NaN payload kept), unorm rounds to nearest-even, snorm rounds ties away from zero, ints extend then clamp; the whole element is written with missing components 0, as main's 32-bit stores now do. mtbuf_d16_model_matches_rdna2 checks the Rust reference model against the recorded hardware vectors (mtbuf_hw.rs); the WARP tests compare the translator with that model. mtbuf_d16_{load,store}_addressing cover immediate, SGPR and unaligned addressing. Probe notes are in tools/rdna2-hwprobe/README.txt. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Xsrj8HzdWhzzYYavNNpHjk@omonkeyz on GitHub · 2026-11-22 14:43 UTC · original
Applied in
a415541(merged in9ab6f59) with your authorship kept, thanks! Translator lib 69/0 and the WARP mtbuf exec cases 10/0 pass here. #72 can now be resubmitted on top of this.Pull request closed