feat(shader): implement MIMG PCK2/PCK4 loads as measured on hardware #1809

Merged
adriadam10 merged 1 commit from upstream-pr/1809 into main 2026-10-08 21:05:03 +00:00
adriadam10 commented 2026-10-08 19:57:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T19:57:04Z.


What

Implements the four MIMG packed horizontal loads, image_load[_mip]_pck2/pck4 (opcodes 0x70, 0x71, 0x73, 0x74), as measured on hardware. The four stores (0x76, 0x77, 0x79, 0x7a) decode, so they count in the progress table, but throw at translation.

#1314 was closed after a measurement where these loads only returned zeros. That measurement used data masks 0x3 and 0xf. The loads only return data with DMASK 0x1, in a single dword. Measured on RDNA2 (gfx1035) with the hardware oracle, against plain image_load_pcks of the same texels on random memory, over x/y/mip edge rows and 9 widths:

measured
result one dword: the raw bits of the N texels (N = 2 for PCK2, 4 for PCK4) from x & ~(N-1) on row y, concatenated (element k at bit k * texel bits) and zero-extended
out of range 0 when the mip is past the last level, x+N-1 >= width, or y >= height
formats with data N texels fit in 32 bits: R8/R16/RG8 for PCK2, R8 for PCK4
R32, RG16, RGBA8, masks other than 0x1 zeros

0 mismatches over 2,160 rows per format (12,960 for mip variants) across 20 opcode/format combinations: 8-bit UNORM/SNORM/UINT/SINT, 16-bit UNORM/UINT/SINT/FLOAT and RG8 UNORM/UINT/SINT. It's the same aligned window and all-or-nothing bound as BY2/BY4 (#1793), so this reuses that path.

  • Decoder: data mask 0x1 only, 32-bit addresses and data, 2D, full descriptor. The mip variants take the LOD component.
  • Translation: imageBy with imagePacked, one dword.
  • Materializer: direct, identity-swizzled 2D UNORM/UINT/SINT R8 (PCK4), R8/R16/RG8 (PCK2). SNORM and 16-bit FLOAT were measured, but PackedImageTexel can't rebuild their bits from the view, so they throw. Packed image modes whose texels can't fit are not generated.
  • Emitter (EmitByReadOp): concatenates PackedImageTexel of each aligned texel into one dword, zero when out of range.
  • Stores: not measured. Opcode 0x76 on 32_32_32_32_FLOAT hung the GPU during #1314, so they throw at translation.
  • TechnicalDebt line next to the BY2/BY4 entry.

Tested

Linux (CachyOS), on current main. agc_driver_image_pck_n passes on RADV (gfx1035) and CI's lavapipe (Mesa 25.2.8): PCK2 R8/R16/RG8 and PCK4 R8, with and without mip, 32 lanes per run with x near both edges, x ≥ width, x = -1 and 2^31, y = height and -1, and mip = level count. It also checks the store opcodes, wider formats and non-identity swizzle throw. image_pck_n checks decode, every refused mask and translation. Negative checks: dropping the x alignment fails at x 5, dropping the bound fails at x 60 (width 61), and not shifting element k fails at x 0. Full ctest: 490/490.

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: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4792092196 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1809). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T19:57:04Z. --- ### What Implements the four MIMG packed horizontal loads, `image_load[_mip]_pck2/pck4` (opcodes 0x70, 0x71, 0x73, 0x74), as measured on hardware. The four stores (0x76, 0x77, 0x79, 0x7a) decode, so they count in the progress table, but throw at translation. #1314 was closed after a measurement where these loads only returned zeros. That measurement used data masks 0x3 and 0xf. The loads only return data with **DMASK 0x1**, in a single dword. Measured on RDNA2 (gfx1035) with the [hardware oracle](docs/dev/HW_ORACLE.md), against plain `image_load_pck`s of the same texels on random memory, over x/y/mip edge rows and 9 widths: | | measured | |---|---| | result | one dword: the raw bits of the N texels (N = 2 for PCK2, 4 for PCK4) from `x & ~(N-1)` on row y, concatenated (element k at bit `k * texel bits`) and zero-extended | | out of range | 0 when the mip is past the last level, `x+N-1 >= width`, or `y >= height` | | formats with data | N texels fit in 32 bits: R8/R16/RG8 for PCK2, R8 for PCK4 | | R32, RG16, RGBA8, masks other than 0x1 | zeros | 0 mismatches over 2,160 rows per format (12,960 for mip variants) across 20 opcode/format combinations: 8-bit UNORM/SNORM/UINT/SINT, 16-bit UNORM/UINT/SINT/FLOAT and RG8 UNORM/UINT/SINT. It's the same aligned window and all-or-nothing bound as BY2/BY4 (#1793), so this reuses that path. - Decoder: data mask 0x1 only, 32-bit addresses and data, 2D, full descriptor. The mip variants take the LOD component. - Translation: `imageBy` with `imagePacked`, one dword. - Materializer: direct, identity-swizzled 2D UNORM/UINT/SINT R8 (PCK4), R8/R16/RG8 (PCK2). SNORM and 16-bit FLOAT were measured, but `PackedImageTexel` can't rebuild their bits from the view, so they throw. Packed image modes whose texels can't fit are not generated. - Emitter (`EmitByReadOp`): concatenates `PackedImageTexel` of each aligned texel into one dword, zero when out of range. - Stores: not measured. Opcode 0x76 on 32_32_32_32_FLOAT hung the GPU during #1314, so they throw at translation. - TechnicalDebt line next to the BY2/BY4 entry. ### Tested Linux (CachyOS), on current `main`. `agc_driver_image_pck_n` passes on RADV (gfx1035) and CI's lavapipe (Mesa 25.2.8): PCK2 R8/R16/RG8 and PCK4 R8, with and without mip, 32 lanes per run with x near both edges, x ≥ width, x = -1 and 2^31, y = height and -1, and mip = level count. It also checks the store opcodes, wider formats and non-identity swizzle throw. `image_pck_n` checks decode, every refused mask and translation. Negative checks: dropping the x alignment fails at `x 5`, dropping the bound fails at `x 60` (width 61), and not shifting element k fails at `x 0`. Full ctest: 490/490. ### 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: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-08 21:28:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T21:28:14Z.


Progress report (4b6ab6b → 57d4be3)

📈 GPU shader instructions: 99.74% (+0.68%, +8 implemented instructions)

✅ 8 implemented
Encoding Name
MIMG IMAGE_LOAD_MIP_PCK2
MIMG IMAGE_LOAD_MIP_PCK4
MIMG IMAGE_LOAD_PCK2
MIMG IMAGE_LOAD_PCK4
MIMG IMAGE_STORE_MIP_PCK2
MIMG IMAGE_STORE_MIP_PCK4
MIMG IMAGE_STORE_PCK2
MIMG IMAGE_STORE_PCK4
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6069393074 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1809#issuecomment-6069393074). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T21:28:14Z. --- <!-- progress-report --> ### Progress report (4b6ab6b → 57d4be3) 📈 **GPU shader instructions**: 99.74% (+0.68%, +8 implemented instructions) <details> <summary>✅ 8 implemented</summary> | Encoding | Name | | - | - | | MIMG | `IMAGE_LOAD_MIP_PCK2` | | MIMG | `IMAGE_LOAD_MIP_PCK4` | | MIMG | `IMAGE_LOAD_PCK2` | | MIMG | `IMAGE_LOAD_PCK4` | | MIMG | `IMAGE_STORE_MIP_PCK2` | | MIMG | `IMAGE_STORE_MIP_PCK4` | | MIMG | `IMAGE_STORE_PCK2` | | MIMG | `IMAGE_STORE_PCK4` | </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!1809
No description provided.