perf(agc): index the pending storage images by guest range #403

Merged
MichonGoddijn231849 merged 1 commit from upstream-pr/403 into main 2026-10-04 01:06:00 +00:00
MichonGoddijn231849 commented 2026-10-02 19:02:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-02T19:02:57Z.


What

Each guest memory read asks the pending storage images whether it must store results first (FlushPending from the memory-access hook, overlappingPending, and PendingStorageOverlaps for shader resources). Each of these scanned the whole registry, and almost every read overlaps none of the images.

  • The scans read the thread_local refreshing once per image. With MinGW every thread_local access is an __emutls_get_address call, so the scan cost one TLS lookup per pending image.
  • The registry now keeps a sorted, merged index of the guest ranges its images cover. A version that every insert and erase bumps marks the index stale, and the first query after a change rebuilds it. A query that overlaps none of the ranges returns after a binary search.
  • The scans that still run read refreshing once.
  • An image's base address and size are fixed at construction, so an index entry cannot go stale while its image is registered.

In GTA V's Prologue, sampling the submission thread put 17.6% of its time in FlushPending, 15% of it inside __emutls_get_address, and another 8% in overlappingPending.

Tested

Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0.

  • GTA V (PPSA04264), with #401 and the rendering fixes still in progress, at the same spot of the Prologue, APS5_PROFILE_DRAW=1: 6 to 7 fps before, 8 to 8.5 after. Per draw packet, Graphics::Draw went from 67 to 46 µs and the whole packet from 104 to 78 µs. FlushPending and overlappingPending left the top of the profile.
  • Dreaming Sarah (PPSA02929): the title menu and its text render as on main.
  • ctest: all tests 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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4720320731 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/403). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-02T19:02:57Z. --- ### What Each guest memory read asks the pending storage images whether it must store results first (`FlushPending` from the memory-access hook, `overlappingPending`, and `PendingStorageOverlaps` for shader resources). Each of these scanned the whole registry, and almost every read overlaps none of the images. - The scans read the `thread_local` `refreshing` once per image. With MinGW every `thread_local` access is an `__emutls_get_address` call, so the scan cost one TLS lookup per pending image. - The registry now keeps a sorted, merged index of the guest ranges its images cover. A version that every insert and erase bumps marks the index stale, and the first query after a change rebuilds it. A query that overlaps none of the ranges returns after a binary search. - The scans that still run read `refreshing` once. - An image's base address and size are fixed at construction, so an index entry cannot go stale while its image is registered. In GTA V's Prologue, sampling the submission thread put 17.6% of its time in `FlushPending`, 15% of it inside `__emutls_get_address`, and another 8% in `overlappingPending`. ### Tested Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0. - GTA V (PPSA04264), with #401 and the rendering fixes still in progress, at the same spot of the Prologue, `APS5_PROFILE_DRAW=1`: 6 to 7 fps before, 8 to 8.5 after. Per draw packet, `Graphics::Draw` went from 67 to 46 µs and the whole packet from 104 to 78 µs. `FlushPending` and `overlappingPending` left the top of the profile. - Dreaming Sarah (PPSA02929): the title menu and its text render as on `main`. - `ctest`: all tests 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [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. Written with Claude (Anthropic) under my direction; I reviewed and tested it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!403
No description provided.