Skip to content

fix(agc): look up and attach draw recipes on the relocated donor entry - #7369

Merged
adriadam10 merged 3 commits into
boykopovar:mainfrom
Flamefusion:fix/agc-relocated-draw-recipes
Nov 8, 2026
Merged

adriadam10 merged 3 commits into
boykopovar:mainfrom
Flamefusion:fix/agc-relocated-draw-recipes

Conversation

@Flamefusion

@Flamefusion Flamefusion commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

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

  • relocateDrawEntry builds a fresh DrawEntry with per-draw copies of the donor's variants. That entry is not stored in drawCache under the draw's key.
  • findDrawRecipe and, after recording, attachDrawRecipe still look up the draw's own key in drawCache. They find nothing and return, so a relocated hit never finds the donor's recipe, and a recipe built while recording it is dropped. With APS5_TRACE_DRAW_CACHE this shows as "attaches 0".
  • The recipe records also compare stage identity against the per-draw copies, which are new objects on every draw, so even a stored record could never match.

Fix:

  • DrawEntry and DispatchVariant gain a donor pointer. relocateDrawEntry sets 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::draw keys the recipe stages on the donor variant when a matched variant is a relocation copy. It hands the donor entry to findDrawRecipe and attachDrawRecipe, also through commitDraw on 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::DrawWithRecipe rebuilds the push constant block from the current shaders (AssemblePushConstants plus 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_relocation gains RelocatedDrawsReuseTheirRecipe.

  • Its draws read a constant through a user pointer that moves on every draw to identical contents, so after four teaching draws every further draw is a relocated hit.
  • They render into a 64 KiB guest block with the SW_64KB_R_X swizzle mode. The 1 KiB linear target the other cases use is never resident, and a draw into a non-resident target is not recorded, so it would never build a recipe.
  • The case requires all six later draws to be draw-cache hits and all six to be recorded from the recipe.
  • VulkanDevice::DrawRecipeHits() exposes the draw recipe hit counter the [recipe] profile line already keeps, so the test can read it without APS5_PROFILE_DRAW.

Tested

Rebased on main 98346b748c (the branch was about 14,000 commits behind). Conflicts were textual: main had added valueWords/valueSlots/calleeWords/calleeReads next to donor in DispatchVariant and its relocated copy, DrawTraceContext next to DrawRecipeHits() in VulkanDevice, and defaulted trace/shape parameters to commitDraw; recipeDonor now comes before those, and both call sites pass it. findDrawRecipe and attachDrawRecipe on main still 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" -V with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, 17 tests:

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 on main b39d90bf1:

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none (draw recipes on relocated draw-cache hits; found on PPSA03355 Hades (PPSA03355) #3234, no stop there)
  • GPUs tested: NVIDIA GeForce RTX 4050 Laptop GPU, driver 566.24, Windows 11 (build 26200) (after the rebase); NVIDIA GeForce RTX 3050 Laptop GPU, driver 617.42, Windows 11 (build 26300) (before it)
  • AI-assisted: yes

std::shared_ptr<DrawEntry> entry;
{
void Driver::attachDrawRecipe(std::uint64_t key, const std::vector<std::shared_ptr<DispatchVariant>>& stages, std::shared_ptr<const DrawRecipe> recipe, const std::shared_ptr<DrawEntry>& donor) {
std::shared_ptr<DrawEntry> entry = donor;

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.

This 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. AtomicSharedPtr makes 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good 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 090d66e: attachDrawRecipe now uses a compare_exchange_strong loop. 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 at dispatchVariants()). Both the AtomicSharedPtr fallback and std::atomic<std::shared_ptr> provide compare_exchange_strong.

The draw cache relocation and reuse tests (all variants), address passes, mesh draw relocation and linear target resident tests still pass.

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 9508 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp L5441
PR 10678 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp L306
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp L1273, L1276, L1311, L1330-1331
PR 15455 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp L1310-1311
PR 15456 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp L1310-1311
PR 16753 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp L4260-4262

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/Graphics/src/Draw.cpp
PR 1395 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 1896 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp
PR 4040 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 4472 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 5021 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 5609 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hpp
core/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hpp
core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCache.cpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRelocate.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 5925 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hpp
core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCache.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 6804 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7002 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 7275 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 7449 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7464 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7508 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRelocate.cpp
PR 7622 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hpp
core/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hpp
core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRelocate.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 7643 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 8004 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9289 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9356 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 9387 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 9748 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 9852 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 9915 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hpp
core/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hpp
core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRelocate.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 10359 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hpp
core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp
PR 10442 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 10652 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 11346 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
PR 11435 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 11436 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 11452 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 11551 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 11825 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 12828 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 12904 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 13148 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 13809 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 13863 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 13920 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 13928 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hpp
core/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hpp
core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRelocate.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 13929 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hpp
core/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hpp
core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRelocate.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 14344 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 14871 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 14944 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 15136 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 15169 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 15343 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 15548 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp

@MarcZX10

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added agc libSceAgc* unblocks title Names a title ID on the Unblocks line needs rebase Conflicts with main, rebase needed labels Oct 18, 2026
@blawesom

Copy link
Copy Markdown
Contributor

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 known main regressions (#5444 Mesa, #7584 BDA, #7766, #7784), none from this PR.

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/7369
git checkout <your branch>
git merge --ff-only FETCH_HEAD

Head is f08cae59a.

@adriadam10 adriadam10 self-assigned this Oct 19, 2026
@adriadam10
adriadam10 force-pushed the fix/agc-relocated-draw-recipes branch from 090d66e to 403651e Compare October 19, 2026 14:22
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 19, 2026
@Flamefusion

Copy link
Copy Markdown
Contributor Author

@adriadam10 do you need anything from my side for this pr ?

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed unblocks title Names a title ID on the Unblocks line labels Oct 19, 2026
@Flamefusion
Flamefusion force-pushed the fix/agc-relocated-draw-recipes branch from 403651e to 562f910 Compare October 20, 2026 05:44
@Flamefusion

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (87a32d145). New head is 562f9107f; the three commits are unchanged in intent.

Thanks @blawesom for the earlier rebase handoff. main had moved again since then, so I redid it on the latest tip:

Verified on Windows 11, MinGW GCC 15.2, Ninja, Release, BUILD_TESTING=ON, NVIDIA RTX 3050 Laptop (driver 617.42):

  • builds
  • all 32 AGC draw-path tests pass, including the draw cache relocation/reuse variants, mesh draw relocation, linear target resident and pipelined indirect draws
  • check_conventions.py passes

A draw that misses on its own register key and is served by a relocated
draw entry (relocateDrawEntry, boykopovar#4943) never got a draw recipe:

- relocateDrawEntry builds a fresh DrawEntry with per-draw copies of the
  donor's variants. That entry is not stored in drawCache under the draw's
  key.
- Driver::draw still passes the draw's own key to findDrawRecipe and, after
  recording, to attachDrawRecipe. Both look the key up in drawCache, find
  nothing and return, so a recipe built while recording such a draw is
  dropped and the next relocated draw of the same shape records in full
  again ("attaches 0" with APS5_TRACE_DRAW_CACHE).
- The recipe records also compare stage identity against the per-draw
  copies, which are new objects on every draw, so even a stored record
  could never match.

Changes:

- DrawEntry and DispatchVariant gain a donor pointer. relocateDrawEntry
  sets it on the relocated entry and on every copied variant, always to
  the original cached entry/variant (a copy of a copy points at the
  root), so the chain never grows.
- Driver::draw keys the recipe stages on the donor variant when a matched
  variant is a relocation copy, and hands the donor entry to
  findDrawRecipe/attachDrawRecipe (also through commitDraw on the
  pipelined path). With a donor, both read and update the donor entry's
  recipe list directly instead of looking the key up; without one they
  behave as before.
- DrawWithRecipe rebuilds the push constant block from the current shaders
  and patches it through the recorded resources when the recipe has push
  stages, instead of replaying the bytes captured with the recipe. A
  relocated draw moves user words that end up in push constants, so the
  captured block would carry the first draw's values.

Draws that are not relocated take the same path as before: their matched
variants have no donor and recipe lookup still goes through drawCache.

Measured on Hades (PPSA03355, discussion boykopovar#3234), where nearly every sprite
draw is served through a relocated entry: lookups and attaches now
succeed, but Graphics::Draw builds a recipe for only ~15 of ~100,000 draws
per 10 s because the draws' ShaderResources are not Reusable(), so the
frame rate does not change yet. The fix is what lets recipes apply to
relocated draws once that is addressed.
Adds RelocatedDrawsReuseTheirRecipe to the draw cache relocation test.
It covers the case the previous commit fixes: a draw that misses on its
own key, is served by a relocated draw entry and should then be recorded
from the recipe of the cached draw it was relocated from.

- The draws read a constant through a user pointer that moves on every
  draw to identical contents, like MovedDataHitsTheCache, so after four
  teaching draws every further draw is a relocated hit.
- They render into a 64 KiB guest block with the SW_64KB_R_X swizzle
  mode. The linear 1 KiB target the other cases use is never resident,
  and a draw into a non-resident target is not recorded, so it never
  builds a recipe and could not show the bug.
- The case checks that all six relocated hits are draw-cache hits and
  that all six were recorded through DrawFromRecipe.

VulkanDevice::DrawRecipeHits() returns the draw kind's recipe hit
counter that the [recipe] profile line already keeps, so the test can
read it without APS5_PROFILE_DRAW.

Without the previous commit the case fails with "0 of 6 draws served by
a relocated entry were recorded from the cached draw's recipe": the
lookup uses the draw's own key, which has no draw cache entry. With it,
agc_driver_draw_cache_relocation, agc_driver_draw_cache_reuse (and its
_off, _verify and _inline variants), agc_driver_address_passes,
agc_driver_mesh_draw_relocation and agc_driver_linear_target_resident
pass.
attachDrawRecipe builds a new recipe list from the entry's current one
and stores it: it loads the old list, copies the still-valid records
behind the new one and stores the result. Each AtomicSharedPtr operation
is atomic, but the sequence is not. If two attaches load the same old
list, each stores a list holding only its own new record, and the later
store drops the earlier attachment.

With recipes attached through the relocated donor entry, draws with
different register keys that relocate from the same cached draw attach
to one DrawEntry, and on the pipelined path their commits run apart from
the worker. Concurrent attaches to the same entry are therefore no
longer limited to one key.

The update is now a compare_exchange_strong loop. When another attach
has replaced the list since it was loaded, the new list is rebuilt from
the list now stored and the exchange is retried, so both records are
kept, within the dispatchVariants() limit as before. The
AtomicSharedPtr fallback and std::atomic<std::shared_ptr> both provide
compare_exchange_strong.

agc_driver_draw_cache_relocation, agc_driver_draw_cache_reuse (and its
_off, _verify and _inline variants), agc_driver_address_passes,
agc_driver_mesh_draw_relocation and agc_driver_linear_target_resident
pass.
@Flamefusion
Flamefusion force-pushed the fix/agc-relocated-draw-recipes branch from 562f910 to 56c0854 Compare November 2, 2026 12:00
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 2, 2026
@TechLevelZero

Copy link
Copy Markdown
Contributor

✅ NVIDIA GPU test: passed

PR head 56c0854 merged onto main 1d91f29 · tested 2026-11-02 19:41 UTC · 20 min

GPU NVIDIA RTX 2000 Ada Generation, driver 595.99.02, Vulkan 1.4.329
Host Ubuntu 26.04.1 LTS, kernel 7.0.0-38-generic, container ubuntu:24.04
Logs build and test logs for this run
Build ✅ passed (Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON)
Tests ✅ 2,617 passed · 5 failed (0 new, 2 also fail on main, 3 unstable on main) · 44 skipped (ANYPS5_REQUIRE_VULKAN=1)
Test setup CPU-only tests without a GPU; GPU tests (and any CPU-only test that failed or skipped without one) once on the GPU with VK_LAYER_KHRONOS_validation and ANYPS5_NO_SHADER_CACHE=1; main ran the same way
Test selection 2,666 of 3,544 tests run: the ones this change can reach, chosen by tools/select_tests.py from main's build graph
Vulkan validation ✅ no new validation IDs vs main (981 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) ⚠️ agc_driver_pipeline_journal 120.1 s, ⚠️ agc_driver_graphics 36.3 s, ⚠️ agc_driver_graphics_maps_fallback 36.2 s
Unstable on main (3, these also failed in recent main runs on this machine; not counted against this PR)
agc_driver_job_manager_compute_capacity: failed in 1 of the last 10 main runs
agc_driver_pipeline_journal: failed in 3 of the last 10 main runs
agc_submit_progress_no_timeline: failed in 7 of the last 10 main runs
Failing on main too (2, not counted against this PR)
agc_driver_image_table
guest_socket_options_multicast
Validation IDs already present on main (4 IDs in 510 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (510 tests): agc_driver, agc_driver_address_passes, agc_driver_alias_copy_label, agc_driver_alpha_to_coverage, agc_driver_array_layer_target, agc_driver_bc_block_copy, agc_driver_bda_anchor_reads, agc_driver_bda_span_reads, and 502 more
VUID-vkCmdCopyImage-srcImage-01548 (7 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_sampling, agc_driver_depth_storage_dispatch, agc_driver_depth_surface_from_storage, agc_driver_dispatch_move_depth
VUID-vkCmdCopyImage-srcImage-01551 (7 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_sampling, agc_driver_depth_storage_dispatch, agc_driver_depth_surface_from_storage, agc_driver_dispatch_move_depth
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (1 test): agc_driver_prepared_exports
Skipped (44)
agc_driver_bda_reads_shadowed_results: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_bda_reads_shadowed_results_per_build: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_sample_order_grid_reference: skipped, the device does not keep depth drawn at custom sample locations at those locations, even after a transition that names them: the composite of uniform renders holds the guest's depth in 0 of 3005 sloped samples, so no path can be compared with it bit for bit
agc_host_import_sparse: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_import_settle_initial_dcc: skipped, the device has no deferred settle of host imports: imports under 1 MiB wait for one only on Windows
agc_unit_shadow_completion_store: skipped, the device reports watched host memory written when it imports or reads it
guest_http_uri_locale: 
guest_video_out_color_space: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_hdr: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_high_frame_rate: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_output_mode: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_resolution_status: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_wqhd_detection: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
video_out_flip_aftergpu: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_backtoback: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_controls: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip_in_order: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_dcc: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_deferred: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_aftergpu: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_main: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_fps_limit: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_fresh: skipped, no display or Vulkan device: 
Reproduce
git fetch origin 56c0854bbea2f6f3fdefa82ea730b37bfd34485b 1d91f2966d0eef82a021628a7aa8e78e615ac807
git checkout 1d91f2966d0eef82a021628a7aa8e78e615ac807 && git merge --no-ff 56c0854bbea2f6f3fdefa82ea730b37bfd34485b
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build && cmake --build build --target libs
VK_DRIVER_FILES=/nonexistent/icd.json ctest --test-dir build -E '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 32 --output-on-failure
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 4 --output-on-failure
# failures are then re-run alone: --timeout 360 --parallel 2; new validation IDs: the test alone, twice, --parallel 1

Automated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs.

@adriadam10
adriadam10 merged commit 227b26e into boykopovar:main Nov 8, 2026
12 of 13 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Re-checked the rebased head: the donor chain (always the root entry/variant), recipe lookup/attach on the donor with compare-and-retry, the push-constant rebuild in DrawWithRecipe and the null donor for the pipelined indirect commitDraw are unchanged and correct. The new case pins recipeHits == hits, which is 0 without the fix; the NVIDIA run on this head passed with no new failures; merged.

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

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants