feat(shader): implement image_load_pck and image_load_mip_pck with signed variants #557
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/557"
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 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 fromllvm-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:
iselects texel dwordi(sodmask:0xareturns dwords 1 and 3). Dwords past the end of the texel read 0._pck._pck_sgnsign-extends them from the width of the whole texel (for example8_80xa580gives0xffffa580). For texels of 32 bits or more,_sgnchanges nothing.Implementation
imageLoadpath. The mip forms take one more address component, asimage_load_mipdoes.MemoryInfo::imagePackedmarks the access, anddataSignedmarks the_sgnforms.ResourceTrackerkeeps a packed load as a separate image resource (ImageResource::packed). For that resource,ResourceMaterializerrecords 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 asf * (2^b - 1) + 0.5(b ≤ 16, the same recoverydepthUnorm16uses), 32-bit float components by bitcast. It places them at their bit offsets and applies the_sgnextension. 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.
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_sgnextends 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.image_load, mip forms ignoring the LOD, swizzle check removed, snorm accepted.agc_driver_pixel_helper_lanes, which fails on local RADV onmaintoo (since #305).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)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
IMAGE_LOAD_MIP_PCKIMAGE_LOAD_MIP_PCK_SGNIMAGE_LOAD_PCKIMAGE_LOAD_PCK_SGNImported 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.
main)core/shader/recompiler/RdnaDecoder/src/RdnaImageOpDecoder.cppL296-298Imported 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 onpacked, the materializer and the emitter only act when it is set, and the new specialization field is keyed and serialized everywheredepthUnorm16is.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.