feat(shader): implement the packed MIMG pck2 and pck4 variants #1314

Closed
ebosido444-ai wants to merge 1 commit from upstream-pr/1314 into main
ebosido444-ai commented 2026-10-07 23:22:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ebosido444-ai on 2026-10-07T23:22:10Z.


What

Implements the eight packed MIMG opcodes that #1214 identified as a hidden gap: image_load_pck2, image_load_pck4, image_load_mip_pck2, image_load_mip_pck4, image_store_pck2, image_store_pck4, image_store_mip_pck2, image_store_mip_pck4 (MIMG opcodes 112/113, 115/116, 118/119, 121/122). Until now each threw unsupported MIMG opcode at decode while #942's OPCODE_VARIANTS aliases counted them as decoded via the base *_PCK opcodes.

Sources (numbers and semantics, all generated from AMD's machine-readable ISA):

  • AMD amdgpu_isa_rdna2.xml (gpuopen.com/machine-readable-isa, schema 1.1.1): the opcode numbers and the descriptions, verbatim — IMAGE_LOAD_PCK2 "Load 2 horizontal elements from the largest miplevel in an image surface... 8- and 16-bit components are zero-extended. The format specified in the resource descriptor is ignored. Illegal for element sizes greater than 64 bits."; IMAGE_LOAD_PCK4 the same with 4 elements and a 32-bit element cap; the MIP forms take "a user-specified miplevel"; the stores write "already packed" texel data ("The texel data is already packed and the format specified in the resource descriptor is ignored").
  • Generated opcode constants: ROCm rocjitsu generated/rdna2/opcodes.h (kImageLoadPck2Mimg = 112 ... kImageStoreMipPck4Mimg = 122) and tinygrad autogen/amd/rdna2/enum.py (IMAGE_LOAD_PCK2 = 112 ... IMAGE_STORE_MIP_PCK4 = 122) agree with each other and with the tables quoted in #1214.
  • In-tree base-PCK shape from #557/#561 (image_load_pck/image_store_pck, semantics measured on RDNA2 hardware, gfx1035: raw texel dwords, dmask bit i selects texel dword i), widened exactly as this family requires: the opcode, never dmask, selects the variant and its fixed two-dword (dmask 0x3) or four-dword (dmask 0xf) packed window; the mip forms take one more address component like image_load_mip_pck; MemoryInfo::imagePacked marks the access and the existing PackedImageTexel/PackedStoreTexel emission unpacks the packed format across the window dwords (shadPS4's video_core packed-format unpacking is that same base path). #942 conflated the variant width with dmask; this PR separates them.

Exact-or-throw (the #843 provenance rule): the one thing the ISA tables do not settle — dmask sub-windows and the element-to-dword layout for elements above 32 bits — throws (MIMG pck2 and pck4 variants require a full data mask, RdnaImageOpDecoder.cpp) and is recorded in TechnicalDebt marked "unverified on hardware". Multisampled rejection and the D16 ban mirror the base PCK family exactly (image_store_pck2/pck4 stay accepted on multisampled dimensions, as image_store_pck is).

Compat payoff: shaders using packed-format 2-/4-element surface reads and writes now translate instead of failing at decode — the hidden eight-op gap #1214 traced to RdnaImageOpDecoder.cpp having no entries for 112–122.

Tested

Windows 11, w64devkit g++ (GCC 15), standalone decode+translate driver following the core/libs/tests pattern (ImageMsaaLoad.cpp):

g++ -std=c++20 -O1 -static -Icore/shader/recompiler/Translation/include -Icore/shader/recompiler/RdnaDecoder/include -Icore/shader/recompiler/IntermediateRepresentation/include -Icore/shader/recompiler/ControlFlow/include -Icore/shader/recompiler/Optimization/include -Icore/shader/recompiler -Icore/libs core/libs/tests/ImagePckVariants.cpp core/shader/recompiler/RdnaDecoder/src/*.cpp core/shader/recompiler/IntermediateRepresentation/src/*.cpp core/shader/recompiler/IntermediateRepresentation/src/IrBuilder/*.cpp core/shader/recompiler/ControlFlow/src/*.cpp core/shader/recompiler/Translation/src/*.cpp core/shader/recompiler/Translation/src/MemoryInstructions/*.cpp core/shader/recompiler/Translation/src/TranslationContext/*.cpp -o out_pck.exe

Built clean, out_pck.exe exited 0. The new image_pck_variants ctest (core/libs/tests/ImagePckVariants.cpp, registered like image_msaa_load) checks for all eight opcodes: opcode/RdnaOpcode/IsImageOpcode mapping, the fixed 2-/4-dword widths (dataComponents, dataDwordCount), the extra address component on the mip forms, imagePacked/imageHasMip/dataDwords/dmask in the emitted ImageRead/ImageWrite MemoryInfo through imageLoad/imageStore, and rejection of sub-window dmask, multisampled dimensions (for 112/113/115/116/121/122, mirroring the base family) and D16 (for all eight).

  • python3 tools/check_conventions.py --base origin/main — "All conventions checks passed."
  • No RDNA2 hardware on this machine: behaviour is verified against AMD's machine-readable ISA tables only and is recorded in TechnicalDebt as "unverified on hardware", per the CONTRIBUTING provenance rule.

Progress

python3 tools/progress.py: shaders 1139/1166 (97.68%) before and after — unchanged, because #942's OPCODE_VARIANTS aliases in tools/progress.py already credit these eight ISA names to the base *_PCK enum entries (the counting bug #1214 fixes). With this PR the credit is real: the eight new enum names map 1:1 onto IMAGE_LOAD_PCK2...IMAGE_STORE_MIP_PCK4, so after #1214 removes the four aliases its 1131/1166 baseline becomes 1139/1166 (+8 genuinely decoded ops). tools/progress.py is intentionally untouched here — one topic per PR.

Checklist

  • Based on current main; no other open PR implements the same functions (all 275 open PR diffs scanned for Pck2|Pck4|ImageLoadPck|112u|113u; the only hits are tools/progress.py counting fixes in #1214/#1049/#1053 and unrelated binary constants)
  • 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); the exact-or-throw line and its assumption are listed in TechnicalDebt marked "unverified on hardware"
  • No notes, investigation .md files or images added to the repository (only the test and the TechnicalDebt entry)
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none (complements #1214, whose alias removal this PR makes truthful)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4779674134 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1314). Originally posted by [ebosido444-ai](https://github.com/ebosido444-ai) on 2026-10-07T23:22:10Z. --- ### What Implements the eight packed MIMG opcodes that #1214 identified as a hidden gap: `image_load_pck2`, `image_load_pck4`, `image_load_mip_pck2`, `image_load_mip_pck4`, `image_store_pck2`, `image_store_pck4`, `image_store_mip_pck2`, `image_store_mip_pck4` (MIMG opcodes 112/113, 115/116, 118/119, 121/122). Until now each threw `unsupported MIMG opcode` at decode while #942's `OPCODE_VARIANTS` aliases counted them as decoded via the base `*_PCK` opcodes. Sources (numbers and semantics, all generated from AMD's machine-readable ISA): - AMD `amdgpu_isa_rdna2.xml` (gpuopen.com/machine-readable-isa, schema 1.1.1): the opcode numbers and the descriptions, verbatim — `IMAGE_LOAD_PCK2` "Load 2 horizontal elements from the largest miplevel in an image surface... 8- and 16-bit components are zero-extended. The format specified in the resource descriptor is ignored. Illegal for element sizes greater than 64 bits."; `IMAGE_LOAD_PCK4` the same with 4 elements and a 32-bit element cap; the `MIP` forms take "a user-specified miplevel"; the stores write "already packed" texel data ("The texel data is already packed and the format specified in the resource descriptor is ignored"). - Generated opcode constants: ROCm rocjitsu `generated/rdna2/opcodes.h` (`kImageLoadPck2Mimg = 112` ... `kImageStoreMipPck4Mimg = 122`) and tinygrad `autogen/amd/rdna2/enum.py` (`IMAGE_LOAD_PCK2 = 112 ... IMAGE_STORE_MIP_PCK4 = 122`) agree with each other and with the tables quoted in #1214. - In-tree base-PCK shape from #557/#561 (`image_load_pck`/`image_store_pck`, semantics measured on RDNA2 hardware, gfx1035: raw texel dwords, `dmask` bit *i* selects texel dword *i*), widened exactly as this family requires: the opcode, never `dmask`, selects the variant and its fixed two-dword (`dmask 0x3`) or four-dword (`dmask 0xf`) packed window; the mip forms take one more address component like `image_load_mip_pck`; `MemoryInfo::imagePacked` marks the access and the existing `PackedImageTexel`/`PackedStoreTexel` emission unpacks the packed format across the window dwords (shadPS4's `video_core` packed-format unpacking is that same base path). #942 conflated the variant width with `dmask`; this PR separates them. Exact-or-throw (the #843 provenance rule): the one thing the ISA tables do not settle — `dmask` sub-windows and the element-to-dword layout for elements above 32 bits — throws (`MIMG pck2 and pck4 variants require a full data mask`, `RdnaImageOpDecoder.cpp`) and is recorded in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md) marked "unverified on hardware". Multisampled rejection and the D16 ban mirror the base PCK family exactly (`image_store_pck2/pck4` stay accepted on multisampled dimensions, as `image_store_pck` is). Compat payoff: shaders using packed-format 2-/4-element surface reads and writes now translate instead of failing at decode — the hidden eight-op gap #1214 traced to `RdnaImageOpDecoder.cpp` having no entries for 112–122. ### Tested Windows 11, w64devkit g++ (GCC 15), standalone decode+translate driver following the `core/libs/tests` pattern (`ImageMsaaLoad.cpp`): ``` g++ -std=c++20 -O1 -static -Icore/shader/recompiler/Translation/include -Icore/shader/recompiler/RdnaDecoder/include -Icore/shader/recompiler/IntermediateRepresentation/include -Icore/shader/recompiler/ControlFlow/include -Icore/shader/recompiler/Optimization/include -Icore/shader/recompiler -Icore/libs core/libs/tests/ImagePckVariants.cpp core/shader/recompiler/RdnaDecoder/src/*.cpp core/shader/recompiler/IntermediateRepresentation/src/*.cpp core/shader/recompiler/IntermediateRepresentation/src/IrBuilder/*.cpp core/shader/recompiler/ControlFlow/src/*.cpp core/shader/recompiler/Translation/src/*.cpp core/shader/recompiler/Translation/src/MemoryInstructions/*.cpp core/shader/recompiler/Translation/src/TranslationContext/*.cpp -o out_pck.exe ``` Built clean, `out_pck.exe` exited 0. The new `image_pck_variants` ctest (`core/libs/tests/ImagePckVariants.cpp`, registered like `image_msaa_load`) checks for all eight opcodes: opcode/`RdnaOpcode`/`IsImageOpcode` mapping, the fixed 2-/4-dword widths (`dataComponents`, `dataDwordCount`), the extra address component on the mip forms, `imagePacked`/`imageHasMip`/`dataDwords`/`dmask` in the emitted `ImageRead`/`ImageWrite` MemoryInfo through `imageLoad`/`imageStore`, and rejection of sub-window `dmask`, multisampled dimensions (for 112/113/115/116/121/122, mirroring the base family) and D16 (for all eight). - `python3 tools/check_conventions.py --base origin/main` — "All conventions checks passed." - No RDNA2 hardware on this machine: behaviour is verified against AMD's machine-readable ISA tables only and is recorded in TechnicalDebt as "unverified on hardware", per the CONTRIBUTING provenance rule. ### Progress `python3 tools/progress.py`: shaders 1139/1166 (97.68%) before and after — unchanged, because #942's `OPCODE_VARIANTS` aliases in `tools/progress.py` already credit these eight ISA names to the base `*_PCK` enum entries (the counting bug #1214 fixes). With this PR the credit is real: the eight new enum names map 1:1 onto `IMAGE_LOAD_PCK2`...`IMAGE_STORE_MIP_PCK4`, so after #1214 removes the four aliases its 1131/1166 baseline becomes 1139/1166 (+8 genuinely decoded ops). `tools/progress.py` is intentionally untouched here — one topic per PR. ### 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 (all 275 open PR diffs scanned for `Pck2|Pck4|ImageLoadPck|112u|113u`; the only hits are `tools/progress.py` counting fixes in #1214/#1049/#1053 and unrelated binary constants) - [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`); the exact-or-throw line and its assumption are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md) marked "unverified on hardware" - [x] No notes, investigation `.md` files or images added to the repository (only the test and the TechnicalDebt entry) - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none (complements #1214, whose alias removal this PR makes truthful) - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-08 01:02:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T01:02:59Z.


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
#1398 docs/dev/TechnicalDebt.md L64-65
#1399 docs/dev/TechnicalDebt.md L64-65
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6050006098 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1314#issuecomment-6050006098). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T01:02:59Z. --- <!-- 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 | |---|---|---|---| | #1398 | `docs/dev/TechnicalDebt.md` [L64-65](https://github.com/boykopovar/AnyPS5/blob/084aeeb67aaff58b4ec51609f0f012e132a912a6/docs/dev/TechnicalDebt.md#L64-L65) | | | | #1399 | `docs/dev/TechnicalDebt.md` [L64-65](https://github.com/boykopovar/AnyPS5/blob/084aeeb67aaff58b4ec51609f0f012e132a912a6/docs/dev/TechnicalDebt.md#L64-L65) | | |
adriadam10 commented 2026-10-08 11:07:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T11:07:25Z.


I measured these opcodes on RDNA2 hardware with the HW oracle (gfx1035), encoded raw because LLVM rejects them for both gfx1013 and gfx1035:

  • Loads 112, 113, 115 and 116, with dmask 0x3 and 0xf, on 8_UINT, 16_UINT, 32_UINT, 8_8_8_8_UINT and 32_32_32_32_FLOAT: every dword the dmask selects comes back 0, and the registers after it stay untouched. image_load_pck on the same texel with the same dmask returns the texel, for example 0xefcaa580 on 32_UINT, where opcode 112 returns 0x00000000.
  • Stores 118, 119, 121 and 122 on 32_UINT: nothing is written, and the texel keeps its old value. image_store_pck overwrites it. Opcode 118 on 32_32_32_32_FLOAT hung the GPU.

On this hardware the ISA XML entries are not working packed loads and stores. The PR returns and writes texel data, which looks plausible but doesn't match the hardware, and the test only checks decode and the IR shape. With the measured behaviour, the right handling stays what main does now, throwing at decode, so nothing is left to merge. Closing for that reason. If a title's shader really uses one of these opcodes, please comment with the title ID and the instruction. We can measure that form, and gfx1013 differences would be worth knowing too.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6058521867 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1314#issuecomment-6058521867). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T11:07:25Z. --- I measured these opcodes on RDNA2 hardware with the HW oracle (gfx1035), encoded raw because LLVM rejects them for both gfx1013 and gfx1035: - Loads 112, 113, 115 and 116, with dmask 0x3 and 0xf, on `8_UINT`, `16_UINT`, `32_UINT`, `8_8_8_8_UINT` and `32_32_32_32_FLOAT`: every dword the dmask selects comes back **0**, and the registers after it stay untouched. `image_load_pck` on the same texel with the same dmask returns the texel, for example `0xefcaa580` on `32_UINT`, where opcode 112 returns `0x00000000`. - Stores 118, 119, 121 and 122 on `32_UINT`: **nothing is written**, and the texel keeps its old value. `image_store_pck` overwrites it. Opcode 118 on `32_32_32_32_FLOAT` hung the GPU. On this hardware the ISA XML entries are not working packed loads and stores. The PR returns and writes texel data, which looks plausible but doesn't match the hardware, and the test only checks decode and the IR shape. With the measured behaviour, the right handling stays what `main` does now, throwing at decode, so nothing is left to merge. Closing for that reason. If a title's shader really uses one of these opcodes, please comment with the title ID and the instruction. We can measure that form, and gfx1013 differences would be worth knowing too.
ebosido444-ai commented 2026-10-08 11:30:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ebosido444-ai on 2026-10-08T11:30:26Z.


Silicon settles it — accepting the close. The HW-oracle rows are exactly the class of evidence the #843 rule exists for: the generated ISA tables and our widening implied functional packed variants, and the hardware answers with zeros and unwritten texels (with image_load_pck working on the same texel as the control). LLVM refusing to encode them for gfx1013 and gfx1035 was the tell I should have weighted harder alongside the table triple-check. Since normal compiler output can't contain these opcodes and the silicon behaviour is a silent no-op, the decode-level implementation would make no shader run that didn't before — the #901 bar agrees with the close. No follow-up from me unless a title is shown reaching one of these rows.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6058887724 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1314#issuecomment-6058887724). Originally posted by [ebosido444-ai](https://github.com/ebosido444-ai) on 2026-10-08T11:30:26Z. --- Silicon settles it — accepting the close. The HW-oracle rows are exactly the class of evidence the #843 rule exists for: the generated ISA tables and our widening implied functional packed variants, and the hardware answers with zeros and unwritten texels (with `image_load_pck` working on the same texel as the control). LLVM refusing to encode them for gfx1013 and gfx1035 was the tell I should have weighted harder alongside the table triple-check. Since normal compiler output can't contain these opcodes and the silicon behaviour is a silent no-op, the decode-level implementation would make no shader run that didn't before — the #901 bar agrees with the close. No follow-up from me unless a title is shown reaching one of these rows.
adriadam10 commented 2026-10-08 19:57:15 +00:00 (Migrated from github.com)

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


Correction to my measurement above: the loads aren't no-ops. I only tried data masks 0x3 and 0xf. With DMASK 0x1, image_load[_mip]_pck2/pck4 return one dword: the raw bits of the N texels from x & ~(N-1), concatenated. They return 0 out of range, and data only when N texels fit in 32 bits (R8/R16/RG8 for PCK2, R8 for PCK4). 0 mismatches over 20 opcode/format combinations on gfx1035, details in #1793 (same window rule as BY2/BY4) and #1809, which implements the loads. The stores are still unmeasured and throw.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6067941989 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1314#issuecomment-6067941989). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T19:57:15Z. --- Correction to my measurement above: the loads aren't no-ops. I only tried data masks 0x3 and 0xf. With **DMASK 0x1**, `image_load[_mip]_pck2/pck4` return one dword: the raw bits of the N texels from `x & ~(N-1)`, concatenated. They return 0 out of range, and data only when N texels fit in 32 bits (R8/R16/RG8 for PCK2, R8 for PCK4). 0 mismatches over 20 opcode/format combinations on gfx1035, details in #1793 (same window rule as BY2/BY4) and #1809, which implements the loads. The stores are still unmeasured and throw.

Pull request closed

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!1314
No description provided.