feat(shader): implement image_store_pck and image_store_mip_pck #561

Merged
adriadam10 merged 2 commits from upstream-pr/561 into main 2026-10-04 21:24:51 +00:00
adriadam10 commented 2026-10-04 20:47:54 +00:00 (Migrated from github.com)

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


What

Implements the two packed MIMG stores: image_store_pck and image_store_mip_pck (gfx10 opcodes 0x0a and 0x0b, numbers from llvm-mc -mcpu=gfx1013 -show-encoding). They are the store side of #557, and this PR is stacked on it. Only the second commit is new.

Behaviour measured on HW

Measured with raw kernels on an RDNA2 iGPU (gfx1035). Each lane stored one texel, and the result was read back from texture memory with global_load ... glc dlc. Covered: 7 formats (8 uint, 16 sint, 8_8 unorm, 8_8_8_8 uint, 16_16_16_16 sint, 32_32_32 float, 32_32_32_32 float), both ops, dmask 0xf/0x1/0x2/0x5/0xa/0x8. A Python model matched all 2688 cells:

  • No format conversion. Texel dword i gets the next data register when dmask bit i is set, and 0 otherwise. The whole texel is always written, so dmask:0x2 on a 64-bit texel writes 0 and then v0. Bits past the texel width are dropped, and register dwords past the end of the texel are ignored.
  • dst_sel is ignored. A reversed swizzle gives the same bytes.
  • 96-bit formats (32_32_32) are not written at all.

Implementation

  • The decoder, opcode classifier and dispatch go through the existing imageStore path. The mip form takes one more address component, as image_store_mip does. Both forms set MemoryInfo::imagePacked, so ResourceTracker keeps them as a separate resource, as it does for the loads.
  • ResourceMaterializer now accepts packed accesses on storage images. Identity dst_sel is still required for sampled ones only, because the hardware ignores it on these stores.
  • The format checks that both directions share moved into PackedTexelFormat. PackedStoreTexel (SPIR-V) builds the texel dwords from dmask, extracts each component's bits at its offset, and writes them through the storage view. It only accepts formats whose bits go through that view unchanged: unsigned integer components, 32-bit float (bitcast), and the raw 32-bit signed integer storage case that already exists. Everything else throws:
    • Unorm/snorm/srgb: Vulkan's float to normalized conversion may round either way when the product isn't an exact integer.
    • f16: the NaN payload is not preserved.
    • Signed integers narrower than 32 bits: these storage images are already refused.
    • Packed bitfields, conversion formats, and 96-bit formats (the hardware writes nothing for these).

Tested

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

  • New agc_driver_image_store_packed_tests (tests/execution/ImageStorePacked.cpp). It covers 10 formats: 8/16 uint, 8_8 uint, 32 sint, 32 float, 16_16 uint, 8_8_8_8 uint, 32_32 uint, 16_16_16_16 uint and 32_32_32_32 float, with 32 lanes.
    • image_store_pck runs with dmask 0xf/0x5/0xa/0x8, one row each.
    • image_store_mip_pck (dmask 0xb) writes level 0 from even lanes and level 1 from odd lanes.
    • A reversed-swizzle descriptor is also tested.
    • The texture lives in a registered guest block. After the dispatch the test flushes the storage image and compares every texel of the surface, including texels that weren't written, against the model above.
    • The data includes a negative qNaN with a payload (0xff8e8900) and a denormal in a 32-bit float texel. Both pass bit-exact on the three drivers. Only OpBitcast and OpImageWrite touch them, with no float arithmetic.
    • It also checks that 8_8_8_8_UNORM and 32_32_32_FLOAT are refused.
  • The test fails without each part of the change (9 mutations, RADV and lavapipe):
    • packed store taken as a plain image_store
    • unselected dwords not zeroed
    • registers not packed by dmask
    • no field shift
    • no field mask
    • mip form ignoring the LOD
    • storage swizzle refused
    • unorm accepted
    • 96-bit accepted
  • Full Release ctest: everything passes except agc_driver_pixel_helper_lanes, which also fails on local RADV on main (since #305).

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: #557
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4737511480 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/561). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-04T20:47:54Z. --- ### What Implements the two packed MIMG stores: `image_store_pck` and `image_store_mip_pck` (gfx10 opcodes 0x0a and 0x0b, numbers from `llvm-mc -mcpu=gfx1013 -show-encoding`). They are the store side of #557, and this PR is stacked on it. Only the second commit is new. #### Behaviour measured on HW Measured with raw kernels on an RDNA2 iGPU (gfx1035). Each lane stored one texel, and the result was read back from texture memory with `global_load ... glc dlc`. Covered: 7 formats (8 uint, 16 sint, 8_8 unorm, 8_8_8_8 uint, 16_16_16_16 sint, 32_32_32 float, 32_32_32_32 float), both ops, dmask 0xf/0x1/0x2/0x5/0xa/0x8. A Python model matched all 2688 cells: - No format conversion. Texel dword `i` gets the next data register when dmask bit `i` is set, and **0 otherwise**. The whole texel is always written, so `dmask:0x2` on a 64-bit texel writes `0` and then `v0`. Bits past the texel width are dropped, and register dwords past the end of the texel are ignored. - dst_sel is ignored. A reversed swizzle gives the same bytes. - 96-bit formats (`32_32_32`) are not written at all. #### Implementation - The decoder, opcode classifier and dispatch go through the existing `imageStore` path. The mip form takes one more address component, as `image_store_mip` does. Both forms set `MemoryInfo::imagePacked`, so `ResourceTracker` keeps them as a separate resource, as it does for the loads. - `ResourceMaterializer` now accepts packed accesses on storage images. Identity dst_sel is still required for sampled ones only, because the hardware ignores it on these stores. - The format checks that both directions share moved into `PackedTexelFormat`. `PackedStoreTexel` (SPIR-V) builds the texel dwords from dmask, extracts each component's bits at its offset, and writes them through the storage view. It only accepts formats whose bits go through that view unchanged: unsigned integer components, 32-bit float (bitcast), and the raw 32-bit signed integer storage case that already exists. Everything else throws: - Unorm/snorm/srgb: Vulkan's float to normalized conversion may round either way when the product isn't an exact integer. - f16: the NaN payload is not preserved. - Signed integers narrower than 32 bits: these storage images are already refused. - Packed bitfields, conversion formats, and 96-bit formats (the hardware writes nothing for these). ### Tested Linux (CachyOS), RADV (Mesa 26.2) + lavapipe, and CI's lavapipe (Mesa 25.2.8), cold: 1 s. - New `agc_driver_image_store_packed_tests` (`tests/execution/ImageStorePacked.cpp`). It covers 10 formats: 8/16 uint, 8_8 uint, 32 sint, 32 float, 16_16 uint, 8_8_8_8 uint, 32_32 uint, 16_16_16_16 uint and 32_32_32_32 float, with 32 lanes. - `image_store_pck` runs with dmask 0xf/0x5/0xa/0x8, one row each. - `image_store_mip_pck` (dmask 0xb) writes level 0 from even lanes and level 1 from odd lanes. - A reversed-swizzle descriptor is also tested. - The texture lives in a registered guest block. After the dispatch the test flushes the storage image and compares every texel of the surface, including texels that weren't written, against the model above. - The data includes a negative qNaN with a payload (`0xff8e8900`) and a denormal in a 32-bit float texel. Both pass bit-exact on the three drivers. Only `OpBitcast` and `OpImageWrite` touch them, with no float arithmetic. - It also checks that 8_8_8_8_UNORM and 32_32_32_FLOAT are refused. - The test fails without each part of the change (9 mutations, RADV and lavapipe): - packed store taken as a plain `image_store` - unselected dwords not zeroed - registers not packed by dmask - no field shift - no field mask - mip form ignoring the LOD - storage swizzle refused - unorm accepted - 96-bit accepted - Full Release ctest: everything passes except `agc_driver_pixel_helper_lanes`, which also fails on local RADV on `main` (since #305). ### 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: #557 - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-04 20:48:14 +00:00 (Migrated from github.com)

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


Progress report (d7f0c49 → ef84d7b)

📈 GPU shader instructions: 80.79% (+0.52%, +6 implemented instructions)

✅ 6 implemented
Encoding Name
MIMG IMAGE_LOAD_MIP_PCK
MIMG IMAGE_LOAD_MIP_PCK_SGN
MIMG IMAGE_LOAD_PCK
MIMG IMAGE_LOAD_PCK_SGN
MIMG IMAGE_STORE_MIP_PCK
MIMG IMAGE_STORE_PCK
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5984236705 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/561#issuecomment-5984236705). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-04T20:48:14Z. --- <!-- progress-report --> ### Progress report (d7f0c49 → ef84d7b) 📈 **GPU shader instructions**: 80.79% (+0.52%, +6 implemented instructions) <details> <summary>✅ 6 implemented</summary> | Encoding | Name | | - | - | | MIMG | `IMAGE_LOAD_MIP_PCK` | | MIMG | `IMAGE_LOAD_MIP_PCK_SGN` | | MIMG | `IMAGE_LOAD_PCK` | | MIMG | `IMAGE_LOAD_PCK_SGN` | | MIMG | `IMAGE_STORE_MIP_PCK` | | MIMG | `IMAGE_STORE_PCK` | </details>
github-actions[bot] commented 2026-10-04 21:11:24 +00:00 (Migrated from github.com)

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


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:5984424127 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/561#issuecomment-5984424127). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-04T21:11:24Z. --- <!-- 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:46 +00:00 (Migrated from github.com)

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


Thanks. llvm-mc for gfx1013 gives 0x0a and 0x0b for image_store_pck and image_store_mip_pck, LLVM rejects d16 on both, and the decoder refuses d16 for them too. The data path matches your measurement: register DmaskComponentIndex(dmask, i) goes to texel dword i, unselected dwords are written as 0, and the whole texel is always written. I also checked that dropping the swizzle check for storage can't reach a packed load. ImageRead is always a sampled resource and ImageWrite always a storage one, so sampled packed loads still need an identity swizzle.

The accepted set looks right to me: only components whose bits go through the storage view unchanged, with a throw for fields that straddle a dword, normalized formats, f16, narrow signed formats and the 96-bit formats the hardware doesn't write. Existing stores take the same path as before.

Ready to merge from my side once #557 is in.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5984498764 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/561#issuecomment-5984498764). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T21:19:46Z. --- Thanks. llvm-mc for gfx1013 gives 0x0a and 0x0b for image_store_pck and image_store_mip_pck, LLVM rejects d16 on both, and the decoder refuses d16 for them too. The data path matches your measurement: register DmaskComponentIndex(dmask, i) goes to texel dword i, unselected dwords are written as 0, and the whole texel is always written. I also checked that dropping the swizzle check for storage can't reach a packed load. ImageRead is always a sampled resource and ImageWrite always a storage one, so sampled packed loads still need an identity swizzle. The accepted set looks right to me: only components whose bits go through the storage view unchanged, with a throw for fields that straddle a dword, normalized formats, f16, narrow signed formats and the 96-bit formats the hardware doesn't write. Existing stores take the same path as before. Ready to merge from my side once #557 is in.
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!561
No description provided.