perf(agc): group resource metadata allocations by lifetime #1366

Closed
TibixDev wants to merge 2 commits from upstream-pr/1366 into main
TibixDev commented 2026-10-08 00:26:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TibixDev on 2026-10-08T00:26:38Z.


What

Performance justification remains open: the isolated current-main buffer-only measurements below do not show an improvement. The old stacked timing claim has been removed.

Allocate resource-owned metadata vectors from one monotonic arena, declared before its users so their elements are destroyed first. Arena chunks live until the ShaderResources object is destroyed; binding records keep their existing ownership.

Rebased only the arena change directly onto main d146ec1b6. Removed the #1324/#1357/#1359/#1360/#1361/#1364 dependency stack. Main's descriptor-cache allocation, deferred construction, image validation and texture-base-level tracking are preserved. Current main can repeat captureValidation during reuse; it assigns the same texture count and reuses vector capacity, so this does not accumulate arena allocations for a fixed resource layout.

Depends on: none.

Tested

Fedora 44, GCC 16.2.1, Release: agc_driver_graphics and agc_driver_pm4 pass (3.28 seconds total), as do contribution checks and git diff --check. The new --metadata-lifetime fixture covers empty, 1-, 8- and 32-binding resources, abandonment before deferred completion, shared ownership through completion, descriptor data and destruction. It also runs in the regular graphics suite.

Targeted upload-lifetime, upload-failure cleanup and descriptor-pool recycling tests pass on RX 6600 RADV and lavapipe with core/synchronization validation and no validation errors. The RADV draw-descriptor/snapshot test also passes without validation errors.

The full recorder suite passes its assertions on lavapipe. With validation enabled, both unchanged main and this PR emit the same existing diagnostics: one SYNC-HAZARD-WRITE-AFTER-WRITE and ten VUID-vkCmdEndRendering-None-06161 errors. This is not a validation-clean full-suite result.

AddressSanitizer and leak detection pass for that fixture using ANYPS5_ENABLE_ASAN=ON. A local negative control inserting allocationArena.release() into the destructor before member destruction fails with heap-use-after-free in ShaderResources::~ShaderResources. Restoring the implementation passes again; the mutation is not part of the PR.

cmake -S . -B build-asan-review -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_ASAN=ON
cmake --build build-asan-review --target agc_driver_graphics_tests --parallel 8
ASAN_OPTIONS=detect_leaks=1:halt_on_error=1 ./build-asan-review/tests/agc_driver_graphics_tests --metadata-lifetime

The build also used the existing local FFMPEG_PREBUILT_DIR cache; it is unrelated to this test. No Windows runtime or title FPS result is claimed.

Isolated measurement

Ryzen 5 5600, CPU 3, identical GCC/Release flags and benchmark source. Main d146ec1b6 production code versus only this PR's arena change. Three ABBA cycles, six processes per variant; each process reports the median of nine batches of 512 complete resource builds/destructions after one warm-up batch. Each non-empty binding carries 256 bytes of flattened shader data. The Vulkan calls are mocked, and buffer/descriptor pools stay warm across builds.

Buffer bindings Main, us/build+destroy Arena, us/build+destroy Median change
0 0.2626 0.2682 +2.1%
1 0.8469 0.9226 +8.9%
8 3.0862 3.1991 +3.7%
32 12.7647 12.9032 +1.1%

All checksums match. Every row's process-median range overlaps between variants; the medians are approximately 1–9% slower with the arena. This fixture does not justify the optimization. It contains buffers, not the earlier eight-texture workload, and does not establish mixed-resource or title performance. Further performance justification is needed before merging.

taskset -c 3 ./build-fedora/tests/agc_driver_graphics_tests --benchmark-resource-metadata

For the baseline, build this same harness with main's core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp. All other production files on this branch already match main. Restore the PR header and rebuild for the arena variant.

Checklist

  • Based on main at the revision above; prior prerequisites removed.
  • One topic.
  • No new code comments.
  • Unsupported paths retain their errors.
  • No notes, logs, or images added to the repository.
  • No new third-party code.
  • General behavior.
  • Depends on: none.
  • AI-assisted: yes.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4780119082 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1366). Originally posted by [TibixDev](https://github.com/TibixDev) on 2026-10-08T00:26:38Z. --- ### What Performance justification remains open: the isolated current-main buffer-only measurements below do not show an improvement. The old stacked timing claim has been removed. Allocate resource-owned metadata vectors from one monotonic arena, declared before its users so their elements are destroyed first. Arena chunks live until the `ShaderResources` object is destroyed; binding records keep their existing ownership. Rebased only the arena change directly onto main `d146ec1b6`. Removed the #1324/#1357/#1359/#1360/#1361/#1364 dependency stack. Main's descriptor-cache allocation, deferred construction, image validation and texture-base-level tracking are preserved. Current main can repeat `captureValidation` during reuse; it assigns the same texture count and reuses vector capacity, so this does not accumulate arena allocations for a fixed resource layout. Depends on: none. ### Tested Fedora 44, GCC 16.2.1, Release: `agc_driver_graphics` and `agc_driver_pm4` pass (3.28 seconds total), as do contribution checks and `git diff --check`. The new `--metadata-lifetime` fixture covers empty, 1-, 8- and 32-binding resources, abandonment before deferred completion, shared ownership through completion, descriptor data and destruction. It also runs in the regular graphics suite. Targeted upload-lifetime, upload-failure cleanup and descriptor-pool recycling tests pass on RX 6600 RADV and lavapipe with core/synchronization validation and no validation errors. The RADV draw-descriptor/snapshot test also passes without validation errors. The full recorder suite passes its assertions on lavapipe. With validation enabled, both unchanged main and this PR emit the same existing diagnostics: one `SYNC-HAZARD-WRITE-AFTER-WRITE` and ten `VUID-vkCmdEndRendering-None-06161` errors. This is not a validation-clean full-suite result. AddressSanitizer and leak detection pass for that fixture using `ANYPS5_ENABLE_ASAN=ON`. A local negative control inserting `allocationArena.release()` into the destructor before member destruction fails with `heap-use-after-free` in `ShaderResources::~ShaderResources`. Restoring the implementation passes again; the mutation is not part of the PR. ``` cmake -S . -B build-asan-review -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_ASAN=ON cmake --build build-asan-review --target agc_driver_graphics_tests --parallel 8 ASAN_OPTIONS=detect_leaks=1:halt_on_error=1 ./build-asan-review/tests/agc_driver_graphics_tests --metadata-lifetime ``` The build also used the existing local `FFMPEG_PREBUILT_DIR` cache; it is unrelated to this test. No Windows runtime or title FPS result is claimed. ### Isolated measurement Ryzen 5 5600, CPU 3, identical GCC/Release flags and benchmark source. Main `d146ec1b6` production code versus only this PR's arena change. Three ABBA cycles, six processes per variant; each process reports the median of nine batches of 512 complete resource builds/destructions after one warm-up batch. Each non-empty binding carries 256 bytes of flattened shader data. The Vulkan calls are mocked, and buffer/descriptor pools stay warm across builds. | Buffer bindings | Main, us/build+destroy | Arena, us/build+destroy | Median change | | --- | ---: | ---: | ---: | | 0 | 0.2626 | 0.2682 | +2.1% | | 1 | 0.8469 | 0.9226 | +8.9% | | 8 | 3.0862 | 3.1991 | +3.7% | | 32 | 12.7647 | 12.9032 | +1.1% | All checksums match. Every row's process-median range overlaps between variants; the medians are approximately 1–9% slower with the arena. This fixture does not justify the optimization. It contains buffers, not the earlier eight-texture workload, and does not establish mixed-resource or title performance. Further performance justification is needed before merging. ``` taskset -c 3 ./build-fedora/tests/agc_driver_graphics_tests --benchmark-resource-metadata ``` For the baseline, build this same harness with main's `core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp`. All other production files on this branch already match main. Restore the PR header and rebuild for the arena variant. ### Checklist - [x] Based on main at the revision above; prior prerequisites removed. - [x] One topic. - [x] No new code comments. - [x] Unsupported paths retain their errors. - [x] No notes, logs, or images added to the repository. - [x] No new third-party code. - [x] General behavior. - [x] Depends on: none. - [x] AI-assisted: yes.
TibixDev commented 2026-10-08 07:32:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TibixDev on 2026-10-08T07:32:18Z.


Rebased on 1e1e1390. Updated the #1364 prerequisite after #1113 merged. Retained upload pages now count toward the batch memory budget; metadata lifetime and the existing GPU synchronization tests remain intact.

Fedora 44 Release: agc_driver_graphics_tests, agc_driver_pm4_tests, guest_mapping_history_tests, agc_driver_recorder_tests, agc_recorder_kept_bytes_tests build; the targeted tests and contribution checks pass. Windows CI is pending.
RADV and lavapipe: --copied-buffers-only, --shader-data-only, --draw-upload-only, --draw-snapshot-only, --draw-descriptors-only pass with core and synchronization validation; no validation errors.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6054973356 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1366#issuecomment-6054973356). Originally posted by [TibixDev](https://github.com/TibixDev) on 2026-10-08T07:32:18Z. --- Rebased on `1e1e1390`. Updated the #1364 prerequisite after #1113 merged. Retained upload pages now count toward the batch memory budget; metadata lifetime and the existing GPU synchronization tests remain intact. Fedora 44 Release: `agc_driver_graphics_tests`, `agc_driver_pm4_tests`, `guest_mapping_history_tests`, `agc_driver_recorder_tests`, `agc_recorder_kept_bytes_tests` build; the targeted tests and contribution checks pass. Windows CI is pending. RADV and lavapipe: `--copied-buffers-only`, `--shader-data-only`, `--draw-upload-only`, `--draw-snapshot-only`, `--draw-descriptors-only` pass with core and synchronization validation; no validation errors.
adriadam10 commented 2026-10-11 11:40:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T11:40:46Z.

Review: CHANGES_REQUESTED


Reviewed the commit specific to this PR (f74fa3d6a, ShaderResources.hpp): moving the resource-owned metadata vectors to a std::pmr::monotonic_buffer_resource declared before them looks right (destruction order, the class is non-copyable, and the reuse paths such as noteReusable and captureValidation run once per build, so the arena stays bounded).

Blockers:

  • This is stacked on #1324, #1357, #1359, #1360, #1361 and #1364, all still open and all conflicting with main. Nothing can be built or tested for this PR alone, and it can't merge before them. Please rebase once the stack has landed (or been rebased) and keep Depends on current.
  • The gain is measured only on a synthetic fixture (≈ 12.2 → 11.2–11.5 µs per draw, about 6 %). Please post before/after numbers on main + this commit alone, with the command used, so the arena's effect is separate from the rest of the stack.
  • No test pins the new lifetime rule (arena declared before its users). A small test that builds and destroys a ShaderResources with ASan/valgrind-visible destruction order would cover it, or say why the existing tests already do.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5483162000 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1366#pullrequestreview-5483162000). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T11:40:46Z. **Review:** CHANGES_REQUESTED --- Reviewed the commit specific to this PR (`f74fa3d6a`, `ShaderResources.hpp`): moving the resource-owned metadata vectors to a `std::pmr::monotonic_buffer_resource` declared before them looks right (destruction order, the class is non-copyable, and the reuse paths such as `noteReusable` and `captureValidation` run once per build, so the arena stays bounded). Blockers: - This is stacked on #1324, #1357, #1359, #1360, #1361 and #1364, all still open and all conflicting with `main`. Nothing can be built or tested for this PR alone, and it can't merge before them. Please rebase once the stack has landed (or been rebased) and keep **Depends on** current. - The gain is measured only on a synthetic fixture (≈ 12.2 → 11.2–11.5 µs per draw, about 6 %). Please post before/after numbers on `main` + this commit alone, with the command used, so the arena's effect is separate from the rest of the stack. - No test pins the new lifetime rule (arena declared before its users). A small test that builds and destroys a `ShaderResources` with ASan/valgrind-visible destruction order would cover it, or say why the existing tests already do.
TibixDev commented 2026-10-12 04:01:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TibixDev on 2026-10-12T04:01:40Z.


@adriadam10 updated in 24ac32372, directly on main d146ec1b6:

  • Removed the older dependency stack; Depends on: none. Only the arena change and its tests remain.
  • Added deferred construction/destruction coverage, including abandonment and retained ownership. ASan with leak detection passes. An early-arena-release negative control produces a heap-use-after-free in the destructor; the restored implementation passes.
  • Added a reproducible main-versus-arena benchmark. On the buffer-only 0/1/8/32-binding fixture, the arena medians are about 1–9% slower. The full numbers, method and command are in the updated body; the earlier stacked performance claim has been removed. Performance justification remains unresolved. This result does not support merging the optimization without further evidence.

Graphics/PM4 and targeted RADV/lavapipe lifetime and descriptor tests pass. The full recorder run reproduces the same existing validation diagnostics on main and this branch, documented in the body. Windows runtime/full CI still need maintainer validation.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6117508980 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1366#issuecomment-6117508980). Originally posted by [TibixDev](https://github.com/TibixDev) on 2026-10-12T04:01:40Z. --- @adriadam10 updated in `24ac32372`, directly on main `d146ec1b6`: - Removed the older dependency stack; **Depends on: none**. Only the arena change and its tests remain. - Added deferred construction/destruction coverage, including abandonment and retained ownership. ASan with leak detection passes. An early-arena-release negative control produces a heap-use-after-free in the destructor; the restored implementation passes. - Added a reproducible main-versus-arena benchmark. On the buffer-only 0/1/8/32-binding fixture, the arena medians are about **1–9% slower**. The full numbers, method and command are in the updated body; the earlier stacked performance claim has been removed. **Performance justification remains unresolved.** This result does not support merging the optimization without further evidence. Graphics/PM4 and targeted RADV/lavapipe lifetime and descriptor tests pass. The full recorder run reproduces the same existing validation diagnostics on main and this branch, documented in the body. Windows runtime/full CI still need maintainer validation.
adriadam10 commented 2026-10-13 09:14:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T09:14:27Z.


Closing: the PR's own isolated measurement shows the arena is 1–9% slower on every buffer-only row (0/1/8/32 bindings), the description says further performance justification is needed, and no title or profile shows resource-metadata allocation as a cost. A perf-only change that measures slower doesn't meet CONTRIBUTING (perf PRs post before/after numbers and drop what measured slower). It also currently conflicts with main.

Feel free to reopen, rebased, with a measurement (mixed buffer+texture resources, or a title profile) where the arena wins.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6142290961 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1366#issuecomment-6142290961). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T09:14:27Z. --- Closing: the PR's own isolated measurement shows the arena is 1–9% slower on every buffer-only row (0/1/8/32 bindings), the description says further performance justification is needed, and no title or profile shows resource-metadata allocation as a cost. A perf-only change that measures slower doesn't meet CONTRIBUTING (perf PRs post before/after numbers and drop what measured slower). It also currently conflicts with `main`. Feel free to reopen, rebased, with a measurement (mixed buffer+texture resources, or a title profile) where the arena wins.

Pull request closed

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!1366
No description provided.