Skip to content

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

Draft
Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/22001
Draft

Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/22001

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#22001, originally opened by talha-devp.

Source commit: 06310d94758cb162afe4b2560a12476983a78312. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


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, boykopovar#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 boykopovar#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. boykopovar#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 (258ab7b plus the new test) and this PR (then on 258ab7b; rebased onto ab50895, 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 459f4f8 with boykopovar#16053 reverted, because plain main aborts or draws this scene wrongly (boykopovar#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 perf: Astroneer (PPSA27623) opening cutscene runs at ~10 FPS boykopovar/AnyPS5#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

A buffer fill whose range no single host import covers, but which
existing imports cover contiguously (adjacent registered ranges, each
imported on its own), was refused by FillBuffer, so the caller waited
for the GPU to go idle and stored the fill on the CPU. The fill is now
recorded per covering import between the same barriers, with the same
pending-write and write-stamp bookkeeping over the whole range. The
pieces are planned before anything is recorded; a range with a part
that has no import is still refused. Fills split this way are not
elided as repeats.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@github-actions github-actions Bot added perf Performance change perf numbers missing perf pull request without a before and after summary line labels Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

This pull request is labeled perf, so it needs the summary line of a capture on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with main, rebase needed perf numbers missing perf pull request without a before and after summary line perf Performance change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants