fix(agc): hold small labels behind completions that store guest memory #11995

Closed
josealissonbr wants to merge 6 commits from upstream-pr/11995 into main
josealissonbr commented 2026-10-27 15:57:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by josealissonbr on 2026-10-27T15:57:41Z.


What

A small label (8 bytes or less) recorded on the GPU could become visible before guest memory that an earlier batch of the same queue still had to store on the CPU at its completion. A title that polls the label then reads that memory before the store lands. In PPSA99903 the stage floor and buildings were drawn with stale constants and geometry (#11562).

WriteLabelOnGpu already held a small label behind the completion of pending work when a copied writer was listed. Two other kinds of completion also change what the driver knows about guest memory and were not counted:

  • the pages a BDA-writing shader wrote are marked possibly written in the write tracker only when its batch completes (BdaResources::markWrittenPages), so until then a CPU snapshot of those pages (constants, geometry) still counts as current;
  • the stored save of a storage texture updates its host-side baseline at completion (applyStoredSave).

Neither stores guest memory itself; a title that sees the label before them gets its next reads served from stale driver state.

Recorder::OnComplete now takes whether the completion updates guest state, and the recorder counts those completions until their batch finishes or is discarded, like the existing write-back completions. A completion updates guest state when its shader resources have copied writes (the write-back stores guest memory) or a BDA table that is not read-only (ShaderResources::UpdatesGuestStateAtCompletion), or when it applies a stored save. While any such completion is pending (Recorder::PendingGuestStateCompletions), a small label takes the existing held path (reason 5) instead of being recorded directly. The label line in docs/dev/debt/libSceAgcDriver.md lists the new condition.

agc_driver_indirect_thread_dimensions now expects reason 5 for the argument label written after a producer that stores through its BDA table; it fails on main. agc_driver_alias_copy_label asserts the reason that matches the pending completions (5 behind the image copy's stored save) instead of skipping when the label is held, and checks the copied bytes in both cases.

Tested

Windows 11 Pro 26200, NVIDIA GeForce RTX 5070 (driver 616.64), MinGW GCC 15.2 Release build.

  • PPSA99903 01.000.000 (Sonic the Hedgehog (2006) Recompiled), stage from #11562, tested in game with this commit on top of ae17955d2 before merging current main: the floor and buildings draw correctly with no flicker, at 15-28 presents per second depending on the scene. Without it they flicker; APS5_SYNC_DRAWS=1 or APS5_CPU_STORES=1 hid the bug at about 4 and 2-3 presents per second. A replay of an earlier frame capture of the stage with agc_frame_replay is also correct with it. Not retested in game after the merge with current main.
  • Head 40adf0a901 (main bb04a4f1ea merged), after review: the 65 tests matching indirect_thread|label|completion|copied_writ|write_back|writeback|agc_recorder|agc_driver_bda|agc_storage|agc_driver_storage|store_at|fence ran on this head and on main bb04a4f1ea with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ctest -R <pattern> -j 4 -V: 65 of 65 passed on both, none skipped, no VUID- line and no was not found but was requested by env var VK_INSTANCE_LAYERS in either log. agc_driver_alias_copy_label prints "the label after the image copy was stored at the reap" and passes. The full suite on 48c61f5289 plus the same merge passed 3027 of 3029: agc_driver_alias_copy_label timed out waiting for the held label (fixed in 40adf0a901, which only changes that test) and guest_freebsd_clocks exits with 0xc0000409, as it does on main bb04a4f1ea on this machine.
  • With current main merged: the full CTest suite with ANYPS5_REQUIRE_VULKAN=1 and ANYPS5_NO_SHADER_CACHE=1, 2668 of 2669 passed. agc_driver_mesh_barycentric_emulation fails ("the pixel shader did not emulate barycentrics"); it fails the same way on main e0cd1259a, so it is not from this change.
  • Vulkan validation: tools/vulkan_validation_gate.py refuses to run on Windows, so I followed the manual comparison of AGENTS.md. Every ^agc_ test ran on main e0cd1259a and on this branch with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (Khronos nightly layer, commit b2b44c0, API 1.4.366, through VK_LAYER_PATH), with ctest --test-dir build -R "^agc_" -j 6 -V. Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS. Both ran 1096 tests with the same agc_driver_mesh_barycentric_emulation failure; the same 19 tests logged validation messages on both, with the same IDs and counts (9 VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605, the rest warnings), so this change adds no new ID.

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: Fixes #11562
  • Unblocks: PPSA99903 #12932 (#11562)
  • GPUs tested: NVIDIA GeForce RTX 5070, driver 616.64, Windows 11 Pro 26200
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5037018593 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11995). Originally posted by [josealissonbr](https://github.com/josealissonbr) on 2026-10-27T15:57:41Z. --- ### What A small label (8 bytes or less) recorded on the GPU could become visible before guest memory that an earlier batch of the same queue still had to store on the CPU at its completion. A title that polls the label then reads that memory before the store lands. In PPSA99903 the stage floor and buildings were drawn with stale constants and geometry (#11562). `WriteLabelOnGpu` already held a small label behind the completion of pending work when a copied writer was listed. Two other kinds of completion also change what the driver knows about guest memory and were not counted: - the pages a BDA-writing shader wrote are marked possibly written in the write tracker only when its batch completes (`BdaResources::markWrittenPages`), so until then a CPU snapshot of those pages (constants, geometry) still counts as current; - the stored save of a storage texture updates its host-side baseline at completion (`applyStoredSave`). Neither stores guest memory itself; a title that sees the label before them gets its next reads served from stale driver state. `Recorder::OnComplete` now takes whether the completion updates guest state, and the recorder counts those completions until their batch finishes or is discarded, like the existing write-back completions. A completion updates guest state when its shader resources have copied writes (the write-back stores guest memory) or a BDA table that is not read-only (`ShaderResources::UpdatesGuestStateAtCompletion`), or when it applies a stored save. While any such completion is pending (`Recorder::PendingGuestStateCompletions`), a small label takes the existing held path (reason 5) instead of being recorded directly. The label line in `docs/dev/debt/libSceAgcDriver.md` lists the new condition. `agc_driver_indirect_thread_dimensions` now expects reason 5 for the argument label written after a producer that stores through its BDA table; it fails on `main`. `agc_driver_alias_copy_label` asserts the reason that matches the pending completions (5 behind the image copy's stored save) instead of skipping when the label is held, and checks the copied bytes in both cases. ### Tested Windows 11 Pro 26200, NVIDIA GeForce RTX 5070 (driver 616.64), MinGW GCC 15.2 Release build. - PPSA99903 01.000.000 (Sonic the Hedgehog (2006) Recompiled), stage from #11562, tested in game with this commit on top of `ae17955d2` before merging current `main`: the floor and buildings draw correctly with no flicker, at 15-28 presents per second depending on the scene. Without it they flicker; `APS5_SYNC_DRAWS=1` or `APS5_CPU_STORES=1` hid the bug at about 4 and 2-3 presents per second. A replay of an earlier frame capture of the stage with `agc_frame_replay` is also correct with it. Not retested in game after the merge with current `main`. - Head 40adf0a901 (`main` bb04a4f1ea merged), after review: the 65 tests matching `indirect_thread|label|completion|copied_writ|write_back|writeback|agc_recorder|agc_driver_bda|agc_storage|agc_driver_storage|store_at|fence` ran on this head and on `main` bb04a4f1ea with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ctest -R <pattern> -j 4 -V`: 65 of 65 passed on both, none skipped, no `VUID-` line and no `was not found but was requested by env var VK_INSTANCE_LAYERS` in either log. `agc_driver_alias_copy_label` prints "the label after the image copy was stored at the reap" and passes. The full suite on 48c61f5289 plus the same merge passed 3027 of 3029: `agc_driver_alias_copy_label` timed out waiting for the held label (fixed in 40adf0a901, which only changes that test) and `guest_freebsd_clocks` exits with 0xc0000409, as it does on `main` bb04a4f1ea on this machine. - With current `main` merged: the full CTest suite with `ANYPS5_REQUIRE_VULKAN=1` and `ANYPS5_NO_SHADER_CACHE=1`, 2668 of 2669 passed. `agc_driver_mesh_barycentric_emulation` fails ("the pixel shader did not emulate barycentrics"); it fails the same way on `main` e0cd1259a, so it is not from this change. - Vulkan validation: `tools/vulkan_validation_gate.py` refuses to run on Windows, so I followed the manual comparison of AGENTS.md. Every `^agc_` test ran on `main` e0cd1259a and on this branch with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (Khronos nightly layer, commit b2b44c0, API 1.4.366, through `VK_LAYER_PATH`), with `ctest --test-dir build -R "^agc_" -j 6 -V`. Neither log contains `was not found but was requested by env var VK_INSTANCE_LAYERS`. Both ran 1096 tests with the same `agc_driver_mesh_barycentric_emulation` failure; the same 19 tests logged validation messages on both, with the same IDs and counts (9 `VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605`, the rest warnings), so this change adds no new ID. ### 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: Fixes #11562 - [x] Unblocks: PPSA99903 #12932 (#11562) - [x] GPUs tested: NVIDIA GeForce RTX 5070, driver 616.64, Windows 11 Pro 26200 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
XairRrR commented 2026-10-29 16:10:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T16:10:18Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

The change merges cleanly, builds, and the label and completion tests pass, but it makes the existing agc_driver_alias_copy_label test skip itself instead of running, so that ordering check no longer runs.

What I ran

  • PR head: 368bdbcc0c9c4c18293153550d0f264f68194d4d
  • main: bb04a4f1ea0175e9e4f149f0359a764d62ff3296
  • Merged tree (head merged onto main with --no-ff, no conflicts): 314b83a3a7705575f0416cd9e6fc06b618b28d93
  • Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF, NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.78.08); Release, Ninja, BUILD_TESTING=ON, in a clean worktree.
git fetch origin main pull/11995/head:refs/review/11995
git checkout --detach origin/main
git merge --no-ff --no-edit refs/review/11995
git diff --check origin/main...refs/review/11995
python3 tools/check_conventions.py --base origin/main
cmake --build build -j10
cmake --build build -j10 --target libs

R='indirect_thread|label|completion|copied_writ|write_back|writeback|agc_recorder|agc_driver_bda|agc_storage|agc_driver_storage|store_at|fence'
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 \
  VK_LOADER_DEBUG=error,warn,layer ctest --test-dir build -R "$R" -j4 -V --output-on-failure

# negative control: production files from main, PR test kept
git checkout origin/main -- core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp \
  core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp \
  core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp \
  core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp \
  core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp \
  core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
cmake --build build -j10
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest --test-dir build -R indirect_thread_dimensions --output-on-failure

# baseline: the whole tree at main (test file too), same 64 tests, same environment
git checkout origin/main -- core/libs/prx/libSceAgcDriver/tests/execution/IndirectThreadDimensions.cpp
cmake --build build -j10
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 \
  VK_LOADER_DEBUG=error,warn,layer ctest --test-dir build -R "$R" -j4 -V --output-on-failure

Results

Check Result
Merge onto main Clean
git diff --check Clean
tools/check_conventions.py --base origin/main All conventions checks passed.
Full build + --target libs (merged tree) Passed
64 label/completion/write-back/BDA/storage tests, merged tree, with validation 64/64 passed (the count includes 6 skips)
Same 64 tests on main, with validation 64/64 passed (the count includes 5 skips)
agc_driver_alias_copy_label Runs and passes on main; skips on the merged tree ("the label was not recorded on the GPU (reason 5)")
VUID- lines None in either log
was not found but was requested by env var VK_INSTANCE_LAYERS Absent from both logs; the loader reports adding VK_LAYER_KHRONOS_validation
Negative control (agc_driver_indirect_thread_dimensions) Fails without the production change, as expected
Skipped tests, merged tree vs main

Merged tree:

824 - agc_driver_bda_reads_shadowed_results (Skipped)
825 - agc_driver_bda_reads_shadowed_results_per_build (Skipped)
826 - agc_unit_shadow_completion_store (Skipped)
968 - agc_driver_alias_copy_label (Skipped)
2349 - video_out_flip_labels (Skipped)
2350 - video_out_flip_labels_main (Skipped)

968: skipped, the label was not recorded on the GPU (reason 5)

main:

824 - agc_driver_bda_reads_shadowed_results (Skipped)
825 - agc_driver_bda_reads_shadowed_results_per_build (Skipped)
826 - agc_unit_shadow_completion_store (Skipped)
2349 - video_out_flip_labels (Skipped)
2350 - video_out_flip_labels_main (Skipped)

968: alias copy label tests passed
Negative control output
1/2 Test  #876: agc_driver_indirect_thread_dimensions_cpu ...   Passed    0.79 sec
2/2 Test #1229: agc_driver_indirect_thread_dimensions .......***Failed    1.13 sec
the argument label was not held behind the completion of the producer that stores through the BDA table
50% tests passed, 1 tests failed out of 2

Negative control

I restored the six production files from main, kept the PR's IndirectThreadDimensions.cpp, and rebuilt. agc_driver_indirect_thread_dimensions then failed with the PR's new message, so the changed expectation does depend on the change. The _cpu variant (APS5_NO_GPU_THREAD_DIMENSIONS=1) passes both ways. After this check I restored the merged files.

Findings

Blocking

  1. The change disables agc_driver_alias_copy_label. The test stores to an image with a compute dispatch, copies that image with CopyBuffer (path 3), and records a 4-byte label. It then checks that a CPU read after the label sees the copied bytes. When WriteLabelOnGpu returns anything other than 0, the test returns VulkanTestSkipped (AliasCopyLabel.cpp#L113-L117). On main the label returns 0 and the test passes. On the merged tree it returns 5, and the only difference in WriteLabelOnGpu is the new PendingGuestStoreCompletions() != 0 term (VulkanDevice.cpp#L2542). Skip exit code 77 counts as passed in CTest, so the full-suite run in the description and the NVIDIA bot's "0 new" failures both miss this. The image-copy-then-label ordering that this test guards is now untested.
    Suggested fix: make the test handle reason 5, since the label is now stored at the reap. Accept 5, reap or sync the recorder until the label lands, then compare the destination bytes as before. Keep the GPU-store case covered too, either by a setup where no guest-store completion is pending or by asserting which path was taken. A skip should mean the device lacks something, not that the driver took a different path.

Non-blocking

  1. Neither new completion kind stores guest memory, unlike what the description and names say. markWrittenPages only calls GuestMemory::MarkPossiblyWritten, which stamps the write tracker (BdaResources.cpp#L340-L356). applyStoredSave copies into the texture's host-side original baseline, not guest memory (Texture.cpp#L4425-L4437). The hazard is therefore driver bookkeeping (snapshot or compare state) lagging behind the label, not memory the title reads directly. StoresAtCompletion / PendingGuestStoreCompletions and the PR text point readers at the wrong mechanism.
    Suggested fix: rename to something like UpdatesTrackingAtCompletion / PendingTrackingCompletions, and correct the description.
  2. The debt entry no longer describes when a small label is delayed. docs/dev/debt/libSceAgcDriver.md#L169 says a label of 8 bytes or less is stored by the CPU "while a copied writer is listed, or while an earlier completion store is pending". With this PR it is also delayed while any BDA-writing dispatch or draw, or any stored save, has a pending completion. That widens a documented deviation (the label becomes visible up to one reap later than on the console).
    Suggested fix: update that line in this PR.
  3. The delay probably affects far more labels. StoresAtCompletion holds for every shader with a non-read-only BDA table, and the counter is process-wide. So every fence or RELEASE_MEM label now goes through the CPU-at-reap path while such work is in flight. The description gives presents per second for PPSA99903 only. I could not measure other titles; a tools/trace_digest.py comparison of main and this change on one more title that uses BDA writes would show whether label latency regresses.
  4. No test covers the bug being fixed. The only test change flips the expectation in IndirectThreadDimensions.cpp from 0 to 5. A focused test would close that gap: a BDA-writing dispatch, then a small label, then a check that a cached snapshot of the written range is invalidated once the label is observed. It would fail on main and pass here.

Not verified

  • The in-game fix for PPSA99903 / #11562; I do not run titles.
  • Performance impact on any title.
  • The full CTest suite; I ran the 64 tests matching the label, completion, write-back, BDA and storage paths.
  • Windows / MinGW build.

To get this to a good state

  • Make agc_driver_alias_copy_label run again on the merged tree, accepting or asserting the held path (reason 5), and confirm it no longer skips.
  • Update the label line in docs/dev/debt/libSceAgcDriver.md for the new condition.
  • Optionally rename the new helpers and correct the description so they say the completions update write tracking or compare baselines, not guest memory.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5701021035 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11995#pullrequestreview-5701021035). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-29T16:10:18Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested The change merges cleanly, builds, and the label and completion tests pass, but it makes the existing `agc_driver_alias_copy_label` test skip itself instead of running, so that ordering check no longer runs. ## What I ran - PR head: `368bdbcc0c9c4c18293153550d0f264f68194d4d` - `main`: `bb04a4f1ea0175e9e4f149f0359a764d62ff3296` - Merged tree (head merged onto `main` with `--no-ff`, no conflicts): `314b83a3a7705575f0416cd9e6fc06b618b28d93` - Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF, NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.78.08); Release, Ninja, `BUILD_TESTING=ON`, in a clean worktree. ```sh git fetch origin main pull/11995/head:refs/review/11995 git checkout --detach origin/main git merge --no-ff --no-edit refs/review/11995 git diff --check origin/main...refs/review/11995 python3 tools/check_conventions.py --base origin/main cmake --build build -j10 cmake --build build -j10 --target libs R='indirect_thread|label|completion|copied_writ|write_back|writeback|agc_recorder|agc_driver_bda|agc_storage|agc_driver_storage|store_at|fence' VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 \ VK_LOADER_DEBUG=error,warn,layer ctest --test-dir build -R "$R" -j4 -V --output-on-failure # negative control: production files from main, PR test kept git checkout origin/main -- core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp \ core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp \ core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp \ core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp \ core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp \ core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp cmake --build build -j10 ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest --test-dir build -R indirect_thread_dimensions --output-on-failure # baseline: the whole tree at main (test file too), same 64 tests, same environment git checkout origin/main -- core/libs/prx/libSceAgcDriver/tests/execution/IndirectThreadDimensions.cpp cmake --build build -j10 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 \ VK_LOADER_DEBUG=error,warn,layer ctest --test-dir build -R "$R" -j4 -V --output-on-failure ``` ## Results | Check | Result | |---|---| | Merge onto `main` | Clean | | `git diff --check` | Clean | | `tools/check_conventions.py --base origin/main` | `All conventions checks passed.` | | Full build + `--target libs` (merged tree) | Passed | | 64 label/completion/write-back/BDA/storage tests, merged tree, with validation | 64/64 passed (the count includes 6 skips) | | Same 64 tests on `main`, with validation | 64/64 passed (the count includes 5 skips) | | `agc_driver_alias_copy_label` | **Runs and passes on `main`; skips on the merged tree** ("the label was not recorded on the GPU (reason 5)") | | `VUID-` lines | None in either log | | `was not found but was requested by env var VK_INSTANCE_LAYERS` | Absent from both logs; the loader reports adding `VK_LAYER_KHRONOS_validation` | | Negative control (`agc_driver_indirect_thread_dimensions`) | Fails without the production change, as expected | <details><summary>Skipped tests, merged tree vs main</summary> Merged tree: ``` 824 - agc_driver_bda_reads_shadowed_results (Skipped) 825 - agc_driver_bda_reads_shadowed_results_per_build (Skipped) 826 - agc_unit_shadow_completion_store (Skipped) 968 - agc_driver_alias_copy_label (Skipped) 2349 - video_out_flip_labels (Skipped) 2350 - video_out_flip_labels_main (Skipped) 968: skipped, the label was not recorded on the GPU (reason 5) ``` `main`: ``` 824 - agc_driver_bda_reads_shadowed_results (Skipped) 825 - agc_driver_bda_reads_shadowed_results_per_build (Skipped) 826 - agc_unit_shadow_completion_store (Skipped) 2349 - video_out_flip_labels (Skipped) 2350 - video_out_flip_labels_main (Skipped) 968: alias copy label tests passed ``` </details> <details><summary>Negative control output</summary> ``` 1/2 Test #876: agc_driver_indirect_thread_dimensions_cpu ... Passed 0.79 sec 2/2 Test #1229: agc_driver_indirect_thread_dimensions .......***Failed 1.13 sec the argument label was not held behind the completion of the producer that stores through the BDA table 50% tests passed, 1 tests failed out of 2 ``` </details> ## Negative control I restored the six production files from `main`, kept the PR's `IndirectThreadDimensions.cpp`, and rebuilt. `agc_driver_indirect_thread_dimensions` then failed with the PR's new message, so the changed expectation does depend on the change. The `_cpu` variant (`APS5_NO_GPU_THREAD_DIMENSIONS=1`) passes both ways. After this check I restored the merged files. ## Findings ### Blocking 1. **The change disables `agc_driver_alias_copy_label`.** The test stores to an image with a compute dispatch, copies that image with `CopyBuffer` (path 3), and records a 4-byte label. It then checks that a CPU read after the label sees the copied bytes. When `WriteLabelOnGpu` returns anything other than 0, the test returns `VulkanTestSkipped` ([AliasCopyLabel.cpp#L113-L117](https://github.com/boykopovar/AnyPS5/blob/368bdbcc0c9c4c18293153550d0f264f68194d4d/core/libs/prx/libSceAgcDriver/tests/execution/AliasCopyLabel.cpp#L113-L117)). On `main` the label returns 0 and the test passes. On the merged tree it returns 5, and the only difference in `WriteLabelOnGpu` is the new `PendingGuestStoreCompletions() != 0` term ([VulkanDevice.cpp#L2542](https://github.com/boykopovar/AnyPS5/blob/368bdbcc0c9c4c18293153550d0f264f68194d4d/core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp#L2542)). Skip exit code 77 counts as passed in CTest, so the full-suite run in the description and the NVIDIA bot's "0 new" failures both miss this. The image-copy-then-label ordering that this test guards is now untested. Suggested fix: make the test handle reason 5, since the label is now stored at the reap. Accept 5, reap or sync the recorder until the label lands, then compare the destination bytes as before. Keep the GPU-store case covered too, either by a setup where no guest-store completion is pending or by asserting which path was taken. A skip should mean the device lacks something, not that the driver took a different path. ### Non-blocking 1. **Neither new completion kind stores guest memory, unlike what the description and names say.** `markWrittenPages` only calls `GuestMemory::MarkPossiblyWritten`, which stamps the write tracker ([BdaResources.cpp#L340-L356](https://github.com/boykopovar/AnyPS5/blob/368bdbcc0c9c4c18293153550d0f264f68194d4d/core/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cpp#L340-L356)). `applyStoredSave` copies into the texture's host-side `original` baseline, not guest memory ([Texture.cpp#L4425-L4437](https://github.com/boykopovar/AnyPS5/blob/368bdbcc0c9c4c18293153550d0f264f68194d4d/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp#L4425-L4437)). The hazard is therefore driver bookkeeping (snapshot or compare state) lagging behind the label, not memory the title reads directly. `StoresAtCompletion` / `PendingGuestStoreCompletions` and the PR text point readers at the wrong mechanism. Suggested fix: rename to something like `UpdatesTrackingAtCompletion` / `PendingTrackingCompletions`, and correct the description. 2. **The debt entry no longer describes when a small label is delayed.** [docs/dev/debt/libSceAgcDriver.md#L169](https://github.com/boykopovar/AnyPS5/blob/bb04a4f1ea0175e9e4f149f0359a764d62ff3296/docs/dev/debt/libSceAgcDriver.md#L169) says a label of 8 bytes or less is stored by the CPU "while a copied writer is listed, or while an earlier completion store is pending". With this PR it is also delayed while any BDA-writing dispatch or draw, or any stored save, has a pending completion. That widens a documented deviation (the label becomes visible up to one reap later than on the console). Suggested fix: update that line in this PR. 3. **The delay probably affects far more labels.** [`StoresAtCompletion`](https://github.com/boykopovar/AnyPS5/blob/368bdbcc0c9c4c18293153550d0f264f68194d4d/core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp#L240) holds for every shader with a non-read-only BDA table, and the counter is process-wide. So every fence or `RELEASE_MEM` label now goes through the CPU-at-reap path while such work is in flight. The description gives presents per second for PPSA99903 only. I could not measure other titles; a `tools/trace_digest.py` comparison of `main` and this change on one more title that uses BDA writes would show whether label latency regresses. 4. **No test covers the bug being fixed.** The only test change flips the expectation in `IndirectThreadDimensions.cpp` from 0 to 5. A focused test would close that gap: a BDA-writing dispatch, then a small label, then a check that a cached snapshot of the written range is invalidated once the label is observed. It would fail on `main` and pass here. ## Not verified - The in-game fix for PPSA99903 / #11562; I do not run titles. - Performance impact on any title. - The full CTest suite; I ran the 64 tests matching the label, completion, write-back, BDA and storage paths. - Windows / MinGW build. ## To get this to a good state - Make `agc_driver_alias_copy_label` run again on the merged tree, accepting or asserting the held path (reason 5), and confirm it no longer skips. - Update the label line in `docs/dev/debt/libSceAgcDriver.md` for the new condition. - Optionally rename the new helpers and correct the description so they say the completions update write tracking or compare baselines, not guest memory.
XairRrR commented 2026-11-02 20:03:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T20:03:58Z.

Review: CHANGES_REQUESTED


Re-checked — changes still requested

The new commits (48c61f5289, 40adf0a901, then the merge de8ef8f64d) fix the agc_driver_alias_copy_label skip, rename the helpers and update the debt entry. But merged with current main, the change makes agc_driver_linear_target_completion_stores fail. That test arrived on main in 0ec6032d23, after this branch last merged main.

What changed since my last review

  • AliasCopyLabel.cpp no longer skips. It checks for reason 5 when a guest-state completion or a completion store is pending, and reason 0 otherwise. When the label is held, it waits for the epoch, checks the label is still not visible, reaps the batch, and then compares the bytes.
  • StoresAtCompletion, PendingGuestStoreCompletions and storesGuest are renamed to UpdatesGuestStateAtCompletion, PendingGuestStateCompletions and updatesGuestState. The description now says that the BDA and stored-save completions update driver state, not guest memory.
  • The label line in docs/dev/debt/libSceAgcDriver.md lists the new condition.
  • A merge of main 0278ca9831.
  • Author comment: a tools/trace_digest.py comparison on PPSA01325 or PPSA28997 is promised. It has not been posted yet.

What I ran

  • PR head de8ef8f64d9ec636b4d497a52d180ce7b302f671, main c955a63d3d20822e13bb1c6b55ac5800ca5e4176, merged tree 1a0b24c261730d50517d9a85e3f393e655b355eb (clean --no-ff merge).
  • Debian 13 VM with 32 vCPU (Xeon Gold 6136), GCC 14.2.0, Release, Ninja, lavapipe (Mesa 26.1.6, LLVM 19).
git diff --check c955a63d3d20822e13bb1c6b55ac5800ca5e4176...de8ef8f64d9ec636b4d497a52d180ce7b302f671
python3 tools/check_conventions.py --base c955a63d3d20822e13bb1c6b55ac5800ca5e4176
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 GALLIUM_OVERRIDE_CPU_CAPS=avx \
  ctest --test-dir build -j4 --output-on-failure \
  -R "linear_target_completion_stores|alias_copy_label|indirect_thread_dimensions"

# negative control: the six production files from main, the PR's tests kept
for p in Execution/src/VulkanDevice.cpp Graphics/include/Recorder.hpp Graphics/include/ShaderResources.hpp \
         Graphics/src/Draw.cpp Graphics/src/Recorder.cpp Graphics/src/Texture.cpp; do
  git show c955a63d3d20822e13bb1c6b55ac5800ca5e4176:core/libs/prx/libSceAgcDriver/$p > core/libs/prx/libSceAgcDriver/$p
done
ninja -C build agc_driver_indirect_thread_dimensions_tests agc_driver_linear_target_completion_stores_tests
ctest --test-dir build -j2 --output-on-failure -R "linear_target_completion_stores|indirect_thread_dimensions$"
# restore the same files from 1a0b24c261, rebuild, rerun, git status --porcelain (empty)
Check Result
git diff --check Clean
check_conventions.py All conventions checks passed.
Build, libs (script) Passed
Selected tests (script) 2091 ran: 1972 passed, 111 skipped (all expected). 1 new failure: agc_driver_linear_target_completion_stores. The 7 failures listed as known also fail on main. The 2 main_sync_renames_* tests listed as fixed are tool tests this change does not touch.
agc_driver_alias_copy_label Passes and prints the label after the image copy was stored at the reap
agc_driver_indirect_thread_dimensions, _cpu Pass
agc_driver_linear_target_completion_stores Fails: the first label: the label was not recorded on the GPU (outcome 5)
Same test with main's production files Passes
Vulkan validation comparison Not made (no baseline run on main yet)
Negative control output
1/2 Test #1157: agc_driver_linear_target_completion_stores ...   Passed    0.35 sec
2/2 Test #1126: agc_driver_indirect_thread_dimensions ........***Failed    0.76 sec
the argument label was not held behind the completion of the producer that stores through the BDA table

Negative control result: agc_driver_indirect_thread_dimensions fails without the production change, as before. AliasCopyLabel.cpp calls Recorder::PendingGuestStateCompletions, so it does not build against main's Recorder.hpp, and I could not run it in the negative control. After restoring the merged files, git status --porcelain was empty, and the merged-tree results were reproduced.

Previous findings

  • Blocking — agc_driver_alias_copy_label skipped: Resolved. It runs and passes on the merged tree on lavapipe and takes the held path. The GPU-store path is now asserted rather than skipped.
  • Non-blocking — names and description said "stores guest memory": Resolved. The helpers are renamed to UpdatesGuestStateAtCompletion and PendingGuestStateCompletions, and the description is corrected.
  • Non-blocking — debt entry not updated: Resolved. docs/dev/debt/libSceAgcDriver.md now lists pending completions of address-table writers and of stored saves.
  • Non-blocking — wider label delay in other titles: Still open. The promised trace_digest.py pair has not been posted. The new failure below is a concrete case of this widening.
  • Non-blocking — no focused test for the stale-snapshot bug: Still open. I accept that IndirectThreadDimensions proves the label is now held: it fails on main. No test checks that the stale snapshot or baseline is what the hold prevents. This is still optional.

New findings

Blocking

  1. agc_driver_linear_target_completion_stores fails with this change.
    • main 0ec6032d23 made a graphics-queue label store resident linear color targets first and then record the label on the GPU behind that store (core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp:2601). The test requires reason 0 for that label (core/libs/prx/libSceAgcDriver/tests/execution/LinearTargetCompletionStores.cpp:228).
    • With this PR, the label returns 5. That store goes through FlushPending, which very likely reaches commitStoredSave. This PR now registers the stored-save completion with updatesGuestState = true (core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp:4827-4829). The new PendingGuestStateCompletions() != 0 term (VulkanDevice.cpp:2648) then holds the label.
    • I did not confirm with a debugger that the stored save is the trigger. The test's draws use no address table, though, and with main's production files the test passes.
    • Why it matters: every small graphics-queue label after a draw into a linear target now goes to the CPU-at-reap path. That defeats the in-order GPU label that 0ec6032d23 relies on, and it is a failing test on the merged tree.
    • Suggested fix: decide whether the stored save of a target stored right before the label needs the hold. The GPU store and the label are in one batch in order, so the pending baseline update may not be observable before the label. If it doesn't need the hold, exclude that case, for example by not counting a stored save that StoreDrawnLinear triggers from within WriteLabelOnGpu. If it does, change that test's expectation and say why in the description and the debt entry. Either way, merge current main and rerun the label tests.

Non-blocking

None.

Not verified

  • The Vulkan validation comparison against main: the script had no validation baseline for main 0278ca9831, and I did not run one myself.
  • The negative control for AliasCopyLabel.cpp: it does not build without the PR's Recorder.hpp.
  • The in-game result on PPSA99903, performance in other titles, and Windows or MinGW builds. The author's and other contributors' runs (NVIDIA RTX 5070, RTX 2000 Ada, AMD RX 9070 XT) are accepted as reported, and all of them predate 0ec6032d23 on main.

To get this to a good state

  • Merge current main and make agc_driver_linear_target_completion_stores pass: either stop counting the stored save that a label's own linear-target store triggers, or justify and change its expectation.
  • Rerun the focused label, completion and storage tests with the validation layer on the new merge.
  • Optional: post the promised trace_digest.py comparison on a second title.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5742592519 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11995#pullrequestreview-5742592519). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-02T20:03:58Z. **Review:** CHANGES_REQUESTED --- # Re-checked — changes still requested The new commits (48c61f5289, 40adf0a901, then the merge de8ef8f64d) fix the `agc_driver_alias_copy_label` skip, rename the helpers and update the debt entry. But merged with current `main`, the change makes `agc_driver_linear_target_completion_stores` fail. That test arrived on `main` in 0ec6032d23, after this branch last merged `main`. ## What changed since my last review - `AliasCopyLabel.cpp` no longer skips. It checks for reason 5 when a guest-state completion or a completion store is pending, and reason 0 otherwise. When the label is held, it waits for the epoch, checks the label is still not visible, reaps the batch, and then compares the bytes. - `StoresAtCompletion`, `PendingGuestStoreCompletions` and `storesGuest` are renamed to `UpdatesGuestStateAtCompletion`, `PendingGuestStateCompletions` and `updatesGuestState`. The description now says that the BDA and stored-save completions update driver state, not guest memory. - The label line in `docs/dev/debt/libSceAgcDriver.md` lists the new condition. - A merge of `main` 0278ca9831. - Author comment: a `tools/trace_digest.py` comparison on PPSA01325 or PPSA28997 is promised. It has not been posted yet. ## What I ran - PR head `de8ef8f64d9ec636b4d497a52d180ce7b302f671`, `main` `c955a63d3d20822e13bb1c6b55ac5800ca5e4176`, merged tree `1a0b24c261730d50517d9a85e3f393e655b355eb` (clean `--no-ff` merge). - Debian 13 VM with 32 vCPU (Xeon Gold 6136), GCC 14.2.0, Release, Ninja, lavapipe (Mesa 26.1.6, LLVM 19). ```sh git diff --check c955a63d3d20822e13bb1c6b55ac5800ca5e4176...de8ef8f64d9ec636b4d497a52d180ce7b302f671 python3 tools/check_conventions.py --base c955a63d3d20822e13bb1c6b55ac5800ca5e4176 ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 GALLIUM_OVERRIDE_CPU_CAPS=avx \ ctest --test-dir build -j4 --output-on-failure \ -R "linear_target_completion_stores|alias_copy_label|indirect_thread_dimensions" # negative control: the six production files from main, the PR's tests kept for p in Execution/src/VulkanDevice.cpp Graphics/include/Recorder.hpp Graphics/include/ShaderResources.hpp \ Graphics/src/Draw.cpp Graphics/src/Recorder.cpp Graphics/src/Texture.cpp; do git show c955a63d3d20822e13bb1c6b55ac5800ca5e4176:core/libs/prx/libSceAgcDriver/$p > core/libs/prx/libSceAgcDriver/$p done ninja -C build agc_driver_indirect_thread_dimensions_tests agc_driver_linear_target_completion_stores_tests ctest --test-dir build -j2 --output-on-failure -R "linear_target_completion_stores|indirect_thread_dimensions$" # restore the same files from 1a0b24c261, rebuild, rerun, git status --porcelain (empty) ``` | Check | Result | |---|---| | `git diff --check` | Clean | | `check_conventions.py` | `All conventions checks passed.` | | Build, `libs` (script) | Passed | | Selected tests (script) | 2091 ran: 1972 passed, 111 skipped (all expected). **1 new failure:** `agc_driver_linear_target_completion_stores`. The 7 failures listed as known also fail on `main`. The 2 `main_sync_renames_*` tests listed as fixed are tool tests this change does not touch. | | `agc_driver_alias_copy_label` | Passes and prints `the label after the image copy was stored at the reap` | | `agc_driver_indirect_thread_dimensions`, `_cpu` | Pass | | `agc_driver_linear_target_completion_stores` | **Fails**: `the first label: the label was not recorded on the GPU (outcome 5)` | | Same test with `main`'s production files | Passes | | Vulkan validation comparison | Not made (no baseline run on `main` yet) | <details><summary>Negative control output</summary> ``` 1/2 Test #1157: agc_driver_linear_target_completion_stores ... Passed 0.35 sec 2/2 Test #1126: agc_driver_indirect_thread_dimensions ........***Failed 0.76 sec the argument label was not held behind the completion of the producer that stores through the BDA table ``` </details> **Negative control result:** `agc_driver_indirect_thread_dimensions` fails without the production change, as before. `AliasCopyLabel.cpp` calls `Recorder::PendingGuestStateCompletions`, so it does not build against `main`'s `Recorder.hpp`, and I could not run it in the negative control. After restoring the merged files, `git status --porcelain` was empty, and the merged-tree results were reproduced. ## Previous findings - **Blocking — `agc_driver_alias_copy_label` skipped: Resolved.** It runs and passes on the merged tree on lavapipe and takes the held path. The GPU-store path is now asserted rather than skipped. - **Non-blocking — names and description said "stores guest memory": Resolved.** The helpers are renamed to `UpdatesGuestStateAtCompletion` and `PendingGuestStateCompletions`, and the description is corrected. - **Non-blocking — debt entry not updated: Resolved.** `docs/dev/debt/libSceAgcDriver.md` now lists pending completions of address-table writers and of stored saves. - **Non-blocking — wider label delay in other titles: Still open.** The promised `trace_digest.py` pair has not been posted. The new failure below is a concrete case of this widening. - **Non-blocking — no focused test for the stale-snapshot bug: Still open.** I accept that `IndirectThreadDimensions` proves the label is now held: it fails on `main`. No test checks that the stale snapshot or baseline is what the hold prevents. This is still optional. ## New findings ### Blocking 1. **`agc_driver_linear_target_completion_stores` fails with this change.** - `main` 0ec6032d23 made a graphics-queue label store resident linear color targets first and then record the label on the GPU behind that store (`core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp:2601`). The test requires reason 0 for that label (`core/libs/prx/libSceAgcDriver/tests/execution/LinearTargetCompletionStores.cpp:228`). - With this PR, the label returns 5. That store goes through `FlushPending`, which very likely reaches `commitStoredSave`. This PR now registers the stored-save completion with `updatesGuestState = true` (`core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp:4827-4829`). The new `PendingGuestStateCompletions() != 0` term (`VulkanDevice.cpp:2648`) then holds the label. - I did not confirm with a debugger that the stored save is the trigger. The test's draws use no address table, though, and with `main`'s production files the test passes. - **Why it matters:** every small graphics-queue label after a draw into a linear target now goes to the CPU-at-reap path. That defeats the in-order GPU label that 0ec6032d23 relies on, and it is a failing test on the merged tree. - **Suggested fix:** decide whether the stored save of a target stored right before the label needs the hold. The GPU store and the label are in one batch in order, so the pending baseline update may not be observable before the label. If it doesn't need the hold, exclude that case, for example by not counting a stored save that `StoreDrawnLinear` triggers from within `WriteLabelOnGpu`. If it does, change that test's expectation and say why in the description and the debt entry. Either way, merge current `main` and rerun the label tests. ### Non-blocking None. ## Not verified - The Vulkan validation comparison against `main`: the script had no validation baseline for `main` 0278ca9831, and I did not run one myself. - The negative control for `AliasCopyLabel.cpp`: it does not build without the PR's `Recorder.hpp`. - The in-game result on PPSA99903, performance in other titles, and Windows or MinGW builds. The author's and other contributors' runs (NVIDIA RTX 5070, RTX 2000 Ada, AMD RX 9070 XT) are accepted as reported, and all of them predate 0ec6032d23 on `main`. ## To get this to a good state - Merge current `main` and make `agc_driver_linear_target_completion_stores` pass: either stop counting the stored save that a label's own linear-target store triggers, or justify and change its expectation. - Rerun the focused label, completion and storage tests with the validation layer on the new merge. - Optional: post the promised `trace_digest.py` comparison on a second title. <!-- anyps5-bots job=1903 head=de8ef8f64d9ec636b4d497a52d180ce7b302f671 -->

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!11995
No description provided.