perf(agc): write back a storage image spanning adjacent registered ranges on the GPU through each range's import #5522
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5522"
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 Nesyth on 2026-10-13T22:22:14Z.
What
With #5321, a storage image whose memory spans adjacent registered ranges is written back instead of dropped. No single host import covers such an image, so its write-back takes the CPU path: the driver copies the image out, waits for the queue and stores the changed bytes on the CPU. This change writes it back on the GPU through each range's own import, the way an image inside one import already is. On my Ready or Not bring-up build, an older base with other local changes, these CPU write-backs went from 119-158 per 10 s to none, and the frame rate from 2.17-2.53 to 3.00-3.33 FPS.
Requirestates.Tested
Windows 11 Pro 10.0.22631, Ryzen 7 7800X3D, RX 7900 XTX, WinLibs GCC 15.2.0, Release, on
maina050f856f.splitWriteBackTestsintests/Recorder.cpp(ctestagc_storage_split_writeback): a 200x150 RGBA8 image over two adjacent registered ranges is cleared on the GPU and written back, and every texel has to land with no other byte changed. It runs with 3 mips split at 128 KiB, off a 64 KiB boundary split at 132 KiB, as a linear surface, and over two adjacent allocations, all through the GPU; and on the CPU path, with a second range of other access and with a split inside a 64 KiB unit while unit shadows are on.ctest -R "^agc_": 541 of 547 pass and 4 skip.agc_driver_layered_volume_vertex_no_gplandagc_driver_recorderfail, as they do onmaina050f856fon this GPU.Linux: not run.
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 CnRJay on 2026-10-14T00:57:39Z.
Review: COMMENTED
This is the right fix for the cost #5321 exposes. A spanning image shouldn't pay a GPU→CPU round trip (copy out, wait for the queue, store on the CPU) when each piece has an import it can be copied into on the GPU. 119–158 such round trips per 10 s, at 2.4–3.3 GiB, is exactly the kind of hidden sync that keeps queue 0 from overlapping with the GPU.
Notes from reading the diff:
importSegmentsonly re-checks imports, not registrations.piecescomes fromRegisteredReadableCoversonce, outside the retry loop, whileHostImportsIdentity/HostImportsUnchangedonly prove that the imports didn't change. AGuestAllocationsmutation between the coverage walk and the copy (a range unregistered and reused while its import survives) is the case #5321 guards against with the drop. Taking the coverage walk inside the same attempt, or under the same proof, would close that window. Onmainthe single-import path has the same gap in principle, so this may not need to block, but the split path makes it more likely because it does more lookups.segments.size() == 1,paddingSeeds(segments, ...)forwards to the single-import overload, butwriteBackWindowsstill allocatesimportCopiesas a vector of vectors and searches segments for every piece. That's negligible per write-back, just noting that the unchanged case now runs the general code too.MarkShadowedfiltersshadowedbyrange.beginonly. A shadowed range that starts in one segment and ends in the next would be marked under the first import only. If the unit-alignment rule (no split inside a 64 KiB unit while unit shadows are on) guarantees this can't happen, aRequirethere would document it.For the numbers: the table was measured with an earlier form of the correctness part and on an older bring-up base. Once #5321 lands, the
aps5-summary.jsonllines ofmain + #5321againstmain + #5321 + this, from the same RoN scene with traces, would isolate this change. The current runs combine both.Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-14T01:17:28Z.
Intel run for this PR: Intel UHD Graphics 770 (Raptor Lake iGPU of an i9-13900K), driver 32.0.101.6129, Windows 11, MinGW-w64 GCC 15.2.0 Release, device picked with
ANYPS5_GPU=Intel, at head53a4c0009.agc_storage_split_writebackandagc_recorder_kept_bytespass, and so doesagc_driver_graphics.ctest -R "agc_driver|agc_masked|agc_shader" -j4: no failures out of 386 (358 pass, 28 skipped). These are the same 28 skips asmainhas on this GPU (f64, 64-bit and float atomics, fp16 interpolation and dot, mesh, shader clock and the like, which it does not support), and no new ones.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T19:04:49Z.
Review: CHANGES_REQUESTED
This now conflicts with
main: #5321 is merged, and #5760 (fix(agc): save the bytes a GPU-side store writes outside the write watch) changed the same code. The conflicts are not mechanical:StorageTexture::writeBackWindows(Texture.hpp/Texture.cpp): main added theBuffer* saveparameter and thesavescopies from the tiled scratch; this PR replacesconst HostImport&withstd::span<const ImportSegment>andpaddingSeeds(segments, copied). Both signatures and the finalcopyBufferblock need to be combined, including the save copy next to the per-segment import copies.writeBackLayers, thesettlelambda: main'sadvances/MarkShadowed(*shadowImport, ...)version and this PR'sallKept/markShadowed(now)version differ in when the generation advances. Please say which behaviour should hold with pieces from several imports.copiestoimport->buffer) now also hassaveUnits/savedBytes, which have to work when the image spans several imports.Could you rebase onto current
main, keep #5760's save path working for the split pieces, and rerunagc_storage_split_writebackplus theagc_driver_*tests? A case insplitWriteBackTestswith a spanning image outside the write watch would pin that combination.Imported from boykopovar/AnyPS5. Originally posted by Nesyth on 2026-10-14T20:57:20Z.
@adriadam10 thanks, done in
ea3a2152d, rebased ontomaina050f856f:writeBackWindows: it takes the segments and #5760'sBuffer* save. The save copies come from the tiled scratch at the image's own offsets, so they don't depend on a piece's import, and they're recorded next to the per-segment import copies.main's behaviour holds. The generation advances when a layer, an adjacent range or a shadowed range advances, as inmain'sadvancesversion. Only the shadow marking is split: each range is marked under the import of its piece (markShadowed(now)). Several imports change which import a shadowed range is marked under, not when the generation advances.savedBytesat the image's offsets, andcommitStoredSave(saveUnits)as onmain.splitWriteBackTestshas two new cases outside the write watch, tiled (windowed path) and linear (block-less path). After a first write-back the CPU writes a page in the second range; the second write-back has to keep that page and store the new texels in both ranges. With either save copy removed, its case fails ("the second write-back stored 0 texels below the split and 0 above it").ctest -R "^agc_"on this head passes 541 of 547 with 4 skips,agc_storage_split_writebackincluded. The two failures fail the same way onmaina050f856fon this GPU:agc_driver_layered_volume_vertex_no_gpl, andagc_driver_recorder("a signaled batch's read still refuses"), which passed onmain32e810db4, before #5321 merged.@CnRJay your two points are in the same head:
importSegmentsreads the registered pieces inside each attempt and again at its end, and uses the segments only when both the imports and the pieces are unchanged. The window between that check and the recorded copy is the one the single-import path has.writeBackWindowscuts every piece at its segment's end and merges ranges only within one shadow slab, which belongs to one import. ARequirein the split now states it.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T21:00:47Z.
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.cppL2809, L2904-2905, L4660Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T21:13:25Z.
Review: APPROVED
Re-checked
ea3a2152d: the combination with #5321/#5760 is correct (writeBackWindowstakes the segments and theBuffer* save, the save copies come from the same scratch at the image's own offsets, shadow marking is per segment). Build and the libSceAgcDriver ctest are green on lavapipe; the only red isagc_driver_tessellation(segfault), which also fails on main.agc_storage_split_writebackpasses and fails with the non-test changes reverted. Not covered here: the RoN frame-rate numbers (Windows, RX 7900 XTX). Merging once the full Build is green.