Skip to content

perf(shader): reuse an evicted result's storage for the next patched result - #10757

Closed
Meh7an wants to merge 2 commits into
boykopovar:mainfrom
Meh7an:perf/shader-recycle-patched-results
Closed

Meh7an wants to merge 2 commits into
boykopovar:mainfrom
Meh7an:perf/shader-recycle-patched-results

Conversation

@Meh7an

@Meh7an Meh7an commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What

This PR builds on #10423 (masked result memo). On a masked hit there, materializePreparedMemoized makes 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 RecompileResult holds dozens of vectors, and every DescriptorBinding in 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:

  • 13 % of its samples to destroying results, most of them in that eviction;
  • 15 % to operator delete, mostly the Windows heap's frees;
  • 4 % to the copy.

This PR keeps the storage instead:

  • When the memo evicts a result that nothing else references (use_count() == 1 under 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.
  • The next masked hit on that thread copy-assigns the donor into a kept result (*result = donor) instead of allocating one. The vectors keep their capacity, so most of the copy allocates nothing.
  • applyMemoPatch then 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_ptr to a RecompileResult, 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=1 frees 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_reuse now ends by patching the program for 640 distinct output buffers, enough to fill the memo and evict.
    • Each patched result must hold its own buffer's descriptor, recycled storage or not.
    • The counter must rise exactly when recycling is on.
    • agc_shader_table_snapshot_reuse_unrecycled (new) runs the test with APS5_NO_RESULT_RECYCLE=1. It expects no reuse, and the two existing variants (default and _unmasked) still pass.

Overlap.

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 on main e7f46f5: #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):

frame p50 (ms) p90 (ms) Driver.Packet (ms/frame) Driver.Draw (ms/frame) title FPS (median of six)
#10423 54d7c78 80.1 / 85.1 86.8 / 116.7 80.1 / 89.2 59.6 / 68.0 12.21 / 12.70
this PR bdca440 84.6 / 80.1 116.3 / 87.7 88.3 / 80.5 65.6 / 59.9 12.53 / 12.55
  • 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.Draw 63.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:

    • materializePreparedMemoized going from 19 % to 14 % of its samples and operator delete from 15 % to 9 %;
    • its wait in DrawPipeline::Enqueue on 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=1 against the default in one uncommitted build (the traces say 2ef1dd3beb, 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=1 with recycling on: 0 patch mismatches over about 440,000 patched results.

Tests

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 build summary
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
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
2 #10423 54d7c78 seconds 200:15 from present 3427: 164 presents, frame p50 85.1 / p90 116.7 / p99 126.9 / max 128.3 ms, GPU busy 77.4 ms per present
2 this PR bdca440 seconds 200:15 from present 3408: 181 presents, frame p50 80.1 / p90 87.7 / p99 114.6 / max 115.5 ms, GPU busy 74.3 ms per present

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)

  • present 3373: 137.9 ms at 1605 ms: batch (gpu) 131.7, Driver.Packet (queue worker 0x0) 96.4, Graphics.Draw (draw committer) 90.7, Graphics.Draw.draw_and_resource_release (draw committer) 85.4
  • present 3451: 116.5 ms at 7947 ms: batch (gpu) 75.4, Graphics.Draw (draw committer) 68.6, Graphics.Draw.draw_and_resource_release (draw committer) 63.6, VideoOut.Flip (presenter) 32.3
  • present 3403: 113.4 ms at 4064 ms: batch (gpu) 75.0, Driver.Packet (queue worker 0x0) 72.2, Graphics.Draw (draw committer) 66.5, Graphics.Draw.draw_and_resource_release (draw committer) 62.0
  • present 3495: 113.1 ms at 11690 ms: batch (gpu) 75.1, Graphics.Draw (draw committer) 68.8, Graphics.Draw.draw_and_resource_release (draw committer) 62.8, VideoOut.Flip (presenter) 31.6
  • present 3485: 113.0 ms at 10850 ms: batch (gpu) 74.2, Graphics.Draw (draw committer) 68.1, Graphics.Draw.draw_and_resource_release (draw committer) 61.9, VideoOut.Flip (presenter) 30.0

Threads (ms per frame)

thread busy wait untraced in slices < 20 us largest
title 1.4 (2 %) 0.0 (0 %) 81.3 0.7 Shader.ResolveGraphicsStagesAbi 0.9, Shader.ResolveAbi 0.5
queue worker 0x0 17.5 (21 %) 0.0 (0 %) 65.2 75.6 Driver.Packet 17.5, Driver.EndSubmission 0.0
draw committer 33.3 (40 %) 0.6 (1 %) 48.8 48.3 Graphics.Draw 31.7, Recorder.Submit 1.1
title 0.4 (0 %) 0.0 (0 %) 82.3 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.2
title 0.4 (0 %) 0.0 (0 %) 82.3 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.2
title 0.4 (0 %) 0.0 (0 %) 82.3 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.2
title 0.4 (0 %) 0.0 (0 %) 82.3 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.1
presenter 0.7 (1 %) 31.9 (39 %) 50.0 0.0 VideoOut.Flip 32.5, Driver.Present 0.2
title 0.5 (1 %) 0.0 (0 %) 82.2 0.1 Shader.ResolveGraphicsStagesAbi 0.3, Shader.ResolveAbi 0.2
title 0.3 (0 %) 0.0 (0 %) 82.4 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.1
title 0.4 (0 %) 0.0 (0 %) 82.3 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.2
title 0.4 (1 %) 0.0 (0 %) 82.3 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.2
title 0.4 (1 %) 0.0 (0 %) 82.3 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.2
title 0.4 (1 %) 0.0 (0 %) 82.3 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.2
title 0.4 (0 %) 0.0 (0 %) 82.3 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.2
title 0.5 (1 %) 0.0 (0 %) 82.2 0.1 Shader.ResolveGraphicsStagesAbi 0.3, Shader.ResolveAbi 0.2
gpu 74.5 (90 %) 0.0 (0 %) 8.2 0.0 batch 74.5

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

  • Driver.Present.render_fence_wait (presenter) 87.9 ms at 1417 ms, present 3371
  • Driver.Present.render_fence_wait (presenter) 82.5 ms at 1330 ms, present 3370
  • Driver.Present.render_fence_wait (presenter) 78.7 ms at 1605 ms, present 3373
  • Driver.Present.render_fence_wait (presenter) 70.6 ms at 1524 ms, present 3372
  • Driver.Present.render_fence_wait (presenter) 68.2 ms at 1248 ms, present 3369
  • Driver.Present.render_fence_wait (presenter) 60.5 ms at 1160 ms, present 3368
  • Driver.Present.render_fence_wait (presenter) 52.3 ms at 1074 ms, present 3367
  • Driver.Present.render_fence_wait (presenter) 40.8 ms at 992 ms, present 3366
  • Driver.Present.render_fence_wait (presenter) 35.8 ms at 7399 ms, present 3444
  • Driver.Present.render_fence_wait (presenter) 35.4 ms at 11605 ms, present 3494

Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)

  • batch 1354: 17.6 ms at 1649 ms, present 3373: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 1.3, Driver.Packet.dispatch (queue worker 0x0) 0.6, Driver.Dispatch (queue worker 0x0) 0.5, Driver.Packet.pipeline_drain (queue worker 0x0) 0.3
  • batch 7443: 15.5 ms at 8544 ms, present 3457: GPU no ranges; recorded by no CPU slices
  • batch 10023: 15.3 ms at 11604 ms, present 3493: GPU no ranges; recorded by no CPU slices
  • batch 9453: 15.3 ms at 10961 ms, present 3485: GPU no ranges; recorded by no CPU slices
  • batch 3280: 15.0 ms at 3818 ms, present 3399: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 1.3, Driver.Packet.dispatch (queue worker 0x0) 0.6, Driver.Dispatch (queue worker 0x0) 0.5, Driver.Packet.pipeline_drain (queue worker 0x0) 0.4

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)

  • present 3344: 193.5 ms at 947 ms: batch (gpu) 191.9, Driver.Packet (queue worker 0x0) 155.2, VideoOut.Flip (presenter) 122.9, VideoOut.Flip.present (presenter) 122.8
  • present 3333: 192.6 ms at 0 ms: batch (gpu) 156.2, Driver.Packet (queue worker 0x0) 118.8, Graphics.Draw (draw committer) 79.7, Driver.Packet.draw (queue worker 0x0) 76.3
  • present 3390: 133.7 ms at 5212 ms: Driver.Packet (queue worker 0x0) 108.2, Graphics.Draw (draw committer) 95.6, Driver.Packet.draw (queue worker 0x0) 93.9, Driver.Draw (queue worker 0x0) 91.9
  • present 3413: 121.8 ms at 7357 ms: Graphics.Draw (draw committer) 90.2, batch (gpu) 77.3, Graphics.Draw.draw_and_resource_release (draw committer) 61.1, VideoOut.Flip (presenter) 32.7
  • present 3478: 120.8 ms at 13148 ms: batch (gpu) 73.9, VideoOut.Flip (presenter) 23.8, VideoOut.Flip.present (presenter) 23.7, Driver.Present (presenter) 23.7

Threads (ms per frame)

thread busy wait untraced in slices < 20 us largest
title 1.5 (2 %) 0.0 (0 %) 89.5 0.7 Shader.ResolveGraphicsStagesAbi 0.9, Shader.ResolveAbi 0.6
queue worker 0x0 22.2 (24 %) 0.1 (0 %) 68.6 74.1 Driver.Packet 22.3, Driver.EndSubmission 0.0
draw committer 41.0 (45 %) 0.5 (1 %) 49.5 51.2 Graphics.Draw 38.8, Recorder.Submit 1.6
title 0.4 (0 %) 0.0 (0 %) 90.6 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.2
title 0.4 (0 %) 0.0 (0 %) 90.5 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.2
title 0.5 (1 %) 0.0 (0 %) 90.5 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.2
title 0.4 (0 %) 0.0 (0 %) 90.6 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.2
presenter 0.7 (1 %) 30.4 (33 %) 59.9 0.0 VideoOut.Flip 30.9, Driver.Present 0.2
title 0.5 (1 %) 0.0 (0 %) 90.5 0.1 Shader.ResolveGraphicsStagesAbi 0.3, Shader.ResolveAbi 0.2
title 0.4 (0 %) 0.0 (0 %) 90.6 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.2
title 0.5 (0 %) 0.0 (0 %) 90.5 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.2
title 0.4 (0 %) 0.0 (0 %) 90.6 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.2
title 0.4 (0 %) 0.0 (0 %) 90.5 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.2
title 0.3 (0 %) 0.0 (0 %) 90.7 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.1
title 0.5 (1 %) 0.0 (0 %) 90.5 0.1 Shader.ResolveGraphicsStagesAbi 0.3, Shader.ResolveAbi 0.2
title 0.4 (0 %) 0.0 (0 %) 90.5 0.1 Shader.ResolveGraphicsStagesAbi 0.2, Shader.ResolveAbi 0.2
gpu 74.7 (82 %) 0.0 (0 %) 16.3 0.0 batch 74.7

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

  • Driver.Present.render_fence_wait (presenter) 122.6 ms at 947 ms, present 3344
  • Driver.Present.render_fence_wait (presenter) 118.0 ms at 1141 ms, present 3345
  • Driver.Present.render_fence_wait (presenter) 71.0 ms at 1260 ms, present 3346
  • Driver.Present.render_fence_wait (presenter) 47.5 ms at 1355 ms, present 3347
  • Driver.Present.render_fence_wait (presenter) 34.7 ms at 7811 ms, present 3418
  • Driver.Present.render_fence_wait (presenter) 34.6 ms at 14200 ms, present 3489
  • Driver.Present.render_fence_wait (presenter) 34.5 ms at 6822 ms, present 3407
  • Driver.Present.render_fence_wait (presenter) 34.4 ms at 14286 ms, present 3490
  • Driver.Present.render_fence_wait (presenter) 34.4 ms at 1438 ms, present 3348
  • Driver.Present.render_fence_wait (presenter) 34.2 ms at 8639 ms, present 3427

Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)

  • batch 853: 32.2 ms at 1185 ms, present 3345: GPU no ranges; recorded by Graphics.Draw (draw committer) 0.8, Graphics.Draw.draw_and_resource_release (draw committer) 0.7, Resources.Prepare (draw committer) 0.1, Recorder.Submit (draw committer) 0.1
  • batch 851: 30.3 ms at 1149 ms, present 3345: GPU no ranges; recorded by Graphics.Draw (draw committer) 1.3, Graphics.Draw.draw_and_resource_release (draw committer) 1.2, Recorder.Submit (draw committer) 0.0, Vulkan.DrawFromRecipe (draw committer) 0.0
  • batch 782: 29.8 ms at 975 ms, present 3344: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 0.5, Driver.Packet.dispatch (queue worker 0x0) 0.3, Driver.Dispatch (queue worker 0x0) 0.3, Vulkan.Dispatch (queue worker 0x0) 0.2
  • batch 780: 27.7 ms at 936 ms, present 3343: GPU no ranges; recorded by Graphics.Draw (draw committer) 2.4, Graphics.Draw.draw_and_resource_release (draw committer) 2.2, Recorder.Submit (draw committer) 0.1, Resources.Prepare (draw committer) 0.1
  • batch 836: 23.2 ms at 1101 ms, present 3344: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 0.4, Driver.Packet.draw (queue worker 0x0) 0.2, Driver.Draw (queue worker 0x0) 0.2, Driver.Packet.pipeline_drain (queue worker 0x0) 0.2

Checklist

@github-actions github-actions Bot added perf Performance change perf numbers missing perf pull request without a before and after summary line labels Oct 24, 2026
@github-actions

Copy link
Copy Markdown

This pull request is labeled perf, so it needs the summary line of a capture on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=1 with recycling enabled in the same dirty build, and both report commit 2ef1dd3bebef. 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->memo entries; this change adds a second 256-entry source.maskedMemo table that owns full RecompileResults 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.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 1368 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 1395 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 1896 docs/dev/ENVIRONMENT.md
PR 4472 docs/dev/ENVIRONMENT.md
PR 5371 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 5609 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 5925 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/shader/recompiler/Recompiler.hpp
PR 6186 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/ENVIRONMENT.md
PR 6188 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/shader/recompiler/Recompiler.hpp
PR 6192 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6209 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6235 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.hpp
PR 6280 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6412 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 6416 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6481 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6488 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 6808 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6924 core/shader/recompiler/Recompiler.cpp
docs/dev/ENVIRONMENT.md
PR 7085 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7275 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/ENVIRONMENT.md
PR 7395 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 7449 docs/dev/ENVIRONMENT.md
PR 7508 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7642 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
docs/dev/ENVIRONMENT.md
PR 7643 docs/dev/ENVIRONMENT.md
PR 7684 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 7689 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/shader/recompiler/Recompiler.hpp
PR 8246 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/ENVIRONMENT.md
PR 8592 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 8939 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 9289 docs/dev/ENVIRONMENT.md
PR 9345 docs/dev/ENVIRONMENT.md
PR 9356 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
docs/dev/ENVIRONMENT.md
PR 9387 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
docs/dev/ENVIRONMENT.md
PR 9457 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 9508 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
docs/dev/ENVIRONMENT.md
PR 9633 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 9712 docs/dev/ENVIRONMENT.md
PR 9749 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 9790 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 9852 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
docs/dev/ENVIRONMENT.md
PR 9897 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 9969 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 10049 core/shader/recompiler/Recompiler.hpp
PR 10193 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
docs/dev/ENVIRONMENT.md
PR 10351 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 10359 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 10442 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/ENVIRONMENT.md
PR 10443 docs/dev/ENVIRONMENT.md
PR 10652 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 10867 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 10894 docs/dev/ENVIRONMENT.md
PR 11435 docs/dev/ENVIRONMENT.md
PR 11436 docs/dev/ENVIRONMENT.md
PR 11483 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 11551 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 12544 docs/dev/ENVIRONMENT.md
PR 12746 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/ENVIRONMENT.md
PR 12790 core/shader/recompiler/Recompiler.cpp
PR 12828 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 12840 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/shader/recompiler/Recompiler.cpp
docs/dev/ENVIRONMENT.md
PR 12849 docs/dev/ENVIRONMENT.md
PR 12855 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 12863 docs/dev/ENVIRONMENT.md
PR 12944 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 12994 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 13148 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 13263 docs/dev/ENVIRONMENT.md
PR 13809 docs/dev/ENVIRONMENT.md
PR 13863 docs/dev/ENVIRONMENT.md
PR 13920 docs/dev/ENVIRONMENT.md
PR 13928 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
docs/dev/ENVIRONMENT.md
PR 13929 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
docs/dev/ENVIRONMENT.md
PR 14032 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 14217 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 14218 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 14260 docs/dev/ENVIRONMENT.md
PR 14262 docs/dev/ENVIRONMENT.md
PR 14561 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.hpp
PR 14853 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 14871 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 14944 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 15343 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 15456 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/ENVIRONMENT.md
PR 15529 docs/dev/ENVIRONMENT.md
PR 15548 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
docs/dev/ENVIRONMENT.md
PR 15555 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 15570 docs/dev/ENVIRONMENT.md
PR 15572 docs/dev/ENVIRONMENT.md
PR 15948 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 16217 docs/dev/ENVIRONMENT.md
PR 16260 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 16354 docs/dev/ENVIRONMENT.md
PR 16371 docs/dev/ENVIRONMENT.md
PR 16372 docs/dev/ENVIRONMENT.md
PR 16391 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 16427 docs/dev/ENVIRONMENT.md
PR 16472 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 16631 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 16753 docs/dev/ENVIRONMENT.md
PR 16793 docs/dev/ENVIRONMENT.md
PR 16812 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 16814 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 16831 docs/dev/ENVIRONMENT.md
PR 16935 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 16953 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/ENVIRONMENT.md
PR 17022 core/shader/recompiler/Recompiler.hpp
PR 17056 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 17259 docs/dev/ENVIRONMENT.md
PR 17261 docs/dev/ENVIRONMENT.md
PR 17338 docs/dev/ENVIRONMENT.md
PR 17347 docs/dev/ENVIRONMENT.md
PR 17555 docs/dev/ENVIRONMENT.md
PR 17556 docs/dev/ENVIRONMENT.md
PR 17557 docs/dev/ENVIRONMENT.md
PR 17558 docs/dev/ENVIRONMENT.md
PR 17611 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
docs/dev/ENVIRONMENT.md
PR 17652 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 17706 docs/dev/ENVIRONMENT.md
PR 17719 docs/dev/ENVIRONMENT.md
PR 17729 docs/dev/ENVIRONMENT.md
PR 17738 docs/dev/ENVIRONMENT.md
PR 17749 docs/dev/ENVIRONMENT.md
PR 17786 docs/dev/ENVIRONMENT.md
PR 17796 docs/dev/ENVIRONMENT.md
PR 17943 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/ENVIRONMENT.md
PR 18029 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/ENVIRONMENT.md
PR 18082 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/ENVIRONMENT.md
PR 18106 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 18107 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 18173 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/ENVIRONMENT.md
PR 18185 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 18226 docs/dev/ENVIRONMENT.md
PR 18243 docs/dev/ENVIRONMENT.md
PR 18293 docs/dev/ENVIRONMENT.md
PR 18369 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
docs/dev/ENVIRONMENT.md
PR 18390 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 18515 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
docs/dev/ENVIRONMENT.md
PR 18530 core/shader/recompiler/Recompiler.cpp
PR 18693 docs/dev/ENVIRONMENT.md
PR 18783 docs/dev/ENVIRONMENT.md
PR 18829 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/ENVIRONMENT.md
PR 18842 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 19054 docs/dev/ENVIRONMENT.md
PR 19119 docs/dev/ENVIRONMENT.md
PR 19130 docs/dev/ENVIRONMENT.md
PR 19429 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 19445 docs/dev/ENVIRONMENT.md
PR 19553 docs/dev/ENVIRONMENT.md
PR 19557 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/ENVIRONMENT.md
PR 19564 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 19610 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 19697 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/ENVIRONMENT.md
PR 19707 docs/dev/ENVIRONMENT.md
PR 19710 core/shader/recompiler/Recompiler.hpp
PR 19821 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.hpp
PR 19852 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 19883 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 19967 core/shader/recompiler/Recompiler.cpp
docs/dev/ENVIRONMENT.md
PR 20010 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 20030 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 20041 docs/dev/ENVIRONMENT.md
PR 20070 core/shader/recompiler/Recompiler.hpp
PR 20111 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 20130 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 20153 core/shader/recompiler/Recompiler.hpp
PR 20172 docs/dev/ENVIRONMENT.md
PR 20187 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
docs/dev/ENVIRONMENT.md
PR 20248 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
docs/dev/ENVIRONMENT.md
PR 20315 docs/dev/ENVIRONMENT.md
PR 20344 docs/dev/ENVIRONMENT.md
PR 20368 docs/dev/ENVIRONMENT.md
PR 20518 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.hpp
docs/dev/ENVIRONMENT.md
PR 20519 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
docs/dev/ENVIRONMENT.md
PR 20579 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 20631 core/shader/recompiler/Recompiler.cpp
PR 20756 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 20792 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 20830 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 20870 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 20878 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 20891 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 20899 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 20944 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 20982 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 21018 core/shader/recompiler/Recompiler.hpp
PR 21087 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/ENVIRONMENT.md
PR 21131 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 21156 docs/dev/ENVIRONMENT.md
PR 21180 core/shader/recompiler/Recompiler.cpp
PR 21211 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/ENVIRONMENT.md
PR 21225 docs/dev/ENVIRONMENT.md
PR 21238 docs/dev/ENVIRONMENT.md
PR 21240 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 21303 docs/dev/ENVIRONMENT.md
PR 21336 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp

@github-actions github-actions Bot added build shader core/shader docs agc libSceAgc* labels Oct 24, 2026
@Meh7an
Meh7an marked this pull request as draft October 24, 2026 23:48
@github-actions github-actions Bot removed the perf numbers missing perf pull request without a before and after summary line label Oct 24, 2026
@Meh7an

Meh7an commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Thanks, all three points hold, and the first one changed the picture.

The checklist now says Depends on: #10423, #9049, #9989, pending both authors' confirmation.

@QDarkRex

Copy link
Copy Markdown
Contributor

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.

  • Host: Windows 11 (26300), Ryzen 7 5700X, 32 GB RAM, Radeon RX 9060 XT, AMD driver 26.10.1, WinLibs GCC 15.2.0 r7, Release.
  • Builds: this PR's head bdca440 against its parent 54d7c78 (the perf(shader): reuse a memoized result by patching its copied words #10423 commit), so the A/B isolates the second commit.
  • Runs: ASTRO BOT PPSA21564 01.007.000, -lvl hub_crashsite, no input, 300 s each. One warm-up per arm, then two rounds in the order A B / B A. APS5_HOST_IMPORT_MIB=14336, APS5_TRACE_SUMMARY_EVERY=10, APS5_SAMPLE_WORKER and APS5_SAMPLE_COMMITTER were set in every run. Frame figures come from the 10 s windows from 120 s on. The worker shares are inclusive, as a fraction of all of the queue 0 worker's samples (about 19,000 per run).
Run Build FPS frame p50 Destroying a RecompileResult operator delete materializePreparedMemoized
1 parent 6.43 154.2 ms 5.43 % 5.83 % 10.18 %
2 this PR 6.39 154.8 ms 0.36 % 3.56 % 8.18 %
3 this PR 6.44 154.7 ms 0.42 % 4.27 % 9.34 %
4 parent 6.39 155.4 ms 6.15 % 6.54 % 11.52 %
  • Result destruction on the worker drops from 5.4–6.2 % to 0.4 %. operator delete drops by about 2 points, and the whole memoized materialize by about 2 points. As a share of the worker's non-blocked samples, materializePreparedMemoized goes from 28 % to 22 %.
  • On this scene the memo hits rarely before perf(shader): reuse a memoized result by patching its copied words #10423: on main 5d3ab77 with APS5_PROFILE_DRAW=1, the line reads 11739 hits, 173897 misses (6.3% hits) … 173878 evictions per 10 s. So nearly every draw stage takes the eviction this PR reuses.
  • FPS, frame p50 and GPU busy (100.7–101.0 ms per present) are the same in both arms. The queue 0 worker spends 29–30 % of its samples in DrawPipeline::Enqueue, waiting for the committer, so a worker saving does not reach the frame on this scene.
  • No errors in any run.

AI-assisted: yes (Claude Code). The runs were made on my machine.

@Tehshortbus

Tehshortbus commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

@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.

  • Host: CachyOS Linux (kernel 7.3.0-4-cachyos), Ryzen 7 5800X, 64 GB RAM, RTX 4070 SUPER (driver 615.78.08), GCC 16.2.1, Release.
  • Builds:
  • Tests: agc_shader_table_snapshot_reuse, _unmasked and _unrecycled pass on the cherry-picked build with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation; no VUID- line and no missing-layer message.
  • Runs: APS5_TRACE_SUMMARY_EVERY=10, a warm shader cache for each build (no misses), two rounds in the order B A / A B. Each window is counted from 10 s after the cutscene started.

Cutscene 2, median of the 10 s windows:

base, round 1 this PR, round 1 base, round 2 this PR, round 2
fps 5.0 5.8 5.9 5.5
frame p50 (ms) 192.6 159.7 165.1 168.5
Driver.Packet (ms/frame) 186.4 161.9 160.8 174.3
Shader.DrawStage.materialize (ms/frame) 35.9 31.0 34.7 29.0

Cutscene 1: 13.2 / 13.3 / 14.4 / 13.9 fps.

  • Shader.DrawStage.materialize is 14 to 16 % lower in both rounds, about 5 ms of a ~165 ms frame. The same build moves by more than that between runs (base 5.0 → 5.9 fps), so there is no measurable frame-time change. The largest phase is Graphics.Draw.draw_and_resource_release, at 94 to 115 ms per frame.

Why the patched path dominates in this title, in case it helps the design:

  • Counters. With APS5_PROFILE_DRAW on the base, the memo reports per 10 s in the cutscenes:

    • 3–8 % hits and 81–87 % patched (about 230,000);
    • about the same number of evictions;
    • about 40,000 results held, 200–250 MiB.
  • Probe of 7,392 lookups in a replay of a 4-frame cutscene-1 capture (temporary instrumentation, not in any branch):

    • 91 % of exact keys never recur, so a larger exact table would not help;
    • 1,325 masked keys cover all of the lookups.
  • What differs between draws with the same masked key:

    • buffer base addresses, and the inline buffer descriptors in user data (words 0, 4, 8, 12, …);
    • mostly 2–32 MiB apart, i.e. each draw's constants are in fresh transient memory;
    • the SRT words almost never differ.
  • Where the memo's time goes. A perf profile of cutscene 2 without this PR (same machine) puts materializePreparedMemoized at 15.2 % of queue worker 0's samples. Of that:

    • 49 % destroys evicted results;
    • 31 % copies the donor;
    • 13 % is its own code, mostly the two snapshot hashes.

    Recycling targets the first two, which matches the drop in Shader.DrawStage.materialize above.

The four runs are attached, one zip each. Each holds the run's aps5-summary.jsonl, the same summaries with the Unix time each one was written, the cutscene start times (marks.txt), and the trace of the window from 75 s to 105 s after launch (APS5_TRACE_SECONDS=75:30):

gta-10757-round1.zip
gta-10757-round2.zip
gta-base-round2.zip
gta-base-round1.zip

AI-assisted: yes (Claude Code)

@MarcZX10

Copy link
Copy Markdown
Contributor

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 main and account the new recycle pool in the byte budget/trim path, with a regression covering the merged masked memo plus the pool. The #9049 reuse-path interaction no longer needs to be integrated because that PR closed after measuring no remaining benefit. I’ll re-check the current-main code and evidence when the draft is ready again.

@ntamas94

ntamas94 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

@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 main of 2026-10-31 with #9842, #9891, #9897, #9899, #10678, #13251 and #14032 merged locally (the title needs them to reach the level). Here queue 0's worker bounds the frame: about 165k draws per 10 s, 96 % of them masked memo hits, about 160k evictions per 10 s.

This PR's head as is. Merged onto that tree, patch went from 3.5 to 7.7 µs per hit ([recompile] result memo, APS5_PROFILE_DRAW), and the frame did not move: 91 presents per 10 s. My reading of it, not separately profiled: the thread's 8 kept results come from any source and variant, so *result = donor mostly assigns a result of another shape, bindings changes length and the inner vectors reallocate anyway.

What worked. The pool is kept per source instead of per thread, and only for the variant that is patched next:

  • SourceEntry keeps one spare result and its spareVariant. When the exact table's insert evicts a result whose use_count() is 1 under the source's lock (then an acquire fence), the result becomes the spare. A previous spare is freed there, as an eviction is today.
  • On a masked hit, the lookup that finds the donor (same lock) also takes the spare if spareVariant is the donor's variant. The copy-assign then runs between two results of one variant, so the vectors already have the right lengths and nothing is allocated or freed.
  • Elsewhere the change keeps your PR's reasoning: no weak_ptr to a RecompileResult, and ResultKeyMemo's assignment clears the draw-key memo. The 640-output check from your test passes with it (the counter rises, each patched result holds its own buffer's descriptor).

Measured on the same tree, with the base commit and the commit that adds this:

base per-source spare
recompile phase, µs per draw (APS5_PROFILE_DRAW) 13.9 7.6
worker total, µs per draw 45.0 38.5
draws per 10 s (profiled) 161k 181k
patch, µs per hit 3.5 4.0
presents per 10 s, 5 runs each, interleaved 99.8, 114.0, 106.6, 110.0, 108.2 (mean 107.7) 118.4, 118.2, 118.8, 122.6, 120.0 (mean 119.6)
frame p50 ~91 ms ~82 ms

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 APS5_VERIFY_MASKED_RESULT_MEMO=1, about 200k patched results per 10 s were compared with full materializations, with 0 mismatches. agc_shader (48 tests) and the memo and ShaderMemory tests pass.

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 aps5-summary.jsonl lines of a base and a spare run.

If you would like it, I can send the diff (about 25 lines in Recompiler.cpp) as a patch on your branch, or open it as a separate PR that credits this one.

AI-assisted: yes

@Filip722

Filip722 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

@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 e4501451406e. This is a refinement for this existing PR, with credit to meh7an’s recycling implementation and ntamas94’s source/variant proposal; I have not opened another PR.

  • One spare per source, harvested only from an exact-table victim with a sole owner under the source mutex, and consumed only for the donor’s variant. Copy assignment retains the existing draw-key reset.
  • Retained capacities are included in the existing memo byte/entry accounting. Taking the spare removes that retention charge; budget trimming drops spares before selecting cached entries.
  • The existing 640-output fixture also retains a caller-owned result through eviction. Removing the owner check makes it fail with an overwritten retained result. Removing spare trimming makes the masked-budget regression fail with 560 bytes left after a one-byte trim. Both pass with the predicates restored.

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 ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and ctest -V; three actual Khronos instance/device insertions per run, no VUIDs, missing layers or skips. The conventions check passes. No other vendor was tested.

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 APS5_VERIFY_MASKED_RESULT_MEMO=1, no logged mismatches and intact combat/HUD checks. The prospectively bounded ordinary warm-up then failed its compiled-cache stability gate: the final candidate replay added about 15 KiB to the Vulkan pipeline cache. I parked it without a fourth warm-up or a timed cohort, so there is no accepted frame-time result to claim.

The branch is offered for integration/review of the ownership and budget work; performance validation remains pending. AI-assisted.

@ntamas94

ntamas94 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

@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):

round 1 round 2 mean
base (3cda3d99da) 123.2 108.2 115.7
Filip's d7bf9563b3, cherry-picked 117.0 112.0 114.5
my per-source spare 118.2 111.8 115.0

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 DrawPipeline::Enqueue in 26 % of its samples. Sorry for the earlier claim.

The worker-side saving holds, and Filip's budgeted version keeps all of it (APS5_PROFILE_DRAW=1, which keeps the draw on the worker and so makes the worker the limit):

recompile µs per draw draws per 10 s patch µs per hit patch mismatches
base 13.9 161k 3.5 0
my per-source spare 7.6 181k 4.0 0
Filip's d7bf9563b3 7.9 181k 3.9 0

On this tree, with Filip's commit on it, agc_shader_table_snapshot_reuse, _unmasked, the three agc_shader_result_memo_budget tests and agc_shader_memory pass (6 of 6). Windows 11 26200, RTX 2080 (NVIDIA 617.14), MinGW GCC 15.2, Release. So it is a real CPU saving on the worker. It will reach the frame only where the worker is the limit, or once committer-side work such as the #7895 series removes that bound.

AI-assisted: yes

@CnRJay CnRJay left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@CnRJay CnRJay left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#10423 is already merged, so this applies to main directly; the retained-capacity question above is the open one.

chitters2004 pushed a commit to chitters2004/AnyPS5 that referenced this pull request Nov 2, 2026
…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
chitters2004 pushed a commit to chitters2004/AnyPS5 that referenced this pull request Nov 2, 2026
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
@JJenkx

JJenkx commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

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 926f7dd492b0, final head 240767dd8995:

  • 135afe3d6c3 preserves your authorship and ports only bdca440d39 (the perf(shader): reuse a memoized result by patching its copied words #10423 prerequisite is already merged), including the moved test CMake file and current memo accounting.
  • 240767dd899 replaces the retained thread pool with direct reuse of the exact memo set’s LRU victim on a masked hit. The source lock selects/removes the entry and updates existing byte/entry counts; no extra pool remains outside that accounting. A custom deleter transfers the targeted allocation only when the old shared control block expires. Strong callers keep their immutable result; an old weak reference cannot lock a result after its storage has been patched for another snapshot. The next published result gets a fresh shared control block. Toggle and reuse counter retained.

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 (a weak reference locked recycled storage with another descriptor); restoring the adaptation passes. The executable itself differs because this fixture statically links the production recompiler.

Physical GPU: both main926 and the standalone change pass agc_driver_indirect_patched_stage, agc_driver_draw_write_ranges, and its draw-pipeline variant: 3/3 each, zero skips/VUIDs, required Vulkan, no shader cache, Khronos validation actually inserted at instance/device, APS5_VERIFY_MASKED_RESULT_MEMO=1, frozen inputs unchanged. Release/GCC16.2.1, Linux7.2.11, RX6650XT, RADV Mesa26.2.6. Conventions pass.

Source mbox, CPU/negative-control proof and paired GPU logs/JUnit, SHA-256 ac5ee6e9b36ad96f01c26e28203f4cd676100a9b9caccaff74ad8e43a94795a2 (GitHub digest verified).

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 240767dd8995 on main926 ran Afterdream (PPSA18391,02.000.000) to the opening interview scene and closed normally (native exit0/153.1s). A85:15 diagnostic trace recorded893presents, median16.683ms, zero dropped events. This60FPS scene is dominated by enqueue/presentation waits, so it is regression coverage, not evidence of a speedup from recycling. All original assets, normalized images, source checkpoint saves, frozen SDK and generated modules remained unchanged; kernel setting restored, no private processes remained. Native validation was off. The scene capture was reviewed, with independent background X11 freshness unavailable. Numeric receipt, digest and capture, SHA-256 a249264092fccc46a752ea86e9096adeb94896ca3569287e2337cb6282a69df8 (GitHub digest verified). No paired gain claim.

@Meh7an

Meh7an commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build docs needs rebase Conflicts with main, rebase needed perf Performance change shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants