WIP: perf(agc): read watched draw inputs from snapshots, not host imports #5900

Closed
bcortezf wants to merge 1 commit from upstream-pr/5900 into main
bcortezf commented 2026-10-14 15:07:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by bcortezf on 2026-10-14T15:07:56Z.


What

Closes #5895 .

Since #2253, InPlaceDrawInput has bound vertex and index ranges in place from their VK_EXT_external_memory_host import. The GPU reads imported memory far more slowly than memory the driver allocates, so draws that read their inputs this way spend most of their GPU time waiting.

In Red Dead Redemption (PPSA30528) gameplay, ~900 G-buffer draws per frame, each with ~570 primitives, take ~230 µs each in place and ~2 µs each from a copy. Nsight GPU Trace shows the SMs ~96% idle during them, waiting on the reads.

Which path a range now takes:

Range Path Why
Watched by write-watch, no recorded GPU write over it Copy path again (CopyDrawInput), from a snapshot reused until a write lands on it The CPU copies the range once per change, not once per draw
A GPU write over it is still pending In place, as before A copy would have to wait for the write; this also keeps #4649's barrier path useful
Outside watched memory In place, as before A copy could never be reused
Above DrawInputBudget In place, as before —

Tests: the in-place tests now run on an unwatched host import. A watched range must come from a snapshot unless a GPU write over it is pending.

Tested

Windows 11 (10.0.26200), NVIDIA GeForce RTX 4070 SUPER, driver 616.64

  • Tests: agc_driver_recorder_tests --draw-inputs-in-place-only passes on main and on this branch. On this machine imports are compared, not watched, so the watched assertions are skipped here; the unwatched in-place ones run. The full agc_driver_recorder_tests run stops at (9) a scan under a pending write was kept (DCC keys), and it stops there on main too.
  • Performance base: RDR does not start on current main without two local changes that no longer merge on it: the sceAudioOutGetSystemState export and RDR shader/state fixes. The A/B therefore uses main at a0f5916a2 plus those local changes (base), against the same tree plus this commit (fix). InPlaceDrawInput is identical there and on current main.
  • Protocol: builds without other changes. Only APS5_TRACE_SECONDS=84:5 is set, plus the pad input file the runner uses to skip the intro. One warm-up run per side, then 3 interleaved runs per side.
  • Load and logging: the GPU carried a steady ~40% foreign load (remote desktop encoder + compositor) during both sides. The runner writes stdout/stderr to files on both sides.

Results

frame p50 (ms) GPU busy per present (ms)
base 467.3 / 427.4 / 409.6 (mean 434.8) 301.5 / 202.6 / 218.0 (mean 240.7)
fix 481.4 / 425.5 / 418.8 (mean 441.9) 74.4 / 109.9 / 120.0 (mean 101.4)
  • GPU: −58%.
  • Frame time: unchanged within noise (+1.6%). This base is CPU-bound at ~99% in the queue worker (#5345).
  • Snapshot reuse: a local counter (not in this PR) over the same scene finds that 100% of the vertex and index inputs are watched, and 92% of them are served from a reused snapshot. 8% are copied, ~586 MiB over 1.36 M inputs.

Related: #5345, #5692, #3338 (inputs above DrawInputBudget stay in place).

Summary lines and traces: attached (aps5-summary.jsonl and aps5-trace-*.json.gz of the 6 runs).

Earlier per-draw measurement, on the same machine with the stack of #494/#1193/#1202/#5216 on top of the same base, via draw timestamps:

Before After
G-buffer draw 227.5 µs 1.8 µs
GPU per frame 323 ms 100 ms
Gameplay 3.07 FPS 4.40 FPS
Intro cutscene 5.76 FPS 7.99 FPS
Worker per draw 37.4 µs 34.3 µs

Images are correct in both scenes.

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 (touches the same function as #4649; compatible, whichever lands second rebases)
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 616.64, Windows 11 10.0.26200
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4859975986 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5900). Originally posted by [bcortezf](https://github.com/bcortezf) on 2026-10-14T15:07:56Z. --- ### What Closes #5895 . Since #2253, `InPlaceDrawInput` has bound vertex and index ranges in place from their `VK_EXT_external_memory_host` import. The GPU reads imported memory far more slowly than memory the driver allocates, so draws that read their inputs this way spend most of their GPU time waiting. In Red Dead Redemption (PPSA30528) gameplay, ~900 G-buffer draws per frame, each with ~570 primitives, take ~230 µs each in place and ~2 µs each from a copy. Nsight GPU Trace shows the SMs ~96% idle during them, waiting on the reads. Which path a range now takes: | Range | Path | Why | |---|---|---| | Watched by write-watch, no recorded GPU write over it | Copy path again (`CopyDrawInput`), from a snapshot reused until a write lands on it | The CPU copies the range once per change, not once per draw | | A GPU write over it is still pending | In place, as before | A copy would have to wait for the write; this also keeps #4649's barrier path useful | | Outside watched memory | In place, as before | A copy could never be reused | | Above `DrawInputBudget` | In place, as before | — | **Tests:** the in-place tests now run on an unwatched host import. A watched range must come from a snapshot unless a GPU write over it is pending. ### Tested **Windows 11 (10.0.26200), NVIDIA GeForce RTX 4070 SUPER, driver 616.64** - **Tests:** `agc_driver_recorder_tests --draw-inputs-in-place-only` passes on `main` and on this branch. On this machine imports are compared, not watched, so the watched assertions are skipped here; the unwatched in-place ones run. The full `agc_driver_recorder_tests` run stops at `(9) a scan under a pending write was kept` (DCC keys), and it stops there on `main` too. - **Performance base:** RDR does not start on current `main` without two local changes that no longer merge on it: the `sceAudioOutGetSystemState` export and RDR shader/state fixes. The A/B therefore uses `main` at a0f5916a2 plus those local changes (`base`), against the same tree plus this commit (`fix`). `InPlaceDrawInput` is identical there and on current `main`. - **Protocol:** builds without other changes. Only `APS5_TRACE_SECONDS=84:5` is set, plus the pad input file the runner uses to skip the intro. One warm-up run per side, then 3 interleaved runs per side. - **Load and logging:** the GPU carried a steady ~40% foreign load (remote desktop encoder + compositor) during both sides. The runner writes stdout/stderr to files on both sides. **Results** | | frame p50 (ms) | GPU busy per present (ms) | |---|---|---| | base | 467.3 / 427.4 / 409.6 (mean 434.8) | 301.5 / 202.6 / 218.0 (mean 240.7) | | fix | 481.4 / 425.5 / 418.8 (mean 441.9) | 74.4 / 109.9 / 120.0 (mean 101.4) | - **GPU:** −58%. - **Frame time:** unchanged within noise (+1.6%). This base is CPU-bound at ~99% in the queue worker (#5345). - **Snapshot reuse:** a local counter (not in this PR) over the same scene finds that 100% of the vertex and index inputs are watched, and 92% of them are served from a reused snapshot. 8% are copied, ~586 MiB over 1.36 M inputs. Related: #5345, #5692, #3338 (inputs above `DrawInputBudget` stay in place). Summary lines and traces: attached (`aps5-summary.jsonl` and `aps5-trace-*.json.gz` of the 6 runs). Earlier per-draw measurement, on the same machine with the stack of #494/#1193/#1202/#5216 on top of the same base, via draw timestamps: | | Before | After | |---|---|---| | G-buffer draw | 227.5 µs | 1.8 µs | | GPU per frame | 323 ms | 100 ms | | Gameplay | 3.07 FPS | 4.40 FPS | | Intro cutscene | 5.76 FPS | 7.99 FPS | | Worker per draw | 37.4 µs | 34.3 µs | Images are correct in both scenes. ### 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 (touches the same function as #4649; compatible, whichever lands second rebases) - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 616.64, Windows 11 10.0.26200 - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-14 15:27:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T15:27:52Z.


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
#4649 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp L929-931
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6171920586 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5900#issuecomment-6171920586). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T15:27:52Z. --- <!-- 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 | |---|---|---|---| | #4649 | `core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp` [L929-931](https://github.com/boykopovar/AnyPS5/blob/e154f5658524bf3b6fd2aed987d31f61bfdb64d3/core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp#L929-L931)<br>`core/libs/prx/libSceAgcDriver/tests/Recorder.cpp` | | |

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