Skip to content

feat(shader): implement MIMG PCK2/PCK4 stores as measured on hardware - #24142

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
giovannilentini:feat/shader-pck-stores
Nov 27, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
giovannilentini:feat/shader-pck-stores

Conversation

@giovannilentini

Copy link
Copy Markdown
Contributor

What

Implements image_store[_mip]_pck2/pck4 (MIMG 0x76, 0x77, 0x79, 0x7a), the store side of the PCK2/PCK4 loads from #1809, as measured on RDNA2 hardware.

Measured with the hardware oracle on an AMD Radeon 610M (gfx1036, RDNA2). Lane 0 stores one dword into a linear 2D image built over random bytes, then all lanes read back 2 KiB of it. Plain image_store and image_store_mip at the same coordinates are the reference for addressing. The harness was first checked against a plain image_store (exactly one byte changed) and against the load rule of #1809 (50 rows, same results).

Case Measured
Bounds Same as the loads: nothing is written when the mip is past the last level, x + N - 1 >= width (unaligned x, unsigned) or y >= height
Texels written Texel x + k gets bits k * texel bits of the dword, for k from 0 while x + k stays in the aligned group of 4 / texel bytes texels that holds x: at most N texels, never across a 4-byte boundary. x is not aligned down as in the loads (R8 PCK2: x = 5 writes 5 and 6, x = 3 writes only 3)
Number format Raw bits for UNORM, SINT, UINT and FLOAT (R8, R16, RG8)
Masks other than 0x1 Nothing written
Texels too wide for N in 32 bits Nothing written (R16 and RG8 PCK4, R32 and RGBA8 PCK2, RG16 PCK4); 128-bit formats were not run, since one hung a GPU in #1314
_mip forms Same rule per level, at the address of a plain image_store_mip
  • Translation: imageBy emits ImageWrite for the four opcodes, with the packed flag, imageByElements and the mip flag.
  • Emitter: EmitPackedByStoreOp checks the bounds above, then writes each texel through PackedStoreTexel and EmitStorageImageWrite under the 4-byte group gate. Dynamic mips are gated by EmitStorageImageWrite.
  • Still throwing: UNORM, SINT and FLOAT formats (the packed store view reproduces only UINT bits), other masks (at decode), wide formats (in the materializer), image tables (poisoned at run time) and tiled surfaces (not measured). These are recorded in the debt fragment.
  • Tests: image_pck_n checks that each store translates to one ImageWrite. agc_driver_image_pck_n stores from 32 lanes at non-overlapping in-range, edge, out-of-range and mip positions and compares the whole texture with the model (PCK2 R8, R16 and RG8, PCK4 R8, plain and mip). agc_driver_image_table_packed_unmeasured now expects a PCK store through an image table to be poisoned with no texel written.

The measured store is not the inverse of the load. The open #16321 assumes that inversion, without a measurement, for the BY2/BY4 stores; the same harness can check it.

Overlaps: #16321 changes the same lines in imageBy, EmitWriteOp and the unmeasured mode of ImageTablePacked.cpp, and #22675 changes the PCK store refusal line in tests/execution/ImagePckN.cpp. The changes are independent; whichever lands second needs a small rebase.

Tested

Fedora 45 (Linux 7.3.4), AMD Radeon RX 9070 XT (RADV GFX1201, Mesa 26.2.7), Vulkan validation layer 1.4.350. The same tests ran on main and on this branch with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer:

  • The 22 packed and BY image tests (image_pck_n and agc_driver_image_* for pck_n, by, load_packed, store_packed, table_packed*, packed16_load, packed_horizontal_gather, repacked_float and store_unorm_rounding): 21 of 22 pass on both. agc_driver_image_table_packed_guards also fails on main on this GPU ("unrecoverable packed table format was not poisoned") and passes inside the all mode.
  • Both logs show Insert instance layer "VK_LAYER_KHRONOS_validation", neither shows was not found but was requested by env var VK_INSTANCE_LAYERS, and neither has a VUID- line.
  • ctest -R "image|shader|recompil|spirv|mimg|pck|agc": 2001 of 2001 pass.
  • Negative check: removing the 4-byte group gate makes agc_driver_image_pck_n fail.
  • Hardware measurement: AMD Radeon 610M (gfx1036), ROCm HSA runtime 7.2.1, Fedora 45.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 9070 XT, RADV (Mesa 26.2.7), Fedora 45; hardware oracle on AMD Radeon 610M (gfx1036), ROCm 7.2.1, Fedora 45
  • AI-assisted: yes

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

The reviewed head is 6555dca6d03b3046fdc674cae7ab9186f8f2c685; inspected the translation, SPIR-V emitter, tests, and debt note. I did not run checks, and all files listed for review were read.

What I ran

No commands or tests were run; repository context was read with repo_read.py at the pinned head.

Results

Check Result Note
Source review passed All six changed files read
Tests not run Author reports Linux/Vulkan and hardware runs
Negative control not run Author reports a gate-removal check

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not independently verify the hardware measurements, author-reported test results, or behavior outside the measured 2D subset. The excluded-file list was not available through the reader; the manifest lists six changed files, all included and read.

To get this to a good state

Nothing is required.

@github-actions

github-actions Bot commented Nov 20, 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
PR 16321 core/libs/prx/libSceAgcDriver/tests/execution/ImageTablePacked.cpp L696, L698-699, L706-707, L710
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp L1568-1569
core/shader/recompiler/Translation/src/MemoryInstructions/ImageInstructions.cpp L146-147, L155
PR 22675 core/libs/prx/libSceAgcDriver/tests/execution/ImagePckN.cpp L187-188

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5371 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 6280 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 6488 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 7642 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 9508 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 10193 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 10652 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 13928 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 13929 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 14964 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 16260 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 16953 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 20248 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 20519 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 22424 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 22724 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 23632 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 23666 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp

@AbuMshMsh24

Copy link
Copy Markdown
Contributor

AMD Windows driver run for this (the description has the same GPU under RADV): agc_driver_image_pck_n passes, "image PCK2/PCK4 load and store execution tests passed", and agc_driver_image_table_packed passes, on this PR merged onto main 42f6354612, 0 VUID-. Without the two production files, main still refuses the stores (MIMG PCK2/PCK4 stores are not implemented), so the test is exercising the new path here.

Setup: Windows 10 22H2, AMD Radeon RX 9070 XT (RDNA4, 0x1002:0x7550), AMD Software 26.11.2 (32.0.32029.2010), WinLibs GCC 15.2.0 r7, Release, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, Khronos validation layer 1.4.363.1 inserted. Head 6555dca6d0 merged with --no-ff (clean).

AI-assisted: yes (Claude Code)

@shelbykb2

Copy link
Copy Markdown
Contributor

Independent re-measurement on a discrete gfx1030: 75 of 75 store cases write exactly the bytes this PR's semantics predict, in wave32 and wave64 alike.

Setup: AMD Radeon RX 6800 (1002:73bf), assembly target gfx1030, AMD Software 26.11.2 (driver 32.0.21045.29003), Windows 11 Pro 10.0.26300, tools/hw-oracle through the HIP runtime, fine-grained memory, ieee=0 dx10_clamp=1 denorm32=3 denorm16=3 round32=0 round16=0 fp16_overflow=0. Not gfx1013, and not the gfx1036 of the description.

Instructions: .long pairs with word 0 0xf0000108 | op<<18 from the test's StoreCode (dmask 0x1, 2D): 0x76 PCK2, 0x77 PCK4, 0x79 mip PCK2, 0x7a mip PCK4. The second word is 0x0006211e, so the T# sits in s[24:31]; the test's 0x0001211e points at registers the oracle harness uses for its own buffers. Data 0xD4C3B2A1 in v33, address in v[30:32].

Image: the test's descriptor (words 1 to 7 fmt<<20 | address, 0x0000800f, 0x90010fac, 0, 0x10, 0, 0): linear 2D, 61x3, two levels, formats 5 (R8_UINT), 11 (R16_UINT) and 18 (RG8_UINT). The surface starts 512 bytes into a 4 KiB buffer of random bytes below 0x80, so every written byte shows, with a guard before and after. One lane stores; then all 64 lanes read the whole buffer back.

Expected values: 71 cases from a Python port of the diff's CheckStore loop, and the 4 PCK4 R16/RG8 cases ("nothing written") from the table in the description, since the code refuses those stores.

Instruction, format Cases Result
PCK2 R8 x = 0..7 over two rows x and x+1 written inside a pair; only x at the pair's last texel
PCK4 R8 x = 0..7 over two rows 4, 3, 2, 1 texels, up to the end of the group
PCK2 R16, RG8 x = 0, 1, 2, 3 4 bytes at the first texel of a pair, 2 at the second
PCK4 R16, RG8 x = 0, 1 nothing written
Edges, PCK2 R8 x = 58, 59, 60, 61; y = 3 58 writes 58 and 59; 59 writes 59; 60, 61 and y = 3 write nothing
Edges, PCK4 R8 x = 56, 57, 58, 60, 61; y = 3 56 writes 4; 57 writes 3; 58 writes nothing though 58 to 60 are in bounds; the rest nothing
Edges, PCK2 R16 and RG8 x = 58, 59, 60, 61; y = 3 58 writes 4 bytes; 59 writes 2; the rest nothing
mip PCK2 and PCK4, R8, R16, RG8 level 0 and level 1, inside and at the edges; level 2 (past the last) as the level's own width predicts; level 2 writes nothing

All 75 match, and wave32 and wave64 give identical bytes. In every run no byte outside the predicted texels changed anywhere in the 4 KiB buffer.

Layout, from 17 plain image_store and image_store_mip runs in the same session: 256-byte row pitch, level 1 at the surface start and level 0 512 bytes in.

Not measured: UNORM, SINT and FLOAT formats; dmask other than 0x1; R32, RGBA8, RG16; coordinates 0x80000000 and 0xffffffff (a stray write there would land outside any guard, so the unsigned part of the bounds rule is untested); tiled surfaces; 128-bit formats. For mip level 2, that a stray write would have landed inside the read-back window is inferred from the layout, not shown. I can attach the JSON reports and the per-case before and after bytes if useful.

AI-assisted: yes (Claude Code)

@Jirka135

Copy link
Copy Markdown
Contributor

Windows run of head 6555dca6d0 merged onto main 7ed059fc42 (--no-ff, clean). Windows 11 Enterprise 10.0.26300, WinLibs GCC 15.2.0 Release, Khronos validation layer 1.4.369. NVIDIA GeForce RTX 5090 (10de:2b85, driver 617.42) and AMD Radeon(TM) Graphics (gfx1036 iGPU, driver 32.0.21045.29003, ANYPS5_GPU=AMD).

ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest --test-dir build -R '^(image_pck_n|image_by|agc_driver_image_(pck_n|by|load_packed|store_packed|table_packed.*|packed16_load|packed_horizontal_gather|repacked_float|store_unorm_rounding))$' -V, 23 tests, 3 runs per side per GPU, plus 3 runs without the layer.

RTX 5090 gfx1036 iGPU
main 69/69 (layer), 69/69 (no layer) 69/69, 69/69
this PR 69/69, 69/69 69/69, 69/69
main code + this PR's three test files agc_driver_image_pck_n, agc_driver_image_table_packed_unmeasured and image_pck_n fail: MIMG PCK2/PCK4 stores are not implemented same

Unlike the RX 9070 XT run in the description, agc_driver_image_table_packed_guards passes on both sides here on both GPUs. Every log shows Insert instance layer "VK_LAYER_KHRONOS_validation" and none shows was not found but was requested by env var VK_INSTANCE_LAYERS. No VUID- line on either side or GPU.

GPUs tested: NVIDIA GeForce RTX 5090, driver 617.42, Windows 11; AMD Radeon(TM) Graphics (gfx1036 iGPU), driver 32.0.21045.29003, Windows 11

AI-assisted: yes

@oneandonlydean
oneandonlydean merged commit a513a12 into boykopovar:main Nov 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants