perf(agc): note an address space's in-place reads by reference #4978

Merged
AlxcBTW merged 1 commit from upstream-pr/4978 into main 2026-10-14 13:02:33 +00:00
AlxcBTW commented 2026-10-13 07:09:11 +00:00 (Migrated from github.com)

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::AddressSpace builds directReads once 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 is InPlaceReads(); 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). readOverlap walks plain reads and lists in note order (a list by bisection), so PendingReadOverlaps and DescribePendingRead answer 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 or APS5_FLIP_READ_CHECK notes the ranges one by one as before, so trace lines and the submit-time collect do not change.
  • ShaderResources::MarkGpuWrites notes 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:

  • Sword of the Sea gameplay, RTX 5070: q0 -11.5 ms per frame, +8-9 % FPS (6.33 -> 6.89 FPS over settled segments; two more runs agree within 1 %).
  • record: marks fell from 15-19 us to 3-6 us per dispatch.
  • With only this part switched on, FPS was +5.6 % against the neighbouring base segment.
  • A verify mode that rebuilt 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 of main against this branch, so treat them as the motivation and not as the report the protocol asks for.

Tested

  • tests/Recorder.cpp readListTests, own ctest agc_recorder_read_list: random lists noted by reference answer every PendingReadOverlaps and DescribePendingRead query 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.cpp spaceReadListTests (in agc_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), and space + own == InPlaceReads(); a committed build and a build without the space offer no split.
  • tools/check_conventions.py --base origin/main: passed.
  • CI on the fork (Linux and Windows, same steps as build.yml): Linux and Windows green, 0 failures (https://github.com/AlxcBTW/AnyPS5/actions/runs/38358855402); the new agc_recorder_read_list passed on Linux (lavapipe) and is skipped on Windows, which has no Vulkan on the runner. Run on the commit before a rebase onto a main that only added tests/ShaderMemory.cpp
  • Not tested on hardware by me beyond the lab measurements above; no game was started for this PR.

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: none (CPU time per frame in Sword of the Sea gameplay, PPSA number not recorded here)
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4839687179 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4978). Originally posted by [AlxcBTW](https://github.com/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::AddressSpace` builds `directReads` once 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 is `InPlaceReads()`; 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). `readOverlap` walks plain reads and lists in note order (a list by bisection), so `PendingReadOverlaps` and `DescribePendingRead` answer 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 or `APS5_FLIP_READ_CHECK` notes the ranges one by one as before, so trace lines and the submit-time collect do not change. - `ShaderResources::MarkGpuWrites` notes 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: - Sword of the Sea gameplay, RTX 5070: q0 -11.5 ms per frame, +8-9 % FPS (6.33 -> 6.89 FPS over settled segments; two more runs agree within 1 %). - `record: marks` fell from 15-19 us to 3-6 us per dispatch. - With only this part switched on, FPS was +5.6 % against the neighbouring base segment. - A verify mode that rebuilt `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 of `main` against this branch, so treat them as the motivation and not as the report the protocol asks for. ### Tested - `tests/Recorder.cpp` `readListTests`, own ctest `agc_recorder_read_list`: random lists noted by reference answer every `PendingReadOverlaps` and `DescribePendingRead` query 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.cpp` `spaceReadListTests` (in `agc_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), and `space + own == InPlaceReads()`; a committed build and a build without the space offer no split. - `tools/check_conventions.py --base origin/main`: passed. - CI on the fork (Linux and Windows, same steps as `build.yml`): Linux and Windows green, 0 failures (https://github.com/AlxcBTW/AnyPS5/actions/runs/38358855402); the new `agc_recorder_read_list` passed on Linux (lavapipe) and is skipped on Windows, which has no Vulkan on the runner. Run on the commit before a rebase onto a `main` that only added `tests/ShaderMemory.cpp` - Not tested on hardware by me beyond the lab measurements above; no game was started for this PR. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none (CPU time per frame in Sword of the Sea gameplay, PPSA number not recorded here) - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
xXPBSXx commented 2026-10-13 08:40:20 +00:00 (Migrated from github.com)

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 534451426 together 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 (target agc_driver_graphics_tests; agc_driver_graphics 10 of 10, agc_sparse_buffer_holes, agc_descriptor_pool_reset_failure, agc_compute_descriptor_layout_flags 3 of 3) and tests/Recorder.cpp (target agc_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_unmap and 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).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141707178 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4978#issuecomment-6141707178). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T08:40:20Z. --- Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on main `534451426` together 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` (target `agc_driver_graphics_tests`; `agc_driver_graphics` 10 of 10, `agc_sparse_buffer_holes`, `agc_descriptor_pool_reset_failure`, `agc_compute_descriptor_layout_flags` 3 of 3) and `tests/Recorder.cpp` (target `agc_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_unmap` and 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).
winstrex commented 2026-10-13 16:30:51 +00:00 (Migrated from github.com)

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 main c422b57fb + #4491 (needed to reach the menu). Since this PR conflicts with main, 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_SECONDS window 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):

frame time FPS Graphics.Draw on queue worker 0x0
base 100.3 ± 2.8 ms 9.98 ± 0.28 436 ± 17 us per draw, 69.4 ± 2.7 ms per frame
change 85.5 ± 1.5 ms 11.70 ± 0.21 347 ± 6 us per draw, 55.2 ± 1.0 ms per frame

About 159 draws per frame on both sides, so -14.8 ms per frame (+17 % FPS), with #4428 already on main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6150272190 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4978#issuecomment-6150272190). Originally posted by [winstrex](https://github.com/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 `main` c422b57fb + #4491 (needed to reach the menu). Since this PR conflicts with `main`, 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_SECONDS` window 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): | | frame time | FPS | `Graphics.Draw` on queue worker 0x0 | |---|---|---|---| | base | 100.3 ± 2.8 ms | 9.98 ± 0.28 | 436 ± 17 us per draw, 69.4 ± 2.7 ms per frame | | change | 85.5 ± 1.5 ms | 11.70 ± 0.21 | 347 ± 6 us per draw, 55.2 ± 1.0 ms per frame | About 159 draws per frame on both sides, so -14.8 ms per frame (+17 % FPS), with #4428 already on `main`.
AlxcBTW commented 2026-10-13 16:35:43 +00:00 (Migrated from github.com)

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.txt and tests/BdaResources.cpp); I'll post the new head here once its CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6150361308 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4978#issuecomment-6150361308). Originally posted by [AlxcBTW](https://github.com/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.txt` and `tests/BdaResources.cpp`); I'll post the new head here once its CI is green.
AlxcBTW commented 2026-10-13 18:24:26 +00:00 (Migrated from github.com)

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 is guest_math, which depends on the host libm (#5154).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152315500 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4978#issuecomment-6152315500). Originally posted by [AlxcBTW](https://github.com/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 is `guest_math`, which depends on the host libm (#5154).
adriadam10 commented 2026-10-14 11:25:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:25:09Z.


Reviewed the diff: the shared directReads list is built once per published space, readOverlap keeps 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 main was test registration in libSceAgcDriver/CMakeLists.txt; I rebased and kept both sides. Build and the libSceAgcDriver ctest scope pass on the rebased tree (agc_recorder_read_list and agc_driver_graphics included); agc_driver_tessellation segfaults 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6167242969 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4978#issuecomment-6167242969). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T11:25:09Z. --- Reviewed the diff: the shared `directReads` list is built once per published space, `readOverlap` keeps 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 `main` was test registration in `libSceAgcDriver/CMakeLists.txt`; I rebased and kept both sides. Build and the libSceAgcDriver ctest scope pass on the rebased tree (`agc_recorder_read_list` and `agc_driver_graphics` included); `agc_driver_tessellation` segfaults 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.
adriadam10 commented 2026-10-14 12:11:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T12:11:19Z.


main moved again (new tests registered next to this PR's in tests/BdaResources.cpp and tests/Recorder.cpp); I rebased and kept both sides, no logic changes. Full build and ctest pass on the rebased tree (agc_recorder_read_list and agc_driver_graphics included) except agc_driver_tessellation, which segfaults inside RADV's pipeline-library link (libvulkan_radeon), unrelated to this change. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6168033336 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4978#issuecomment-6168033336). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T12:11:19Z. --- `main` moved again (new tests registered next to this PR's in `tests/BdaResources.cpp` and `tests/Recorder.cpp`); I rebased and kept both sides, no logic changes. Full build and ctest pass on the rebased tree (`agc_recorder_read_list` and `agc_driver_graphics` included) except `agc_driver_tessellation`, which segfaults inside RADV's pipeline-library link (`libvulkan_radeon`), unrelated to this change. Merging once CI is green.
adriadam10 commented 2026-10-14 12:34:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T12:34:18Z.


main moved again (a new test name in the Windows set_tests_properties list in libSceAgcDriver/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_list and agc_driver_graphics included) except agc_driver_tessellation, which segfaults inside RADV's pipeline-library link (libvulkan_radeon), unrelated to this change. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6168450651 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4978#issuecomment-6168450651). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T12:34:18Z. --- `main` moved again (a new test name in the Windows `set_tests_properties` list in `libSceAgcDriver/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_list` and `agc_driver_graphics` included) except `agc_driver_tessellation`, which segfaults inside RADV's pipeline-library link (`libvulkan_radeon`), unrelated to this change. Merging once CI is green.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!4978
No description provided.