perf(agc): read draw vertex and index buffers in place from host imports #2253

Merged
Raghav314 merged 1 commit from upstream-pr/2253 into main 2026-10-10 06:19:00 +00:00
Raghav314 commented 2026-10-09 13:14:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-09T13:14:02Z.


What

Every draw copies its index range and each of its vertex ranges out of guest memory into a new host buffer (CopyDrawInput) before the GPU can read them. A range that lies in a host import is now bound from the import itself, at its offset in it. That's also how the console reads them: the input assembler fetches straight from guest memory, with no copy step.

  • A range is bound in place only when nothing could still write over it: no recorded or in-flight GPU write after the pending results are flushed (the same FlushGpuWrites the copy does, which waits for such a write), no completion label, no queued label store, no copied buffer a dispatch or draw writes back. Otherwise it's copied as before.
  • Its offset in the import has to suit the reader: a multiple of the index size for indices, and for vertices the strictest format alignment of the attributes that share the range. A copy starts its range at offset 0, so only an in-place range can end up misaligned; PlanVertexCopies now records that alignment per range (VertexCopyPlan::alignments).
  • The read is noted on the batch (Recorder::ReadKind::DrawInput), so a CPU store into the range waits for the draw like the other in-place readers, and the barrier validation sees it. The import's buffer stays alive until the batch completes the same way it does for those readers (retireImport).
  • Host imports gain VERTEX_BUFFER and INDEX_BUFFER usage.
  • An index range bound in place is scanned for its highest index at every draw; a copied one keeps that value in the draw input cache with its copy. I tried keeping it for in-place ranges too (same cache, same write and registry generations): standing still in Hades II's hub with 10 s windows alternated, it was slower, 37.5 against 38.4 fps (median of 6 windows each). Its index ranges are small, so the scan costs less than the cache's write collect and lookup.

#1968 and #1769 changed the same loops in prepareDrawInputs and have merged. The in-place index scan uses #1968's HighestDrawIndex, so a primitive restart index is left out of the vertex range whether the indices are copied or bound in place. Attributes whose fetch is out of range still get #1769's zero buffers; only ranges that are actually read can be bound in place. #1969 (null V#s) changes the same loop, so whichever of the two lands second needs a rebase.

PPSA36082

Hades II issues thousands of small draws a frame from vertex and index data in GPU-mapped memory. On main f1451396 with the fixes it needs to reach gameplay, it ran at about 2 fps, and the frame time went to copying draw inputs. With this change it ran at 27-30 fps in the same scene (MangoHud). The previous head of this PR (0e9769bd), on main d70b8998 with the rest of what Hades needs (including #1810), ran gameplay at 40-45 fps with no skipped draws, so the alignment check doesn't cost it anything. The rebase onto current main changed only how the index and vertex paths fit #1968's and #1769's code, not what is bound in place.

Tested

Linux (CachyOS), x86-64, GCC, 7800X3D / RTX 4090.

  • agc_driver_graphics (new checks): a merged vertex range takes the strictest alignment of its attributes.
  • agc_driver_recorder_tests (new drawInputInPlaceTests, over a write-watched block registered and imported like the other draw input tests):
    • An aligned imported range is bound in place, and its read is noted on the open batch as a draw input read. It's gone once the batch completes.
    • A range misaligned for its format is copied; the same range is bound in place for a 2-byte reader.
    • A range under a pending GPU write is bound only after the write completed.
    • A range under a queued label store is copied; a disjoint range still binds in place.
    • Memory without an import, and a draw without a recorder, are copied.
  • agc_driver_recorder_tests runs in ctest only as --pipeline-cache-only, so I ran the whole binary by hand. drawInputInPlaceTests passes. The binary then stops at storageRefreshTests ("the refresh's store of the results did not reach guest memory"), and current main without this change stops at the same check.
  • Mutations, each failing a check: alignment ignored, queued label stores ignored, read not noted, a range keeping its first attribute's alignment, an import bound without a recorder. After the rebase I ran the first and third again, and both still fail.
  • The linux job of current build.yml, run locally on this head (current main bc40a6b5 plus this commit): 597/598. The one failure is agc_driver_dcc_keys_first_write, which fails the same way on main without this change on this machine (RTX 4090) and passes in GitHub's CI.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4800901830 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2253). Originally posted by [Raghav314](https://github.com/Raghav314) on 2026-10-09T13:14:02Z. --- ### What Every draw copies its index range and each of its vertex ranges out of guest memory into a new host buffer (`CopyDrawInput`) before the GPU can read them. A range that lies in a host import is now bound from the import itself, at its offset in it. That's also how the console reads them: the input assembler fetches straight from guest memory, with no copy step. - A range is bound in place only when nothing could still write over it: no recorded or in-flight GPU write after the pending results are flushed (the same `FlushGpuWrites` the copy does, which waits for such a write), no completion label, no queued label store, no copied buffer a dispatch or draw writes back. Otherwise it's copied as before. - Its offset in the import has to suit the reader: a multiple of the index size for indices, and for vertices the strictest format alignment of the attributes that share the range. A copy starts its range at offset 0, so only an in-place range can end up misaligned; `PlanVertexCopies` now records that alignment per range (`VertexCopyPlan::alignments`). - The read is noted on the batch (`Recorder::ReadKind::DrawInput`), so a CPU store into the range waits for the draw like the other in-place readers, and the barrier validation sees it. The import's buffer stays alive until the batch completes the same way it does for those readers (`retireImport`). - Host imports gain `VERTEX_BUFFER` and `INDEX_BUFFER` usage. - An index range bound in place is scanned for its highest index at every draw; a copied one keeps that value in the draw input cache with its copy. I tried keeping it for in-place ranges too (same cache, same write and registry generations): standing still in Hades II's hub with 10 s windows alternated, it was slower, 37.5 against 38.4 fps (median of 6 windows each). Its index ranges are small, so the scan costs less than the cache's write collect and lookup. #1968 and #1769 changed the same loops in `prepareDrawInputs` and have merged. The in-place index scan uses #1968's `HighestDrawIndex`, so a primitive restart index is left out of the vertex range whether the indices are copied or bound in place. Attributes whose fetch is out of range still get #1769's zero buffers; only ranges that are actually read can be bound in place. #1969 (null V#s) changes the same loop, so whichever of the two lands second needs a rebase. ### PPSA36082 Hades II issues thousands of small draws a frame from vertex and index data in GPU-mapped memory. On main f1451396 with the fixes it needs to reach gameplay, it ran at about 2 fps, and the frame time went to copying draw inputs. With this change it ran at 27-30 fps in the same scene (MangoHud). The previous head of this PR (0e9769bd), on main d70b8998 with the rest of what Hades needs (including #1810), ran gameplay at 40-45 fps with no skipped draws, so the alignment check doesn't cost it anything. The rebase onto current main changed only how the index and vertex paths fit #1968's and #1769's code, not what is bound in place. ### Tested Linux (CachyOS), x86-64, GCC, 7800X3D / RTX 4090. - `agc_driver_graphics` (new checks): a merged vertex range takes the strictest alignment of its attributes. - `agc_driver_recorder_tests` (new `drawInputInPlaceTests`, over a write-watched block registered and imported like the other draw input tests): - An aligned imported range is bound in place, and its read is noted on the open batch as a draw input read. It's gone once the batch completes. - A range misaligned for its format is copied; the same range is bound in place for a 2-byte reader. - A range under a pending GPU write is bound only after the write completed. - A range under a queued label store is copied; a disjoint range still binds in place. - Memory without an import, and a draw without a recorder, are copied. - `agc_driver_recorder_tests` runs in ctest only as `--pipeline-cache-only`, so I ran the whole binary by hand. `drawInputInPlaceTests` passes. The binary then stops at `storageRefreshTests` ("the refresh's store of the results did not reach guest memory"), and current main without this change stops at the same check. - Mutations, each failing a check: alignment ignored, queued label stores ignored, read not noted, a range keeping its first attribute's alignment, an import bound without a recorder. After the rebase I ran the first and third again, and both still fail. - The linux job of current `build.yml`, run locally on this head (current main bc40a6b5 plus this commit): 597/598. The one failure is `agc_driver_dcc_keys_first_write`, which fails the same way on main without this change on this machine (RTX 4090) and passes in GitHub's CI. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
popcoder565 commented 2026-10-09 15:25:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:25:05Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head 0e9769bd, merged onto main d70b8998 in one build with 33 other AGC/shader PRs that had no Windows run.

  • This PR's tests pass: agc_driver_graphics. None of them reported skipping a case.
  • agc_driver_recorder_tests (not in ctest), built explicitly: 10 of 10. #2248 and #2299 were merged too, because main fails that test for other reasons (#2155).
  • Full ctest in that build: 514 of 515. The one failure is #2257's new test, which is registered without the Windows PATH setup.

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6083917598 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2253#issuecomment-6083917598). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T15:25:05Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `0e9769bd`, merged onto `main` d70b8998 in one build with 33 other AGC/shader PRs that had no Windows run. - This PR's tests pass: `agc_driver_graphics`. None of them reported skipping a case. - `agc_driver_recorder_tests` (not in ctest), built explicitly: 10 of 10. #2248 and #2299 were merged too, because `main` fails that test for other reasons (#2155). - Full ctest in that build: 514 of 515. The one failure is #2257's new test, which is registered without the Windows `PATH` setup. No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
adriadam10 commented 2026-10-10 06:18:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:18:57Z.


Checked on current main (merges cleanly): libSceAgcDriver build and ctest 277/277, the new agc_driver_graphics alignment checks fail to build without the change, and the full agc_driver_recorder_tests binary run by hand passes drawInputInPlaceTests (it stops later at storageRefreshTests, as on main). Also covered by popcoder565's Windows run on the previous head.

Not covered by tests: the offset/handle arithmetic in prepareDrawInputs itself (only InPlaceDrawInput is pinned). Merging; whichever of this and #1969 lands second needs a rebase (same loop, tests/Graphics.cpp, TechnicalDebt).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094584535 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2253#issuecomment-6094584535). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T06:18:57Z. --- Checked on current main (merges cleanly): libSceAgcDriver build and ctest 277/277, the new `agc_driver_graphics` alignment checks fail to build without the change, and the full `agc_driver_recorder_tests` binary run by hand passes `drawInputInPlaceTests` (it stops later at `storageRefreshTests`, as on main). Also covered by popcoder565's Windows run on the previous head. Not covered by tests: the offset/handle arithmetic in `prepareDrawInputs` itself (only `InPlaceDrawInput` is pinned). Merging; whichever of this and #1969 lands second needs a rebase (same loop, `tests/Graphics.cpp`, TechnicalDebt).
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!2253
No description provided.