fix(agc): free a completed batch's command buffer instead of keeping it #9565
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9565"
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 EagleBearerYS on 2026-10-22T02:28:35Z.
What
The recorder keeps up to 64 completed command buffers for reuse and begins new batches on them. fable-void found that on Windows drivers, a command buffer keeps the host memory of its largest recording until it is freed. Neither the implicit reset at begin nor a releasing reset gives that memory back. So every kept command buffer holds the peak of its own recordings. In one of his title runs, the driver's command arenas grew by 3.4 GiB in 17 s, until the run hit the RAM cap.
This adapts fable-void's dfbbdfdaf4 from his fork (
wip/new-gpu-path). His recorder keeps a pool and a spare list per stream, andmainhas one of each:Recorder::releasefrees a batch's command buffer, and every batch allocates its own from the context's pool. The pool then holds only what batches still recording or in flight need. Fences are still kept for reuse. The spare list's comment, which described command buffers being kept, goes with them.APS5_PROFILE_DRAWset, the[recorder] submitsline also givescommand buffers freed at batch release N, fences kept for reuse N. Without the profile it costs one test of astatic const bool.The cost is one
vkAllocateCommandBuffersper batch, wheremainreused a kept one.fable-void's own test,
idle_command_memory, reads Windows private bytes through a test fixturemaindoesn't have, so it isn't carried.Overlap: checked with
git merge-treeagainst every open PR touching these files, onmain8c26eac3cd. Two conflict:Recorder::release, and keepsmain's reuse of the batch's own command buffer. The two touch the same lines ofrelease. Composed, the batch's own command buffer is freed and the chunk handling stays as #9289 has it. This PR goes first, as Celegans12 agreed (reply), and #9289 rebases over it (note).tests/Recorder.cpp'smain(). Their library changes don't meet: #7048's are inTexture.cpp. Neither needs to wait, and whichever merges second keeps both test modes (note).Tested
agc_recorder_command_buffer_release(new mode--command-buffer-release-onlyof the recorder tests) counts the recorder'svkAllocateCommandBuffersandvkFreeCommandBufferscalls through a resolver probe, over three completed batches. Each batch must free the command buffer it allocated.main's code, it fails ×3 with "command buffer release: after 1 completed batches 1 command buffers were allocated and 0 freed (a completed batch kept its command buffer)".maincf2c667060: 1812/1818, with the same 6 failures asmain.mainagainst this PR (CONTRIBUTING's AGC rule), on one GitHub Linux runner (run). Both runs usedVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1andctest -V, withVK_LOADER_DEBUG=layerto show the layer loading. The device was llvmpipe (LLVM 20.1.2) on Mesa 25.2.8, Ubuntu 24.04.5, Khronos validation layers 1.3.275.agc_recorder_command_buffer_release, plus the 56 tests whose build inputs this PR touches, such asagc_storage_write_back,agc_host_import_unmapandagc_pipeline_cache: 57 with this PR and 56 onmain, where the new test doesn't exist. On both trees 6 of them skip on llvmpipe,agc_unit_shadowamong them, and none fail:mainran its other 50 once and this PR its other 51 three times.mainand 153 with this PR, and neither log haswas not found.VUID-VkImageViewCreateInfo-usage-02275andVUID-vkCmdCopyBuffer-srcBuffer-00118, from tests this PR doesn't change. This PR adds noVUID-message.main6ef5a1c4c,ANYPS5_NO_SHADER_CACHE=1.agc_recorder_command_buffer_releasepasses 3 of 3 on an NVIDIA GeForce RTX 3070 (proprietary driver) and on llvmpipe (LLVM 21.1.8).Recorder.cppandRecorder.hppatmainand the test kept, it fails on both devices with the expected message.^agctests have the same pass set asmainon the 3070 (lds_atomics64,driver_flipanddisplay_buffer_dccleft out).main7e2ba73e4plus other open PRs, with this PR's change the only difference between the two arms.main'sRecorder.cppandRecorder.hppand the new test, it fails after batch 1, with 1 command buffer allocated and 0 freed. With this PR it passes.ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andctest -V. Both arms log the same twoVUID-VkImageViewCreateInfo-usage-02275errors, fromagc_sampled_storage_base_level_usage. This PR adds noVUID-message.main4777caca34merged in (clean; the PR's own diff is unchanged), on GitHub's runners (run): On Linux,agc_recorder_command_buffer_releaseand 49 of the other 55 AGC tests run with it pass 10 of 10, and 6 skip; none fail. On Windows all 69 build: 3 pass 10 of 10 and the other 66, the new test among them, skip without a Vulkan device. On Linux's one run withmain's implementation,agc_recorder_command_buffer_releasefails,agc_gpu_timing_completetimes out, 48 pass and 6 skip. libkernel's suite passes on both and libc's on Windows. On Linux libc's one failure isprecise_wait, a timing test this PR doesn't touch.mainb7d1d47a5fmerged in (clean; the PR's own diff is unchanged), on GitHub's runners (run):agc_recorder_command_buffer_releaseand the AGC tests run with it pass 10 of 10. On Linux that is 56 tests, 6 of them skipped. On Windows all 69 build and pass, and 66 skip without a Vulkan device. On Linuxagc_recorder_command_buffer_releasefails withmain's implementation. The libc and libkernel suites pass on both runners. The libc and libkernel suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.check_conventions.pypasses, with no comment lines added.APS5_PROFILE_DRAW=1; no fatal error. The last[recorder]line readssubmits 44845, ... command buffers freed at batch release 44844, fences kept for reuse 44844, so the release path runs for every batch in this title.3629538bc0, a merge ofmainf3eb573e6f(run). The one conflict was the Windowsset_tests_propertieslist incore/libs/prx/libSceAgcDriver/CMakeLists.txt, where Astronaut10's #11696 addsagc_repeat_storage_guardand this PR addsagc_recorder_command_buffer_release; the merge keeps both. This PR's other changed lines are the same. On Linux,agc_recorder_command_buffer_releasefails withmain's code and passes 10 runs in a row with the change, run with the recorder and AGC tests that share its executable and #11696'sagc_repeat_storage_guard. Linux: 75 run, 68 pass, 7 skip, 0 fail; the skips (agc_driver_unit_shadow,agc_driver_unit_shadow_budget,agc_import_settle_initial_dcc,agc_pipeline_cache_file,agc_shadowed_key_stores,agc_storage_clear_hand_overandagc_unit_shadow) skip withmain's code too. Windows: 91 run, 4 pass, 87 skip (the Vulkan device tests), 0 fail. Suites: libc and libkernel pass on Linux (171 and 289). On Windows libc passes (199), and libkernel passes 309 of 312:exec_arguments,guest_timed_join_import_libkernel_sysandguest_timed_join_import_libkernel_webfail at their setup in the verify's Windows build (FileNotFoundErrorstarting the title, or copying the libraries they load), withmain's code too, and pass inmain's own Windows job at1829def9bf(job). The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.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-22T04:00:39Z.
Early review feedback while this remains a draft: the Linux red/green allocation probe gives useful evidence that completed batches free their command buffers, and the change is scoped to the recorder. Before marking this ready, please resolve the listed overlap with #9289 in
Recorder::releaseand #7048 intests/Recorder.cppwith the affected authors; addDepends onwhere an agreed order is required and retain both PRs’ behavior/tests. The repo’s AGC rule also requires a same-machine, same-GPU focused main/change run withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1and the Khronos validation layer, confirming it loaded and comparing VUIDs. The current report has a Linux llvmpipe regression test but no such paired validation run, and it says the Windows memory measurement is still pending. I did not run tests locally.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T04:21:26Z.
Review: COMMENTED
Ran this on real hardware (Linux, NVIDIA and lavapipe). Head
22bf8fcc9, merged ontoorigin/mainat6ef5a1c4c.Machine: Ubuntu 26.04, GCC 15.2.0,
ninja -j3,ANYPS5_NO_SHADER_CACHE=1, device picked withVK_ICD_FILENAMES.agc_recorder_command_buffer_release(the new--command-buffer-release-onlycase),ctest --repeat until-fail:3:Negative control: reverting
Recorder.cpp/Recorder.hpptoorigin/mainand keeping only the test + itsadd_testmakes it fail on both devices with the expected message, so the test is a genuine red→green guard:No regression in the recorder/graphics
^agcsuite versusorigin/mainon the RTX 3070 (same pass set;lds_atomics64/driver_flip/display_buffer_dccexcluded).GPUs tested: NVIDIA GeForce RTX 3070 (proprietary), llvmpipe/lavapipe (Mesa, software).
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T06:40:25Z.
@jotitadev thanks for running it on the RTX 3070 and lavapipe, with the negative control and the
^agccomparison. It's in Tested now, and the 3070 is on the GPUs tested line.Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-22T08:50:47Z.
Windows native cross-test of22bf8fcc92 completed on c91598099b3d. Baseline62cf2d1a04 is current main7e2ba73e4 plus our #9591/#6918 prerequisites and #9652; the memory change is the only difference between these recorder arms. All authors' commits retained:
https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-oct22-join-memory
Windows11 10.0.26200, RTX5070Ti/NVIDIA617.42, Ryzen7800X3D, WinLibs GCC15.2r7 Release, SPIRV Tools OFF:
Clean final packaging and all369 runtime-module SHA256 values verified before staging. A combined007 loading probe has just started with the same28GiB private/2GiB free guard. No isolated Windows memory saving claimed yet: this title run also carries #9652, and its prior large pipeline was not completely warmed. I will report observed private memory and your freed-buffer counter without attributing an unpaired saving. Raw title data stays local. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-22T08:55:22Z.
Correction to the title-run status above: c915's first007 launch aborted after about29s with
VOP2 opcode is not implemented(std::invalid_argument), well below the RAM cap. It is not a Windows memory-saving result. Native results stand unchanged.I am separating the changes: isolated memory headc4162b2156b8 differs from c915 only by retaining the old joinedRun predicate, plus removing #9652's added fixture assertion. Rebuilt successfully, same recorder/import native gate is running before its title control. No attribution to #9565 yet. The other author's coordination thread has the exact heads:
https://github.com/boykopovar/AnyPS5/pull/9652#issuecomment-6336788980
AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T08:56:37Z.
@Scramblrrrr thanks for the Windows run on the RTX 5070 Ti, with the red control against
main's recorder and the validation comparison. It's this case's first run on a Windows GPU, and it's in Tested and on the GPUs tested line now. Thanks too for keeping the title runs apart until the memory arms are isolated.Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-22T09:19:54Z.
Isolated #9565 control c4162b2156b8 reached the correctly rendered offline007 menu and did not reproduce c915's VOP2 startup abort during its17-minute run. Menu78/62.137794s=1.25527FPS, GPU196.17083ms/present, effectively unchanged versus b36's1.22951FPS. Freed-command-buffer counter was active. This is one run, not sufficient to attribute the combined build's early failure.
Resume09:13:12.714UTC; the game then logged a RenderThread access violation reading0xffffffffffffffff at the previously discussed terrain/quadtree site. The guard terminated it at09:14:29.572UTC,76.858s after input, while the fatal report was being written. It was NOT the28GiBprivate cap: last private23,834,996,736bytes. Free memory fell from~5.3GB just after a trim to166MB at the final sample; the causal ownership of that late drop is unverified. The guest fault is present before guard termination, so this must not be reported as a pure memory-guard exit or a completed gameplay pass.
No isolated Windows RAM-saving claim from this pair. The five-frame menu trace has no dropped events: p50803.7ms/GPU196.0ms, queue0~748.6ms busy per frame, other queues mostly waiting. Next controlled work is #8887; runtime remains c416, no opcode/guest-title bypass. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T12:06:12Z.
Thanks, @MarcZX10. The branch now has
mainat4777caca34merged in (1da6feaf16), with the PR's own diff unchanged. On GitHub's runners (run),agc_recorder_command_buffer_releaseand the other recorder tests pass 10 of 10 on both, and the set fails withmain's implementation on Linux. It's in Tested.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T14:25:31Z.
Review: CHANGES_REQUESTED
The updated head
1da6feaf1699ecdaaee9eaa1a124cf22466edafchas strong red/green evidence: the new resolver-probe test fails against main and passes with the implementation, repeated on llvmpipe, RTX 3070 and RTX 5070 Ti; the paired validation-layer comparisons report no new VUIDs. Hosted eligibility, conventions, labels and report pass; product and relinker jobs are skipped. I did not run a local GPU build.I refreshed upstream/main to
329efe1bfdaff116c57cdf62718026ee4f5521ae. This head is 3 ahead / 45 behind (merge base4777caca343bf09a3fe245830acd9e9f433e8e18); current-base merge-tree, diff-check and conventions pass. The intervening main changes do not touch this PR’s recorder implementation, test or CMake registration. Please bring the branch up to current main and rerun the focused command-buffer-release recorder case before merge, per the branch rule.The current #9289 head
2f412bb25fd3c389381ad6cac1cabda75137438cincludes the #9176 → #9287 stack, but it does not contain this PR’s latest head; the current pairwise merge-tree still conflicts inGraphics/src/Recorder.cpp. The stated order is #9565 first, then #9289 rebases. Please ensure #9289 is rebased over the merged #9565 head and the combined recorder tests are run before that stacked change merges. This is an integration follow-up, not a new defect in this PR’s isolated fix.Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T15:08:04Z.
Thanks, @MarcZX10.
mainatb7d1d47a5fis now merged in (3c447086be), and the PR's own diff is unchanged. On GitHub's runners (run),agc_recorder_command_buffer_releasepasses 10 of 10 on Linux, along with the other AGC tests in that run, and fails there withmain's implementation. On Windows they build and pass, with the tests that need a Vulkan device skipping. It's in Tested. The combined recorder tests with #9289 come after this PR merges, when #9289 rebases over it, in the order agreed in its thread.