fix(shader): read 2D-array T#s through 3D image accesses #2140
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2140"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-09T09:53:44Z.
What
Depends on: #2133 (merged 2026-10-10). This PR is rebased onto
mainwith #2133 in. It now carries only what #2133 doesn't cover.Since #2133, a 3D access bound to a 2D-array T# no longer throws, and it reads the wrong data.
descriptorDimensiondecodes a 2D-array T# as 2D when the access isn't an array access. So a dim 3Dimage_sample_lzorimage_loadon a 2D-array T# matches #2133's new 2D mode:@adriadam10 measured on RDNA2 (gfx1035) with
tools/hw-oracle(https://github.com/boykopovar/AnyPS5/pull/2140#pullrequestreview-5477882896). On a 2D-array T#, dim 3D behaves exactly like dim 2D-array: the layer is r rounded to nearest even and clamped, or z. His rows also coverimage_load_mipon both T# types andimage_get_resinfo:mainimage_sample_lz,image_load,image_load_mipimage_get_resinfo16 16 2 116 16 0 1through the 2D modeimage_load_mipimage_get_resinfo16 16 1 1image_get_lodThe change:
descriptorDimension: a 2D-array T# bound to a 3D access decodes as 2D-array.RuntimeImageModes: a 3D access that isflatVolumeCompatiblegets a 2D-array mode next to #2133's 2D mode.ResourceTracker:flatVolumeCompatiblenow also acceptsimage_load_mipandimage_get_resinfo.image_get_lodstays outside the set, so an image that uses it gets neither mode and fails to bind with the usual "incompatible with the static runtime image interface" error.QueryDimensions: through the 2D mode, a 3D resinfo returns 1 as its third component, not 0.docs/dev/TechnicalDebt.md: #2133's line now covers the 2D-array T#,image_load_mip, resinfo andimage_get_lod.Cube, 1D, MSAA and storage T#s bound to a 3D access are still refused. So are samples with an LOD, bias, derivatives, offset or comparison, and gathers.
Tested
agc_driver_image_volume_address_planar_texture(tests/execution/ImageVolumeAddressPlanarTexture.cpp) runs one compute shader against a 16x16 2D T# and then a 2-layer 2D-array T#. The shader doesimage_sample_lz,image_load,image_load_mipandimage_get_resinfo, all with dim 3D.16 16 1 1and16 16 2 1.image_sample_lzplusimage_get_loddim 3D, must be refused on both T# types.image_get_lodis refused on both T# types.image_volume_address_on_planerecompiles the same way and still refusesimage_sample_l.QueryDimensionschange:third component is not the constant 1, got 0(adriadam10's16 16 0 1);descriptorDimensionchange: the 2D-array T# takes the 2D mode (got 1). This is the behaviour onmain;incompatible with the static runtime image interface ... decodes to {... dim 5 ...};flatVolumeCompatible: the 2D T# is refused, as onmain;image_get_lodinflatVolumeCompatible:image_get_lod 3d on a 2D texture was not refused.main38385164. The rebase onto942a174ehad no conflicts and changed none of the touched hunks. The compile check below was repeated on the rebased tree.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by rmz-24 on 2026-10-09T13:07:40Z.
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 pluslibs. 04f61f76 cherry-picked onto currentmaind70b8998(applies cleanly).agc_driver_image_volume_address_planar_texturepasses on NVIDIA.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by NahuelGenchi on 2026-10-09T15:50:04Z.
Tested with Sonic Origins (PPSA05324) on Linux, R9 380 (RADV, Mesa 26.0.8, GFX8): it gets past the stop.
maind70b8998+ the PRs listed in #2021), I replaced my local workaround for #2023 with this PR (04f61f76 cherry-picked). The shader cache started empty for the new source version, so every shader was recompiled with it.agc_driver_image_volume_address_planar_texturepasses on this card too, along with the other 36 image, bindless, runtime image, shader disk cache andagc_driver_graphicstests.image_srgb_loadpasses here.I tested #2133 the same way; it also gets the title past this stop.
Bring-up thread: #2021
Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-09T23:50:08Z.
Thanks @rmz-24 and @NahuelGenchi. Between you, this now has NVIDIA on Windows (511/511), GFX8 on RADV, and an actual Sonic Origins (PPSA05324) run past the "image descriptor is incompatible with the static runtime image interface" stop with a cold shader cache. That's the evidence it needed.
For the maintainers: #2133 by @queeeef fixes the same stop and was opened first. The main difference is that this PR also decodes 2D-array descriptors and adds 2D-array modes for sampled 3D accesses. #2133 only allows the flat 2D forms CouchRiv measured. I'm happy to close this one, or to split the 2D-array part out as a follow-up on top of #2133, whichever you prefer.
The z != 0 load-returns-zero behavior is still based on CouchRiv's RDNA2 measurement, not PS5 gfx1013.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:00:43Z.
Review: CHANGES_REQUESTED
Thanks. I measured the forms this PR adds on RDNA2 with
tools/hw-oracle(gfx1035).image_sample_lz,image_loadandimage_load_mipwith dim 3D on 2D and 2D-array T#s match the PR in every row. The rows covered r = 0, ±0.5, 0.6, 1.5, 2.5, 3.5, NaN, ±Inf and z = 0..5, -1, 0x80000000. On a 2D-array T#, dim 3D behaves exactly like dim 2D-array (layer = RNE + clamp). The negative test also fails without the change, as it should.image_get_resinfowith dim 3D on a 2D T# now goes through the new 2D mode, and its third component is wrong. On hardware it returns(w, h, 1, levels). With this PR it returns(w, h, 0, levels):QueryDimensions(SpirvImageEmitter.cpp:416) fills only the 2D mode's components. I reproduced this on RADV with a 16x16 T#:16 16 0 1against16 16 1 1on hardware. It happens with resinfo alone and also next to animage_sample_lzdim 3D. Onmainthis threw, so it is now a plausible but wrong value. Please return 1 for that component when the access is 3D and the mode is 2D, and add a resinfo row to the test. 2D-array is already right (16 16 2 1).image_get_lodwith dim 3D through the 2D/2D-array modes is also enabled now. We can't measure it here because it needs derivatives. Please make it throw for those modes, or list it indocs/dev/TechnicalDebt.md.Depends on: #2133, or agree with @queeeef which PR carries both.Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-11T00:57:13Z.
Closing this, since #2133 covers the same Sonic Origins (PPSA05324) stop and is now merged. Thanks again to @rmz-24 and @NahuelGenchi for testing both. If the 2D-array T# path that this PR also decoded turns out to matter for a title, I'll bring it back as a separate, smaller change with that title's log.
Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-11T01:27:31Z.
Thanks @adriadam10. Your gfx1035 rows settled what CouchRiv's table left open. I've rebased onto
mainwith #2133 in, and cut this PR down to what #2133 doesn't cover (Depends on: #2133).image_sample_lzandimage_loadpath now. The rebase turned up a problem on currentmain. A dim 3D access on a 2D-array T# decodes as 2D and matches #2133's 2D mode, so it doesn't throw. It reads layer 0 for any r, and returns zero for z != 0. This PR decodes it as 2D-array and adds the 2D-array mode, so it now matches your "dim 3D behaves exactly like dim 2D-array" rows.maindoesn't return the wrong16 16 0 1. #2133'sflatVolumeCompatibleleaves out queries, so resinfo dim 3D on a 2D T# still throws there. You measured it, so this PR allows it and returns 1 for the third component through the 2D mode. The test has both rows:16 16 1 1on 2D and16 16 2 1on 2D-array. Without theQueryDimensionschange, the test reports your16 16 0 1.image_load: zero for z != 0 through the 2D mode.On my aarch64 lavapipe host, the JIT dies with SIGILL at dispatch for every execution test, #2133's included. So I checked the recompiled SPIR-V and the refusals there, plus five mutants. The PR description has the details. The texel values still need the x86_64 CI run.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T02:10:49Z.
Windows run, since the PR has no Intel results: Windows 11, WinLibs GCC 15.2.0 r7, Release, merged onto
maind31b57a4, RTX 5060 Laptop and the Arrow Lake iGPU (ANYPS5_GPU=Intel).agc_driver_image_volume_address_planar_textureandagc_driver_image_volume_address_on_planepass on both GPUs, and nothing else in theagc_*suite changed.AI-assisted (Claude Code); I ran this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-11T02:26:50Z.
Thanks @Silverash-i8, that adds Intel (Arrow Lake iGPU) and a second NVIDIA run on Windows, both green on the planar-texture and on-plane tests. @adriadam10 both review points are addressed in
c447b289(resinfo returns 1 on the 2D mode, get_lod throws for the 2D and 2D-array modes); ready for another look when you have time.Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-11T04:39:55Z.
@adriadam10 friendly ping when you have a moment: the rework now changes only the 2D-array-through-3D path as you suggested (resinfo returns the layer dimension, get_lod throws for unsupported modes, new test). Silverash-i8 confirmed both planar-texture tests on Windows 11 with NVIDIA and Intel. Happy to adjust anything. AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:12:20Z.
Review: APPROVED
Checked the added forms against my gfx1035 oracle rows (
image_sample_lz,image_load,image_load_mip,image_get_resinfo, dim 3D on 2D and 2D-array T#s): all match, including the resinfo third component now. The new test passes locally and fails with the four source files reverted. Tests on the previous head by @rmz-24 (Windows/NVIDIA) and @NahuelGenchi (Sonic Origins on RADV) cover the same code paths. Merging.