Repository navigation
Conversation
|
This pull request is labeled |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed exact head bdca440d390c7b833a14e15ee38664e16a902033 against its stated dependency #10423. The feature-flag comparison and attached traces are useful, but I found integration and validation gaps that need resolution before this can merge:
- The performance summaries compare
APS5_NO_RESULT_RECYCLE=1with recycling enabled in the same dirty build, and both report commit2ef1dd3bebef. That is a useful feature-flag ablation, but it is not the required two-commit base/change comparison. Please run the same scene on the #10423 dependency head and this exact PR head (or the agreed current integration base and this head), attach both trace captures, and put both distinct commit IDs in the summaries. The hosted product build/test jobs are currently skipped, so they do not supply this comparison. - Please coordinate the new retention path with #9989. That PR's current budget/trim walk counts
source->memoentries; this change adds a second 256-entrysource.maskedMemotable that owns fullRecompileResults and a per-thread pool retaining up to eight more full results. Those references and their vector capacities are outside the current byte accounting, so the configured memo budget would not bound the retained memory after these changes are combined. Update the accounting/trim behavior and add a test that exercises the bound with both tables and the recycle pool, or agree on an explicit integration order that resolves this before merge. - Please also reconfirm the interaction with #9049. Its current change reuses an evicted exact entry's bindings only when
use_count() == 1; the added masked table can keep a second reference to that same result, while this PR separately recycles the complete result when an entry is evicted. This can change when #9049's reuse path is eligible, contrary to the earlier expectation that the two optimizations add up. Coordinate with that author, declare the agreed dependency/order, and validate the combined path.
I did not run the GPU/AGC tests locally: this checkout has no usable configured full build, and the latest hosted Linux/Windows product jobs are skipped. I therefore have not independently validated runtime equivalence or performance.
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
@MarcZX10 Thanks, all three points hold, and the first one changed the picture.
The checklist now says |
|
A second title and a second vendor for this change: ASTRO BOT's Crash Site hub on Windows / AMD. The worker-side saving shows up clearly there too. The frame does not move, because on this title the draw committer bounds the frame rather than the queue 0 worker.
AI-assisted: yes (Claude Code). The runs were made on my machine. |
|
@Meh7an A third title for this change: GTA V (PPSA04264 01.011.001) on Linux / NVIDIA, where queue worker 0 is about 98 % busy in every 10 s window of the first two Story cutscenes. The result is the same as yours: the memo work drops, the frame rate does not move beyond run-to-run noise.
Cutscene 2, median of the 10 s windows:
Cutscene 1: 13.2 / 13.3 / 14.4 / 13.9 fps.
Why the patched path dominates in this title, in case it helps the design:
The four runs are attached, one zip each. Each holds the run's gta-10757-round1.zip AI-assisted: yes (Claude Code) |
|
Thanks for the clean, interleaved rerun. It resolves my earlier capture-comparison concern, and the result is appropriately described as no measurable frame-time change on those scenes; keeping this as a draft until there is a frame-level benefit makes sense. The planned stack has changed since your note: #9989 and #10423 are merged, while #9049 is closed. When you resume this PR, please rebase on current |
|
@Meh7an A title where this shows up in the frame, and a variant of the pool that kept the patch cost down here. Title and host. Crysis Remastered (CUSA18659, PS4 GCN), scripted scene in the first level. Windows 11 26200, RTX 2080 (driver 617.14), MinGW GCC 15.2, Release. The tree is This PR's head as is. Merged onto that tree, What worked. The pool is kept per source instead of per thread, and only for the variant that is patched next:
Measured on the same tree, with the base commit and the commit that adds this:
The presents are the last five 10 s windows of each run (345 to 395 s). The runs alternated, starting with base in two rounds and with the spare in three, and the ranges do not overlap. With Not done yet. A spare is not counted in the memo's byte budget. That is at most one result per source. To meet the review's budget and trim point, the trim could drop each source's spare and the held bytes could include it. I can attach the If you would like it, I can send the diff (about 25 lines in AI-assisted: yes |
|
@Meh7an @ntamas94 I tested a budgeted version of the per-source, same-variant spare proposal and put the integration patch on a review branch, based on main
Matched current-main/refinement validation on Linux/Ryzen 5 7640HS/Radeon 760M, private RADV 26.2.6/libdrm 2.4.133: the same eight focused tests pass on main, on the refinement, and with recycling disabled. These cover table snapshot reuse/unmasked, the three memo budget cases, prepared graphics, vertex fetch and pipeline library. Each run used Gameplay gain remains unknown. A separate Sons of Sparta demanding-route correctness check on the frozen four-change integration plus #10547, actual internal 1080p, exercised 52,743 reuses between pre/post checks with The branch is offered for integration/review of the ownership and budget work; performance validation remains pending. AI-assisted. |
|
@Meh7an @Filip722 A correction to my comment above, and the numbers for Filip's branch. The frame gain I reported does not hold. I ran those rounds while other desktop programs were running on the machine. On a quiet machine, in the same scene and on the same tree, I measured three arms in the order A B C C B A, using presents per 10 s over the last five 10 s windows of each run (345 to 395 s):
Every arm drifted down over the session (123 to 108). The symmetric order cancels the drift, and after that the three arms are equal. On this title the frame is bounded by the draw committer, the same as on ASTRO BOT and GTA V above: about 413k commits per 10 s at 20.6 µs each, and queue 0's worker waits in The worker-side saving holds, and Filip's budgeted version keeps all of it (
On this tree, with Filip's commit on it, AI-assisted: yes |
There was a problem hiding this comment.
Your own table shows no frame-time change on the Sonic 2 page, so for now this is a CPU-attribution change only, which matches keeping it as a draft.
One thing I would settle before it comes out of draft: the recycle list is thread_local and keeps up to RecycledResultsKept results per thread with their vector capacity intact, and *result = donor keeps whatever capacity the kept result already had. After a long run each worker can hold the capacity of the largest results it has seen, for the life of the process, and none of it is visible in ResultMemoBytes(). How many bytes does a worker hold after a long session, and does anything trim the list? The description proposes counting and trimming it with the memo during the integration with #9049; that seems like the part to land with this rather than after.
…URE_REPLAY A capture walks the SRT tape and evaluates every descriptor even when a draw only moved descriptors. With APS5_CAPTURE_REPLAY=1 (off by default) a prepared invocation's capture is rebuilt from the last capture of the same source and plan: the tape records, for every SRT slot, the address it read, the word and whether the slot was active, and the replay rereads exactly those addresses through the same SrtRuntime reader, so ShaderMemory records the same regions and applies the same pending-write handling a full capture does. Nothing read earlier is reused unread, so the draw cache's gates (pending GPU writes, labels, generations) need no second copy. The words feed the same snapshot finish as a full capture (finishSnapshot, split out of materializeSnapshot), then degamma, tables and SRT guards as before. Slot roles are flags, computed beside the pure flat slots and again when a plan is read from the disk cache (the format is unchanged): Descriptor (a descriptor dword is exactly the slot), Address (reaches an address argument of any raw read, including a V# whose records bound a constant-buffer read), Selector (a control-flow condition), Fill, Computed (feeds a descriptor dword through arithmetic) and Fixed (a plan the roles cannot classify). A changed word is accepted only when its slot has no flag but Descriptor; changed user data, any changed word with another flag, an unreadable or unmapped slot, an active descriptor slot the walk did not read, a descriptor the finish rejects, or a moved invalidation serial fall back to a full capture. Plans with image tables, a uniform fill, poisoned or null-root reads are not recorded. APS5_CAPTURE_REPLAY=shadow also runs the full capture and throws on any difference in descriptors, flattened SRT, user data, fill, poison, tables, user-data use or read trace. CaptureReplays(outcome) counts replays and each fallback reason; APS5_PROFILE_DRAW prints them every ten seconds as "[recompile] capture replay". Report for draft/stage-overhead-v3 (C4 follow-up), CPU only, no GPU or game in this session. Numbers rank changes on this machine; none is a speed claim. Commits on draft/stage-overhead-v3 (base 0ff0124, which is draft/stage-overhead-v2): - 9fd594d test(agc): stage fixture loading 8 V# and 1 T# through a table (real buffers, image, 40-word flattened SRT); --bench per phase (invocation, capture, materialize) for hit, moved buffer (memo churn at capacity) and moved image (true miss: 8000 distinct bases); --bench-churn for profiling. - 793383f perf(shader): image masking in the masked result memo. - this commit: replay prototype and fallback counters. Recompile gap (GTA: 7.1 us/packet, patch+Populate explain ~400 of ~1,240 ms per 10 s). perf (DWARF call graphs) of the moved-buffer churn case, samples under materializePreparedMemoized: vector<bool> copies of the donor's bindings 21%, operator new 15.5%, free 13.3%, releasing the evicted result 5.4% (together ~55%: the donor copy plus destroying the evicted result), snapshotHash 16%, the rest inlined (patch, insert, resultBytes). Cherry-picking boykopovar#10757 (reuse an evicted result's storage for the next patched result) locally, conflict resolved by hand, not pushed: churn materialize 1535 -> ~880 ns (-43%, three runs 868-887). boykopovar#10757 is the largest lever found for the gap; land it rather than a copy of it. Eviction itself: ~1 per result is the 4-way, 64-set table of each source refilling with snapshots that never recur (8.6% full hits against 82% patched); the 256 MiB global trim cuts to 3/4 per pass, so it runs rarely. Sizing and ways were not changed: no evidence here that more ways would raise the hit rate when descriptors move every draw. Remaining after boykopovar#10757: the snapshot hash (serial FNV over every descriptor and flattened word) and copy-assigning the donor's per-binding vector<bool> metadata. Image masking (793383f). Safety proof: the compiled result depends on an image descriptor's base only through "base is zero". The binding plan cache key (preparedBindingPlan) already omits word 0 and word 1's low byte except for that test; every base read in plan building (ConstantImageComponents, null-image checks, metadata flags) is that test; Populate copies the 8 words as they are (identity swizzle touches only word 3; inactive elements are zero); ShaderDataDwordsFor copies them into the registration-module metadata; color-target merge images come from the request. So the masked hash keeps dword count, available mask, base-is-zero, word 1 above the base byte and words 2-7, and the patch rewrites words 0-1 of each active element in the image binding and, for registration modules, in the shader data (push data or the ShaderData binding). Fixture: miss 2797 ns vs patched 1373 ns of materialize (4 runs each). GTA's 9.5% misses are an upper bound on what this reaches; which of them are image-only is unmeasured. Replay. Capture of the descriptor fixture: 3.6 us -> 1.70-1.76 us with APS5_CAPTURE_REPLAY=1 (hit, moved buffer and moved image alike). Cost when ineligible: the one-word pixel fixture whose user word changes every draw goes 1277 -> 1515 ns per stage (recording each capture plus a refused attempt), so eligibility decides whether it pays. Benchmark method: build/tests/agc_driver_stage_recapture_tests --bench, Release, GCC 13.3, Xeon @ 2.10 GHz VM, taskset -c 2, ANYPS5_NO_SHADER_CACHE=1, each binary with its own copy of build/core/libs/libs/unpatched via LD_LIBRARY_PATH (the test loads libSceAgcDriver.prx at run time). Fixture phases: 21 batches x 2000 draws after a warm-up batch, a fresh ShaderMemory per draw; median of four interleaved runs, range of run medians: measure (ns) before (9fd594d) after, replay off after, replay on descriptors hit capture 3639 [3560-4069] 3585 [3526-3657] 1698 [1651-1714] descriptors hit materialize 341 [331-347] 308 [302-314] 303 [299-307] moved buffer capture 3644 [3615-3688] 3771 [3654-3945] 1759 [1726-2505] moved buffer materialize 1402 [1372-1422] 1417 [1385-1466] 1353 [1343-1870] moved image (miss) capture 3658 [3589-3848] 3672 [3655-3718] 1756 [1736-2507] moved image (miss) materialize 2797 [2758-2953] 1373 [1370-1389] 1355 [1340-1857] pixel stage, new user data 1243 [1225-1261] 1277 [1236-1316] 1515 [1506-1538] InvocationFor 557 [548-651] 542 [525-560] 544 [540-603] Tests and mutations (StageRecapture.cpp; CTest modes default, verified, unmasked, replay_shadow, replay; 72 CPU tests pass, 29 need Vulkan and skip; the agc_shader suites also pass with APS5_CAPTURE_REPLAY=shadow exported; check_conventions passes). Every mutation below was run under the stated modes: image (default, verified, unmasked modes): I1 masked hash drops word 1 above the base byte KILLED I2 masked hash drops words 2-7 KILLED (height-only change) I3 masked hash drops base-is-zero KILLED I4 patch skips word 1 KILLED (base bit 40) I5 patch skips registration metadata KILLED I6 full hash drops images SURVIVED: the T# words are also in the flattened SRT, which the full hash covers I7 patch skips word 0 KILLED I8 metadata patch one word early KILLED replay (shadow and replay modes): R1 replay accepts a changed address word KILLED (two-tables swap) R2 roles skip address cones KILLED (two-tables swap) R3 replay keeps old descriptor dwords KILLED R4 replay ignores changed user data KILLED R5 tape records no slot words KILLED R6 replay writes flattened words of inactive slots SURVIVED: no fixture with control flow that reads an inactive slot for a descriptor R7 roles treat computed dwords as identities KILLED (s_and_b32 fixture) The riskiest failure, old addresses after a pointer moves while variant and bindings match, is the two-tables test: the root word is an Address slot, so the swap is refused ("address word") and the stage binds the second table's V#; R1 and R2 make it bind the first table's and fail, and shadow mode reports the buffer difference. Not run or unverified: - No GPU: no ANYPS5_REQUIRE_VULKAN or validation-layer runs, no VUID comparison; prepared shader/graphics tests and fusion skip. - No game: GTA eligibility, fallback mix and frame effect unmeasured. A boot with APS5_CAPTURE_REPLAY=1 (or shadow) and APS5_PROFILE_DRAW=1 prints replays and every fallback reason per 10 s; shadow throws on the first mismatch. - Replay hooks only PreparedShaderInvocation::Capture (draws and dispatches through CaptureInvocation); CaptureResources and the dispatch-ahead paths still walk. - One recipe per source: a shader drawn alternately with two SRT layouts refuses every other draw. - Replay reads each word without the descriptor scope the walk opens around multi-word descriptor reads; the invalidation serial is checked before and after, and shadow mode is the guard until measured. - Selector, fill and inactive-slot paths have no CPU fixture (R6). - boykopovar#10757 measured only as a local cherry-pick; boykopovar#14266 (sealed feature digest) not applied; InvocationFor still spends ~200 ns on the digest with test targets. - ShaderDiskCache's IrResourcePlan layout guards now expect 776 bytes and 26 fields (two derived fields recomputed at decode); checked on Linux GCC only, not on MinGW. - No Windows build, no ASan/TSan, no full test suite. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011mLh2bAPqp631cncf3kCbJ
Each replay fixture's plan is encoded and decoded with the disk cache's EncodePlan and DecodePlan, and the roles, source dword slots and replay eligibility derived after the load must equal those of the built plan, so a warm start replays exactly what a cold one would. Report for draft/stage-overhead-v4 (C4 v4 brief), CPU only. Numbers rank changes on this machine; none is a speed claim. Per-frame figures use the brief's GTA rates: 4,100 stages, 3,362 patched, 388 misses, 352 hits; 1 us per capture = 4.1 ms, per patched result = 3.36 ms. Checked against main first: upstream main moved 87 commits since v3's base; none touches the replay, memo or capture code except boykopovar#13517 (disk cache key pair hash). boykopovar#10757, boykopovar#14266 and boykopovar#9899 are still open. Commits (base bbed4ea = v3): - 03abbc4 fix(shader): replay proves its reads, keeps span sync, rolls back refusals; static eligibility; no SourceEntry cycle; oracle tests. - this commit: disk cache round-trip of derived roles. Items, ranked by ms per frame: 1. Capture (brief items 1, 2, 3, 4, 6). Replay on the descriptor fixture: capture 3.6 us off -> 2.46 us on (3 interleaved runs each, medians 3547/3607/3589 vs 2336/2460/2473 ns for hit, moved buffer, moved image). Upper bound if every stage were eligible: 1.1 us x 4,100 = 4.6 ms per frame; the eligible fraction is unmeasured. v3 reached 1.7 us; the 0.75 us difference is the price of the fixes below (span scoped descriptor reads, read journal). A statically ineligible stage now costs one branch and a relaxed counter: the one-word pixel stage 1267 ns off vs 1280 ns on (v3: +19%). - P1 unrecorded reads: fixed. A plan is ineligible when any memory read reachable from a descriptor, condition or address cone is not a recorded slot (dynamicReads included), decided once per plan (IrResourcePlan::replayEligible, recomputed after a disk cache load). Shown by: the static+runtime-offset fixture reports "ineligible plan" and matches the oracle; mutation V1 (drop the check) fails it. - P1 span sync: fixed. Descriptor words are reread first, in source order, under the span the tape opens. Shown by: with pages read word by word, the set of (address, bytes) pending-write queries of a replayed draw equals an independent full capture's; mutation V2 (span 0) fails it. - Found by the new oracle, not in the brief: a refused replay left its reads in ShaderMemory, so after a pointer swap the draw recorded the old table's words as regions the draw cache would validate. Fixed with an SrtRuntime read journal over ShaderMemory's read/recent masks, rolled back unless replay commits. Mutation V3 (always commit) fails the pointer-swap region check. - P2 cycle: fixed; SourceEntry keeps plan, recipe, user-data use and read trace only. Recipe bytes are still outside the memo budget (one recipe per source, a few hundred bytes). - Item 4, a compiled capture plan replacing the tape: not done. I disagree that it should replace guarded replay as the next step: the tape's own evaluation is ~25% of capture in the fixture profile (compute + Run + evaluate), reads through ShaderMemory and the walk's bookkeeping are the rest, so a faster evaluator that still re-derives every address and branch bounds out near 1 us of 3.6. Guarded replay keeps addresses and branches only behind equality of every word that produced them (now proven complete statically) and still reads every word. If eligibility in GTA turns out low, the compiled plan is the next lever; it shares the role analysis built here. - Item 6 oracle: done. Oracle() captures through CaptureResources (never replayed) on its own ShaderMemory, materializes without the memo, and the test compares results, descriptor words, every region read (address and bytes) and the pending-write spans queried. 2. Patched path (item 5), 3,362 per frame. Churn materialize 1.41 us (descriptor fixture, every insert evicting). perf: ~55% donor deep copy (vector<bool> metadata, new) and freeing the evicted result, 16% hashing. boykopovar#10757 cherry-picked locally earlier: 1535 -> ~880 ns (-43%), ~2.2 ms per frame at GTA's rate; it remains someone else's open PR, not pushed here. Experiment (not committed): not inserting patched results into the exact memo at all leaves churn materialize unchanged (1408 vs 1424 ns medians of 3): the copy is destroyed later by its consumer instead, so admission alone saves no CPU; only avoiding the deep copy does. The payload split (shared module and layout, a structural binding template, a per-invocation payload of descriptors, user data and flattened SRT) is the right design but touches ~200 uses of DescriptorBinding's per-element metadata across the driver, which this CPU-only session cannot exercise; not started. Expected effect if the template holds the ~20 metadata vectors: the copy shrinks to the payload words, i.e. most of the 55%. 3. Exact key compare (item 8), predates us. Memo lookup trusts a 64-bit FNV hash. An exact compare needs the key words kept per entry: one copy per insert (~3,750 per frame) and one compare per hash hit (~3,714 per frame). At memcmp speed (~0.1-0.2 ns per word vs ~2.4 ns per word for the serial hash, from the profile) and an estimated 100 to 500 key words per GTA snapshot: ~0.04-0.4 ms per frame CPU, plus 65-73k entries x 0.4-2 KB = 26-140 MiB of memory. Collision risk of a good 64-bit hash is negligible, but FNV over 32-bit words mixes differences only upward. Not changed; a cheaper hardening is a stronger 64-bit mixer at equal cost. 4. Image masking (kept from v3): miss 2.8 us vs patched 1.37 us of materialize in the fixture, at most 388 x 1.4 us = 0.54 ms per frame. Tests and mutations (StageRecapture.cpp, CTest modes default, verified, unmasked, replay_shadow, replay; 72 CPU tests pass, 29 Vulkan-only skip; agc_shader suites also pass with APS5_CAPTURE_REPLAY=shadow; check conventions passes): V1 roles miss unrecorded reads KILLED (static+runtime offset) V2 descriptor reads without span KILLED (span query sets) V3 refused replay keeps its reads KILLED (pointer swap regions) V4 every plan eligible KILLED V5 (R6) inactive slot takes reread word SURVIVED: no fixture evaluates a slot whose flat output is inactive V6 changed selector accepted KILLED (branch fixture) R1, R2, R3, R4, R5, R7 KILLED (rerun on v4) D1 disk decode skips slot roles KILLED (round trip) New fixtures: runtime offset beside a static descriptor, branch on a table word (selector on and off, buffer moved while off), pointee moved behind an unchanged pointer, one buffer both bound and the address and bounds of another descriptor read (Descriptor and Address roles on one word). Not done or unverified: - Item 7 partly: pending descriptor writes across page crossings and forced-sync retries, image masking breadth (storage and atomic aliases, repeated storage mips, inactive registration heaps, MSAA/FMASK, tiling, constant swizzles, target merges), lifetime tests. - R6 fixture; selector-dependent flat activity. - Item 4 compiled plan and item 5 payload split (reasons above). - No GPU: no Vulkan or validation-layer runs. No game: eligibility, fallback mix and frame effect unmeasured; a boot with APS5_CAPTURE_REPLAY=shadow APS5_PROFILE_DRAW=1 prints replays and each fallback reason per 10 s and throws on the first mismatch. - Disk cache layout guards (776 bytes, 27 fields) checked on Linux GCC only; no Windows, ASan, TSan or full suite. My own best idea: measure eligibility first. If most GTA stages refuse on user data (per-draw SRT pointers from a ring), extend recipes to treat a user-data pointer word as an Address root that may change when the pointee layout is identical, by keying recipes on (plan, pointee offsets) and rereading through the new base; that turns the common "same table layout at a new ring address" case from a refusal into a replay without freezing any address, and it uses the same journal and oracle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011mLh2bAPqp631cncf3kCbJ
|
I hit the same allocation/destruction path in a Linux Wobbly Life CPU sample, so I refreshed your topic commit onto current main and tested an adaptation to the merged #9989 budget logic. Your branch is unchanged; this is a reference for this PR, not a duplicate implementation PR. Two-commit reference on main
CPU: main’s five focused snapshot/budget/concurrent-trim cases pass; the change’s six pass, including recycle-off, masking-off, existing budget cases and added strong/weak ownership checks. With the exact same fixture object linked against the original pool implementation, the weak-reference check fails ( Physical GPU: both main926 and the standalone change pass Source mbox, CPU/negative-control proof and paired GPU logs/JUnit, SHA-256 The matched Wobbly attempt stopped on its baseline at162.5s (guest null write/SIGSEGV, before the trace window); the candidate arm was never launched. There is no valid title pair from that attempt. The separate Afterdream standalone-candidate smoke completed successfully (details below). No FPS gain or paired title performance result is claimed here. Raw native CPU samples, proprietary game code/data and native game logs stay private. Additional native smoke: standalone head |
|
Closing as superseded by #16234 (merged 2026-11-07). It stops inserting donor-patched results into the exact memo, so there is no eviction left to recycle, and it removes the sizing, insert and free that this PR only made cheaper. I redid the recycle on top of #16234 as a per-source pool of released patched results (counted in the memo budget and trimmed first) and measured it on S3K, same machine and scene, worker sampler windows: creation plus release 361 to 365 samples, finishDraw 24.5 to 24.6 ms per frame, FPS 19.28 to 19.43. Flat, because the cost left is the element-wise copy of the donor, not the allocation. Nothing further to land here. |
What
This PR builds on #10423 (masked result memo). On a masked hit there,
materializePreparedMemoizedmakes a fresh copy of the donor result (std::make_shared<RecompileResult>(*donor)) and puts it into the exact table. The insert evicts the set's least recently used entry, and when that drops the evicted result's last reference, the result is destroyed on the worker, under the source's lock.A
RecompileResultholds dozens of vectors, and everyDescriptorBindingin it holds about twenty more. So each patched hit costs one full allocation of a result and one full free of another.On Sonic Origins Plus's Sonic 2 menu page with #10423 applied, the result memo evicts about 31,000 results per second. Sampling the queue worker (
APS5_SAMPLE_WORKER, 80 s on the page) attributes:operator delete, mostly the Windows heap's frees;This PR keeps the storage instead:
use_count() == 1under the source's lock, followed by an acquire fence), it moves the result into a small list owned by the calling thread (ThreadOwned, at most 8 results) instead of freeing it.*result = donor) instead of allocating one. The vectors keep their capacity, so most of the copy allocates nothing.applyMemoPatchthen writes the snapshot's words as before.ResultKeyMemo's assignment already clears the draw-key memo, so nothing of the old result survives.Nothing holds a
weak_ptrto aRecompileResult, so a result whose count is 1 under the lock cannot gain a new owner while it is reused. Every other owner (a recorded draw, the other table) keeps the count above 1, and that result is freed as before when its last owner drops it.APS5_NO_RESULT_RECYCLE=1frees every evicted result, as perf(shader): reuse a memoized result by patching its copied words #10423 does.ShaderRecompiler::RecycledResults()counts the reuses.agc_shader_table_snapshot_reusenow ends by patching the program for 640 distinct output buffers, enough to fill the memo and evict.agc_shader_table_snapshot_reuse_unrecycled(new) runs the test withAPS5_NO_RESULT_RECYCLE=1. It expects no reuse, and the two existing variants (default and_unmasked) still pass.Overlap.
tools/pr_overlap.pylists perf(shader): reuse an evicted memo result's bindings for the next miss #9049, feat(agc): GPU descriptor heap on VK_EXT_descriptor_heap (APS5_GPU_HEAP) #9508 and fix(shader): bound the bytes the recompiler's result memos hold #9989. Their conflicts are with lines perf(shader): reuse a memoized result by patching its copied words #10423 changes inRecompiler.cpp(the memo entries andmaterializePreparedMemoized). There is also theENVIRONMENT_MODIFICATIONtest list in the AGCCMakeLists.txt, where perf(shader): reuse a memoized result by patching its copied words #10423 and this PR add test names and feat(agc): GPU descriptor heap on VK_EXT_descriptor_heap (APS5_GPU_HEAP) #9508 edits the same line.materializePreparedMemoized, which perf(shader): reuse a memoized result by patching its copied words #10423 rewrites. The result fields they add are copied by the copy-assignment like every other member.ResultMemoBytes()and trimmed with the memo, with a test.Tested
Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 2080 Ti, driver 617.14, i9-9900K.
Sonic Origins Plus (PPSA05324), Sonic 2 page of the main menu,
main's defaults. Two clean builds onmaine7f46f5: #10423's head 54d7c78 and this PR's head bdca440. Each got one warm-up boot, then two interleaved traced rounds (APS5_TRACE_SECONDS=200:15):Driver.Packet(ms/frame)Driver.Draw(ms/frame)No frame-time difference within this page's noise. The page switches between a fast mode (p90 about 87 ms) and a slow one (about 116 ms), and each build landed in each mode once. Averaged, frame p50 goes 82.6 -> 82.4 ms and
Driver.Draw63.8 -> 62.8 ms.Why: the queue worker now waits on the draw thread. A sampled profile of the queue worker (
APS5_SAMPLE_WORKER, 80 s) shows:materializePreparedMemoizedgoing from 19 % to 14 % of its samples andoperator deletefrom 15 % to 9 %;DrawPipeline::Enqueueon a full draw queue growing from 11 % to 19 %.The CPU this PR saves turns into waiting, so on this page it cannot show as frame time until the draw thread gets faster. I'm keeping the PR as a draft until then and will re-measure.
The earlier flag A/B was noise. It ran
APS5_NO_RESULT_RECYCLE=1against the default in one uncommitted build (the traces say2ef1dd3beb, dirty) and read p50 89.2 / 84.2 -> 81.8 / 82.8 ms. Its first "off" round landed in the slow mode, which this clean rerun shows is noise. Its traces: recycle-s2-round1.zip, recycle-s2-round2.zip.No mismatches.
APS5_VERIFY_MASKED_RESULT_MEMO=1with recycling on: 0 patch mismatches over about 440,000 patched results.Tests
ctest(2064 tests) onmaine7f46f5 plus perf(shader): reuse a memoized result by patching its copied words #10423 plus this PR: everything passes exceptagc_driver_sample_order,agc_driver_sample_order_grid_referenceandagc_driver_sample_order_recipe_depth_locations, which fail the same way on plainmaine7f46f5 on this machine (as in perf(shader): reuse a memoized result by patching its copied words #10423).ctest --test-dir build -R "^agc_shader_|^agc_driver_draw_cache" -VwithANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation: 48/48 onmaine7f46f5, 49/49 with perf(shader): reuse a memoized result by patching its copied words #10423, and 50/50 with this PR (the extra one isagc_shader_table_snapshot_reuse_unrecycled). None of the logs haswas not found but was requested by env var VK_INSTANCE_LAYERSor aVUID-line.The summaries of all four clean rounds follow, then the full digests of round 1. All four traces are attached:
recycle-clean-s2-round1.zip
recycle-clean-s2-round2.zip
Round 1, #10423 54d7c78
seconds 200:15 from present 3354: 182 presents, frame p50 80.1 / p90 86.8 / p99 116.5 / max 137.9 ms, GPU busy 74.6 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit 54d7c78, dropped: yes
{"commit":"54d7c780a583","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"200:15"},"gpu":"NVIDIA GeForce RTX 2080 Ti","driver":"NVIDIA 617.14","os":"Windows 10.0.26300","cpu":"Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz","cpu_threads":16,"memory_mib":32684,"title_id":"PPSA05324","title":"Sonic Origins","content_version":"02.002.000","resolution":"3840x2160","window":{"spec":"seconds 200:15","first_present":3354,"ms":15050.577},"presents":182,"frame_ms":{"p50":80.127,"p90":86.84,"p99":116.533,"max":137.889},"gpu_busy_ms_per_present":74.62,"worker_busy_pct":{"queue worker 0x0":97.001},"top_phases_ms_per_frame":{"Driver.Packet":80.115,"Graphics.Draw":62.677,"Driver.Packet.draw":60.628,"Driver.Draw":59.584,"Graphics.Draw.draw_and_resource_release":52.265,"Driver.Draw.shader_compile_and_link":37.047,"VideoOut.Flip":32.487,"Driver.Present":32.397},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":6.102,"events_lost":386130,"totals_full":false},"draw committer":{"events_full_after_s":12.778,"events_lost":47537,"totals_full":false}},"trace":"aps5-trace-54d7c780a583-9420.json.gz"}Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 74.5, VideoOut.Flip 32.5, Driver.Present 32.4, VideoOut.Flip.present 32.2, Driver.Present.render_fence_wait 31.9, Vulkan.Retire 31.9, Vulkan.Retire.wait 31.9, Graphics.Draw 31.7, Graphics.Draw.draw_and_resource_release 26.1, Driver.Packet 17.5
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Round 1, this PR bdca440
seconds 200:15 from present 3333: 165 presents, frame p50 84.6 / p90 116.3 / p99 192.6 / max 193.5 ms, GPU busy 74.7 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit bdca440, dropped: yes
{"commit":"bdca440d390c","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"200:15"},"gpu":"NVIDIA GeForce RTX 2080 Ti","driver":"NVIDIA 617.14","os":"Windows 10.0.26300","cpu":"Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz","cpu_threads":16,"memory_mib":32684,"title_id":"PPSA05324","title":"Sonic Origins","content_version":"02.002.000","resolution":"3840x2160","window":{"spec":"seconds 200:15","first_present":3333,"ms":15011.098},"presents":165,"frame_ms":{"p50":84.575,"p90":116.336,"p99":192.64,"max":193.492},"gpu_busy_ms_per_present":74.693,"worker_busy_pct":{"queue worker 0x0":97.218},"top_phases_ms_per_frame":{"Driver.Packet":88.322,"Graphics.Draw":69.74,"Driver.Packet.draw":66.729,"Driver.Draw":65.594,"Graphics.Draw.draw_and_resource_release":58.618,"Driver.Draw.shader_compile_and_link":38.525,"VideoOut.Flip":30.932,"Driver.Present":30.913},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":6.173,"events_lost":385570,"totals_full":false},"draw committer":{"events_full_after_s":13.162,"events_lost":38828,"totals_full":false}},"trace":"aps5-trace-bdca440d390c-24144.json.gz"}Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 74.7, Graphics.Draw 38.8, Graphics.Draw.draw_and_resource_release 31.6, VideoOut.Flip 30.9, Driver.Present 30.9, VideoOut.Flip.present 30.8, Driver.Present.render_fence_wait 30.4, Vulkan.Retire 30.4, Vulkan.Retire.wait 30.3, Driver.Packet 22.3
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
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)