Skip to content

perf(agc): reuse read-only sparse buffer address uploads - #27991

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
kteal:perf/read-only-sparse-address-uploads
Dec 4, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
kteal:perf/read-only-sparse-address-uploads

Conversation

@kteal

@kteal kteal commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

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=1 switch.

#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 8c02bb89f41c and d39c2210ebf5. The submitted patch has the same stable Git patch ID after rebasing onto 4814cae85517. 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.

Run order Build Presents Seconds per present
1 main 138 0.75
2 feature 88 1.10
3 feature 77 1.00
4 main 131 0.56

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.

Rebased build Presents Seconds per present
main 4814cae85517 1 36.88
feature 7042da5d054c 2 30.12

The 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.

Backing Main medians (ms) Feature medians (ms)
192 MiB contiguous, trimmed tail 10.95, 10.95 10.93, 10.92
80 unwatched backed spans 16.26, 16.18 14.89, 15.82
Same layout, 79 spans write-tracked 17.49, 16.25 0.36, 0.41

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

{"commit":"8c02bb89f41c","dirty":null,"gpu":"NVIDIA GeForce RTX 4070 Laptop GPU","driver":"NVIDIA 621.24","os":"Windows 10.0.26200","resolution":"1920x1080","title_id":"PPSA18026","window":{"spec":"seconds 0:60","first_present":777,"ms":103179.029},"presents":138,"frame_ms":{"p50":157.189,"p90":174.438,"p99":785.943,"max":80849.852},"gpu_busy_ms_per_present":44.954,"trace_dropped":false,"env":{"APS5_COMPARE_SPARSE_UPLOADS":"1","APS5_DRAW_CACHE_INDIRECT":"1","APS5_DRAW_CACHE_PUSH_WORD":"1","APS5_TRACE_SECONDS":"0:60","APS5_UNIFORM_INDIRECT_RECORDS":"1"},"trace":"sparse-addr-main-8c02bb89f41c.json.gz","worker_busy_pct":{},"top_phases_ms_per_frame":{}}
{"commit":"d39c2210ebf5","dirty":null,"gpu":"NVIDIA GeForce RTX 4070 Laptop GPU","driver":"NVIDIA 621.24","os":"Windows 10.0.26200","resolution":"1920x1080","title_id":"PPSA18026","window":{"spec":"seconds 0:60","first_present":916,"ms":96570.268},"presents":88,"frame_ms":{"p50":168.941,"p90":200.88,"p99":45925.886,"max":45925.886},"gpu_busy_ms_per_present":56.746,"trace_dropped":false,"env":{"APS5_COMPARE_SPARSE_UPLOADS":"1","APS5_DRAW_CACHE_INDIRECT":"1","APS5_DRAW_CACHE_PUSH_WORD":"1","APS5_TRACE_SECONDS":"0:60","APS5_UNIFORM_INDIRECT_RECORDS":"1"},"trace":"sparse-addr-feature-d39c2210ebf5.json.gz","worker_busy_pct":{},"top_phases_ms_per_frame":{}}
{"commit":"d39c2210ebf5","dirty":null,"gpu":"NVIDIA GeForce RTX 4070 Laptop GPU","driver":"NVIDIA 621.24","os":"Windows 10.0.26200","resolution":"1920x1080","title_id":"PPSA18026","window":{"spec":"seconds 0:60","first_present":941,"ms":77120.347},"presents":77,"frame_ms":{"p50":153.031,"p90":192.132,"p99":32455.733,"max":32455.733},"gpu_busy_ms_per_present":50.011,"trace_dropped":false,"env":{"APS5_COMPARE_SPARSE_UPLOADS":"1","APS5_DRAW_CACHE_INDIRECT":"1","APS5_DRAW_CACHE_PUSH_WORD":"1","APS5_TRACE_SECONDS":"0:60","APS5_UNIFORM_INDIRECT_RECORDS":"1"},"trace":"sparse-addr-feature-repeat-d39c2210ebf5.json.gz","worker_busy_pct":{},"top_phases_ms_per_frame":{}}
{"commit":"8c02bb89f41c","dirty":null,"gpu":"NVIDIA GeForce RTX 4070 Laptop GPU","driver":"NVIDIA 621.24","os":"Windows 10.0.26200","resolution":"1920x1080","title_id":"PPSA18026","window":{"spec":"seconds 0:60","first_present":895,"ms":73328.283},"presents":131,"frame_ms":{"p50":207.497,"p90":235.691,"p99":1029.028,"max":44996.214},"gpu_busy_ms_per_present":51.297,"trace_dropped":false,"env":{"APS5_COMPARE_SPARSE_UPLOADS":"1","APS5_DRAW_CACHE_INDIRECT":"1","APS5_DRAW_CACHE_PUSH_WORD":"1","APS5_TRACE_SECONDS":"0:60","APS5_UNIFORM_INDIRECT_RECORDS":"1"},"trace":"sparse-addr-main-repeat-8c02bb89f41c.json.gz","worker_busy_pct":{},"top_phases_ms_per_frame":{}}
{"commit":"4814cae85517","dirty":null,"gpu":"NVIDIA GeForce RTX 4070 Laptop GPU","driver":"NVIDIA 621.24","os":"Windows 10.0.26200","resolution":"1920x1080","title_id":"PPSA18026","window":{"spec":"seconds 0:30","first_present":1055,"ms":36876.862},"presents":1,"frame_ms":{"p50":36876.862,"p90":36876.862,"p99":36876.862,"max":36876.862},"gpu_busy_ms_per_present":739.905,"trace_dropped":false,"env":{"APS5_COMPARE_SPARSE_UPLOADS":"1","APS5_DRAW_CACHE_INDIRECT":"1","APS5_DRAW_CACHE_PUSH_WORD":"1","APS5_TRACE_SECONDS":"0:30","APS5_UNIFORM_INDIRECT_RECORDS":"1"},"trace":"sparse-current-main-late-4814cae85517.json.gz","worker_busy_pct":{},"top_phases_ms_per_frame":{}}
{"commit":"7042da5d054c","dirty":null,"gpu":"NVIDIA GeForce RTX 4070 Laptop GPU","driver":"NVIDIA 621.24","os":"Windows 10.0.26200","resolution":"1920x1080","title_id":"PPSA18026","window":{"spec":"seconds 0:30","first_present":1023,"ms":60236.436},"presents":2,"frame_ms":{"p50":30635.496,"p90":30635.496,"p99":30635.496,"max":30635.496},"gpu_busy_ms_per_present":752.627,"trace_dropped":false,"env":{"APS5_COMPARE_SPARSE_UPLOADS":"1","APS5_DRAW_CACHE_INDIRECT":"1","APS5_DRAW_CACHE_PUSH_WORD":"1","APS5_TRACE_SECONDS":"0:30","APS5_UNIFORM_INDIRECT_RECORDS":"1"},"trace":"sparse-current-feature-late-7042da5d054c.json.gz","worker_busy_pct":{},"top_phases_ms_per_frame":{}}

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
  • Unblocks: none
  • GPUs tested: Windows 11 build 26200, Intel Iris Xe Graphics (32.0.101.7088) and NVIDIA GeForce RTX 4070 Laptop GPU (32.0.16.2124, NVIDIA 621.24)
  • AI-assisted: yes

Summary by CodeRabbit

  • Performance
    • Read-only sparse uploads can now reuse cached buffers in additional safe cases, reducing unnecessary buffer allocations.
  • Bug Fixes
    • Writable uploads no longer reuse read-only snapshots, helping ensure changed data is reflected correctly.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Sparse upload cache

Layer / File(s) Summary
Sparse upload cache rules
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
Addressable sparse regions can use comparison caching when the stated backing, write, and overlap conditions are met. Refreshes require a cached buffer to lack shader-device-address usage and have one reference before modifying it exclusively.
Sparse address-read checks
core/libs/prx/libSceAgcDriver/tests/execution/UploadCacheReadOnlyFlush.cpp
The test reserves guest memory with an inaccessible gap and checks sparse snapshot reuse, replacement, retention of existing snapshot bytes, and separation from writable descriptors. It enables sparse upload comparison and runs these checks when buffer device addresses are supported.

Possibly related PRs

  • boykopovar/AnyPS5#27451: Both changes use the sparse upload path and address how sparse pieces that are inaccessible are handled.

Suggested labels: agc, perf

Suggested reviewers: edubox, eaglebearerys, marczx10

Change: Refactor

Merge Risk: Minimal · up to 7042d

The change lets eligible read-only sparse uploads reuse an existing buffer when their bytes are unchanged. No concrete defect was established in the cache-eligibility change or its execution checks, so merge risk is minimal.

Security architecture risk: Minimal · up to 7042d

The optimization reuses an existing snapshot only for eligible reads. If validation fails, the normal upload path handles the request without changing a snapshot still in use. The reviewed change does not grant new write access.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The new sharing applies to matching uploads within the cache for the current Vulkan device, not to arbitrary shader-addressable buffers. Entries must match guest base, allocation extent, usage, and backed layout.

Trust Boundaries and Controls

  • observed — The new admission check uses the same predicate that controls the shader address table's Write bit. It also independently excludes declared shader writes overlapping the full logical guest range, including any portion outside the trimmed allocation.

Resilience and Maintainability Implications

  • observed — Refresh holds a shared reference while validating, so cache replacement cannot release the buffer being checked. A failed addressable refresh does not evict or modify the entry. A successful fallback publishes its completed upload through the existing locked replacement path, which updates cache accounting.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 94f483a9-f26b-4911-86a0-1f7a3c0e0b7c
Commits

Reviewing files that changed from the base of the PR and between a4ebd90 and 7042da5.

Files selected for processing: 2

  • core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
  • core/libs/prx/libSceAgcDriver/tests/execution/UploadCacheReadOnlyFlush.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@JJenkx

JJenkx commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

AMD Linux check of the exact head 7042da5d054c. Arch Linux 7.3.5, RX 6650 XT, RADV Mesa 26.3.1, GCC 16.2.1, Release, -DBUILD_TESTING=ON. Ran with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 and the Khronos validation layer inserted:

  • agc_driver_upload_cache_read_only_flush (this PR's extended UploadCacheReadOnlyFlush.cpp): pass, with 0 VUID- and 0 SYNC-HAZARD.

This is correctness only. I didn't measure the performance effect, which would need matched title traces.

AI-assisted: yes

@akimfomin

Copy link
Copy Markdown

In KytyPS5 #1270, page-table physical storage and uploaded address content have separate lifetimes. For the read-only address cache here, rebind just one backing page and require a new lookup for that page, with neighboring unchanged address uploads remaining cache hits. Track the page-table bytes and payload-upload bytes separately. This is a proposed synthetic control, without a memory or performance claim.

@github-actions github-actions Bot added the agc libSceAgc* label Nov 28, 2026
@kteal

kteal commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

@akimfomin I ran the single-page rebind control on 7042da5d054c on Windows with Intel Iris Xe and an RTX 4070 Laptop. Rebinding one 64 KiB page to different contents at the same guest address replaced only the middle upload. Both neighboring uploads hit the cache. Vulkan readbacks confirmed that earlier draws retained the original bytes and the new draw saw the replacement.

The fixture kept three separate sparse uploads live. Each contained two backed 64 KiB pages with a hole between them. It checked the address-table entries against the Vulkan buffer device addresses after each lookup. A second build of the same commit counted the range-table bytes written and guest payload bytes copied separately. Both GPUs gave the same results.

Lookup Payload cache hits Range table written Payload copied
Changed rebind, reuse enabled 2 of 3 112 B 128 KiB
Next lookup, unchanged 3 of 3 0 B 0 KiB
Rebind again to byte-identical backing 3 of 3 0 B 0 KiB
Changed rebind, reuse disabled 0 of 3 112 B 384 KiB

The 128 KiB copy covers both backed pages of the replaced upload. All eight runs across the submitted and instrumented drivers, with reuse enabled and disabled, loaded Khronos validation and reported zero VUIDs or synchronization hazards. This control measures correctness and copy volume only.

@JJenkx thanks for independently checking the PR’s read-only flush test on the RX 6650 XT under Linux.

AI-assisted: yes

@github-actions github-actions Bot added the perf Performance change label Nov 28, 2026
@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4448 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 5372 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6186 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6197 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 9289 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 9508 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 9852 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 10492 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 10497 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 12157 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 12944 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 13148 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 13863 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 13920 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 13928 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 13929 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 15296 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 15297 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 15570 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 18173 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 22647 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 23596 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp

@Plyxen Plyxen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked head 7042da5d05. All on Windows 11 with WinLibs GCC 15.2 (Release), applied to main 4c7578e0a4 together with #28006, #27985, #28002, #28001, #27987, #28007, #27994. tools/check_conventions.py --head and tools/debt_fold.py --check passed and the full build succeeded. In the full CPU suite (5,135 tests) the only failure is windows_read_trap_unknown, which fails on main too (fixed in #28028). The full GPU suite (2,249 tests) on both GPUs, with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer and the 1.4.363 layer inserted, matches main on the same machine. The GPUs were an NVIDIA RTX 5080 (621.24) and an AMD Radeon gfx1036 iGPU (26.11.2). Only agc_driver_linear_target_import_creation fails, as on main (fixed in #28029), and neither log has a VUID- or SYNC-HAZARD line.

agc_driver_upload_cache_read_only_flush, which sets APS5_COMPARE_SPARSE_UPLOADS and runs CheckSparseAddressReads when 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 behind APS5_COMPARE_SPARSE_UPLOADS, the default is unchanged.

AI-assisted: yes (Claude Code)

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 through repo_read.py; I ran no build or tests.

Results

Check Result Note
Diff and source review passed Two changed files read
Build and runtime tests not run No commands run

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.cpp was excluded from the review folder due to size and read through repo_read.py.

To get this to a good state

Nothing is required.

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 pieces check on the addressable cache lookup.

Source review at 7042da5d05. The head trial-merges onto 700fae9438. Paired Vulkan execution is queued.

AI-assisted: yes.

@oneandonlydean
oneandonlydean merged commit f76091e into boykopovar:main Dec 4, 2026
15 of 17 checks passed
@kteal
kteal deleted the perf/read-only-sparse-address-uploads branch December 4, 2026 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* perf Performance change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants