perf(agc): reuse read-only sparse buffer address uploads #27991
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27991"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by kteal on 2026-11-28T01:28:11Z.
What
Repeated read-only draws can share one unchanged Vulkan buffer, avoiding a request for another backing buffer, a guest-to-host copy and a hole clear. In a 220 MiB upload with 79 of 80 backed spans write-tracked, this reduced median host time per upload from 16.25–17.49 ms to 0.36–0.41 ms on an RTX 4070 Laptop.
A sparse buffer can have a shader device address even when every use of that address is read-only. The opt-in sparse comparison cache previously excluded every addressable buffer. Planet Zoo's Animal Market repeatedly uploaded large ranges with identical backing and bytes.
Allow a fresh sparse upload into the existing comparison cache when the address table grants no write permission and no declared shader write overlaps the full guest range. Addressable snapshots stay immutable. A live GPU write is flushed before validation. Spans without a valid unchanged-generation proof are compared byte for byte. A mismatch or inaccessible span falls back to the ordinary upload. A single backed span that already fills the trimmed allocation stays on the normal copy path. Matching device, usage, extent and backed layout are still required. The optimization uses the existing
APS5_COMPARE_SPARSE_UPLOADS=1switch.#27451 covers a sparse piece that disappears between registration and upload. The addressable comparison here can only return an unchanged buffer. The existing upload path determines how to handle an inaccessible piece. Warm-cache integration review
Tested
Planet Zoo (PPSA18026), Goodwin House loading, RTX 4070 Laptop at 1920×1080. Four fresh processes used the same title executable, runtime libraries, preset, warm shader-cache seed and screen-triggered 60-second capture. Only the graphics driver changed. The measured revisions were
8c02bb89f41candd39c2210ebf5. The submitted patch has the same stable Git patch ID after rebasing onto4814cae85517. All four native traces retained every event. A separate, later 140-second window on main ended when the title exited before writing a summary and is excluded.Across the four windows the pooled frame time was 0.66 s on main and 1.05 s on the feature (60.4% higher). The mix of quick loading-screen presents and long scene-transition frames varied across launches, limiting what these means say about park performance. The public Perfetto extracts retain the native present markers and presentation and resource-completion durations on anonymous tracks. Frame digests · Summary lines
Two additional fresh processes used the submitted revisions and the same shader seed, GPU, settings and Goodwin scene. They requested a 30-second capture starting 110 seconds after confirming the loading screen.
4814cae855177042da5d054cThe later window has a small sample count because each heavy loading frame can exceed the requested window length.
Host cost per upload. One reader held the original snapshot. Four fresh RTX processes per layout each timed ten registrations and
Upload(true)calls, in main / feature / feature / main order. The table reports each process median after discarding its first two samples. The 80-span layouts have 220 MiB of data across a 300 MiB guest range, with a 1 MiB hole after each backed span.On each 80-span layout, the feature returned the held Vulkan buffer in all 20 timed uploads. Main returned a buffer distinct from the held reader in all 20. On the trimmed dense control both revisions used the ordinary path for all 20 uploads. Comparing that dense buffer had been slower in an exploratory build, which motivated the fully backed check. Individual samples
Animal Market prototype. In five consecutive ten-present windows on the earlier park-capable renderer, enabling read-only address reuse saved 9.8% and 12.0% against adjacent controls. Those measurements used a separate integration build with the warm-decommit fix and allowed refresh of exclusively owned buffers. The submitted implementation keeps addressable snapshots immutable. The park percentages apply to the prototype.
GPU correctness. On Windows 11, the sparse-hole and read-only flush tests passed on each tested adapter on main and the feature. The read-only flush test also passed with sparse comparison explicitly enabled on both revisions. The feature fixture checks equal handles, a guest CPU mutation, GPU readback of the old and new snapshots, and exclusion of an overlapping shader write. The validation layer was loaded, the shader cache disabled, Vulkan required, and these runs logged zero VUIDs.
As a separate diagnostic, forcing the comparison cache on in the non-addressable pool-identity test on Intel caused the shortened upload to miss the pre-primed Vulkan handle on both main and this patch. Both diagnostic runs then logged the same device-destruction VUID during cleanup. The pool test passes under its normal settings on both revisions and GPUs.
Summary extracts and trace links
Run 1 · Run 2 · Run 3 · Run 4 · Run 5 · Run 6
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-28T07:01:38Z.
Review: APPROVED
Checked head
7042da5d05. All on Windows 11 with WinLibs GCC 15.2 (Release), applied tomain4c7578e0a4together with #28006, #27985, #28002, #28001, #27987, #28007, #27994.tools/check_conventions.py --headandtools/debt_fold.py --checkpassed and the full build succeeded. In the full CPU suite (5,135 tests) the only failure iswindows_read_trap_unknown, which fails onmaintoo (fixed in #28028). The full GPU suite (2,249 tests) on both GPUs, withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layerand the 1.4.363 layer inserted, matchesmainon the same machine. The GPUs were an NVIDIA RTX 5080 (621.24) and an AMD Radeon gfx1036 iGPU (26.11.2). Onlyagc_driver_linear_target_import_creationfails, as onmain(fixed in #28029), and neither log has aVUID-orSYNC-HAZARDline.agc_driver_upload_cache_read_only_flush, which setsAPS5_COMPARE_SPARSE_UPLOADSand runsCheckSparseAddressReadswhen buffer device addresses are available, passes on both GPUs.One non-blocking note: the whole-title table shows the feature at 1.05 s per present against 0.66 s on
main. So the title-level gain isn't shown yet, only the per-upload one. Since the path stays behindAPS5_COMPARE_SPARSE_UPLOADS, the default is unchanged.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T07:29:29Z.
Review: APPROVED
Reviewed — looks good
The read-only sparse upload reuse is guarded by address write permissions and write overlap checks, and the added test exercises cache reuse, mutation, and writable separation.
What I ran
Reviewed head
7042da5d054c33622b5f9704acc964960d2305bc. I inspected the prepared diff, changed source context, and the added execution test throughrepo_read.py; I ran no build or tests.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No build or runtime test was run in this review. The author reports GPU tests and performance measurements, which I did not independently verify. The manifest lists two changed files; both were read.
GuestBufferMemory.cppwas excluded from the review folder due to size and read throughrepo_read.py.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T20:46:00Z.
Review: COMMENTED
The new fixture checks that a guest byte change creates a new sparse address upload while the earlier upload remains intact. Could the same fixture also change the committed pieces with the guest range otherwise unchanged, then verify the newly absent bytes read as zero? That tests the
piecescheck on the addressable cache lookup.Source review at
7042da5d05. The head trial-merges onto700fae9438. Paired Vulkan execution is queued.AI-assisted: yes.