feat(shader): implement the D16 format buffer loads #329
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/329"
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 boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-02T06:23:06Z.
What
Nine D16 format loads were rejected by the decoder:
buffer_load_format_d16_{x,xy,xyz,xyzw}(0x80-0x83) andbuffer_load_format_d16_hi_x(0x26).tbuffer_load_format_d16_{x,xy,xyz,xyzw}(0x08-0x0b).The ISA sweep only covered MUBUF opcodes below 0x80, which is why it missed the first four. They load a formatted element like the 32-bit forms, convert each component to 16 bits, and pack two per VGPR.
Semantics measured on an RDNA2 GPU (ROCm HSA, raw kernels; 3344 vectors per format, all matched by a Python model):
Packing:
_xwrites the low half and keeps the high half._hi_xwrites the high half and keeps the low half._xyand_xyzwoverwrite their registers._xyzkeeps the upper half of its second register.0x3c00) for non-integer formats and 1 for UINT/SINT.Implementation:
MemoryInfo::d16marks the load.EmitD16FormatComponentinstead ofNormalizeFormatComponent. It uses integer ops only (q = (v << s) / Mwith the remainder for UNORM/SNORM, mantissa truncation for RTZ), so results don't depend on the driver's f32→f16 rounding.0xffaf). The test includes them._x/_hi_xreuse thed16Halfdestination selector from #319.D16 format stores are not part of this PR. The existing formatted stores don't convert to the format yet, and that will be a separate change.
Test
agc_driver_format_d16: 16 results × 32 lanes captured on the RDNA2 GPU. It covers every component type above, the double-rounding cases, f32 specials (±inf, NaN payloads, 65520, overflow and subnormal edges), every packing form including the preserved halves, and a descriptor built in the shader with swizzlex,0,1,1.Tested
Linux, full ctest (100) passes.
8unorm is 0xdead0000, expected 0xdead3c00. Without the f16 one constant:xyzw_hi is 0x3f800000, expected 0x3c003c00.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)d16Half); review only the last commitImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-02T06:23:29Z.
Progress report (
d3ec1f1→5c8c5d2)📈 GPU shader instructions: 74.96% (+3.95%, +46 implemented instructions)
✅ 46 implemented
DS_READ_I8_D16DS_READ_I8_D16_HIDS_READ_U8_D16DS_READ_U8_D16_HIDS_WRITE_B8_D16_HIFLAT_LOAD_SBYTE_D16FLAT_LOAD_SBYTE_D16_HIFLAT_LOAD_SHORT_D16FLAT_LOAD_SHORT_D16_HIFLAT_LOAD_UBYTE_D16FLAT_LOAD_UBYTE_D16_HIFLAT_STORE_BYTE_D16_HIFLAT_STORE_SHORT_D16_HIGLOBAL_LOAD_SBYTE_D16GLOBAL_LOAD_SBYTE_D16_HIGLOBAL_LOAD_SHORT_D16GLOBAL_LOAD_SHORT_D16_HIGLOBAL_LOAD_UBYTE_D16GLOBAL_LOAD_UBYTE_D16_HIGLOBAL_STORE_BYTE_D16_HIGLOBAL_STORE_SHORT_D16_HITBUFFER_LOAD_FORMAT_D16_XTBUFFER_LOAD_FORMAT_D16_XYTBUFFER_LOAD_FORMAT_D16_XYZTBUFFER_LOAD_FORMAT_D16_XYZWBUFFER_LOAD_FORMAT_D16_HI_XBUFFER_LOAD_FORMAT_D16_XBUFFER_LOAD_FORMAT_D16_XYBUFFER_LOAD_FORMAT_D16_XYZBUFFER_LOAD_FORMAT_D16_XYZWBUFFER_LOAD_SBYTE_D16BUFFER_LOAD_SBYTE_D16_HIBUFFER_LOAD_SHORT_D16BUFFER_LOAD_SHORT_D16_HIBUFFER_LOAD_UBYTE_D16BUFFER_LOAD_UBYTE_D16_HIBUFFER_STORE_BYTE_D16_HIBUFFER_STORE_SHORT_D16_HISCRATCH_LOAD_SBYTE_D16SCRATCH_LOAD_SBYTE_D16_HISCRATCH_LOAD_SHORT_D16SCRATCH_LOAD_SHORT_D16_HISCRATCH_LOAD_UBYTE_D16SCRATCH_LOAD_UBYTE_D16_HISCRATCH_STORE_BYTE_D16_HISCRATCH_STORE_SHORT_D16_HI