perf(agc): bind the address space's BDA table for writes inside writable imports #4979

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

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T07:09:18Z.


What

GuestBufferMemory::CachedAddressTable() returns the cached address space's own BDA table (its serial and ranges) for a build whose writes all land in ranges that already have write permission, instead of building and keying a table per set of written addresses.

AddressRanges() splits only the space's ranges without write permission around the written intervals. When no written interval overlaps such a range, its result is the space's own ranges, so the build binds the space's table by the space serial, as a build without writes does. The check is a bisection per written interval over the space's sorted, disjoint ranges. A write that overlaps a range without write permission (a writable image mirror inside a read-only import) keeps the per-writes table as before.

No environment switch: the path is always on and exact.

Why

A build that maps only the cached space but writes through V#s got a table keyed by its writes: a new key for nearly every set of written addresses, so each such build merged the space's imported ranges (about 9000 in Sword of the Sea gameplay), stored them, then hashed and compared them in BdaResources. In a CPU sample of the lab line (Sword of the Sea gameplay, RTX 5070) CachedAddressTable and hashRanges were about 4 % of the q0 thread.

This is independent of the read-list change and has no dependency on it. I did not measure it in isolation on main; the figure above is a sampling share on the lab line, not a measured FPS gain.

Tested

  • tests/BdaResources.cpp spaceWritableWritesTests (in agc_driver_graphics), with a writable and a read-only import registered: builds with one write and with two writes inside the writable import bind the serial of the build without writes, and the cached ranges equal AddressRanges() (the full walk) and the ranges of the build without writes; the read-only import stays without write permission. On main the serial differs per set of writes, so the test fails there.
  • 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/38357743201), run before a rebase onto a main that only added tests/ShaderMemory.cpp
  • 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
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4839688251 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4979). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-13T07:09:18Z. --- ### What `GuestBufferMemory::CachedAddressTable()` returns the cached address space's own BDA table (its serial and ranges) for a build whose writes all land in ranges that already have write permission, instead of building and keying a table per set of written addresses. `AddressRanges()` splits only the space's ranges without write permission around the written intervals. When no written interval overlaps such a range, its result is the space's own ranges, so the build binds the space's table by the space serial, as a build without writes does. The check is a bisection per written interval over the space's sorted, disjoint ranges. A write that overlaps a range without write permission (a writable image mirror inside a read-only import) keeps the per-writes table as before. No environment switch: the path is always on and exact. ### Why A build that maps only the cached space but writes through V#s got a table keyed by its writes: a new key for nearly every set of written addresses, so each such build merged the space's imported ranges (about 9000 in Sword of the Sea gameplay), stored them, then hashed and compared them in `BdaResources`. In a CPU sample of the lab line (Sword of the Sea gameplay, RTX 5070) `CachedAddressTable` and `hashRanges` were about 4 % of the q0 thread. This is independent of the read-list change and has no dependency on it. I did not measure it in isolation on `main`; the figure above is a sampling share on the lab line, not a measured FPS gain. ### Tested - `tests/BdaResources.cpp` `spaceWritableWritesTests` (in `agc_driver_graphics`), with a writable and a read-only import registered: builds with one write and with two writes inside the writable import bind the serial of the build without writes, and the cached ranges equal `AddressRanges()` (the full walk) and the ranges of the build without writes; the read-only import stays without write permission. On `main` the serial differs per set of writes, so the test fails there. - `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/38357743201), run before a rebase onto a `main` that only added `tests/ShaderMemory.cpp` - 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 - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
xXPBSXx commented 2026-10-13 09:41:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T09:41:54Z.


Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on main 2a2a3dc65 together with nine other open GPU PRs (their own commits applied, no merge commits; one further PR, #5024, conflicted with them and was left out), 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 (that test is known to fail sometimes on address layout, see #4660), agc_sparse_buffer_holes, agc_descriptor_pool_reset_failure, agc_compute_descriptor_layout_flags 3 of 3 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:6142756121 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4979#issuecomment-6142756121). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T09:41:54Z. --- Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on main `2a2a3dc65` together with nine other open GPU PRs (their own commits applied, no merge commits; one further PR, #5024, conflicted with them and was left out), 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 (that test is known to fail sometimes on address layout, see #4660), `agc_sparse_buffer_holes`, `agc_descriptor_pool_reset_failure`, `agc_compute_descriptor_layout_flags` 3 of 3 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).
AlxcBTW commented 2026-10-13 18:24:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T18:24:29Z.


Rebased onto current main. The only conflict was the test call list in tests/BdaResources.cpp. Full ctest on the fork CI is green on Windows and Linux, apart from the host-libm guest_math case (#5154).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152316476 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4979#issuecomment-6152316476). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-13T18:24:29Z. --- Rebased onto current main. The only conflict was the test call list in `tests/BdaResources.cpp`. Full ctest on the fork CI is green on Windows and Linux, apart from the host-libm `guest_math` case (#5154).
github-actions[bot] commented 2026-10-13 23:26:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T23:26:16Z.


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
#5542 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp L3798-3799
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157345820 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4979#issuecomment-6157345820). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T23:26:16Z. --- <!-- 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 | |---|---|---|---| | #5542 | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` [L3798-3799](https://github.com/boykopovar/AnyPS5/blob/c7844d9cb5a3d5811a810359d85d97bf3fe98742/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L3798-L3799) | | |
adriadam10 commented 2026-10-14 11:15:42 +00:00 (Migrated from github.com)

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


Checked the new path against AddressRanges(): with no written interval overlapping a range without write permission, the split leaves the space's ranges unchanged, so binding the space's table and serial is equivalent. Built and ran the libSceAgcDriver tests on the PR merged onto main: agc_driver_graphics (with spaceWritableWritesTests) passes and fails with GuestBufferMemory.cpp reverted. Also thanks to @xXPBSXx for the Windows run. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6167086797 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4979#issuecomment-6167086797). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T11:15:42Z. --- Checked the new path against `AddressRanges()`: with no written interval overlapping a range without write permission, the split leaves the space's ranges unchanged, so binding the space's table and serial is equivalent. Built and ran the libSceAgcDriver tests on the PR merged onto main: `agc_driver_graphics` (with `spaceWritableWritesTests`) passes and fails with `GuestBufferMemory.cpp` reverted. Also thanks to @xXPBSXx for the Windows run. Merging once the full Build 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!4979
No description provided.