perf(agc): bind small, rarely read draw inputs in place where they are copied #20368
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20368"
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 talha-devp on 2026-11-15T02:55:11Z.
What
NVIDIA's Windows driver reads a host import of guest memory far slower than a buffer it allocated, so since
4a6069481fevery draw input is copied there (DrawInputsInPlaceUsable). A copy costs the draw committer a write collect, a buffer and a read, whatever its size. A sprite-heavy title pays that for every draw: Hades II (PPSA36082) draws about 1,170 times per frame in combat and is CPU-bound at about 26 FPS with 4 ms of GPU time per frame. In a committer sample of that scene,CopyDrawInputwas 15 % of the thread (GetWriteWatchcollects andBuffercreation).Where draw inputs are copied, this binds in place the ones the draw barely uses:
InPlaceDrawInputMaxReads).Indirect draws keep copying, since their counts are not known when the inputs are bound.
APS5_DRAW_INPUTS_IN_PLACE_BELOWsets the size, and 0 copies them all.APS5_DRAW_INPUTS_IN_PLACE=1andAPS5_NO_DRAW_INPUTS_IN_PLACE=1keep their meaning.Since #20578, a vertex range under a pending GPU write is also bound in place there (
APS5_NO_BEHIND_INPUTS_IN_PLACE). The two add up: a small, rarely read range is bound in place whether or not a write is pending, and a larger vertex range only when one is. Each switch turns off only its own part.Why the fetched span. Hades' vertex ranges are 64 KiB to over 16 MiB, because a ring buffer's base reaches up to the highest vertex, while each draw fetches a few vertices. The range size would exclude all of them.
Why the read limit. Reads, not bytes, are what cost the GPU on that driver. Astroneer (PPSA27623, CPU-bound at about 10 FPS) warm run, GPU ms per frame:
main)APS5_DRAW_INPUTS_IN_PLACE=1)These rows come from local diagnostic builds of the same machine and scene. About half of Astroneer's small inputs are read more than 512 times; none of Hades' is.
Changes:
DrawInputsInPlaceBelow(driver default)Context::drawInputsInPlaceBelowfetchedandreadsarguments ofInPlaceDrawInputagc_draw_inputs_in_place_driveragc_draw_inputs_copied: whole range, more fetched than the size, unknown reads, one read over the limit, and at the limitARCHITECTURE.mdand anENVIRONMENT.mdrowTested
Windows 10 22H2 (19045), RTX 4060 (NVIDIA 621.14), Ryzen 5 5600, MSYS2 UCRT64 GCC 16.2.0, Release.
Arms. Measured as
53e90579f9(this change onmain2f6d40f29b) againstfbad8a40d0(thatmain). Both have #20310 merged, which records and replays controller input; the Hades II scene is a replay of one recorded session. The branch was then rebased onto3ae84d01bd. Its conflicts were linesmainadded next to this change, arestartTableline beside the index-input call inprepareDrawInputsand ahostPointerImportfield beside the newVulkanDevicestate, and both sides are kept in each. See the GPU tests below.Hades II, combat (one replay each, 160 s, the same recording). Windows from 40 s.
APS5_PROFILE_DRAW[draw] pipelinedandworker_busy_pct.mainFPSmaincommittermainworkermainGPU ms/frametools/trace_digest.pyof the 55–65 s window. The traces' buffers filled, so their slice inventories are partial; the summary statistics are complete.main:306 presents, frame p50 33.4 / p90 38.3 / p99 74.4 / max 144.8 ms, GPU busy 3.8 ms per present379 presents, frame p50 26.4 / p90 30.9 / p99 35.7 / max 127.8 ms, GPU busy 3.6 ms per presentAstroneer, after the intro (two pairs, cold then warm run of 120 s each, the second pair in reverse order). Warm run medians from 30 s:
mainFPS / GPU msmainfirst)The FPS gap of pair 1 is not repeated by pair 2. The GPU time stays within about 1 ms.
trace_digestof the 70–80 s window, pair 2:main:91 presents, frame p50 98.9 / p90 110.0 / p99 957.9 / max 957.9 ms, GPU busy 40.2 ms per present93 presents, frame p50 97.2 / p90 106.9 / p99 969.3 / max 969.3 ms, GPU busy 40.9 ms per presentSummary lines (Hades main, Hades PR, Astroneer pair 2 PR, Astroneer pair 2 main)
APS5_DIAG_PAD_REPLAYinenvis set by my local wrapper; nothing in these builds reads it.The traces are kept locally and I can attach them.
GPU tests.
ctest -R agc_draw_inputs -VwithANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer(layer 1.4.363) coversagc_draw_inputs_in_place_driver,agc_draw_inputs_in_placeandagc_draw_inputs_copied.VUID-lines.b90068f9f5(built without #20310): 3 of 3 pass, the layer is inserted, and there are 0VUID-lines. The 21 other draw-input and snapshot tests ofagc_driver_recorder_tests(such asagc_draw_input_reuse,agc_owned_draw_inputs*andagc_unwatch_snapshot_scope*) also pass, with the layer inserted and 0VUID-lines.main45f6d379cc,2446139491:agc_draw_inputs_in_place_driver,agc_driver_recorder,agc_draw_inputs_in_placeandagc_draw_inputs_copiedpass, 4 of 4, with the layer inserted and 0VUID-lines. Thatmainhas #20578, which changed the same check inInPlaceDrawInput.agc_draw_inputs_copiedkeeps #20578's checks and also checks that a small vertex range free of pending writes is bound in place.main, with #20578: measured asb10ecb9916(this head onmain45f6d379cc) against4020742320(thatmain). Both have the #16053 revert so the title renders correctly. Same replay, default path, no profiler, roundsmain/PR/PR/main.APS5_PIPELINE_STATS).trace_digest, 55–65 s:main334 presents, frame p50 30.9 / p90 35.0 / p99 42.7 / max 161.3 ms, GPU busy 3.9 ms per present; this PR412 presents, frame p50 23.9 / p90 28.4 / p99 38.3 / max 164.2 ms, GPU busy 3.9 ms per present.With #20315. The draw-input part of #20315 copies, on the GPU, only the inputs behind a pending GPU write, so it does not cover these. Same Hades replay, median FPS and committer µs/draw from 40 s:
APS5_DRAW_PIPELINE=1 APS5_PIPELINE_DISPATCH=1 APS5_PIPELINE_DISPATCH_MISSES=1): 27.6 FPS alone, 35.1 FPS with this PRThe two merge with one conflict, where both add a line at the start of
prepareDrawInputs.Overlap. #19445 changes the same condition in
InPlaceDrawInput(large inputs in place); whichever merges second keeps both.tools/pr_overlap.py --branch feat/small-draw-inputs-in-placefinds no overlap among the pull requests it can compare. It exits failed-closed because 112 open PRs that conflict withmainshare these files. I searched their diffs forInPlaceDrawInput,drawInputsInPlace,DrawInputsInPlaceandAPS5_DRAW_INPUTS_IN_PLACE. Only #19445, #20315 (both above) and #9852 name them; #9852 is a test that readsDrawInputsInPlace()for a storage counter, which this does not change.python tools/check_conventions.py --base origin/main: all checks pass.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-15T03:53:53Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the notes below are optional.
What I ran
20de8205e9bc9b149770ca9c92e67b66baffcfceusingrepo_read.py.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-15T16:00:56Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
aabbdaffda3d470bf227a07a24746f19c8e42dc2using the prepared diff andrepo_read.py. I ran no build or tests.Results
includedFindings
Blocking
None.
Non-blocking
None.
Not verified
VulkanDevice.cppandRecorder.cppwere excluded from the review bundle for size; I read only the changed regions in those files throughrepo_read.py.description.mdandcommits.mdwere read. The bundle listed six files as included and two as excluded. Performance measurements in the PR description are author reported and were not independently verified. Build, tests, and console behavior were not run.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T01:13:09Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the review was limited to selected changed files, so approval is not justified.
What I ran
Reviewed head
b90068f9f5d24dd68300aa2fff2bb085422be663using the prepared diff and targeted source reads. No build or tests were run.Results
Findings
Blocking
None identified in the code read.
Non-blocking
None.
Not verified
Full text was not read for
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppandcore/libs/prx/libSceAgcDriver/tests/Recorder.cpp; only targeted ranges were inspected. Also not read:core/libs/prx/libSceAgcDriver/Graphics/include/Context.hpp,core/libs/prx/libSceAgcDriver/tests/DrawInputsInPlace.cpp,docs/dev/ARCHITECTURE.md, anddocs/dev/ENVIRONMENT.md. Build, automated tests, and reported performance measurements were not independently verified.To get this to a good state
Nothing is required. Optional: run the relevant build and tests on this head and verify the reported performance measurements.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T14:40:05Z.
Review: COMMENTED
Reviewed — comments
Changes are required before merge: verify and correct whether the small-input optimization applies to NVIDIA Windows draws when
APS5_DRAW_INPUTS_IN_PLACE=1is set.What I ran
Reviewed head
244613949165e9021ffa36d9ac31df93cc0de18busing the prepared diff andrepo_read.pytargeted reads. No tests were run.Results
Findings
Blocking
None verified.
Non-blocking
APS5_DRAW_INPUTS_IN_PLACE=1enables in-place binding on NVIDIA Windows, but the small-input default threshold remains 1024 bytes (VulkanDevice.cpp:1945-1947). The description says the optimization applies where inputs are copied; with the override set, inputs are already bound in place regardless of size. This may be intentional as the override explicitly opts into that behavior, but the interaction is not documented and makes the threshold ineffective. Clarify the override semantics or add coverage/documentation for this combination.Not verified
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppandcore/libs/prx/libSceAgcDriver/tests/Recorder.cppwas not available in the review folder; the changed hunks and relevant ranges were read throughrepo_read.py.Read changed lines in
core/libs/prx/libSceAgcDriver/Execution/include/DrawInputsInPlace.hpp,core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp,core/libs/prx/libSceAgcDriver/Graphics/include/Context.hpp,core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp,core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp,core/libs/prx/libSceAgcDriver/tests/DrawInputsInPlace.cpp,core/libs/prx/libSceAgcDriver/tests/Recorder.cpp,docs/dev/ARCHITECTURE.md, anddocs/dev/ENVIRONMENT.md.files.jsonwas unavailable; the review folder identifies the two changed files excluded from its full-text bundle.To get this to a good state
Nothing is required. Optional: document or test the threshold's interaction with
APS5_DRAW_INPUTS_IN_PLACE=1.