perf(agc): skip address shadow publishes for gaps and pending storage units #23234
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23234"
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 Feuris on 2026-11-18T20:42:38Z.
What
In
GuestBufferMemory::UploadFinish, address-based heap shadow publication previously published a single[heapsBegin, heapsEnd)bounding span acrossspace->baseand direct host-backed regions. When active heaps had unreferenced address gaps between them or overlapped pending 64 KiB storage-texture write units (which address-based builds exempt fromFlushPending),PublishShadowsOnlypublished whole address gaps and shadowed units underneath active pending storage images.This change:
direct && hostBackedaddress intervals (directHostHeapRanges) and their[directHostHeapsBegin, directHostHeapsEnd)bounding span onGuestBufferMemory::AddressSpaceat space construction/patching time, avoiding per-upload range rebuilding in steady state.UploadFinishearly via lock-freeLiveUnitsClear(heapsBegin, heapsEnd - heapsBegin)before constructing or subtracting ranges when no live shadow unit overlaps the bounding span.StorageTexture::SubtractPendingUnitsbacked by aPendingList::unitsVersion-keyedAtomicSharedPtr/ThreadScratchsnapshot of inward 64 KiB-aligned pending units, plusThreadScratchoutput storage, eliminating per-uploadPending().mutexlocks and sorts in steady state.std::spanoverload ofStorageTexture::PublishShadowsOnlywithLiveUnitsClearearly exit before lockingRegistry().mutexorGpuMutex().Tested
origin/main(d50640e264) andperf/agc-subtract-pending-units(8e6184a1ee) withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer(Vulkan SDK layer 1.4.363.0):Insert instance layer "VK_LAYER_KHRONOS_validation"confirmed in both logs; 0 newVUID-validation errors introduced.agc_driver_address_draw_space_reuse(0.56 s),agc_driver_address_passes(0.71 s),agc_driver_resident_heap_mirror(1.62 son PR;1.07 sonorigin/main),agc_driver_graphics(13.13 s),agc_driver(18.34 s): 5/5 passed.PPSA31162, Super Meat Boy 3D02.000.001,3840x2160, level/Game/Levels/World1/L_W1_L01/L_W1_L01idle after deterministicpad_timelineboot/menu entry with warmshader_cacheand restarted process,APS5_TRACE_SECONDS=95:5,APS5_LAZY_SHADER_PREPARE=1, noAPS5_PROFILE_*or otherAPS5_TRACE_*switches, unredirected console):origin/maind50640e26408vs8e6184a1ee8a):Performance comparison
d50640e264Frame and GPU times (ms)
Top phases (ms per frame)
Worker busy time (%)
Graphics track (per present)
main #1->head #1->main #2->head #2, same scene & settings):origin/main(d50640e26408) noise floor (main #1vsmain #2):47vs47presents,frame_ms.p50105.066 msvs106.357 ms(+1.291 ms/+1.23%),gpu_busy_ms_per_present86.567vs88.129 ms(+1.562 ms),Graphics.Draw25.805vs25.445 ms/present,Graphics.Barrier.shadow-publish41.28vs41.21 / present.8e6184a1ee8a(head #1vshead #2):53vs44presents,frame_ms.p5094.109 msvs117.366 ms,gpu_busy_ms_per_present77.019vs99.292 ms,Resources.Complete1.23vs1.32 ms/present(vs2.00/1.91 ms/presentonmain),Graphics.Draw12.796vs12.453 ms/present(-50.4%/-51.1%vsmain),Driver.Packet.prepare_memory12.553vs12.067 ms/present(-50.1%/-50.6%vsmain),GpuMutex.wait.label12.120vs11.711 ms/present(-51.3%/-51.2%vsmain),GpuMutex.wait.hook2.50vs2.20 ms/present(vs9.38/10.84 ms/presentonmain),Graphics.Barrier.shadow-publish36.49vs36.18 / present(-11.6%/-12.2%vsmain).trace_digest.py output (baseline
d50640e264& candidate 8e6184a1ee8a)Baseline (
aps5-trace-d50640e26408-18940.json.gz)seconds 95:5 from present 849: 47 presents, frame p50 105.1 / p90 117.2 / p99 131.5 / max 131.5 ms, GPU busy 86.6 ms per present
AMD Radeon RX 6700 XT, AMD proprietary driver 26.10.1 (AMD proprietary shader compiler), Windows 10.0.26200, 3840x2160, commit
d50640e264, 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 209.3, Driver.Packet.memory_wait 106.9, batch 88.3, Driver.Packet.dispatch 26.9, Driver.Dispatch 26.8, Graphics.Draw 25.4, Driver.Packet.prepare_memory 24.4, Graphics.Draw.draw_and_resource_release 23.8, GpuMutex.wait.label 23.8, GpuMutex.wait.hook 9.4
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Candidate (
aps5-trace-8e6184a1ee8a-25352.json.gz)seconds 95:5 from present 884: 53 presents, frame p50 94.1 / p90 104.6 / p99 120.7 / max 120.7 ms, GPU busy 77.0 ms per present
AMD Radeon RX 6700 XT, AMD proprietary driver 26.10.1 (AMD proprietary shader compiler), Windows 10.0.26200, 3840x2160, commit 8e6184a1ee8a, dropped: no
Slowest 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 186.7, Driver.Packet.memory_wait 96.4, batch 78.7, Driver.Packet.dispatch 24.9, Driver.Dispatch 24.8, Graphics.Draw 12.4, Driver.Packet.prepare_memory 11.8, GpuMutex.wait.label 11.0, Graphics.Draw.draw_and_resource_release 10.8, Vulkan.Dispatch 9.4
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
python tools/check_conventions.py --base origin/mainpassed.python tools/pr_overlap.py --branch perf/agc-subtract-pending-unitsmerged 101/101 non-conflicting open PRs touching shared files with 0 line overlaps.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
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T21:17:11Z.
Review: APPROVED
Reviewed — looks good
The reviewed changes appear sound from the inspected code; the author reports focused tests passed, but those checks were not run in this review.
What I ran
Reviewed head
b8eeb13d395c11c25615acf97fd637a649d9a3b2. Readdescription.md,commits.md,manifest.json,diff.patch, and the changed code inTexture.hpp,GuestBufferMemory.cpp,Texture.cpp, plus targeted context inUnitShadow.cppandTexture.cpp. The changedGuestBufferMemory.cppandTexture.cppfiles were read around their changed hunks throughrepo_read.py; their full texts were excluded from the review folder. No tests or build checks were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author reports paired focused test runs, a live gameplay check, and convention and overlap checks; these were not independently verified. The promised standalone performance traces are not present in the review artifacts. No build, test, or console behavior was independently confirmed.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T04:38:30Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change based on the code inspected; the author’s reported checks were not run during this review.
What I ran
Reviewed head
8e6184a1ee8aaa516b658b1245bd5d362aeafed7using the pinnedrepo_read.pyreader. No build or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Build, tests, performance captures, and console behavior were not independently verified. Read all three changed files:
Texture.hpp,GuestBufferMemory.cpp, andTexture.cpp. No changed files were excluded;files.jsonwas not present in the review folder listing. The author’s description reports focused tests and gameplay measurements, but those reports were not independently checked.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-11-24T19:40:04Z.
Review: CHANGES_REQUESTED
Blocking concurrency gap on exact head
8e6184a1ee8aaa516b658b1245bd5d362aeafed7.SubtractPendingUnits()snapshots units only frompending.textures, but the existing pending registry intentionally has a second still-pending state:FlushPending()removes each selected texture frompending.textures, pushes it intopending.flushing, publishesflushingCount, and only after that acquiresGuestMemory::GpuMutex()to perform the store. Other correctness paths (otherPendingOverlaps,RefreshObligation,adjacentPendingUnchanged) explicitly inspect bothpending.texturesandpending.flushingbecause a texture influshingstill owns results that have not reached guest memory yet.That leaves a race in the new optimization:
FlushPending, erases a pending image frompending.textures, adds it topending.flushing, then blocks waiting forGpuMutex().UploadFinish, builds the cachedUnitSnapshot; the image is absent because the snapshot walks onlypending.textures.GpuMutex()inPublishShadowsOnlyand is allowed to publish an older unit shadow under the range that A is still responsible for storing.The
unitsVersioninvalidation does not fix this: moving an image out ofpending.texturesmerely makes the rebuilt snapshot omit it;pending.flushingis never added toUnitSnapshot::units.Please include the pending units of
pending.flushingin the snapshot (or otherwise make the transition into flushing invisible toSubtractPendingUnitsuntil the store is complete). The snapshot must be invalidated on both entry to and removal fromflushingif its contents can change there. Add a deterministic regression that parks a selectedFlushPendingtexture in the registered-flushing / pre-GpuMutexwindow, runs the address-heap publication path concurrently, and proves the overlapping unit is subtracted until the flush completes. The current broad GPU/perf runs do not exercise that ordering deterministically.I did not find another blocker in the range-merging/steady-state fast path. The title regression reported on the earlier head is also correctly cleared on this head; this request is specifically about the pending→flushing transition.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-11-25T01:38:07Z.
Review: APPROVED
Reviewed exact head
7978760b49de2f04f136033174312ecb4c085f8fon machinemain, focused on the pending→flushing concurrency blocker I raised on the prior head.The blocker is addressed.
SubtractPendingUnits()now builds its unit snapshot underpending.mutexfrom bothpending.texturesandpending.flushing.FlushPending()bumps the unit version when selected textures enterpending.flushing, and the unregister path bumps it again after removal, so cached/thread-local snapshots are invalidated across both state transitions.The new
agc_subtract_flushing_unitsregression deterministically parks a selected flush after registration inpending.flushingbut before acquiringGpuMutex(). It verifies the unit remains subtracted while parked, verifies the cached snapshot stops subtracting after the flush unregisters, and—when watched host imports/unit shadows are available—runs the addressableGuestBufferMemory::Upload(true)path while parked and checks that the older shadow is not published before the flush completes. That directly exercises the ordering gap from my previous review rather than relying only on broad GPU/performance runs.I found no remaining blocker in the delta that addresses my request. Hosted Windows is still in progress at review time; this approval is code/regression review evidence, not a claim that the pending job passed.
AI-assisted review: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T02:29:30Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the performance evidence is author-reported, and the targeted code review found no verified defect.
What I ran
Reviewed head
7978760b49de2f04f136033174312ecb4c085f8f. No commands or tests were run. Readdescription.md,commits.md,manifest.json,diff.patch, and changed source ranges inGuestBufferMemory.cpp,Texture.cpp, andRecorder.cpp; also readTexture.hppand the test CMake file. The full text for the three large files was excluded by the review bundle; targeted ranges were read throughrepo_read.py.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full changed-file texts for
GuestBufferMemory.cpp,Texture.cpp, andRecorder.cppwere not read; only their relevant changed hunks and surrounding ranges were inspected. Tests, prechecks, and console behavior were not independently run or confirmed. The PR description’s reported runs and performance captures were not independently verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T09:29:17Z.
Review: COMMENTED
Reviewed — no blocking findings
No concrete blocking defect was verified in the changed logic inspected; the available evidence is not sufficient for approval.
What I ran
Reviewed head
d2402b5870018d38c4871d2543e22b977da55431using the prepared diff andrepo_read.pyreader tools. No tests or builds were run.Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
I read the prepared description, commits, manifest, diff, and file listing. I inspected the changed declarations in
Texture.hpp, the test registration changes inagc_driver_recorder_tests.cmake, and targeted changed-code context inGuestBufferMemory.cppandTexture.cpp.Recorder.cppand the full text ofGuestBufferMemory.cppandTexture.cppwere excluded from the review folder; I inspected only relevant ranges of the latter two through the reader. I did not run the reported GPU tests or verify the performance captures.To get this to a good state
Nothing is required. The points above are optional: run the focused tests on this head and review the remaining changed-file context before treating the review as complete.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-29T09:37:28Z.
Review: COMMENTED
Actionable comments posted: 3
94cf7f7f-1560-4c26-a020-eeeefe93a85aReviewing files that changed from the base of the PR and between
1c99516e94andd2402b5870.core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_recorder_tests.cmakeIncluded 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 coderabbitai[bot] on 2026-11-29T10:07:52Z.
Review: COMMENTED
Actionable comments posted: 1
d5aa0d46-6de5-482d-8ce1-8fa909e629deReviewing files that changed from the base of the PR and between
d2402b5870and738d7d22f9.core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppIncluded 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 MarcZX10 on 2026-11-29T10:30:25Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the focused tests and code inspected support merging.
What I ran
Reviewed head
738d7d22f9eee33c8d432066afb15f07b21e7aa2. I read the prepared description, commits, manifest, diff, and targeted source ranges usingrepo_read.py. I ran no commands or tests.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full contents of
GuestBufferMemory.cpp,Texture.cpp, andtests/Recorder.cppwere excluded from the review bundle because they were too large; targeted ranges were read throughrepo_read.py. I did not read every changed line, run tests, or independently verify the reported performance captures or CI. The manifest marksTexture.hppandtests/cmake/agc_driver_recorder_tests.cmakeas included, but I read only the relevant changed ranges from those files. Excluded by rule: nofiles.jsonwas available in the prepared review folder; the manifest identifies the three excluded full files listed above.To get this to a good state
Nothing is required. Optional: run the focused recorder test and performance comparison on the review head to independently confirm the reported results.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:00:50Z.
Review: COMMENTED
The publication follows the merged host-backed intervals and subtracts storage units that are pending or parked in
flushing. The regression holds a flush before it getsGpuMutex, then checks that the cached subtraction clears after completion. Please retain both sides of that check on rebase. The paired recorder controls and new pending-unit cases are queued on lavapipe.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.