feat(shader): implement MIMG BY2/BY4 loads as measured on hardware #1793

Merged
adriadam10 merged 2 commits from upstream-pr/1793 into main 2026-10-08 19:37:25 +00:00
adriadam10 commented 2026-10-08 19:18:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T19:18:52Z.


What

Replaces #1526 by @kali113, which I closed by mistake (see the comment there). The first commit is theirs, adapted to main after #639. The second commit is ours: it makes the four loads follow what the hardware does. The four stores decode, so they count in the progress table, but throw at translation.

Measured on RDNA2 (gfx1035) with the hardware oracle. Each check compares the BY result against plain image_loads of the same texels on random memory, over x/y/mip edge rows, 9 widths and several formats:

measured #1526 assumed
window x & ~(N-1) .. +N-1 on row y (N = 2 for BY2, 4 for BY4) x .. x+N-1
out of range every register 0 when the mip is past the last level, x+N-1 >= width, or y >= height not modelled
formats with data the N texels fit in one dword: R8/R16 (dmask 0x3) or RG8 (0xf) for BY2, R8 (0xf) for BY4 R32 (BY4), RG32 (BY2)
R32, RG32, RG16, RGBA8 always zeros data

These agree with pandather's gfx1031 measurements posted on #1526 (aligned window, all-or-nothing bound, data only from narrow formats). Loads: 0 mismatches over 2,160 rows per format (12,960 for mip variants) across 24 opcode/format/mask combinations. Stores were measured too: they write from the unaligned x up to the end of its dword. That's a different rule, so they stay unimplemented for a follow-up.

  • Decoder: BY2 accepts DMASK 0x3 and 0xf, BY4 0xf. Other masks, A16/D16, non-2D and partial descriptors throw.
  • Materializer: only R8/R16/RG8 (BY2) and R8 (BY4) with a direct, identity-swizzled 2D descriptor. Everything else throws.
  • Emitter (EmitByReadOp): one ImageRead per instruction. It fetches the N aligned texels with OpImageFetch at the clamped LOD and zeroes every register when the window is out of range, converting each texel like image_load. The level's width and height are max(size(LOD 0) >> lod, 1), the extent Vulkan defines for a view's levels, not OpImageQuerySizeLod at a per-lane LOD. CI's lavapipe returns one lane's level size for all 8 lanes of a group there, which zeroed a lane whose neighbour read another mip.
  • ShaderDiskCache format version 20: ImageResource has byElements/byComponents.
  • TechnicalDebt line next to the MIMG tfe/lwe entry.

Tested

Linux (CachyOS), on the merge with main. agc_driver_image_by passes on RADV (gfx1035) and CI's lavapipe (Mesa 25.2.8). It covers R8/R16 (0x3) and RG8 (0xf) for BY2 and R8 for BY4, with and without mip, 32 lanes per run with x near both edges, x ≥ width, x = -1 and 2^31, y = height and -1, and mip = level count. It checks that the store opcodes and every unsupported format/swizzle throw, and that registers past the mask keep their value. image_by checks decode and translation. Full ctest: 488/488, and the BY/gather tests three times on each driver. Negative checks: dropping the x alignment fails at x 5, and dropping the width - x >= N bound fails at x 60 (width 61).

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
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4791690637 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1793). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T19:18:52Z. --- ### What Replaces #1526 by @kali113, which I closed by mistake (see the comment there). The first commit is theirs, adapted to `main` after #639. The second commit is ours: it makes the four loads follow what the hardware does. The four stores decode, so they count in the progress table, but throw at translation. Measured on RDNA2 (gfx1035) with the [hardware oracle](docs/dev/HW_ORACLE.md). Each check compares the BY result against plain `image_load`s of the same texels on random memory, over x/y/mip edge rows, 9 widths and several formats: | | measured | #1526 assumed | |---|---|---| | window | `x & ~(N-1)` .. +N-1 on row y (N = 2 for BY2, 4 for BY4) | x .. x+N-1 | | out of range | every register 0 when the mip is past the last level, `x+N-1 >= width`, or `y >= height` | not modelled | | formats with data | the N texels fit in one dword: R8/R16 (dmask 0x3) or RG8 (0xf) for BY2, R8 (0xf) for BY4 | R32 (BY4), RG32 (BY2) | | R32, RG32, RG16, RGBA8 | always zeros | data | These agree with pandather's gfx1031 measurements posted on #1526 (aligned window, all-or-nothing bound, data only from narrow formats). Loads: 0 mismatches over 2,160 rows per format (12,960 for mip variants) across 24 opcode/format/mask combinations. Stores were measured too: they write from the unaligned x up to the end of its dword. That's a different rule, so they stay unimplemented for a follow-up. - Decoder: BY2 accepts DMASK 0x3 and 0xf, BY4 0xf. Other masks, A16/D16, non-2D and partial descriptors throw. - Materializer: only R8/R16/RG8 (BY2) and R8 (BY4) with a direct, identity-swizzled 2D descriptor. Everything else throws. - Emitter (`EmitByReadOp`): one `ImageRead` per instruction. It fetches the N aligned texels with `OpImageFetch` at the clamped LOD and zeroes every register when the window is out of range, converting each texel like `image_load`. The level's width and height are `max(size(LOD 0) >> lod, 1)`, the extent Vulkan defines for a view's levels, not `OpImageQuerySizeLod` at a per-lane LOD. CI's lavapipe returns one lane's level size for all 8 lanes of a group there, which zeroed a lane whose neighbour read another mip. - `ShaderDiskCache` format version 20: `ImageResource` has `byElements`/`byComponents`. - TechnicalDebt line next to the MIMG `tfe`/`lwe` entry. ### Tested Linux (CachyOS), on the merge with `main`. `agc_driver_image_by` passes on RADV (gfx1035) and CI's lavapipe (Mesa 25.2.8). It covers R8/R16 (0x3) and RG8 (0xf) for BY2 and R8 for BY4, with and without mip, 32 lanes per run with x near both edges, x ≥ width, x = -1 and 2^31, y = height and -1, and mip = level count. It checks that the store opcodes and every unsupported format/swizzle throw, and that registers past the mask keep their value. `image_by` checks decode and translation. Full ctest: 488/488, and the BY/gather tests three times on each driver. Negative checks: dropping the x alignment fails at `x 5`, and dropping the `width - x >= N` bound fails at `x 60` (width 61). ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-08 19:20:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T19:20:28Z.


Progress report (b858fdc → d5a3a43)

📈 GPU shader instructions: 99.06% (+0.69%, +8 implemented instructions)

✅ 8 implemented
Encoding Name
MIMG IMAGE_LOAD_BY2
MIMG IMAGE_LOAD_BY4
MIMG IMAGE_LOAD_MIP_BY2
MIMG IMAGE_LOAD_MIP_BY4
MIMG IMAGE_STORE_BY2
MIMG IMAGE_STORE_BY4
MIMG IMAGE_STORE_MIP_BY2
MIMG IMAGE_STORE_MIP_BY4
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6067330846 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1793#issuecomment-6067330846). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T19:20:28Z. --- <!-- progress-report --> ### Progress report (b858fdc → d5a3a43) 📈 **GPU shader instructions**: 99.06% (+0.69%, +8 implemented instructions) <details> <summary>✅ 8 implemented</summary> | Encoding | Name | | - | - | | MIMG | `IMAGE_LOAD_BY2` | | MIMG | `IMAGE_LOAD_BY4` | | MIMG | `IMAGE_LOAD_MIP_BY2` | | MIMG | `IMAGE_LOAD_MIP_BY4` | | MIMG | `IMAGE_STORE_BY2` | | MIMG | `IMAGE_STORE_BY4` | | MIMG | `IMAGE_STORE_MIP_BY2` | | MIMG | `IMAGE_STORE_MIP_BY4` | </details>
adriadam10 commented 2026-10-08 19:29:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T19:29:04Z.


Windows failed image_by with 0xc0000135 (DLL not found). The test was registered without the PATH prepend for libc that its sibling tests (scalar_call, image_sample_gather) have. Added it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6067474622 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1793#issuecomment-6067474622). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T19:29:04Z. --- Windows failed `image_by` with `0xc0000135` (DLL not found). The test was registered without the `PATH` prepend for `libc` that its sibling tests (`scalar_call`, `image_sample_gather`) have. Added it.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!1793
No description provided.