perf(agc): keep shaders off host imports on NVIDIA's Windows driver and cut per-draw CPU #20315

Closed
simnJS wants to merge 22 commits from upstream-pr/20315 into main
simnJS commented 2026-11-15 01:09:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simnJS on 2026-11-15T01:09:39Z.


What

Draft, opened early so the direction is visible and others can try it. It is testable today and will keep moving; the follow-up steps listed at the end will come as separate pull requests, and I am happy to split this one into a series in whatever order suits review.

The problem. A PS5 title's GPU reads and writes the game's memory directly. AnyPS5 imports that memory with VK_EXT_external_memory_host and lets shaders use it in place. On NVIDIA's proprietary Windows driver, shader access to an imported host range is very slow while a buffer copy to or from the same range is fast (measured on an RTX 4080 SUPER: shader stores into an import about 1.5 GiB/s, shader reads 35 to 50 us per MiB, vkCmdCopyBuffer about 19 GiB/s). Once that is out of the way, the frame is bound by the driver's own CPU cost per draw, not by the GPU.

What this branch does, 22 commits, each mechanism behind its own kill switch documented in docs/dev/ENVIRONMENT.md:

Keeping shaders off host imports. The copy-back choice and the input twins are decided per driver, as DrawInputsInPlaceUsable already does, and switch on for NVIDIA's Windows driver only; the other entries change the staging path wherever a driver stages:

  • 0a62088146 copy staged regions back with a buffer copy on NVIDIA's Windows driver (APS5_CHANGED_COPY_BACK / APS5_NO_CHANGED_COPY_BACK). Still needed after #15792: forcing the compute copy-back on this branch drops the scene below to 7 fps with 130 ms of GPU time per frame.
  • a3c8e26598 bound the staging shadows of cached builds and re-stage refused regions.
  • 85007498b8 hand a staged region's shadow over to the next dispatch in the batch (APS5_NO_STAGING_HANDOVER).
  • 426fbd20e2 copy draw inputs behind a pending GPU write on the GPU (APS5_NO_DRAW_INPUT_GPU_COPY).
  • d53f6d8eba share one staging shadow per guest region and land only the copy-backs a dispatch reaches (APS5_NO_SHARED_STAGING_SHADOWS).
  • bb736a43ec upload single-key storage images behind a pending GPU write on the GPU (APS5_NO_SINGLE_KEY_GPU_UPLOAD).
  • ea00d54b8d, 14968eb1a0 serve read-only dispatch inputs from device-local twins of their host imports, refreshed only when the write tracker says the range changed (APS5_NO_INPUT_TWINS).

Driver CPU per draw (all drivers):

  • 105998d546, f2dbae986e reuse a draw's resource and target proofs while nothing they read moved (APS5_NO_DRAW_PROOFS, APS5_VERIFY_DRAW_PROOFS), and read the clock only when profiling.
  • 83488a6232, abaae73388 reuse a shape's remembered stages across moved user words, vertex tables included (APS5_NO_DRAW_SHAPE_USER_WORDS, APS5_NO_SHAPE_VERTEX_INPUT_STAGES).
  • cce2baa353 learn a draw's relocation where the draw finishes. With APS5_DRAW_PIPELINE the queue worker drained the finisher before every draw that followed a cache miss, which serialised the three threads; a third of the worker's time was that drain.
  • 560761e833, b1a8ed0533 run pipelined work in the collect epoch its queue worker held and walk a recipe draw's surfaces on the finisher (APS5_NO_SHARED_COLLECT_EPOCH, APS5_NO_FINISHER_PRECOLLECT). Measured as neutral on their own so far; kept as groundwork.

Diagnostics and tooling:

  • f2b220a97b write a diagnostic line with one call and keep prints off the GPU mutex.
  • 57199a5356, d00992c576 counters for pipelines built at draws and for the write-watch calls of collects (APS5_PIPELINE_STATS=2).
  • b3691289ef APS5_UNPACED_FLIPS=1 lifts the emulated vblank cap for benchmarks.
  • 4d31007572, 719fda99e6, 97bbe79aeb a pipeline cache test and the debt fragments.

Where it stands. Same machine throughout: NVIDIA GeForce RTX 4080 SUPER, driver 621.01, Windows 11 (10.0.26300), Ryzen 9 7950X3D, 1920x1080. These figures were taken at earlier points of this same stack, before its last rebase; the summary lines and traces in the form the Performance report asks for are not attached yet and current main has not been measured, so read them as where things are, not as the required comparison.

Title, scene Before This stack
Card Shop Simulator (PPSA36301), street after New Game about 6 fps, then 1 to 2, on 0f4538fa02 41 fps default; 52 to 58 average with APS5_DRAW_PIPELINE=1 APS5_PIPELINE_DISPATCH=1 APS5_PIPELINE_DISPATCH_MISSES=1; 49 to 68 uncapped
Subnautica (PPSA02453), Creative, near the lifepod not measured 23 to 24 fps default, about 29 with the pipeline switches
Balatro (PPSA21402) not measured locked 59.9; 250 to 475 uncapped (with an earlier form of the unpaced switch)

GPU busy time is 9 to 12 ms per frame on the first title and 16 to 18 ms on Subnautica, so both are CPU-bound in the driver: on the first title, about 18 to 20 us of CPU per draw in each of the three pipeline threads. The draw count of the first scene varies from 400 to 830 between launches, which is why the fps ranges are wide; I now compare per-draw cost on agc_frame_replay captures instead.

What comes next (in progress, as separate pull requests): per-resource versions in place of the global proof stamp, write tracking by page protection for memory that stays clean, retained draw sites so a draw seen before only pushes what changed, and keeping staged surfaces in device memory between a retile and the dispatch that reads them.

How to try it. Convert a title as usual with this branch's libraries. APS5_DRAW_PIPELINE=1 APS5_PIPELINE_DISPATCH=1 APS5_PIPELINE_DISPATCH_MISSES=1 gives the three-thread pipeline; each APS5_NO_... switch above turns one mechanism off to isolate a regression. Reports from AMD, Intel and Linux are especially welcome: apart from the two driver-gated mechanisms, this touches code every driver runs, and none of it has run anywhere but the machine above.

Tested

Windows 11, NVIDIA GeForce RTX 4080 SUPER (621.01). The three titles above were played from their menus into a scene and checked by screenshot; rendering looks correct in each. Focused AGC and VideoOut tests on this branch: 245 run with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, 244 passed, 1 skipped (agc_driver_host_write_shadowed_unit, Linux only). tools/check_conventions.py --base origin/main, tools/env_reference.py --check and tools/debt_fold.py --check pass.

Not done yet: the validation-layer comparison with main (no Khronos layer installed on this machine), the summary lines and traces of main and of this branch, any run on another vendor or on Linux or macOS, and tools/pr_overlap.py.

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: NVIDIA GeForce RTX 4080 SUPER, driver 621.01, Windows 11 (the validation-layer comparison is still to do)
  • AI-assisted: yes

Notes on the checklist. Based on main as of 5cc140af09 and merges cleanly with main today; my own #18388 and #18390 are in the same area and I will close or rebase them against this. "One topic" is left unticked on purpose: this is a stack, opened as one draft so it can be measured as a whole, and it can be split. AI-assisted: written with Claude. Mythos 5.2 did the analysis, the orchestration and the most critical code, Opus agents the rest; it is still working on the next steps. I am responsible for every line.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5318160168 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20315). Originally posted by [simnJS](https://github.com/simnJS) on 2026-11-15T01:09:39Z. --- ### What Draft, opened early so the direction is visible and others can try it. It is testable today and will keep moving; the follow-up steps listed at the end will come as separate pull requests, and I am happy to split this one into a series in whatever order suits review. **The problem.** A PS5 title's GPU reads and writes the game's memory directly. AnyPS5 imports that memory with `VK_EXT_external_memory_host` and lets shaders use it in place. On NVIDIA's proprietary Windows driver, shader access to an imported host range is very slow while a buffer copy to or from the same range is fast (measured on an RTX 4080 SUPER: shader stores into an import about 1.5 GiB/s, shader reads 35 to 50 us per MiB, `vkCmdCopyBuffer` about 19 GiB/s). Once that is out of the way, the frame is bound by the driver's own CPU cost per draw, not by the GPU. **What this branch does**, 22 commits, each mechanism behind its own kill switch documented in `docs/dev/ENVIRONMENT.md`: Keeping shaders off host imports. The copy-back choice and the input twins are decided per driver, as `DrawInputsInPlaceUsable` already does, and switch on for NVIDIA's Windows driver only; the other entries change the staging path wherever a driver stages: - `0a62088146` copy staged regions back with a buffer copy on NVIDIA's Windows driver (`APS5_CHANGED_COPY_BACK` / `APS5_NO_CHANGED_COPY_BACK`). Still needed after #15792: forcing the compute copy-back on this branch drops the scene below to 7 fps with 130 ms of GPU time per frame. - `a3c8e26598` bound the staging shadows of cached builds and re-stage refused regions. - `85007498b8` hand a staged region's shadow over to the next dispatch in the batch (`APS5_NO_STAGING_HANDOVER`). - `426fbd20e2` copy draw inputs behind a pending GPU write on the GPU (`APS5_NO_DRAW_INPUT_GPU_COPY`). - `d53f6d8eba` share one staging shadow per guest region and land only the copy-backs a dispatch reaches (`APS5_NO_SHARED_STAGING_SHADOWS`). - `bb736a43ec` upload single-key storage images behind a pending GPU write on the GPU (`APS5_NO_SINGLE_KEY_GPU_UPLOAD`). - `ea00d54b8d`, `14968eb1a0` serve read-only dispatch inputs from device-local twins of their host imports, refreshed only when the write tracker says the range changed (`APS5_NO_INPUT_TWINS`). Driver CPU per draw (all drivers): - `105998d546`, `f2dbae986e` reuse a draw's resource and target proofs while nothing they read moved (`APS5_NO_DRAW_PROOFS`, `APS5_VERIFY_DRAW_PROOFS`), and read the clock only when profiling. - `83488a6232`, `abaae73388` reuse a shape's remembered stages across moved user words, vertex tables included (`APS5_NO_DRAW_SHAPE_USER_WORDS`, `APS5_NO_SHAPE_VERTEX_INPUT_STAGES`). - `cce2baa353` learn a draw's relocation where the draw finishes. With `APS5_DRAW_PIPELINE` the queue worker drained the finisher before every draw that followed a cache miss, which serialised the three threads; a third of the worker's time was that drain. - `560761e833`, `b1a8ed0533` run pipelined work in the collect epoch its queue worker held and walk a recipe draw's surfaces on the finisher (`APS5_NO_SHARED_COLLECT_EPOCH`, `APS5_NO_FINISHER_PRECOLLECT`). Measured as neutral on their own so far; kept as groundwork. Diagnostics and tooling: - `f2b220a97b` write a diagnostic line with one call and keep prints off the GPU mutex. - `57199a5356`, `d00992c576` counters for pipelines built at draws and for the write-watch calls of collects (`APS5_PIPELINE_STATS=2`). - `b3691289ef` `APS5_UNPACED_FLIPS=1` lifts the emulated vblank cap for benchmarks. - `4d31007572`, `719fda99e6`, `97bbe79aeb` a pipeline cache test and the debt fragments. **Where it stands.** Same machine throughout: NVIDIA GeForce RTX 4080 SUPER, driver 621.01, Windows 11 (10.0.26300), Ryzen 9 7950X3D, 1920x1080. These figures were taken at earlier points of this same stack, before its last rebase; the summary lines and traces in the form the Performance report asks for are not attached yet and current `main` has not been measured, so read them as where things are, not as the required comparison. | Title, scene | Before | This stack | |---|---|---| | Card Shop Simulator (PPSA36301), street after New Game | about 6 fps, then 1 to 2, on `0f4538fa02` | 41 fps default; 52 to 58 average with `APS5_DRAW_PIPELINE=1 APS5_PIPELINE_DISPATCH=1 APS5_PIPELINE_DISPATCH_MISSES=1`; 49 to 68 uncapped | | Subnautica (PPSA02453), Creative, near the lifepod | not measured | 23 to 24 fps default, about 29 with the pipeline switches | | Balatro (PPSA21402) | not measured | locked 59.9; 250 to 475 uncapped (with an earlier form of the unpaced switch) | GPU busy time is 9 to 12 ms per frame on the first title and 16 to 18 ms on Subnautica, so both are CPU-bound in the driver: on the first title, about 18 to 20 us of CPU per draw in each of the three pipeline threads. The draw count of the first scene varies from 400 to 830 between launches, which is why the fps ranges are wide; I now compare per-draw cost on `agc_frame_replay` captures instead. **What comes next** (in progress, as separate pull requests): per-resource versions in place of the global proof stamp, write tracking by page protection for memory that stays clean, retained draw sites so a draw seen before only pushes what changed, and keeping staged surfaces in device memory between a retile and the dispatch that reads them. **How to try it.** Convert a title as usual with this branch's libraries. `APS5_DRAW_PIPELINE=1 APS5_PIPELINE_DISPATCH=1 APS5_PIPELINE_DISPATCH_MISSES=1` gives the three-thread pipeline; each `APS5_NO_...` switch above turns one mechanism off to isolate a regression. Reports from AMD, Intel and Linux are especially welcome: apart from the two driver-gated mechanisms, this touches code every driver runs, and none of it has run anywhere but the machine above. ### Tested Windows 11, NVIDIA GeForce RTX 4080 SUPER (621.01). The three titles above were played from their menus into a scene and checked by screenshot; rendering looks correct in each. Focused AGC and VideoOut tests on this branch: 245 run with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`, 244 passed, 1 skipped (`agc_driver_host_write_shadowed_unit`, Linux only). `tools/check_conventions.py --base origin/main`, `tools/env_reference.py --check` and `tools/debt_fold.py --check` pass. Not done yet: the validation-layer comparison with `main` (no Khronos layer installed on this machine), the summary lines and traces of `main` and of this branch, any run on another vendor or on Linux or macOS, and `tools/pr_overlap.py`. ### 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 - [ ] 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 - [x] Unblocks: none - [ ] GPUs tested: NVIDIA GeForce RTX 4080 SUPER, driver 621.01, Windows 11 (the validation-layer comparison is still to do) - [x] AI-assisted: yes Notes on the checklist. Based on `main` as of 5cc140af09 and merges cleanly with `main` today; my own #18388 and #18390 are in the same area and I will close or rebase them against this. "One topic" is left unticked on purpose: this is a stack, opened as one draft so it can be measured as a whole, and it can be split. AI-assisted: written with Claude. Mythos 5.2 did the analysis, the orchestration and the most critical code, Opus agents the rest; it is still working on the next steps. I am responsible for every line.
MarcZX10 commented 2026-11-17 04:12:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T04:12:01Z.

Review: COMMENTED


Partial review of the AGC staging and draw-cache stack — no blocking findings in what was read

Nothing blocks this in the parts I read; the points below are optional, and most of the 11,979-line diff is not verified.

What I ran

  • Head 97bbe79aeb1f29281472a64f6adb40afdfde2cfb, base main. The draft was not merged-previewed.
  • Read the console's description.md, commits.md, manifest.json, files.json, and the house sections "Readable reviews", "Accuracy and evidence" and "Standard PR response format".
  • Read about 200 of the 11,979 diff lines (the two NVIDIA-gated headers, the VulkanDevice.cpp switch block, the draw-proof and write-watch hunks), plus Grep searches over the whole diff for added getenv calls, definitions and the kill-switch rows in docs/dev/ENVIRONMENT.md.
  • No reader calls, no build, no tests, no writes to the repository.

Results

Check Result Note
Per-driver gating (copy-back, input twins) passed Matches the description for NVIDIA's Windows driver
Kill-switch rows vs code failed One row names the wrong file (see Findings)
Build not run No build in this review
Author's focused AGC and VideoOut tests not run Author-reported only: 245 run, 244 passed, 1 skipped
Repository check scripts not run Author-reported only
Full text of changed files not run Six files are not in the review folder; no reader calls

Findings

Blocking

None verified.

Non-blocking

  • docs/dev/ENVIRONMENT.md (diff.patch line 11768): the APS5_NO_CHANGED_COPY_BACK row names Graphics/src/GuestBufferMemory.cpp. The only added read of that variable is in core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp:1932, and the APS5_CHANGED_COPY_BACK row already names that file. Smallest fix: change the location cell of the APS5_NO_CHANGED_COPY_BACK row to Execution/src/VulkanDevice.cpp.

Sources

Not verified

  • Most of the diff: about 200 of 11,979 lines were read by hunk. Not read: Graphics/src/GuestBufferMemory.cpp, Graphics/src/Recorder.cpp, Graphics/src/ShaderResources.cpp, Graphics/src/Texture.cpp, tests/Graphics.cpp, and the rest of Execution/src/VulkanDevice.cpp. Their full text is not in the review folder, and I did not use the reader on them.
  • Behaviour on every driver, including the default path: draw proofs (DrawCache.cpp), shape user words (Draw.cpp), relocation learning (DrawRelocate.cpp), and the shared collect epoch (GuestMemory.cpp). Not audited.
  • Concurrency in the three pipeline threads, the collect epochs and the write-watch counting. Not verified.
  • The description says each mechanism has its own kill switch. In the added getenv calls I found no switch for the staging-shadow bounding (a3c8e26598) or the relocation learning (cce2baa353). The unread hunks might still gate them.
  • The new calls ClearInputTwins and InputTwinBuffers are declared and defined in the diff. Nothing was compiled.
  • Author-reported numbers (fps, per-draw CPU, test counts) and the Linux, AMD, Intel and macOS behaviour. Not run here.

To get this to a good state

Nothing is required.

Optional:

  • Fix the APS5_NO_CHANGED_COPY_BACK location cell in docs/dev/ENVIRONMENT.md.
  • Name the mechanisms without a kill switch in the description, or add one.
  • For a formal decision, the files in the review folder and the unread hunks above need a full review.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5932702614 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20315#pullrequestreview-5932702614). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-17T04:12:01Z. **Review:** COMMENTED --- # Partial review of the AGC staging and draw-cache stack — no blocking findings in what was read Nothing blocks this in the parts I read; the points below are optional, and most of the 11,979-line diff is not verified. ## What I ran - Head `97bbe79aeb1f29281472a64f6adb40afdfde2cfb`, base `main`. The draft was not merged-previewed. - Read the console's `description.md`, `commits.md`, `manifest.json`, `files.json`, and the house sections "Readable reviews", "Accuracy and evidence" and "Standard PR response format". - Read about 200 of the 11,979 diff lines (the two NVIDIA-gated headers, the `VulkanDevice.cpp` switch block, the draw-proof and write-watch hunks), plus `Grep` searches over the whole diff for added `getenv` calls, definitions and the kill-switch rows in `docs/dev/ENVIRONMENT.md`. - No reader calls, no build, no tests, no writes to the repository. ## Results | Check | Result | Note | |---|---|---| | Per-driver gating (copy-back, input twins) | passed | Matches the description for NVIDIA's Windows driver | | Kill-switch rows vs code | failed | One row names the wrong file (see Findings) | | Build | not run | No build in this review | | Author's focused AGC and VideoOut tests | not run | Author-reported only: 245 run, 244 passed, 1 skipped | | Repository check scripts | not run | Author-reported only | | Full text of changed files | not run | Six files are not in the review folder; no reader calls | ## Findings **Blocking** None verified. **Non-blocking** - `docs/dev/ENVIRONMENT.md` (diff.patch line 11768): the `APS5_NO_CHANGED_COPY_BACK` row names `Graphics/src/GuestBufferMemory.cpp`. The only added read of that variable is in `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp:1932`, and the `APS5_CHANGED_COPY_BACK` row already names that file. Smallest fix: change the location cell of the `APS5_NO_CHANGED_COPY_BACK` row to `Execution/src/VulkanDevice.cpp`. ## Sources - [`VulkanDevice.cpp` at the head, line 1932](https://github.com/boykopovar/AnyPS5/blob/97bbe79aeb1f29281472a64f6adb40afdfde2cfb/core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp#L1932) - [`ChangedCopyBacks.hpp` at the head](https://github.com/boykopovar/AnyPS5/blob/97bbe79aeb1f29281472a64f6adb40afdfde2cfb/core/libs/prx/libSceAgcDriver/Execution/include/ChangedCopyBacks.hpp) - [`InputTwins.hpp` at the head](https://github.com/boykopovar/AnyPS5/blob/97bbe79aeb1f29281472a64f6adb40afdfde2cfb/core/libs/prx/libSceAgcDriver/Execution/include/InputTwins.hpp) ## Not verified - Most of the diff: about 200 of 11,979 lines were read by hunk. Not read: `Graphics/src/GuestBufferMemory.cpp`, `Graphics/src/Recorder.cpp`, `Graphics/src/ShaderResources.cpp`, `Graphics/src/Texture.cpp`, `tests/Graphics.cpp`, and the rest of `Execution/src/VulkanDevice.cpp`. Their full text is not in the review folder, and I did not use the reader on them. - Behaviour on every driver, including the default path: draw proofs (`DrawCache.cpp`), shape user words (`Draw.cpp`), relocation learning (`DrawRelocate.cpp`), and the shared collect epoch (`GuestMemory.cpp`). Not audited. - Concurrency in the three pipeline threads, the collect epochs and the write-watch counting. Not verified. - The description says each mechanism has its own kill switch. In the added `getenv` calls I found no switch for the staging-shadow bounding (`a3c8e26598`) or the relocation learning (`cce2baa353`). The unread hunks might still gate them. - The new calls `ClearInputTwins` and `InputTwinBuffers` are declared and defined in the diff. Nothing was compiled. - Author-reported numbers (fps, per-draw CPU, test counts) and the Linux, AMD, Intel and macOS behaviour. Not run here. ## To get this to a good state Nothing is required. Optional: - Fix the `APS5_NO_CHANGED_COPY_BACK` location cell in `docs/dev/ENVIRONMENT.md`. - Name the mechanisms without a kill switch in the description, or add one. - For a formal decision, the files in the review folder and the unread hunks above need a full review.

Pull request closed

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!20315
No description provided.