fix(agc): keep a CPU store that rewrote a pending block with its baseline bytes #14302
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14302"
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 hugodearaujo on 2026-11-01T07:56:34Z.
What
A storage image write-back keeps the CPU's bytes in a 64 KiB block the write watch stamped after the layer's generation. #1599 made one exception: if the stamped range still holds the image's baseline bytes (the guest bytes the image was uploaded from), the GPU results are stored anyway. The debt file already lists the gap: a CPU store that writes the baseline value back after the GPU changed it can't be told apart from no store, so the GPU result wins.
Control (PPSA34547) runs into exactly that gap. It writes its per-frame constant buffers over memory that a storage image (format 13 or 29) still covers with pending results. The constants it writes match the bytes the image was uploaded from. A dispatch then binds that memory as a buffer, and the
imported buffer regionflush stores the stale texels over the constants. Several shaders take loop counts from those constant buffers (s_buffer_load_dword→s_cmp_lt_u32loop, for example program 0x1004260100 at pc 0xaec), so they read texel pairs as counts (0x43954395,0x46d446d4,0x025a000c).fix(agc): keep a CPU store that rewrote a pending block with its baseline bytesmarkLayersPendingnow records the write generation of each layer's last GPU results. When a layer first becomes pending, it collects the layer's range first, so CPU stores from before the results get older stamps.writeBackLayers, and the same rule insaveBeforeUnwatch), a range whose bytes equal the baseline still stores the GPU results, except when the range is a whole 64 KiB block of the layer and a CPU store (ChangedBlocks' CPU flag) reached it after that generation. In a whole block every stamped page holds the layer's own bytes, so that store is the later write, whatever value it wrote.agc_unchanged_cpu_stampskeeps passing.fix(agc): a unit kept for the CPU stays kept when it is written again before a re-uploadA write-back that keeps blocks of a unit for the CPU leaves the unit stale at its old generation, without saved guest bytes. A dispatch looks up its storage images before it flushes the images pending over its imported buffers (
ShaderResources, step (2)), so it can write such a unit again without re-uploading it. With 1. alone that went wrong twice:storing storage image results pending over memory outside the write watch without the guest bytes saved before them is not implemented. Control stopped on that once in 10 runs with 1. alone (below).The blocks a write-back keeps for the CPU are now recorded with the unit's generation, in the record
saveBeforeUnwatchalready keeps for the blocks it finds written when memory leaves the watch (keptAtUnwatch). While the record holds (the unit's generation hasn't moved), new results leave the unit's pending-since generation alone. If they land outside the write watch,markLayersPendingfirst saves the unit's guest bytes, so the next write-back compares with them and still keeps the recorded blocks. The next upload of the unit gives it a new generation, which ends the record.Related: #7048 (open) saves guest bytes for the same error in a wider set of units (any unit without saved bytes, whatever its generation). This PR covers only units with blocks a write-back kept for the CPU, and it also keeps those blocks at the next write-back.
Runtime evidence: Control, cold shader cache, a diagnostic build that logs each range a dispatch or draw captures that a storage write-back stored to within the previous second. Three separate runs show the same chain. Example (run
chi-9):The keep decision for that block (run
chk-1, the same chain on image 0x38b120000):The block was stamped after the layer's generation (
changed 1), butbaselineUnchanged 1dropped it from the kept set. WithoutAPS5_LOOP_GUARDthese runs end in a GPU ring timeout ([device-fault] unfinished dispatch: ... program 0x1004260100) or inbuffer descriptor uses an unsupported type (buffer 2 V# ff1a1514 ff1a1514 ff191612 ff171410), which is a vertex shader V# table filled with texels. With an empty shader cache this happened in about 30% of runs. A warm cache never hit it in our runs, because the timing differs.Tested
Linux (Arch, kernel 7.2.11), x86-64, RX 9070 XT, RADV (Mesa 26.2.6), on
maincc26ab4438.New test
agc_storage_rewritten_blocks: a linear storage image over write-watched memory, cleared on the GPU and marked pending. The CPU then writes the baseline bytes back into one whole 64 KiB block, and the image is written back. The block keeps the CPU's bytes and the other blocks get the clear color. A second case writes the same bytes before the GPU results are recorded and expects the GPU results everywhere, as #1599 does. Onmainthe first case fails:(c) a CPU store of the baseline bytes after the GPU results: the GPU results were stored over the CPU's later store at +65536. With the fix it passes.New test
agc_storage_rewritten_stale_units: a 64 KiB R_X storage image (8 block units) over write-watched memory, cleared red and marked pending; the CPU writes unit 1's baseline bytes back, and the write-back keeps unit 1 and stores red elsewhere. The image is then cleared blue and marked pending again without a refresh, and written back. It runs twice: once with the memory taken out of the write watch between the two write-backs, once with it still watched. Both expect unit 1 to keep the CPU's bytes and the other units to be blue.main+ the tests: fails at the first write-back ((r) memory that left the write watch: the first write-back stored over unit 1, which the CPU rewrote with its baseline bytes after the results).storing storage image results pending over memory outside the write watch without the guest bytes saved before them is not implemented. With that case moved second, the watched case fails:(r) watched memory: the second write-back stored the image's stale unit 1 over the CPU's store, which nothing re-uploaded.Paired run with
VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1,ctest -V -R 'agc_storage|agc_unchanged_cpu_stamps|agc_driver_recorder$|agc_slice_dirty|agc_import_watch'(18 tests):main+ the tests, 14 pass, andagc_storage_rewritten_blocks,agc_storage_rewritten_stale_unitsandagc_driver_recorder(which includes the first) fail. This branch, 17 pass. On both,agc_storage_clear_hand_overis skipped by its own skip code, and noVUID-line appears.Control (PPSA34547), new game, empty shader cache per run, about 420 s, base
mainde83e8f270+ #11580 + #12458, alternating runs (series 1 used commit 1 alone, series 2 this branch):buffer descriptor uses an unsupported type (buffer 2 V# ff000000 ff000000 ff000000 ff000000)at 377 s,... V# ff23201b ff221f1a ff231f1a ff24201bat 183 s)storing storage image results pending over memory outside the write watch without the guest bytes saved before them is not implemented, 127 s)... V# ff000000 ff000000 ff000000 ff000000at 183 s)Every other run reached the 420 s limit. The counts are too small to prove anything: series 2 alone gives a two-sided Fisher p of 1.0, and the base's 3 stops in 30 runs against 0 in 20 for this branch give p = 0.27. The base hit the abort less often in series 2 (1 in 20) than in earlier runs (about 30%). Series 2 never showed the error from series 1's commit-1 run, and its 20 runs with this branch had no stop at all.
Conventions: pass (0 errors; the debt entry length warning was already there before this change)
Rerun on this branch merged with
mainc674f8c14d(one conflict inmarkLayersPending, wheremainnow skips the capture when every unit is already pending; the pending generation is still recorded for every unit): the same 18 tests pass underVK_LAYER_KHRONOS_validation, withagc_storage_clear_hand_overskipped by its own skip code and noVUID-line.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 MarcZX10 on 2026-11-01T09:30:27Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The new AGC regression cases appear targeted, but this head conflicts with open #8246 in
Texture.cppand has no recorded landing-order agreement or corresponding dependency declaration.What I ran
Reviewed PR head
34d48019fdbdbe48c76364f438ed6e49084f24f6, targetingmainat PR basec674f8c14da93df7a6b37657117ca3f58357477f. A merge preview against currentmain26fa1212b82f76dd49cf12d65e445d6ff3e0844cis clean; a separate pairwise preview against open #8246 head9377004c3c38bc505be16eafb509609386318a94conflicts inTexture.cpp. Static checks ran in the Linux review environment; I did not invoke a local compiler or build.Results
git diff --checkmaincore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp.34d48019guest_padexited with0xc0000409; CTest reports one failure out of 2,583, with several tests skipped. This test is outside the changed paths, so I cannot attribute the failure to this PR.Raw output — conventions and diff check
git diff --checkproduced no output.Raw output — clean current-main preview
Raw output — pairwise preview
Raw output — hosted checks
Raw output — failing Windows test
Findings
Blocking
Texture.cpp.CONTRIBUTING.mdrequires authors of overlapping changes to agree which lands first and record the dependency inDepends onwhere applicable. This PR currently saysDepends on: none, and I found no recorded agreement with #8246's author. Please coordinate the order with that author and update the checklist; if this PR must land second, declare #8246 and rebase after the dependency lands. I am not asking either author to close their PR.Non-blocking
guest_pad, which is not among this PR's changed paths. The log does not establish a connection to this change. Please confirm whether it reproduces on the same head or compare against the current base before treating it as unrelated.Sources
Not verified
guest_padfailure or establish whether it occurs on currentmain.To get this to a good state
Please record the agreed landing order with #8246 and update
Depends onaccordingly, then investigate or document the Windowsguest_padresult. I will refresh the PR head and rerun the same applicable checks on the updated revision.