perf(agc): sort guest buffer regions through indices before merging them #4248

Merged
hypermoist merged 1 commit from upstream-pr/4248 into main 2026-10-13 04:47:05 +00:00
hypermoist commented 2026-10-12 02:16:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-12T02:16:20Z.


What

GuestBufferMemory::UploadPrepare sorted the build's Region objects themselves by address, then appended them to a merged vector that was never reserved. A Region holds several vectors and shared pointers (a few hundred bytes), so each resource build moved every region many times through the sort and the reallocations; on Killing Floor 3 (PPSA08427) the sort fell back to its heap phase and UploadPrepare was about a sixth of the queue-0 worker at the title screen.

The regions are now sorted through an index array and merged is reserved up front, so each region is moved once. The order and the merge are the same: equal begin addresses were unordered before and still are.

Tested

Linux (CachyOS, kernel 7.2.9), RTX 3060 (NVIDIA 615.78.08), GCC 16.2.1, Release.

  • Killing Floor 3 (PPSA08427, 02.011.000), on our fork with the same settings before and after, measured with perf on the queue-0 worker at the title screen: UploadPrepare went from 17.4% to 8.8% of its samples, and the title screen from about 26 to 28 presents per 10 s. Measured on a branch based on main from 2026-10-11; UploadPrepare's sort and merge are unchanged on current main. The title does not run on main alone (it stops at a draw with clip distances, #423).
  • On this branch: agc_driver_graphics, agc_driver_dcc_keys_first_write and agc_driver_storage_cache_budget pass.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01Uzy15wqYTt6iWyxYXEzUWo

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4824141211 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4248). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-12T02:16:20Z. --- ### What `GuestBufferMemory::UploadPrepare` sorted the build's `Region` objects themselves by address, then appended them to a `merged` vector that was never reserved. A `Region` holds several vectors and shared pointers (a few hundred bytes), so each resource build moved every region many times through the sort and the reallocations; on Killing Floor 3 (PPSA08427) the sort fell back to its heap phase and `UploadPrepare` was about a sixth of the queue-0 worker at the title screen. The regions are now sorted through an index array and `merged` is reserved up front, so each region is moved once. The order and the merge are the same: equal begin addresses were unordered before and still are. ### Tested Linux (CachyOS, kernel 7.2.9), RTX 3060 (NVIDIA 615.78.08), GCC 16.2.1, Release. - Killing Floor 3 (PPSA08427, 02.011.000), on our fork with the same settings before and after, measured with `perf` on the queue-0 worker at the title screen: `UploadPrepare` went from 17.4% to 8.8% of its samples, and the title screen from about 26 to 28 presents per 10 s. Measured on a branch based on `main` from 2026-10-11; `UploadPrepare`'s sort and merge are unchanged on current `main`. The title does not run on `main` alone (it stops at a draw with clip distances, #423). - On this branch: `agc_driver_graphics`, `agc_driver_dcc_keys_first_write` and `agc_driver_storage_cache_budget` pass. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Uzy15wqYTt6iWyxYXEzUWo
github-actions[bot] commented 2026-10-12 03:52:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T03:52:05Z.


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.

Pull request Conflicting files (lines on main) Same exports Same new files
#1345 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp L2760-2763
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6117422038 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4248#issuecomment-6117422038). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T03:52:05Z. --- <!-- pr-overlap --> 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**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #1345 | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` [L2760-2763](https://github.com/boykopovar/AnyPS5/blob/61e4b5506ce7bb5ce6fdd1c63a5396e589206143/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L2760-L2763) | | |
Scramblrrrr commented 2026-10-12 04:51:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T04:51:11Z.


Preparing a007 Windows cross-test of your existing commit8083dd11149, author retained, applied cleanly on our experimental runtime-table integration: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-region-sort-cross-test head908ee2bc431dfa78070e36e01044460e3fcba7e5. Not built or staged yet. After the ongoing range-map baseline, will run graphics/DCC/storage/sparse-buffer native checks and the same warm-cache007 configuration. No competing implementation or current-main mergeability claim. AI-assisted: Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6117967328 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4248#issuecomment-6117967328). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T04:51:11Z. --- Preparing a007 Windows cross-test of your existing commit8083dd11149, author retained, applied cleanly on our experimental runtime-table integration: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-region-sort-cross-test head908ee2bc431dfa78070e36e01044460e3fcba7e5. Not built or staged yet. After the ongoing range-map baseline, will run graphics/DCC/storage/sparse-buffer native checks and the same warm-cache007 configuration. No competing implementation or current-main mergeability claim. AI-assisted: Codex.
Scramblrrrr commented 2026-10-12 05:05:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T05:05:46Z.


Native Windows cross-test on 908ee2bc431dfa78070e36e01044460e3fcba7e5 passed 5/5 in 6.27 s: graphics, DCC keys first write, storage cache budget, driver sparse-buffer holes, and graphics sparse-buffer holes. RTX 5070 Ti, Vulkan required, no skips. This includes our existing sparse-copy/range-map integration; not a current-main-only claim.

No isolated 007 FPS result for this change yet. The preceding game run (without the sorting change staged) progressed beyond the licence screen and then hit the known #423 clip-distance export stop, so that integration is next before the next game run. Your change remains author-preserved and no competing PR is proposed.

AI-assisted: Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6118105698 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4248#issuecomment-6118105698). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T05:05:46Z. --- Native Windows cross-test on 908ee2bc431dfa78070e36e01044460e3fcba7e5 passed 5/5 in 6.27 s: graphics, DCC keys first write, storage cache budget, driver sparse-buffer holes, and graphics sparse-buffer holes. RTX 5070 Ti, Vulkan required, no skips. This includes our existing sparse-copy/range-map integration; not a current-main-only claim. No isolated 007 FPS result for this change yet. The preceding game run (without the sorting change staged) progressed beyond the licence screen and then hit the known #423 clip-distance export stop, so that integration is next before the next game run. Your change remains author-preserved and no competing PR is proposed. AI-assisted: Codex.
Scramblrrrr commented 2026-10-12 21:56:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T21:56:55Z.


Re-cross-test on the newer 007 recovery/fiber/key-reservation stack: your exact8083dd11149 author-preserved, integration e8cc22c7b (https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-key-and-region-sort), one production file changed relative to163f0b856. Windows/RTX5070Ti/GCC15.2 Release: full mocked agc_driver_graphics PASS5.52s; native agc_driver_dcc_keys_first_write PASS0.59s and agc_driver_storage_cache_budget PASS0.39s, neither skipped. The latter two initially were not built; after building them, both pass. Clean diff-check. This is the experimental integration, not current-main-only validation.

Game comparison has started normal warm-cache/cache16, graphicsFFD11FE14B53708C49F639F3826E31B6CC4CE6BD55AB267CFE07CAE3464C69DD/libc99D37E34. No sampler/profile or concurrent builds/native tests. Prior key-only run163f intentionally ended after~4m37 Resume, slow scene0.24->0.16FPS, unsupported image-table writes/partial output persist; no sorting FPS result yet. AI-assisted: Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6133350619 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4248#issuecomment-6133350619). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T21:56:55Z. --- Re-cross-test on the newer 007 recovery/fiber/key-reservation stack: your exact8083dd11149 author-preserved, integration e8cc22c7b (https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-key-and-region-sort), one production file changed relative to163f0b856. Windows/RTX5070Ti/GCC15.2 Release: full mocked agc_driver_graphics PASS5.52s; native agc_driver_dcc_keys_first_write PASS0.59s and agc_driver_storage_cache_budget PASS0.39s, neither skipped. The latter two initially were not built; after building them, both pass. Clean diff-check. This is the experimental integration, not current-main-only validation. Game comparison has started normal warm-cache/cache16, graphicsFFD11FE14B53708C49F639F3826E31B6CC4CE6BD55AB267CFE07CAE3464C69DD/libc99D37E34. No sampler/profile or concurrent builds/native tests. Prior key-only run163f intentionally ended after~4m37 Resume, slow scene0.24->0.16FPS, unsupported image-table writes/partial output persist; no sorting FPS result yet. AI-assisted: Codex.
Scramblrrrr commented 2026-10-12 22:09:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T22:09:10Z.


007 comparison on e8cc22c7b (#4248 on key/recovery/fiber stack) ended intentionally22:07:56.753UTC (4m23 after Resume22:03:34.078), not a crash. GraphicsFFD11FE1/libc99D37E34/cache16, normal warm cache, no sampler/profile or concurrent builds/native tests. Startup2FPS; slow scene0.43 then0.22->0.15FPS, same bright circles over black. Last private22.766GB/free5.312GB. Image-table deferred write-backs remain unsupported. This single Windows run does not establish a title-level sorting improvement; its native tests pass as reported above.

Also found #4206 absent from this current recovery stack, though it was cross-tested on our earlier8c1ed096 stack. Prepared author-preserved fixture/fix port a9454c295 (codex/first-light-key-sort-sparse-holes), not staged. CPU hole/native GPU readback/full mocked graphics pass3/3 in6.01s; verifying production-only negative control next. This fixes recycled sparse-hole bytes, not a claimed cause of the missing scene. Still leaving runtime-table stores/reference-texture fix to SleglJan. AI-assisted: Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6133518353 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4248#issuecomment-6133518353). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T22:09:10Z. --- 007 comparison on e8cc22c7b (#4248 on key/recovery/fiber stack) ended intentionally22:07:56.753UTC (~4m23 after Resume22:03:34.078), not a crash. GraphicsFFD11FE1/libc99D37E34/cache16, normal warm cache, no sampler/profile or concurrent builds/native tests. Startup~2FPS; slow scene0.43 then0.22->0.15FPS, same bright circles over black. Last private22.766GB/free5.312GB. Image-table deferred write-backs remain unsupported. This single Windows run does not establish a title-level sorting improvement; its native tests pass as reported above. Also found #4206 absent from this current recovery stack, though it was cross-tested on our earlier8c1ed096 stack. Prepared author-preserved fixture/fix port a9454c295 (codex/first-light-key-sort-sparse-holes), not staged. CPU hole/native GPU readback/full mocked graphics pass3/3 in6.01s; verifying production-only negative control next. This fixes recycled sparse-hole bytes, not a claimed cause of the missing scene. Still leaving runtime-table stores/reference-texture fix to SleglJan. AI-assisted: Codex.
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!4248
No description provided.