fix(shader): gather a 3D image's image_gather4_lz from one slice as measured #9183
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9183"
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 fma-rc on 2026-10-21T14:34:56Z.
What
image_gather4_lzthrough a 3D T# was emitted asOpImageGatheron a 3D image, which SPIR-V does not allow (gathers take 2D, cube and rect images). NVIDIA's compiler dies on it with SIGILL, RADV crashes, and lavapipe refuses the pipeline (vkCreateComputePipelines: Vulkan result -13). Death Stranding 2 (PPSA02015) has such a compute shader (0xc280112c00) and stops there: NVIDIA with SIGILL at 157 s, the 680M with a crash (rc 139).The hardware gathers four texels of one slice. Measured on a Radeon 610M (gfx1036) with the hardware oracle, 3742 rows over every clamp mode and border color:
The recompiler now emits four
OpImageFetchreads with that addressing. The sampler state reaches the shader as a specialization constant, or through the image's runtime metadata in registration modules. A border color table, a swizzled or integer texture with border addressing, image or sampler tables, unnormalized coordinates and samplers that disagree throw. The shader debt file records the measurement. Probes, results and the model check: evidence/gather-3d-volume (checkall.pymatches all 3742 rows).@mrfelek found the same shader in #5424 (comment) and fixed it on their fork (
fix/volume-gather-lz), without a PR, with four level-zero samples at the footprint's texel centres, from a Radeon 780M measurement of the slice choice and of wrap and clamp on it. This PR fetches the texels instead, because the measurement above shows that the sampler's filters, LOD clamp and bias do not change a gather, and it adds the per-axis modes, the 1/256 snap, the half-border modes and the border colors.Tested
Arch Linux, rebased on
main4f41f4c375(2026-11-03,3cb6fb3ebb). Withmain's own newImageResourcefields the info encoder now counts 50 fields and the record stays 108 bytes. The two checks that expected the unimplemented border paths to throw are dropped. The FreeType submodule ismain's again (my earlier rebase had moved it back to 2.13.3).agc_driver_image_*,agc_shader_*,agc_shader_disk_cache*) pass on the RTX 5080, RADV (Radeon 610M) and lavapipe, except three that skip on RADV (agc_driver_image_array_rows_past_layer_limit,agc_driver_image_array_window_past_layer_limit,agc_driver_image_table_vouched_lookups). The Windows build and ctest pass (3919 of 3919), with no failure the merge base lacks.OpSRemwith a negative operand is undefined in Vulkan withoutmaintenance8, and the NVIDIA RTX 2000 Ada in CI returned 3 for -1 mod 7.agc_driver_image_gather_volumenow also fails if the gather shader containsOpSRemorOpSMod; it fails ate92ec413c9(test only) and passes with the fix.agc_driver_image_gather_volume: red channel, alpha and blue gathers over all eight clamp modes and three border colors, an odd 7x5x3 volume, per-axis modes, rounding ties and denormal coordinates, a 241-texel-wide volume at 1/256 boundaries, a base level, a swizzle, null images, a vertex-shader variant through the registration path, and a gather next to a 3D sample through another sampler. Expected values come from the measured model.mainthe test fails on every device: NVIDIA RTX 5080 SIGILL (132), Radeon 610M and 680M crash (139), lavapipevkCreateComputePipelines: Vulkan result -13, llvmpipe rc 1. With the PR it passes on all five.main's extent and passes with the fix.agc_driver_image_gather_one_dimensional,image_converted_unorm,image_sample_reduction,image_sint8,image_srgb_load,image_sample_unnormalizedpass onmainand with the PR on the RTX 5080, 610M and lavapipe.conventions_env_reference,conventions_blob_reads,agc_driver_f64_denorm_preserve_spirv,agc_driver_f16_to_f32_unpack_spirv, the threenet_dontwait_blocking_send*) fail the same way on the merge base on this machine.mainwith PR 5426, PR 7978, PR 6565, PR 6182, PR 8223 and our multisampled-target retire change, which it needs to reach this shader: without this PR the RTX 5080 stops with SIGILL in the shader compiler at 157 s and the 680M crashes; with it both run on to the next stop,color targets with fewer fragments than samples (EQAA) are unsupported(RTX 5080 at 86 s, frame 88; 680M at 228 s, frame 63, picture visible).tools/check_conventions.py --base origin/mainpasses.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)Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T00:01:48Z.
Review: COMMENTED
First Apple GPU / MoltenVK run. It confirms the bug here as a distinct vendor failure, shows the fix clears it, and surfaces one case in the new test that cannot run on this device.
Machine: Apple M2 Max, macOS 27.2, x86_64 under Rosetta 2. Vulkan loader + MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0). Release,
BUILD_TESTING=ON.Base/method: PR #8658
feat/macos-port@a1fb8e3e9c(currentmaina6dcea9279plus the macOS port), notmain—maindoes not build on macOS. This PR's diff (git diff merge-base..df4fd534d -- . ':!docs') applied on top, clean.Negative control (revert the production files to the PR's base, keep the new
ImageGatherVolume.cpp):agc_driver_image_gather_volumefails at pipeline creation. MoltenVK translates theOpImageGatheron a 3D image to MSL and Metal refuses it:So this is a fourth vendor's manifestation of the same bug the PR fixes: alongside the RTX 5080 SIGILL, the RADV crash and lavapipe's
-13, MoltenVK rejectstexture3d.gatherat MSL compile withVK_ERROR_INITIALIZATION_FAILED.With this PR: the shader compiles (the fix emits
OpImageFetchinstead), so the pipeline-creation failure is gone. The test then aborts on a Metal device limit, at the3001-texel-wide volume case:Metal caps a 3D texture at 2048 on this GPU (
maxImageDimension3Dis 2048 on MoltenVK here), and the 1/256-boundary case asks for 3001, which trips a hard Metal assertion that takes down the whole test. The fix itself is fine on MoltenVK — the gather lowering compiles and the pipeline builds; it is the test that can't run to completion here. AmaxImageDimension3Dguard on the wide-volume case (skip, or clamp the width) would let it run on Apple and on any device with a 2048 3D limit.I could not get the test past that case to check the gathered values on MoltenVK, so this is not a value check — only the compile (red→green) and the device-limit abort.
GPUs tested: Apple M2 Max (MoltenVK 1.4.2).
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-22T00:36:38Z.
Thanks @jotitadev, the MoltenVK compile failure is a good fourth data point. You're right that 3001 was too wide: Vulkan only guarantees
maxImageDimension3Dof 256. a8779a382d moves that case to a 241 texel wide volume, which every device can create, with 32 new coordinates that each land a texel apart depending on whether u times the width is rounded to float before the 1/256 snap or taken exactly, the same property the 3001 inputs had. It passes on NVIDIA, RADV and lavapipe here and still fails at that case with the recompiler from before the exact product, so it should now run to the end on your M2.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T08:11:36Z.
Review: DISMISSED
The hardware evidence and the expanded coordinate/clamp coverage are unusually useful. I reviewed head
a8779a382d3655ba1376b753cf76bc423247b56and compiled the new focused test. I need two repository requirements completed before this is ready:The checklist says this is based on current
mainata806c69bfe, but that is the merge base and the PR is 1,198 commits behind the currentmain(d6eafa54d0). The product build jobs for this head are skipped, so the reported device results do not validate the current merge base. Please update the branch, correct the checklist, and rerun the focused test against the updated code (or a current-main merge commit) on a supported host. My exact-head Release build ofagc_driver_image_gather_volume_testssucceeded. I attempted its CTest run with lavapipe, but the test process exits before Vulkan initialization because this host's Intel Xeon E5-1620 v2 lacks the required LZCNT, BMI1, BMI2, MOVBE, AVX2 and FMA extensions. I therefore could not independently execute the value checks here.CONTRIBUTING.md requires the Game bring-up discussion to list the open PRs and local changes the title still needs. The current PPSA02015 discussion (#5424) does not list this PR. Please update it with #9183 and the outstanding work needed to reach the shader; the PR description says the reproduction also needs #8223, #9186 and the local multisampled-target-retire change.
Local checks on this head:
git diff --checkpassed; the conventions command exited 0 with one warning that the new debt entry is 1,026 characters, over the 1,000-character guideline. The focused test target compiled. Its execution was blocked by this host CPU check, as described above.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T08:26:06Z.
Review: COMMENTED
Re-ran a8779a382 on the M2 after the 241-wide change. The test now runs to the end on MoltenVK. The new wide case also fails without the exact product here, as it does on your GPUs.
Machine: Apple M2 Max, macOS 27.2, x86_64 under Rosetta 2. Release,
BUILD_TESTING=ON.Drivers: MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), and MoltenVK main + SPIRV-Cross #2704.
Base/method: PR #8658
feat/macos-port@ee0a438415(currentmainplus the macOS port), notmain, which does not build on macOS. This PR's diff (git diff merge-base..a8779a382 -- . ':!docs') applied on top, clean. Full rebuild before each run.agc_driver_image_gather_volumepasses 3 of 3 on both drivers. The Metalwidth (3001) greater than the maximum allowed size of 2048abort from my earlier run is gone, so this is now a full value check on Apple, not just the compile.no member named 'gather' in 'metal::texture3d<...>',vkCreateComputePipelinesresult -3).3D gather of red, wrap: thread 26 component 0 is 98/255, expected 2/255, because that commit also predates the addressing-mode reduction. So I ran only the 241-wide case through a local one-off patch (not part of the PR). It fails on both drivers with3D gather of red from a 241 texel wide volume at 1/256 texel boundaries: thread 0 component 0 is 243/255, expected 242/255. With the full PR, the same case alone passes 3 of 3.^agcsuite with the PR:-j1 --timeout 30, 857 tests. Base: 17 failures with MoltenVK 1.4.2 and 16 with main + #2704. With the PR there is one more on each driver:agc_driver_uint8x4_color_targeton 1.4.2 andagc_driver_cross_workgroup_flagon main + #2704. Both also fail intermittently on the base without this PR, with the same messages (a UINT16_ABGR export byte mismatch, anda workgroup did not see another workgroup's flag store). Neither involves a 3D gather. No timeouts.GPUs tested: Apple M2 Max (MoltenVK 1.4.2; MoltenVK main + SPIRV-Cross #2704)
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T13:19:41Z.
Review: APPROVED
Reviewed — approved
The 3D
image_gather4_lzlowering merges cleanly, builds, and passes the focused image, gather and disk cache tests on lavapipe. The new test fails withmain's recompiler. Two things were not checked here: the measured hardware model (no AMD GPU on this machine) and the bring-up list. The only new validation IDs come frommain's sampler creation, not from this change.What I ran
Head
3cb6fb3ebb3fa6d30b8a373c3a006504f6247445,main4f41f4c375f5abb487dbd184fbc150f31994d762, merged tree8d1e202a94108a3eba9754cfc8d4744b136fc146. Debian 13 VM (Xeon Gold 6136, AVX2/FMA), GCC 14.2.0, Release, Ninja. Vulkan was lavapipe (Mesa 26.1.6, LLVM 19); there is no GPU.Results
git diff --checkcheck_conventions.pylibs(script)mainagc_driver_image_sample_lod_clamp, a device limitation)agc_driver_image_gather_volumeVUID-lines, all in the new test, all fromvkCreateSamplerwithMIRROR_CLAMP_TO_EDGE(see Non-blocking)git status --porcelainemptyNew validation IDs in agc_driver_image_gather_volume
Negative control
I restored the eight production files from
main:Resources.hpp,ResourceMaterializer.hpp/.cpp,DescriptorBindingBuilder.cpp,ResourceTracker.cpp,PipelineSpecialization.hpp,ShaderDiskCache.cppandSpirvImageEmitter.cpp. I kept the new test and rebuilt it. It fails on the first case:Output
This matches the description's lavapipe result on
main(pipeline refused). I then restored the merged files, rebuilt everything, and the test passed again.Findings
Blocking
None.
Non-blocking
main's missingsamplerMirrorClampToEdgeenablement (core/libs/prx/libSceAgcDriver/Graphics/src/GuestSamplerResource.cpp:32-44).VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGEthroughtoVkAddressMode.core/enablessamplerMirrorClampToEdgeorVK_KHR_sampler_mirror_clamp_to_edge.mainand are listed as new only because the test does not exist there.vkCreateSamplerfor every guest sampler with those modes. Fixing it is a separate change: enable the feature, or throw when it is unavailable. It is worth a debt entry or a follow-up issue.docs/dev/debt/shader.mdcorrectly says the model comes from gfx1036, not the PS5's gfx1013. The 4.0 clamp bound and the half-border pinning are the parts most likely to differ between RDNA2 parts. A later run on a second RDNA2 GPU would firm them up. Not required for this PR.Earlier review points, checked on this head:
RunThrowschecks are gone.3rdparty/freetypeis no longer in the diff.SpirvImageEmitter.cpp:925-928adds one period and usesOpUModwith a nonzero divisor (the extent isUMax(size, 1)). The test rejects anyOpSRemorOpSModin the gather shader.I also checked by hand:
EmitVolumeGatherLz(SpirvImageEmitter.cpp:839): the rounding bias for negative values, the 64-bit shift split at shift 32, and denormals.RuntimeAbi::CompareStateMask(13 bits) for registration modules.Not verified
checkall.py. Everything here is lavapipe only.