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

Closed
PrivacyOnion wants to merge 1 commit from upstream-pr/17157 into main
PrivacyOnion commented 2026-11-08 12:59:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-08T12:59:59Z.


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 0abeac5d9a; 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5211515773 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17157). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-08T12:59:59Z. --- ### 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 <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> 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: ```text 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 0abeac5d9a; 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 <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 5070, driver 616.64, Windows 11 10.0.26200 - [x] AI-assisted: yes
THEMANnt commented 2026-11-08 20:48:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-11-08T20:48:04Z.

Review: APPROVED


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5819606001 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17157#pullrequestreview-5819606001). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-11-08T20:48:04Z. **Review:** APPROVED --- 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](https://github.com/boykopovar/AnyPS5/actions/runs/42482823097/job/128738441171) skipped both GPU cases, so I did not count that job as GPU execution.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!17157
No description provided.