feat(shader): split unused-result 64-bit bitwise buffer atomics without shaderBufferInt64Atomics #11510
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11510"
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 morten-holm on 2026-10-26T17:40:13Z.
What
A 64-bit
buffer_atomic_or,andorxorcompiles on a device withoutshaderBufferInt64Atomicswhen the instruction result is not used.The recompiler now emits two 32-bit atomics on the low and high dwords of the 64-bit address. The 64-bit alignment and bounds checks stay. Each dword is atomic. The pair is not atomic as one 64-bit operation.
Other 64-bit buffer atomics, and any atomic whose result is read, still fail with "64-bit buffer atomics need shaderBufferInt64Atomics". The limit is listed in
docs/dev/debt/shader.md.MoltenVK and KosmicKrisp do not expose
shaderBufferInt64Atomics.Tested
agc_shader_memory_testspasses. New cases: OR, AND and XOR compile without the capability and do not declare Int64Atomics. They declare it when the device has it. An OR with a stored result and an ADD still fail.mainand on this change withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(validation layer 1.4.363, x86-64): both exit 0. Neither log has "was not found but was requested". Neither has aVUID-line. This test creates no Vulkan device, so the layer was not exercised. These runs used an oldermainbase than this branch.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T17:44:21Z.
Review: CHANGES_REQUESTED
Two validation gaps remain before this shader change is ready to merge:
Int64Atomics. They would still pass if the emitter accidentally dropped the atomic. Please inspect the emitted SPIR-V and assert that each OR/AND/XOR case contains the expected two 32-bit atomic operations, including the low/high dword addresses.CONTRIBUTING.mdrequires the same focused AGC test on currentmainand the change, on the same machine and GPU, with the requested Vulkan environment and validation comparison. The description says themainrun used an older base than this branch. Please rerun both at current base88795ed44801fa719eb2df990cbe1f11a1f9bd81and this head, then record the exact commits, GPU vendor/model, driver and OS, missing-layer check, and anyVUID-differences. The hosted product and relinker jobs are currently skipped, so they do not supply this comparison.Local
tools/check_conventions.pyandgit show --checkpass. I have not run the focused AGC test locally; the current-main build for the separate #11481 reproduction is still compiling. Changes requested for the test assertion and required current-base validation, not for a demonstrated runtime defect.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T10:17:33Z.
Review: COMMENTED
Clean
mainvs this head on Linux, since macOS can't buildmain.Linux run: Ubuntu 26.04, GCC 15.2, Release. RTX 3070 (NVIDIA 595.99.02) and lavapipe (Mesa 26.0.3), one at a time via
VK_DRIVER_FILES. Khronos validation layer 1.4.341 withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1;VK_LOADER_DEBUG=layershows the layer inserted, no "was not found but was requested", 0VUID-lines.Base
main808a557ac(newer than88795ed448; the merge of9ebcc241fis clean).main+ only this PR'stests/ShaderMemory.cpp:agc_shader_memoryfails with64-bit buffer atomics need shaderBufferInt64Atomics. So the new cases do catch the missing split.mainalone:agc_shader_memorypasses.main+ this PR (merge --no-commit):agc_shader_memorypasses 3/3.agc_driver_buffer_atomics*,agc_driver_global_atomics64andagc_driver_image_atomics64pass 3/3 on both devices (7/7 per run).agc_shader_memorycreates no Vulkan device, so the layer only covers the execution tests. Both devices here exposeshaderBufferInt64Atomics, so the split itself doesn't run on GPU here. These runs show the native path doesn't change.^agcsuite (no flip/display/lds64,-j1): 3070 1052/1052, lavapipe 1051/1052. The one failure isagc_driver_multisample_retirement, which also fails onmain.public_headerspasses.GPUs tested: NVIDIA RTX 3070 (Linux), lavapipe.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T22:06:02Z.
Review: CHANGES_REQUESTED
Reviewing exact head
990a69fa06c1a229d56cdb7aa6ffe44952e2d83d.What I ran
88795ed448with currentmain319621ba2e: current main has since changedcore/libs/prx/libSceAgcDriver/Execution/src/ShaderMemory.cpp,core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp, and related AGC shader tests.Results
808a557; current main changed AGC shader-memory implementation and testsFindings
Blocking
mainand the PR for shader-recompiler changes, usingANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1, and the Khronos validation layer, with logs compared for missing-layer warnings and new VUIDs. The posted comparison used main808a557, while this PR is still based on88795edand current main is319621ba; current main has changed the AGC shader-memory implementation and test sources since then. Please rebase or otherwise test the PR against current main and post the matched focused results before approval.Non-blocking
agc_shader_memorycreates no Vulkan device. Ensure the matched comparison includes a Vulkan-using focused test so the layer is actually inserted and can check for VUIDs.Sources
Not verified
To get this to a good state
Rebase or test against current main, post the same focused checks on both trees with the required layer active, and include a Vulkan-using test in the validation comparison; then request a re-review.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T17:08:27Z.
Review: COMMENTED
Matched current-
mainrun of head990a69fa0, plus the cause of the NVIDIA CI failure on this head.Linux: Ubuntu 26.04, GCC 15.2, Release. RTX 3070 (NVIDIA 595.99.02) and lavapipe (Mesa 26.0.3), one at a time via
VK_DRIVER_FILES. Khronos validation layer 1.4.341,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1. Basemainf91137142; the head merges onto it cleanly.main+ this PR'sShaderMemory.cpponlyagc_shader_memoryfails:64-bit buffer atomics need shaderBufferInt64Atomicsagc_shader_memory+buffer_atomics*+global_atomics64+image_atomics64VUID-VUID-^agcsuite (no display/flip/lds64),-j1 --timeout 30The one RTX 3070 failure is
agc_driver_graphics_maps_fallbacktiming out at 30 s, which also times out onmainhere under load.public_headerspasses. The layer was inserted in the 6 device tests;agc_shader_memorycreates no device, as noted before.The NVIDIA CI failure is not NVIDIA-specific; it comes from
ANYPS5_ENABLE_SPIRV_TOOLS=ON. The CI builds with it; the build above does not. I rebuiltagc_shader_memory_testsfrom the same merge with-DANYPS5_ENABLE_SPIRV_TOOLS=ONand it fails without any GPU, with the CI's message:an unused-result bitwise buffer atomic was not emitted as two 32-bit atomics.With the option on,
RecompilerunsValidateAndOptimizeSpirv, andverifySplitsees the optimized module. I dumped the module the OR case compiles to. The entry function has no atomic left: it computes the buffer address and bounds compares, then returns. The only atomics left are in the helper function (one 32-bitOpAtomicOrwith a constant 1, a compare-exchange and an atomic store). The native compile of the same program (CapabilityInt64Atomics) loses its 64-bit atomic the same way. So the optimizer drops the test program's buffer atomic in both modes, andverifySplitfinds 0 halves. That is a test problem, not a sign that the split emits the wrong thing.Possible fixes: skip
verifySplitunder#if ANYPS5_ENABLE_SPIRV_TOOLS, or give the test program an atomic that the optimizer keeps. Thedeclares(...)checks still pass with the option on, because the capability stays declared after the instruction is removed.GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02, Linux); lavapipe (Mesa 26.0.3). As before, neither device runs the split at execution time, because both have
shaderBufferInt64Atomics.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T18:13:06Z.
Review: COMMENTED
Follow-up to my earlier note on the NVIDIA CI failure (
ANYPS5_ENABLE_SPIRV_TOOLS=ON): I traced why the optimizer drops the atomic. It is the test's buffer descriptor, not the split and not the optimizer.Head
990a69fa0merged ontomainf91137142, Linux, GCC 15.2, Release, SPIRV-Tools from the submodule. No GPU is involved;agc_shader_memorynever creates a device.What removes it. I dumped the module before optimization (
APS5_SPIRV_OPT=none) and ran AnyPS5's default pass list one prefix at a time. All 5 atomics survive untildead-branch-elimright afterccp, which removes the two splitOpAtomicOrs. Withoutccpthey stay. There is noOpUndefin the module, so this is not undefined-value folding.Why. The recompiler already emits the bounds check as a constant false:
%155 = OpLogicalAnd %bool %153 %false. The test's V# is256u, 0x01016facuwith stride 0 (word 1 bits 16-29).0x01016fachas OOB_SELECT (bits 28-29) = 0, the structured mode, andbyteAddresschecksindex < num_records && offset < stridethere. With stride 0 every access is out of bounds, so the atomic is dead code, and dropping it is correct. The native 64-bit compile ends up with no atomic for the same reason. Without SPIRV-Tools nothing folds the branch, soverifySplitsees the atomics in the dead block.Production impact: none that I can see. A real out-of-range buffer atomic is dropped the same way, and the 0-halves result comes from the test's descriptor.
Fix (test only), verified:
0x31016facusets OOB_SELECT = 3 (raw), so the access at offset 0 of the 256-byte buffer is in bounds.v0instead ofv40. The atomic needs both changes to pass. With only the first, the atomic survives, butv40/v41are never written, so the data is the constant 0.ccpthen folds bothOpUConverthalves to%uint_0, and the lastverifySplitcheck fails ("do not take the low and high dwords of the operand").v0is the invocation id and stays variable.agc_shader_memoryThe red should be unchanged: on
main, the first OR compile withoutshaderBufferInt64Atomicsthrows beforeverifySplitruns, whatever the V# and vdata are. I did not rerun that part.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T23:09:33Z.
Review: COMMENTED
Re-run of head
c12f979291for the matched-run request. The SPIRV-Tools ON failure is fixed.Linux (Ubuntu 26.04, GCC 15.2, Release), merged onto current
main7fcab08f71, and the same tests on thatmainalone. lavapipe (Mesa 26.0.3),ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, Khronos validation layer 1.4.341.main7fcab08f71main+c12f979291agc_shader_memory, the 4agc_driver_buffer_atomics*,global_atomics64,image_atomics64VUID-VUID-agc_shader_memoryc12f979291reverted (old test)an unused-result bitwise buffer atomic was not emitted as two 32-bit atomicsThe last row is the NVIDIA CI failure, reproduced without a GPU. The fixed test also covers the OR-with-OR and OR-with-AND programs, with
v2as the second vdata.The NVIDIA CI has not reported on this head yet. I did not rerun the 3070, since the failure did not depend on the GPU.
GPUs tested: lavapipe (Mesa 26.0.3), Ubuntu 26.04
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.