fix(agc): look up and attach draw recipes on the relocated donor entry #7369
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7369"
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 Flamefusion on 2026-10-18T02:55:54Z.
What
A draw that misses on its own register key and is served by a relocated draw entry (
relocateDrawEntry, #4943) never uses or keeps a draw recipe, so every such draw is recorded in full (Graphics::Draw) instead of from the cached draw's recipe (DrawFromRecipe).In
Driver::draw(Execution/src/Driver/Draw/Draw.cpp):relocateDrawEntrybuilds a freshDrawEntrywith per-draw copies of the donor's variants. That entry is not stored indrawCacheunder the draw's key.findDrawRecipeand, after recording,attachDrawRecipestill look up the draw's own key indrawCache. They find nothing and return, so a relocated hit never finds the donor's recipe, and a recipe built while recording it is dropped. WithAPS5_TRACE_DRAW_CACHEthis shows as "attaches 0".Fix:
DrawEntryandDispatchVariantgain adonorpointer.relocateDrawEntrysets it on the relocated entry and on every copied variant, always to the original cached entry or variant (a copy of a copy points at the root), so the chain never grows.Driver::drawkeys the recipe stages on the donor variant when a matched variant is a relocation copy. It hands the donor entry tofindDrawRecipeandattachDrawRecipe, also throughcommitDrawon the pipelined path. With a donor, both read and update the donor entry's recipe list directly instead of looking up the key; without one they behave as before.Graphics::DrawWithReciperebuilds the push constant block from the current shaders (AssemblePushConstantsplus the recorded patches) when the recipe has push constants. Relocation moves user words that land in push constants, so the donor's block must not be replayed as-is.Found while profiling Hades (PPSA03355, discussion #3234), whose sprite draws move per-draw pointers on almost every draw. There, recipe attaches now succeed, but few of its draws build a recipe at all: most hold an address-based build's lease, so they are not reusable. This PR therefore claims no frame-rate change; it makes the relocated path consistent with the exact-key path.
Test:
agc_driver_draw_cache_relocationgainsRelocatedDrawsReuseTheirRecipe.VulkanDevice::DrawRecipeHits()exposes the draw recipe hit counter the[recipe]profile line already keeps, so the test can read it withoutAPS5_PROFILE_DRAW.Tested
Rebased on
main98346b748c(the branch was about 14,000 commits behind). Conflicts were textual:mainhad addedvalueWords/valueSlots/calleeWords/calleeReadsnext todonorinDispatchVariantand its relocated copy,DrawTraceContextnext toDrawRecipeHits()inVulkanDevice, and defaultedtrace/shapeparameters tocommitDraw;recipeDonornow comes before those, and both call sites pass it.findDrawRecipeandattachDrawRecipeonmainstill look up only the draw's own key.Windows 11 Home (build 26200), WinLibs GCC 15.2.0 r7 (posix-seh, ucrt), Release,
-DBUILD_TESTING=ON, Intel Core i7-14650HX, NVIDIA GeForce RTX 4050 Laptop GPU (driver 566.24), Vulkan SDK 1.4.363.0.ctest -R "draw_cache|address_passes|mesh_draw_relocation|linear_target_resident" -VwithANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, 17 tests:main(the fix files frommain, the test commit kept):agc_driver_draw_cache_relocation,_relocation_recipe_verifyand_relocation_draw_pipelinefail with0 of 6 draws served by a relocated entry were recorded from the cached draw's recipe, expected all; the other 14 pass.was not found but was requested by env var VK_INSTANCE_LAYERS; both have 0VUID-lines.tools/check_conventions.pypasses.tools/pr_overlap.py --branchnow reports #6804 and #10678, which change thecommitDrawsignature and its call sites inDraw.cpp; neither implements the same thing.Original run, before the rebase:
Windows 11 (build 26300), WinLibs GCC 15.2.0 (posix-seh, ucrt), Release,
-DBUILD_TESTING=ON, Ryzen 7 7435HS / 16 GB, NVIDIA GeForce RTX 3050 Laptop GPU (driver 617.42, graphics pipeline libraries available), rebased onmainb39d90bf1:agc_driver_draw_cache_relocationpasses, as doagc_driver_draw_cache_reuseand its_reuse_off,_reuse_verifyand_reuse_inlinevariants.agc_driver_address_passes,agc_driver_address_passes_targets_split,agc_driver_mesh_draw_relocationandagc_driver_linear_target_residentalso pass.0 of 6 draws served by a relocated entry were recorded from the cached draw's recipe, expected all.[recipe]profile line go from 0 to non-zero, though only about 15 recipes are built per ~100,000 draws (see above). No frame-rate change.tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branchreports four line overlaps, none implementing the same thing: #6454 (test includes and theMovedDataHitsTheCacheend inDrawCacheRelocation.cpp), #6914 (the recipe block inExecution/.../Draw.cpp), and #7254 and #7256 (DrawWithRecipeinGraphics/src/Draw.cpp). Happy to rebase on whichever goes first.APS5_NO_GPLis set.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T02:58:54Z.
Code review location:
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCache.cpp; line 220This donor path lets relocated entries from different draw keys attach recipes to the same
DrawEntry. The recipe update below is a load-copy-store sequence: if two completions load the same old vector, each builds a vector with only its own new record, and the later store drops the other attachment.AtomicSharedPtrmakes each operation safe, but not this compound update. Could this use a compare-and-retry loop (or per-entry serialization) so parallel relocated draws do not discard each other’s cached recipes?Imported from boykopovar/AnyPS5. Originally posted by Flamefusion on 2026-10-18T03:10:44Z.
Code review location:
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCache.cpp; line 220Good catch, thanks. The race was already possible on one key, but sharing the donor entry across keys makes it much more likely, and pipelined commits can attach in parallel.
Fixed in 090d66e6e:
attachDrawRecipenow uses acompare_exchange_strongloop. If another attach replaced the list after the load, the new list is rebuilt from the list now stored and the exchange is retried, so both records are kept (still capped atdispatchVariants()). Both theAtomicSharedPtrfallback andstd::atomic<std::shared_ptr>providecompare_exchange_strong.The draw cache relocation and reuse tests (all variants), address passes, mesh draw relocation and linear target resident tests still pass.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T03:14:47Z.
Thanks for the fix. The compare-and-retry rebuilds from the latest recipe list on contention, which addresses the lost-attachment race I flagged. The updated head is clean; I have not run the draw-cache tests locally.
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-19T08:50:57Z.
Rebase handoff — rebased onto current
main(all three commits, authorship unchanged). Test-file conflicts unioned (main's newer SRT-walker tests kept alongside your recipe-coverage tests).Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; the draw-cache tests pass (5/5); conventions pass; full suite green apart from the four knownmainregressions (#5444 Mesa, #7584 BDA, #7766, #7784), none from this PR.To pick it up:
Head is
f08cae59a.Imported from boykopovar/AnyPS5. Originally posted by Flamefusion on 2026-10-19T18:04:26Z.
@adriadam10 do you need anything from my side for this pr ?
Imported from boykopovar/AnyPS5. Originally posted by Flamefusion on 2026-10-20T05:44:43Z.
Rebased onto current
main(87a32d145). New head is562f9107f; the three commits are unchanged in intent.Thanks @blawesom for the earlier rebase handoff.
mainhad moved again since then, so I redid it on the latest tip:Graphics/src/Draw.cpp: textual conflict with #7254 inDrawWithRecipe. I keptmain's layeredtargetSlicesline and the push-constant patching from this PR.Execution/src/Driver/Draw/Draw.cpp: #6931 added a pipelined indirectcommitDrawcall with the old signature, which git did not flag. It now passesnullptrfor the recipe donor. Indirect draws never take the recipe path, so this changes nothing in behaviour.Verified on Windows 11, MinGW GCC 15.2, Ninja, Release,
BUILD_TESTING=ON, NVIDIA RTX 3050 Laptop (driver 617.42):check_conventions.pypasses