perf(agc): write draw descriptors from retained CPU metadata #1334

Merged
TibixDev merged 2 commits from upstream-pr/1334 into main 2026-10-11 08:45:19 +00:00
TibixDev commented 2026-10-07 23:46:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TibixDev on 2026-10-07T23:46:39Z.


What

Keep buffer and image descriptor metadata with each resource. Build each draw's descriptor set from that metadata in one update, with the draw's snapshot buffers substituted. This removes Vulkan descriptor copies from the draw path.

Guest snapshots, resource ownership, and descriptor-set lifetimes stay the same. #639/#1219 change resource ABI handling; #1202 changes snapshot allocation. Neither replaces these descriptor copies.

Tested

Fedora 44, Release: graphics tests. RX 6600 with Vulkan validation: mixed buffer and sampler-array bindings, repeated snapshot overrides, unchanged descriptors, and one update with no descriptor copies. Windows was not tested.

Isolated comparison: upstream e9846679 versus the same revision plus this PR. For eight storage-buffer descriptors, preparing a draw with one changed snapshot took 28.689 → 3.333 µs; with eight snapshots it took 37.294 → 4.935 µs. Six pinned processes per variant in ABBA order, using host RADV. These are draw-binding preparation timings, not title frame time.

Checklist

  • Current main; no duplicate open PR.
  • One topic.
  • No new code comments.
  • Unsupported paths still throw; UI stubs are documented.
  • No notes, logs, or images in the repository.
  • No new third-party code.
  • General behavior.
  • Depends on: none.
  • AI-assisted: yes.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4779843430 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1334). Originally posted by [TibixDev](https://github.com/TibixDev) on 2026-10-07T23:46:39Z. --- ### What Keep buffer and image descriptor metadata with each resource. Build each draw's descriptor set from that metadata in one update, with the draw's snapshot buffers substituted. This removes Vulkan descriptor copies from the draw path. Guest snapshots, resource ownership, and descriptor-set lifetimes stay the same. #639/#1219 change resource ABI handling; #1202 changes snapshot allocation. Neither replaces these descriptor copies. ### Tested Fedora 44, Release: graphics tests. RX 6600 with Vulkan validation: mixed buffer and sampler-array bindings, repeated snapshot overrides, unchanged descriptors, and one update with no descriptor copies. Windows was not tested. Isolated comparison: upstream `e9846679` versus the same revision plus this PR. For eight storage-buffer descriptors, preparing a draw with one changed snapshot took 28.689 → 3.333 µs; with eight snapshots it took 37.294 → 4.935 µs. Six pinned processes per variant in ABBA order, using host RADV. These are draw-binding preparation timings, not title frame time. ### Checklist - [x] Current `main`; no duplicate open PR. - [x] One topic. - [x] No new code comments. - [x] Unsupported paths still throw; UI stubs are documented. - [x] No notes, logs, or images in the repository. - [x] No new third-party code. - [x] General behavior. - [x] Depends on: none. - [x] AI-assisted: yes.
TibixDev commented 2026-10-08 06:09:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TibixDev on 2026-10-08T06:09:24Z.


Rebased on e9846679 with no production changes.

Measured upstream e9846679 against the same revision plus this PR (cc32a55f). Fedora 44, GCC 16 Release, Ryzen 5 5600, CPU 3, RX 6600. The runner explicitly selects host RADV and its matching host library directory. Supporting libc and libkernel binaries are identical between variants.

The same fixture calls production ShaderResources::PrepareDrawBindings with eight storage-buffer bindings and either one or eight snapshot overrides. Snapshot data changes on each call. Descriptor allocation, snapshot allocation/copy, and recorder retirement remain in the timing. One warmup and nine batches of 5,120 draws per process, with retirement every 32 draws. Six processes per variant in ABBA × 3 order; validation is off for timing. No game or build ran during measurement.

Snapshots per draw Upstream median (µs) PR median (µs) Less time Upstream range PR range
1 28.689 3.333 88.4% 28.302–32.750 3.272–4.064
8 37.294 4.935 86.8% 36.351–39.453 4.780–5.439

Snapshot checksums match. Both benchmark variants pass separate core and sync validation runs on RADV. The PR's mixed buffer/sampler-array, repeated snapshot override, and descriptor update-count tests pass with validation on RADV and llvmpipe. Graphics and contribution checks pass.

This measures draw-binding preparation only; no title frame time or Windows result is claimed. AI-assisted.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6053569480 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1334#issuecomment-6053569480). Originally posted by [TibixDev](https://github.com/TibixDev) on 2026-10-08T06:09:24Z. --- Rebased on `e9846679` with no production changes. Measured upstream `e9846679` against the same revision plus this PR (`cc32a55f`). Fedora 44, GCC 16 Release, Ryzen 5 5600, CPU 3, RX 6600. The runner explicitly selects host RADV and its matching host library directory. Supporting `libc` and `libkernel` binaries are identical between variants. The same fixture calls production `ShaderResources::PrepareDrawBindings` with eight storage-buffer bindings and either one or eight snapshot overrides. Snapshot data changes on each call. Descriptor allocation, snapshot allocation/copy, and recorder retirement remain in the timing. One warmup and nine batches of 5,120 draws per process, with retirement every 32 draws. Six processes per variant in ABBA × 3 order; validation is off for timing. No game or build ran during measurement. | Snapshots per draw | Upstream median (µs) | PR median (µs) | Less time | Upstream range | PR range | |---:|---:|---:|---:|---:|---:| | 1 | 28.689 | 3.333 | 88.4% | 28.302–32.750 | 3.272–4.064 | | 8 | 37.294 | 4.935 | 86.8% | 36.351–39.453 | 4.780–5.439 | Snapshot checksums match. Both benchmark variants pass separate core and sync validation runs on RADV. The PR's mixed buffer/sampler-array, repeated snapshot override, and descriptor update-count tests pass with validation on RADV and llvmpipe. Graphics and contribution checks pass. This measures draw-binding preparation only; no title frame time or Windows result is claimed. AI-assisted.
EdouardSence commented 2026-10-08 09:09:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-08T09:09:09Z.


Title-level data for this change, from a retail title (Astro Bot, PPSA21567 v01.019.000), in case it helps the review.

Setup: RX 9070 XT (GFX1201), RADV / Mesa 26.2.4, Linux 7.2.9. Base is the astrobot fork at 88d7bb62 plus #943 (815d2747, 00e6d078), because upstream main stops on this title (#1458). For this test, only libSceAgcDriver.prx changes between runs.

Profile before the change: perf record ran for 40 s on the title screen. The driver thread (Driver::run) was ~100% busy. With DWARF unwinding, 1321 of 3570 samples on that thread (37%) were in glibc memcpy called from libvulkan_radeon.so, from ShaderResources::PrepareDrawBindings (the vkUpdateDescriptorSets call with the VkCopyDescriptorSet array). The hot paths are the 16–31 and 32–63 byte copies, i.e. one copy per descriptor. APS5_PROFILE_DRAW reported ~5.7k draws/s on that scene.

Presents per second ([present] lines, APS5_PROFILE_DRAW=1, 200 s from boot to title screen, no input):

run logos (windows 3–8) title screen (last 6 windows)
base 21.9 26.3
base, second run 22.2 26.2
this PR (cc32a55f, cherry-picked) 25.9 33.4
equivalent local patch (same approach) 27.2 34.9
  • No new errors in the log and no amdgpu faults in any run.
  • Frames dumped with APS5_DUMP_FRAMES match visually between base and patched runs. The differences are animation timing only.
  • The Recorder.cpp test hunk conflicted on the fork, so I dropped it for this build only. I didn't run this PR's tests here.
  • On upstream main 5d42b82, my own version of the same change passes 428/428 ctest on this GPU.

AI-assisted: the profiling, the measurements and this write-up were done by Claude (Claude Code) on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6056569535 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1334#issuecomment-6056569535). Originally posted by [EdouardSence](https://github.com/EdouardSence) on 2026-10-08T09:09:09Z. --- Title-level data for this change, from a retail title (Astro Bot, PPSA21567 v01.019.000), in case it helps the review. **Setup:** RX 9070 XT (GFX1201), RADV / Mesa 26.2.4, Linux 7.2.9. Base is the `astrobot` fork at 88d7bb62 plus #943 (815d2747, 00e6d078), because upstream `main` stops on this title (#1458). For this test, only `libSceAgcDriver.prx` changes between runs. **Profile before the change:** `perf record` ran for 40 s on the title screen. The driver thread (`Driver::run`) was ~100% busy. With DWARF unwinding, 1321 of 3570 samples on that thread (37%) were in glibc `memcpy` called from `libvulkan_radeon.so`, from `ShaderResources::PrepareDrawBindings` (the `vkUpdateDescriptorSets` call with the `VkCopyDescriptorSet` array). The hot paths are the 16–31 and 32–63 byte copies, i.e. one copy per descriptor. `APS5_PROFILE_DRAW` reported ~5.7k draws/s on that scene. **Presents per second** (`[present]` lines, `APS5_PROFILE_DRAW=1`, 200 s from boot to title screen, no input): | run | logos (windows 3–8) | title screen (last 6 windows) | |---|---|---| | base | 21.9 | 26.3 | | base, second run | 22.2 | 26.2 | | this PR (cc32a55f, cherry-picked) | 25.9 | 33.4 | | equivalent local patch (same approach) | 27.2 | 34.9 | - No new errors in the log and no amdgpu faults in any run. - Frames dumped with `APS5_DUMP_FRAMES` match visually between base and patched runs. The differences are animation timing only. - The `Recorder.cpp` test hunk conflicted on the fork, so I dropped it for this build only. I didn't run this PR's tests here. - On upstream `main` 5d42b82, my own version of the same change passes 428/428 `ctest` on this GPU. AI-assisted: the profiling, the measurements and this write-up were done by Claude (Claude Code) on my machine.
oneandonlydean commented 2026-10-11 03:35:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T03:35:17Z.


This conflicts with main again (ShaderResources.hpp/.cpp, tests/Recorder.cpp). Could you rebase it?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105070297 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1334#issuecomment-6105070297). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T03:35:17Z. --- This conflicts with `main` again (`ShaderResources.hpp/.cpp`, `tests/Recorder.cpp`). Could you rebase it?
adriadam10 commented 2026-10-11 08:41:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T08:41:28Z.


Rebased on current main (conflicts in ShaderResources.hpp/.cpp and tests/Recorder.cpp after #1730b29c4, which added allocationDescriptors and still copies the whole set). Resolved by dropping that member in favour of the retained descriptor arrays from this PR, and using main's snapshot index lookup for the overrides.

Added on top of your commit:

  • tests/Recorder.cpp: the test's sampler binding used 11, which #639's typed heaps reject; it now uses RuntimeAbi::Binding::Samplers.
  • tests/Graphics.cpp (descriptorSnapshotTests): it pinned the old copy-then-overwrite behaviour; it now expects no copies, one write per binding, and an untouched binding keeping its original descriptor.

Checked: agc_driver_graphics passes, and agc_driver_recorder_tests --draw-descriptors-only passes (that target is not registered in ctest on main; built by hand). Merging once CI is green on the new head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107229840 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1334#issuecomment-6107229840). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T08:41:28Z. --- Rebased on current `main` (conflicts in `ShaderResources.hpp/.cpp` and `tests/Recorder.cpp` after #1730b29c4, which added `allocationDescriptors` and still copies the whole set). Resolved by dropping that member in favour of the retained descriptor arrays from this PR, and using main's snapshot index lookup for the overrides. Added on top of your commit: - `tests/Recorder.cpp`: the test's sampler binding used `11`, which #639's typed heaps reject; it now uses `RuntimeAbi::Binding::Samplers`. - `tests/Graphics.cpp` (`descriptorSnapshotTests`): it pinned the old copy-then-overwrite behaviour; it now expects no copies, one write per binding, and an untouched binding keeping its original descriptor. Checked: `agc_driver_graphics` passes, and `agc_driver_recorder_tests --draw-descriptors-only` passes (that target is not registered in ctest on `main`; built by hand). Merging once CI is green on the new head.
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!1334
No description provided.