fix(agc): give a vertex copy headroom when its range keeps growing #19100
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19100"
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 videogamer10293 on 2026-11-12T19:27:12Z.
What
A draw whose vertex range starts at the same address as a kept copy, but reaches a little further, cannot reuse that copy. A vertex lookup takes only a kept copy at least as long as the read (Recorder.cpp#L3700). So draws that walk through one large vertex buffer in consecutive windows copy the whole range again on every draw. Where vertex input is copied rather than read in place, each copy is a new host buffer, and a burst of them can push the host heap over its budget. NVIDIA's Windows driver is such a case:
DrawInputsInPlaceUsableis false for it, so only inputs of up to 1024 bytes with few reads are bound in place.With this change, when a vertex copy misses only because the kept copy at the same address is unchanged but shorter, the new copy is made longer than the read. The next draws in the sequence then reuse it.
Recorder::ShorterDrawSnapshotKepttells whether such a copy is kept. It must have the same address and use, be shorter, come from the current allocation registry, not be an owned-input copy, and be unchanged since it was made, from where its bytes start (a copy can start past its address, #9875).CopyDrawInputtakes agrowLimit. It grows only vertex copies, only past such a kept copy, by at most a quarter of the read, never past the limit, and never pastDrawInputBudget(a longer copy would not be kept). The grown range is collected with the read, so the kept copy's generation covers all of it.Recorder::GuestWritesPendingIn), no storage image with pending results, and no unpublished unit shadow. They must not overlap a resident depth surface or host-only samples (HostOnlySampleRanges). These checks are queries only. The read itself still goes throughGuestMemory::Read; the extra bytes are then copied directly, without its flush and read guard.VertexDescriptorEnd), using the smallest end when a copy merges several attributes. The limit is cut at any color, depth, stencil or HTILE address past the read. Indirect draws and index copies do not grow.Why a quarter. It bounds the extra bytes when the descriptor is much larger than the read. In the earlier Sky Garden runs below, the limit, not the quarter, capped the growth: the second copy grew by about 9 %, which was enough for 22 copies of 32 MiB or more to become 3. A range that grows by more than its headroom on every draw gets copies longer than on
mainthat are never reused. That costs memory and gains nothing.This PR claims no speed change. PPSA21564 (ASTRO BOT) stopped on these copies in Sky Garden on Windows with NVIDIA (traced below); two more levels stop on
mainon a full host heap and reach the cap with this change.Tested
Windows only: Windows 10 Pro 10.0.19045, Ryzen 5 7600X, 31893 MiB of RAM, RTX 5070 Ti, NVIDIA 621.24, WinLibs GCC 15.2.0 (UCRT), Release,
BUILD_TESTING=ON. Heade78ae2ee05onmain3c07e1d05e; every result below is from this head and thatmain. Both build trees carried the same local test-only edit, not committed: a Windows_putenv_sinUploadCacheReadOnlyFlush.cpp, which does not build on Windows on thismain(#19899, #22373).Others ran older heads: relativespace2K (RX 6800 XT) and JJenkx (RX 6700 XT) on Windows, and blawesom on Linux with RADV (comment). In blawesom's run the unit-shadow check skipped itself, since its block was not imported and watched; it ran here.
mainhas since moved toe35c90cfe3. Among this PR's files it changed onlytests/Graphics.cppandtests/Recorder.cpp, and the branch merges with it without a conflict. I did not rerun the tests on that merge.Tests
tools/select_tests.pywith the 19 files that differed fromupstream/mainat the time (the 9 of this PR and 10 from a newermain) selects 6171 tests; the 9 alone select 3245 of them. Withtools/select_tests.py ctest build, the same 3 fail on both sides:agc_driver_stencil_plane_memory,agc_driver_msaa_dcc_unwatchandagc_driver_bda_device. Onmain,agc_driver_image_table_packed_guardsalso failed once; it passed 3 of 3 runs alone on each side. After every build, the staged.prxcopies next to the test executables matched the rebuilt libraries.growingVertexCopyTests, inagc_driver_recorder, uses a real device and a write-watched block. It checks that:grownVertexCopyShadowTests, inagc_driver_recorder: a copy whose headroom ends before a fresh unit shadow grows; one whose headroom reaches it does not.validationTests, inagc_graphics_profile_draw, checks without a device:VertexDescriptorEnd;GrownVertexCopyBytes(the quarter, the limit, theDrawInputBudgetcap);VertexCopyGrowEnd(color, depth, stencil and HTILE cuts).VertexPlanScratchEmptiesEveryList, inagc_exclusive_scratch, covers the two new plan lists.agc_driver_recorder,agc_graphics_profile_draworagc_exclusive_scratch; the unchanged head passes before and after. Two pass:prepareDrawInputspassing no limit. No unit test draws through that call; the title runs below do.ShorterDrawSnapshotKept. The cut looks only at the address where a target starts; a target that starts below the read's end and reaches into the headroom is left to the pending-write and resident-depth checks.agc_driver_recorderunderctest -VwithVK_ADD_LAYER_PATHset to the layer,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_LAYERS_DISABLE=~implicit~ VK_LOADER_DEBUG=layerand the Khronos Windows layer 1.4.368. On both sides it passes, the loader inserts the layer and no implicit layer: Neither log haswas not found but was requested by env var VK_INSTANCE_LAYERSor aVUID-line. The same settings over the 25 tests matching^(agc_driver_recorder|agc_draw_inputs_.*|agc_owned_draw_inputs.*|agc_driver_vertex.*|agc_driver_draw_offset.*|agc_draw_snapshot.*)$give the same on both sides: noVUID-line, 24 pass andagc_driver_vertex_elected_atomic_maxskips. The loader inserts the layer in 22 of them;agc_driver_vertex_table_read_order,agc_driver_vertex_table_read_order_counts_offandagc_draw_inputs_in_place_driverprint no loader line. The other new checks run without a device:agc_graphics_profile_drawusesMockVulkan.Title. PPSA21564 01.007.000, no input, muted, 300 s cap, 2 runs per level and side. One run dir and relinked executable from
main3c07e1d05e; the sides differ only inlibSceAgcDriver.prx. Runs alternatemain, PR,main, PR, and share one shader cache, which was empty before the firsthero_ape_escaperun. No local print lines. The same two levels behaved the same on an older head, with pad input (comment).main3c07e1d05ee78ae2ee05hero_ape_escapepath_maker_mana_treeTimes are the launcher's wall time. Every
mainrun ends on a failed buffer allocation in heap 1, thenterminate calledon aMemoryAllocationError. The firsthero_ape_escaperun:At every stop, heap 1 (the host heap, 15947 MiB here) was over its budget of 15084 to 15085 MiB. No run of this PR printed a failed allocation. I did not trace the copies in these two levels; the A/B shows only that the stop goes away with this change. Not tested with more RAM.
Earlier runs: Sky Garden, on older heads
PPSA21564 01.007.000,
-lvl underwater_aerial_garden, no input, 3840x2160, 600 s cap, shader cache warmed by one discarded run. B1 ismain+ #18356 (4a69efb803). Every arm carried a local print line, not committed, that logs each draw input copy of 32 MiB or more. "End" is the launcher's wall time.maind4d6b64710d4d6b64710067d9cb616, a local commit, not pushed)d91bb06af9d91bb06af9d91bb06af9d91bb06af9d91bb06af9maind91bb06af9main+ earlier versionThe "earlier version" rows are
77f76c2429, a local commit, not pushed: no unit-shadow check, a multisample query in place ofHostOnlySampleRanges, and the whole range read throughGuestMemory::Read. Themain+ earlier version run made no copy of 32 MiB or more, so that pair shows nothing either way. Local print lines onmain3c8b74996f+ #18356 showed that all 23 copies of 32 MiB or more start at0x1078e68ca0and grow from 76 to 133 MiB, about 2.9 GiB in all, within 1.48 s before the stop. In a later run they came from ordinary draws, and every lookup after the first found the previous copy kept, from the current registry and unchanged, but shorter.Overlap.
tools/pr_overlap.py --branchon this head finds three open pull requests that change the same lines, each for another purpose: #9915 (vertex out-of-bounds range checks), #19620 (unbounded indirect vertex inputs) and #21923 (queue worker lock contention). None gives a copy headroom; whichever merges second can rebase. It could not compare 65 others, which conflict withmain. A search of their diffs for the copy, keep and lookup functions and the vertex copy plan finds three; the diffs of #7642 and #9508 (308 and 366 files) could not be fetched. #9712 and #15570 change the line inCopyDrawInputthat creates the copy's buffer, and the draft #20315 adds a GPU copy beforeCopyDrawInputfor ranges with a pending GPU write.#16879 replaces a kept snapshot's
registryGeneration, whichShorterDrawSnapshotKeptreads, with aforgetSerial; winstrex agreed that it goes first, and this PR takes that change when it rebases onto it.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T19:51:57Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
d5257453547598b651ce41f02b7ca4b5e4caaf03(PR 19100 againstmain). Read the title and description, the commit, the manifest, and the full diff.Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp:2018— The cut at render-target, depth, stencil and HTILE addresses (lines 2018–2024) has no test. The author's mutation checks say the same. If the cut were dropped, the two new tests would still pass. TheDrawInputBudgetcap (Draw.cpp:1485), the unit-shadow check (Draw.cpp:1453) and the tail copy (Draw.cpp:1496) are untested too.Sources
CopyDrawInputgrowth stepVertexDescriptorEndNot verified
agc_driver_recorderandagc_graphics_profile_drawon the rebased headd525745354, and the ctest run of 2732 passes) are author reports, not runs by this review.Draw.cpp:1496skips theGuestMemory::Readguard. Its safety depends on the generation collected atDraw.cpp:1486before the copy. I did not check the write-watch timing.Draw.cpp:2016covers only addresses at or above the read end. A depth, stencil or HTILE surface that starts lower and reaches into the headroom relies onResidentDepthGuardOverlaps_nid_no_patchand the pending-write checks. Not verified.tests/Graphics.cppandtests/Recorder.cppwere read only as diff hunks; their full text is too large for the review folder and was not read.To get this to a good state
Nothing is required. The test-coverage point in Findings is optional.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-13T23:00:39Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the source inspected supports the copy headroom guards, and the author reports focused tests and validation on this head.
What I ran
Read the prepared diff and source context at head
20d136c3379fd699fd01d8996e94dc3798748e02. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
tests/Graphics.cppandtests/Recorder.cppwere excluded from the prepared review folder because they were too large. Their diff hunks were read, but their surrounding test code was not. No build, tests, or title run was performed by me. The description reports focused tests, mutation checks, and Vulkan validation on this head; those results were not independently verified.description.md,commits.md,manifest.json,diff.patch,Draw.hpp,Recorder.hpp,VertexInput.hpp,Draw.cpp, andRecorder.cppwere read; no changed files were omitted from the manifest.To get this to a good state
Nothing is required. Optional: add or retain call-site coverage for the render-target cut and budget cap, which the description says are not exercised by tests at the draw call.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T04:50:06Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change based on the code inspected; approval is not justified because two changed test files were not fully read and no checks were run.
What I ran
e78ae2ee05b9de7e0146afcb5e14af11aa1412abusing the pinnedrepo_read.pyreader.Results
Findings
Blocking
None identified in the code inspected.
Non-blocking
None.
Not verified
tests/Graphics.cppandtests/Recorder.cppwere excluded from the review folder; only relevant ranges were read through the reader. The remaining portions of those files were not reviewed.mainhead mentioned in the description.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-22T12:58:53Z.
Review: APPROVED
Windows check of head
e78ae2ee05with GCC 16, on an NVIDIA GPU and on an AMD one. The AMD runs in the thread are of older heads. Merged ontomaine493612311(clean merge).Setup: Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (
x86_64-ucrt-posix-seh, r3), Release full build, run from PowerShell withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. GPUs, each picked withANYPS5_GPU: NVIDIA GeForce RTX 5070 Ti (621.01) and the Ryzen 7 7700X's integrated AMD Radeon (1002:164e, Adrenalin 26.10.2). This was built together with #24906, which touches other files.agc_driver_recorder(withgrowingVertexCopyTests),agc_driver_graphicsandagc_exclusive_scratch: all pass on both GPUs, onmainand with this PR, in 3 of 3 runs, with noVUID-lines.GrownVertexCopyBytesnever growing (if (growLimit <= bytes) return bytes;→return bytes;),agc_driver_recorderfails on the Radeon with "a vertex copy past an unchanged shorter one took no headroom".The growth conditions read well to me. It only grows a vertex copy past an unchanged, shorter kept copy at the same address, by at most a quarter, within
DrawInputBudgetand the attribute descriptors' end. It stops at any color, depth, stencil or HTILE address, and only when the extra bytes have no pending write, storage result, unpublished unit shadow, resident depth or host-only samples. The extra bytes are collected with the read, so the kept copy's generation covers them.AI-assisted: yes (Claude Code)