feat(shader): implement image_gather4h_pck end to end #1701
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1701"
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 pandather on 2026-10-08T17:01:18Z.
What
Decodes the two packed horizontal gathers from the AMD machine-readable ISA specs —
IMAGE_GATHER4H_PCK(MIMG opcode 98 = 0x62) andIMAGE_GATHER8H_PCK(opcode 99 = 0x63) — implements gather4h_pck fully through translation, the SPIR-V backend and a GPU execution test measured against RDNA2 hardware, and documents gather8h_pck as a desktop null-op. Shader instructions: 1143/1166 -> 1145/1166 decoded; gather4h_pck additionally implemented (the progress table counts implementation separately once the op reaches titles).No open PR covers these two opcodes: #1314 (packed load/store
pck2/pck4, a different opcode family) was closed without merging, and #1053 maps other gather variants. The branch rebases onto currentmainwith no conflicts in the decoder (the only conflict during rebase was the TechnicalDebt.md tail, both sides appending entries).amdgpu_isa_rdna1.xml/amdgpu_isa_rdna2.xml. The decoder accepts multi-bit DMASKs for these two only and sizes the data span aspopcount(dmask)— measured on gfx1031 with sentinel-prefilled destination registers: exactlypopcount(dmask)consecutive VGPRs are written from vdst ascending, unlike gather4h which always writes four components. A zero DMASK is rejected at decode (measured: the instruction still executes and writes a single zero dword, but every real compiler emission uses a non-zero mask; rejecting matches the other MIMG mask rules).floor(u*width-0.5)+{-1,0,+1,+2}clamped to[0,width); the row isfloor(v*height), negative rows clamp to 0 and rows past the height read zeros; the raw bits of the window texels are concatenated into a little-endian bitstream (texel k at bit offsetk*texelBits, components little-endian); output register j — the j-th set DMASK bit in ascending order — receives stream word j, zero past the end of the stream. Formats with more than 32 bits per texel write zeros (hardware limit; measured for RGBA16/RGBA32). The window is clamped regardless of the sampler addressing mode (wrap and mirror measured identical to clamp on the validated normalized-sampler recipe). The anchor rule matches the repo's existing PS5-validatedHorizontalOffsets(floor(x-0.5), offsets-1..+2), so no new convention is introduced.imageMemoryInfoFromInstruction; the SPIR-V emitter's newEmitPackedHorizontalGatherOpfetches each window texel with per-laneOpImageFetchand reassembles the bitstream with byte assembly, then selects stream word j into destination register j. D16 (lformat-packed 16-bit) data throws "packed horizontal gather with D16 data is not measured" — sub-32-bit packing was measured on hardware (R8 packs four texel dwords into vdst only; RG8 pairs) but the repo's resource model exposes those as distinct formats whose per-texel bit width needs its own emitter path, so it stays an explicit throw rather than a guess.popcount(dmask)registers. It decodes (so progress counts it) but throws at translation; implementing its eight-texel semantics would be an unverified guess on this hardware, and LLVM rejects the mnemonic on every RDNA1/RDNA2 target.Sources:
amdgpu_isa_rdna1.xml/amdgpu_isa_rdna2.xml, opcodes 98/99) cross-checked against LLVM's assembler base word for gfx1031 (image_gather4h v[16:19], v[4:5], s[0:7], s[8:11] dmask:0x1 dim:SQ_RSRC_IMG_2D->F1840108 00401004; PCK word0sF1880108/F18C0108).Tested
Oracle measurements: RDNA2 hardware (gfx1031, AMD RX 6700 XT) via SSH/HSA as described above. Test-runner side: Windows 11 on an RTX Blackwell Series GPU (driver 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7):
ninjaclean,agc_driver_image_sample_gather,agc_driver_image_packed_horizontal_gatherand the full suite report100% tests passed out of 458. Conventions check (tools/check_conventions.py) passes.agc_driver_image_sample_gather: checks both PCK gathers decode from hand-encoded words, multi-bit DMASKs are accepted withdataComponents == popcount(dmask), and zero DMASK is rejected.agc_driver_image_packed_horizontal_gather: GPU execution test through the recompiler and SPIR-V backend — a 16x4 RGBA8 linear image whose texel markers equal(texelIndex*4+channel+1) & 0xFF, 32 lanes covering interior anchors, both left-edge clamps, row clamping past the height (zero rows), and DMASKs 0x1/0x5/0xF selecting different stream words; all four output registers per lane are checked against the measured bitstream rule. The test passes on the Blackwell runner device, reproducing the gfx1031-measured semantics exactly.Not tested: no title or homebrew (no compiler in the toolchain emits these mnemonics; real PS5 shaders using them would come from GNM-proven games, not available here). Sub-32-bit-per-texel formats throw explicitly rather than being exercised. gather8h_pck behavior beyond desktop is unknown.
Checklist
main; no other open PR implements the same opcodes (#1314 and #1053 checked — different opcode families)imageGatherD16 throw, gather8h_pck translation throw); 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 adriadam10 on 2026-10-08T17:18:27Z.
Thanks, the measurements are solid. I pushed one commit on top (
fix(shader): fetch packed horizontal gather texels and cover edge coordinates) and rebased onmain, so it can go in:OpImageFetchat LOD 0 and packs it with the existingPackedImageTexel(theimage_load_pckpath), as the description says. The previous version sampled through the title's sampler withOpImageSampleExplicitLod, so a linear filter, LOD bias or min LOD in the S# could change the raw bits. It also duplicatedPackedImageTexel's exactness check and unorm rebuild.u * sizeis decoratedNoContraction, so a driver can't fuse it with the- 0.5into an FMA and move the anchor (#446).(k+0.5)/16and the float just below), negativeu,u > 1, negativev(clamps to row 0, which the old expected value got wrong), andv = 1.0and2.0(zeros). Before, it only ran DMASK 0xF with rows in[0, height). Only the firstpopcount(dmask)registers are compared.tfe/lweentry instead of the end of the section, and updated it to say the sampler state isn't used.Tested on the merge with
main: RADV (gfx1035) and CI's lavapipe (Mesa 25.2.8).agc_driver_image_packed_horizontal_gatherandimage_sample_gatherpass, and the full ctest passes. Negative check: moving the window by one texel fails atdmask 15 thread 0 register 2.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T17:18:47Z.
Progress report (
55e8959→028bea7)📈 GPU shader instructions: 98.37% (+0.17%, +2 implemented instructions)
✅ 2 implemented
IMAGE_GATHER4H_PCKIMAGE_GATHER8H_PCKImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T17:56:29Z.
Rebased on
mainafter #639. The new test needed raw bounds (OOB_SELECT3) in its buffer descriptors, as #639 did for the existing execution tests. Retested on the merge: packed horizontal gather on RADV and CI's lavapipe, full ctest 483/483, and the negative check still fails.