feat(shader): implement image_load_pck and image_load_mip_pck with signed variants #557

Merged
adriadam10 merged 1 commit from upstream-pr/557 into main 2026-10-04 21:24:35 +00:00
adriadam10 commented 2026-10-04 20:33:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T20:33:22Z.


What

Implements the four packed MIMG loads that were missing from the decoder: image_load_pck, image_load_pck_sgn, image_load_mip_pck, image_load_mip_pck_sgn (gfx10 opcodes 2-5, numbers from llvm-mc -mcpu=gfx1013 -show-encoding).

Behaviour measured on HW

Measured with raw kernels on an RDNA2 iGPU (gfx1035), across 27 formats (8/16/32-bit, 2- and 4-component, unorm/snorm/uint/sint/float, 2_10_10_10, 10_10_10_2), dmask 0x1/0x2/0x3/0x4/0x5/0x8/0xa/0xe/0xf, at LOD 0:

  • No format conversion: the result is the raw texel. dmask bit i selects texel dword i (so dmask:0xa returns dwords 1 and 3). Dwords past the end of the texel read 0.
  • Texels narrower than 32 bits are zero-extended by _pck. _pck_sgn sign-extends them from the width of the whole texel (for example 8_8 0xa580 gives 0xffffa580). For texels of 32 bits or more, _sgn changes nothing.
  • The format's dst_sel is not applied.

Implementation

  • The decoder, opcode classifier and dispatch go through the existing imageLoad path. The mip forms take one more address component, as image_load_mip does. MemoryInfo::imagePacked marks the access, and dataSigned marks the _sgn forms.
  • ResourceTracker keeps a packed load as a separate image resource (ImageResource::packed). For that resource, ResourceMaterializer records the descriptor's format (packedFormat, part of the specialization and of the disk cache key). It throws unless the image is a direct sampled image (not storage, not a bindless table) with identity dst_sel. The view swizzle can't be undone in the shader.
  • PackedImageTexel (SPIR-V) rebuilds the texel bits from the fetched components using the existing format table: integer components bit-exact, unorm components as f * (2^b - 1) + 0.5 (b ≤ 16, the same recovery depthUnorm16 uses), 32-bit float components by bitcast. It places them at their bit offsets and applies the _sgn extension. Formats whose bits can't be recovered exactly from the view throw: snorm (-128 and -127 both read as -1.0), f16, srgb, scaled, packed bitfields, depth-bits planes and conversion formats.

Stores (image_store_pck, image_store_mip_pck) are left as they were (they still throw) for a follow-up.

Tested

Linux (CachyOS), RADV (Mesa 26.2) + lavapipe, and CI's lavapipe (Mesa 25.2.8), cold: 0 s.

  • New agc_driver_image_load_packed_tests (tests/execution/ImageLoadPacked.cpp): 11 formats (8/16 unorm, 16 sint, 8_8 unorm, 32 float, 16_16 sint, 8_8_8_8 unorm/sint, 32_32 uint, 16_16_16_16 unorm, 32_32_32_32 float), 32 lanes, two mip levels. It runs all four ops with dmask 0xf/0xa/0x4/0x3, and the mip forms read level 1 for half the lanes. Bytes are chosen so _sgn extends both ways. Float texels have no NaN or denormal bits. The expected values come from the texel bytes, using the model above that matched the hardware. It also checks that 8_8_8_8_SNORM and a swizzled descriptor are refused.
  • The test fails without each part of the change (7 mutations, RADV and lavapipe): no sign extension, every component in dword 0, unorm not rescaled, packed read as a plain image_load, mip forms ignoring the LOD, swizzle check removed, snorm accepted.
  • Full Release ctest: everything passes except agc_driver_pixel_helper_lanes, which fails on local RADV on main too (since #305).
  • 8_SINT (format 6) is not in the test: the driver does not support it as a guest texture format yet.

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:4737408272 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/557). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-04T20:33:22Z. --- ### What Implements the four packed MIMG loads that were missing from the decoder: `image_load_pck`, `image_load_pck_sgn`, `image_load_mip_pck`, `image_load_mip_pck_sgn` (gfx10 opcodes 2-5, numbers from `llvm-mc -mcpu=gfx1013 -show-encoding`). #### Behaviour measured on HW Measured with raw kernels on an RDNA2 iGPU (gfx1035), across 27 formats (8/16/32-bit, 2- and 4-component, unorm/snorm/uint/sint/float, 2_10_10_10, 10_10_10_2), dmask 0x1/0x2/0x3/0x4/0x5/0x8/0xa/0xe/0xf, at LOD 0: - No format conversion: the result is the raw texel. dmask bit `i` selects texel dword `i` (so `dmask:0xa` returns dwords 1 and 3). Dwords past the end of the texel read 0. - Texels narrower than 32 bits are zero-extended by `_pck`. `_pck_sgn` sign-extends them from the width of the whole texel (for example `8_8` `0xa580` gives `0xffffa580`). For texels of 32 bits or more, `_sgn` changes nothing. - The format's dst_sel is not applied. #### Implementation - The decoder, opcode classifier and dispatch go through the existing `imageLoad` path. The mip forms take one more address component, as `image_load_mip` does. `MemoryInfo::imagePacked` marks the access, and `dataSigned` marks the `_sgn` forms. - `ResourceTracker` keeps a packed load as a separate image resource (`ImageResource::packed`). For that resource, `ResourceMaterializer` records the descriptor's format (`packedFormat`, part of the specialization and of the disk cache key). It throws unless the image is a direct sampled image (not storage, not a bindless table) with identity dst_sel. The view swizzle can't be undone in the shader. - `PackedImageTexel` (SPIR-V) rebuilds the texel bits from the fetched components using the existing format table: integer components bit-exact, unorm components as `f * (2^b - 1) + 0.5` (b ≤ 16, the same recovery `depthUnorm16` uses), 32-bit float components by bitcast. It places them at their bit offsets and applies the `_sgn` extension. Formats whose bits can't be recovered exactly from the view throw: snorm (-128 and -127 both read as -1.0), f16, srgb, scaled, packed bitfields, depth-bits planes and conversion formats. Stores (`image_store_pck`, `image_store_mip_pck`) are left as they were (they still throw) for a follow-up. ### Tested Linux (CachyOS), RADV (Mesa 26.2) + lavapipe, and CI's lavapipe (Mesa 25.2.8), cold: 0 s. - New `agc_driver_image_load_packed_tests` (`tests/execution/ImageLoadPacked.cpp`): 11 formats (8/16 unorm, 16 sint, 8_8 unorm, 32 float, 16_16 sint, 8_8_8_8 unorm/sint, 32_32 uint, 16_16_16_16 unorm, 32_32_32_32 float), 32 lanes, two mip levels. It runs all four ops with dmask 0xf/0xa/0x4/0x3, and the mip forms read level 1 for half the lanes. Bytes are chosen so `_sgn` extends both ways. Float texels have no NaN or denormal bits. The expected values come from the texel bytes, using the model above that matched the hardware. It also checks that 8_8_8_8_SNORM and a swizzled descriptor are refused. - The test fails without each part of the change (7 mutations, RADV and lavapipe): no sign extension, every component in dword 0, unorm not rescaled, packed read as a plain `image_load`, mip forms ignoring the LOD, swizzle check removed, snorm accepted. - Full Release ctest: everything passes except `agc_driver_pixel_helper_lanes`, which fails on local RADV on `main` too (since #305). - 8_SINT (format 6) is not in the test: the driver does not support it as a guest texture format yet. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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-04 20:33:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-04T20:33:43Z.


Progress report (d7f0c49 → e2ac1a6)

📈 GPU shader instructions: 80.62% (+0.35%, +4 implemented instructions)

✅ 4 implemented
Encoding Name
MIMG IMAGE_LOAD_MIP_PCK
MIMG IMAGE_LOAD_MIP_PCK_SGN
MIMG IMAGE_LOAD_PCK
MIMG IMAGE_LOAD_PCK_SGN
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5984119997 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/557#issuecomment-5984119997). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-04T20:33:43Z. --- <!-- progress-report --> ### Progress report (d7f0c49 → e2ac1a6) 📈 **GPU shader instructions**: 80.62% (+0.35%, +4 implemented instructions) <details> <summary>✅ 4 implemented</summary> | Encoding | Name | | - | - | | MIMG | `IMAGE_LOAD_MIP_PCK` | | MIMG | `IMAGE_LOAD_MIP_PCK_SGN` | | MIMG | `IMAGE_LOAD_PCK` | | MIMG | `IMAGE_LOAD_PCK_SGN` | </details>
github-actions[bot] commented 2026-10-04 21:11:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-04T21:11:22Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#524 core/shader/recompiler/RdnaDecoder/src/RdnaImageOpDecoder.cpp L296-298
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5984423842 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/557#issuecomment-5984423842). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-04T21:11:22Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #524 | `core/shader/recompiler/RdnaDecoder/src/RdnaImageOpDecoder.cpp` [L296-298](https://github.com/boykopovar/AnyPS5/blob/3403c80595f8ea9e0ee5a9d3b1d684d9e074b681/core/shader/recompiler/RdnaDecoder/src/RdnaImageOpDecoder.cpp#L296-L298) | | |
oneandonlydean commented 2026-10-04 21:19:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T21:19:41Z.


Thanks. I checked the encodings with llvm-mc for gfx1013: image_load_pck, image_load_pck_sgn, image_load_mip_pck and image_load_mip_pck_sgn are MIMG opcodes 2 to 5, and the test shader disassembles to exactly the six loads the result table names. LLVM rejects d16 on all four, and the decoder already refuses d16 for them, so that case throws as it should. The dmask handling matches your measurement: the raw texel dwords go through the existing writeImageComponents, so dmask bit i picks texel dword i, and dwords past the texel are 0.

I also checked the unorm recovery numerically: trunc(f * (2^b - 1) + 0.5) gives back every code for every width up to 16 bits, even when the view's float is off by up to 16 ulp. So it doesn't depend on how a driver rounds the conversion. Existing image paths are untouched: the tracker key only splits on packed, the materializer and the emitter only act when it is set, and the new specialization field is keyed and serialized everywhere depthUnorm16 is.

One optional addition: the float texels in the test have their exponent forced into a normal range, so no NaN payload or denormal goes through the sampled 32-bit float view on the load side. #561 covers both on the store side. A single texel with a NaN payload and a denormal in 32_FLOAT would show that the bitcast path keeps them on each driver. That's not a blocker.

This only adds encodings that main refused, so it's ready to merge from my side.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5984498036 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/557#issuecomment-5984498036). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T21:19:41Z. --- Thanks. I checked the encodings with llvm-mc for gfx1013: image_load_pck, image_load_pck_sgn, image_load_mip_pck and image_load_mip_pck_sgn are MIMG opcodes 2 to 5, and the test shader disassembles to exactly the six loads the result table names. LLVM rejects d16 on all four, and the decoder already refuses d16 for them, so that case throws as it should. The dmask handling matches your measurement: the raw texel dwords go through the existing writeImageComponents, so dmask bit i picks texel dword i, and dwords past the texel are 0. I also checked the unorm recovery numerically: `trunc(f * (2^b - 1) + 0.5)` gives back every code for every width up to 16 bits, even when the view's float is off by up to 16 ulp. So it doesn't depend on how a driver rounds the conversion. Existing image paths are untouched: the tracker key only splits on `packed`, the materializer and the emitter only act when it is set, and the new specialization field is keyed and serialized everywhere `depthUnorm16` is. One optional addition: the float texels in the test have their exponent forced into a normal range, so no NaN payload or denormal goes through the sampled 32-bit float view on the load side. #561 covers both on the store side. A single texel with a NaN payload and a denormal in 32_FLOAT would show that the bitcast path keeps them on each driver. That's not a blocker. This only adds encodings that main refused, so it's ready to merge from my side.
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!557
No description provided.