perf(agc): note an address space's in-place reads by reference #4978
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4978"
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 AlxcBTW on 2026-10-13T07:09:11Z.
What
An address-based build now notes the cached address space's in-place reads by reference instead of copying them into its batch.
GuestBufferMemory::AddressSpacebuildsdirectReadsonce when the space is published: the ranges its imports serve in place, sorted and disjoint. It is shared by every build that takes the space and dies with it, so it follows the registry generation, the import epoch and the device exactly as the space does.GuestBufferMemory::SplitInPlaceReads()returns that list plus the build's own in-place ranges. Their concatenation isInPlaceReads(); a build that does not hold the space (or is committed) returns nothing and keeps the old path.Recorder::NotePendingReadList()notes a shared list on the open batch in O(1).readOverlapwalks plain reads and lists in note order (a list by bisection), soPendingReadOverlapsandDescribePendingReadanswer and report the reader kind exactly as the ranges noted one by one. The same list noted again in a batch is dropped, because an earlier note is always found first. A capture trace orAPS5_FLIP_READ_CHECKnotes the ranges one by one as before, so trace lines and the submit-time collect do not change.ShaderResources::MarkGpuWritesnotes the space's list, then the build's own ranges.No environment switch: the path is always on and exact.
Why
Every address-based build copied the space's imported ranges (about 9000 in Sword of the Sea gameplay) into its batch, roughly 44 million range notes per 10 s, only for the copy HLE's reader check to scan them. On a lab line (a fork of this code with the same hooks) the change, together with the BDA table memo that is not part of this PR, measured:
record: marksfell from 15-19 us to 3-6 us per dispatch.InPlaceReads()on sampled notes and compared found 0 mismatches in 517 comparisons.These numbers come from the lab line, not from
main, and I did not capture the Performance report summary lines ofmainagainst this branch, so treat them as the motivation and not as the report the protocol asks for.Tested
tests/Recorder.cppreadListTests, own ctestagc_recorder_read_list: random lists noted by reference answer everyPendingReadOverlapsandDescribePendingReadquery like the same ranges noted one by one, for the open batch and for the batch in flight, with plain reads of other kinds before, between and after the lists, the same list noted twice, and empty and null lists. It also checks that the queries cover several reader kinds, so the comparison is not vacuous, and that the noted-read counter adds the list's size.tests/BdaResources.cppspaceReadListTests(inagc_driver_graphics): the space's list is shared by builds while the registry stands, rebuilt when a range is added or removed, is valid (sorted, disjoint), andspace + own == InPlaceReads(); a committed build and a build without the space offer no split.tools/check_conventions.py --base origin/main: passed.build.yml): Linux and Windows green, 0 failures (https://github.com/AlxcBTW/AnyPS5/actions/runs/38358855402); the newagc_recorder_read_listpassed on Linux (lavapipe) and is skipped on Windows, which has no Vulkan on the runner. Run on the commit before a rebase onto amainthat only addedtests/ShaderMemory.cppChecklist
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T08:40:20Z.
Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on main
534451426together with six other open GPU PRs (their own commits applied, no merge conflicts), so only the tests that belong to this PR say something about it:tests/BdaResources.cpp(targetagc_driver_graphics_tests;agc_driver_graphics10 of 10,agc_sparse_buffer_holes,agc_descriptor_pool_reset_failure,agc_compute_descriptor_layout_flags3 of 3) andtests/Recorder.cpp(targetagc_driver_recorder_tests;agc_pipeline_cache,agc_pipeline_library,agc_pipeline_library_off,agc_pipeline_library_fast_only,agc_unchanged_cpu_stamps,agc_storage_*,agc_recorder_read_list,agc_host_import_unmapand the other tests of that target): 3 of 3 passed each.Not tested: no game run. The batch was built once, not per PR; nothing failed, so no bisect was needed.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by winstrex on 2026-10-13T16:30:51Z.
Measured on a game: The Pathless (PPSA01825, 02.000.000) at the main menu, Windows 11, RTX 5070 Ti, WinLibs GCC 15.2.0 Release. Base is
mainc422b57fb+ #4491 (needed to reach the menu). Since this PR conflicts withmain, I measured an equivalent commit applied on top of that base: the cached address space keeps one shared list of its in-place reads and the batch notes it by reference, once per batch, as here.APS5_TRACE_SECONDSwindow of 12 s at the menu, warm caches, runs alternated base/change, 3 valid runs per side (runs lost to the Wwise crash of #361 were repeated):Graphics.Drawon queue worker 0x0About 159 draws per frame on both sides, so -14.8 ms per frame (+17 % FPS), with #4428 already on
main.Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T16:35:43Z.
Thank you @winstrex, that's a great independent number: −14.8 ms per frame (+17 % FPS) on The Pathless, a different title from the one I measured, with #4428 already on main. A rebase onto current main is on its way. The conflicts are test registration only (
CMakeLists.txtandtests/BdaResources.cpp); I'll post the new head here once its CI is green.Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T18:24:26Z.
Rebased onto current main. The only conflicts were in test registration (
CMakeLists.txt,tests/BdaResources.cpp; both sides' tests kept). Full ctest on the fork CI is green on Windows and Linux. The only Linux failure isguest_math, which depends on the host libm (#5154).Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:25:09Z.
Reviewed the diff: the shared
directReadslist is built once per published space,readOverlapkeeps the note order across plain reads and lists, a repeated list is dropped, and the capture-trace / flip-read-check paths still note ranges one by one.space + own == InPlaceReads()and the by-reference vs one-by-one equivalence are pinned by the new tests, which don't compile without the change.The only conflict with
mainwas test registration inlibSceAgcDriver/CMakeLists.txt; I rebased and kept both sides. Build and the libSceAgcDriver ctest scope pass on the rebased tree (agc_recorder_read_listandagc_driver_graphicsincluded);agc_driver_tessellationsegfaults inside RADV's pipeline-library link (libvulkan_radeon), unrelated to this change. Thanks @xXPBSXx and @winstrex for the Windows and The Pathless runs; merging once CI is green.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T12:11:19Z.
mainmoved again (new tests registered next to this PR's intests/BdaResources.cppandtests/Recorder.cpp); I rebased and kept both sides, no logic changes. Full build and ctest pass on the rebased tree (agc_recorder_read_listandagc_driver_graphicsincluded) exceptagc_driver_tessellation, which segfaults inside RADV's pipeline-library link (libvulkan_radeon), unrelated to this change. Merging once CI is green.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T12:34:18Z.
mainmoved again (a new test name in the Windowsset_tests_propertieslist inlibSceAgcDriver/CMakeLists.txt); I rebased and kept both sides, no logic changes. Build and the libSceAgcDriver ctest scope pass on the rebased tree (agc_recorder_read_listandagc_driver_graphicsincluded) exceptagc_driver_tessellation, which segfaults inside RADV's pipeline-library link (libvulkan_radeon), unrelated to this change. Merging once CI is green.