feat(shader): implement the D16 format buffer stores #331

Merged
adriadam10 merged 4 commits from upstream-pr/331 into main 2026-10-04 09:54:12 +00:00
adriadam10 commented 2026-10-02 06:35:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-02T06:35:42Z.


What

This adds the store half of the D16 formats. The loads were #329.

  • MUBUF: buffer_store_format_d16_{x,xy,xyz,xyzw} (0x84-0x87) and buffer_store_format_d16_hi_x (0x27).
  • MTBUF: tbuffer_store_format_d16_{x,xy,xyz,xyzw} (0x0c-0x0f).

Each component is a 16-bit half: two per VGPR, low half first, and _hi_x takes the high half.

Semantics measured on an RDNA2 GPU (2048 vectors × 15 stores, all matched by a Python model):

Component type Stored value
UNORM / SNORM / USCALED / SSCALED, 32-bit and 11/10-bit FLOAT the half as f16, widened exactly to f32, then encoded like a 32-bit formatted store (#330)
16-bit FLOAT the half, unchanged
UINT the half zero-extended, then saturated (0x3c00 → 0xff in 8_UINT, 0x00003c00 in 32_UINT)
SINT the half sign-extended, then saturated (0xbc00 → 0x80 in 8_SINT, 0xffffbc00 in 32_SINT)

The whole element is written with missing components as 0, as in #330.

The f16 → f32 widening is done with integer ops: subnormals are normalized with FindUMsb and NaN payloads are kept. unpackHalf2x16 may flush f16 denormals or quiet NaNs, depending on the driver, and both are visible in the 11/10-bit float formats.

Test agc_driver_format_d16_store: 16 results × 32 lanes captured on the RDNA2 GPU. It covers every component type above, f16 specials (±inf, NaN 0x7e00/0x7c01, subnormals 0x0001/0x8001, 65504) in both halves, the xy/xyz/xyzw packing with zero fill, and _hi_x through the descriptor's format.

Tested

Linux, full ctest (102) passes.

  • RADV (Radeon 660M) and lavapipe: the test passes.
  • Treating the half as f32 bits instead of converting it: 8unorm is 0xaaaaaa00, expected 0xaaaaaaff.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #251 (test harness), #319 → #329 → #330 (D16 loads, store encoding); review only the last commit
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4713467388 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/331). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-02T06:35:42Z. --- ### What This adds the store half of the D16 formats. The loads were #329. - MUBUF: `buffer_store_format_d16_{x,xy,xyz,xyzw}` (0x84-0x87) and `buffer_store_format_d16_hi_x` (0x27). - MTBUF: `tbuffer_store_format_d16_{x,xy,xyz,xyzw}` (0x0c-0x0f). Each component is a 16-bit half: two per VGPR, low half first, and `_hi_x` takes the high half. Semantics measured on an RDNA2 GPU (2048 vectors × 15 stores, all matched by a Python model): | Component type | Stored value | |---|---| | UNORM / SNORM / USCALED / SSCALED, 32-bit and 11/10-bit FLOAT | the half as **f16, widened exactly to f32**, then encoded like a 32-bit formatted store (#330) | | 16-bit FLOAT | the half, unchanged | | UINT | the half zero-extended, then saturated (`0x3c00` → `0xff` in `8_UINT`, `0x00003c00` in `32_UINT`) | | SINT | the half sign-extended, then saturated (`0xbc00` → `0x80` in `8_SINT`, `0xffffbc00` in `32_SINT`) | The whole element is written with missing components as 0, as in #330. The f16 → f32 widening is done with integer ops: subnormals are normalized with `FindUMsb` and NaN payloads are kept. `unpackHalf2x16` may flush f16 denormals or quiet NaNs, depending on the driver, and both are visible in the 11/10-bit float formats. Test `agc_driver_format_d16_store`: 16 results × 32 lanes **captured on the RDNA2 GPU**. It covers every component type above, f16 specials (±inf, NaN `0x7e00`/`0x7c01`, subnormals `0x0001`/`0x8001`, 65504) in both halves, the `xy`/`xyz`/`xyzw` packing with zero fill, and `_hi_x` through the descriptor's format. ### Tested Linux, full ctest (102) passes. - RADV (Radeon 660M) and lavapipe: the test passes. - Treating the half as f32 bits instead of converting it: `8unorm is 0xaaaaaa00, expected 0xaaaaaaff`. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #251 (test harness), #319 → #329 → #330 (D16 loads, store encoding); review only the last commit - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-02 06:36:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-02T06:36:03Z.


Progress report (d3ec1f1 → b29fe00)

📈 GPU shader instructions: 75.73% (+4.72%, +55 implemented instructions)

✅ 55 implemented
Encoding Name
DS DS_READ_I8_D16
DS DS_READ_I8_D16_HI
DS DS_READ_U8_D16
DS DS_READ_U8_D16_HI
DS DS_WRITE_B8_D16_HI
FLAT FLAT_LOAD_SBYTE_D16
FLAT FLAT_LOAD_SBYTE_D16_HI
FLAT FLAT_LOAD_SHORT_D16
FLAT FLAT_LOAD_SHORT_D16_HI
FLAT FLAT_LOAD_UBYTE_D16
FLAT FLAT_LOAD_UBYTE_D16_HI
FLAT FLAT_STORE_BYTE_D16_HI
FLAT FLAT_STORE_SHORT_D16_HI
GLOBAL GLOBAL_LOAD_SBYTE_D16
GLOBAL GLOBAL_LOAD_SBYTE_D16_HI
GLOBAL GLOBAL_LOAD_SHORT_D16
GLOBAL GLOBAL_LOAD_SHORT_D16_HI
GLOBAL GLOBAL_LOAD_UBYTE_D16
GLOBAL GLOBAL_LOAD_UBYTE_D16_HI
GLOBAL GLOBAL_STORE_BYTE_D16_HI
GLOBAL GLOBAL_STORE_SHORT_D16_HI
MTBUF TBUFFER_LOAD_FORMAT_D16_X
MTBUF TBUFFER_LOAD_FORMAT_D16_XY
MTBUF TBUFFER_LOAD_FORMAT_D16_XYZ
MTBUF TBUFFER_LOAD_FORMAT_D16_XYZW
MTBUF TBUFFER_STORE_FORMAT_D16_X
MTBUF TBUFFER_STORE_FORMAT_D16_XY
MTBUF TBUFFER_STORE_FORMAT_D16_XYZ
MTBUF TBUFFER_STORE_FORMAT_D16_XYZW
MUBUF BUFFER_LOAD_FORMAT_D16_HI_X
MUBUF BUFFER_LOAD_FORMAT_D16_X
MUBUF BUFFER_LOAD_FORMAT_D16_XY
MUBUF BUFFER_LOAD_FORMAT_D16_XYZ
MUBUF BUFFER_LOAD_FORMAT_D16_XYZW
MUBUF BUFFER_LOAD_SBYTE_D16
MUBUF BUFFER_LOAD_SBYTE_D16_HI
MUBUF BUFFER_LOAD_SHORT_D16
MUBUF BUFFER_LOAD_SHORT_D16_HI
MUBUF BUFFER_LOAD_UBYTE_D16
MUBUF BUFFER_LOAD_UBYTE_D16_HI
MUBUF BUFFER_STORE_BYTE_D16_HI
MUBUF BUFFER_STORE_FORMAT_D16_HI_X
MUBUF BUFFER_STORE_FORMAT_D16_X
MUBUF BUFFER_STORE_FORMAT_D16_XY
MUBUF BUFFER_STORE_FORMAT_D16_XYZ
MUBUF BUFFER_STORE_FORMAT_D16_XYZW
MUBUF BUFFER_STORE_SHORT_D16_HI
SCRATCH SCRATCH_LOAD_SBYTE_D16
SCRATCH SCRATCH_LOAD_SBYTE_D16_HI
SCRATCH SCRATCH_LOAD_SHORT_D16
SCRATCH SCRATCH_LOAD_SHORT_D16_HI
SCRATCH SCRATCH_LOAD_UBYTE_D16
SCRATCH SCRATCH_LOAD_UBYTE_D16_HI
SCRATCH SCRATCH_STORE_BYTE_D16_HI
SCRATCH SCRATCH_STORE_SHORT_D16_HI
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5946806821 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/331#issuecomment-5946806821). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-02T06:36:03Z. --- <!-- progress-report --> ### Progress report (d3ec1f1 → b29fe00) 📈 **GPU shader instructions**: 75.73% (+4.72%, +55 implemented instructions) <details> <summary>✅ 55 implemented</summary> | Encoding | Name | | - | - | | DS | `DS_READ_I8_D16` | | DS | `DS_READ_I8_D16_HI` | | DS | `DS_READ_U8_D16` | | DS | `DS_READ_U8_D16_HI` | | DS | `DS_WRITE_B8_D16_HI` | | FLAT | `FLAT_LOAD_SBYTE_D16` | | FLAT | `FLAT_LOAD_SBYTE_D16_HI` | | FLAT | `FLAT_LOAD_SHORT_D16` | | FLAT | `FLAT_LOAD_SHORT_D16_HI` | | FLAT | `FLAT_LOAD_UBYTE_D16` | | FLAT | `FLAT_LOAD_UBYTE_D16_HI` | | FLAT | `FLAT_STORE_BYTE_D16_HI` | | FLAT | `FLAT_STORE_SHORT_D16_HI` | | GLOBAL | `GLOBAL_LOAD_SBYTE_D16` | | GLOBAL | `GLOBAL_LOAD_SBYTE_D16_HI` | | GLOBAL | `GLOBAL_LOAD_SHORT_D16` | | GLOBAL | `GLOBAL_LOAD_SHORT_D16_HI` | | GLOBAL | `GLOBAL_LOAD_UBYTE_D16` | | GLOBAL | `GLOBAL_LOAD_UBYTE_D16_HI` | | GLOBAL | `GLOBAL_STORE_BYTE_D16_HI` | | GLOBAL | `GLOBAL_STORE_SHORT_D16_HI` | | MTBUF | `TBUFFER_LOAD_FORMAT_D16_X` | | MTBUF | `TBUFFER_LOAD_FORMAT_D16_XY` | | MTBUF | `TBUFFER_LOAD_FORMAT_D16_XYZ` | | MTBUF | `TBUFFER_LOAD_FORMAT_D16_XYZW` | | MTBUF | `TBUFFER_STORE_FORMAT_D16_X` | | MTBUF | `TBUFFER_STORE_FORMAT_D16_XY` | | MTBUF | `TBUFFER_STORE_FORMAT_D16_XYZ` | | MTBUF | `TBUFFER_STORE_FORMAT_D16_XYZW` | | MUBUF | `BUFFER_LOAD_FORMAT_D16_HI_X` | | MUBUF | `BUFFER_LOAD_FORMAT_D16_X` | | MUBUF | `BUFFER_LOAD_FORMAT_D16_XY` | | MUBUF | `BUFFER_LOAD_FORMAT_D16_XYZ` | | MUBUF | `BUFFER_LOAD_FORMAT_D16_XYZW` | | MUBUF | `BUFFER_LOAD_SBYTE_D16` | | MUBUF | `BUFFER_LOAD_SBYTE_D16_HI` | | MUBUF | `BUFFER_LOAD_SHORT_D16` | | MUBUF | `BUFFER_LOAD_SHORT_D16_HI` | | MUBUF | `BUFFER_LOAD_UBYTE_D16` | | MUBUF | `BUFFER_LOAD_UBYTE_D16_HI` | | MUBUF | `BUFFER_STORE_BYTE_D16_HI` | | MUBUF | `BUFFER_STORE_FORMAT_D16_HI_X` | | MUBUF | `BUFFER_STORE_FORMAT_D16_X` | | MUBUF | `BUFFER_STORE_FORMAT_D16_XY` | | MUBUF | `BUFFER_STORE_FORMAT_D16_XYZ` | | MUBUF | `BUFFER_STORE_FORMAT_D16_XYZW` | | MUBUF | `BUFFER_STORE_SHORT_D16_HI` | | SCRATCH | `SCRATCH_LOAD_SBYTE_D16` | | SCRATCH | `SCRATCH_LOAD_SBYTE_D16_HI` | | SCRATCH | `SCRATCH_LOAD_SHORT_D16` | | SCRATCH | `SCRATCH_LOAD_SHORT_D16_HI` | | SCRATCH | `SCRATCH_LOAD_UBYTE_D16` | | SCRATCH | `SCRATCH_LOAD_UBYTE_D16_HI` | | SCRATCH | `SCRATCH_STORE_BYTE_D16_HI` | | SCRATCH | `SCRATCH_STORE_SHORT_D16_HI` | </details>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!331
No description provided.