fix(shader): act on the containing dword for unaligned 32-bit buffer atomics #6094
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6094"
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 n-delic on 2026-10-14T21:44:36Z.
What
A 32-bit buffer atomic whose address is not a multiple of 4 now acts on the dword that holds the address. On
mainit records an unaligned BDA fault and is dropped. 64-bit buffer atomics are unchanged: off an 8-byte boundary they still fault.Source: section 8.1.7 ("Alignment") of the RDNA2 ISA:
That is mode DWORD of
SH_MEM_CONFIG.alignment_mode. The console's mode is unknown (as the existing "V# bases off a DWORD boundary" entry already notes).buffer_atomic_or(MUBUF 0x3a) at odd byte offsets in a compute shader. In the strict modes, section 3.11 reports a misaligned atomic as a memory violation, so the console is not in one of those.All of this is recorded in
docs/dev/debt/shader.md.Tested
Linux (Pop!_OS, kernel 7.1.5), GCC, Release.
New
agc_driver_buffer_atomic_unaligned: 32 lanes each runbuffer_atomic_add(glc) of 1 at byte offsetlane * 4 + k, for k = 0 to 3. The test checks that:On
mainit fails at k = 1 (lane 0 returned 3735928559, expected 0).agc_shader_memory: the specialized 32-bitbuffer_atomic_incno longer emits arecord_bda_faultcall.agc_driver_buffer_atomics,_float,_inc_dec64,_or_swap64: pass.ctest -R 'agc|shader': 563 of 563 pass.agc_driver_preparation_scope_settlefailed once and passed on reruns; it also failed intermittently on the rebased #5176 branch, which does not touch it.MXGP 26: with this change (on a branch with other local fixes), the title runs with 0 BDA faults, where it reported
reason=7(unaligned) faults before.tools/check_conventions.py --base upstream/mainpasses.Not tested: AMD hardware, the hardware oracle, Windows.
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 fma-rc on 2026-10-15T00:12:09Z.
I ran the unaligned case on real RDNA2 with
tools/hw-oracle: gfx1036 (Ryzen 7 7800X3D iGPU), Linux 7.2 KFD, wave32, raw buffer V# (word30x31016fac), ieee 0, dx10_clamp 1, denorm32 0, denorm16 3, round 0, coarse memory. KFD programsSH_MEM_CONFIG.alignment_modeas UNALIGNED for gfx10 (kfd_device_queue_manager_v10.c).buffer_atomic_or/buffer_atomic_add(with and withoutglc) at byte offsets 1, 2 and 3 abort the dispatch: the queue dies and the oracle exits with no result. Offsets 0, 4 and 8 act on that dword (or 0xffat 4 turns0x55667788into0x556677ff, returns the old dword). As a control on the same queue,buffer_load_dwordat offsets 1/2/3/5 reads byte-shifted (0x88112233,0x77881122,0x66778811,0xcc556677), so the queue really is in UNALIGNED mode.So on gfx1036 a misaligned atomic faults in UNALIGNED mode too, not only in the strict modes. If gfx1013 behaves the same, DWORD mode is the only one where MXGP's atomics would run, which is what this PR models. With this PR on
mainab9a47684,agc_shader_memoryandagc_driver_buffer_atomic_unalignedpass on NVIDIA RTX 5080, RADV and lavapipe.Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-15T06:57:48Z.
MXGP 26 (PPSA30839), the title in the description, on Linux: Ubuntu 24.04, GCC 13.3, Release, RTX 4070 Ti (NVIDIA 595.99),
maind92a8dad3with #6160 merged (it needs that to get past itss_swappc_b64stop at 135 s), relinked with--to-intel, 180 s runs with pad input.BDA access failed: ... instruction=0xa08 bytes=4 stage=4 reason=736 and 70 times in two runs.6c188638aadded (clean merge): 2 of 2 runs reach the 180 s limit with none of those lines. A run with screenshots reaches the title screen and the "Welcome to MXGP26" account prompt.Not checked on Windows, and nothing here says what the console does with the misaligned atomic.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-10-15T09:19:19Z.
Windows run, for the "Not tested: ... Windows" line. Windows 11 (26200), RTX 3060 Laptop GPU (NVIDIA 617.42), WinLibs GCC 15.2.0 r7 (UCRT), Release,
BUILD_TESTING=ON. Head6c188638amerged ontomainc0be1f69b(clean);ANYPS5_GPU=3060, and the test log shows the RTX 3060 selected.agc_driver_buffer_atomic_unaligned,agc_shader_memory,agc_driver_buffer_atomics,_float,_inc_dec64,_or_swap64: pass.SpirvRuntimeBuffer.cppfrommainand the PR's tests (2 of 2 runs):agc_driver_buffer_atomic_unalignedfails:buffer_atomic_add at byte offset 1: lane 0 returned 3735928559, expected 0.agc_shader_memoryfails:specialized buffer atomic: a 32-bit atomic records an unaligned fault instead of acting on its dword.ctest -R "agc|shader|guest_playgo" -j4: 580/580 pass with the PR.main: 578/579. Both skip the same 3 tests (agc_host_import_sparse,agc_driver_sparse_dma_buf_import,agc_driver_stencil_ref_export).mainfailure wasagc_driver_resource_cache_storage_admission(numerical exception, once under-j4). It passed 2 of 2 when run alone.Not run: MXGP 26, the hardware oracle.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:14:39Z.
Some 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/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mdImported from boykopovar/AnyPS5. Originally posted by erm14254 on 2026-10-15T13:11:53Z.
Code Violet (PPSA26528, Unreal Engine 5.5) on Windows: Windows 11 (10.0.22631), RTX PRO 6000 Blackwell Workstation Edition (NVIDIA 597.16), WinLibs GCC 15.2.0 r7, Release.
maind92a8dad3with #6258 and the three other fixes listed in #6256 (the title needs them to reach its title screen), then this PR's head 6c188638a cherry-picked on top (clean).deferred write-back failed: BDA access failed: ... instruction=0x7bc bytes=4 stage=4 reason=7, once per present at the title screen (a compute shader).agc_driver_buffer_atomic_unaligned,agc_shader_memoryandagc_driver_gds_append_consumepass on that build.Nothing here says what the console does with the misaligned atomic either.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-17T00:01:01Z.
Checked the change against the RDNA2 ISA §8.1.7 (DWORD alignment mode), built and ran
agc_shader_memory,agc_driver_buffer_atomic_unalignedand theagc_driver_buffer_atomics*tests on RADV, and confirmed the two new tests fail without theSpirvRuntimeBuffer.cppchange. Windows, NVIDIA and title runs from fma-rc, zaryabzip, milescoviello and erm14254 agree; merging.Minor, not blocking: the
docs/dev/debt/shader.mdline says the UNALIGNED-mode behaviour is not measured, but fma-rc measured above that misaligned atomics abort the dispatch there. Worth updating in a follow-up.Imported from boykopovar/AnyPS5. Originally posted by keravyn-ops on 2026-10-17T08:33:21Z.
AMD / Windows run of this PR at 6c188638a: Radeon 780M (RDNA 3, 0x15bf), AMD driver 25.10.20.01 (32.0.21020.1007), Windows 11 Home 10.0.26100, WinLibs GCC 15.2.0 r7, Release.
agc_driver_buffer_atomic_unaligned: pass (buffer atomic unaligned tests passed, 0.69 s)agc_shader_memory: pass (0.50 s)AI-assisted: yes (runs made on the device above).