perf(agc): compare captured memory before recording only behind a wait memory has not satisfied #15845
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15845"
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 mehmetbayoglu on 2026-11-04T18:58:01Z.
What
#7446 compares the memory a draw or dispatch captured with guest memory before recording or queuing it, and prepares it again once when they differ. The compare runs for every draw and dispatch on the queue worker. Call of Duty: Black Ops (PPSA34501) at Kino der Toten records about 7,100 draws per frame, and the compare costs about 45 ms per frame on queue worker 0 (
Driver.Draw.draw_enqueuedwent from 3 to 15 ms to 45 ms), which is the thread that paces the frame. Kino dropped from 15.0 to 10.8 fps withAPS5_PIPELINED_DRAWS=32; reverting #7446 alone brings it back.The race #7446 closes needs a write that lands after the capture and that the title ordered behind a label. The debt entry it edited ties it to the graphics queue passing a
WAIT_REG_MEMon another queue's recorded label store without landing it. This PR keeps the compare and runs it only while that is the case:notePendingWaitrecords waits for the graphics queue too (it returned early for queue 0). The graphics queue does not land them:landPendingWaitsdrops each one once memory satisfies it, before the packet's guest reads. A newer wait on the same address replaces the older one, andwaitMemorydrops the waits on an address when memory satisfies a wait on it.capturedMemoryChangedreturns early when the worker holds no such wait. The compare, the recapture and their call sites inDraw.cppandDispatch.cppare unchanged.[labels]counts capture checks run and skipped;[landwait]also reports for the graphics queue (dropped and still pending waits).What is skipped: a draw captured while no wait the worker passed is unsatisfied. Then either memory satisfied the title's wait before the capture (the title wrote its fill before the label, so the capture holds it), the queue waited on its own label (which orders no CPU or other-queue write), or there is no wait at all, which is a race on the console too. Every compare site runs on the worker that executed the waits, with no packet between the capture and the compare. The debt entry is updated.
Tested
Windows 11 Pro, NVIDIA GeForce RTX 4070 Ti (617.42), i7-13700K, WinLibs GCC, Release. Measured on
main086c0686c8and this change on it (14da8033c1); the branch is rebased ontob11c7bf84fwithout conflicts.Tests.
DrawRecaptureOnChangeandDispatchRecaptureOnChangenow open the gate the way a title does: the hook notes aWAIT_REG_MEMon a label memory does not hold, then changes the table, and the draw or dispatch is prepared again once as before. New cases: a noted wait with no change (the compare runs, nothing is prepared again), the same draw after the label is written (the compare is skipped), and in the dispatch test two waits on one address with references 1 and 2 (one write of 2 closes the gate).AGC suite,
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -R "agc|shader_cache":main086c0686c8: 1338 of 1339 pass.086c0686c8: 1338 of 1339 pass. Onb11c7bf84f: 1376 of 1377 pass.agc_driver_direct_write_completion. TheVUID-messages are the same IDs and counts onmainand this PR.Same output. A strict replay of a 3-frame Kino capture (
agc_frame_replay --strict, each run from a copy of the same warm shader cache, with a local per-command digest that is not part of this PR), two runs of this PR against three ofmain:main; 57 of 57 render passes equal.mainruns. All are label-run dispatches that differ only in their descriptor sets, the same class in whichmain's own runs differ from each other (37 to 47 records).Kino der Toten, b set (
APS5_PIPELINED_DRAWS=32 APS5_PIPELINE_DISPATCH=1 APS5_BATCH_CAP=1024 APS5_DRAW_CACHE_ENTRIES=32768and the rest shown in the summary lines), and ip (the same plusAPS5_DRAW_INPUTS_IN_PLACE=1). Scripted route, warm caches, Kino window from the trace summary, three runs each in the order main, PR, PR, main, main, PR; fps:mainA second series of this PR against the revert gave b 15.0 against 15.0 and ip 15.7 against 16.4 (one PR run at 14.9 with GPU spikes). In an
APS5_PROFILE_DRAW=1run of this PR,[labels]reportedcapture checks 0 run, 2443949 skipped (no unlanded wait): Kino never holds such a wait.Traces as the Performance report form describes (
APS5_TRACE_SECONDS=42:5in the scene, b set),tools/trace_digest.pysummary lines:main: seconds 42:5 from present 1147: 52 presents, frame p50 92.3 / p90 100.4 / p99 279.3 / max 279.3 ms, GPU busy 3.3 ms per presentThis PR: seconds 42:5 from present 1351: 70 presents, frame p50 67.1 / p90 73.5 / p99 251.5 / max 251.5 ms, GPU busy 3.1 ms per present
The
tools/trace_digest.pyoutput of both runs and their traces are attached.python3 tools/check_conventions.py --base origin/mainpasses.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)Summary by CodeRabbit
Bug Fixes
Performance
Documentation
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T04:56:24Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected wait tracking and capture gating support the stated behavior, and no blocking defect was verified.
What I ran
Reviewed head
093c045e3fee311830682931357745c2fa3eaea1using the prepared diff and pinnedrepo_read.pysource. No tests or build commands were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author-reported test suite, performance captures, and console behavior were not independently verified. The source review covered all eight files listed in
manifest.json;files.jsonwas not available through the reader. No excluded files were identified in the manifest.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T07:08:11Z.
Review: COMMENTED
Actionable comments posted: 3
Architecture findings (3)
Advisory architecture findings (3)
8a087760-d806-4bd6-ab36-2c6a924a358eReviewing files that changed from the base of the PR and between
643d306fb0andff6e738ac4.core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Synchronization/SynchronizationStatistics.hppcore/libs/prx/libSceAgcDriver/Execution/include/ShaderMemory.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketFlush.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/DeferredLabels.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/SynchronizationStatistics.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/LinkedCodeDependencies.cppcore/libs/prx/libSceAgcDriver/tests/execution/DispatchRecaptureOnChange.cppcore/libs/prx/libSceAgcDriver/tests/execution/DrawRecaptureOnChange.cppdocs/dev/debt/libSceAgcDriver.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T07:25:42Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the implementation and targeted source paths support the stated wait-gated recapture behavior.
What I ran
Reviewed head
55b42f39035505a2c3f54f3b9bfdc0791684ab76against the prepared diff and source at that pinned head. No build or test commands were run; the test and performance results in the description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Builds, automated tests, and runtime behavior were not independently verified. Author-reported AGC suite, replay, and performance results were not rerun. No files were excluded:
files.jsonreports all 14 changed files included, and every added line was read. Source context was read selectively for wait execution, draw and dispatch recapture, ShaderMemory known-value tracking, and test helpers; unrelated portions of those files were not reviewed.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T07:31:22Z.
Review: COMMENTED
Architecture findings (2)
Advisory architecture findings (2)
eb9855bc-90b3-4946-bcce-ee5842990e8cReviewing files that changed from the base of the PR and between
ff6e738ac4and55b42f3903.core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/DeferredLabels.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libSceAgcDriver/tests/execution/DispatchRecaptureOnChange.cppdocs/dev/debt/changes/perf-agc-recapture-gate.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T08:03:10Z.
Review: COMMENTED
Architecture findings (2)
Advisory architecture findings (2)
capturedMemoryChanged(memory, snapshots)without the newrequiredargument, so it defaults to false. With no unsatisfied wait pending, this path skips the compare even for user patches, captures served from queued-store known values, and programs with no registered header. The otherfinishDrawcall sites force the compare in those cases, and the debt doc says it still happens. Stale captured memory could be recorded on this path.notePendingWaitnow removes every remembered wait on the same awaited address before adding a new one, including older waits a compute queue has not landed yet. Before the PR, every distinct remembered wait on a compute queue was landed. If a newer wait on a label has a lower reference value or a different compare function, the older ordering is lost and its fill can be read early. The design relies on labels being monotonic, and nothing enforces that.245e5418-f567-49c8-94b1-c3c6d79bc6faReviewing files that changed from the base of the PR and between
55b42f3903and7d1f2e52ae.core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/ShaderMemory.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/DeferredLabels.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T08:15:29Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
7d1f2e52ae3a0f703648630b072703b640dfb34busing the prepared diff and pinned repository reader. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The PR-reported test results, benchmark measurements, traces, build, and convention check were not independently verified. No files were excluded by the prepared manifest.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-01T12:07:57Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional. At head
5bd9154450155663605c7fcc71168d1a57e10210, the wait tracking and draw/dispatch gates appear consistent with the stated goal.What I ran
Reviewed the prepared description, commits, manifest, and diff, then inspected changed code and relevant callers through
repo_read.pyat the pinned head. No build or tests were run.Results
Negative control
Not run; no tests were executed or changed for a negative control.
Findings
Blocking
None.
Non-blocking
None.
Sources
WaitMemory.cppat the reviewed head: pending waits are tracked by address, satisfied waits are removed, and graphics waits are retained until memory satisfies them.DeferredLabels.cppat the reviewed head,Draw.cpp, andDispatch.cpp: capture comparison is gated by pending waits and the additional capture conditions.Not verified
No tests, builds, console runs, or performance captures were independently performed. The test and performance results in the PR description are author-reported. I reviewed changed hunks and relevant context in all 14 paths listed under
reviewedinfiles.json; that manifest lists no excluded paths.Files reviewed
core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Synchronization/SynchronizationStatistics.hppcore/libs/prx/libSceAgcDriver/Execution/include/ShaderMemory.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketFlush.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/DeferredLabels.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/SynchronizationStatistics.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/LinkedCodeDependencies.cppcore/libs/prx/libSceAgcDriver/tests/execution/DispatchRecaptureOnChange.cppcore/libs/prx/libSceAgcDriver/tests/execution/DrawRecaptureOnChange.cppdocs/dev/debt/changes/perf-agc-recapture-gate.mdTo get this to a good state
Nothing required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-01T12:12:39Z.
Review: COMMENTED
🏛️ Architecture findings (2)
Advisory architecture findings (2)
💬 Code review
da5a1b89-7ee2-471e-9b7c-88fa3a02caafReviewing files that changed from the base of the PR and between
7d1f2e52aeand5bd9154450.core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/DeferredLabels.cppcore/libs/prx/libSceAgcDriver/tests/execution/DrawRecaptureOnChange.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:40:54Z.
Review: COMMENTED
The trial merge onto
c1601e56d5conflicts inDeferredLabels.cpp. When integrating the pending-wait cache, keep address validation on every path that rereads a retained wait packet, not only the initial wait. The wait record can outlive a mapping change. Preserve both the unsatisfied-wait recapture control and a satisfied-wait case that skips the expensive compare. Performance evidence should use paired traces from the same scene and machine.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-03T23:31:00Z.
Review: COMMENTED
Actionable comments
d9c98a24-47fb-4707-ab9f-b3a3c05ba2b3Reviewing files that changed from the base of the PR and between
5bd9154450and2b93b8860b.core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/ShaderMemory.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketFlush.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/DeferredLabels.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libSceAgcDriver/tests/LinkedCodeDependencies.cppcore/libs/prx/libSceAgcDriver/tests/execution/DispatchRecaptureOnChange.cppdocs/dev/debt/changes/perf-agc-recapture-gate.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T00:32:04Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The pending-wait replacement can discard an earlier unsatisfied condition and disable a needed capture check.
What I ran
Reviewed head
2b93b8860b1faf5f7d3d384f7cea1a8efe02acbcusing the prepared diff and manifest, plus targeted reads throughrepo_read.py. No tests or builds were run.Results
Negative control
Not run; no test was run to confirm the proposed wait-ordering regression.
Findings
Blocking
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cpp:156replaces any remembered wait at the same address when a new unsatisfied wait is noted. For example, if the old wait is>= 2and a later wait is>= 1, with memory at0, both can pass through another queue’s recorded label store. The later wait replaces the old one; when memory reaches1, the later condition is satisfied and removed, although the old condition remains unsatisfied. The graphics queue does not land these waits, so a subsequent draw or dispatch can skip its capture comparison and use stale captured data. Keep each independently unsatisfied condition until that condition is satisfied, and add coverage for this ordering.Non-blocking
None.
Sources
Not verified
No tests, performance runs, builds, or console behavior were independently verified. All 14 changed files were included in the prepared diff; targeted source context was read for wait tracking, wait comparisons, packet processing, capture gating, and the changed tests. No files were excluded by the manifest.
To get this to a good state
Retain each unsatisfied wait condition independently and remove it only when its own condition is satisfied. Add a regression test for an older
>= 2wait followed by an unsatisfied>= 1wait on the same address, then memory reaching1.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.