Skip to content

fix(agc): refresh moved buffer bindings in draw recipes - #17157

Closed
PrivacyOnion wants to merge 1 commit into
boykopovar:mainfrom
PrivacyOnion:codex/fix-draw-recipe-buffers
Closed

PrivacyOnion wants to merge 1 commit into
boykopovar:mainfrom
PrivacyOnion:codex/fix-draw-recipe-buffers

Conversation

@PrivacyOnion

Copy link
Copy Markdown
Contributor

What

Refresh the buffer bindings used by a cached draw recipe when the current draw relocates a read-only guest buffer or changes its shader-data words. A recipe created before the change currently passes ProveCurrent but records with the template's old bindings. A green input can consequently render the red input from the original draw.

Run MovedReadOnlyBuffers after the recipe's resource proof and pass the resulting bindings to recordDraw, as the ordinary cached-draw path already does. If the bindings cannot be reused safely, report a buffer miss and let the caller take the ordinary draw path. The existing checks handle empty, written, inaccessible, oversized and pending-write ranges. The resource template remains unchanged; per-draw bindings retain their snapshots through the recorded batch.

The regression tests create an initially unrelocated recipe, switch between red and green inputs, repeat a relocated input, and return to the original one. They read every rendered pixel for both guest-buffer addresses and shader-data words. They also exercise refusal of written, inaccessible, empty and differently sized bindings, including the ordinary null-buffer fallback.

Related work: #9508 touches this path too. Its recipe.movedBuffers flag is initialized from !resolved.moved.empty(), and its moved-buffer check runs only when that flag was set. The regression here creates the recipe with no initial relocation and changes the binding on a later hit, so that conditional check does not cover it. This PR checks current bindings on every hit. These edits share a merge hunk and will need to be reconciled if both land; this PR does not depend on the GPU heap.

Tested

Windows 11 10.0.26200, Ryzen 5 5600, NVIDIA GeForce RTX 5070, driver 616.64, Release, WinLibs GCC 15.2.0 UCRT/POSIX r7. Tested base: eb41c5465d1fa7b8239be2a6e3a00bf9e58d3b1f. Rebased onto 57c0f6a48d before publication; the intervening merges do not change the AGC driver, shader recompiler, libc, or CMake helper sources used by these GPU tests.

The same focused tests ran on this machine and GPU against the base AGC library and the changed one, with the new tests present in both runs:

ANYPS5_REQUIRE_VULKAN=1
ANYPS5_NO_SHADER_CACHE=1
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation
ctest --test-dir <build> -R 'agc_driver_draw_cache_relocation|agc_driver_draw_recipe_(buffers|data)$|agc_driver_vertex_target_range' -V
  • Base: the eight existing tests pass. Both new pixel tests fail with recipe pixel 0 channel 0 is 255, expected 0 after selecting the green input.
  • Change: all ten tests pass, none skipped. Includes recipe/decode verification, eviction, retained relocation donors, the draw pipeline, plan verification, and copied/imported vertex-target range tests.
  • Inspected both complete verbose logs: zero VUID- lines, and neither contains was not found but was requested by env var VK_INSTANCE_LAYERS. The explicit validation layer was requested in both runs; implicit overlay layers were disabled for both through VK_LOADER_LAYERS_DISABLE=~implicit~.
  • Sniper Ghost Warrior Contracts 2, PPSA03131 01.004.000, relinked with --windows --no-patches: launch-screen diagnostic captures on the base and change, with the same supported runtime and validation layer. The base capture alternates background tints; the corrected 900-frame capture does not show that alternation, and the process remains alive at the 90-second capture limit. The last 80 sampled frames' largest adjacent background mean RGB changes are approximately (31.121, 26.336, 25.655) on the base and (0.400, 0.364, 0.399) on the change. Camera/animation timing differs between runs; these are diagnostic color observations, not a deterministic replay or a performance measurement. Neither game log contains a VUID- or missing-layer warning.
  • Planet Coaster, PPSA01735 01.017.000: both base and change still stop before rendering with the same guest access violation at PPSA01735.exe+0x9dca1, writing address 0xa4. This PR does not unblock that title.
  • python tools/check_conventions.py --base upstream/main: passes. The requested --base origin/main was also run; the fork main is stale and reports 18 errors in pre-existing upstream commits, unrelated to this five-file diff.

Overlap review: python tools/pr_overlap.py --branch codex/fix-draw-recipe-buffers --repo boykopovar/AnyPS5 examined 1,801 other open PRs at final head 0abeac5; 57 share files. It reports merge conflicts with #9508, #9897, #14032 and #16753, plus 28 comparisons it cannot complete automatically, so its exit status is 2, not a clean pass. I compared all 32 reported heads in the shared recipe path against their merge bases. Twenty-four do not change DrawWithRecipe; #7642 changes its batch bound, #9356/#9387/#15548 select mesh stages, #9897/#14032 check vertex ranges, and #16753 changes ownership and small-list bookkeeping. The conditional buffer relocation in #9508 is described above. No other inspected branch checks later buffer/data relocation for an initially unrelocated recipe. There are no shared exports or shared new test files.

No speed or new title-unblock claim is made. Diagnostic captures enable frame dumping and capture tracing; they are not performance traces.

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
  • GPUs tested: NVIDIA GeForce RTX 5070, driver 616.64, Windows 11 10.0.26200
  • AI-assisted: yes

@github-actions

github-actions Bot commented Nov 8, 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/Graphics/src/Draw.cpp
PR 1395 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 5609 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 5925 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 7002 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 7085 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 7256 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 7275 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 7668 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 8246 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 9356 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 9387 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 9508 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 9712 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 9852 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 9897 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 9915 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 10351 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 10442 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 10497 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 10678 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 11452 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
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 13147 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 13148 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 13809 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 13863 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 13920 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 13928 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 13929 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 14032 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 14944 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 15343 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 15456 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 15548 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 15570 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 15572 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 15941 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 16753 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 16760 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 16879 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 17611 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 17738 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 17850 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 17915 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 17943 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 17956 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 17976 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 18029 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 18177 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 18390 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 18515 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 19065 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 19100 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 19119 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 19373 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 19445 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 19620 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 19697 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 19852 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 20186 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 20315 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 20368 core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 20518 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 20519 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
PR 20578 core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp

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

The recipe path now calls the existing MovedReadOnlyBuffers check before recording, then passes the resulting binding updates into PrepareDrawBindings. That restores the normal draw path’s refresh for both relocated guest buffers and changed shader data. A rejected refresh returns a recipe miss before recording the draw. I traced that path and checked the submitted fixtures for red-to-green-to-red pixel output and fallback on unsafe bindings. The PR reports those pixel tests on an RTX 5070. Hosted Windows skipped both GPU cases, so I did not count that job as GPU execution.

@Meh7an

Meh7an commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Confirming this on Sonic Origins (PPSA05324), Windows 11, RTX 2080 Ti, driver 617.14: without this change, random regions of the 3D menu backgrounds render black (the S3K sea on some boots, other regions on others).

Bisecting by eye over the driver merges: 8ce7b561e4 (#6867) is clean and 12181acfaa is black. The merges between them don't boot on Windows because of the instance lock (#12970, later reverted), which is consistent with #7369 being the cause.

The same three-line change on main 78acbbf639 removes the black regions here. The same 38 focused draw tests under Vulkan validation came back identical on main and with the change (37 passed, 1 skipped, no VUID-).

@dantdmdarealguy

Copy link
Copy Markdown
Contributor

Title confirmation: Demon's Souls PPSA01341 v01.007.000, Windows 11 Pro, RTX 5080 (driver 32.0.16.1742), WinLibs GCC 15.2.0 Release, main 14bff3fc4a + #17787 (to get past a separate load crash), with and without this PR (0abeac5d9a).

Without it, character-creation text turns into grey boxes within a minute. Some strings show another string's glyphs (the "CHARACTER CREATION" header draws "Body Type"), and green full-screen triangles cover the scene. After the player dies in the tutorial, the whole UI layer draws an icon atlas and green triangles. APS5_NO_DRAW_RECIPE=1 or APS5_NO_DRAW_RELOCATION=1 avoids it; APS5_NO_UNIT_SHADOW=1 doesn't. With this PR the text stays correct (3+ minutes in character creation, class list included). The 11-04 libraries (5b1d381d5a) render it correctly too.

@PrivacyOnion
PrivacyOnion force-pushed the codex/fix-draw-recipe-buffers branch from edf8515 to 02191a1 Compare November 12, 2026 19:34
@PrivacyOnion

Copy link
Copy Markdown
Contributor Author

The Windows CI failure was in unrelated guest_relative_sleep (

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 14, 2026
@PrivacyOnion

Copy link
Copy Markdown
Contributor Author

Superseded by #17669 (already merged into main).

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

Labels

agc libSceAgc* build needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants