fix(agc): order deferred write-backs after queued draws' index reads #6914
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6914"
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 moong15 on 2026-10-16T17:54:39Z.
What
A pipelined draw (the draw pipeline, depth 8) reads its index buffer from guest memory when it is committed, not when its packet is processed. By then the packets queued behind it may already have run, and a later dispatch's deferred storage-image write-back can land in the same bytes first. The draw then reads indices that are really image texels.
Stellar Blade hits this every time the main menu loads. Each frame it sets
INDEX_BASEto the same allocation for a 6-index, 32-bit full-screen quad, then recycles that allocation for a 66x66 storage image (format 75). Once the image's write-back overtakes the queued quad, the quad's indices are garbage and the frame aborts:Change:
DrawPipeline::HeldReadsrecords the guest ranges each queued draw still reads at commit: its index range, and the extent of every guest buffer descriptor and vertex attribute its stages bind. A pipelined DMA copy holds its source range the same way.Texture.cpp). AWAIT_REG_MEMover that range stores it when it polls (WaitMemory.cpp), so the wait is satisfied without waiting for another flush.APS5_NO_QUEUED_DRAW_READ_ORDER=1restores the old order.[draw] pipelinedprofile line reports read ranges and stores held, and the[storage]line counts the stores released after the reads committed.agc_driver_queued_index_read_order, in three phases: a queued draw's index read and its vertex read must still see their original bytes when a later dispatch's write-back covers them, and aWAIT_REG_MEMover a held range, whose value only the deferred write-back produces, must be satisfied.Tested
Windows 11, MinGW build. Stellar Blade (PPSA13197 v01.141), same path to the main menu each run:
APS5_NO_QUEUED_DRAW_READ_ORDER=1)Holding the stores had no measurable cost on the
[draw] pipelinedline.ctest -j 8on this branch: 1348/1352. The four failures also fail on this machine without this change:agc_driver_quad_pixel_maskandagc_driver_layered_volume_vertex_no_gpl(fail on main),select_tests(needs symlink rights) andagc_driver_gpu_map_on_fiber.agc_driver_queued_index_read_orderpasses. It fails withAPS5_NO_QUEUED_DRAW_READ_ORDER=1, when only the index range is held (vertex phase), and without the write-back store from the wait (wait phase).agc_driver_queued_index_read_order, 8 in parallel, withANYPS5_NO_SHADER_CACHE=1: 0 failures.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repository🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T18:44:45Z.
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/Execution/src/Driver/Draw/Draw.cppL611core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cppL129core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppL604-605core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppL604-605core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppL143docs/dev/debt/libSceAgcDriver.mdL147Some 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/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawPipeline.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawPipeline.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawPipeline.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Memory/WrittenBuffers.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawPipeline.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Memory/WrittenBuffers.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdImported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-16T19:13:35Z.
@moong15 thanks for this. The new test
agc_driver_queued_index_read_orderis flaky on lavapipe when it runs with no shader cache next to other tests, which is how CI runs it (CONTRIBUTING.md: parallel ctest, first run with no shader cache). Its last check fails:Cause, from my runs: after
WaitForCommits()nothing is queued, so the queue worker's idle store (StoreIdleResults→FlushAllPending("idle"), after the 50 ms quiet period inQueueWorker.cpp) can take the pending image first. In a traced failing run, theidleflush appears afterWaitForCommits(), and at line 284StorageTexture::AnyPending()was already false with the indices still intact.FlushGpuWrites(Pool, PoolBytes)+AgcDriverWaitIdle_nid_postfix()then return before that write-back shows up inPool. With a probe that polledIndicesIntact()after the final check, the bytes landed 2–9 ms later in all 9 hits out of 60 runs. So the write-back arrives late; nothing is lost. The order check at line 273 passed in every run, so the production change looks fine here.I did not check whether
FlushGpuWritesshould also wait for an idle write-back that is already in flight. If it should, that is a separate issue in code this PR does not change.Test-side fix for
core/libs/prx/libSceAgcDriver/tests/execution/QueuedIndexReadOrder.cpp, replacing lines 284–286. I built and ran this exact code (results below):ctest -V -R '^agc_driver_queued_index_read_order$', 3 runsMESA_SHADER_CACHE_DIRper run, one at a time, 60 runsMESA_SHADER_CACHE_DIRper run, 12 copies at once, 3 × 60 runsAPS5_NO_QUEUED_DRAW_READ_ORDER=1, 10 runsThe negative control works.
check_conventions.pypasses. The head merges cleanly withmainatc84249186(13 commits after your base, none touching the files this PR changes), but I did not run the test on the merged tree.Setup: Linux, lavapipe Mesa 26.2.4 (LLVM 23.1.1), default CMake build (
CMAKE_BUILD_TYPEempty), cleanenv -i,ANYPS5_NO_SHADER_CACHE=1 APS5_NO_PIPELINE_JOURNAL=1for the direct binary loops, head ec5175ac232b287aa6c9335aa8ac16949c6e7fb5.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-16T22:10:04Z.
Review: COMMENTED
The cause is well shown (a queued draw reads its indices at commit, a later write-back lands in the same bytes first, Stellar Blade reproduces it on every menu load, 5 of 5 runs fail without the fix and run 8 with the switch off fails again). The test fails with the switch set. Two questions and one measurement.
HeldReadsrecords only the index range of a queued draw. What else does a queued draw read from guest memory at commit rather than at prepare? Indirect argument buffers, vertex data fetched through a BDA range, and descriptor words that are re-read incommitDrawwould be held to the same bug. Please list whatcommitDrawreads from guest memory and show that the others are snapshotted at prepare, so this is the whole class and not one instance.WAIT_REG_MEMdepends on)? The hold must not be able to wait on itself; a test with a label wait over a held range would show it.[draw] pipelinedline" is one line from one run. Post the summary lines of main (switch off) and this PR at the menu, same scene, noAPS5_PROFILE_*, since the write-backs it delays are on the path to the flip.Imported from boykopovar/AnyPS5. Originally posted by moong15 on 2026-10-17T06:13:29Z.
Updated in 747161864.
What a queued draw reads at commit.
commitDraw(Execution/src/Driver/Draw/Draw.cpp) runsVulkanDevice::Draw->Graphics::Draw->prepareDrawInputs. Every guest read on that path:decode->state, the draw keystages.push_back:407RecompileResult)Graphics::GuestMemorySnapshotbyte copies)decodeReads-> :424-426 -> snapshotPm4::ReadDrawArgumentsResolveDrawstore->Bytes()HighestDrawIndex(and the cached :963)GuestMemory::ReadFlushPending(..., "in-place vertex input")GuestMemory::ReadGuestMemory::Read(copy.source, ...)inside the commitrefreshResidentTargetCheckRange)Registers, user data, push constants, BDA/SRT constants, indirect arguments and descriptor words are read or snapshotted at prepare. Indirect draws never take the pipelined branch. At commit, the index buffer (11-14) was already held. The vertex buffer reads (16) and the pipelined DMA copy source (17) were not; both are held now.
QueuedDrawReadRangesreturns the index range plus the extent of every guest buffer descriptor and vertex attribute the draw's stages bind, andenqueueDmaPacketpasses the copy source the same way. Every other commit-time read goes throughGuestMemory::Read, whose flush hook reachesHeldReads, so the hold covers it as well. One read is not held: the colour/cmask texels a register clear materializes from the draw's own target (18). It goes through the hook, and it is the same aliasing the debt note already records for a surface read as index data, so it is recorded there.Can the hold wait on itself. The draws always commit: the commit thread pops items without waiting on any label or drain, and the GPU mutex is always taken before the pipeline mutex, so there is no cycle. The real gap was in the other direction, as you suspected: a store that the hold refused was never retried. A
WAIT_REG_MEMon that store's bytes would then spin, becausewaitMemorydoes not rerunFlushPending, andStoreIdleResultsneeds all queues idle, which is false while that worker waits. The refused range is now recorded, and the commit thread stores it as soon as no queued item reads it (DrawPipeline::storeDeferred). The[storage]line counts those stores.Tests.
agc_driver_queued_index_read_ordernow has three phases: the index read, the vertex read, and aWAIT_REG_MEMover a held range whose reference value only the deferred write-back produces, which must be satisfied within 10 s while the draw still reads its own bytes. Each phase fails without its part of the fix:APS5_NO_QUEUED_DRAW_READ_ORDER=1, the index phase failsThe test's vertex data is reached through a buffer descriptor, so the separate vertex-attribute loop has no case of its own.
160 runs, 8 in parallel, with
ANYPS5_NO_SHADER_CACHE=1: 0 failures. Fullctest -j 8: 1348/1352. The 4 failures also fail without this change on this machine:agc_driver_quad_pixel_mask,agc_driver_layered_volume_vertex_no_gpl,select_tests(needs symlink rights) andagc_driver_gpu_map_on_fiber.The menu summary lines, main against this PR, follow in a separate comment.
Imported from boykopovar/AnyPS5. Originally posted by moong15 on 2026-10-17T08:30:23Z.
Correction to my earlier reply: the retry I described there is gone. In game runs it stored a refused write-back after the holding draws committed, which could land after the title had already reused that memory for the next frame's indices, and the draw then read texels as indices. The hold now stays as it was, and a
WAIT_REG_MEMover a held range stores the pending write-backs itself when it polls (WaitMemory.cpp), so the bytes appear only when something waits for them.agc_driver_queued_index_read_orderstill covers it: without that flush the wait phase fails ("the wait over the held range was not satisfied ... after 10.0 s").Same machine and scene, from start to the in-game scene with Enter pressed every 20 s:
APS5_NO_QUEUED_DRAW_READ_ORDER=1): "vertex fetch exceeds descriptor record count", then abort at 150 s, loading from the menu.Imported from boykopovar/AnyPS5. Originally posted by TheSovietWaffle on 2026-10-17T11:35:54Z.
NVIDIA and Windows data point at the current head
8d26c406a: Release, Windows 10 Pro 22H2 (19045), WinLibs GCC 15.2.0 r7, libraries rebuilt from the head. Device chosen withANYPS5_GPU.agc_driver_queued_index_read_order: NVIDIA RTX 3080 (617.42) 5 of 5 (device selected in the log, not skipped); AMD Radeon Graphics (Raphael iGPU,1002:164e, AMD Windows driver) 3 of 3.agc_driver_draw_cache_reuse,agc_driver_draw_cache_reuse_off,agc_driver_draw_cache_reuse_verify,agc_driver_draw_cache_reuse_inline,agc_driver_pipelined_dispatchandagc_driver_pipelined_dispatch_itempass on the RTX 3080.The earlier head
a436481eegave the same results on the RTX 3080.Not checked: whether the new test fails on
mainwithout the change on these GPUs, and titles.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-17T13:35:48Z.
Review: COMMENTED
A Linux run on NVIDIA and lavapipe, since the description has Windows on AMD only.
Machine: Ubuntu 26.04, i7-8700, GCC 15.2, Release,
BUILD_TESTING=ON. NVIDIA GeForce RTX 3070 (driver 595.99.02) and lavapipe (Mesa 26.0.3, LLVM 21.1.8) on the same host. PR merged ontomain12a71f3f5(clean).ANYPS5_NO_SHADER_CACHE=1,-j1 --timeout 30.agc_driver_queued_index_read_order--repeat until-fail:30, serialAPS5_NO_QUEUED_DRAW_READ_ORDER=1queued index read: the queued draw's commit stored the image's results over its index buffer^agc(637 tests), PR vsmainagc_driver_f16_fma_denormal_modesandagc_driver_fma_mix_f16_denormal_modesfail onmainon this GPU too)I ran the repeats serially only, so this does not cover the parallel, cold-cache case @Dextroid17 reported.
Not run: Windows, AMD, Stellar Blade or any title.
GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02) and lavapipe (Mesa 26.0.3), Ubuntu 26.04
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by marco-scheffler on 2026-10-17T14:09:15Z.
Linux NVIDIA data point: Ubuntu 24.04.4, RTX 4000 SFF Ada Generation, driver 595.99.02, GCC 13.3.0, Release. This PR at
8d26c406amerged ontomainc9e6c45de, fullcteston the RTX (ANYPS5_GPU=RTX, Xvfb with-DANYPS5_VIDEO_OUT_TEST_DRIVER=x11): no new failures. The only failures,video_out_flip_eop{,_main,_aftergpu}(#6616) andagc_driver_{f16_fma,fma_mix_f16}_denormal_modes, fail the same way on thatmain(0/5 serial with and without this PR).Imported from boykopovar/AnyPS5. Originally posted by moong15 on 2026-10-17T14:22:28Z.
Rebased onto
main47a266cf9with no conflicts. After the rebase,agc_driver_queued_index_read_orderfailed in about 1 of 7 runs while the machine was busy, with "the queued draw holds no read of its vertex range". The cause is a race in the test. In the vertex phase, the gate item let the draw commit as soon as it was queued, so the commit thread could run it before the test thread checkedHeldReads. The gate now stays closed until the test has checked the hold. No production code changed. With that change the test passed 30 of 30 runs one at a time, and every repeat passed underctest -j12 --repeat until-fail:8next to the other pipelined and draw-cache tests withANYPS5_NO_SHADER_CACHE=1. It still fails withAPS5_NO_QUEUED_DRAW_READ_ORDER=1, with "the queued draw's commit stored the image's results over its index buffer".check_conventions.pypasses.@CnRJay, about your third point, the menu summary lines. These come from one build (the game branch carrying this fix) with the fix on and with
APS5_NO_QUEUED_DRAW_READ_ORDER=1, which puts back whatmaindoes. NoAPS5_PROFILE_*. Same scene: the title menu, from the first menu window until loading starts. Windows are 10 s. Windows, RX 9070 XT, 3840x2160.Driver.Packetms/frameDriver.Packetms/frameThe two pairs disagree. Pair 1 has the fix about 3 ms slower at p50, and pair 2 shows no difference. Two pairs can't settle a 3 ms gap at the menu. After the menu there is nothing to compare: with the fix off, every run aborts on the index read while loading from the menu (150 s and 165 s), and with it on, the game reaches the in-game scene (323 s and 380 s).
If a 3 ms menu cost would matter here, I can run another pair on this rebased head and post it.
Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-18T00:22:13Z.
Tested on Linux (Arch),
c++ (GCC) 16.2.1 20260810, Release,BUILD_TESTING=ON,mainate3838332ee31af787ad311b7eadbe53d8d012e95. GPU tests ran on lavapipe (llvmpipe, LLVM 22.1.8).#6656, #6914 and #6249 together fail two tests that #6249 adds, and #6656, #6914, #6249 and #6146 together fail one that #6146 adds. Each is a three-way interaction: no pair of the PRs fails (2 of 2 for every row,
mainhas none of these tests).mainagc_driver_copy_surface_bytes,agc_driver_copy_surface_bytes_no_aliasagc_driver_depth_expand_out_of_place(
CopySurfaceBytes.cpp:257on #6249's head andDepthExpandOutOfPlace.cpp:900on #6146's head.)What I found: the copy holds back its own source. #6656 makes
enqueueDmaPacketqueue DMA_DATA copies on the draw pipeline by default (PacketMemory.cpp:271). #6914 lists the copy's source as a held read of that queued item (PacketMemory.cpp:313), andDrawPipeline::HeldReadsmakesStorageTexture::FlushPendingreturn without storing anything while any queued item lists a read over the range (Texture.cpp:3218). The committer runs the item while it is stillitems.front()with its reads listed (DrawPipeline.cpp:157, popped only at:173). For a copy over 64 KiB,VulkanDevice::CopyBufferthen callsFlushPending(source, ..., "buffer copy source")(VulkanDevice.cpp:2660on #6249's head) to store the GPU-produced image bytes before the buffer copy reads them. That call now sees the copy's own read, returns false, and the copy moves the stale guest bytes. Debug print on the three-PR merge:FlushPending held 0x7f..c0000 +0x20000 reason=buffer copy source, thenincorrect_bytes=121865for the 128x120 cases. The tests are #6249's because they are the only ones that copy a GPU-produced source through this path; the problem needs no #6249 code. #6146's test fails the same way: it passes with the fix below.Evidence on the three-PR merge:
APS5_NO_QUEUED_DRAW_READ_ORDER=1(turns offHeldReads): both pass.APS5_NO_PIPELINE_DMA=1: both pass. Neither alone is the bug, the pair is.Fix tried (two small hunks on top of #6914):
DrawPipeline::ReleaseRunningReads()(committer thread: locksmutex, clearsitems.front().reads), called first thing in the DMA copy commit lambda inenqueueDmaPacket. The held read still protects the copy's source against stores queued ahead of it; it just stops holding it against the copy's own flush. Skippingitems.front()insideHeldReadsfor every item does not work: it breaks #6914's ownagc_driver_queued_index_read_order, because a draw's commit is meant to be held against its own reads. With the two hunks:agc_driver_copy_surface_bytes,agc_driver_copy_surface_bytes_no_alias,agc_driver_depth_expand_out_of_place,agc_driver_depth_expand_out_of_place_inlineandagc_driver_queued_index_read_orderpass 5 of 5, twice, on the merge of all four PRs.Who should act: #6914's author (the fix belongs next to their held read; the read hold is what is new). #6656 only turned the path on by default.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-18T00:41:43Z.
A second host for @nicolasfalesy's #6249 result, on a different
mainand LLVM: CachyOS x86-64, GCC 16.2.1, Release,env -i, lavapipe (llvmpipe, LLVM 23.1.1), 3 runs per arm via ctest. Mainf1af6c591, merged in order with #6914ce35d8fec, #6249bdf65336dand #665682119a8b8:agc_driver_copy_surface_bytes*tests pass 3/3.ReleaseRunningReads()clearsitems.front().readsundermutex, called first in theenqueueDmaPacketcopy lambda): both pass 3/3, andagc_driver_queued_index_read_orderstill passes 3/3.APS5_NO_QUEUED_DRAW_READ_ORDER=1:agc_driver_queued_index_read_orderfails 3/3 (the queued draw's commit stored the image's results over its index buffer). So with the fix applied, #6914's test still depends onHeldReads, and its pass above is not a vacuous one. By reading, the new call runs only in the DMA copy lambda, so a queued draw keeps its hold on its own reads.Not run: #6146 or the four-PR merge, the #6249 + #6656 and #6914 + #6656 pairs, the
APS5_NO_PIPELINE_DMA=1arm, Windows, NVIDIA/AMD, or a PS5.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by moong15 on 2026-10-18T09:42:28Z.
@nicolasfalesy, @Dextroid17, thanks. Confirmed and fixed in 6647ccd11, rebased onto
main09127eada.The self-hold doesn't need #6656 or #6249: on
mainit shows withAPS5_PIPELINE_DMA=1, and it covers every queued copy, not just those over 64 KiB. A copy at or under 64 KiB reads its source withGuestMemory::Read, whose flush hook reachesHeldReads, so its own listed read refused the store just asCopyBuffer's flush did for the large ones.The fix is the one you described.
DrawPipeline::ReleaseRunningReads()clearsitems.front().readsundermutex, and the DMA copy commit lambda inenqueueDmaPacketcalls it first. While the copy waits in the queue, its source stays held against write-backs. Draws never call it, so a draw is still held against its own reads.Test:
agc_driver_queued_index_read_orderhas a fourth phase. It leaves an image's results pending over the pool, queues a 4 KiBDMA_DATAcopy out of it withAPS5_PIPELINE_DMA=1, checks that the copy holds its source while queued, and requires the copied bytes to match the image's results once they land.agc_driver_pipelined_*tests underctest -j8withANYPS5_NO_SHADER_CACHE=1all pass.ReleaseRunningReads()call removed: fails with "the queued copy of the image: 4089 of 4096 copied bytes miss the image's results over the copy source".APS5_NO_QUEUED_DRAW_READ_ORDER=1: the index phase fails as before.I left the large copy out of this test. On
main, a copy over 64 KiB out of a pending image loses the image's bytes (120192 of 131072 here) even withAPS5_NO_QUEUED_DRAW_READ_ORDER=1and withoutAPS5_PIPELINE_DMA, which looks like what #6249 fixes. The fix above releases the read before either copy path runs, so with #6249 merged the large copy no longer refuses its own flush; your four-PR runs cover that.Windows 11, AMD Radeon RX 9070 XT, AMD 26.8.1 (LLPC).
check_conventions.pypasses.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-18T11:06:02Z.
@moong15 I re-ran this on
6647ccd11, with the same host and settings as my run above (CachyOS, GCC 16.2.1, Release,env -i, lavapipe, 3 runs per arm):agc_driver_queued_index_read_orderpasses 3/3.ReleaseRunningReads()call removed fromenqueueDmaPacket: it fails 3/3 withthe queued copy of the image: 4089 of 4096 copied bytes miss the image's results over the copy source. That is the same count you got.APS5_NO_QUEUED_DRAW_READ_ORDER=1: it fails 3/3 on the index phase (the queued draw's commit stored the image's results over its index buffer).6647ccd11(on main09127eada), with #6249bdf65336dand then #66562104a014fmerged, with no local patch: bothagc_driver_copy_surface_bytes*tests pass 3/3, andagc_driver_queued_index_read_orderpasses 3/3. In my earlier run (mainf1af6c591, #6914ce35d8fec, #665682119a8b8), that merge at the older heads failed 3/3 and passed only with the fix applied by hand.Not run: #6146 or the four-PR merge,
APS5_PIPELINE_DMA=1on baremain, the over-64 KiB copy onmain, the pairs, theAPS5_NO_PIPELINE_DMA=1arm, your 10-repeatctest -j8run, Windows, NVIDIA/AMD, or a PS5.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T13:41:07Z.
Checked the held-read ranges (index, buffer descriptors, vertex attributes, DMA source), the
FlushPending/WAIT_REG_MEMordering, the self-hold fix for queued copies and the test; the cross-platform runs in the thread cover the test on NVIDIA, AMD and lavapipe.Added two commits on your branch: a rebase onto current
main, and a docs commit folding the newdocs/dev/debt/libSceAgcDriver.mdentry into the existing "Storage image write-back" line instead of leaving two, and fixing it to match the code (no retry of refused stores; the[storage]line counts the listings the hold turned away, the[draw] pipelinedline the stores held); merged.Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-19T17:41:46Z.
Review: COMMENTED
Thanks for the pairs, and for fixing the race in the test.
I agree two pairs can't settle 3 ms, but the PR already has a counter that can. The hold only changes behaviour when a write-back overlaps an index range a queued draw still has to read. The earlier runs held 27 stores in one run and 324 and 65 in another, whole-run totals. At about 250 frames per 10 s window that is at most a store held every few frames, which is too little work to cost 3 ms of
Driver.Packeton every frame. If the[draw] pipelinedlines for the same windows show the same small numbers of held reads and stores on the fix-on runs, the pair-1 difference is run-to-run spread; if a window shows hundreds of holds, it isn't. Please post the held read ranges and held stores per 10 s window next to the table.Pair 1's fix-off run also lost its second window to the start of loading at about 25 s (127 presents), so only the 10-20 s window of that pair is comparable. A third pair run in the opposite order (off first) would remove the ordering effect.