perf(agc): memoize host import run bounds per lease snapshot #6951
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6951"
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 alfalfa-star on 2026-10-16T20:54:58Z.
What
Every host import lookup walks the lease to find the run of registry ranges around an address (
importRun): from the containing range out to both ends of the run, which is linear in the run length. Kena: Bridge of Spirits (PPSA01802) and Record of Lodoss War (PPSA05347) look runs up thousands of times per frame (HostImportFor,sameRangein the import refresh,importAllocation).That walk depends only on the lease snapshot, the containing range and the import window block, so its first and last index are now memoized per thread (
continuedRun). The key is a weak reference to the lease'sRangessnapshot (Lease::Snapshot()), the index of the containing range, the import window and the window's low end. Everything that depends on other state still runs on every call, as onmain:largest, the failed blocks, the remembered refusals under the caller's budget andliveBytes, and the halving block search.importRunBoundsreturns the chosen indices, sosameRange,runCoversand the whole-run lookup inimportAllocationcompare against the lease without copying the run's range pointers.APS5_NO_RUN_MEMO=1turns the memo off.Tested
AMD Radeon RX 9070 XT (RADV GFX1201), Mesa 26.2.4, Arch Linux (kernel 7.2.9), i7-13700KF.
importRunFailureShrinkTests: a failed 8 MiB block is recorded between two lookups on an unchanged registry, and the run must shrink to its 4 MiB block and not import the failed block again. It fails when the failed-block check is dropped from the block search.importRunGrowthTestsandimportRunReplacedTestscheck that a run grows and shrinks when its ranges are registered or replaced.tools/select_tests.pyonmain77e31219c: 1649 of 1652 selected tests pass;agc_driver_guest_memory_lifetime,agc_driver_image_array_window_past_layer_limitandagc_driver_tessellationfail the same way on plainmainon this machine.agc_driver_graphics_testspasses with and withoutAPS5_NO_RUN_MEMO=1.APS5_TRACE_SECONDS=100:30, eight alternating rounds, both builds with the same local stand-in for the import ceiling (see the review reply):main339 presents per 30 s on average (8 runs), this PR 352 (7 runs), +4 %, within Kena's spread, so no measurable gain on Kena. One run with this PR crashed in the game's code; details in the review reply. Summary lines of the last round-1 pair (main77e31219c, this PR c3ac6b47f; both dirty from the stand-in):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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-16T21:58:34Z.
Review: COMMENTED
Default-off span mirror plus two changes that are on by default, and no measurement of any of them.
APS5_NO_INCREMENTAL_IMPORT_REFRESH) and the run memo (APS5_NO_RUN_MEMO) change behaviour for every title on every host, and the registry change journal decides which imports get refreshed. A missed journal entry leaves an import pointing at a remapped range. Say what bounds the journal (what happens when it wraps, or when the registry changes during a refresh), and add a test where an allocation is unmapped and remapped between two refreshes and the next draw must see the new pages.agc_*suite there and say so.APS5_SPAN_NO_FLUSH=1skips flushing pending GPU writes over the span before it is served. Leave that out of this PR, or show a title that needs it. A switch whose only effect is to serve stale data is not a performance feature.GuestAllocationsand the mirror in one PR; the mirror (off by default) and the refresh changes (on by default) are two topics and should be two PRs, so the default-on part can be measured and merged on its own.APS5_SPAN_MIRROR=1and once without, noAPS5_PROFILE_*.Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-17T00:05:16Z.
Data point from a CPU-bound scene on Windows: RTX 3060 12 GB (NVIDIA 617.42), i5-12400F, Windows 10 19045, MinGW GCC Release. Minecraft Dungeons II (PPSA16064 01.100.100), title screen, no input, 200 s rows,
APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1;mainaf0fff762vsmain+ this PR, interleaved with five other PRs in one batch, two rounds. FPS is the mean of the last 10[present]windows, GPU busy and idle gaps per frame over the last 8. This scene is CPU-bound on this machine (44-47 ms of idle gaps per frame).mainWithin the run-to-run spread (
mainitself moved 6.61 -> 6.76 between rounds), no regression, 0 fatal.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T06:48:17Z.
A profile from another title where this path is the largest committer cost; it doesn't measure this PR. Metal Gear Solid 4 (PPSA18194), Ubuntu 24.04, i7-13700K, RTX 4070 Ti (595.99.02), Release, pad input.
main0dc15620d2plus what MGS4 needs here (#6814, #6842, #6237) and #6917. In this scene the queue-0 committer holds the GPU mutex for about 7.9 s of every 10 s (APS5_PROFILE_DRAW, 124k commits per 10 s), so its per-draw CPU time sets the frame rate.perf record -F 199 --call-graph dwarffor 6 s at 225 s; of the 555 samples withDrawPipeline::runon the stack (inclusive):HostImportForrefreshImportsInPlaceDrawInput(fromprepareDrawInputs)sameRange(HostImport, Lease)importRun(Lease, ...)GuestAllocations::Lease::heldSo most of it is the import refresh re-walking runs on each draw's input lookup, which your incremental refresh and per-lease run memo target. I haven't run this PR on MGS4 yet. I can if that's useful, but MGS4 needs those three PRs on top.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-17T10:37:42Z.
Thanks. I measured each part on its own, and the PR is now one topic. I force-pushed it down to the part that is on by default and measurably faster: the run memo (
ae409e197, on currentmain). The title and description changed accordingly. What happened to the rest:Kena (PPSA01802), forest title scene, no input.
mainf8b22edfb+ each part, warm cache,APS5_TRACE_SECONDS=100:30, three rotated rounds per batch. Linux 7.2.9, RX 9070 XT, RADV Mesa 26.2.4.mainAPS5_NO_INCREMENTAL_IMPORT_REFRESH=1APS5_SPAN_MIRROR=1(another batch)spaceReadListtwice in six parallel ctest runs, which neithermainnor this version does. On the remap test you asked for: an unmap or remap of an imported range can't leave a stale import, journal or not, because the pin waiter retires imports over a range before a mutation changes it. What the refresh does need to see is a run that grows next to an unchanged import. The new test covers that case and failed when the incremental refresh skipped its walk.APS5_SPAN_NO_FLUSH.UDMABUF_CREATE_LIST, and it was on by default, which the old description didn't make clear. It's out of this PR too. #4449 already implements the same idea (a dma-buf run list for scattered direct memory), so I won't open a competing PR. I'll post the Kena numbers there instead.Windows: this version touches no Linux-only code. I can't run the
agc_*suite on Windows here; the memo is plain C++ on the lease, the same on both.Measurement of this version (rotated with another build; one run of each reached a lighter stretch with 48 ms GPU busy instead of about 80 and isn't comparable):
mainSummary lines
The traces are kept locally; I can attach any of them.
ctest -R '^agc_'six times with-j16: 629 of 630 pass each time (agc_driver_tessellationsegfaults onmaintoo).AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T11:54:05Z.
Review: CHANGES_REQUESTED
Thanks for narrowing this to the memo. One correctness problem before it can merge:
GuestBufferMemory.cpp:1301-1309: the memo is keyed on&lease[0]+ size + index + window and validated only against the first and last range of the run. Each registry invalidation builds a newLease::Rangesvector (GuestAllocations.cpp:636-642) and the old one is freed when its last lease is released, so a later snapshot can be allocated at the same address with the same size (unmap one range, map another). If a middle range of the run, or the neighbour just outside it (first - 1/last + 1, which decides whether the run extends), is a different range in the new snapshot, the stale bounds still pass the check and the import covers the wrong memory.GuestAllocationsGeneration()read when the lease was acquired (or hold ashared_ptrto theRangesvector in the entry so its address cannot be reused while the memo refers to it).BdaResources.cppimportRunGrowthTestsonly covers a size change. Add a case where a range is unmapped and a different one mapped so the vector keeps its size, and the run must change.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-19T13:47:27Z.
Isolated author-fix benchmark, 2026-10-19: main
8444508241a9e4a6f5d5604d007451ce62d39cc0versus main plus only this PR at author heada69514fe75bf0baa30c1e19a144ea10b3ec43606(local candidate71b4f9bcedd4c67d5c397e4a586991ff3fdf1d36). Original authorship preserved; no #7938, #6321, #6617 or separate local correctness amendment included. Exact candidate branch.PPSA05347, Record of Lodoss War: Deedlit in Wonder Labyrinth, stationary initial forest tutorial, HP100/100. Same Ryzen 9 7950X / RX 6650 XT / RADV Mesa 26.2.4-arch1.1 / Linux 7.2.9-arch1-1.
+23.37% FPS in this single ordered main/candidate pair. Independent initially empty per-source shader/Mesa caches, owned by the game user before launch; 195-second warm-up, then fresh 250-second measured process. Identical scripted inputs, no movement at checkpoint, only
APS5_TRACE_SECONDS=200:30among tracing/profiling switches, measured stdout on a real PTY. Same 1536×864 logical window on DP-2, 3072×1728 swapchain; official trace reports 3840×2160. The 190/240-second screenshots show matching scenes and readable tutorial text, with no obvious rendering difference.All four processes exited 0 and are gone; temporary kernel limit restored to 64 MiB. Both measured runs retain four existing storage-image GPU-results-pending shutdown warnings. No VUID, assertion failure, abort or segfault in measured terminal output. The same four focused tests pass on main with regression tests and on the candidate, Vulkan required, shader cache disabled, Khronos validation enabled, with no skips or missing-layer/VUID messages; conventions pass. One scene and one ordered pair do not establish statistical significance, long-session stability, console-equivalent behavior or gains in other titles.
Official summary lines from both complete traces:
Main trace · Candidate trace · Main digest · Candidate digest · Evidence: exact patch, commands, logs, reports, screenshots and checksums
AI-assisted: yes. Earlier pinned evidence follows.
Refresh with author fix
a69514fe75(2026-10-19): switched the local integration to your current snapshot-identity implementation; my earlier amendment below is historical and is no longer needed in this integration. Refreshed branch, head225a1f9fe075439adfc7b1ab50188eee195a9c1b, is main48790e0233fd2237aac77f25683339d3bc0d4c8f+ #7938 + your two current commits + #6321. Original authorship is preserved.The same four focused tests (
agc_driver_graphics,guest_memory,guest_mmap_fixed_anonymous,MemoryPoolTest) pass on main with the allocator/snapshot regressions added, on the refreshed composition, and withAPS5_NO_RUN_MEMO=1. RX 6650 XT, RADV Mesa 26.2.4-arch1.1, Linux 7.2.9-arch1-1; Vulkan required, shader cache disabled, Khronos validation enabled. No skips, missing-layer messages, orVUID-errors. Conventions pass. Exact commands, verbose logs and source patch.This is refreshed composition/correctness evidence, not a new performance measurement or an isolated measurement of this PR. The earlier benchmark remains pinned to its earlier sources. AI-assisted: yes.
Update 2026-10-19: snapshot-identity correctness amendment and an incremental composition test.
I reproduced the same-count snapshot replacement problem raised in review. An extracted-helper repro reuses the lease vector address, count and endpoint pointers after replacing a middle range with a writable range: cached bounds remain
0:2, while fresh bounds are0:0.The attached amendment adds an immutable snapshot owner-identity check using a
weak_ptrandowner_before. It keeps the existing memo algorithm, reserves control-block identity without pinning the snapshot or mapped ranges, and invalidates hits when the registry publishes a different snapshot. It also adds a lease-identity test, a graphics regression alternating the middle range's protections, and the missing environment-variable documentation.The actual
agc_driver_graphicsregression fails when only the snapshot-identity hit condition is removed and passes when it is restored. The isolated repro likewise fails before and passes after. These are correctness tests; the earlier performance result below does not establish correctness.Amendment patch · Evidence bundle: reproduction sources, red/green logs, focused test logs, protocol, six screenshots, reports, digests and hashes
Current composition experiment on PPSA05347, Record of Lodoss War – Deedlit in Wonder Labyrinth, stationary initial forest tutorial, HP100/100:
6e3f0020b16d0890226118645042fec3d5e9ea65= upstream main43a2abaf775337665afb5d32ba0c39cbd4469d2c+ allocator PR #7938.effb226e3ee903a0ad15131e8d9e90613f9d7cf6= base + this PR's unchangedae409e197880b67df18090076e7206b9a256d491(local cherry-pick7b6edf19ffda1ff98aa8d73ed6bf37fa1c5890f5) + the snapshot-identity amendment.+14.86% average FPS in this single matched pair. This is the incremental contribution above #7938, not a main-versus-combined result or a general gameplay claim.
Same Ryzen 9 7950X / RX6650XT / RADV Mesa26.2.4-arch1.1 / Linux7.2.9-arch1-1. Each arm used separate initially empty shader/Mesa caches, a 195-second warm-up, then a fresh 250-second measured process. Identical scripted inputs, no movement at checkpoint,
APS5_TRACE_SECONDS=200:30, no other profiling flags. Measured stdout inherited a real PTY without redirection. Same 1536×864 logical window on DP-2; the protocol records the 3072×1728 swapchain and trace-reported 3840×2160 separately. Pipeline1, SPIR-V full, draw cache4096 and host import16384MiB matched. All four processes exited0 at scheduled close, no surviving game PID, temporary udmabuf8192MiB restored to64MiB.Six screenshots show the same scene, readable tutorial and HP100/100 without an obvious rendering difference. Both measured runs printed a
vkAllocateMemory (-1000072003)host-import failure with fallback to copies. This does not establish long-session stability or Windows/macOS correctness.On the same Linux/GPU, the base and corrected candidate passed
agc_driver_graphics,guest_memory,guest_mmap_fixed_anonymousandMemoryPoolTest, withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationand verbose ctest logs. No missing-layer warning orVUID-was found in either log. Conventions check passed. The peer implementation remains credited to its author; this is a supporting amendment and test report, not a duplicate implementation PR.Summary lines from the two traces:
Base trace · Candidate trace · Base digest · Candidate digest
Historical pure-main comparison (unchanged; prior source pin and shorter capture):
Supporting performance test on PPSA05347, Record of Lodoss War – Deedlit in Wonder Labyrinth, stationary initial forest/tutorial checkpoint.
Tested pure main
5eba12d6bd3f4f2a2b1beee872f66cbd2b09d894against that main plus only this PR's commitae409e197880b67df18090076e7206b9a256d491(local cherry-pick5dd45a70f40b5df972e45e762b26fad61586025b). No diagnostic instrumentation or other peer changes.This single pair measured +17.5% average FPS in this scene.
Graphics.Drawfell from 6.883 to 2.735 ms/present andDriver.Packet.device_lockfrom 9.515 to 4.287 ms/present. This is supporting evidence for this title/scene, not a claim about all gameplay or other titles.Same machine/session: Ryzen 9 7950X, RX 6650 XT / RADV NAVI23, Mesa 26.2.4-arch1.1, Linux 7.2.9-arch1-1. Both used independent initially empty shader/Mesa cache directories, ran the scene once, then restarted for the measured warm-cache capture. Identical scripted inputs; no movement at the captured checkpoint. Screenshots at 190 and 210 seconds confirm matching camera, tutorial and HP 100/100. Same 1536×864 logical window on DP-2, 3072×1728 swapchain; the trace summary reports 3840×2160.
Only
APS5_TRACE_SECONDS=200:10was set among trace/profile switches. Measured game output stayed on a real PTY with no log redirection. Both traces are complete (trace_dropped=false). Both versions passed the same 12 focused tests withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1, andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, using the same RADV device: zeroVUID-messages and no missing validation layer. Warm-up and measured runs all exited 0 and restored the prior kernel setting. Existing GPU-results-pending storage-image teardown warnings remain; these short runs do not establish long-session stability.Summary lines from
aps5-summary.jsonl:Main trace · Candidate trace · Report · Evidence bundle: both trace digests, test logs, protocol, summaries and hashes
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T16:59:05Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-19T16:59:29Z.
@adriadam10 Fixed in a69514fe7, rebased on
maindbac9fa15(force-pushed).std::weak_ptrto the lease'sRangessnapshot (Lease::Snapshot(), a new accessor inGuestAllocations.hpp). A hit requires the same owner (owner_beforeboth ways), index, window and window block. While the entry exists, its weak reference keeps the snapshot's control block allocated, so a later snapshot can't take over its identity. It doesn't pin the ranges or the vector's contents. A snapshot is immutable, so the size and first/last range checks are gone.importRunReplacedTests(BdaResources.cpp, inagc_driver_graphics): three adjacent pieces, the middle one read-only, so the run at the first piece is one piece long. The test then replaces the middle piece four times, alternating writable and read-only, so the registry keeps three ranges. After each replacement the import must cover 3 pieces, then 1.APS5_NO_RUN_MEMO=1on the old code.APS5_NO_RUN_MEMOhas its row indocs/dev/ENVIRONMENT.md.agc_driver_*,guest_memory*andguest_mmap*pass on Linux 7.2.9, RX 9070 XT, RADV Mesa 26.2.4, Release, except four that fail the same way on plainmainhere (image_table_vouched_lookups,bda_device,guest_memory_lifetime,tessellation). The conventions check passes.@JJenkx thanks for reproducing it and for the Lodoss numbers. Your amendment uses the same weak-owner idea. I wrote the change on the rebased branch rather than applying the patch.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-19T19:40:57Z.
Current-main follow-up with DMA enabled in both builds, 2026-10-19: main
da3ea52b53d9d0fb0b4938035798de7c765a2341versus main plus only the two commits from author heada69514fe75bf0baa30c1e19a144ea10b3ec43606(local candidatea63eab2f850d686fe931e93c169ee681b0fe821f). Exact candidate branch.PPSA05347, Record of Lodoss War: Deedlit in Wonder Labyrinth, stationary initial forest tutorial, HP 100/100. Same Ryzen 9 7950X, AMD RX 6650 XT, RADV Mesa 26.2.4-arch1.1, Linux 7.2.9-arch1-1.
+13.63% FPS in one candidate/main ordered pair. This supports a gain on top of DMA in this scene; it is not a replicated or cross-title result.
Initially identical private warm shader/Mesa cache clones (file hashes included), identical scripted input,
APS5_TRACE_SECONDS=200:30, no profiling switches beyond the official trace, stdout on a real PTY. The window was 1536×864 on DP-2; the official trace reports 3840×2160. Both 190/240-second screenshot pairs show the same forest tutorial checkpoint, readable text and no obvious rendering difference. Both native processes and supervisors exited 0, the PIDs are gone, and the temporary kernel limit was restored to 64 MiB. Neither terminal log contains a VUID, assertion, segmentation fault or device-loss message.Focused correctness checks used required Vulkan, disabled shader cache and Khronos validation on both builds. All 18 selected cases executed with no skips or missing-layer messages. 17/18 pass on each build;
agc_driver_guest_memory_lifetimefails identically atguest prefix unmap failed, after a rejected GPU submission, and both logs containVUID-vkResetFences-pFences-01123. No additional failing case or new VUID appears with this PR. The partial-unmap issue is being checked separately against #7849. The enabled execution-source list and complete logs are included; this is not an all-green test claim.Official summary lines:
Complete traces, trace_digest outputs, summaries, scripts, manifests, focused/native logs and four screenshots. SHA-256:
3b0754b2f279a2442ff576b837089b2710792ceebde6b6f9c16f5f5e31588280.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-19T19:57:45Z.
Compatibility follow-up: #6951 retains its Lodoss benefit when combined with the partial-unmap lifetime correction in #7849. This is a comparison against main + #7849, not bare main.
Pinned upstream main:
8075b6af190ff8f83c1bff9a7f74cd71e5902140. Baseline68a90e7d8ccf8bb9f3bca3b1da1b99e530f60ab4contains only the three commits from #7849 author head1ead0f921b72b97d0acf9140a55179063a79090e; candidate5dab1820843d70b4323cf39de80d9452553eca00adds only the two commits from this PR ata69514fe75bf0baa30c1e19a144ea10b3ec43606. Exact patches and commit author log are attached.Same Ryzen 9 7950X / RX 6650 XT, RADV Mesa 26.2.4-arch1.1, Linux 7.2.9-arch1-1; PPSA05347 stationary initial forest tutorial, HP 100/100. DMA enabled in both, initially identical independent warm shader/Mesa cache clones, same scripted input and official
APS5_TRACE_SECONDS=200:30capture. Baseline ran first. Window 1536×864 on DP-2; official trace reports 3840×2160.+14.68% FPS in this single matched pair. This supports compatibility and a scene-specific benefit; it is not a replicated or cross-title claim.
Both builds: 18/18 focused tests pass with required Vulkan, disabled shader cache and Khronos validation, no skips, missing-layer messages or VUIDs. Both native runs exited 0 and closed, their PIDs are gone, and the temporary kernel limit was restored to 64 MiB. No VUID, assertion, segmentation fault or device-loss message in either native terminal log. The four 190/240-second captures show the same tutorial checkpoint with readable text and no obvious rendering difference; they cannot establish full gameplay correctness.
Official summary lines:
Traces, source patches, scripts, manifests, full test/native logs, reports and screenshots. SHA-256:
7c6289d68bb8a714ed55e5299d86ec27a1155ff4e9765847b097ac60fe3dff89.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T00:33:37Z.
Issue #8103 has a Windows repro where aligned import coalescing chooses a block that crosses ranges already outside write-watch, causing the resident 4x DCC color source to lose watch coverage. I have a local test-first candidate that filters coalesced runs by
GuestMemory::Watched; it touchesimportRun, which this PR is restructuring, plus a regression inBdaResources.cpp.I have not pushed or opened a competing PR. Would you prefer to consider this as a follow-up on your run-bounds change once that lands, or do you see a way to integrate the watch-coverage check cleanly here? I’ll keep the candidate local until we agree on the overlap and a Windows run can check the exact DCC case.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T11:35:19Z.
Review: CHANGES_REQUESTED
The snapshot-identity fix and
importRunReplacedTestsaddress the earlier point. What is left is a conflict withmainthat needs a design decision, so we can't rebase it for you:GuestBufferMemory.cppconflicts:mainrewroteimportRun(largestandbudgetparameters, the halving window sizes,leasedRun, and thefailedBlocks/refusalschecks insideskipped/stillRefused).importRunreturns now depends on state outside the lease snapshot:largest,budget,state.failedBlocks,state.refusalsandstate.liveBytes. The current key (snapshot, index, window, window block) would return a stale run after a refusal is recorded or cleared, or whenlargest/budgetdiffer between callers (sameRange,importAllocation, the import refresh).mainand either memoize only the part that depends on the snapshot (the first/last walk beforeskipped/largest), applying those checks to the memoized bounds on every call, or key on the extra inputs. Add a test where a refusal or a failed block is recorded for a run between two lookups on the same snapshot, and the run must shrink.importRunto filter byGuestMemory::Watched; rebase on whichever lands first.perflabel bot still asks for the two summary lines andtools/trace_digest.pyoutput in the PR; the comment above has the lines, please add the digest after the rebase.Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-20T17:10:44Z.
@adriadam10 Rebased on
main77e31219cas c3ac6b47f, one commit (force-pushed).continuedRunmemoizes the first and last index of the continuing ranges, keyed on a weak reference to the lease'sRangessnapshot, the containing index, the import window and the window's low end.importRunBoundsthen applieslargest,skipped(failedBlocks, andstillRefusedwith the caller's budget andliveBytes) and the halving block search on every call, asimportRunonmaindoes.importRunisleasedRunover those bounds.sameRange(both overloads),runCoversand the whole-runfindImportinimportAllocationcompare against the bounds without copying the run's range pointers.importRunFailureShrinkTests: an 8 MiB window of 64 KiB pieces is imported, the imports are cleared and allocations limited to 4 MiB. A lookup of the same address on the unchanged registry then fails the 8 MiB block, and the retry must shrink to the 4 MiB block; a later lookup must not import the failed block again. With theskippedcheck dropped from the block search it fails (checked withimportBlockFailureTestsdisabled, which otherwise fails first).importRunGrowthTestsandimportRunReplacedTestsare kept.tools/select_tests.pypicked 1652; 1649 pass.agc_driver_guest_memory_lifetime,agc_driver_image_array_window_past_layer_limitandagc_driver_tessellationfail the same way on plainmain77e31219chere.agc_driver_graphics_testspasses with and withoutAPS5_NO_RUN_MEMO=1.Performance, Kena: Bridge of Spirits (PPSA01802) 02.008.000, forest title scene from a fixed save, no input,
APS5_TRACE_SECONDS=100:30, RX 9070 XT / i7-13700KF, RADV Mesa 26.2.4, shared warm shader cache.main77e31219c, and with this PR alike, three map-time host imports fail atvkAllocateMemorywith-1000072003(VK_ERROR_INVALID_EXTERNAL_HANDLE) early in the boot, and the "failed 3 times in a row" rule lowers the budget to the 3 MiB then live for the rest of the session:host import budget: 0 MiB live of 0 MiB (lowered after vkAllocateMemory failed ...), about 2.3 M imports refused, 12 to 21 presents per 30 s with either build. So both builds below carry the same one-line local stand-in (not in this PR) that leaves the ceiling alone for that result.mainAbout +6 %, inside Kena's run-to-run spread; Kena is bound by
Driver.Packethere, not by the run walk. JJenkx's Lodoss pairs above are the case where it shows.memcpyin the game's own code read0x8f83fb8c0, which was not mapped (nothing within 64 MiB of it; destination0x2040), on the thread insceKernelBatchMap2. It didn't happen in the other five runs with this PR or in the six onmain. I can't tie it to this change, but I'm reporting it.Round 1 pair below. The
mainbuild was made in the same worktree withmain'sGuestBufferMemory.cppswapped in, so its line saysc3ac6b47ffb6,dirty. Both traces dropped worker events after about 6 s, so the per-thread times are partial.main77e31219c(+ ceiling stand-in): summary line andtools/trace_digest.pyseconds 100:30 from present 856: 334 presents, frame p50 89.7 / p90 95.5 / p99 109.3 / max 120.5 ms, GPU busy 47.2 ms per present
AMD Radeon RX 9070 XT (RADV GFX1201), radv Mesa 26.2.4-arch1.1, Linux 7.2.9-arch1-1, 3840x2160, commit c3ac6b47ffb6 (dirty), dropped: yes
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 72.9, Driver.Packet.memory_wait 57.2, batch 47.2, Driver.WorkerWait 31.5, Driver.WorkerWait.idle_and_completion_poll 31.5, Graphics.Draw 27.6
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
this PR c3ac6b47f (+ ceiling stand-in): summary line and
tools/trace_digest.pyseconds 100:30 from present 1016: 363 presents, frame p50 82.7 / p90 86.8 / p99 93.1 / max 93.9 ms, GPU busy 44.0 ms per present
AMD Radeon RX 9070 XT (RADV GFX1201), radv Mesa 26.2.4-arch1.1, Linux 7.2.9-arch1-1, 3840x2160, commit c3ac6b47ffb6 (dirty), dropped: yes
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 71.0, Driver.Packet.memory_wait 55.4, batch 44.0, Driver.WorkerWait 26.4, Driver.WorkerWait.idle_and_completion_poll 26.4, Graphics.Draw 23.7
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
@MarcZX10 Go ahead with your
GuestMemory::Watchedfilter on its own; there's no need to fold it in here. The filter checks state outside the snapshot, so with this PR it belongs inimportRunBoundsbesideskipped(run on every call), not in the memoized walk. Whichever lands first, the other rebases onto it.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-20T17:23:14Z.
Follow-up with a
mainbuild checked out at its own commit, so the summary lines carry77e31219c835andc3ac6b47ffb6(both dirty only from the same ceiling stand-in). Two more alternating rounds:main368, 336; this PR 348, 347 presents per 30 s. Over all rounds:main339 (8 runs), this PR 352 (7 runs), +4 %, so no measurable gain on Kena; the gain shows where the run walk is hot (Lodoss above). No crash in these four. The round-1 pair's summary lines are now in the PR description.main77e31219c:tools/trace_digest.pyseconds 100:30 from present 945: 368 presents, frame p50 80.3 / p90 89.5 / p99 104.2 / max 124.1 ms, GPU busy 43.3 ms per present
AMD Radeon RX 9070 XT (RADV GFX1201), radv Mesa 26.2.4-arch1.1, Linux 7.2.9-arch1-1, 3840x2160, commit
77e31219c8(dirty), dropped: yesSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 68.2, Driver.Packet.memory_wait 52.9, batch 43.3, Driver.WorkerWait 26.7, Driver.WorkerWait.idle_and_completion_poll 26.7, Graphics.Draw 23.1
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
this PR c3ac6b47f:
tools/trace_digest.pyseconds 100:30 from present 958: 348 presents, frame p50 84.1 / p90 99.2 / p99 107.0 / max 111.7 ms, GPU busy 45.6 ms per present
AMD Radeon RX 9070 XT (RADV GFX1201), radv Mesa 26.2.4-arch1.1, Linux 7.2.9-arch1-1, 3840x2160, commit c3ac6b47ffb6 (dirty), dropped: yes
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 84.0, Driver.Packet.memory_wait 62.8, batch 45.8, Graphics.Draw 28.2, Driver.WorkerWait 21.2, Driver.WorkerWait.idle_and_completion_poll 21.2
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T19:25:10Z.
@adriadam10 could you take another look at your change request when you have a moment? On the current head (c3ac6b47ff) your points look addressed to us: only the snapshot walk is memoized, refusals are rechecked on every call, and a refusal test was added. We also checked that a variant of the change that drops the snapshot identity from the memo key fails
importCrossingTests, so the key is covered by the tests. If anything is still open on your side, we'll follow up.