perf(agc): track pending and borrowed texture units in 64-bit words #10886
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10886"
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 meh7an on 2026-10-25T07:28:57Z.
What
StorageTexture::markLayersPendingruns on the draw thread for every draw that writes a storage image or color target, and it marks the written units pending.layerPendingandborrowedUnitsarestd::vector<bool>, and every call walks them unit by unit over the written range:It does all of this even when every unit of the range is pending already, which is the usual case for a target drawn many times in a frame. On Sonic Origins Plus's Sonic 2 menu page, a sampled profile of the draw committer (
APS5_SAMPLE_COMMITTER, 80 s) putsmarkLayersPendingat 6.2 % of its samples, almost all in its own code. The draw committer is about 94 % busy there, and the queue worker waits on it.This PR:
UnitFlags, which keeps one bit per unit in 64-bit words and has range queries (AnyIn,AllIn), range fill (SetRange),Any,CountandBools, plusoperator[]and theassign/size/empty/clearthe existing code uses.layerPendingandborrowedUnitsuse it.markLayersPending:AllIn);weak_ptr::lockbefore it, when no unit in the range is borrowed (AnyIn).anyLayerPending,clearByKeysFillandforgetBorroweduseAny,CountandSetRangeinstead ofstd::any_of,std::count,std::none_ofand per-unit loops.Bools().Nothing changes in behaviour:
Test.
agc_driver_graphicsgainsunitFlagsTests. It covers ranges across a word boundary, a single unit cleared inside a range, a whole word cleared between full ones, empty ranges, andassign(n, true)leaving no bits pastn.Overlap.
tools/pr_overlap.pylists #7514, #9685, #9879, #10026 and #10656. The proposed order is that they go first, and this PR rebases onto each as it merges:markLayersPendingfor units that become pending. It stays inside theAllInguard, which only skips a call in which no unit changes state.borrowedUnits.UnitFlagskeepsoperator[], so their other uses of the two members compile unchanged.Of the PRs the check could not compare (they conflict with
main), #6202, #6960, #7048 and #7604 also touchmarkLayersPendingor these members. What they add likewise concerns units that are not pending yet, or runs only while no unit is pending (#6960).Tested
Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 2080 Ti, driver 617.14, i9-9900K, on
maincf528e78c6.Sonic Origins Plus (PPSA05324), Sonic 2 page of the main menu,
main's defaults. Two clean builds:maincf528e78c6and this PR 9d17136b66. One warm-up boot (both builds share the shader cache version), then two interleaved traced rounds (APS5_TRACE_SECONDS=200:15):Graphics.Draw(draw thread, ms/frame)Driver.Packet(worker, ms/frame)mainGraphics.Drawdrops by 9 % and 10 %, and itsdraw_and_resource_releaseby 11 % and 12 % (56.2 / 52.5 -> 49.9 / 46.3 ms).Driver.Packetdrops by 4 %: it waits less on a full draw queue.Tests
ctest(2288 tests) onmainplus this PR: everything passes exceptagc_host_import_cut_lifetime("the larger side of an unmap of 1440 KiB at the start of the import's first 2 MiB run left the write watch") andagc_driver_depth_plane_partial_store("repeated lookups of the first layer of an unchanged array proved no refresh"), which fail the same way on plainmaincf528e78c6on this machine.ctest --test-dir build -R "storage|alias|write_back|writeback|texture|image_write|pending|borrow|depth_plane|graphics" -VwithANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation: 85/86 onmainand 85/86 on this PR (the sameagc_driver_depth_plane_partial_storefailure in both). Neither log haswas not found but was requested by env var VK_INSTANCE_LAYERS, and neither has aVUID-line.The summaries of all four rounds follow, then the full digests of round 2. All four traces are attached:
unit-flags-s2-round1.zip
unit-flags-s2-round2.zip
maincf528e78c6maincf528e78c6Round 2,
maincf528e78c6seconds 200:15 from present 3575: 181 presents, frame p50 80.1 / p90 89.4 / p99 111.8 / max 116.3 ms, GPU busy 67.8 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit
cf528e78c6, dropped: yesSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 67.7, Graphics.Draw 31.8, Driver.Present 27.2, VideoOut.Flip 27.1, VideoOut.Flip.present 27.0, Driver.Present.render_fence_wait 26.7, Vulkan.Retire 26.7, Vulkan.Retire.wait 26.6, Graphics.Draw.draw_and_resource_release 26.4, Driver.Packet 17.5
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Round 2, this PR 9d17136b66
seconds 200:15 from present 3669: 189 presents, frame p50 77.1 / p90 86.8 / p99 107.2 / max 108.8 ms, GPU busy 68.6 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit 9d17136b6624, dropped: yes
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 68.6, VideoOut.Flip 28.3, Driver.Present 28.3, VideoOut.Flip.present 28.1, Driver.Present.render_fence_wait 27.7, Vulkan.Retire 27.7, Vulkan.Retire.wait 27.7, Graphics.Draw 25.7, Graphics.Draw.draw_and_resource_release 20.6, Driver.Packet 15.2
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
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-10-25T08:23:41Z.
Review: APPROVED
The bitset helper’s range masks handle word boundaries and preserve the logical size; the
markLayersPendingfast path skips only an already-pending range, while borrowed-unit handling remains independently range-scoped. The new unit tests cover boundaries, empty ranges, and tail bits. The author reports broad current-main/PR comparison and GPU validation runs; hosted product jobs are skipped by repository policy, and I could not independently run the AGC suite in this environment. No blocking defect found in the diff.