fix(shader): sample a 3D T# through DIM 2D_ARRAY as a volume #7381
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7381"
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 thuanquang on 2026-10-18T03:48:15Z.
What
Yakuza 0 Director's Cut (PPSA31327) stops a few seconds into its first cutscene (discussion #6722):
The pixel shader samples a 3D RGBA8 T# with DIM 2D_ARRAY image instructions. #5555 accepts 2D-array loads and stores on a 3D T#, and #5461 accepts biased DIM 2D samples of a one-slice volume, but a 2D-array sample of a volume has no runtime mode.
I measured what RDNA2 does with the hardware oracle template, run through the Windows driver's comgr and HIP runtime on an RX 6700 XT (gfx1031). On 16x16x4 R32_FLOAT 3D T#s with one and three levels,
image_sample,image_sample_landimage_sample_lzwith DIM 2D_ARRAY returned the same value as the same instruction with DIM 3D in all 256 lanes of 66 cases:image_sample_l.So the third address VGPR is the normalized r coordinate, addressed by the sampler's Z mode, not a layer index. These cases used wrap only: r = 1.0 reads slice 0 and r = 0.375 slice 1.
This change adds a Dim3D runtime mode for a 2D-array sampled image whose accesses are all
image_sample,image_sample_lorimage_sample_lz(new tracker flagvolumeArraySampleCompatible, the same instruction set ascubeFaceCompatible). The emitter already samples a Dim3D mode with the instruction's three coordinates, and the driver already binds a 3D T# as a 3D view withaddressModeWfrom CLAMP_Z, so neither needed a change.These keep throwing, because they are not measured:
image_get_lod;ImageResourcehas a new field, so the shader disk cache format goes from 40 to 41 and theImageResourcefield count from 39 to 40. (maintook 38, 39 and 40 for other format changes, and field count 39 for #5958's field, after this PR was opened.)Overlap:
ImageResourcefield and edit the samefieldCount<ImageResource>()line. As @klosixgaming-arch found, two PRs that make the same count edit merge without a conflict, and the result fails to build. Whichever lands second has to raise the count again.cubeFaceCompatibleline that the new flag's line follows, and the debt entry after the new one.FormatVersiontoo.Tested
Windows 11 26200, AMD Radeon RX 6700 XT (gfx1031), driver 32.0.21045.5002, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON,ANYPS5_REQUIRE_VULKAN=1:agc_driver_image_array_sample_on_volume: a compute shader on a 16x16x4 RGBA8 3D T# with a repeat point sampler.image_sample_lzwith DIM 3D and with DIM 2D_ARRAY, andimage_sample_lwith DIM 2D_ARRAY, are given r = (z + 0.5) / 4 + k for k from -1 to 2, and must return slice z.image_sample_lwith LOD 1 must return slice z / 2 of level 1, with DIM 3D and with DIM 2D_ARRAY. Each level has its own markers, so reading the LOD from the wrong register would fail.image_sample_bwith DIM 2D_ARRAY must still be refused.main2626e5ee7it fails with the title's message:image descriptor is incompatible with the static runtime image interface: descriptor format 56 decodes to {class 1, dim 4, conversion 0, packed 0, cube 0, depthBits 0, unorm16 0, srgb 0}.agc_shader_memory(verifyVolumeArrayLoadMode): the flag selects the Dim3D mode for a 3D T#, a 2D-array T# still selects the 2D-array mode, and without the flag a sample on a 3D T# is still refused.agc_shader_disk_cache: the new field round-trips.main7f596df48on 2026-10-19, head 1b3256848.mainhad takenFormatVersion40 andfieldCount<ImageResource>()39 (#5958) for other fields, so this now raises them to 41 and 40. Before this rebase the count edit merged silently withmain's identical one and the merge failed to build, as @klosixgaming-arch and @johandavidcm found.agc_driver_image_array_sample_on_volume,agc_shader_memoryandagc_shader_disk_cachepass 2 of 2 on 1b3256848 on the RX 6700 XT.ctest --parallel 4 --timeout 120onmain7f596df48with this change: 1604 tests, 17 fail, none from this PR:conventions_*andhardware_oracle_compare(CI'sconventionsjob passes on this head);guest_pthread_rwlockandguest_file_lock_process, under load;main's three known AMD failures:agc_driver_lds_mixed_width_atomics(#6976),agc_driver_lds_lock_budget(#7344),agc_driver_layered_volume_vertex_no_gpl(#4768);agc_driver_layered_volume_draw,agc_driver_layered_volume_vertex,agc_driver_draw_cache_reuse_offandagc_driver_stencil_replay_no_gpl(VK_ERROR_DEVICE_LOSTat the first submit). All four pass from renamed copies of their executables, so they hit stale entries in AMD's per-executable pipeline cache;agc_driver_store_idle_resultsfailed once and passed when rerun.1002:13c0, 32.0.21042.62). WithResourceMaterializer.cppandResourceTracker.cppset back tomain,agc_shader_memoryand the volume test fail on both. Nothing else in the 716-testagc_|shader|recompilerset changes status.ctest --parallel 4 --timeout 120onmain1e2d9b369with this change: 1463 tests. The only failures are three AMD GPU tests that fail without it on this machine too:agc_driver_lds_mixed_width_atomics(#6976),agc_driver_lds_lock_budget(#7344) andagc_driver_layered_volume_vertex_no_gpl(#4768).python tools/check_conventions.py --base origin/mainwith this title and body passes.Hardware measurement (RX 6700 XT, gfx1031, driver 32.0.21045.5002): DIM 2D_ARRAY vs DIM 3D, lane by lane
Each case runs the same instruction twice in separate processes, once with DIM 2D_ARRAY and once with DIM 3D, over 256 lanes in 2x2 quads, and compares all four returned components of every lane. The T# is a 16x16x4 R32_FLOAT volume (
SW_MODE9) over memory where every dword holds its own index, so a value names the dword (or blend) the hardware read. The sampler wraps in x, y and z, withMAX_LOD0xfff.image_sample_lzimage_sample_lzZ_FILTER0image_sample_lzimage_sampleimage_sample_lzimage_sample_l(LOD 1)With point filtering and one level, r = 0, 0.125 read slice 0, 0.375 slice 1, 0.5 and 0.625 slice 2, 0.875 slice 3, 1.0, 1.125, 2.0 and 3.0 slice 0, 1.5 slice 2 and -0.125 slice 3, for both DIM values.
image_loadwith DIM 2D_ARRAY takes the integer slice instead, as #5555 implements. With point filtering and three levels, lane 0 of a plainimage_samplewhose r steps by 2 slices across its quad reads dword 19456, as when u and v step by 2 texels, instead of the 23552 that a 1-texel step with constant r reads, with either DIM value. So r's derivative takes part in the LOD.Kernel core (the T# is built in s[24:31] from the input buffer address, the sampler in s[32:35]):
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)1002:13c0(@wachi35676), RTX 5090 (@klosixgaming-arch)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T03:59:41Z.
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.
main)core/shader/recompiler/ShaderDiskCache.cppL141-143core/shader/recompiler/ShaderDiskCache.hppL16core/shader/recompiler/ShaderDiskCache.hppL16core/shader/recompiler/ShaderDiskCache.hppL16Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/shader/recompiler/Optimization/src/ResourceMaterializer.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/Resources.hppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/ShaderDiskCache.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.hppdocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/Resources.hppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/Optimization/src/ResourceTracker.cppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.hppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/ShaderDiskCache.hppcore/shader/recompiler/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.hppcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/ShaderDiskCache.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/Optimization/src/ResourceTracker.cppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.hppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/Optimization/src/ResourceTracker.cppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.hppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/Resources.hppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/Optimization/src/ResourceTracker.cppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.hppcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/Resources.hppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/Optimization/src/ResourceTracker.cppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.hppImported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-18T14:57:54Z.
Second-GPU run on head
f405b7cae, Windows 11 Pro 26220, NVIDIA GeForce RTX 4070 (596.21), WinLibs MinGW-w64 GCC 15.2, Release. Stacked on maina62c724c3together with #7413 (d622a55dc); merges cleanly, no shared file. Targeted build (relinker, libs and the shader andagc_driver_*image/sample/shader/table/volume test executables), not a full build.agc_driver_image_array_sample_on_volume,agc_shader_memoryandagc_shader_disk_cachepass 3 of 3. The execution test ran on the RTX 4070 (no skip): DIM 3D and DIM 2D_ARRAYimage_sample_lz, DIM 2D_ARRAYimage_sample_l, and LOD 1 on the two-level volume all return the expected slice, so this GPU's sampler wraps r like the RX 6700 XT measurement, andimage_sample_bis still refused.ResourceMaterializer.cppandResourceTracker.cppset back to main, tests kept. The execution test fails with the title's message (image descriptor is incompatible with the static runtime image interface: descriptor format 56 decodes to {class 1, dim 4, ...}) andagc_shader_memoryfails. Restored, both pass.ctest -j1 --timeout 300 -R '^(agc_driver_(shader|table|descriptor|sample|image|volume|3d)|shader_|agc_shader_|scalar_call)': 81 of 81 pass, including the neighbouring volume and image-sample tests.check_conventions.py --base origin/mainpasses andgit diff --checkis clean.3e3e8b905) against the stack: no stop line, no driver failure, same dump content. They do not sample a 3D T# through 2D_ARRAY, so that says nothing about the change. PPSA31327 is not available to me.image_sample/_l/_lz, so the runtime image interface of those shaders gets one more variant even when no volume is bound. I did not measure a cost.Not checked: PPSA31327, the full
^agc_driver_pass and the non-GPU suite, SPIR-V validation withspirv-val, AMD/Intel, Linux.Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T00:13:09Z.
Tested at
f405b7caeon Windows 11 (GCC 15.2.0, Release), merged ontomain9f25d0bf5, on an RTX 5070 Ti (617.42) and an AMD Radeon iGPU, RDNA2 (1002:13c0, 32.0.21042.62,ANYPS5_GPU=AMD).agc_driver_image_array_sample_on_volume,agc_shader_memoryandagc_shader_disk_cachepass on both, and the volume test actually runs rather than skipping.agc_|shader|recompilerset, no test changes status againstmainon either GPU.ResourceMaterializer.cppandResourceTracker.cppset back tomain,agc_shader_memoryand the volume test fail on both GPUs withdescriptor format 56 decodes to {class 1, dim 4, ...}.Small wording point: the debt entry says the Z mode "wraps or clamps", but the measurement used wrap only.
AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-19T00:51:05Z.
Tested on Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA GeForce RTX 5090 (driver 617.42), Ryzen 9 9950X3D. Head
15882eaeamerged onto currentmain(a373e85e5). The merge is textually clean, but it does not build:Cause: this PR adds
volumeArraySampleCompatibletoImageResourceand changes the assertion on line 143 fromfieldCount<ImageResource>() == 38to== 39.mainhas since changed the same line to 39 for a different field (8545c2301), so git merges the two identical edits without a conflict and the result asserts 39 while the struct now has 40 fields. It needs a rebase and the count bumped to 40; it won't show a conflict or the "needs rebase" label.With only that assertion changed to
== 40on top of the merge, it builds andagc_shader_memory,agc_shader_bindlessandagc_driver_image_array_sample_on_volumepass here. I did not run Yakuza 0 (no dump). I did not review the new Dim3D sampling code line by line, so I am not approving yet.AI-assisted: yes. Written with AI assistance and reviewed by me.
Imported from boykopovar/AnyPS5. Originally posted by johandavidcm on 2026-10-19T02:35:24Z.
PPSA31327 (Yakuza 0 Director's Cut 01.015.000) with this branch, as asked. Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, RTX 4070 (617.42).
main40393b0f9with #6725 (c8f7fc06e), #6572 (fd301cc30) and 15882eaea, plus the bring-up discussion's local PlayGo file; #7199 is already inmain.main66702f1cfwith #6725, #6572 and #7199): the title stops a few seconds into the first cutscene withimage descriptor is incompatible with the static runtime image interface: descriptor format 56 decodes to {class 1, dim 4, ...}.autosave0000.sav. I closed it after about 5 minutes; the log has no stop line or driver failure, and the process exits with 0.To build on that
mainI had to setfieldCount<ImageResource>() == 40, as @klosixgaming-arch found.FormatVersionhas the same problem:mainalready went from 38 to 39 for another field, and this PR's 38 -> 39 merges silently with it, so after the rebase it stays at 39 althoughImageResourcegained a field again. It needs 40 too, or caches written bymain's format 39 are read with the new field order.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-19T07:22:10Z.
Thanks @klosixgaming-arch and @johandavidcm for catching the silent count merge, and @johandavidcm for the Yakuza 0 run. Rebased onto
main7f596df48(1b3256848):fieldCount<ImageResource>()is now 40:main's 39 (#5958's field) plus this PR's.FormatVersionis now 41, becausemainalready uses 40.On the RX 6700 XT the volume test,
agc_shader_memoryandagc_shader_disk_cachepass 2 of 2 on 1b3256848. The full suite onmain7f596df48with it shows no failure from this PR (details in the description).The body now lists your runs.
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-19T08:44:17Z.
Rebase handoff — rebased onto current
maincleanly (authorship unchanged).Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; full suite green apart from the four knownmainregressions (#5444 Mesa, #7584 BDA, #7766, #7784), none from this PR.To pick it up:
Head is
31890290d.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-19T08:44:31Z.
Correction: the pushed
rebase/7381was mid-rebase (a later PR's conflicted state). The correct clean branch is being re-pushed now — your PR rebased cleanly with no conflicts; head1b3256848content, builds and full suite pending the re-verification. Apologies for the noise.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-19T08:47:35Z.
The clean branch is re-pushed: head
f3ab91fcc, builds, conventions pass, full suite green apart from the four knownmainregressions (agc_driver_tessellation— Mesa #5444;agc_driver_bda_device— #7584;agc_driver_image_table_vouched_lookups— #7766;agc_driver_guest_memory_lifetime— #7784), none from this PR. To pick up:git fetch https://github.com/blawesom/AnyPS5 rebase/7381thengit merge --ff-only FETCH_HEADon your branch.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T19:40:24Z.
Checked the tracker and materializer changes (loads, gathers, bias, comparison and mixed load+sample all clear the flag; a real 2D-array T# still picks the 2D-array mode), the execution test (it fails on
mainwith the title's message and pins the slice and LOD markers), the cache version/field count bumps and the debt entry.mainmoved under the PR: thecubeFaceStoreline inResourceTracker.cppand the extended cube entry indocs/dev/debt/shader.mdconflicted with it, so I rebased keeping both. The Build run on the rebased head is the gate; merged.