Repository navigation
feat(shader): implement image_gather4h_pck end to end - #1701
Merged
adriadam10 merged 3 commits intoOct 8, 2026
Merged
Conversation
This was referenced Oct 8, 2026
adriadam10
force-pushed
the
feat/shader-decode-gather-h-pck
branch
from
October 8, 2026 17:17
03af90a to
b89eb3c
Compare
Collaborator
|
Thanks, the measurements are solid. I pushed one commit on top (
Tested on the merge with |
9 tasks done
adriadam10
force-pushed
the
feat/shader-decode-gather-h-pck
branch
2 times, most recently
from
October 8, 2026 17:55
eb4cb7d to
7a5ffa3
Compare
Collaborator
This was referenced Oct 8, 2026
Decodes IMAGE_GATHER4H_PCK (MIMG opcode 98) and IMAGE_GATHER8H_PCK
(opcode 99), implements gather4h_pck through translation, the SPIR-V
backend and a GPU execution test, and documents gather8h_pck as a
desktop null-op.
Semantics were measured on gfx1031 hardware with hand-encoded MIMG
words (LLVM rejects the PCK gather mnemonics on every RDNA1/RDNA2
target). The measured rule for gather4h_pck: the four-texel horizontal
window is floor(u*width-0.5)+{-1,0,+1,+2} clamped to the width, the row
is floor(v*height) clamped, the raw bits of the window texels are
concatenated into a little-endian bitstream (texel k at bit offset
k*texelBits), and output register j - the j-th set DMASK bit in
ascending order - receives stream word j, zero past the end of the
stream. Exactly popcount(dmask) consecutive VGPRs are written from vdst
ascending; texels wider than 32 bits write zeros (hardware limit); rows
past the height read zeros; negative coordinates clamp to zero. The
window anchor matches the repo's existing PS5-validated HorizontalOffsets
rule, so this reuses the established convention.
The decoder accepts multi-bit DMASKs for these two opcodes only and
sizes their data span as popcount(dmask) (measured), unlike gather4h
which always writes four components. Translation carries the packed
flag through imageMemoryInfoFromInstruction; the SPIR-V emitter
reassembles the bitstream per lane with per-texel OpImageFetch and
byte assembly. D16 data throws until measured.
gather8h_pck never returns texel data on this hardware: across dmasks
0x1-0xFF including the upper nibble, RGBA8/RGBA16/RGBA32 formats, 1D/2D
and 3D descriptors, normalized and unnormalized sampling, sentinel-
prefilled destination registers confirm it only ever zero-fills
popcount(dmask) registers. It decodes but throws at translation.
The measured semantics and the gather8h_pck null-op are recorded in
docs/dev/TechnicalDebt.md.
…rdinates Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
adriadam10
force-pushed
the
feat/shader-decode-gather-h-pck
branch
from
October 8, 2026 18:43
7a5ffa3 to
028bea7
Compare
11 tasks done
12 tasks done
12 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 (feat(shader): implement the packed MIMG pck2 and pck4 variants #1314 and test(shader): add regression test for ImageGather4h and map packed gather variants #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)