fix(agc): recycle detiler descriptor pools once their batches complete #6168
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6168"
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 parl0v on 2026-10-15T00:10:45Z.
What
TextureDetiler::BeginBatchreset the texture, image and CMASK descriptor pools only whenRecorder::Idle(). A title that keeps the recorder busy never reaches that point, so every 64 detiles added a new 64-set pool untilvkAllocateDescriptorSetsfailed with -2 (VK_ERROR_OUT_OF_DEVICE_MEMORY). On PPSA25344 (Sword of the Sea) with #6060 the title holds near 9 FPS, the process climbs to about 31.6 GB private and stops withafter 12 and 22 minutes in two runs.
Each pool now carries the serial of the newest recorder batch that used one of its sets (
Recorder::OpenSerial()). When the current pool is full, the next pool whose serial is at or belowRecorder::CompletedThrough()(the newest serial with no batch still in flight) is reset and reused; only when none is free is a new pool created. The idle reset inBeginBatchstays. The three pool sets share this ring (DescriptorRing).Tested
Windows 10, PPSA25344 title screen,
APS5_PROFILE_DRAW=1, RTX 3060, same relinked executable, 40 min each:The last twelve windows of the 40-min run average 9.99 FPS. An earlier 15-min run of the same build went from 9.92 to 10.45 GB with no stop.
With
main's import path (#6060 built,APS5_NO_WATCHED_PRIVATE_IMPORTS=1) SotS's title runs at about 3 FPS (#5596), the recorder goes idle between frames and the pools are reset there, so a 40-min run doesn't stop (238 windows, 7,132 frames). The stop needs a title fast enough to keep batches in flight, which #6060 and #5851 both give it.ctest -R '^agc_': 563 of 564 on RTX 4060;agc_shader_disk_cachefails the same way onmain.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-10-15T00:12:31Z.
Code review location:
core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetilerDescriptors.cpp; line 37When this pool reaches 64 sets, the search begins at
(ring.current + 1)and iterates onlystep < ring.pools.size(), so it never considers the current pool. If the current pool’s last-use serial has completed (the common case when there is just one pool, or after older pools are busy), this allocates a new pool instead of resetting the completed one. Under a sustained workload this can still grow descriptor-pool memory without bound. Could the selection checkring.currenttoo when its serial is<= completed? A regression test with one pool whose serial is completed at the next allocation would cover this.Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-15T00:17:33Z.
Code review location:
core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetilerDescriptors.cpp; line 37Thanks, you're right that it skipped the current pool. Fixed in
0e15b9be9: the search now runsstep <= ring.pools.size(), so it ends at the current pool and resets it when its serial is completed. Before, this cost one pool more than needed rather than unbounded growth (the skipped pool was the first one checked at the next fill, and the 40-min SotS run held at 10.4 GB), but it was still a pool too many.The test you suggested is in
tests/TextureDetiler.cpp: three pools' worth of dispatches with no batch in flight, and the pool count has to stay the same. It fails on8e56f5610and passes now.ctest -R '^agc_'is 563/564 on the RTX 4060 (onlyagc_shader_disk_cache, as onmain).Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-15T00:25:18Z.
Same 40-min run with #5851 instead of #6060 (box 2, RTX 3060, SotS title, 8.45 FPS over its last twelve 10 s windows): it stops after 73 windows (about 12 min) with the same
So the stop follows the frame rate, not either import change: both PRs that bring SotS back to ~9 FPS reach it, and
main's import path at ~3 FPS doesn't.Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-15T00:41:22Z.
Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with
0e15b9be9merged into mainab9a47684:agc_driver_graphics.Recorder.hpp,TextureDetiler.hpp,TextureDetiler.cpp,TextureDetilerDescriptors.cpp):agc_driver_graphicsfails withAGC graphics: a full descriptor pool whose batches completed must be reset and reused, not joined by a new pool; the other 7 pass.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-15T01:12:37Z.
@coltken95 thanks, good to have the test failing on
main's detiler sources on a second OS.A second 40-min SotS title run with this PR at
0e15b9be9(on top of #6060): 23,605 frames, 9.96 FPS over the last twelve windows, no stop, private bytes 10.01 → 10.34 GB, +18 MB over the last 15 min.Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-15T03:47:41Z.
A question on head
0e15b9be9, from reading the code. InallocateFrom(TextureDetilerDescriptors.cpplines 27 to 39), whenRecorder::Active()is null,completedisstd::numeric_limits<std::uint64_t>::max()and every pool's serial is stored as 0 (line 62). So once the current pool holds 64 sets, the next pool in the ring is reset at once, and with a single pool that is the pool just filled. If any caller detiles without an active recorder and puts more than 64 sets into one command buffer before submitting it, the sets already bound there would be freed before it runs. If no such path exists, a throw there would make that explicit.The runs here did not reach that case. Current main
a077a88dfwith this PR merged: its 4 tests pass on an RTX 5080 (NVIDIA), the Ryzen 7800X3D's integrated Radeon (RADV) and lavapipe. UnderVK_LAYER_KHRONOS_validationon NVIDIA and RADV they report the same messages as main's tests (pre-existingvkCmdPipelineBarrieraccess-mask ones) and nothing about descriptor sets. On a Radeon 680M the new test also fails on main's detiler sources.Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-10-15T04:04:01Z.
Windows run of
0e15b9be9merged ontomaina077a88df(clean); Windows 11 10.0.26200, Ryzen 7 5800X, RTX 4090 (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 r7, Release, default environment.mainat this base and not from this PR:agc_driver_image_plane_address_on_line(fails onmaine52e140f5, reported on #5583) andguest_kqueue(#5493's newDeniedParentWatchcase under an elevated session, reported there). Both pass onmainfa539dd9b.Tested with AI assistance (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T08:07:48Z.
Review: CHANGES_REQUESTED
Checked on the PR merged onto current main: build + ctest of libSceAgcDriver are green (
agc_driver_tessellationsegfaults on main as well), andagc_driver_graphicsfails with the detiler sources reverted, so the new test does exercise the recycling.One point to fix:
TextureDetilerDescriptors.cpp:29and:62: with no activeRecorder,completedisUINT64_MAXand every serial is stored as 0, so as soon as the current pool holds 64 sets the next ring slot is reset immediately, and with a single pool that is the pool just filled. Sets already recorded into the same command buffer would be freed before it runs; before this PR a new pool was created there (the reset only happened inBeginBatch). This is the case @fma-rc asked about above. Without a recorder there is no completion information, so the ring should not reuse a pool (create a new one, as before), or throw if that path cannot happen. Please add a test case for it (more than 64Dispatchcalls with no active recorder, asserting no pool is reset while its sets are bound).The rest (serial taken from
OpenSerial(),CompletedThrough()bound, the idle reset kept inBeginBatch) looks right to me.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T08:15:12Z.
Review: APPROVED
Checked on the PR merged onto current main: build + ctest of libSceAgcDriver are green (
agc_driver_tessellationsegfaults on main as well).Added one commit on your branch (
fix(agc): keep detiler descriptor pools unrecycled without a recorder) for the case @fma-rc asked about: with no activeRecorder,completedwasUINT64_MAXand every serial 0, so a full pool reset the next ring slot at once (with one pool, the one just filled) while its sets could still be recorded in the same command buffer. Without a recorder there is no completion information, socompletedis now 0 and those sets get serialUINT64_MAX: such pools are only reset byBeginBatch(as on main), and a full one is joined by a new pool.The detiler test ran its 192 dispatches with no recorder, so it required exactly that reuse. It is now two cases: with no recorder, no pool is reset and new pools are created; with an active recorder, 4 batches of 64 dispatches with
Sync()between them keep the pool count of the first batch.agc_driver_graphicspasses, fails with your previous lines (a descriptor pool was reset with no recorder ...), and fails with a ring that never reuses (a full descriptor pool whose batches completed must be reset and reused ...).The rest (serial taken from
OpenSerial(),CompletedThrough()bound, the idle reset kept inBeginBatch) looks right to me. Merging once the full Build is green.