fix(agc): write copied buffers back before reporting an unaligned BDA access #6373
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6373"
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 AlxcBTW on 2026-10-15T13:27:29Z.
What
Fixes to the deferred write-back of an unaligned BDA (buffer device address) access, found in Sword of the Sea (PPSA25344) cave gameplay.
fix(agc): rate-limit the deferred report of an unaligned BDA access. About 1,500-2,000deferred write-back failed: BDA access failed ... bytes=4 stage=4 reason=7lines appear per cave row (unaligned 4-byte atomics at pc0x5c8), each formatted on the queue worker.BdaResources::CheckFaultthrowsBdaUnalignedAccessfor that fault and the recorder prints the first 8 reports whole, then every 1024th with the running count. Every other deferred failure is printed each time.fix(agc): write copied buffers back before reporting an unaligned BDA access.ShaderResources::WriteBackBuffers()calledCheckFault()beforeguestMemory.WriteBack(), so a dispatch that recorded an unaligned access lost the stores of all its other invocations, although the shader only skips that access. For that fault the write-back now happens first and the report follows.fix(agc): publish after an unaligned BDA access only when it is the only fault. The fault record keeps the first fault of a dispatch, so an early unaligned access could hide a later unmapped or permission fault. The shader now sets a stickyotherFaultsflag (the former reserved word of the record) for every fault of another kind; an unaligned record with that flag set fails the command like any other fault and publishes nothing.fix(agc): write storage images back before reporting an unaligned BDA access. The synchronousShaderResources::WriteBack()threw before marking the written storage images dirty; it now handles them first and rethrows, as the deferred path does.fix(agc): rate-limit the deferred unaligned BDA reports per instruction. The throttle counter is kept per program counter instead of process-wide, and the periodic line names the pc.The root cause of the unaligned 4-byte atomics is still open; this PR does not fix it. It only stops the log flood and the lost stores.
Tested
Linux, lavapipe (llvmpipe), fork CI run 38943606573 on the PR head
69b683a90:agc_|shader|recompiler|spirv|video_out: 632 of 633 pass.agc_driver_mesh_index_cacheaborts withLLVM ERROR: Cannot emit physreg copy instruction(lavapipe shader compile) on the PR base03c4cb5e7(38950206046) and on the head before these fixesc0588d274(38947969934), and passes onorigin/mainf26eb67c8(38947975043); it is a stale-base failure, not caused by this PR.agc_recorder_deferred_failure_report(12 other failures print 12 lines, 12 unaligned reports at one pc print 8, the 1024th prints the count line with the pc, another pc prints its own first 8); a block intests/BdaResources.cpp(an unaligned fault publishes the other stores and is reported; an unmapped fault, and an unaligned fault with another fault kind recorded, publish nothing);tests/BdaExecution.cppruns a shader that records two faults in either order and checks the first reason is kept and the sticky flag is set only for a non-unaligned fault.WriteBack()has no test: the mock device of the resource tests creates no images and no test drives a synchronous draw with a fault.origin/main03c4cb5e7; Windows 11, MinGW-w64 GCC 15.2: the libs compiled on that head (fork CI run 38782444478);ctestwas not run on Windows, and the new commits were not built on Windows.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 github-actions[bot] on 2026-10-15T13:33:23Z.
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/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cppL247core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppL5488-5493Some 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/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/shader/recompiler/BdaAbi.hppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/shader/recompiler/SpirvBackend/src/SpirvBdaFault.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/shader/recompiler/BdaAbi.hppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtImported from boykopovar/AnyPS5. Originally posted by Neithennn on 2026-10-15T15:30:37Z.
Windows NVIDIA run, since
ctestwas not run for this PR: three existing tests fail with it and pass on main.Windows 11 Pro 26200, NVIDIA GeForce RTX 4080 (driver 617.42), AMD Ryzen 7 5800X, WinLibs GCC 15.2.0 r7, Ninja, Release, bundled dependencies,
BUILD_TESTING=ON,ANYPS5_NO_SHADER_CACHE=1. Headeca2078abmerged onto mainff23657f3; full build succeeds.ff23657f3(5 serial runs, clean rebuild)agc_driver_graphicsguest memory cannot be committed twice or before uploadagc_driver_image_tableimage table border BC4 table T#/direct S# did not report its entry rejectionagc_driver_multisample_fill_host_onlythe sentinel fill did not landagc_driver_bda_device,agc_driver_bda_span_reads,agc_driver_storage_write_back_overhang: pass.ctest -R "agc_|shader|recompiler|spirv|video_out" -j 8: 619/623; the fourth failure isagc_driver_store_over_untracked(#6347/#6383), also on main.I have not established which of the two commits causes each failure. The
WriteBackBufferschange now callsguestMemory.WriteBack()before rethrowing a BDA fault, and the first message is about committing guest memory, but that link is not verified.AI-assisted: yes (runs done with Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-15T18:37:32Z.
@Neithennn thanks for the run.
Cause of each failure, from the code and from fork CI runs on Linux (lavapipe) of main, of each commit alone and of the head:
agc_driver_graphics,guest memory cannot be committed twice or before upload: the second commit.tests/BdaResources.cppasserts that a use with a recorded fault fails before anything is published(
failed GPU command published writes), and one block sets anInvalidRectanglerecord, expectsWriteBack()tothrow, clears the record and calls
WriteBack()again. With the second commit the first call has already committedthe guest memory before it rethrows, so the second call stops in
GuestBufferMemory::WriteBack. The second commitalone fails the test; the first commit alone and main pass.
agc_driver_image_table,image table border BC4 table T#/direct S# did not report its entry rejection: the firstcommit. The test captures stderr per dispatch and looks for the
image table:line of each rejected entry. The ratelimit counts every deferred failure of the process and prints the first 8: the first part of the test produces 5, the
BC0 round of the border test 3, so the first rejection of the BC4 round is the 9th and prints nothing. The first
commit alone fails the test; the second commit alone and main pass.
agc_driver_multisample_fill_host_only,the sentinel fill did not land: not tied to either commit. The test submitsonly the compute fill kernel, which the driver takes as a buffer fill (
Driver::fillBuffer,VulkanDevice::FillBuffer).It builds no
ShaderResourcesand registers no recorder completion, which are the only places the commits change. Aninstrumented build of the head (one line in
Recorder::finishwhen a batch has completions, one inWriteBackBuffers) printed neither line during this test and printed both duringagc_driver_bda_span_reads, used asa control. The test passed 20 of 20 on lavapipe for main, each commit alone, the head and the changed commits. I could
not reproduce the 1/5 and have no explanation for it. The full output of a failing run
(
ctest -R agc_driver_multisample_fill_host_only --output-on-failure) would show whether a[gpu]line precedes it.Changes, two commits on
origin/main03c4cb5e7:fix(agc): rate-limit the deferred report of an unaligned BDA access. The limit now covers only the fault thatflooded in PPSA25344, the unaligned access (reason 7).
BdaResources::CheckFaultthrows aBdaUnalignedAccessforit and
Recorder::finishrate-limits that type; every other deferred failure is printed each time, as on main. Newtest
agc_recorder_deferred_failure_report: 12 other failures print 12 lines, 12 unaligned reports print 8, and the1024th prints the count line.
fix(agc): write copied buffers back before reporting an unaligned BDA access. The write-back before the report islimited to the same fault: the shader skips an unaligned access and the other invocations are unaffected. Every other
fault still throws before anything is published, which the existing assertions in
tests/BdaResources.cpprequireand which are unchanged. New block there: an unaligned fault publishes the other stores and is reported as
BdaUnalignedAccess; an unmapped fault publishes nothing.Run on Linux with lavapipe (llvmpipe, LLVM 20.1.2), fork CI:
agc_driver_graphicsandagc_driver_image_tablefail with the messages above;agc_driver_bda_device,agc_driver_bda_span_reads,agc_driver_multisample_fill_host_onlyandagc_driver_store_over_untrackedpass.agc_driver_image_tablefails, the rest passes.agc_driver_graphicsfails, the rest passes.agc_driver_graphics,agc_driver_image_table,agc_driver_multisample_fill_host_only(also 20 of 20 repeated),agc_driver_bda_device,agc_driver_bda_span_reads,agc_driver_store_over_untrackedandagc_recorder_deferred_failure_reportpass.agc_|shader|recompiler|spirv|video_out, https://github.com/AlxcBTW/AnyPS5/actions/runs/38785686515: 632 of 633 pass;agc_driver_mesh_index_cacheaborts, as it does on main (https://github.com/AlxcBTW/AnyPS5/actions/runs/38785707388, 631 of 632).Windows, MinGW-w64 GCC 15.2: the libs target of the changed commits compiles (https://github.com/AlxcBTW/AnyPS5/actions/runs/38782444478); the tests are built
on Linux only.
tools/check_conventions.py --base origin/mainpasses.Not run: ctest on Windows with an NVIDIA GPU, so the three failures are not re-checked on the machine that reported
them, and no game was run, so the effect on the Sword of the Sea log and stores is reasoned from the code. To check on
your side:
ctest -R "agc_driver_graphics$|agc_driver_image_table$|agc_driver_multisample_fill_host_only$|agc_driver_bda|agc_recorder_deferred_failure_report" --output-on-failure.Imported from boykopovar/AnyPS5. Originally posted by Neithennn on 2026-10-15T21:07:27Z.
@AlxcBTW Thanks for the breakdown. Windows rerun of the new head
c0588d274: all three are gone.Windows 11 Pro 26200, NVIDIA GeForce RTX 4080 (driver 617.42), WinLibs GCC 15.2.0 r7, Release,
ANYPS5_NO_SHADER_CACHE=1. Current maince991f1ecdoes not build on Windows here (GpuIndirectArgumentsMisalignedWriterAhead.cpp:25: requested alignment '65536' exceeds object file maximum 8192), so the base is main + #6452 (4fe92c9c2), with this head merged on top.agc_driver_graphics: passes (targeted, full suite and 3 serial runs).agc_driver_image_table,agc_driver_bda_device,agc_driver_bda_span_reads, the newagc_recorder_deferred_failure_report: pass.agc_driver_multisample_fill_host_only: passes (targeted, full suite and 5 serial runs).ctest -j 8: 1298/1299; the failure isguest_kqueue(0xc0000409, #6173), which also fails on the base alone.On
agc_driver_multisample_fill_host_only: I captured a failing run later, on a different tree (the same base + #6184 + Tamalero's 5bce3de8a, where it failed 3 of 10 serial runs; the base alone passed 20/20). No[gpu]line precedes the failure: the output has only the two Vulkan device initialisations, each followed by the[write-watch] host imports of write-watched memory keep the write watch: yes (...)probe line, thenAGC graphics: the sentinel fill did not land. So it does not look tied to your commits.AI-assisted: yes (runs done with Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T18:23:53Z.
First AMD-on-Linux (RADV) run of this PR. Merged onto
main8d5d4df96(clean merge), built in full and compared with the samemain, on the same machine.AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.
Full suite (
ANYPS5_REQUIRE_VULKAN=1 ctest -j8) at4668d6893: 1639/1641 with this PR, against 1638/1640 onmain. The two failures are the same on both, so this PR adds none:agc_driver_image_table_vouched_lookups(#7766, fixed by #7916) andagc_driver_guest_memory_lifetime(#7784).The PR's new ctest entry,
agc_recorder_deferred_failure_report, runs and passes here. No other ctest entry is added, skipped or removed compared withmain.This checks correctness only; I did not measure performance.
GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38
AI-assisted: yes