feat: d16 typed buffer loads and stores (buffer/tbuffer_*_format_d16_*) in the RDNA 2 interpreter and HLSL — 1,156/1,490 #230
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/230"
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 LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-25T19:39:45Z.
Supersedes #223 (closed by the maintainer for conflicts; now rebased onto main
e921268)Only the README lines conflicted; numbers recomputed. The float32 → float16 narrowing here keeps NaN payloads (buffer conversion, #150), so it stays separate from the f16 ALU helpers of #218, which give the canonical NaN.
Change
The 18 d16 typed buffer encodings that main still refused now run in the reference interpreter and translate to HLSL:
buffer_load_format_d16_{x,xy,xyz,xyzw,hi_x},buffer_store_format_d16_{x,xy,xyz,xyzw,hi_x},tbuffer_load_format_d16_{x,xy,xyz,xyzw},tbuffer_store_format_d16_{x,xy,xyz,xyzw}(the full list of_format_d16names inMNEMONICSwhererdna2_exec.executablewas false). The PR builds on the 32-bit typed formats of #150 and reuses its format tables, DST_SEL handling, bounds and conversions.Interpreter coverage, recounted on the tree merged with main
e921268: 1,208 → 1,226 of 1,490 encodings (rdna2_exec.coverage()), 81% → 82% in all 9 READMEs; the test count stays1400+(1,481 collected). #232 moves the same coverage line from the same base (1,208), and neither PR has merged yet, so the figures stay as they are. Whichever PR lands second will get the combined figure recomputed.Rules and sources
AMD, "RDNA 2" Instruction Set Architecture, November 2020 (archived copy from
docs/research/rdna2-sources.md, SHA-25622aec03f…4795, printed page numbers):VDATA + i/2, low half first (xyzw uses 2 VGPRs)FeatureUnpackedD16VMemis set only for GFX8 (AMDGPU.td), and the packedTBUFFER_LOAD_FORMAT_D16_XYusesVGPR_32(BUFInstructions.td)_d16_xwrites bits 15-0,_d16_hi_xbits 31-16, and the other half is keptD0[15:0] = MEM[ADDR]/D0[31:16] = MEM[ADDR]; §8.1.6 p. 64; AMD RDNA 2 XML: "store the result into the low/high 16 bits of a 32-bit vector register"Applied conversions:
0x7F800001→0x7C01). A 16-bit FLOAT field comes back unchanged. USCALED and SSCALED go float32 (the exact integer) → float16 to nearest even, overflow to infinity.0x3C00) for float, normalized and scaled formats and the integer 1 otherwise, #150's value narrowed like any other component.UNORM/SNORM and FLOAT narrowing: assumed, measurement requested
The ISA only says "data returned from the texture unit is converted to 16 bits" (§8.1.4, p. 59). No public source says how the data is rounded, so both rules are labelled assumed in the code, and akimfomin/PortBridge#85 asks for the decisive words. Only four 16-bit values separate one rounding of the exact quotient from two: 16_UNORM
0xFFAF→0x3BFDand0xFFEF→0x3BFF, 16_SNORM0x7FF7→0x3BFFand0x8009→0xBBFF. Narrowing the float32 instead gives0x3BFE,0x3C00,0x3C00and0xBC00. The other widths give the same half under both roundings, and a test checks this.Since the review, 32-bit FLOAT formats narrow toward zero (65504 past the range, NaN payload 1 when its top 10 bits are zero). The SPIR-V path
third_party/leonida/rdna2spirv.pyalready narrows them this way, so both translators of AnyXboxX now agree. The previous version of this PR rounded to nearest with infinity past the range and refused that NaN. Both choices are still assumptions until PortBridge#85 answers.Assumptions (not measured, stated in
emu/rdna2_buffer_d16.py)_d16_xyzis kept, like the high half of_d16_x. The ISA only gives pseudo-code for_xand_hi_x.Refused by name (no fake success)
32_UINT,32_32_SINT, …): whether 32 → 16 bits truncates or clamps is not documented.The HLSL follows the module's existing convention: what the interpreter refuses at run time (a MUBUF format read from the V#) reads zeros there.
HLSL
BufHalfRatiorounds the exact quotient by integer long division (the remainder stays below the 16-bit denominator), andBufHalfFromFloat(to nearest even, or toward zero for FLOAT formats) uses integer operations only, with nodoubleand nof32tof16(Intel UHD has no FP64, andf32tof16rounding is driver-defined).BufNarrowandBufWidensit on top of #150'sBufDecodeandBufEncode.BufFieldnow copies a 16-bit FLOAT field, a path #150 could not reach. Only the halves a load fills are written.Verification
Branch rebased on main
e921268(head2d2a7a7). Tests were run on the same tree rebased on9a06443;e921268only adds launcher/docs changes.Oracle and test data
tests/test_rdna2_exec_format_d16.py(hand-computed values):0x7F800001→0x7C01, −0.0 and float32 subnormals; 32_FLOAT through the instruction gives the toward-zero half;structformate) for nearest even, and the largest float16 not above |x| for toward zero, each over 20,000 random float32 values and the subnormal range;fractions.Fraction, nearest float16 by exact distance), which also checks that only two UNORM16 and two SNORM16 values differ from narrowing the float32;tests/test_rdna2_exec_format.py:test_typed_buffer_instructions_count_in_coverageis back, as the review asked. It now requires all 32 typed-buffer names to run in the interpreter (14 32-bit and 18 d16), so the test fails if a d16 form stops executing.tests/test_rdna2_hlsl_format_d16.py(8 tests): interpreter vs GPU, byte for byte. Float special values and random bits through 32/32x4/16x4 FLOAT; UNORM/SNORM/SCALED/INT 8, 10 and 16-bit formats with the midpoint fields injected; DST_SEL and bounds; MTBUF with an INVALID V#; partial EXEC on loads (v8-v11 refilled before each load so kept halves are compared); stores with partial words (stride 1 and 2); wave64.test_typed_buffer_instructions_count_in_coveragefails because 18 names are not executable. I also mutated the HLSL: dropping ties-to-even fails 2 GPU tests, zeroing the kept half fails 7, and decoding UNORM/SNORM through the float32 again failstest_normalized_scaled_and_integer_formats_match[formats0](16-bit UNORM/SNORM; the GPU data holds the four separating values)._d16cases from #150's refusal test (they now run).Checklist
E_NOTIMPL), never a fake success.test_readme_sync.pychecks it).AI assistance: written with Claude Code (Claude Opus 5.5), reviewed and run on our hardware (RTX, WARP, Intel UHD).
🤖 Generated with Claude Code
Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-25T19:45:45Z.
Rebased again onto main
4f2cf5cafter #226 merged (README now 1,156/1,490, 78%); full suite 1376/1376/1374 passed on RTX/WARP/Intel.AI use: Claude Code (Claude Opus 5.5).
Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-25T21:03:07Z.
Thanks for the d16 forms.
test_typed_buffer_instructions_count_in_coveragefromtests/test_rdna2_exec_format.pyinstead of updating it. It was the only check that the typed buffer forms run in the interpreter. Please restore it with the d16 forms included, so a d16 form that stops executing fails a test.Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-25T21:45:34Z.
Follow-up after the review: (1)
test_typed_buffer_instructions_count_in_coverageis still deleted (maintests/test_rdna2_exec_format.py:174); please restore it with its assertion updated for the d16 forms. (2)rdna2_buffer_d16.py:29-32adds a new Leonida measurement citation ("Measured on an RX 6700 ... ubiquitarianism/leonida docs/shader_validation.md"); please remove it and mark unmeasured behaviour as assumed, or cite the AMD ISA. (3) Please rebase on main and recount the README RDNA 2 line withrdna2_exec.coverage()on the merged tree.Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-25T22:54:21Z.
Thanks. Updated and rebased on main
e921268(one commit,2d2a7a7):test_typed_buffer_instructions_count_in_coverageis back intests/test_rdna2_exec_format.py. It now requires all 32 typed-buffer names to run in the interpreter (14 32-bit and 18 d16), so a d16 form that stops executing fails it.0xFFAF/0xFFEF, 16_SNORM0x7FF7/0x8009) are pinned in an "assumed" test. The measurement request is akimfomin/PortBridge#85. One rule also changed in this pass: 32-bit FLOAT formats now narrow toward zero (65504 past the range, NaN payload 1 when its top bits are zero) instead of to nearest with infinity, matching what our SPIR-V path already does. That rule is also labelled assumed, in the same request.rdna2_exec.coverage()on the merged tree: 1,208 → 1,226 / 1,490 (82%) in the 9 READMEs. The test count stays 1400+ (1,481). #232 is still open, so this figure does not include it. Whichever PR lands second will be recomputed.Checks: full suite on the RTX 4060 (1463 passed, 17 skipped); d16 and format files on WARP (98 passed) and Intel UHD (98 passed); ruff clean.
AI use: Claude Code (Claude Opus 5.5).