fix(shader): accept 3D image stores on 2D T#s #20792
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20792"
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 brumskysb on 2026-11-15T15:38:19Z.
What
A DIM 3D
image_storethrough a 2D T# throws today (image descriptor is incompatible with the static runtime image interface):RuntimeImageModesoffers a 2D-array runtime mode for a write-only DIM 3D storage image but no 2D mode.The rule was measured on RDNA2 (gfx1036, Windows driver 31.0.22044.1) in #17807 (evidence gist https://gist.github.com/brumskysb/1dbfc6a1dddebdc046e43762747372ac): a DIM 3D
image_storethrough a 2D T# (8x8 32_FLOAT,image_store v4, v[5:7], s[8:15] dmask:0x1 dim:SQ_RSRC_IMG_3D) writes the lane's (x, y) texel when z is 0 and nothing when z is 1. With all z 0 it wrote all 64 texels and nothing outside the face, with all z 1 it moved 0 dwords, with mixed z it wrote exactly the z 0 lanes, andimage_store_mipat mip 0 with z 0 matched. This is the store counterpart of the load rule already inEmitReadOp, and of #9249 for 2D-array T#s.Change:
ResourceMaterializer.cpp(3 lines added) offers aDim2Dmode after theDim2DArrayone for a write-only DIM 3D storage image; the relative order of the existing modes is unchanged and there is no newImageResourcefield, so the shader disk cache encoder is untouched.SpirvImageEmitter.cpp(1 line changed) gatesEmitWriteOpon z == 0 for a DIM 3D address on a 2D image, as it already does for a 2D-array address on a 1D image. Loads, samples and atomics are unchanged: the unit test still refuses a load+store through a 2D T# and an atomic through a UINT 2D T# whose plain store is accepted. Modes offered for a write-only 3D storage image: 50 on main, 75 here; the limitImageTableAbi::MaxModesis 256.Tests: a new execution test
ImageStoreVolumeThroughPlane(three legs: all z 0, all z 1, z = lane & 1; 8x8 32_FLOAT 2D T#; expected values come from the rule above, not from the recompiler), a new unit caseverifyPlaneVolumeStoreMode, and a debt fragment.An existing test pinned the old refusal:
verifyGuardedDescriptorSourcesstored through a 2D T# with DIM 3D and expected that to be refused. I repaired it by changing the DIM of that one instruction word (0xf0200f10, DIM 3D, to 0xf0200f20, DIM 1D_ARRAY), not by weakening the assertion; DIM 1D_ARRAY is refused with the same message. Other DIMs tried on this branch: CUBE and 2D_ARRAY are accepted, 2D_MSAA and 1D are refused with a different message. The repair does not depend on this change: with the two recompiler edits reverted and the new unit case removed,agc_shader_memorypasses on main's sources.Not measured and not tested: formats other than 32_FLOAT, multi-component
dmasks, mip levels above 0, and a z other than 0 and 1 on a 2D T#. The recompiler applies the same rule to them, and the debt entry says so. The execution test coversimage_storeonly (mip 0, 32_FLOAT, onedmask);image_store_mipsharesEmitWriteOpbut is measured on hardware at mip 0 only and is not separately tested here.Debt entry length: the entry grows from 1,225 to 1,450 characters, over the 1,000-character guideline (
check_conventions.pyreports a warning, 0 errors). It is not trimmed because every sentence carries a measured condition.Debt entry change, extracted by script from
tools/debt_fold.py --show shaderagainstdocs/dev/debt/shader.md(the first 1140 characters of the entry are byte-identical; only the closing sentence differs):dmasks, mip levels above 0 and a z other than 0 and 1 on a 2D T#; none of those is measured.Overlap:
tools/pr_overlap.pyfails closed (exit 2): it flags #16260 (ShaderMemory.cppnear line 12620, next to the new unit case) and could not compare 36 PRs that conflict withmain. I read the patches of those 36 and of 42 more open PRs that touchResourceMaterializer.cpporSpirvImageEmitter.cpp(78 in all, from a snapshot of the open PRs taken 2026-11-15 07:47 MST): none adds a line that combines DIM 3D with a 2D image, and none implements this change. Four title searches found only unrelated PRs. Textual conflicts are possible; a duplicate was not found.Evidence (logs, the overlap scripts and their output, the test-bed scripts): https://gist.github.com/brumskysb/0117427a8393feda23e0b69eacc506c5
Tested
All on Linux (Ubuntu 26.04.1 LTS, kernel 7.0.0-43-generic), Mesa lavapipe (llvmpipe, LLVM 21.1.8, Vulkan 1.4.79, mesa-vulkan-drivers 26.0.8), Khronos validation layer 1.4.363.1, Release build,
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer,ctest -V. The loader lineInsert instance layer "VK_LAYER_KHRONOS_validation"is in all 29 Vulkan test logs andwas not found but was requestedis in none;VUID-lines: 0 in all 40 runs, on main's sources and on the branch (no new ids). Head229fb74cb4onmain0510af2dcc.agc_driver_image_store_volume_through_planefails withimage descriptor is incompatible with the static runtime image interface(format 22), andagc_shader_memoryfails with the same message from the new unit case.agc_shader_memorypasses.image_store_volume_through_array,image_store_array_through_volume,image_store_face_on_cube,image_store_line_through_plane,image_store_line_through_plane_arrayandagc_shader_memory. The five neighbouring execution tests also pass on main.3725323f1f; the rebase touched none of these files): with only the z == 0 gate reverted and the 2D mode kept, the execution test fails withleg B (all z 1): texel (0, 0) with z 1 is 0x3f800000, expected 0xcdcdcdcd. Restored, it passes.verifyPlaneVolumeStoreMode: a write-only DIM 3D store on a 2D T# selects aDim2Dmode; withreadset it is refused; with a UINT 2D T# the store selectsDim2D, and flipping onlyatomicmakes it refused. The unit negatives were not mutation-tested.tools/debt_fold.py --check: pass.--show shaderagainstdocs/dev/debt/shader.md: the final sentence of this entry is the only change of ours (plus one unrelated fragment already on main).tools/check_conventions.py --base origin/main: 0 errors, 1 warning (debt length).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T13:01:00Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the code read supports the described write-only DIM 3D store behavior through a 2D T#.
What I ran
Reviewed head
229fb74cb46165f3bf166dffc709371a0ab86767. No commands or tests were run by me; the author reports Linux lavapipe tests and a separate RDNA2 hardware measurement. Readdescription.md,commits.md,diff.patch,manifest.json, and all included changed files. Read the changed lines and relevant context inShaderMemory.cppthroughrepo_read.py; that file was excluded from the review folder because of its size.files.jsonwas not available as a review document.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No tests were run independently. The reported hardware measurement and author-reported test results were not independently confirmed. Only changed-line neighborhoods and relevant context were read for
ShaderMemory.cpp, rather than its full text; all added lines in that file were inspected. No other changed file was excluded from reading.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T01:02:48Z.
Review: APPROVED
Reviewed — looks good
The inspected code implements the described 3D image store through a 2D view and retains the stated restrictions on reads and atomics.
What I ran
Reviewed head
f42bd82ad199a3a67122e238ecc2435822df4854usingrepo_read.pyto inspect the prepared diff and targeted repository code. I did not run commands or tests; test results in the description are author-reported.Results
Findings
Blocking
None in the code inspected.
Non-blocking
None.
Not verified
Read changed lines in
ResourceMaterializer.cpp,SpirvImageEmitter.cpp,ShaderMemory.cpp,ImageStoreVolumeThroughPlane.cpp, andfix-shader-3d-store-through-2d.md, plus the prepared description, commits, manifest, and diff.fix-volume-samples-on-2d-tsharp.mdis deleted and has no new lines to inspect. The full contents ofShaderMemory.cppand the deleted debt fragment were not read. Tests and hardware behavior were not independently verified; execution on PS5 gfx1013 and unmeasured formats, masks, mip levels, and z values remain unverified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T01:03:52Z.
Review: COMMENTED
f8ca6712-fc98-4049-9ccd-15aa3ff77868Reviewing files that changed from the base of the PR and between
335fd4626fandf42bd82ad1.core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/execution/ImageStoreVolumeThroughPlane.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cppdocs/dev/debt/changes/fix-shader-3d-store-through-2d.mddocs/dev/debt/changes/fix-volume-samples-on-2d-tsharp.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.