fix(agc): advance stored layers when a write-back keeps CPU-written blocks #4663
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4663"
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 fdfawef324 on 2026-10-12T18:17:28Z.
What
On a host-imported surface a storage write-back keeps the 64 KiB blocks that the CPU wrote since their tracked layer's generation, stores the rest, and stamps the stored ranges with
MarkWritten. Settling advanced the stored layers' generations past those stamps only when no layer kept a block (or when an adjacent pending surface needed the collect).So when one tracked layer kept a block, every other stored layer kept its old generation, and the write-back's own stamps then read as CPU writes: the next write-back kept those layers as well and did not store the GPU's newer results over them.
A tracked layer is one 64 KiB unit when the surface has block units: tiled (not linear), 64 KiB-aligned base, not thick, with layer and block tracking on. Otherwise it is an array layer (64 KiB-aligned layer slices, layer tracking on) or the whole surface. With a single tracked layer, a layer that kept a block is the only stored layer, so nothing advances and settling behaves as on
main.Settling now collects and advances each stored layer that kept no block. A layer that kept a block keeps its old generation and re-uploads at its next use, as before. When no stored layer advances (nothing stored, or every selected layer kept a block), no adjacent pending surface needs the collect and no unit was retiled into the unit shadow, settling still skips the collect, as on
main.MarkShadowednow takes the settle collect's generation also when a block was kept;mainpassedTrackerGeneration()there without collecting. The two differ only for a CPU write to a stored unit made after the keep decision: onmaina later walk stamped it newer, so the retiled unit went stale and the CPU's bytes won; now this walk stamps it at the marked generation and the stored results win, as they already did when no block was kept.agc_storage_kept_unit_settleuses a 1024x512 RGBA8 surface in 64 KiB tiling (32 block units). It writes one byte of unit 0 from the CPU, stores a red clear (unit 0 is kept, as intended), then stores a blue clear, and requires units 1-31 to be blue and unit 0 to keep the CPU's byte after both stores. It runs on GPU-mapped direct memory (the host-import path, where that import keeps the memory write-watched) and on watched memory with host imports off (the write-back that stores through the CPU). Onmainthe direct-memory case fails:The watched-memory case passes on
main. It guards the kept layer's old generation on the path that stores through the CPU, which this change also makes collect and advance when a unit is kept: if settling advanced the layer that kept a block too, the watched case fails (the second write-back stored over unit 0, which the CPU wrote after that unit's generation).The watched-memory case is required and passes independently when the optional direct-memory subcase is unavailable. Unsupported direct imports still print the specific subcase reason and continue. A missing host write watch or any readback failure fails the test. The suite no longer reports all of its coverage skipped merely because the direct-memory subcase could not run.
Found while tracing the storage corruption in Demon's Souls (PPSA01342 v1.005). On its own this change shows no visible difference there: the green band in that title's movies comes from shared write tracking, fixed in #4661. This PR fixes the write-back bookkeeping that the test above exercises.
Tested
Windows Server 2025, RTX 3060, GCC 15.2 (Release). The branch is rebased onto
mainat14db08435; the tests below ran on the same commit rebased onto84659e16d(git range-diffshows it unchanged). Main between the two adds the3rdparty/libusb-cmakesubmodule, which this worktree's build directory could not configure without initialising, and changes nolibSceAgcDriverfile.agc_storage_kept_unit_settle: passes with this change. With only theTexture.cppchange reverted, the direct-memory case fails with the message above. With settling also advancing layers that kept a block, the watched-memory case fails (checked on the earlier base014221568).ctest -R agc -j 4(446 tests): 436 pass andagc_driver_stencil_ref_exportskips. 9 fail, and each also failed with only theTexture.cppchange reverted (checked on the earlier base621ce1da1):agc_driver_flat_loads,agc_driver_flat_loads_x2_x3,agc_driver_flat_loads_x4,agc_driver_global_loads,agc_driver_global_loads_x2_x3,agc_driver_global_loads_x4,agc_driver_flat_apertures_2,agc_driver_flat_apertures_5(abort with "guest allocation ... is still pinned by GPU work or an import") andagc_driver_pixel_interlock(vkDeviceWaitIdlereturns -4).tools/check_test_registration.py: passes.agc, and any title or homebrew.Follow-up for Linux CI coverage:
ca73d0fchanges only the fixture's completion policy; the production code and GPU readback body are unchanged. The entire matching-headerRecorder.cppand unchangedTexture.cpppass GCC-O3syntax checks. A CPU replay of the literal completion selector/catch/Require, with explicit observation callbacks replacing GPU work, reports old exit 77 versus corrected exit 0 after watched success/direct unavailability; the unchanged Linuxcheck_skips.pyreports lost coverage before and passes afterward. Injected watched/direct failures still fail. This is a completion-policy check, not a fresh Linux or native GPU rerun; the published CI run must verify lavapipe rendering coverage.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
Co-Authored-By: Codex [email protected]
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-12T21:50:08Z.
Changes in this revision (rebased onto current
mainat14db08435, still one commit; the conflict intests/Recorder.cppwith--integer-clear-onlykeeps both options):Texture.cpp: tiled (not linear), 64 KiB-aligned base, not thick, with layer and block tracking on; otherwise a tracked layer is an array layer (64 KiB-aligned layer slices, layer tracking on) or the whole surface. Fixed in the commit message and the body.settlereturns before the collect when no stored layer advances (nothing stored, or every selected layer kept a block, e.g. a single tracked layer that kept one), no adjacent pending surface needs it and nothing was retiled into the unit shadow. This replaces thekeep.empty()check and drops the walk that advanced nothing; a cost change, not a correctness one.MarkShadowedtakes the settle collect's generation instead ofTrackerGeneration()when a block was kept, and when the two differ (a CPU write to a stored unit after the keep decision: the stored results now win, as when no block was kept).Backing's destructor releases the direct memory whenever it was allocated, also when mapping it failed.Texture.cppchange reverted the direct-memory case fails at unit 1; with it both cases pass. The suite ran on base84659e16d(same commit pergit range-diff); the newest base adds thelibusb-cmakesubmodule, which my build directory could not configure.No finding was refuted in this round.
Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-13T05:00:37Z.
An Intel run, and the full suite, which the description lists as not run.
Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, CI configure flags, an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. The head c6b403d71 merged into
main495bf91a0, which passes 1023 of 1023 on both GPUs.agc_storage_kept_unit_settleand the other 16 recorder entries pass on both GPUs with--repeat until-fail:3.ctest --timeout 120 --parallel 4): 1024 of 1024 on both GPUs. That includes the nine that fail on your machine with and without this change (agc_driver_flat_loadsand_x2_x3,_x4;agc_driver_global_loadsand_x2_x3,_x4;agc_driver_flat_apertures_2,_5;agc_driver_pixel_interlock). They pass on both GPUs here.Texture.cppas onmain,agc_storage_kept_unit_settlefails on both GPUs with the direct-memory message from the description ((k) GPU-mapped direct memory: unit 1 kept the results of the earlier write-back; ...). The other 16 pass.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-13T08:30:23Z.
Linux test (Arch, GCC 16.2.1, Release, Intel Arc B390 on Mesa 26.2.2 ANV), head
c6b403d71merged alone ontomain7e181fcc3(clean merge):agc_storage_kept_unit_settlefails on the direct-memory case, with the same message your description gives for the unfixed code:The watched-memory case passes. On this machine the write-watch probe reports
dma-buf imports keep write protection: yesandhost imports resolve write protection: yes, so GPU-mapped direct memory goes through the dma-buf import path here rather than Windows' host import, which may be why theTexture.cppchange doesn't reach it. Happy to rerun with any trace switch.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:57:03Z.
Review: CHANGES_REQUESTED
Checked on Linux (RADV, Radeon 660M): the PR merged onto main builds,
agc_storage_kept_unit_settlepasses, and it fails with only theTexture.cppchange reverted, so the test does exercise the change there.libSceAgcDriverctest otherwise matches main (agc_driver_tessellationsegfaults on main too).the second write-back stored over unit 0, which the CPU wrote after that unit's generation. That is the failure that the watched-memory case guards against (a layer that kept a block must keep its old generation). There the probe reportsdma-buf imports keep write protection: yes, so direct memory takes the dma-buf import path, not the host-import path the description targets. We can't reproduce it on RADV, so please find out why that path advances (or stamps) unit 0's generation, and either fix it or restrict what the test claims. A test that fails on a Linux driver can't be merged.Happy to re-review once the Linux/ANV case passes.
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-13T15:11:01Z.
Thanks for the Linux run. I traced it, and the failure doesn't come from a dma-buf write-back path. Your direct memory never reached the dma-buf import.
host imports resolve write protection: yesanddma-buf imports keep write protection: yes,importAllocation(GuestBufferMemory.cpp:759-774) tries the host-pointer import first. That attempt runs in a window that doesn't stay watched. dma-buf is tried only if the host-pointer import fails. On ANV the host-pointer import of shared direct memory succeeds, soImportWatched(GuestMemory.cpp:1216-1219) takes the surface out of the write watch.7e181fcc3, beforee5449936f) that store wrote every unit whole, over unit 0. That's your message. On currentmainthe same store throwsstoring storage image results pending over memory outside the write watch ... not implemented, which no technical-debt entry covers yet. The existing entry only covers results over a range that left the watch after they became pending. Here the range was compared from before the upload, and the saved bytes are gone after the first GPU-direct store. That needs its own PR.Texture.cppchange, because the compared path has no generations to settle. I reproduced both outcomes on Windows by importing private watched memory (Windows compares that import):7e181fcc3, with and without this PR's change, the run fails with your message.mainthe run throws.What changed: the branch is rebased onto
f2c314e90with one extra commit. The direct case now checks the write watch again after the import. If the import took the memory out of the watch, it printsthe host import of the direct memory took it out of the write watch (its imports are compared): ... not testedand the test returns 77. Where the import keeps the memory watched (the Windows alias import, or a Linux dma-buf import when the host-pointer import fails, as with shared memory on RADV), the case runs as before. That path uses the same write-back and settle code as Windows.Could you rerun
ctest -R '^agc_storage_kept_unit_settle$' -Von the new head? ctest prints nothing for a skipped test without-V. I expectunits stored next to a unit kept for the CPU in watched memory: ok, the new skip line, and the test reported as skipped. A different result would mean my reading is wrong somewhere. If you also have an AMD or other non-ANV Linux machine with/dev/udmabufaccess, a run there would cover the dma-buf case.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T15:52:59Z.
Review: APPROVED
Checked on Linux (RADV): the PR merged onto main builds,
agc_storage_kept_unit_settlepasses, and it fails with only theTexture.cppchange reverted. The remaininglibSceAgcDriverctest difference vs main isagc_driver_tessellation(segfaults on main too). The ANV case from @nicolasfalesy is now skipped (77) when the host import takes the memory out of the write watch, which matches the trace in your reply; the compared-path store throwing on main is a separate follow-up. Windows full-suite runs by @kr4y4 pass. Merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T22:26:09Z.
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/Texture.cppL4474-4485Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T06:19:04Z.
The full Build is red on this head, on Linux only:
tools/check_skips.pyfails withagc_storage_kept_unit_settle skipped(run 38513427247). On CI's lavapipe the test now returns 77, and the reason it prints isn't one of the device limitations the check accepts, so the job counts it as lost coverage.Could the direct-memory case skip on its own and let the rest of the test run (and pass) there? If the remaining skip really is a device limitation, word it the way
check_skips.pyexpects ("skipped, the device ..."); otherwise the case needs to run on lavapipe.Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-14T08:10:29Z.
Fixed in
ca73d0f. The watched-memory case now runs and passes independently; an unavailable direct-memory subcase only prints its own reason. Missing host write watching and all readback failures remain failures, so this does not turn required coverage into a skip.Verification: full matching-header Recorder.cpp and unchanged Texture.cpp pass GCC -O3 syntax checks. The literal completion-policy CPU replay reproduces old exit77/check_skips failure and corrected exit0/check_skips success; injected watched/direct failures still fail. The GPU readback body and production code are unchanged. This follow-up has not been rerun on Linux or on a native GPU; CI must confirm lavapipe coverage.
On
ca73d0f, conventions run 38533264055, eligibility and report pass. GitHub retains cancelled duplicate conventions run 38533264336; rerunning it requires repository admin rights. The test-only Build gate skipped Linux/Windows, so a maintainer Build dispatch withpr=4663is needed for a fresh lavapipe result.GPUs tested: NVIDIA GeForce RTX 3060 12 GB, driver 591.86 (32.0.15.9186), Vulkan 1.4.325, Windows Server 2025 10.0.26100 (prior production-fix/readback evidence in the PR; this follow-up uses source and CPU checks only).
AI-assisted: yes
Co-Authored-By: Codex [email protected]
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T17:03:15Z.
Re-checked the new commit
ca73d0f: the watched-memory case now runs and passes on its own when the direct-memory subcase is unavailable, so lavapipe no longer returns 77 for the whole test (thecheck_skips.pyfailure from the last Build). Production code is unchanged. On Linux (RADV) the PR merged onto main builds,agc_storage_kept_unit_settlepasses, and it fails with only theTexture.cppchange reverted. Merging once the full Build is green.