perf(agc): relocate cached draws across user words that only reach the shader as values #6539
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6539"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-15T19:24:24Z.
What
Third step for #4054, stacked on #5609. A user-data word that the resource walk never reads, and that the compiled stage only receives as a pushed value, still took part in the draw key and in the relocation alias. RADV's base-vertex SGPR is one: it changes on every draw, so a title whose draws would otherwise relocate across its moved pointers missed on every draw anyway. On Ratchet & Clank under RetroArch's PCSX2 core, 0.1% of draws hit the cache.
shaderDataUserWords) the resource walk did not read at all:DispatchVariant::forwardedWords.forwarded. They stay out of the alias key, a relocation accepts any change to them, and the new value is patched into the pushed data the same way a moved pointer's value is.main's data-only path (#5216's shape reuse), which already owns that case. A relocation that finds the draw's decode but not every stage also gives way to that path when it applies, instead of claiming the draw with an incomplete entry.APS5_NO_FORWARDED_RELOCATION=1turns the forwarded words off;APS5_NO_DRAW_RELOCATION=1still turns the whole thing off.Related: #5656 (on #494) lets a data-only hit reuse a stage whose changed user words it never reads; it counts the words a layout forwards into shader data as read, so a changed forwarded word still recompiles the stage there. This PR patches such a word on the relocation path instead. The two touch different paths and no shared code.
Only the commits after #5609's head are this PR.
Tested
Windows 11, NVIDIA GeForce RTX 5070 Ti, MinGW-w64 GCC 15.2.0, on main
940eba9a2with #4943 and #5609.ctest: 1271 of 1292 pass, 14 skipped.guest_call_trace_abort,windows_backtrace_reportandagc_driver_store_over_untrackedfail, and fail the same way on plain main here;agc_driver_prepared_graphics_prebuild_0/_1andundeliverable_host_exceptionfail under my test runner because it skips their environment changes and pass pattern, and pass run with those;agc_driver_multisample_fill_host_onlyfailed once in the parallel run and passes alone.agc_driver_draw_cache_relocation: a pixel shader reads its red channel through a user-data pointer and its green channel from a user word it gets as a value. Eight draws with the same contents at moving addresses and a changing green value hit the cached draw from the fifth on (0 hits withAPS5_NO_FORWARDED_RELOCATION=1), and a hit given green 1.0 writes 255 to the target (64 if the value is not patched: checked by removing the patch).main'sagc_driver_draw_cache_reusecases pass unchanged: their user words are plain values, which still go through the data-only path.operator newimports) 167 to 136, audio produced in the heavy intro scenes 41-43% of real time to 45-47%.APS5_VERIFY_DRAW_ENTRIES=1, which captures every hit again and compares: 0 stages differed; the last four 10 s windows of the run captured 868,744 hits again.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-16T08:53:04Z.
Tested on Linux (Arch),
c++ (GCC) 16.2.1 20260810, Release,BUILD_TESTING=ON,mainat5d9dcc42d2ec5401aebd089028b8d4d7410a77b4. GPU tests ran on lavapipe (Mesa 26.2.2, llvmpipe with LLVM 22.1.8).With the dependencies from the description (#4943 and #5609) merged first,
agc_driver_draw_cache_relocationaborts (2 of 2):mainplus #4943 plus #5609 without this PR passes the same test (2 of 2).mainalone does not have the test. glibc detects a heap corruption, so a write past a buffer or a double free happens somewhere in the code this PR changes or runs. I did not find the exact line.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-16T09:32:03Z.
Root cause of the
corrupted double-linked listabort that @nicolasfalesy reported inagc_driver_draw_cache_relocation.Reproduced on Linux (Arch), RX 9070 XT (RADV, Mesa 26.2.4), Release, PR head
12a5f02d1: 14 of 15 runs abort. The abort is in static destruction at process exit:entryPool()andvariantPool()inDrawRelocate.cppare function-local statics.relocateDrawEntrycallsentryPool().Take()beforecloneVariantfirst callsvariantPool(), so the entry pool is constructed first and destroyed last. Its spareDrawEntryobjects still holdstages(cleared only when an entry is taken again). Those stages holdshared_ptr<DispatchVariant>objects whose deleter callsReturnonvariantPool(), which is already destroyed by then.~RelocationPool<DrawEntry>deletes the spare entries, the variant deleters push into the destroyed pool's vector, and glibc catches the heap corruption.Fix tested on the same head: make both pools immortal, the same pattern as other process-lifetime singletons in the driver:
With this change
agc_driver_draw_cache_relocationpasses 10 of 10 runs. Clearing an entry'sstagesinReturnwould also work, but the immortal pools also cover any other object that keeps a pooled variant until exit.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-16T17:58:23Z.
Rebase handoff + independent confirmation of the abort — rebased onto current
main(both commits, authorship unchanged). The conflicts:Pipeline::Continuekeepsmain'soptimized->Schedule()atop this PR'sapplyrestructure, and the disk-cachestatic_assertis pinned to the merged tree's actualRecompileResultsize (488 —mainrestructured it since your base).Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesagc_driver_draw_cache_relocationaborts withcorrupted double-linked list— 1/1 on my runs, matching your root-cause analysis from this morning (theentryPool/variantPoolstatic-destruction order). Same device class as your repro (RX 9070 XT / RADV), so this is a second confirmation on the same head12a5f02d1(pre-rebase) rather than new information — the rebase does not change it.agc_driver_same_queue_label_waitfailed once in parallel runs and passed solo — the second draw-state-filtering PR where I have seen that test flake (also on #6523); if your destruction-order fix lands, that pair may be worth a look too.To pick it up:
Head is
51c11a856(amended to fold in the Continue/Schedule repair).Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-16T18:07:01Z.
Correction on the
agc_driver_same_queue_label_waitremark above: root-caused to my machine, not this PR — the card heat-soaked after a long verification day (junction ~95°C) and that timing-sensitive test's measurement flips when hot; it passes again after four minutes idle on the same build. Not a signal about this PR or your destruction-order fix. Please disregard.Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-19T03:35:03Z.
Reviewing this for a possible 007 Windows cross-test after our current loading probe. Public baseline63ec3b290 is mainca13a56a5 plus the title's carried fixes and #6616; 150 selected native checks pass, one Linux-only import case skips. Menu remains1.911FPS, GPU180.25ms/present, so there is still substantial CPU preparation cost. Recent menu report:
9.4k draw packets/10s,246us, key/lookup/validation14.9k captures, per-packet capture150us, recompile/materialization95us, graphics-lock wait192us. These are inclusive phase labels, not proof your optimization applies. Draw-cache hits remain low; no benefit claimed from this PR yet.GitHub reports current heads #6539=12a5f02d and #5609=09238da8 conflict with main. Do you have a newer current-main rebase/WIP to use before I duplicate that integration work? I can review/adapt meanwhile; no title data needed.
Overlap to preserve: our #7508 at858c36315 replaces the per-word tagging scan in tagVariantRuns with ForEachRelocationRun; it retains #6454's AppendSharedWords first inside each emitted partition callback. SleglJan already cross-tested that combination on Linux and noted your adjacent edit. Public integration has that same partitioning. Any combination needs both provenance/shared-word handling and the forwarded-value patches, with the existing changed-green readback control kept. I will report exact heads and native/title evidence for an actual test. AI-assisted: Codex; raw title data remains local.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T12:51:10Z.
Thanks for this. Two things before it can be reviewed:
agc_driver_draw_cache_relocationaborts withcorrupted double-linked liston this head, the static-destruction order ofentryPool/variantPooldescribed in the thread. Could you push that fix?mainand conflicts inDrawRelocate.cpp,Pipeline.cpp,DrawCacheRelocation.cpp,SrtDescriptorEvaluation.cpp,SrtEvaluator.cppandShaderDiskCache.cpp. Relocation has changed onmainsince your base (stage-data patches for relocated hits, the mesh index descriptor on relocated stages, shared words recorded by run). Please rebase onto currentmainand say whether the value-only user-word rule still holds on top of those changes.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-20T16:27:23Z.
Additional local integration evidence for the pool-lifetime and current SRT metadata concerns above (AI-assisted: yes).
I combined PR head
12a5f02d10fd8bfeedf101df27cb079a3b01f5b1with main7526640c3c1c5ea236c33b43b854681e8d169745and the carried HTILE integration; local integration commit1a1f519ebfe9dce77b3f3aaf1be96f205d46d162. This is not a current-main-only comparison or a performance result.RelocationPool<T>shared ownership and capture that owning pointer in each returned object's deleter:[pool = this->shared_from_this()](T* released) { pool->Return(released); }, with each pool accessor holding a staticstd::shared_ptr<RelocationPool<T>>. This keeps a pool alive until its outstanding objects are returned during shutdown.sharedvalidation metadata cleared before rebuilding address-bound runs in this integration.readInstructionsand descriptorsourceLeads, and roll back those additions when a tape walk refuses. Before that adaptation,agc_driver_draw_cache_moved_bufferfailed on the tape path while theAPS5_NO_SRT_TAPEcontrol passed.After these adaptations, seven focused tests passed five repetitions each (35 executions): shader disk cache, moved buffer, relocation, and draw-cache reuse/default-off/verify/inline. Linux/RADV,
MALLOC_PERTURB_=165,ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation; no VUID errors, skips, or missing-layer warnings in that log.Hades II native controls also completed, but do not establish a forwarding performance benefit or regression. An initial cold-cache run had black timed captures during a long frame stall; a later ordinary-settings repeat rendered the hub. The cache conditions differed, so the initial black captures should not be attributed to forwarding from these runs. This does not settle the general value-only rule or replace the requested current-main rebase/review.
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-20T19:51:24Z.
The repair source is now available on JJenkx/AnyPS5,
fix/descriptor-relocation-integration, rebased onto main2185dbf92e8d9013a1620d2dfc95de50494e19f8. Prerequisite commits from #5609 and #6539 retain their original authorship. This is a tested integration branch for review/cherry-picking, not a replacement PR or a performance claim.The relevant repairs are:
readInstructions,operandReadsand descriptorsourceLeads, preserve operand nesting, and roll the metadata back on tape refusal. The differential tape/interpreter regression fails without this repair (read provenance has a different size from the reads) and passes with it.EqualData, with moved-buffer and changed-length regression coverage. This builds on the preceding data-only integration commits in the branch; it is not a standalone patch against main.Matched focused validation on Arch Linux / AMD Radeon RX 6650 XT / RADV 26.2.4:
2185dbf92e: 5/5 matching tests pass.572fe318ce: those five plus the dependency's new moved-buffer test pass (6/6).VUID-messages, missing validation-layer warnings, or skipped tests.Both runs used:
The moved-buffer test is absent on main; the other five test names match. Conventions checks pass. These results establish focused correctness coverage, not a title FPS improvement. AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-20T20:34:05Z.
A matched Hades II measurement is now available for the integration branch above (AI-assisted: yes). This pair does not show a speedup.
Baseline
17558c1cd1bb8b8cb6c0e44c4a7ea7af774016f5is main9a97ac784da5d40cc7b7d968898ffbf5b8b5377aplus the refreshed #6300 depth dependency. Candidate64ba4ebacf38fead38f699555b2418e1c24463a6adds the combined descriptor relocation stack and its integration repairs. This is a dependency-baseline comparison, not a main-only result or an isolated measurement of #6539.Both legs used identical starting save hashes, the same inputs and rendered Underworld room, separate initially empty shader/Mesa caches, the same hardware and trace settings (
APS5_TRACE_SECONDS=160:15,APS5_TRACE_EVENTS=1048576). Both compiled 199 shaders from cold caches, exited normally, restored the kernel setting, and produced complete traces (trace_dropped=false). Both traces were processed withtools/trace_digest.py.The official summary reports
Driver.Draw.shader_compile_and_linkat 9.366 versus 10.717 ms/frame andShader.DrawStageat 6.105 versus 6.835 ms/frame. These are inclusive scopes; they do not mean actual shader compilation continued during the window. The candidate p50 was 6.1% higher in this single pair; that is insufficient to establish regression significance, but does not support a performance claim for this scene.The complete official summary lines, full source pins and comparison conditions are in comparison.json. Full traces are retained locally. Next I will investigate preparation/lookup costs before proposing any speed claim.
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-20T21:25:31Z.
A bounded-cache correctness follow-up is available in 198bca0fd0 on the existing integration branch. AI-assisted: yes. This depends on the relocation stack; it is not an isolated patch against main or a performance claim.
learnPendingRelocation()previously pruned both alias maps whenever their size reached 16,384, including when learning only refreshed an existing key. Stage donors were also checked once before inserting multiple stages, allowing the map to exceed its bound within that loop. The helper now checks each insertion and prunes only for a new key at capacity; existing donors still receive refreshed payloads.The regression exercises both stage and decode donor maps: updates at capacity preserve every other key and replace payloads; repeated new insertions retain the newest entry, stay within the bound, and account for evictions. The unconditional-pruning negative control fails with
updating an existing alias evicted unrelated donors at capacity; the fixed implementation passes.Full Linux
libsbuild and five focused checks pass on AMD Radeon RX 6650 XT / RADV: shader memory, moved buffer, relocation, data-hit user words and its verification variant. Vulkan required, shader caches disabled, Khronos validation enabled; zero VUIDs, skips or missing-layer warnings. Conventions pass with the existing debt-length warning. These checks validate this integration, not a fresh main-versus-candidate comparison.Hades II PPSA36082 also reached the expected Underworld room, then closed normally after 188 seconds; PID gone and kernel setting restored. Warm shader cache: 199 hits, zero misses. The sparse screenshot shows no obvious new corruption. Instrumented timings vary, so no title speedup is claimed. Native core validation was not requested; the validation result above applies to the focused tests.
Logs, source patch and compact validation evidence.
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T10:06:20Z.
Matched measurement of the integration branch on another title and platform, where the miss pattern is exactly what this stack targets. It shows no gain; the candidate is slower here. AI-assisted: yes.
Setup
APS5_TRACE_SUMMARY_EVERY=10, steady-state intervals from 60 s on.71401e331, plus the test-only #8310 so the tree builds on Windows.fix/descriptor-relocation-integrationat572fe318c. A local, unpublished merge: the only conflict wasShaderDiskCache::FormatVersion(43 vs 42), set to 44.This scene issues ~1,650 draws per frame. With
APS5_TRACE_DRAW_CACHE, main hits only 0.5–0.8 % of ~410k lookups per 10 s; almost every miss isuser words/pointers onlyand becomes a data-only hit that still compiles ~1.5 stages per draw.Driver.Packet/ frame71401e331Candidate data-only hits per 10 s: 219k stages reused, 530k compiled, against 208k/611k on main.
So the relocation path converts a few more lookups, but on this title the per-draw cost it adds outweighs that. That matches the earlier per-draw content hashing concern. The queue worker stays ~90 % busy in both builds, and the frame is worker-bound.
Summaries are in my local evidence; I can share the
aps5-summary.jsonlpair if useful.Pull request closed