fix(shader): bind 2D textures to 3D sample and load accesses as measured #2133

Merged
queeeef merged 2 commits from upstream-pr/2133 into main 2026-10-10 06:25:23 +00:00
queeeef commented 2026-10-09 09:46:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by queeeef on 2026-10-09T09:46:53Z.


What

Fixes #2023. A 3D image access bound to a 2D T# matched no runtime image mode and threw "image descriptor is incompatible with the static runtime image interface" (Sonic Origins PPSA05324). RuntimeImageModes already offers a 3D mode for a 2D access, but not the reverse.

Semantics source: CouchRiv's hardware-oracle measurement in #2023 on RDNA2 (gfx1036):

  • image_sample_lz with dim 3D on a 2D T# returns the (u,v) texel for every r.
  • image_load with dim 3D returns the (x,y) texel for z = 0 and zeros otherwise.

Change:

  • A new flatVolumeCompatible image flag, narrowed in ResourceTracker::Merge, stays true only while every use of the image is one of those two measured forms: an image_sample_lz with no other sample flags, or an image_load without mip, packing or BY.
  • For such a 3D access, RuntimeImageModes adds a 2D mode: not storage, not depth, no conversion or packed format.
  • Sampling through it already uses only (u,v). EmitReadOp now returns zero when z != 0.
  • The flag is stored in the shader disk cache.
  • Everything else (LOD, bias, derivatives, offsets, compare, gathers, queries, stores, image_load_mip) keeps throwing. Recorded in TechnicalDebt, including that gfx1013 is not measured.

Tested

Linux, lavapipe (Mesa 25.2.8), main at a7ff8852.

  • New agc_driver_image_volume_address_on_plane:
    • 32 lanes sample a 2D RGBA8 texture through dim-3D image_sample_lz with r in {0, 0.5, 1, 1.5, -0.25, 3, 0.25, 0.75} and expect the (u,v) texel.
    • They load through dim-3D image_load with z in {0, 1, 2, 3, 4, -1} and expect the texel for z = 0 and zeros otherwise.
    • The same shader on a real two-slice 3D texture reads each slice, so 3D T#s still pick the 3D mode.
    • A dim-3D image_sample_l on the 2D T# is still refused.
  • Without the fix the test fails with the issue's message. Dropping the z check fails the z = 1 lanes; offering the mode for any use fails the refusal check.
  • All 29 agc_driver_image_*, runtime_images and bindless_images execution tests, agc_shader_disk_cache (now round-trips the flag), agc_driver, agc_shader_memory and agc_driver_graphics pass. tools/check_conventions.py and tools/check_test_registration.py pass.
  • Not tested in the game. @NahuelGenchi, could you check whether Sonic Origins gets past this stop?

Checklist

  • Based on current main, no overlap with open PRs
  • One topic
  • No comments
  • Unimplemented paths throw
  • No notes/images
  • Submodules unchanged
  • Generic behaviour, not title-specific
  • Depends on: none
  • AI-assisted: yes (Claude Code), reviewed and tested by me
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4798774965 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2133). Originally posted by [queeeef](https://github.com/queeeef) on 2026-10-09T09:46:53Z. --- ### What Fixes #2023. A 3D image access bound to a 2D T# matched no runtime image mode and threw "image descriptor is incompatible with the static runtime image interface" (Sonic Origins PPSA05324). `RuntimeImageModes` already offers a 3D mode for a 2D access, but not the reverse. Semantics source: CouchRiv's hardware-oracle measurement in #2023 on RDNA2 (gfx1036): - `image_sample_lz` with dim 3D on a 2D T# returns the (u,v) texel for every r. - `image_load` with dim 3D returns the (x,y) texel for z = 0 and zeros otherwise. Change: - A new `flatVolumeCompatible` image flag, narrowed in `ResourceTracker::Merge`, stays true only while every use of the image is one of those two measured forms: an `image_sample_lz` with no other sample flags, or an `image_load` without mip, packing or BY. - For such a 3D access, `RuntimeImageModes` adds a 2D mode: not storage, not depth, no conversion or packed format. - Sampling through it already uses only (u,v). `EmitReadOp` now returns zero when z != 0. - The flag is stored in the shader disk cache. - Everything else (LOD, bias, derivatives, offsets, compare, gathers, queries, stores, `image_load_mip`) keeps throwing. Recorded in TechnicalDebt, including that gfx1013 is not measured. ### Tested Linux, lavapipe (Mesa 25.2.8), main at a7ff8852. - New `agc_driver_image_volume_address_on_plane`: - 32 lanes sample a 2D RGBA8 texture through dim-3D `image_sample_lz` with r in {0, 0.5, 1, 1.5, -0.25, 3, 0.25, 0.75} and expect the (u,v) texel. - They load through dim-3D `image_load` with z in {0, 1, 2, 3, 4, -1} and expect the texel for z = 0 and zeros otherwise. - The same shader on a real two-slice 3D texture reads each slice, so 3D T#s still pick the 3D mode. - A dim-3D `image_sample_l` on the 2D T# is still refused. - Without the fix the test fails with the issue's message. Dropping the z check fails the z = 1 lanes; offering the mode for any use fails the refusal check. - All 29 `agc_driver_image_*`, `runtime_images` and `bindless_images` execution tests, `agc_shader_disk_cache` (now round-trips the flag), `agc_driver`, `agc_shader_memory` and `agc_driver_graphics` pass. `tools/check_conventions.py` and `tools/check_test_registration.py` pass. - Not tested in the game. @NahuelGenchi, could you check whether Sonic Origins gets past this stop? ### Checklist - [x] Based on current main, no overlap with open PRs - [x] One topic - [x] No comments - [x] Unimplemented paths throw - [x] No notes/images - [x] Submodules unchanged - [x] Generic behaviour, not title-specific - Depends on: none - AI-assisted: yes (Claude Code), reviewed and tested by me
rmz-24 commented 2026-10-09 12:38:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rmz-24 on 2026-10-09T12:38:43Z.


Windows run: Windows 11 Pro 25H2 (10.0.26200.9457), RTX 5060 Ti (NVIDIA 617.42), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON, full build plus libs. c1b85fb9 cherry-picked onto current main d70b8998 (applies cleanly).

  • agc_driver_image_volume_address_on_plane passes on NVIDIA hardware, in addition to lavapipe.
  • Full ctest: 511/511.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6081052757 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2133#issuecomment-6081052757). Originally posted by [rmz-24](https://github.com/rmz-24) on 2026-10-09T12:38:43Z. --- Windows run: Windows 11 Pro 25H2 (10.0.26200.9457), RTX 5060 Ti (NVIDIA 617.42), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, `-DANYPS5_ENABLE_SPIRV_TOOLS=ON`, full build plus `libs`. c1b85fb9 cherry-picked onto current `main` d70b8998 (applies cleanly). - `agc_driver_image_volume_address_on_plane` passes on NVIDIA hardware, in addition to lavapipe. - Full ctest: 511/511. AI-assisted: yes
NahuelGenchi commented 2026-10-09 15:50:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NahuelGenchi on 2026-10-09T15:50:02Z.


Tested with Sonic Origins (PPSA05324) on Linux, R9 380 (RADV, Mesa 26.0.8, GFX8): yes, it gets past the stop.

  • On my testing branch (main d70b8998 + the PRs listed in #2021), I replaced my local workaround for #2023 with this PR (c1b85fb9 cherry-picked). The shader cache started empty for the new source version, so every shader was recompiled with it.
  • No draw or dispatch was rejected, and the title presents its boot frames up to the SEGA logo as before. A 3D access outside the two measured forms would still throw, so the title's accesses fit them.
  • agc_driver_image_volume_address_on_plane passes on this card too, along with the other 36 image, bindless, runtime image, shader disk cache and agc_driver_graphics tests.

I tested #2140 the same way; it also gets the title past this stop.

Bring-up thread: #2021

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6084330331 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2133#issuecomment-6084330331). Originally posted by [NahuelGenchi](https://github.com/NahuelGenchi) on 2026-10-09T15:50:02Z. --- Tested with Sonic Origins (PPSA05324) on Linux, R9 380 (RADV, Mesa 26.0.8, GFX8): yes, it gets past the stop. - On my testing branch (`main` d70b8998 + the PRs listed in #2021), I replaced my local workaround for #2023 with this PR (c1b85fb9 cherry-picked). The shader cache started empty for the new source version, so every shader was recompiled with it. - No draw or dispatch was rejected, and the title presents its boot frames up to the SEGA logo as before. A 3D access outside the two measured forms would still throw, so the title's accesses fit them. - `agc_driver_image_volume_address_on_plane` passes on this card too, along with the other 36 image, bindless, runtime image, shader disk cache and `agc_driver_graphics` tests. I tested #2140 the same way; it also gets the title past this stop. Bring-up thread: #2021
adriadam10 commented 2026-10-10 06:13:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:13:06Z.


Checked on our side:

  • Hardware oracle on RDNA2 (gfx1035, IEEE=0): image_sample_lz dim 3D on a 2D T# equals dim 2D on 43 rows (r from -1 to 100, ±Inf, NaN; point clamp/wrap/border, bilinear clamp/wrap), and image_load dim 3D returns the (x,y) texel for z = 0 and zero for z = 1..4, -1, 0x80000000 and 0x10000, also with out-of-range x/y. Same result with a non-zero DEPTH field in the 2D T#. Matches CouchRiv's gfx1036 run.
  • Build and the libSceAgc/libSceAgcDriver ctest pass on RADV. Without the ResourceMaterializer change the new test throws the error from #2023, and without the z check it fails on the z = 1 lanes.

Added on your branch:

  • Rebased on current main (adjacency conflicts with the constantSwizzle fields in Resources.hpp, ResourceTracker.cpp and ShaderDiskCache.cpp; both kept).
  • A final period on the new TechnicalDebt line.

Merging once the full Linux and Windows build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094540164 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2133#issuecomment-6094540164). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T06:13:06Z. --- Checked on our side: - Hardware oracle on RDNA2 (gfx1035, IEEE=0): `image_sample_lz` dim 3D on a 2D T# equals dim 2D on 43 rows (r from -1 to 100, ±Inf, NaN; point clamp/wrap/border, bilinear clamp/wrap), and `image_load` dim 3D returns the (x,y) texel for z = 0 and zero for z = 1..4, -1, 0x80000000 and 0x10000, also with out-of-range x/y. Same result with a non-zero DEPTH field in the 2D T#. Matches CouchRiv's gfx1036 run. - Build and the libSceAgc/libSceAgcDriver ctest pass on RADV. Without the ResourceMaterializer change the new test throws the error from #2023, and without the z check it fails on the z = 1 lanes. Added on your branch: - Rebased on current main (adjacency conflicts with the `constantSwizzle` fields in `Resources.hpp`, `ResourceTracker.cpp` and `ShaderDiskCache.cpp`; both kept). - A final period on the new TechnicalDebt line. Merging once the full Linux and Windows build is green.
github-actions[bot] commented 2026-10-10 06:19:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T06:19:35Z.


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
#2140 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp L630
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp L953
#2348 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp L630
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094589233 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2133#issuecomment-6094589233). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T06:19:35Z. --- <!-- pr-overlap --> 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 | |---|---|---|---| | #2140 | `core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp` [L630](https://github.com/boykopovar/AnyPS5/blob/03bf8ff335e59057a404fa34fdb62ec4de038508/core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp#L630)<br>`core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp` [L953](https://github.com/boykopovar/AnyPS5/blob/03bf8ff335e59057a404fa34fdb62ec4de038508/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L953) | | | | #2348 | `core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp` [L630](https://github.com/boykopovar/AnyPS5/blob/03bf8ff335e59057a404fa34fdb62ec4de038508/core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp#L630) | | |
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!2133
No description provided.