perf(agc): record buffer fills across several host imports on the GPU #22001

Open
talha-devp wants to merge 1 commit from upstream-pr/22001 into main
talha-devp commented 2026-11-17 01:14:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by talha-devp on 2026-11-17T01:14:23Z.


What

A buffer fill (CP DMA fill or a recognized fill kernel, VulkanDevice::FillBuffer) whose range no single host import covers was refused, even when existing imports cover it contiguously: two adjacent registered ranges, each imported on its own. The caller then waited for the GPU to go idle (WaitIdle) and stored the fill on the CPU.

FillBuffer now plans the fill over the existing imports first: when the range has no single import, it walks the imports that hold it (ExistingHostImportFor), one piece per import, and refuses unless every piece has an import and every piece boundary stays 16-byte aligned to the fill (so the pattern phase is kept). Nothing is recorded before the plan is complete. The pieces are then recorded between the same barriers as a single fill (uniform fills with vkCmdFillBuffer, 16-byte patterns from the cached pattern buffer or, with APS5_FILL_CHAIN=1, seeded and doubled per piece). The pending-write checks, SyncThrough, key and label flushes, the pending-write note and the write stamp cover the whole range as before. After a sync the plan is made again, as the single import is looked up again today. A range with a part that has no import is still refused and stored by the caller as before. A fill split this way is not elided as a repeat: the repeat check compares one import serial, and a split fill has none.

Seen in Astroneer (PPSA27623, #21967): the per-frame 640 KiB fill straddles two GPU-mapped ranges (0x90000 imported at map time during loading and the next range imported later) in some launches; in a profiled one, 798 of 5237 fills went to the CPU at about 7.4 ms each.

No import is made or replaced. A joined import (importJoined, which #6197 exposes as HostImportSpanning for storage surfaces) could cover this layout too, but it retires the two existing imports and imports the joined range anew, and joinedRun takes only some layouts (a run that starts where the access starts, or ranges larger than the 8 MiB window). Recording per existing import leaves the import table as it is. #17255 walks existing imports the same way for sampled texture uploads (ExistingHostImportCopies, not merged); this PR uses only the existing ExistingHostImportFor and does not touch GuestBufferMemory.

Tested

Windows 10 Pro 22H2 (19045), NVIDIA GeForce RTX 4060, driver 621.14.

GPU tests, same build directory, main (258ab7b6bd plus the new test) and this PR (then on 258ab7b6bd; rebased onto ab5089590a, whose new commits change no file of libSceAgcDriver), ctest -R <50 fill, copy, import and label tests> -V with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer (validation layer 1.4.363):

  • main: 48 of 50 passed; the two failures are the new agc_driver_fill_across_imports and _chain ("a uniform fill across two imports was not stored on the GPU"). 0 VUID- lines, the layer inserted 77 times, was not found but was requested 0 times.
  • this PR: 50 of 50 passed, 0 VUID- lines, the layer inserted 77 times, was not found but was requested 0 times.

The new test registers two adjacent ranges of 0x90000 and 0x50000 bytes and checks the import layout it needs (each range imported on its own, no import over both). A fill across the boundary is refused and leaves the memory unchanged while the second range has no import. With both imported, a uniform fill and a 16-byte pattern fill are recorded on the GPU (the recorder holds work after the call) and the bytes are checked across the boundary, with the bytes before and after the fill left alone. _chain runs the same with APS5_FILL_CHAIN=1.

Astroneer (PPSA27623), opening cutscene, no input, 120 s per launch, cold and warm launch pairs in the order base, change, change, base (the second round's warm launch crashed in the title's FAsyncLoadingThread at 15 s, before any fill was split, and that round was run again), APS5_PIPELINE_STATS=1 only. Base: main 459f4f8c22 with #16053 reverted, because plain main aborts or draws this scene wrongly (#21967); change: the same plus this PR. Both arms carry a counter of CPU-stored fills that is not part of this PR. Which layout a launch gets is decided by the title's memory layout, so not every launch splits the fill. FPS is the cutscene window 30-100 s of the summary clock, fill commit cost the [commits] line's bufferfill mean over 30-90 s.

arm launch fill split across imports fills, CPU-stored fill commit (us) FPS 30-100 s
base round 1 warm no 12055, 0 65-90 11.82
base round 4 warm no 12838, 0 60-74 12.26
change round 3 warm no 11715, 0 62-88 11.20
change round 2 rerun warm yes, 1630 fills (3260 pieces) 10666, 2 63-80 10.16
change round 2 cold yes, 112 fills 1483, 0
change round 3 cold yes, 296 fills 3889, 1

The base arm got no split layout in this set, so this set has no FPS comparison of that layout. Earlier the same night, on the base without the counter, a warm launch with the split layout had fill commits of 1425-1568 us at 9.64 FPS, and a profiled one stored 1136 of 7434 fills on the CPU. With this PR the split fills are recorded on the GPU and cost what a fill through one import costs. The one split-layout warm launch (10.16 FPS) lies inside the spread of one-import warm launches on this machine the same night (10.16 to 12.81 FPS, 7 launches) but at its low end.

trace_digest.py of the summary files (the 100:10 trace window ended after the 120 s launches, so no window trace was written):

base round 4 warm:   **10 intervals**, 0.0 to 100.3 s, 1717 presents
                     NVIDIA GeForce RTX 4060, NVIDIA 621.14, Windows 10.0.19045, 3840x2160, commit 0df6715630d5
change round 2 warm: **10 intervals**, 0.0 to 100.5 s, 1557 presents
                     NVIDIA GeForce RTX 4060, NVIDIA 621.14, Windows 10.0.19045, 3840x2160, commit 728bf11ce927

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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 (refs #21967: removes the CPU-stored fills of the split layout; the cutscene stays CPU-bound)
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4060, driver 621.14, Windows 10 Pro 22H2 (19045)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5348432845 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22001). Originally posted by [talha-devp](https://github.com/talha-devp) on 2026-11-17T01:14:23Z. --- ### What A buffer fill (CP DMA fill or a recognized fill kernel, `VulkanDevice::FillBuffer`) whose range no single host import covers was refused, even when existing imports cover it contiguously: two adjacent registered ranges, each imported on its own. The caller then waited for the GPU to go idle (`WaitIdle`) and stored the fill on the CPU. `FillBuffer` now plans the fill over the existing imports first: when the range has no single import, it walks the imports that hold it (`ExistingHostImportFor`), one piece per import, and refuses unless every piece has an import and every piece boundary stays 16-byte aligned to the fill (so the pattern phase is kept). Nothing is recorded before the plan is complete. The pieces are then recorded between the same barriers as a single fill (uniform fills with `vkCmdFillBuffer`, 16-byte patterns from the cached pattern buffer or, with `APS5_FILL_CHAIN=1`, seeded and doubled per piece). The pending-write checks, `SyncThrough`, key and label flushes, the pending-write note and the write stamp cover the whole range as before. After a sync the plan is made again, as the single import is looked up again today. A range with a part that has no import is still refused and stored by the caller as before. A fill split this way is not elided as a repeat: the repeat check compares one import serial, and a split fill has none. Seen in Astroneer (PPSA27623, #21967): the per-frame 640 KiB fill straddles two GPU-mapped ranges (0x90000 imported at map time during loading and the next range imported later) in some launches; in a profiled one, 798 of 5237 fills went to the CPU at about 7.4 ms each. No import is made or replaced. A joined import (`importJoined`, which #6197 exposes as `HostImportSpanning` for storage surfaces) could cover this layout too, but it retires the two existing imports and imports the joined range anew, and `joinedRun` takes only some layouts (a run that starts where the access starts, or ranges larger than the 8 MiB window). Recording per existing import leaves the import table as it is. #17255 walks existing imports the same way for sampled texture uploads (`ExistingHostImportCopies`, not merged); this PR uses only the existing `ExistingHostImportFor` and does not touch `GuestBufferMemory`. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 10 Pro 22H2 (19045), NVIDIA GeForce RTX 4060, driver 621.14. GPU tests, same build directory, `main` (258ab7b6bd plus the new test) and this PR (then on 258ab7b6bd; rebased onto ab5089590a, whose new commits change no file of `libSceAgcDriver`), `ctest -R <50 fill, copy, import and label tests> -V` with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer` (validation layer 1.4.363): - `main`: 48 of 50 passed; the two failures are the new `agc_driver_fill_across_imports` and `_chain` ("a uniform fill across two imports was not stored on the GPU"). 0 `VUID-` lines, the layer inserted 77 times, `was not found but was requested` 0 times. - this PR: 50 of 50 passed, 0 `VUID-` lines, the layer inserted 77 times, `was not found but was requested` 0 times. The new test registers two adjacent ranges of 0x90000 and 0x50000 bytes and checks the import layout it needs (each range imported on its own, no import over both). A fill across the boundary is refused and leaves the memory unchanged while the second range has no import. With both imported, a uniform fill and a 16-byte pattern fill are recorded on the GPU (the recorder holds work after the call) and the bytes are checked across the boundary, with the bytes before and after the fill left alone. `_chain` runs the same with `APS5_FILL_CHAIN=1`. Astroneer (PPSA27623), opening cutscene, no input, 120 s per launch, cold and warm launch pairs in the order base, change, change, base (the second round's warm launch crashed in the title's `FAsyncLoadingThread` at 15 s, before any fill was split, and that round was run again), `APS5_PIPELINE_STATS=1` only. Base: `main` 459f4f8c22 with #16053 reverted, because plain `main` aborts or draws this scene wrongly (#21967); change: the same plus this PR. Both arms carry a counter of CPU-stored fills that is not part of this PR. Which layout a launch gets is decided by the title's memory layout, so not every launch splits the fill. FPS is the cutscene window 30-100 s of the summary clock, fill commit cost the `[commits]` line's `bufferfill` mean over 30-90 s. | arm | launch | fill split across imports | fills, CPU-stored | fill commit (us) | FPS 30-100 s | |---|---|---|---|---|---| | base | round 1 warm | no | 12055, 0 | 65-90 | 11.82 | | base | round 4 warm | no | 12838, 0 | 60-74 | 12.26 | | change | round 3 warm | no | 11715, 0 | 62-88 | 11.20 | | change | round 2 rerun warm | yes, 1630 fills (3260 pieces) | 10666, 2 | 63-80 | 10.16 | | change | round 2 cold | yes, 112 fills | 1483, 0 | | | | change | round 3 cold | yes, 296 fills | 3889, 1 | | | The base arm got no split layout in this set, so this set has no FPS comparison of that layout. Earlier the same night, on the base without the counter, a warm launch with the split layout had fill commits of 1425-1568 us at 9.64 FPS, and a profiled one stored 1136 of 7434 fills on the CPU. With this PR the split fills are recorded on the GPU and cost what a fill through one import costs. The one split-layout warm launch (10.16 FPS) lies inside the spread of one-import warm launches on this machine the same night (10.16 to 12.81 FPS, 7 launches) but at its low end. `trace_digest.py` of the summary files (the 100:10 trace window ended after the 120 s launches, so no window trace was written): ``` base round 4 warm: **10 intervals**, 0.0 to 100.3 s, 1717 presents NVIDIA GeForce RTX 4060, NVIDIA 621.14, Windows 10.0.19045, 3840x2160, commit 0df6715630d5 change round 2 warm: **10 intervals**, 0.0 to 100.5 s, 1557 presents NVIDIA GeForce RTX 4060, NVIDIA 621.14, Windows 10.0.19045, 3840x2160, commit 728bf11ce927 ``` ### 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) and the licence notice of code adapted from upstream (see AGENTS.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 (refs #21967: removes the CPU-stored fills of the split layout; the cutscene stays CPU-bound) - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4060, driver 621.14, Windows 10 Pro 22H2 (19045) - [x] AI-assisted: yes
MarcZX10 commented 2026-11-23 02:11:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:11:55Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the targeted code review supports merging, while the reported test runs were supplied by the author.

What I ran

Reviewed head 06310d94758cb162afe4b2560a12476983a78312 using repo_read.py to inspect the prepared diff and changed code. No commands or tests were run in this review.

Read: description.md, commits.md, manifest.json, diff.patch, VulkanDevice.cpp (the changed fill path), and FillAcrossImports.cpp. The full source file was excluded from the review folder because it was too large, so it was read through the pinned repository reader. The CMake registration file was in the review bundle but not read. No other changed files were listed in the manifest.

Results

Check Result Note
Targeted source review passed Fill planning and execution inspected
Tests run by reviewer not run Author reports GPU test results
CMake test registration not run File not read

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not run tests, build the change, or verify the reported GPU, game, and performance results. I did not inspect the test registration CMake file. The review did not cover the remainder of VulkanDevice.cpp or unrelated repository code.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6015839106 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22001#pullrequestreview-6015839106). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T02:11:55Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the targeted code review supports merging, while the reported test runs were supplied by the author. ## What I ran Reviewed head `06310d94758cb162afe4b2560a12476983a78312` using `repo_read.py` to inspect the prepared diff and changed code. No commands or tests were run in this review. Read: `description.md`, `commits.md`, `manifest.json`, `diff.patch`, `VulkanDevice.cpp` (the changed fill path), and `FillAcrossImports.cpp`. The full source file was excluded from the review folder because it was too large, so it was read through the pinned repository reader. The CMake registration file was in the review bundle but not read. No other changed files were listed in the manifest. ## Results | Check | Result | Note | |---|---|---| | Targeted source review | passed | Fill planning and execution inspected | | Tests run by reviewer | not run | Author reports GPU test results | | CMake test registration | not run | File not read | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I did not run tests, build the change, or verify the reported GPU, game, and performance results. I did not inspect the test registration CMake file. The review did not cover the remainder of `VulkanDevice.cpp` or unrelated repository code. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 22:13:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:13:42Z.

Review: COMMENTED


The trial merge onto a1b75b0947 conflicts in VulkanDevice.cpp. When integrating the current fill path, preserve the preflight of the entire address range before any GPU command is recorded. Keep the 16-byte pattern phase continuous across adjacent imports and keep the gap case that rejects the fill without recording a prefix. Please rerun FillAcrossImports and the existing buffer-fill controls on the merged head.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6179529396 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22001#pullrequestreview-6179529396). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T22:13:42Z. **Review:** COMMENTED --- The trial merge onto `a1b75b0947` conflicts in `VulkanDevice.cpp`. When integrating the current fill path, preserve the preflight of the entire address range before any GPU command is recorded. Keep the 16-byte pattern phase continuous across adjacent imports and keep the gap case that rejects the fill without recording a prefix. Please rerun `FillAcrossImports` and the existing buffer-fill controls on the merged head. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/22001:upstream-pr/22001'
git switch 'upstream-pr/22001'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/22001'
git switch 'upstream-pr/22001'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/22001'
git switch 'upstream-pr/22001'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/22001'
git switch 'main'
git merge --squash 'upstream-pr/22001'
git switch 'main'
git merge --ff-only 'upstream-pr/22001'
git switch 'main'
git merge 'upstream-pr/22001'
git push origin 'main'
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!22001
No description provided.