perf(agc): drop three per-draw allocations on the draw and materialize paths #9177
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9177"
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 milescoviello on 2026-10-21T14:21:49Z.
What
Three allocations that ran on every draw or stage materialization, in three commits:
Driver::drawcopies the draw programs for every draw. Since the draw finisher (#6946), the draw tail takesprograms = decode->programson every draw: one allocation, plus oneuserDatavector and twoshared_ptrreference bumps per program. Before #6946, the copy was made only for draws that write user words (the mesh index buffer words, indirect record words or relocated user patches), and every other draw readdecode->programsin place.DrawTail::writableProgramsnow holds that copy, made on the same condition as before, andDrawTail::programspoints at it or atdecode->programs. Every write goes throughwritablePrograms, so a const view of the decode can't be written.writablePrograms. When it is empty, the captureddecodekeepsdecode->programsalive.decodeis only replaced (by the relocated copy) on draws with user patches, and those take the copy.Driver::drawreservesprograms.size() + 2RecompileResults for every draw. Only three paths fillresults: the rect-list pair, barycentric emulation and CPU-path indirect draws. The reserve now sits right before the first push on each of those paths, with the same bound, so&results[i]stays stable. An ordinary direct draw no longer allocates there.DescriptorBindingBuilder::Populatereserves its exactshaderDataUserWordscount.GuestSamplersDescriptorreserves four dwords per sampler, asGuestBuffersDescriptoralready does.ResolveImageTablesSharedreturns one shared emptyResolvedImageTableswhen there are no tables, still callingResolveImageTablesfirst so its mismatch check keeps throwing.Tested
Rebased onto
main16319642a4, after #6946's draw finisher, as9e6966b121. #6946 moved the end ofDriver::drawinto aDrawTailthat owns its own copy of the programs, and its commit closures move that copy. So the old first commit (capturingwritableProgramsinstead of copying a const vector) no longer applied, and the copy it avoided became one made on every draw. The new first commit makes that copy only for the draws that write user words, as before #6946. The other two commits are replayed onto the new structure. The second commit's removed reservation now sits in the tail setup.On that head, Ubuntu 26.04.1 (kernel 7.0), GCC 15.2, NVIDIA RTX 4070 Ti, driver 615.71.09, Release:
mesh_draw_relocation|draw_cache_relocation|pipelined_indirect_draw|indirect_patched_stage|rect_list_indirect|rect_list_corner|pixel_barycentric_emulation|image_table|shader_disk_cache|_draw_pipeline$|draw_finisher|draw_pipeline_trace|draw_data_hit_user_words|mesh|indirect|queued_raw_shaderpass 3 of 3. That's the earlier 15 plus #6946's draw finisher and pipelined-draw tests and the other mesh and indirect tests. Two of them,agc_driver_pipelined_metadata_pass_draw_pipelineandagc_driver_finisher_label_order_draw_pipeline, ran in a second pass after their executables were built.ANYPS5_REQUIRE_VULKAN=1: the 34 tests matchingmesh_draw_relocation|draw_cache_relocation|pipelined_indirect_draw|indirect_patched_stage|rect_list_indirect|rect_list_corner|pixel_barycentric_emulation|image_table|shader_disk_cache|draw_finisher|draw_pipeline_trace|draw_data_hit_user_words|draw_cache_reuse|draw_write_rangespass 3 of 3 onmain16319642a4and 3 of 3 on this head.CoD Black Ops II (PPSA34502), war-room menu: current
mainagainst this head, same machine and scene.main0db47b263dplus #9656 (f1a1b46987; itslibSceVoice.mddebt-file conflict resolved tomain's side, the code merged cleanly). Without #9656,mainstops this title at 10 s (#9601).dc10dbdc15).7270:10in every run.tools/performance_compare.py --require-matching-contextaccepts all three pairs.On current
mainthis still shows no measurable difference.mainalone went from 9.9 to 14.0 presents per 10 s, and the two usable pairs differ by -12 % and +21 %.Driver.Draw, mostlyGraphics.Draw.draw_and_resource_release. Three small allocations per draw don't show next to that.The summaries, traces and comparator reports of all six runs are in this release. Round 3's window lines:
Base:
This PR:
Before the rebase onto #6946.
Rebased onto
maincc0078595das07e939750f, with no conflicts.git range-diffshows the three commits unchanged. On that head, on Ubuntu 26.04.1 (kernel 7.0), GCC 15.2, NVIDIA RTX 4070 Ti, driver 615.71.09, Release: the 15 tests matchingmesh_draw_relocation|draw_cache_relocation|pipelined_indirect_draw|indirect_patched_stage|rect_list_indirect|rect_list_corner|pixel_barycentric_emulation|image_table|shader_disk_cachepass 3 of 3.CoD Black Ops II (PPSA34502), war-room menu:
main4777caca34against the pre-rebase head, same machine and scene.main4777caca34plus #9656 (9d56f02254). Without #9656,mainstops this title at 10 s onsceVoiceGetPortAttr(#9601).5b24a5b8c3).APS5_TRACE_FRAMES=7270:10: the menu starts at about present 7246, after the title's 60 FPS intro. So both sides' windows start at the same present, with the same environment and nothing dropped, andtools/performance_compare.py --require-matching-contextaccepts all three pairs.On
mainthis shows no measurable difference. A frame takes about 0.9 to 1.1 s, and 690 to 890 ms of it isGraphics.Draw.draw_and_resource_release, the per-draw snapshot copies that #8756 removes. Three small allocations per draw don't show next to that, and round 2's gap is within this machine's run-to-run noise. The summaries, traces and comparator reports of all six runs are in this release. Round 3's window lines:Base:
This PR:
Supporting context only, not evidence against
main: the same menu on a faster composite base. The runs below are from before the rebase: Ubuntu 24.04, GCC 13.3, NVIDIA RTX 4070 Ti, driver 595.99.02, i7-13700K.Suites on
maine072e8840a:^agc_|^shader|^request_serializer$passes 866 of 869. The 3 failures are #6683's sample-order tests, which fail onmainon this card too; #9056 fixes them.mainand on this head, with no VUID on either.CoD Black Ops II (PPSA34502), war-room menu, on a composite base. Release libs, 12 GB cap, the scripted run, 10 s summaries from 140 s. On
mainalone the menu is bound by per-draw snapshot copies (about 9 presents per 10 s), and the three commits make no measurable difference there: 9.2 against 9.2 over three rounds. So the comparison runs onmainf894ba69d3with #8975 (its pre-merge head), #8756, #8888 and #8928 merged (base690fd73114), and the same three commits on it, where the menu reaches about 60 presents per 10 s and these allocations are a visible part of the queue worker's time. Six alternating rounds, after one warm-up round each:The mean is 59.9 against 61.7, +2.9 %, and this PR is ahead in 4 of 6 rounds. That's small next to the run-to-run noise on this machine, which shares its CPU with other services. Treat it as a modest gain, not a proven one. Round 4's base run lost its first intervals to host load.
Captures of round 6, the last one (summary files, traces and
tools/trace_digest.pyoutput), are in this release. The 220:5 window lines:Base:
This PR:
macOS, a title bound by the queue worker: @imellag ran it on an Apple M4 Pro (macOS 27.0.1, MoltenVK 1.4.2, x86-64 Release under Rosetta 2).
maindoesn't build on macOS, so the base wasmaincecb540a63plus the macOS port PRs, with this PR's three commits (pre-rebase head401aab07d9, the same commits) cherry-picked onto it. Arms alternated, scripted input.AMD, Linux: @JJenkx ran it on an RX 6650 XT (RADV, Mesa 26.2.4) with ASTRO BOT booted without input, the PR against its own base, alternated base, PR, PR, base. FPS 21.40, 21.42 on the base and 21.54, 21.18 with the PR: no change and no regression on that scene. Swapping in jemalloc gains about 4 % there, so allocation does show, but these three allocations are too small to.
Windows 11 Enterprise 26300, NVIDIA GeForce GT 1030 (driver 582.78), WinLibs GCC 15.2.0 r7 (UCRT), Release: the 28 AGC relocation, indirect, rect-list, barycentric, draw descriptor and pipelined tests pass 3 of 3 on
mainand 3 of 3 with this change. The pattern also matched 6 relinker relocation tests. They could not start on either side, because that run didn't build the relinker they launch.Not tested: Intel.
Overlap (the generated report on this head: a textual conflict with #9049; #6804, #7369, #9387 and #9508 also share
Draw.cppbut conflict withmain, so they weren't compared):DrawTail, and the reservations stay in the three paths that fillresults.GuestSamplersDescriptorinto a function that fills a reused vector (result.clear()), next to this PR'sresult.reserve(resources.size() * 4u). Whichever lands second keeps the reserve after theclear(). With a reused vector it costs nothing once the capacity is there.main. ItsDraw.cppchanges only readprograms, so the const view this PR gives that code is enough, and it doesn't touchresults' reservations.std::optionaland still appends at most the two tessellation results, which that branch's reservation covers. So the two only touch neighbouring lines.Draw.cpp; their changes are distinct.Checklist
main; no other open PR implements the same functions (a textual conflict with #9049, and neighbouring lines of #9387, #9508, #6804 and #7369: see Overlap above)NotImplemented_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 JJenkx on 2026-10-21T17:26:04Z.
AMD/Linux data point, for the "Not tested: AMD" line. The result is neutral: no change and no regression.
Setup
maine072e8840a; both builds are clean, and one relinkedapp.elfis shared by both.ANYPS5_PRESENT_MODE=immediate,APS5_TRACE_SECONDS=150:30,APS5_TRACE_EVENTS=4194304.Means are 21.36 FPS for this PR and 21.41 for the base, within noise. Swapping the whole allocator for a preloaded jemalloc gained about 4 % on this scene (#357), so allocation cost is visible here, but the three allocations this PR removes are too small to show.
AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T17:26:52Z.
Thanks @JJenkx. A neutral result on RADV fits what this PR removes: three small allocations per draw, which only show on a frame bound by the draw path, as BO2's menu is here. I added your run to the Tested section and the GPU line.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T08:22:07Z.
Review: DISMISSED
Review
I did not find a correctness defect in the three allocation changes on this head. The move capture is valid for the local writable program vector, and the scoped reservations match the result-producing paths. I’m requesting changes for the performance evidence and the current overlap state.
Performance evidence
The CONTRIBUTING performance guidance asks for main and change summary lines from the same machine and scene, with traces attached per the issue form. The only paired traces in this PR are from the composite base
690fd731145aand the candidate. Your description explicitly says that base includes #8975, #8756, #8888, and #8928, and correctly warns that the +2.9% result is small and noisy.I ran the repository comparator on those attached summaries and traces. With
--require-matching-context, it rejects the pair becausewindow.first_presentdiffers (7848 vs 7836). Without that requirement, it warns that the measurements do not isolate the code change. Both traces also report dropped events, so the trace detail is incomplete even though the summary data is available. The PR mentions a separatemain-alone 9.2 vs 9.2 result, but does not include its matching summary/trace evidence.Please add a same-machine, same-scene comparison of current
mainand this change, with the matching summary lines and traces (or explain any unavoidable context mismatch in the report). Please keep the composite-base result clearly labeled as supporting context rather than evidence of the change against main. The current head is 599 commits behind current main, so please also refresh the base and rerun the focused validation after rebasing.Overlap
The generated overlap report now lists #6946 and #9508 in addition to #6804, #7369, and newer #9387. These are not all duplicates, but the impact should be recorded:
Draw.cppstill unconditionally reservesresultsforprograms.size() + 2, which would erase this PR’s ordinary-draw allocation saving if that path is combined as written. Its draw-finisher also changes the ownership/capture flow, so the vector-capture optimization should be rechecked against the combined implementation.Please add the relevant PRs to the overlap notes/checklist and coordinate the combined behavior with those authors as needed. The existing #6804 and #7369 intersections appear to be neighboring, distinct changes.
Checks I ran
git diff --check: passed.main: passed.main: clean.The code changes themselves look reasonable. I’ll revisit the review when the performance comparison and overlap notes are updated.
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-22T10:57:27Z.
@MarcZX10 thanks.
Rebase: onto
maincc0078595das07e939750f, with no conflicts. The three commits are unchanged, and the 15 focused tests pass 3 of 3.Current
mainagainst this PR: three alternating rounds in BO2's war-room menu on the same machine.main4777caca34plus #9656, which the title needs to start.APS5_TRACE_FRAMES=7270:10). The windows start at the same present with the same environment and nothing dropped, and--require-matching-contextaccepts all three pairs.main: mean frame time -0.2 %, +9.5 % (the round with this PR first) and +0.2 %. A menu frame there is about a second, and 690 to 890 ms of it isGraphics.Draw.draw_and_resource_release, the per-draw snapshot copies #8756 removes. Three small allocations per draw don't show next to that.Overlap: recorded under Overlap in Tested.
programscapture. Whichever of the two lands second has to carry the other's change by hand, and #9508 inherits that through #6946.@Raghav314 (#6946, #9508): do you have a preferred order? If #6946 goes first, I'll rebase this onto it and move the three reservations and the
writableProgramscapture into your finisher. If this goes first, the same two changes apply on your side. @Alexius0815 (#9387): I don't think we need an order. Correct me if your barycentric branch can append more than two results.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-22T10:58:16Z.
An Apple / MoltenVK data point, on a title whose frame is bound by the queue worker. A small gain there.
Setup: Apple M4 Pro, macOS 27.0.1, MoltenVK 1.4.2, x86-64 Release under Rosetta 2.
maindoes not build on macOS, so the base ismaincecb540a63+ #8658 + #9193 + #9263 + #8612. This PR's three commits (head 401aab07d9) cherry-pick onto it cleanly. Warm shader caches,APS5_TRACE_SUMMARY_EVERY, no other trace or profile switch, arms alternated, scripted input.In Lana every run of this PR is above the mean of the base runs, and the worker is busy about 3 points less. That fits the per-draw allocations this removes: Lana records about 650 draws a frame with the queue worker as the limit. God of War is limited by the GPU, so it shows no change, and no regression.
AI-assisted: yes (Claude Code). The runs are from my M4 Pro.
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-22T10:59:20Z.
@imellag thanks for the M4 Pro runs. Planet of Lana, with about 650 draws a frame and the queue worker as the limit, is the kind of scene where these allocations should show. Every PR run was above the base mean, and the worker dropped about 3 points, which fits that. God of War being neutral is also useful, as it shows no regression in a GPU-bound case. Added to Tested.
AI-assisted: yes (Claude Code)