perf(agc): cut three per-draw costs in ShaderResources #15682

Merged
oneandonlydean merged 4 commits from upstream-pr/15682 into main 2026-11-04 19:18:42 +00:00
oneandonlydean commented 2026-11-04 04:14:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-11-04T04:14:40Z.


What

Three small costs in the per-draw shader resource path, each from a CPU profile of one title's queue-0 worker; behaviour is unchanged, and the first two have an environment switch that restores the old path.

  • In-place read overlap. ShaderResources::ReadsOverlap built the whole InPlaceReads vector on every call; recordDraw calls it once per queued store for every draw that is not address-based. GuestBufferMemory::InPlaceReadsOverlap walks the same regions (the address space's base regions, then the build's own, each when bound in place) and stops at the first overlap. The profile showed about 3% of the worker in the list build. APS5_NO_READS_OVERLAP_WALK=1 builds the list as before.
  • Vectors and template records. A build grew its binding and allocation vectors one element at a time and tracked occupied binding numbers in a std::set (about 3.7% of the worker was allocator time inside builds); the counts are known before the plan is walked, so the vectors are reserved once. A build that binds BDA tables, or a fault buffer while APS5_LOOP_GUARD is set, can never be reused (noteReusable and NeverReusable refuse it), so it no longer copies its data words for a template refresh nor records the proof of its sampled textures; a fault-only build is reusable and keeps both. APS5_KEEP_TEMPLATE_RECORDS=1 keeps both for every build.
  • Texture counters and the stage-A texture. Per sampled element a build bumped the shared [textures] counters with an atomic add on a line every building thread writes, although they are only printed under APS5_PROFILE_DRAW (about a tenth of precollectImages in the profile); the adds now run only when the counters are reported. A stage-B fast hit also copied the record's texture pointer (another atomic reference count); the record's reference is now moved out on a hit.

Both switches are in docs/dev/ENVIRONMENT.md. Not included: skipping the zero-fill of overwritten texture snapshots (#9884 and #10845 already cover the large dropped case; the rest is unmeasured).

Tested

  • Linux workstation, main 1c8c0efc8c. Built agc_driver_graphics_tests and agc_driver_recorder_tests; tools/check_conventions.py passes. Passed: agc_driver_graphics_maps_fallback, the four new agc_driver_fault_only_template_records* tests, agc_driver_recorder and agc_recorder_read_list.
  • New checks: the recorder test compares InPlaceReadsOverlap and ReadsOverlap with the listed reads on seven probes and on every read of a build; the new graphics-test mode builds a fault-buffer stage with a flattened-SRT data binding and compares the data-word hash with and without APS5_KEEP_TEMPLATE_RECORDS and APS5_LOOP_GUARD.
  • With the change taken out and the tests kept: making InPlaceReadsOverlap return false fails agc_driver_recorder_tests (the in-place read overlap walk disagrees with the listed reads); making keepsTemplateRecords always true fails agc_driver_fault_only_template_records_loop_guard (the other three variants still pass).
  • Merges cleanly with the head of #10256 (3c2bbeaf3d), which also touches ShaderResources.cpp.
  • Not measured: no before/after timing of these costs on this head. The percentages above come from profiles taken earlier on our fork, not from this branch. Not run: Windows, macOS, a game.

Checklist

  • Based on current main 1c8c0efc8c; 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; silent stubs are listed in technical debt (none added)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5148746066 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15682). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-11-04T04:14:40Z. --- ### What Three small costs in the per-draw shader resource path, each from a CPU profile of one title's queue-0 worker; behaviour is unchanged, and the first two have an environment switch that restores the old path. - **In-place read overlap.** `ShaderResources::ReadsOverlap` built the whole `InPlaceReads` vector on every call; `recordDraw` calls it once per queued store for every draw that is not address-based. `GuestBufferMemory::InPlaceReadsOverlap` walks the same regions (the address space's base regions, then the build's own, each when bound in place) and stops at the first overlap. The profile showed about 3% of the worker in the list build. `APS5_NO_READS_OVERLAP_WALK=1` builds the list as before. - **Vectors and template records.** A build grew its binding and allocation vectors one element at a time and tracked occupied binding numbers in a `std::set` (about 3.7% of the worker was allocator time inside builds); the counts are known before the plan is walked, so the vectors are reserved once. A build that binds BDA tables, or a fault buffer while `APS5_LOOP_GUARD` is set, can never be reused (`noteReusable` and `NeverReusable` refuse it), so it no longer copies its data words for a template refresh nor records the proof of its sampled textures; a fault-only build is reusable and keeps both. `APS5_KEEP_TEMPLATE_RECORDS=1` keeps both for every build. - **Texture counters and the stage-A texture.** Per sampled element a build bumped the shared `[textures]` counters with an atomic add on a line every building thread writes, although they are only printed under `APS5_PROFILE_DRAW` (about a tenth of `precollectImages` in the profile); the adds now run only when the counters are reported. A stage-B fast hit also copied the record's texture pointer (another atomic reference count); the record's reference is now moved out on a hit. Both switches are in `docs/dev/ENVIRONMENT.md`. Not included: skipping the zero-fill of overwritten texture snapshots (#9884 and #10845 already cover the large dropped case; the rest is unmeasured). ### Tested - Linux workstation, `main` `1c8c0efc8c`. Built `agc_driver_graphics_tests` and `agc_driver_recorder_tests`; `tools/check_conventions.py` passes. Passed: `agc_driver_graphics_maps_fallback`, the four new `agc_driver_fault_only_template_records*` tests, `agc_driver_recorder` and `agc_recorder_read_list`. - New checks: the recorder test compares `InPlaceReadsOverlap` and `ReadsOverlap` with the listed reads on seven probes and on every read of a build; the new graphics-test mode builds a fault-buffer stage with a flattened-SRT data binding and compares the data-word hash with and without `APS5_KEEP_TEMPLATE_RECORDS` and `APS5_LOOP_GUARD`. - With the change taken out and the tests kept: making `InPlaceReadsOverlap` return false fails `agc_driver_recorder_tests` (`the in-place read overlap walk disagrees with the listed reads`); making `keepsTemplateRecords` always true fails `agc_driver_fault_only_template_records_loop_guard` (the other three variants still pass). - Merges cleanly with the head of #10256 (`3c2bbeaf3d`), which also touches `ShaderResources.cpp`. - Not measured: no before/after timing of these costs on this head. The percentages above come from profiles taken earlier on our fork, not from this branch. Not run: Windows, macOS, a game. ### Checklist - [x] Based on current `main` `1c8c0efc8c`; 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; silent stubs are listed in technical debt (none added) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
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!15682
No description provided.