feat: d16 typed buffer loads and stores (buffer/tbuffer_*_format_d16_*) in the RDNA 2 interpreter and HLSL — 1,078/1,490 #223
No reviewers
Labels
No labels
accessibility
bloqué : binaire console
bug
chargeur
console-dll
cpu
documentation
duplicate
enhancement
good first issue
gpu
help wanted
invalid
performance
question
runtime-gdk
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LooperSalty--AnyXboxX!223
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/223/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?
@KainanP on GitHub · 2026-11-25 17:37 UTC · original
KainanP:feat/buffer-format-d16→main· +684 −59 · 17 files · 1 commits · closed without mergingChange
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 measured conversions.Interpreter coverage: 1,060 → 1,078 of 1,490 encodings (
rdna2_exec.coverage()). The README still said 1,046, so it now says 70% → 72% in all 9 languages, and the test count goes to 1200+ (1,250 collected).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:
0x3C00) for float, normalized and scaled formats and the integer 1 otherwise: #150's measured value, narrowed like any other component.Assumptions (not measured, stated in
emu/rdna2_buffer_d16.py)0x3BFEinstead of0x3BFD), 16_UNORM 65519 (0x3C00instead of0x3BFF) and 16_SNORM 32759 (0x3C00instead of0x3BFF). I checked every quotient c / (2^n − 1) for n = 1 to 16 exhaustively: only 4 differ, and the fourth (n = 14) matches no format. These three are pinned in the tests and are the cheapest hardware measurement that would settle the order._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 (MUBUF format read from the V#, NaN) reads zeros there.
HLSL
BufHalfFromFloatuses 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
Runtime built from this branch with VS 2022 Build Tools CMake (
ANYXBOXX_RUNTIME=<worktree>/runtime/build/bin).Oracle and test data
tests/test_rdna2_exec_format_d16.py(54 tests, hand-computed values):structformate) over 20,000 random float32 values and the subnormal range, plus every normalized field of widths 2, 8, 10, 11 and 16;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_every_typed_buffer_encoding_counts_in_coveragefails because 18 names are not executable. I also mutated the HLSL: dropping ties-to-even fails 2 GPU tests, and zeroing the kept half fails 7._d16cases from #150's refusal test and its "14 executable" coverage assertion, both superseded.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
The 18 encodings buffer_load/store_format_d16_{x,xy,xyz,xyzw,hi_x} and tbuffer_load/store_format_d16_{x,xy,xyz,xyzw} now run in the reference interpreter and translate to HLSL, on top of the 32-bit typed formats of #150. - Packing (RDNA 2 is packed d16): component i goes to VGPR VDATA + i/2, low half first; _d16_x and the third component of _d16_xyz write bits 15-0, _d16_hi_x bits 31-16, and the other half is kept. ISA section 8.1.2 (p. 56), 8.1.4 (p. 59), 8.1.6 (p. 64), 12.14 (p. 211, 215: "D0[15:0] = MEM[ADDR]", "D0[31:16] = MEM[ADDR]"); AMD RDNA 2 XML ("low/high 16 bits of a 32-bit vector register"); LLVM 20.1.8 FeatureUnpackedD16VMem only on GFX8. - Loads narrow the 32-bit result of the non-d16 load (section 8.1.4: "data returned from the texture unit is converted to 16 bits"): integer formats of 16 bits or less keep the low 16 bits; float, normalized and scaled values go float32 -> float16, round to nearest even, overflow to infinity, subnormals kept (assumed). 32-bit integer formats are refused by name (truncation or clamping is not documented), as is a float32 NaN whose top 10 payload bits are zero. - Stores widen each half to the value the non-d16 store takes (UINT zero-extended, SINT sign-extended, float16 -> float32 exact, 16-bit FLOAT copied), then reuse #150's measured saturation. UNORM/SNORM/SCALED stores stay refused. - HLSL uses integer operations only for the float16 conversion (no double: Intel UHD has no FP64). Interpreter coverage 1,060 -> 1,078 of 1,490 encodings (README 70% -> 72%, it still showed 1,046); test count 1200+. New tests in tests/test_rdna2_exec_format_d16.py (hand-computed values, Python's binary16 rounding as an independent oracle) and tests/test_rdna2_hlsl_format_d16.py (byte-for-byte GPU parity in wave32 and wave64). Co-Authored-By: Claude Opus 5.5 <[email protected]>@LooperSalty on GitHub · 2026-11-25 18:39 UTC · original
This PR now conflicts with main after the other merges (RDNA 2 interpreter/HLSL files). Please rebase on main and reopen. Thanks!
@KainanP on GitHub · 2026-11-25 18:59 UTC · original
Already measured on RDNA 2 hardware, no request needed: every UNORM16/SNORM16 value on gfx1031 gives the exact quotient rounded once to f16, not the f32 result narrowed, so assumption 1 is wrong for the pinned cases (16_UNORM 0xFFAF → 0x3BFD, 0xFFEF → 0x3BFF, 16_SNORM 0x7FF7 → 0x3BFF) and there is a fourth one, 16_SNORM 0x8009 → 0xBBFF; f16 denormals kept, buffer and tbuffer alike:
github.com/ubiquitarianism/leonida@9f9a7c5f30/docs/shader_validation.md (L1612-L1665)AI use: Claude Code (Claude Opus 5.5).
@KainanP on GitHub · 2026-11-25 19:40 UTC · original
Superseded by #230: rebased onto main
cf84f8das asked, with UNORM/SNORM d16 loads now rounding the exact quotient once, as measured on gfx1031 (0xFFAF, 0xFFEF, 0x7FF7, 0x8009); full suite 1314/1314/1312 passed on RTX/WARP/Intel.AI use: Claude Code (Claude Opus 5.5).
Pull request closed