fix(agc): invalidate primary draw state after secondary execution #27875

Open
IvanFogel wants to merge 2 commits from upstream-pr/27875 into main
IvanFogel commented 2026-11-27 17:43:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by IvanFogel on 2026-11-27T17:43:04Z.


What

With APS5_PARALLEL_ATLAS=1, a draw can execute a secondary Vulkan command buffer and then return to recording on the primary. The primary recorder still remembers the pipeline and dynamic state from its previous draw. If the next draw requests the same values, the recorder skips commands that Vulkan requires it to emit again. In the existing single-sample depth replay test this leaves zero covered texels during capture. Vulkan command-buffer state

Invalidate the primary recorder’s cached pipeline and dynamic state immediately after vkCmdExecuteCommands. The host regression checks the command log for an initial draw, an identical draw that can safely suppress repeated state, and the same draw after secondary execution, where the recorder must emit the state again.

The failure also arose while qualifying #19557. The existing depth replay fixture exercises it on upstream main independently of that PR.

When this PR opened, the overlap scan left 79 branches to inspect manually. #27979 opened later and includes the same primary-state invalidation among five pooled-recording fixes. Its test registrations at f1281ce9f466 cover other cases. This PR now registers the single-sample depth capture and replay with pooled recording enabled. Merge order with #27979 is still open. #24327 changes the adjacent depth-bias method.

Tested

December 4, Linux Release on NVIDIA RTX 3070 Ti (620.73.04). Added agc_driver_frame_replay_single_sample_depth_parallel_atlas in response to the Vulkan execution review. It runs the existing capture and replay fixture in its own directory with pooled recording enabled. A debugger trace on the isolated fix confirmed that the fixture draws on the primary, executes a secondary recorded on a worker, and draws again on the same primary. The fixture checks captured depth coverage and replayed output.

I ran the four focused CTests with pooled recording disabled in the outer environment, so the new registration had to enable it. On main c1e5709defeb with only the test registration added, three controls passed and the new case failed with zero covered texels and eight distinct Vulkan draw validation errors. On this PR at 163fed3808db, all four passed with zero skips and zero validation errors. The Vulkan loader confirmed that the Khronos validation layer was active.

Plyxen independently tested the previous head in a combined Windows 11 build. All 60 graphics tests passed on an RTX 5080 and a Radeon iGPU. Removing this PR’s source change from that build made two tests fail. The new registration has been run locally on Linux. Windows review

Original Linux qualification. Compared upstream 13bf980d9659 and this commit 478dec33c359 in Release on the same NVIDIA GeForce RTX 3070 Ti, driver 620.73.04, CachyOS Linux 7.3.5-2, GCC 16.2.1. These are host and synthetic renderer fixtures. Native Windows and retail titles were not tested.

Focused CTest executions Upstream main This PR
17 host controls 17 passed 17 passed
22 Vulkan cases, parallel pool off 22 passed 22 passed
Same 22 Vulkan cases, parallel pool on 21 passed, 1 failed 22 passed

On main, agc_driver_frame_replay_single_sample_depth reported zero covered texels and eight distinct VUID-vkCmdDraw errors with the pool on. The fixed build passed its depth coverage and replay assertions in both modes. Three depth-sampling controls each used eight pooled secondary buffers when enabled and zero when disabled.

Ran verbose CTest with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer. Both logs confirmed 54 layer insertions, using validation 1.4.363 with headers 1.4.335. The fixed build had zero skips and zero Vulkan validation errors across all 61 executions.

Ran the new agc_command_state assertion against the unchanged recorder first. It observed zero commands after secondary execution where the test expected a pipeline bind and 19 dynamic-state calls. The same assertion passed with the fix.

Checklist

  • Based on current main at rebase. No other open PR implemented the same functions when this PR opened on November 27. #27979 opened November 28 and now overlaps the production fix.
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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 3070 Ti, driver 620.73.04, CachyOS Linux 7.3.5-2 x86-64
  • AI-assisted: yes

Summary by CodeRabbit

  • Bug Fixes
    • Graphics state is refreshed after executing secondary command buffers, so subsequent draws correctly reapply their required state instead of relying on stale tracked state.
  • Tests
    • Added coverage verifying that draws after secondary command-buffer execution emit the expected state changes.
    • Added a frame-replay test configuration for single-sample depth rendering with parallel atlas enabled.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5530836199 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27875). Originally posted by [IvanFogel](https://github.com/IvanFogel) on 2026-11-27T17:43:04Z. --- ### What With `APS5_PARALLEL_ATLAS=1`, a draw can execute a secondary Vulkan command buffer and then return to recording on the primary. The primary recorder still remembers the pipeline and dynamic state from its previous draw. If the next draw requests the same values, the recorder skips commands that Vulkan requires it to emit again. In the existing single-sample depth replay test this leaves zero covered texels during capture. [Vulkan command-buffer state](https://docs.vulkan.org/spec/latest/chapters/cmdbuffers.html#commandbuffers) Invalidate the primary recorder’s cached pipeline and dynamic state immediately after `vkCmdExecuteCommands`. The host regression checks the command log for an initial draw, an identical draw that can safely suppress repeated state, and the same draw after secondary execution, where the recorder must emit the state again. The failure also arose while qualifying #19557. The existing depth replay fixture exercises it on upstream `main` independently of that PR. When this PR opened, the overlap scan left 79 branches to inspect manually. #27979 opened later and includes the same primary-state invalidation among five pooled-recording fixes. Its test registrations at `f1281ce9f466` cover other cases. This PR now registers the single-sample depth capture and replay with pooled recording enabled. Merge order with #27979 is still open. #24327 changes the adjacent depth-bias method. ### Tested **December 4, Linux Release on NVIDIA RTX 3070 Ti (620.73.04).** Added `agc_driver_frame_replay_single_sample_depth_parallel_atlas` in response to the [Vulkan execution review](https://github.com/boykopovar/AnyPS5/pull/27875#pullrequestreview-6177788271). It runs the existing capture and replay fixture in its own directory with pooled recording enabled. A debugger trace on the isolated fix confirmed that the fixture draws on the primary, executes a secondary recorded on a worker, and draws again on the same primary. The fixture checks captured depth coverage and replayed output. I ran the four focused CTests with pooled recording disabled in the outer environment, so the new registration had to enable it. On main `c1e5709defeb` with only the test registration added, three controls passed and the new case failed with zero covered texels and eight distinct Vulkan draw validation errors. On this PR at `163fed3808db`, all four passed with zero skips and zero validation errors. The Vulkan loader confirmed that the Khronos validation layer was active. Plyxen independently tested the previous head in a combined Windows 11 build. All 60 graphics tests passed on an RTX 5080 and a Radeon iGPU. Removing this PR’s source change from that build made two tests fail. The new registration has been run locally on Linux. [Windows review](https://github.com/boykopovar/AnyPS5/pull/27875#pullrequestreview-6168150713) **Original Linux qualification.** Compared upstream `13bf980d9659` and this commit `478dec33c359` in Release on the same NVIDIA GeForce RTX 3070 Ti, driver 620.73.04, CachyOS Linux 7.3.5-2, GCC 16.2.1. These are host and synthetic renderer fixtures. Native Windows and retail titles were not tested. | Focused CTest executions | Upstream main | This PR | | --- | --- | --- | | 17 host controls | 17 passed | 17 passed | | 22 Vulkan cases, parallel pool off | 22 passed | 22 passed | | Same 22 Vulkan cases, parallel pool on | 21 passed, 1 failed | 22 passed | On main, `agc_driver_frame_replay_single_sample_depth` reported zero covered texels and eight distinct `VUID-vkCmdDraw` errors with the pool on. The fixed build passed its depth coverage and replay assertions in both modes. Three depth-sampling controls each used eight pooled secondary buffers when enabled and zero when disabled. Ran verbose CTest with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` and `VK_LOADER_DEBUG=layer`. Both logs confirmed 54 layer insertions, using validation 1.4.363 with headers 1.4.335. The fixed build had zero skips and zero Vulkan validation errors across all 61 executions. Ran the new `agc_command_state` assertion against the unchanged recorder first. It observed zero commands after secondary execution where the test expected a pipeline bind and 19 dynamic-state calls. The same assertion passed with the fix. <!-- 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. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main` at rebase. No other open PR implemented the same functions when this PR opened on November 27. #27979 opened November 28 and now overlaps the production fix. - [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) and the licence notice of code adapted from upstream (see AGENTS.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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: NVIDIA GeForce RTX 3070 Ti, driver 620.73.04, CachyOS Linux 7.3.5-2 x86-64 <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Graphics state is refreshed after executing secondary command buffers, so subsequent draws correctly reapply their required state instead of relying on stale tracked state. * **Tests** * Added coverage verifying that draws after secondary command-buffer execution emit the expected state changes. * Added a frame-replay test configuration for single-sample depth rendering with parallel atlas enabled. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
MarcZX10 commented 2026-11-27 17:46:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T17:46:28Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the targeted source review supports the described state-cache invalidation behavior.

What I ran

Reviewed head 478dec33c3594fc3eb059597d79b696d441a6759 from the prepared diff and reader. No test commands were run.

Results

Check Result Note
Diff and changed code passed Invalidation and regression assertion reviewed
Tests not run Only author-reported results available

Findings

Blocking

None.

Non-blocking

None.

Not verified

Tests and runtime behavior were not independently verified. Read core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp, core/libs/prx/libSceAgcDriver/tests/CommandStateLog.hpp, and the changed region of core/libs/prx/libSceAgcDriver/tests/Graphics.cpp. The full Graphics.cpp was excluded from the prepared review folder, but its changed region was read through the pinned reader. No other changed files were excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6091709474 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27875#pullrequestreview-6091709474). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-27T17:46:28Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the targeted source review supports the described state-cache invalidation behavior. ## What I ran Reviewed head `478dec33c3594fc3eb059597d79b696d441a6759` from the prepared diff and reader. No test commands were run. ## Results | Check | Result | Note | | --- | --- | --- | | Diff and changed code | passed | Invalidation and regression assertion reviewed | | Tests | not run | Only author-reported results available | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Tests and runtime behavior were not independently verified. Read `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp`, `core/libs/prx/libSceAgcDriver/tests/CommandStateLog.hpp`, and the changed region of `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp`. The full `Graphics.cpp` was excluded from the prepared review folder, but its changed region was read through the pinned reader. No other changed files were excluded. ## To get this to a good state Nothing is required.
Plyxen commented 2026-12-03 10:40:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T10:40:30Z.

Review: APPROVED


I read the diff at 478dec33c3. Windows 11, GCC 15.2, merged into main at b97867d3ce6 together with other open PRs (so not an isolated build), with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 and VK_LAYER_KHRONOS_validation on an RTX 5080 (621.24) and a Radeon iGPU (26.11.2).

  • the 60 tests of agc_driver_graphics_tests: pass on both GPUs. The loader log shows the layer inserted and no "was not found" line, and neither run has a VUID- or SYNC-HAZARD line.
  • Control (RTX 5080, the same tree with only this PR's source change taken out): agc_command_state and agc_driver_graphics fail: "the primary draw state after secondary execution" is recorded as empty.

The red rollup is only cancelled runs; no check failed.

Not checked: a title.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6168150713 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27875#pullrequestreview-6168150713). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-12-03T10:40:30Z. **Review:** APPROVED --- I read the diff at `478dec33c3`. Windows 11, GCC 15.2, merged into `main` at `b97867d3ce6` together with other open PRs (so not an isolated build), with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1` and `VK_LAYER_KHRONOS_validation` on an RTX 5080 (621.24) and a Radeon iGPU (26.11.2). - the 60 tests of `agc_driver_graphics_tests`: pass on both GPUs. The loader log shows the layer inserted and no "was not found" line, and neither run has a `VUID-` or `SYNC-HAZARD` line. - Control (RTX 5080, the same tree with only this PR's source change taken out): `agc_command_state` and `agc_driver_graphics` fail: "the primary draw state after secondary execution" is recorded as empty. The red rollup is only cancelled runs; no check failed. Not checked: a title. AI-assisted: yes (Claude Code)
ligmaSec commented 2026-12-03 20:20:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T20:20:50Z.

Review: COMMENTED


The mock fixture verifies that an identical draw re-emits tracked graphics state after a secondary buffer. Could a Vulkan execution case also record a primary draw after secondary work and verify its output under validation? That would cover the production transition alongside the existing state-call assertions. The tracked pipeline bind in CommandState is graphics-only.

Source review at 478dec33c3. Paired Vulkan execution is pending.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6177788271 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27875#pullrequestreview-6177788271). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T20:20:50Z. **Review:** COMMENTED --- The mock fixture verifies that an identical draw re-emits tracked graphics state after a secondary buffer. Could a Vulkan execution case also record a primary draw after secondary work and verify its output under validation? That would cover the production transition alongside the existing state-call assertions. The tracked pipeline bind in `CommandState` is graphics-only. Source review at `478dec33c3`. Paired Vulkan execution is pending. AI-assisted: yes.
MarcZX10 commented 2026-12-04 09:26:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T09:26:33Z.

Review: APPROVED


Reviewed — looks good

The change invalidates cached primary draw state after secondary execution, and the added assertions cover state emission afterward.

What I ran

Reviewed head 163fed3808db626b55954095675aea5c9617fd8e using repo_read.py to inspect the changed code and relevant call site. No tests or builds were run. The reader returned the requested source ranges, but its audit-log append failed because the run directory is read-only.

Reader commands
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp 1590 1643
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp 1640 1720
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp 3425 3475
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/tests/Graphics.cpp 15780 15915
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/tests/CommandStateLog.hpp 1 157
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_frame_replay_tests.cmake 1 100
python3 repo_read.py search 'ExecuteCommands(' core/libs/prx/libSceAgcDriver/Graphics

Results

Check Result Note
Pinned source inspection passed All four changed files reviewed
Tests and builds not run No checks executed

Negative control

Not run by the reviewer. The description reports that the assertion failed against the unchanged recorder; that result was not independently verified.

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

The reported CTest, Vulkan validation, Windows, and hardware runs were not independently reproduced. files.json lists four reviewed files and no excluded files; Graphics.cpp was read through repo_read.py because its full text was not packaged in files/.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6186535329 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27875#pullrequestreview-6186535329). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-12-04T09:26:33Z. **Review:** APPROVED --- # Reviewed — looks good The change invalidates cached primary draw state after secondary execution, and the added assertions cover state emission afterward. ## What I ran Reviewed head `163fed3808db626b55954095675aea5c9617fd8e` using `repo_read.py` to inspect the changed code and relevant call site. No tests or builds were run. The reader returned the requested source ranges, but its audit-log append failed because the run directory is read-only. <details> <summary>Reader commands</summary> ```text python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp 1590 1643 python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp 1640 1720 python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp 3425 3475 python3 repo_read.py cat core/libs/prx/libSceAgcDriver/tests/Graphics.cpp 15780 15915 python3 repo_read.py cat core/libs/prx/libSceAgcDriver/tests/CommandStateLog.hpp 1 157 python3 repo_read.py cat core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_frame_replay_tests.cmake 1 100 python3 repo_read.py search 'ExecuteCommands(' core/libs/prx/libSceAgcDriver/Graphics ``` </details> ## Results | Check | Result | Note | |---|---|---| | Pinned source inspection | passed | All four changed files reviewed | | Tests and builds | not run | No checks executed | ## Negative control Not run by the reviewer. The description reports that the assertion failed against the unchanged recorder; that result was not independently verified. ## Findings ### Blocking None. ### Non-blocking None. ## Sources - The tracker invalidates its cached state after `vkCmdExecuteCommands`; invalidation clears the known-state bits and cached pipeline state. [Recorder.cpp at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/163fed3808db626b55954095675aea5c9617fd8e/core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp#L1621-L1632) · [execution method](https://github.com/boykopovar/AnyPS5/blob/163fed3808db626b55954095675aea5c9617fd8e/core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp#L1688-L1691) - The regression assertion checks initial state emission, suppression of identical state, and emission again after secondary execution. [Graphics.cpp at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/163fed3808db626b55954095675aea5c9617fd8e/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp#L15833-L15845) ## Not verified The reported CTest, Vulkan validation, Windows, and hardware runs were not independently reproduced. `files.json` lists four reviewed files and no excluded files; `Graphics.cpp` was read through `repo_read.py` because its full text was not packaged in `files/`. ## To get this to a good state Nothing is required.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/27875:upstream-pr/27875'
git switch 'upstream-pr/27875'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/27875'
git switch 'upstream-pr/27875'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/27875'
git switch 'upstream-pr/27875'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/27875'
git switch 'main'
git merge --squash 'upstream-pr/27875'
git switch 'main'
git merge --ff-only 'upstream-pr/27875'
git switch 'main'
git merge 'upstream-pr/27875'
git push origin 'main'
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!27875
No description provided.