Skip to content

perf(agc): write back a storage image spanning adjacent registered ranges on the GPU through each range's import - #5522

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
Nesyth:perf/agc-split-storage-write-back
Oct 14, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
Nesyth:perf/agc-split-storage-write-back

Conversation

@Nesyth

@Nesyth Nesyth commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

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.

  • The image is split at the ranges' boundaries into pieces with one import each. The retile writes every piece to its own import, or to that import's unit shadow, and the padding and shadow seeds of a piece come from its own import. A shadowed range is marked under the import of its piece; ranges only merge within one shadow slab, so none crosses into the next piece, which a Require states.
  • Outside the write watch, the stored bytes are also saved, as fix(agc): save the bytes a GPU-side store writes outside the write watch #5760 does for an image inside one import. The save copies come from the same retile scratch at the image's own offsets, so they don't depend on which import a piece goes to; they are recorded next to the pieces' import copies, on both the windowed and the block-less path.
  • Ranges with different access (writable or GPU-mapped) keep the CPU path, and so does a split that is not on a 64 KiB boundary while unit shadows are on, since a unit has one shadow.
  • The registered pieces are read inside each lookup attempt and read again at its end. If they or the imports changed, the lookup is retried once and then falls back to the CPU path.
  • An image inside one import is written back as before.

Tested

Windows 11 Pro 10.0.22631, Ryzen 7 7800X3D, RX 7900 XTX, WinLibs GCC 15.2.0, Release, on main a050f85.

  • New test splitWriteBackTests in tests/Recorder.cpp (ctest agc_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.
  • Two cases store twice outside the write watch, tiled (windowed path) and linear (block-less path): after the first write-back the CPU writes a page in the second range, and the second write-back has to keep that page and store the new texels in both ranges.
  • Reverting each part of the change makes its case fail. With either save copy removed, its second-store case fails ("the second write-back stored 0 texels below the split and 0 above it").
  • ctest -R "^agc_": 541 of 547 pass and 4 skip. agc_driver_layered_volume_vertex_no_gpl and agc_driver_recorder fail, as they do on main a050f85 on this GPU.
  • Ready or Not (PPSA18605), same scene, builds alternated (ABBA), 30 s profiler windows. These runs used an earlier form of the correctness part that counted adjacent ranges of one allocation only, not fix(agc): count adjacent registered allocations as covering a storage-image write-back #5321:
runs spanning write-backs on the CPU path per 10 s recorded-store syncs per 10 s FPS
before 2 119-158 (2.4-3.3 GiB) 38-48 (578-831 ms) 2.17, 2.53
after 2 none (154-211 on the GPU, 2 pieces each) 0-1 3.33, 3.00

Linux: not run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA18605 Ready or Not (PPSA18605) #4184
  • GPUs tested: AMD Radeon RX 7900 XTX, AMD Software Adrenalin 26.8.1 (driver 32.0.31041.1004), Windows 11 Pro 10.0.22631
  • AI-assisted: yes

@CnRJay CnRJay left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • The retry in importSegments only re-checks imports, not registrations. pieces comes from RegisteredReadableCovers once, outside the retry loop, while HostImportsIdentity / HostImportsUnchanged only prove that the imports didn't change. A GuestAllocations mutation 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. On main the 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.
  • When segments.size() == 1, paddingSeeds(segments, ...) forwards to the single-import overload, but writeBackWindows still allocates importCopies as 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.
  • Per-segment MarkShadowed filters shadowed by range.begin only. 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, a Require there 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.jsonl lines of main + #5321 against main + #5321 + this, from the same RoN scene with traces, would isolate this change. The current runs combine both.

@tibzejoker

Copy link
Copy Markdown
Contributor

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 head 53a4c0009.

  • agc_storage_split_writeback and agc_recorder_kept_bytes pass, and so does agc_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 as main has 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).

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 the Buffer* save parameter and the saves copies from the tiled scratch; this PR replaces const HostImport& with std::span<const ImportSegment> and paddingSeeds(segments, copied). Both signatures and the final copyBuffer block need to be combined, including the save copy next to the per-segment import copies.
  • writeBackLayers, the settle lambda: main's advances / MarkShadowed(*shadowImport, ...) version and this PR's allKept / markShadowed(now) version differ in when the generation advances. Please say which behaviour should hold with pieces from several imports.
  • The block-less path (copies to import->buffer) now also has saveUnits / 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 rerun agc_storage_split_writeback plus the agc_driver_* tests? A case in splitWriteBackTests with a spanning image outside the write watch would pin that combination.

@Nesyth
Nesyth force-pushed the perf/agc-split-storage-write-back branch from 53a4c00 to ea3a215 Compare October 14, 2026 20:56
@Nesyth

Nesyth commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

@adriadam10 thanks, done in ea3a215, rebased onto main a050f85:

  • writeBackWindows: it takes the segments and fix(agc): save the bytes a GPU-side store writes outside the write watch #5760's Buffer* 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.
  • settle: main's behaviour holds. The generation advances when a layer, an adjacent range or a shadowed range advances, as in main's advances version. 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.
  • Block-less path: the per-segment import copies, then fix(agc): save the bytes a GPU-side store writes outside the write watch #5760's save copy into savedBytes at the image's offsets, and commitStoredSave(saveUnits) as on main.
  • Test: splitWriteBackTests has 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").
  • Tests: ctest -R "^agc_" on this head passes 541 of 547 with 4 skips, agc_storage_split_writeback included. The two failures fail the same way on main a050f85 on this GPU: agc_driver_layered_volume_vertex_no_gpl, and agc_driver_recorder ("a signaled batch's read still refuses"), which passed on main 32e810d, before fix(agc): count adjacent registered allocations as covering a storage-image write-back #5321 merged.

@CnRJay your two points are in the same head:

  • importSegments reads 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.
  • A shadowed range can't cross into the next piece: writeBackWindows cuts every piece at its segment's end and merges ranges only within one shadow slab, which belongs to one import. A Require in the split now states it.
  • One segment: left on the general code; it costs one small vector and a one-item loop per write-back.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
#5390 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp L2809, L2904-2905, L4660

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 14, 2026

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked ea3a215: the combination with #5321/#5760 is correct (writeBackWindows takes the segments and the Buffer* 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 is agc_driver_tessellation (segfault), which also fails on main. agc_storage_split_writeback passes 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.

@adriadam10
adriadam10 merged commit 3f0936a into boykopovar:main Oct 14, 2026
8 of 9 checks passed
TheBlenDed pushed a commit to TheBlenDed/AnyPS5 that referenced this pull request Oct 25, 2026
Main now carries boykopovar#4450, boykopovar#4475 and Pipodi's pointer-in-record table columns (c794273), which replace our copies and our record-pointer columns; boykopovar#5181, boykopovar#5989, boykopovar#5906, boykopovar#5484 (live snapshot mismatches serve live bytes; our retry is dropped), boykopovar#5483, boykopovar#5522, boykopovar#4732, boykopovar#5792. Kept local: the two-lane wave64 hang fixes, boykopovar#5815, option 1 substitutes, image-table stores and set 0 tables, stencil remap, 10_11_11 blending, the VRAM share/spill, block-hash snapshots, diagnostics. Versions: disk FormatVersion 42, RuntimeAbi 17, request serializer v30, BdaAbi UnnormalizedWrap 11 / DirectImage 12. Notes in work/sync-20261013/*-3.md.

AI-assisted: yes
@Nesyth
Nesyth deleted the perf/agc-split-storage-write-back branch November 17, 2026 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants