perf(agc): put the shader data, image table maps and BDA tables in resizable BAR memory #15570

Open
milescoviello wants to merge 13 commits from upstream-pr/15570 into main
milescoviello commented 2026-11-03 19:13:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-03T19:13:49Z.


Depends on #9712, and builds on its BAR placement (Context::SnapshotProperties, the budget and refusal fallbacks of Buffer). This PR's own change is the last commit, 0918b0dc37.

What

#9712 moves draw snapshots, vertex copies and the draw upload ring to resizable BAR memory. The other buffers the CPU writes once per resource build, and every wave of the shaders binding them reads, stay in cached host memory:

  • the flattened SRT and shader data (addDataBuffer), read by every wave;
  • image table maps (ImageTableMap), several dependent loads per image sample;
  • BDA page tables, walked by every address-based access;
  • expanded index copies, zero-padded and zero vertex copies;
  • the read-only guest region copies of address-based builds (snapshotCopy, copyRegion).

On an RTX 4070 Ti (driver 615.71.09, PCIe 4.0) a compute read benchmark of 16-byte loads gives (ms):

Pattern Cached host memory (these buffers today) BAR memory Device memory
Coalesced 5.1 0.142 0.154
Random 94 2.3 2.7
Same 512 bytes per warp 2.2 0.035 0.035

How

  • Each of the buffers above takes context.SnapshotProperties(), so it lands in BAR memory under #9712's rules, and in host memory otherwise.
  • The CPU never reads them back. A data buffer placed in device memory keeps its words (Allocation::deviceWords) for the reuse compare in MovedDispatchBuffers, which compared the buffer's bytes. Writable region copies, which the write-back diffs, stay in host memory. Index copies the CPU scans for the highest index stay in host memory, as in #9712.

Tested

  • Ghost of Tsushima (PPSA02225), GPU profile (APS5_PROFILE_GPU=1 APS5_PROFILE_GPU_DRAWS=1), local stack, last 30 windows of each run. The same placement covered #9712's buffers too, so this is the combined effect:
Host memory (run 293) BAR memory (run 294)
GPU time per present 227 ms 180 ms
Instanced decal draws (variants 0x322 + 0x26x) 88 ms 48 ms
Draw class 146 ms 96 ms
  • That run lost the gain on the CPU: compares of device-memory buffers on the CPU (a snapshot refresh, which #9712 already covers; the data-buffer reuse compare, which this PR fixes) read uncached BAR memory at about 95 MB/s. With both fixed, the committer threads went back to normal load.
  • Not a frame-rate win yet without the profile. Same stack, 1200 s runs, fps median after 420 s:
Run Placement fps GPU busy per present
285-292 host memory 2.82-2.93 238-245 ms
296 BAR, both compares fixed 2.57 243 ms
297 BAR, plus copied vertex inputs and CPU read overlays 2.39 244 ms

The GPU profile serializes every draw, so it shows what each shader pays for its reads. Without it, GoT's frame isn't bound by those reads. I'm finding the CPU cost behind the lower rate with an in-process sampler of the driver threads, comparing host and BAR runs, and this stays a draft until that's explained.

  • Focused tests at 0918b0dc37: agc_bda_staging, agc_buffer_pool, agc_draw_inputs_copied, agc_draw_inputs_in_place, agc_draw_snapshot_cap, agc_draw_snapshot_epoch, agc_driver_bda_device, agc_driver_bda_span_reads, agc_driver_graphics, agc_driver_image_table, agc_driver_image_table_reuse, agc_driver_large_tracked_snapshot, agc_driver_partially_resident_snapshot, agc_driver_prepared_graphics:
Where Result
Linux, RTX 4070 Ti (BAR over the 12 GiB heap, so the placement is active) 14 of 14 pass in each of 3 runs
Windows 11 VM, GT 1030 (256 MiB BAR, so host memory as before) 14 of 14 pass in each of 3 runs, base 8ff4baf534 and head
Khronos validation, base #9712 4e93e34d8e vs head not valid: the 1.4.363 layer this run pointed at was not installed, and these test programs don't print the loader's "not found" error, so it validated nothing (#17896). 14 of 14 tests pass on each side. A re-run with layer 1.4.341 and VK_LOADER_DEBUG=layer follows the rebase.

Checklist

  • Based on current main; no other open PR implements the same functions (#9712 covers the snapshots, this PR the rest)
  • 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
  • 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: #9712
  • Fixes: none
  • Unblocks: none (a performance change; its measurements on PPSA02225 are under Tested)
  • GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 615.71.09, Ubuntu 26.04.1 (in progress); NVIDIA GeForce GT 1030, Windows 11 VM (in progress)
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5143079502 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15570). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-03T19:13:49Z. --- > **Depends on #9712**, and builds on its BAR placement (`Context::SnapshotProperties`, the budget and refusal fallbacks of `Buffer`). This PR's own change is the last commit, `0918b0dc37`. ### What #9712 moves draw snapshots, vertex copies and the draw upload ring to resizable BAR memory. The other buffers the CPU writes once per resource build, and every wave of the shaders binding them reads, stay in cached host memory: - the flattened SRT and shader data (`addDataBuffer`), read by every wave; - image table maps (`ImageTableMap`), several dependent loads per image sample; - BDA page tables, walked by every address-based access; - expanded index copies, zero-padded and zero vertex copies; - the read-only guest region copies of address-based builds (`snapshotCopy`, `copyRegion`). On an RTX 4070 Ti (driver 615.71.09, PCIe 4.0) a compute read benchmark of 16-byte loads gives (ms): | Pattern | Cached host memory (these buffers today) | BAR memory | Device memory | |---|---|---|---| | Coalesced | 5.1 | 0.142 | 0.154 | | Random | 94 | 2.3 | 2.7 | | Same 512 bytes per warp | 2.2 | 0.035 | 0.035 | ### How - Each of the buffers above takes `context.SnapshotProperties()`, so it lands in BAR memory under #9712's rules, and in host memory otherwise. - The CPU never reads them back. A data buffer placed in device memory keeps its words (`Allocation::deviceWords`) for the reuse compare in `MovedDispatchBuffers`, which compared the buffer's bytes. Writable region copies, which the write-back diffs, stay in host memory. Index copies the CPU scans for the highest index stay in host memory, as in #9712. ### Tested - Ghost of Tsushima (PPSA02225), GPU profile (`APS5_PROFILE_GPU=1 APS5_PROFILE_GPU_DRAWS=1`), local stack, last 30 windows of each run. The same placement covered #9712's buffers too, so this is the combined effect: | | Host memory (run 293) | BAR memory (run 294) | |---|---|---| | GPU time per present | 227 ms | 180 ms | | Instanced decal draws (variants 0x322 + 0x26x) | 88 ms | 48 ms | | Draw class | 146 ms | 96 ms | - That run lost the gain on the CPU: compares of device-memory buffers on the CPU (a snapshot refresh, which #9712 already covers; the data-buffer reuse compare, which this PR fixes) read uncached BAR memory at about 95 MB/s. With both fixed, the committer threads went back to normal load. - **Not a frame-rate win yet without the profile.** Same stack, 1200 s runs, fps median after 420 s: | Run | Placement | fps | GPU busy per present | |---|---|---|---| | 285-292 | host memory | 2.82-2.93 | 238-245 ms | | 296 | BAR, both compares fixed | 2.57 | 243 ms | | 297 | BAR, plus copied vertex inputs and CPU read overlays | 2.39 | 244 ms | The GPU profile serializes every draw, so it shows what each shader pays for its reads. Without it, GoT's frame isn't bound by those reads. I'm finding the CPU cost behind the lower rate with an in-process sampler of the driver threads, comparing host and BAR runs, and this stays a draft until that's explained. - Focused tests at `0918b0dc37`: `agc_bda_staging`, `agc_buffer_pool`, `agc_draw_inputs_copied`, `agc_draw_inputs_in_place`, `agc_draw_snapshot_cap`, `agc_draw_snapshot_epoch`, `agc_driver_bda_device`, `agc_driver_bda_span_reads`, `agc_driver_graphics`, `agc_driver_image_table`, `agc_driver_image_table_reuse`, `agc_driver_large_tracked_snapshot`, `agc_driver_partially_resident_snapshot`, `agc_driver_prepared_graphics`: | Where | Result | |---|---| | Linux, RTX 4070 Ti (BAR over the 12 GiB heap, so the placement is active) | 14 of 14 pass in each of 3 runs | | Windows 11 VM, GT 1030 (256 MiB BAR, so host memory as before) | 14 of 14 pass in each of 3 runs, base `8ff4baf534` and head | | Khronos validation, base #9712 `4e93e34d8e` vs head | not valid: the 1.4.363 layer this run pointed at was not installed, and these test programs don't print the loader's "not found" error, so it validated nothing (#17896). 14 of 14 tests pass on each side. A re-run with layer 1.4.341 and `VK_LOADER_DEBUG=layer` follows the rebase. | ### Checklist - [x] Based on current `main`; no other open PR implements the same functions (#9712 covers the snapshots, this PR the rest) - [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) - [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: #9712 - [x] Fixes: none - [x] Unblocks: none (a performance change; its measurements on PPSA02225 are under Tested) - [x] GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 615.71.09, Ubuntu 26.04.1 (in progress); NVIDIA GeForce GT 1030, Windows 11 VM (in progress) - [x] AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-11-21 05:20:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T05:20:04Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this change based on the prepared diff and the targeted source read; the author’s reported tests were not run during this review.

What I ran

  • Reviewed head d1c817f4f32816a19034b645b78bd3c514e73d96 using repo_read.py.
  • No commands or tests were run.

Results

Check Result Note
Diff and targeted source review passed Buffer placement and fallback paths inspected
Tests not run Results in the description are author reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • Did not read every changed file. Full text for GuestBufferMemory.cpp, ShaderResources.cpp, tests/Graphics.cpp, and tests/Recorder.cpp was excluded from the review bundle; targeted changed ranges in those files were read through repo_read.py. Other changed files were not individually read in full.
  • Did not run the focused tests or verify the reported GPU performance results.
  • The review bundle’s files.json was unavailable; the included/excluded file list was checked via the review folder listing.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6003063572 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15570#pullrequestreview-6003063572). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T05:20:04Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this change based on the prepared diff and the targeted source read; the author’s reported tests were not run during this review. ## What I ran - Reviewed head `d1c817f4f32816a19034b645b78bd3c514e73d96` using `repo_read.py`. - No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted source review | passed | Buffer placement and fallback paths inspected | | Tests | not run | Results in the description are author reported | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified - Did not read every changed file. Full text for `GuestBufferMemory.cpp`, `ShaderResources.cpp`, `tests/Graphics.cpp`, and `tests/Recorder.cpp` was excluded from the review bundle; targeted changed ranges in those files were read through `repo_read.py`. Other changed files were not individually read in full. - Did not run the focused tests or verify the reported GPU performance results. - The review bundle’s `files.json` was unavailable; the included/excluded file list was checked via the review folder listing. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 22:40:56 +00:00 (Migrated from github.com)

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

Review: COMMENTED


The trial merge onto c1601e56d5 conflicts in the BAR context, draw, recorder, and shader-resource paths. Reconcile placement with #9712 before rerunning the production bindings. The allocation-failure cases should verify that both the intended BAR placement and the host fallback still expose the shader data and table bytes. A successful allocation alone cannot show that the upload’s visibility and fallback survived the move.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6179884553 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15570#pullrequestreview-6179884553). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T22:40:56Z. **Review:** COMMENTED --- The trial merge onto `c1601e56d5` conflicts in the BAR context, draw, recorder, and shader-resource paths. Reconcile placement with #9712 before rerunning the production bindings. The allocation-failure cases should verify that both the intended BAR placement and the host fallback still expose the shader data and table bytes. A successful allocation alone cannot show that the upload’s visibility and fallback survived the move. 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/15570:upstream-pr/15570'
git switch 'upstream-pr/15570'

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