Skip to content

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

Closed
ebosido444-ai wants to merge 1 commit into
boykopovar:mainfrom
ebosido444-ai:feat/shader-mimg-pck2-pck4
Closed

ebosido444-ai wants to merge 1 commit into
boykopovar:mainfrom
ebosido444-ai:feat/shader-mimg-pck2-pck4

Conversation

@ebosido444-ai

Copy link
Copy Markdown
Contributor

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 fix(tools): stop counting IMAGE_*_PCK2/PCK4 as decoded instructions #1214.
  • In-tree base-PCK shape from feat(shader): implement image_load_pck and image_load_mip_pck with signed variants #557/feat(shader): implement image_store_pck and image_store_mip_pck #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). fix(tools): count packed MIMG variants as decoded shader instructions #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

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

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

@github-actions github-actions Bot added build shader core/shader docs agc libSceAgc* labels Oct 8, 2026
popcoder565 added a commit to popcoder565/AnyPS5 that referenced this pull request Oct 8, 2026
… shared lines

boykopovar#1372 adds its test after the vop1 decode tests and boykopovar#1314 its debt entry after s_setkill, the places where this branch added its own. The wave control decode test now precedes the vop1 decode tests and the s_sethalt entry follows sceRtcParseDateTime, so either pull request can merge first without a conflict.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
adriadam10 pushed a commit to popcoder565/AnyPS5 that referenced this pull request Oct 8, 2026
… shared lines

boykopovar#1372 adds its test after the vop1 decode tests and boykopovar#1314 its debt entry after s_setkill, the places where this branch added its own. The wave control decode test now precedes the vop1 decode tests and the s_sethalt entry follows sceRtcParseDateTime, so either pull request can merge first without a conflict.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adriadam10

Copy link
Copy Markdown
Collaborator

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.

@adriadam10 adriadam10 closed this Oct 8, 2026
@ebosido444-ai

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants