perf(agc): linear color targets over imported memory get a resident image #6892
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6892"
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 tibzejoker on 2026-10-16T16:53:08Z.
What
A linear color target took a synchronous draw every time it was drawn to: copy in, draw, copy out, then a CPU wait for the GPU. Tiled targets have a resident image instead, so their draws are recorded and continue the open batch.
With this change, a linear target whose memory already has a host import gets a resident image like a tiled target:
keepRecordedDrawstores its results back to guest memory right after the draw, with a recorded store (StorageTexture::FlushPending). CPU readers still see them, without the wait.ExistingHostImportForis a lookup only. Memory without an import keeps the synchronous path, so nothing changes for it.APS5_NO_RESIDENT_LINEAR=1restores the old path for every linear target.Why lookup only: a first version created the import, and that broke
agc_driver_pixel_ancillary_wordandagc_driver_pixel_fixed_point_position. An import made over a short-lived block left the next block allocated at the same address unwatched.Overlap: #1191 (MichonGoddijn231849) implements the same idea. It is ~6,000 commits behind main and conflicts in 10 files. This PR is a narrower take on current main. I asked on #6754 whether Michon prefers to fold it into #1191 or rebase #1191 instead, and I'm happy to close this one if so.
Tested
Windows 11, MinGW (WinLibs GCC 15.2), RTX 4090 (driver 616.92).
New test
agc_driver_linear_target_resident: a draw into a linear R32G32B32A32 target over imported memory must leave the recorder busy (recorded, not waited), and the pixels must be in guest memory afterWaitIdle, without a flush. It passes with the change and fails withAPS5_NO_RESIDENT_LINEAR=1, which is main's path:the draw into an imported linear target waited for the GPU instead of being recorded.ctest -R "agc_driver|agc_masked": 473/474. The one failure isagc_driver_gpu_indirect_arguments_misaligned_writer_ahead, which does not build with MinGW on main (alignas(65536), fixed by #6452).GTA V (PPSA04264), Story, same scene, on main
eb901bcf4+ #6488 (needed to drive the game): 14.64 → 16.47 FPS (frame counter over 150 s), rendering checked.The new test also passes on an Intel UHD Graphics 770 (Windows 11), and fails there with
APS5_NO_RESIDENT_LINEAR=1.Performance report (same machine, same scene,
APS5_TRACE_SECONDS=240:60, 3840x2160). Base is the same build withAPS5_NO_RESIDENT_LINEAR=1, which is main's path:GPU busy per present is unchanged (39.3 vs 39.5 ms); the time saved is the CPU wait of each synchronous draw.
Traces and summary lines: https://github.com/tibzejoker/AnyPS5/releases/tag/perf-resident-linear-20261016
Checklist
main; no other open PR implements the same functions. Exception: #1191 (see What).NotImplemented_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
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T17:38:30Z.
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/Draw.cppL2013core/libs/prx/libSceAgcDriver/Graphics/src/State.cppL1402core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppL68core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppL2615core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppL68core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppL2615core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppL68core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppL68core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppL68Some 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/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppImported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-16T18:30:46Z.
Review: COMMENTED
Linux run of
7b621ddbb, plus one gap in the new test.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). PR merged ontomain93e54cedd. All runs-j1 --timeout 30.agc_driver_linear_target_residentAPS5_NO_RESIDENT_LINEAR=1the draw into an imported linear target waited for the GPU instead of being recorded^agc_driver|^agc_masked(466 tests), PR vsmainThe test passes without the
keepRecordedDrawhunk. I removed the new loop that callsStorageTexture::FlushPendingfor linear residents (the rest of the PR unchanged):agc_driver_linear_target_residentstill passes on both devices. The test reads the target withGuestMemory::Read, andReadcallsFlushGpuWriteson the range before copying, so the test flushes the image itself. A guest CPU reads the memory directly. With the read changed to a plain copy from the block:FlushPendingloop + this test changepixel (0, 0) holds (-nan, -nan, -nan, -nan)(the 0xff fill)So with a direct read the test covers the store-back that the description relies on ("CPU readers still see them, without the wait").
I also checked a target switching paths between draws.
ExistingHostImportForreturns null after anyGuestAllocationsmutation until something callsHostImportForagain, so the same linear target can be drawn resident, then synchronously, then resident again. I drew the left half, ended an unrelatedMutation, then drew the right half, and the reverse order with aHostImportForcall in between. The resident/synchronous pattern was as expected (recorded=1then0, and0then1), and all 1024 pixels were correct in both orders on both devices.Not run: Windows, AMD, GTA V 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 tibzejoker on 2026-10-16T18:42:58Z.
Thanks @jotitadev, good catch:
GuestMemory::Readflushed the image itself, so the test didn't cover the store-back.I took your change: the test now copies the block directly (
std::memcpy, "raw guest read"). Pushed as88ee39183, also rebased on current main.Rerun on Windows 11:
APS5_NO_WRITE_WATCH=1)FlushPendinglooppixel (0, 0) holds (nan, nan, nan, nan)APS5_NO_RESIDENT_LINEAR=1waited for the GPU instead of being recordedOn the path switching after a
GuestAllocationsmutation: agreed, that's expected. Until something callsHostImportForagain, the target simply takes the synchronous path, and the results stay correct either way, as your runs show. In a running title the imports are reconciled by the next upload, so it's a short window.Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-16T19:52:52Z.
Data point: RTX 3060 12 GB (NVIDIA 617.42), i5-12400F, Windows 10 19045, MinGW GCC Release. Minecraft Dungeons II (PPSA16064 01.100.100), title screen, no input, 200 s rows,
APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1;mainc84249186vsmain+ this PR, interleaved with three other PRs in one batch, two rounds. FPS is the mean of the last 10[present]windows, GPU busy and idle gaps per frame over the last 8. This scene is CPU-bound on this machine (45-47 ms of idle gaps per frame).main88ee39183)Neutral on this scene (within the row spread); no regression. 0 fatal.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-16T20:24:55Z.
Thanks @parl0v for the run. Neutral there is what I'd expect: the change only touches linear color targets whose memory already has a host import, so a scene that draws to tiled targets keeps the old path. Good to have the no-regression data point on another title and GPU.
Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-16T20:33:34Z.
Tested on a third GPU family — Windows 11, RTX 3070 (Ampere, driver 617.42), WinLibs GCC 15.2 build of
88ee39183:Ampere agrees with your 4090/Intel results: the resident path and the post-draw store behave correctly here.
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-16T20:34:44Z.
Thanks @akkadbakkad89, that makes three NVIDIA generations plus Intel and lavapipe with the same result.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T23:59:36Z.
Windows full Build result for PR head
88ee391839405a8194c851e1b917116cf7be4225(run): compilation completed, but CTest markedagc_driver_linear_target_residentskipped on this runner. The overall Windows CTest run ended 1349/1350, withagc_shader_helpershitting the configured 120-second timeout; its output says the shader helper preparation assertions passed before CTest timed out. The Linux job passed. This run adds no Windows runtime result for the new test, separate from the hardware results already reported here.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T01:44:15Z.
@jotitadev's catch (the test read through
GuestMemory::Read, which flushes) is fixed in88ee39183, and the store-back now fails without theFlushPendingloop on the RTX 4090. The new test passes on the RTX 4090, the RTX 3070 (@akkadbakkad89, 469/469), the UHD 770 and lavapipe, and @parl0v's Minecraft Dungeons II run is neutral. Windows CI:agc_driver_linear_target_residentwas skipped on that runner, so CI adds no Windows runtime result for it;agc_shader_helpershit the 120 s timeout after its assertions passed, the runner hang class. Linux is green.Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-17T04:00:51Z.
AMD result, since the thread has only NVIDIA, Intel and lavapipe so far. Linux,
main07e7414819with88ee39183merged:agc_driver_linear_target_residentpasses on a Radeon 610M (RADV, Mesa) and on an RTX 5080 (driver 615.78.08). With the four source files reverted tomainit fails on both withthe draw into an imported linear target waited for the GPU instead of being recorded. It also passes on lavapipe.Titles on the RTX 5080,
main9bf01db66against the same plus this PR, one 10 s trace each:Neutral on both. A burst of about 700 consecutive Playroom frames per side shows no rendering difference; the largest frame-to-frame changes are cutscene cuts in both.