perf(agc): commit draws from records resolved on the finisher, with the finisher's job slimmed, under APS5_DIRECT_DRAWS #22647
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22647"
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 Nesyth on 2026-11-18T00:03:42Z.
What
With the lean front (#22434) the queue-0 worker hands a draw to the draw finisher, but the draw committer still prepares every draw on the thread that holds the GPU lock: the template proof, the resolve of each stage's resources, the buffers and the vertex and index inputs, and the render targets. This PR lets the finisher resolve a draw to a record that the committer commits directly, and makes the finisher's job cheap enough for that move to pay. Moved alone, the work measured -0.5% on
main: the single finisher became the busy stage. With the finisher's job slimmed in the same PR, the in-run A/B below gives +6.6% over #22434.Four commits, every switch a
RuntimeSwitchthat is off by default and thatAPS5_ABcan toggle within one run:APS5_DIRECT_DRAWS): a lean draw the worker marks direct is resolved on the finisher from a per-thread prepared invocation cache, a walk of each stage's resources that records the words it read, and a store of shared stage results; the committer commits it from that record.APS5_DIRECT_RETRYresolves a walk again (at most twice) when its reads were not settled.APS5_DIRECT_PASS_TARGETSkeeps the targets another record's draw refreshed in the open pass when nothing they depend on moved.APS5_DIRECT_BUFFERSandAPS5_DIRECT_INPUTSprepare the draw's buffers and its index and vertex inputs on the finisher.APS5_PRECISE_SETTLEsettles a range under a newer 64 KiB block stamp by its page and store stamps;APS5_FAST_SETTLEgives the settle checks their short ways;APS5_MERGED_SETTLEtests more than two copied buffer ranges once, sorted and merged;APS5_UNLOCKED_STAMPS,APS5_WRITE_SNAPSHOT_FRONTSandAPS5_PENDING_FRONTSread the tracker stamps, the published pending-write snapshot and the pending storage list without their locks (the fronts serve every existing caller, including the flush hook and the committer's checks);APS5_IMPORT_SNAPSHOTSanswers host import lookups from a per-thread snapshot of the import set.APS5_LEAN_PREPARErefreshes a per-thread copy of the shape's decode in place;APS5_INVOCATION_SLOTS_WIDEgives each finisher 16,384 invocation slots instead of 1,024;APS5_PREPARED_CAPACITYreserves the prepared lists at their exact sizes;APS5_BUFFER_BLOB_APPENDlays a draw's buffer blob out first, reserves it at its exact size and fills it by appending.APS5_STAGE_MEMO): a direct draw's stage resolve is reused when its content repeats under moved table pointers (the user words the walk read are equal and the words that may move are only addresses), from a store shared by the finishers;APS5_STAGE_MEMO_ADMIT_THIRDstores a content at its third sighting;APS5_STAGE_MEMO_FRONTgives each finisher a lock-free front of the store.Every step keeps today's output, and each has a verify mode that runs today's path (which is what executes) and compares:
APS5_VERIFY_DIRECT_DRAWS,APS5_VERIFY_DIRECT_BUFFERS,APS5_VERIFY_DIRECT_INPUTS,APS5_VERIFY_DRAW_RECORDS,APS5_VERIFY_STAGE_MEMO,APS5_VERIFY_UNLOCKED_STAMPS,APS5_VERIFY_WRITE_SNAPSHOT_FRONTS,APS5_VERIFY_PENDING_FRONTSandAPS5_VERIFY_IMPORT_SNAPSHOTS.With every switch unset the output is unchanged. A few pieces run in both arms because they are shared plumbing: the stamp words are read and written through
std::atomic_ref, the recorder stores one word per published snapshot and the pending list one per flushing change, and the lean-prepare commit's allocation trims (fixed arrays for at most eight registered views, two reserves, and runningnoteDrawWritersonly when a stage may write a guest buffer) are not behind its switch. The stage memo adds two analysis functions to the shader recompiler (TraceSideForwards,SrtTape::AddressForwards); they change no emitted shader, but they move the shader cache version, so the first boot after this change recompiles.#22025 also moves draw planning to the finisher (
PreparedDraw) and changesGraphics::Draw's parameters; whichever of the two lands second adapts.Tested
Windows 11 Pro 26300, Radeon RX 7900 XTX (AMD Software 26.10.1), Ryzen 7 7800X3D, Release, MinGW-w64 GCC 15.2. This head is
ff4fc7af5d:main14deacc1f3with #15456 and #22434 (02f1afce80), plus these four commits.PPSA04264 (v01.011.001), Performance graphics mode, a story save in the city (about 3,000 draws and 95 compute dispatches per frame), the player standing still, warm caches; every run sets
APS5_DRAW_PIPELINE=1APS5_PIPELINED_DRAWS=32APS5_PIPELINE_DISPATCH=1APS5_LEAN_FRONT=1APS5_LEAN_LIST_DIRECT=1.In-run A/B, the nineteen switches of this PR toggled together over the lean front (
APS5_AB=30:with all of them, phases of 30 s from 260 s after the first present; each B phase against its neighbouring A phases, the first pair left out while the scene settles): gain +8.78 +- 0.75 presents per 10 s (+6.6%, 5 pairs, the first pair left out: the scene settles).Captures,
mainand this PR one after the other in the same session (mainat 00:37, this PR at 00:45), the log not redirected,APS5_TRACE_SECONDS=240:60, both with the lean front's two switches and this PR's nineteen set (APS5_DIRECT_DRAWS=1APS5_DIRECT_RETRY=1APS5_DIRECT_PASS_TARGETS=1APS5_DIRECT_BUFFERS=1APS5_DIRECT_INPUTS=1APS5_PRECISE_SETTLE=1APS5_FAST_SETTLE=1APS5_MERGED_SETTLE=1APS5_UNLOCKED_STAMPS=1APS5_WRITE_SNAPSHOT_FRONTS=1APS5_PENDING_FRONTS=1APS5_IMPORT_SNAPSHOTS=1APS5_LEAN_PREPARE=1APS5_INVOCATION_SLOTS_WIDE=1APS5_PREPARED_CAPACITY=1APS5_BUFFER_BLOB_APPEND=1APS5_STAGE_MEMO=1APS5_STAGE_MEMO_ADMIT_THIRD=1APS5_STAGE_MEMO_FRONT=1;mainreads none of them, they are set in both arms so both summary lines carry the same environment):main14deacc1f3ff4fc7af5d)+11.0% FPS between the captures (this includes #22434). The
mainarm runs without #15456's finisher default but withAPS5_DRAW_PIPELINE=1, so both arms run the finisher.Verify boot of this head, every switch on and every verify mode at 64: 283 s in game at 15.1 FPS, 0 fatal, 0 device lost; 98% of the draws took the direct path. The last report of each verify: direct draws 7,662 checked, buffers 6,413 (merged settles 3,754), inputs 6,650 (exact capacities 6,650), stage memo 12,151, draw records about 7,600 answers and 6,700 commits, lean front about 7,700 draws (these per 10 s window); unlocked stamps 236,603, write-snapshot fronts 3,505,574, pending fronts 2,233,114, import snapshots 226,965 (these since the start): 0 differing. One
[stage-memo-verify] the shared stage differsline came in the first minutes (same variant, same read ranges and values, another shared key): the shared key holds the variant's learned buffer substitutes (BufferSubstituteTable::LearnedSlots), which flip once from unlearned to learned, so a memo entry stored before a slot was learned keeps the general stage while a fresh resolve after it gets the specialized one. Both are valid compiles of the same program for these reads; making the entry carry the learned count would remove the line and needs a recompiler change, which I left for a follow-up.On this machine
mainshows the frame's top half mirrored into its bottom half (the viewport control default of #16053, #20835; #20827 fixes it); both arms carry it.Traces, both captured on the same machine in one session: main 14deacc1f3, this PR. Summary lines and
tools/trace_digest.pyoutput below.tools/check_conventions.pypasses.agc_driver_draw_records_hitsvariants for the stage memo (with its verify on) and for the slimmed buffers and inputs.agc_driver_target_memo_lean_frontfails as it does on #22434 (#15456's finisher default meeting #17738's test; it passes withAPS5_NO_DRAW_PIPELINE=1).agc_shader_memoryandagc_shader_memory_coherent_atomic_loadsdid not run on this machine: the local antivirus removes their executable after it is linked.tools/pr_overlap.py --branchfinds no open pull request that conflicts with these lines; the ones it could not compare conflict withmainthemselves.trace_digest: main
14deacc1f3seconds 240:60 from present 4369: 836 presents, frame p50 71.3 / p90 75.6 / p99 90.2 / max 116.6 ms, GPU busy 25.8 ms per present
AMD Radeon RX 7900 XTX, AMD proprietary driver 26.10.1 (LLPC), Windows 10.0.26300, 3840x2160, commit
14deacc1f3, dropped: noSlowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 28.9, Graphics.Draw 25.9, batch 25.8, Graphics.Draw.draw_and_resource_release 22.6, Driver.Packet.draw 16.3, Driver.Draw 16.0, Driver.DrawFinish 15.4, Driver.Draw.prepare 10.7, Driver.Packet.dispatch 9.1, Driver.Dispatch 9.1
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest: this PR
ff4fc7af5dseconds 240:60 from present 4692: 932 presents, frame p50 64.1 / p90 67.9 / p99 80.5 / max 124.0 ms, GPU busy 24.6 ms per present
AMD Radeon RX 7900 XTX, AMD proprietary driver 26.10.1 (LLPC), Windows 10.0.26300, 3840x2160, commit
ff4fc7af5d, dropped: noSlowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 28.8, batch 24.6, Vulkan.DrawFromRecord 15.0, Graphics.DrawWithRecord 14.9, Driver.Packet.draw 14.5, Graphics.DrawWithRecord.draw_and_resource_release 14.1, Graphics.Draw 12.9, Graphics.Draw.draw_and_resource_release 11.0, Driver.Packet.dispatch 8.7, Driver.Dispatch 8.7
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Main merged (2026-11-18):
mained1a01d035merged as85c9eed5d1through #22434's merge. Main's #22079 madeDrawPipeline::Watchmove-only andWrittenSincetake it by reference, so the merge commit adapts the direct path's settle helper to it (the watch is emplaced, not assigned). Every target builds, 167 of 170 focused tests pass (agc_driver_target_memo_lean_frontas above; the twoagc_shader_memorytests did not run here),tools/check_conventions.pypasses. A verify boot of85c9eed5d1with every switch on and every verify mode at 64: 283 s in game at 15.9 FPS, 0 fatal, 0 differing in every verify, and three of the knownshared stage differslines explained above. The A/B and captures above are fromff4fc7af5d.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-21T08:20:01Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change based on the inspected code; optional review scope limits are listed below.
What I ran
Reviewed head
85c9eed5d1b1e5b5c6e4e083f4381099c51c6628using the prepareddiff.patchand targeted source reads throughrepo_read.py. No build or tests were run.Results
Findings
Blocking
None identified in the code inspected.
Non-blocking
None.
Not verified
The manifest lists 113 changed files; I read the changed lines of 12. The remaining changed lines were not reviewed, including the large direct draw, graphics, recompiler, and test changes; the complete behavior and test coverage are therefore not verified. No execution or hardware behavior was verified. The source reviewed includes
DirectDraws.cpp,Submission.cpp,RewindKick.cpp,EntryPoints.cpp, andRewind.cpp; the patch and manifest were also consulted. Excluded-by-size files were not read.To get this to a good state
Nothing is required. Optional: complete review of the remaining changed lines and run the applicable tests before relying on the full PR behavior.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T13:44:30Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected changes at head
ba1819c4c1da07c8ed9846702c9fe2a815cccae1show no verified blocking defect, but the review is incomplete because many changed files were not read.What I ran
No tests or builds were run. I inspected the prepared description, commit list, manifest, diff, and selected code from the patch using the pinned review reader.
Results
Findings
Blocking
None verified in the inspected portions.
Non-blocking
No specific non-blocking finding.
Not verified
The implementation is large and the review is incomplete. I did not read every file marked
reviewedin the manifest, including many source and test files, and the manifest identifies numerous changed files as excluded because they were too large for the review folder. The diff and description report substantial concurrency, shader memoization, direct draw, and performance behavior that was not fully audited. Author-reported tests and performance measurements were not run by me.To get this to a good state
Nothing is required for this comment. Optional: complete the audit of the unread changed source and test files and run the focused tests on this head.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T19:07:37Z.
Review: COMMENTED
The published captures and verify boot are for
ff4fc7af5d. The current headba1819c4c1also brings in a newer lean front and conflicts with maina9cbd48cbin the draw, submission, and resource preparation paths. Please refresh the validation-enabled comparison for the rebased head and include a same-scene pair of trace digests with the same lean-front and finisher code in both arms. The existing main-to-branch pair includes the lean-front change, so the two-build comparison cannot isolate the direct-draw gain. The in-run switch comparison measures the combined effect of this PR's switches on the earlier branch.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.