perf(agc): keep shaders off host imports on NVIDIA's Windows driver and cut per-draw CPU #20315
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20315"
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 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_hostand 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,vkCmdCopyBufferabout 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
DrawInputsInPlaceUsablealready does, and switch on for NVIDIA's Windows driver only; the other entries change the staging path wherever a driver stages:0a62088146copy 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.a3c8e26598bound the staging shadows of cached builds and re-stage refused regions.85007498b8hand a staged region's shadow over to the next dispatch in the batch (APS5_NO_STAGING_HANDOVER).426fbd20e2copy draw inputs behind a pending GPU write on the GPU (APS5_NO_DRAW_INPUT_GPU_COPY).d53f6d8ebashare one staging shadow per guest region and land only the copy-backs a dispatch reaches (APS5_NO_SHARED_STAGING_SHADOWS).bb736a43ecupload single-key storage images behind a pending GPU write on the GPU (APS5_NO_SINGLE_KEY_GPU_UPLOAD).ea00d54b8d,14968eb1a0serve 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,f2dbae986ereuse 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,abaae73388reuse a shape's remembered stages across moved user words, vertex tables included (APS5_NO_DRAW_SHAPE_USER_WORDS,APS5_NO_SHAPE_VERTEX_INPUT_STAGES).cce2baa353learn a draw's relocation where the draw finishes. WithAPS5_DRAW_PIPELINEthe 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,b1a8ed0533run 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:
f2b220a97bwrite a diagnostic line with one call and keep prints off the GPU mutex.57199a5356,d00992c576counters for pipelines built at draws and for the write-watch calls of collects (APS5_PIPELINE_STATS=2).b3691289efAPS5_UNPACED_FLIPS=1lifts the emulated vblank cap for benchmarks.4d31007572,719fda99e6,97bbe79aeba 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
mainhas not been measured, so read them as where things are, not as the required comparison.0f4538fa02APS5_DRAW_PIPELINE=1 APS5_PIPELINE_DISPATCH=1 APS5_PIPELINE_DISPATCH_MISSES=1; 49 to 68 uncappedGPU 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_replaycaptures 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=1gives the three-thread pipeline; eachAPS5_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 --checkandtools/debt_fold.py --checkpass.Not done yet: the validation-layer comparison with
main(no Khronos layer installed on this machine), the summary lines and traces ofmainand of this branch, any run on another vendor or on Linux or macOS, andtools/pr_overlap.py.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)Notes on the checklist. Based on
mainas of5cc140af09and merges cleanly withmaintoday; 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.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
97bbe79aeb1f29281472a64f6adb40afdfde2cfb, basemain. The draft was not merged-previewed.description.md,commits.md,manifest.json,files.json, and the house sections "Readable reviews", "Accuracy and evidence" and "Standard PR response format".VulkanDevice.cppswitch block, the draw-proof and write-watch hunks), plusGrepsearches over the whole diff for addedgetenvcalls, definitions and the kill-switch rows indocs/dev/ENVIRONMENT.md.Results
Findings
Blocking
None verified.
Non-blocking
docs/dev/ENVIRONMENT.md(diff.patch line 11768): theAPS5_NO_CHANGED_COPY_BACKrow namesGraphics/src/GuestBufferMemory.cpp. The only added read of that variable is incore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp:1932, and theAPS5_CHANGED_COPY_BACKrow already names that file. Smallest fix: change the location cell of theAPS5_NO_CHANGED_COPY_BACKrow toExecution/src/VulkanDevice.cpp.Sources
VulkanDevice.cppat the head, line 1932ChangedCopyBacks.hppat the headInputTwins.hppat the headNot verified
Graphics/src/GuestBufferMemory.cpp,Graphics/src/Recorder.cpp,Graphics/src/ShaderResources.cpp,Graphics/src/Texture.cpp,tests/Graphics.cpp, and the rest ofExecution/src/VulkanDevice.cpp. Their full text is not in the review folder, and I did not use the reader on them.DrawCache.cpp), shape user words (Draw.cpp), relocation learning (DrawRelocate.cpp), and the shared collect epoch (GuestMemory.cpp). Not audited.getenvcalls I found no switch for the staging-shadow bounding (a3c8e26598) or the relocation learning (cce2baa353). The unread hunks might still gate them.ClearInputTwinsandInputTwinBuffersare declared and defined in the diff. Nothing was compiled.To get this to a good state
Nothing is required.
Optional:
APS5_NO_CHANGED_COPY_BACKlocation cell indocs/dev/ENVIRONMENT.md.Pull request closed