Skip to content

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

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
queeeef:fix/agc-3d-access-on-2d-texture
Oct 10, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
queeeef:fix/agc-3d-access-on-2d-texture

Conversation

@queeeef

@queeeef queeeef commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

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 a7ff885.

  • 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

@rmz-24

rmz-24 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

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. c1b85fb cherry-picked onto current main d70b899 (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

Copy link
Copy Markdown
Contributor

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

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

Bring-up thread: #2021

queeeef and others added 2 commits October 10, 2026 05:15
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, boykopovar#2023). CouchRiv measured RDNA2 (gfx1036)
with the hardware oracle: image_sample_lz with dim 3D ignores r and
reads the (u,v) texel, and image_load reads the (x,y) texel when z is
0 and returns zero otherwise. Add a 2D mode for 3D accesses whose only
uses are those two forms, and make the load return zero for z != 0.
Every other access keeps throwing.

Fixes boykopovar#2023

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@adriadam10

Copy link
Copy Markdown
Collaborator

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 3D image access bound to a 2D T#: image descriptor is incompatible with the static runtime image interface #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.

@adriadam10
adriadam10 force-pushed the fix/agc-3d-access-on-2d-texture branch from c1b85fb to 090a30c Compare October 10, 2026 06:13
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 10, 2026
@github-actions

github-actions Bot commented Oct 10, 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
#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

@adriadam10
adriadam10 merged commit 1a66868 into boykopovar:main Oct 10, 2026
14 checks passed
SleglJan pushed a commit to SleglJan/AnyPS5 that referenced this pull request Oct 10, 2026
…2d-texture

fix(shader): bind 2D textures to 3D sample and load accesses as measured
overlordxrz-source added a commit to overlordxrz-source/AnyPS5 that referenced this pull request Oct 11, 2026
Since boykopovar#2133, a 3D image_sample_lz or image_load bound to a 2D-array T#
decodes as 2D and matches the new 2D mode, so it reads layer 0 for any
r and returns zero for z != 0. adriadam10 measured on RDNA2 (gfx1035)
that dim 3D on a 2D-array T# behaves exactly like dim 2D-array, with r
or z as the layer. Decode a 2D-array T# bound to a 3D access as 2D-array
and add a 2D-array mode next to the 2D one.

The same measurement covers image_load_mip on both T# types and
image_get_resinfo, which returns (w, h, 1, levels) on a 2D T# and
(w, h, layers, levels) on a 2D-array T#. Allow those accesses and return
1 as the third resinfo component through the 2D mode. image_get_lod is
not measured and keeps throwing.
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.

3D image access bound to a 2D T#: image descriptor is incompatible with the static runtime image interface

4 participants