feat(shader): implement the packed MIMG pck2 and pck4 variants #1314
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1314"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 threwunsupported MIMG opcodeat decode while #942'sOPCODE_VARIANTSaliases counted them as decoded via the base*_PCKopcodes.Sources (numbers and semantics, all generated from AMD's machine-readable ISA):
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_PCK4the same with 4 elements and a 32-bit element cap; theMIPforms 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/rdna2/opcodes.h(kImageLoadPck2Mimg = 112...kImageStoreMipPck4Mimg = 122) and tinygradautogen/amd/rdna2/enum.py(IMAGE_LOAD_PCK2 = 112 ... IMAGE_STORE_MIP_PCK4 = 122) agree with each other and with the tables quoted in #1214.image_load_pck/image_store_pck, semantics measured on RDNA2 hardware, gfx1035: raw texel dwords,dmaskbit i selects texel dword i), widened exactly as this family requires: the opcode, neverdmask, 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 likeimage_load_mip_pck;MemoryInfo::imagePackedmarks the access and the existingPackedImageTexel/PackedStoreTexelemission unpacks the packed format across the window dwords (shadPS4'svideo_corepacked-format unpacking is that same base path). #942 conflated the variant width withdmask; this PR separates them.Exact-or-throw (the #843 provenance rule): the one thing the ISA tables do not settle —
dmasksub-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/pck4stay accepted on multisampled dimensions, asimage_store_pckis).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.cpphaving no entries for 112–122.Tested
Windows 11, w64devkit g++ (GCC 15), standalone decode+translate driver following the
core/libs/testspattern (ImageMsaaLoad.cpp):Built clean,
out_pck.exeexited 0. The newimage_pck_variantsctest (core/libs/tests/ImagePckVariants.cpp, registered likeimage_msaa_load) checks for all eight opcodes: opcode/RdnaOpcode/IsImageOpcodemapping, the fixed 2-/4-dword widths (dataComponents,dataDwordCount), the extra address component on the mip forms,imagePacked/imageHasMip/dataDwords/dmaskin the emittedImageRead/ImageWriteMemoryInfo throughimageLoad/imageStore, and rejection of sub-windowdmask, 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."Progress
python3 tools/progress.py: shaders 1139/1166 (97.68%) before and after — unchanged, because #942'sOPCODE_VARIANTSaliases intools/progress.pyalready credit these eight ISA names to the base*_PCKenum entries (the counting bug #1214 fixes). With this PR the credit is real: the eight new enum names map 1:1 ontoIMAGE_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.pyis intentionally untouched here — one topic per PR.Checklist
main; no other open PR implements the same functions (all 275 open PR diffs scanned forPck2|Pck4|ImageLoadPck|112u|113u; the only hits aretools/progress.pycounting fixes in #1214/#1049/#1053 and unrelated binary constants)NotImplemented_nid_no_patch); the exact-or-throw line and its assumption are listed in TechnicalDebt marked "unverified on hardware".mdfiles or images added to the repository (only the test and the TechnicalDebt entry)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.
main)docs/dev/TechnicalDebt.mdL64-65docs/dev/TechnicalDebt.mdL64-65Imported 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:
8_UINT,16_UINT,32_UINT,8_8_8_8_UINTand32_32_32_32_FLOAT: every dword the dmask selects comes back 0, and the registers after it stay untouched.image_load_pckon the same texel with the same dmask returns the texel, for example0xefcaa580on32_UINT, where opcode 112 returns0x00000000.32_UINT: nothing is written, and the texel keeps its old value.image_store_pckoverwrites it. Opcode 118 on32_32_32_32_FLOAThung 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
maindoes 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.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_pckworking 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.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/pck4return one dword: the raw bits of the N texels fromx & ~(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