fix(agc): bind large vertex inputs in place instead of copying them #19445

Merged
SP4C3B4R-8 merged 3 commits from upstream-pr/19445 into main 2026-11-23 18:28:14 +00:00
SP4C3B4R-8 commented 2026-11-13 10:16:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SP4C3B4R-8 on 2026-11-13T10:16:27Z.


What

An indirect draw's counts are unknown when its inputs are prepared, so prepareDrawInputs copies the whole range its vertex descriptor spans. In a heavy 3D scene those copies reach 144 MiB each and are allocated again and again in host memory (Buffer per copy), until heap 1 is full and the title dies with vkAllocateMemory -2.

InPlaceDrawInput now binds a vertex input range of at least APS5_LARGE_INPUT_IN_PLACE_MIB (default 8 MiB; 0 copies them as before) in place from its host import on any device, also where in-place inputs are otherwise off (NVIDIA's Windows driver). Everything else of the in-place path stays: the pending label and queued store refusals, the copied-writer checks, the import alignment and NotePendingRead. Index ranges and smaller vertex ranges are unchanged. The variable is listed in docs/dev/ENVIRONMENT.md.

Tested

Windows 11 Pro, Ryzen 7 7800X3D, GeForce RTX 5070 Ti (NVIDIA 610.88), the same retail 3D title's heaviest level, launched straight into it, APS5_HOST_IMPORT_MIB=14336 APS5_TEXTURE_CACHE_MIB=3584, otherwise defaults, one run per side of 280 s:

main cddfa7e662 this PR
result dies at ~235 s: vkAllocateMemory buffer: allocation=150994944 ... heap 0 14610/15227 MiB; heap 1 15334/15132 MiB: Vulkan result -2 (presentation failed, driver failure) runs the whole 280 s, no allocation failure
fps in the level (10 s intervals, 70-230 s) 4.2-4.5 4.2-4.6

The same failure with default budgets (APS5_HOST_IMPORT_MIB 20480, automatic texture cache) is masked by the texture cache budget shrinking to 2048 MiB first, on both sides. The allocations were traced on an older base: 168 new host buffers, 7.1 GB in 235 s, from indirect draws' vertex ranges; with the change, 24 MiB.

Focused tests on main and on this PR, same machine and GPU, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build -R '^(agc_draw_inputs_in_place_driver|agc_owned_draw_inputs.*|agc_draw_inputs_in_place|agc_draw_inputs_copied|agc_vertex_input.*|agc_driver_native_msaa_vertex_input|agc_driver_prepared_shaders_abi_deferred_vertex_inputs)$' -V: 12/12 passed on both, no VUID- lines, the validation layer was found in both logs.

tools/pr_overlap.py reported open PRs touching Draw.cpp (#18390, #18515, #19119) and ENVIRONMENT.md; compared by hand, none changes InPlaceDrawInput or the vertex input copies.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 5070 Ti, driver 610.88, Windows 11 Pro
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01DuBfeb8q3sBv5kLpAytGCG

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5293796018 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19445). Originally posted by [SP4C3B4R-8](https://github.com/SP4C3B4R-8) on 2026-11-13T10:16:27Z. --- ### What An indirect draw's counts are unknown when its inputs are prepared, so `prepareDrawInputs` copies the whole range its vertex descriptor spans. In a heavy 3D scene those copies reach 144 MiB each and are allocated again and again in host memory (`Buffer` per copy), until heap 1 is full and the title dies with `vkAllocateMemory` -2. `InPlaceDrawInput` now binds a vertex input range of at least `APS5_LARGE_INPUT_IN_PLACE_MIB` (default 8 MiB; 0 copies them as before) in place from its host import on any device, also where in-place inputs are otherwise off (NVIDIA's Windows driver). Everything else of the in-place path stays: the pending label and queued store refusals, the copied-writer checks, the import alignment and `NotePendingRead`. Index ranges and smaller vertex ranges are unchanged. The variable is listed in `docs/dev/ENVIRONMENT.md`. ### Tested Windows 11 Pro, Ryzen 7 7800X3D, GeForce RTX 5070 Ti (NVIDIA 610.88), the same retail 3D title's heaviest level, launched straight into it, `APS5_HOST_IMPORT_MIB=14336 APS5_TEXTURE_CACHE_MIB=3584`, otherwise defaults, one run per side of 280 s: | | `main` cddfa7e662 | this PR | |---|---|---| | result | dies at ~235 s: `vkAllocateMemory buffer: allocation=150994944 ... heap 0 14610/15227 MiB; heap 1 15334/15132 MiB: Vulkan result -2` (presentation failed, driver failure) | runs the whole 280 s, no allocation failure | | fps in the level (10 s intervals, 70-230 s) | 4.2-4.5 | 4.2-4.6 | The same failure with default budgets (`APS5_HOST_IMPORT_MIB` 20480, automatic texture cache) is masked by the texture cache budget shrinking to 2048 MiB first, on both sides. The allocations were traced on an older base: 168 new host buffers, 7.1 GB in 235 s, from indirect draws' vertex ranges; with the change, 24 MiB. Focused tests on `main` and on this PR, same machine and GPU, `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build -R '^(agc_draw_inputs_in_place_driver|agc_owned_draw_inputs.*|agc_draw_inputs_in_place|agc_draw_inputs_copied|agc_vertex_input.*|agc_driver_native_msaa_vertex_input|agc_driver_prepared_shaders_abi_deferred_vertex_inputs)$' -V`: 12/12 passed on both, no `VUID-` lines, the validation layer was found in both logs. `tools/pr_overlap.py` reported open PRs touching `Draw.cpp` (#18390, #18515, #19119) and `ENVIRONMENT.md`; compared by hand, none changes `InPlaceDrawInput` or the vertex input copies. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 5070 Ti, driver 610.88, Windows 11 Pro - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DuBfeb8q3sBv5kLpAytGCG
MarcZX10 commented 2026-11-21 04:22:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T04:22:29Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the code preserves the existing in-place vertex safety checks while allowing large vertex ranges to use host imports.

What I ran

Reviewed head d76c084138abd8667f9257d74b4a8c717e9db080 using the prepared review bundle and repo_read.py. No commands or tests could be run in this review environment. The reported Windows runtime and focused test results are author-reported, not independently verified.

Results

Check Result Note
Changed code review passed Both changed files and the touched vertex path were read.
Tests not run Runtime and test results are author-reported.
Negative control not run No executable test environment was available.

Findings

Blocking

None.

Non-blocking

None.

Not verified

The repository diff and description were read. Full text was available and read for both changed files: core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp and docs/dev/ENVIRONMENT.md. Targeted context was read for HostImportFor in core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp, the draw-input callers, and drawInputsInPlace configuration in VulkanDevice.cpp. No changed files were excluded. Runtime behavior, GPU synchronization on physical hardware, and the author-reported tests were not independently verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6002794291 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19445#pullrequestreview-6002794291). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T04:22:29Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the code preserves the existing in-place vertex safety checks while allowing large vertex ranges to use host imports. ## What I ran Reviewed head `d76c084138abd8667f9257d74b4a8c717e9db080` using the prepared review bundle and `repo_read.py`. No commands or tests could be run in this review environment. The reported Windows runtime and focused test results are author-reported, not independently verified. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Both changed files and the touched vertex path were read. | | Tests | not run | Runtime and test results are author-reported. | | Negative control | not run | No executable test environment was available. | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The repository diff and description were read. Full text was available and read for both changed files: `core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp` and `docs/dev/ENVIRONMENT.md`. Targeted context was read for `HostImportFor` in `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp`, the draw-input callers, and `drawInputsInPlace` configuration in `VulkanDevice.cpp`. No changed files were excluded. Runtime behavior, GPU synchronization on physical hardware, and the author-reported tests were not independently verified. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-23 09:37:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T09:37:27Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the review supports merging, and the author reported focused tests and a title run that I did not perform.

What I ran

Reviewed head f1e0c06caf855eec1b55034bd263864fbb2f85e4. I read the prepared description, commits, manifest, diff, and both changed files; I used repo_read.py search and targeted reads for the affected vertex input path, import lookup, and read tracking. No tests or build commands were run.

Results

Check Result Note
Diff and changed code passed Both changed files read
Build and tests not run Test runs in description are author reported
Runtime behavior not run No console or title run

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not read files.json because it is unavailable in the review folder; the manifest lists both changed files as included, and I read both. I did not verify the reported Windows 11, NVIDIA, or other device behavior, run the focused tests, inspect the repository's test coverage, or check the base merge state.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6019304833 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19445#pullrequestreview-6019304833). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T09:37:27Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the review supports merging, and the author reported focused tests and a title run that I did not perform. ## What I ran Reviewed head `f1e0c06caf855eec1b55034bd263864fbb2f85e4`. I read the prepared description, commits, manifest, diff, and both changed files; I used `repo_read.py` search and targeted reads for the affected vertex input path, import lookup, and read tracking. No tests or build commands were run. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code | passed | Both changed files read | | Build and tests | not run | Test runs in description are author reported | | Runtime behavior | not run | No console or title run | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I did not read `files.json` because it is unavailable in the review folder; the manifest lists both changed files as included, and I read both. I did not verify the reported Windows 11, NVIDIA, or other device behavior, run the focused tests, inspect the repository's test coverage, or check the base merge state. ## To get this to a good state Nothing is required.
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!19445
No description provided.