fix(agc): mark a resolve destination after releasing the source's import gate hold #26338

Merged
JJenkx merged 1 commit from upstream-pr/26338 into main 2026-11-29 01:47:18 +00:00
JJenkx commented 2026-11-23 18:24:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-11-23T18:24:24Z.


What

ResolveMultisampleTarget marked the destination dirty while it still held the source's DccPublication and the targets lock. When a map-time import is announced, the source publication takes the source's import gate stripes shared. The destination's first pending transition (MarkDirty -> markLayersPending) then opens a nested PublishHold on the destination's own address. PublishHold refuses a nested publication that needs a stripe below one its thread already holds, so with the destination in a lower stripe than the source the resolve threw:

AGC graphics: a nested storage image publication needs a map-time import gate stripe below one its thread already holds

Stripes are address >> 21 modulo 256, so whether this fires depends only on where the two surfaces sit and on whether an import is announced at that moment.

The source publication and the targets lock now end in a block before destination.MarkDirty(), so the destination publishes in its own non-nested hold. The rest of the function, including the destruction of averaged and framebuffer under the targets lock, is unchanged. The source hold never covered the destination's stripes, so the destination's transition had no protection from it that it loses here; markLayersPending takes its own hold as it does for every other caller.

agc_driver_msaa_resolve_publication_order (in agc_driver_alpha_to_coverage_tests) allocates a 4-sample DCC source and a resolve destination until the destination has a stripe below the source's highest one and outside the source's stripes. It draws the source, holds a MapImportGate::ImportHold on a free stripe from another thread so publications go striped, and runs one CB resolve under the GPU lock. It requires the resolve to finish while the import is still held and at least two striped publications to be counted, so it cannot pass without going through the striped path.

Why: a Windows run of Snoopy and the Great Mystery Club (PPSA28795, discussion #7382) on main 2ef49858bb aborted at 33 s with the message above ([videoout] presentation failed, then terminate). It happened in 1 of 7 runs; 2 repeats and 4 runs under gdb (catching C++ throws) did not hit it again, so the game's stack was not captured. This is the nested publication on a different address that I found in the driver; I have not shown that Snoopy took this exact path, and the PR does not claim the title is fixed. The game has native multisample targets (see #18288).

Related: #25911 rewrites the body of the same function and keeps MarkDirty inside the publication; whichever lands second needs a small rebase. #26273 changes a different lock order (host imports vs the pending mutex).

Tested

Windows 11 Enterprise 22621, Ryzen 9 5950X, Radeon RX 6700 XT (AMD driver 26.11.2), WinLibs GCC 15.2 UCRT r7, Release, Ninja. Built on ec96e53dfbf; the branch was then rebased onto bcc7c4de8c4, which changes nothing under core/libs/prx/libSceAgcDriver.

  • This PR: every test of agc_driver_alpha_to_coverage_tests, agc_driver_graphics_tests and agc_driver_msaa_layout_tests matched by agc_driver_msaa_|alpha_to_coverage (26 tests), 3 runs: 26/26 each run. The 3 agc_driver_msaa_dcc_compared_import_* tests skip on Windows by design (#ifndef _WIN32). The new test printed in every run: multisample resolve: source stripes 1-2, destination from stripe 0, import on stripe 3, 3 striped publications.
  • Control: the same tree with MultisampleTarget.cpp restored to main (I checked that the staged tests/libSceAgcDriver.prx was rebuilt and matches the unpatched control driver), 3 runs: agc_driver_msaa_resolve_publication_order fails every run with the message above; agc_driver_msaa_dcc_publish_gate passes.
  • tools/check_conventions.py --base origin/main: passed.
  • Linux, in my run: RX 6650 XT, RADV Mesa 26.3.1, Khronos layer 1.4.363, 3 runs. The 25 tests that build ran passed, with 0 VUID- and 0 SYNC-HAZARD. agc_driver_msaa_enable_single_sample was left out by that build's execution-test selection.
  • NVIDIA Pascal, in a reviewer's run: Quadro P3200, driver 582.42, Windows 11 26300, head applied on main c55872d43f. 25 of 25 on main and 26 of 26 with this head, 2 runs each, with the validation layer requested. That comment states neither the layer revision nor skip counts. The new test prints "source stripes 1-2, destination from stripe 0, import on stripe 3, 3 striped publications".
  • AMD Windows, in a reviewer's run: AMD Radeon iGPU (gfx1036), Windows 11 Pro 26200, Khronos layer 1.4.363. ^agc_driver_msaa_(resolve_publication_order|dcc_unwatch|dcc_publish_gate)$ passes 9 of 9 (3 runs). With MultisampleTarget.cpp restored to main, agc_driver_msaa_resolve_publication_order fails all 3 runs. 0 VUID-.
  • Not tested: macOS, and a longer Snoopy series with the change.

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 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 confirmed; motivated by the PPSA28795 abort in #7382
  • GPUs tested: AMD Radeon RX 6700 XT, AMD driver 26.11.2, Windows 11 22621; NVIDIA GeForce RTX 4070, driver 610.88, Windows 11 26300, in a reviewer's run
  • AI-assisted: yes

Summary by CodeRabbit

  • Bug Fixes
    • Improved multisample resolve behavior when memory publication is in progress. Resolve operations can now complete without waiting on unrelated import activity, while destination updates are published afterward. This helps keep resolve completion and memory updates in the expected order.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5458837206 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26338). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-11-23T18:24:24Z. --- ### What `ResolveMultisampleTarget` marked the destination dirty while it still held the source's `DccPublication` and the targets lock. When a map-time import is announced, the source publication takes the source's import gate stripes shared. The destination's first pending transition (`MarkDirty` -> `markLayersPending`) then opens a nested `PublishHold` on the destination's own address. `PublishHold` refuses a nested publication that needs a stripe below one its thread already holds, so with the destination in a lower stripe than the source the resolve threw: ``` AGC graphics: a nested storage image publication needs a map-time import gate stripe below one its thread already holds ``` Stripes are `address >> 21` modulo 256, so whether this fires depends only on where the two surfaces sit and on whether an import is announced at that moment. The source publication and the targets lock now end in a block before `destination.MarkDirty()`, so the destination publishes in its own non-nested hold. The rest of the function, including the destruction of `averaged` and `framebuffer` under the targets lock, is unchanged. The source hold never covered the destination's stripes, so the destination's transition had no protection from it that it loses here; `markLayersPending` takes its own hold as it does for every other caller. `agc_driver_msaa_resolve_publication_order` (in `agc_driver_alpha_to_coverage_tests`) allocates a 4-sample DCC source and a resolve destination until the destination has a stripe below the source's highest one and outside the source's stripes. It draws the source, holds a `MapImportGate::ImportHold` on a free stripe from another thread so publications go striped, and runs one CB resolve under the GPU lock. It requires the resolve to finish while the import is still held and at least two striped publications to be counted, so it cannot pass without going through the striped path. **Why:** a Windows run of Snoopy and the Great Mystery Club (PPSA28795, discussion #7382) on `main` `2ef49858bb` aborted at 33 s with the message above (`[videoout] presentation failed`, then `terminate`). It happened in 1 of 7 runs; 2 repeats and 4 runs under gdb (catching C++ throws) did not hit it again, so **the game's stack was not captured**. This is the nested publication on a different address that I found in the driver; I have not shown that Snoopy took this exact path, and the PR does not claim the title is fixed. The game has native multisample targets (see #18288). Related: #25911 rewrites the body of the same function and keeps `MarkDirty` inside the publication; whichever lands second needs a small rebase. #26273 changes a different lock order (host imports vs the pending mutex). ### Tested Windows 11 Enterprise 22621, Ryzen 9 5950X, Radeon RX 6700 XT (AMD driver 26.11.2), WinLibs GCC 15.2 UCRT r7, Release, Ninja. Built on `ec96e53dfbf`; the branch was then rebased onto `bcc7c4de8c4`, which changes nothing under `core/libs/prx/libSceAgcDriver`. - **This PR:** every test of `agc_driver_alpha_to_coverage_tests`, `agc_driver_graphics_tests` and `agc_driver_msaa_layout_tests` matched by `agc_driver_msaa_|alpha_to_coverage` (26 tests), 3 runs: **26/26 each run**. The 3 `agc_driver_msaa_dcc_compared_import_*` tests skip on Windows by design (`#ifndef _WIN32`). The new test printed in every run: `multisample resolve: source stripes 1-2, destination from stripe 0, import on stripe 3, 3 striped publications`. - **Control:** the same tree with `MultisampleTarget.cpp` restored to `main` (I checked that the staged `tests/libSceAgcDriver.prx` was rebuilt and matches the unpatched control driver), 3 runs: `agc_driver_msaa_resolve_publication_order` **fails every run** with the message above; `agc_driver_msaa_dcc_publish_gate` passes. - `tools/check_conventions.py --base origin/main`: passed. - Linux, in [my run](https://github.com/boykopovar/AnyPS5/pull/26338#issuecomment-7114627198): RX 6650 XT, RADV Mesa 26.3.1, Khronos layer 1.4.363, 3 runs. The 25 tests that build ran passed, with 0 `VUID-` and 0 `SYNC-HAZARD`. `agc_driver_msaa_enable_single_sample` was left out by that build's execution-test selection. - NVIDIA Pascal, in [a reviewer's run](https://github.com/boykopovar/AnyPS5/pull/26338#issuecomment-7120410391): Quadro P3200, driver 582.42, Windows 11 26300, head applied on `main` `c55872d43f`. 25 of 25 on `main` and 26 of 26 with this head, 2 runs each, with the validation layer requested. That comment states neither the layer revision nor skip counts. The new test prints "source stripes 1-2, destination from stripe 0, import on stripe 3, 3 striped publications". - AMD Windows, in [a reviewer's run](https://github.com/boykopovar/AnyPS5/pull/26338#issuecomment-7122734712): AMD Radeon iGPU (gfx1036), Windows 11 Pro 26200, Khronos layer 1.4.363. `^agc_driver_msaa_(resolve_publication_order|dcc_unwatch|dcc_publish_gate)$` passes 9 of 9 (3 runs). With `MultisampleTarget.cpp` restored to `main`, `agc_driver_msaa_resolve_publication_order` fails all 3 runs. 0 `VUID-`. - Not tested: macOS, and a longer Snoopy series with the change. ### 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) 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 - [x] Fixes: none - [x] Unblocks: none confirmed; motivated by the PPSA28795 abort in #7382 - [x] GPUs tested: AMD Radeon RX 6700 XT, AMD driver 26.11.2, Windows 11 22621; NVIDIA GeForce RTX 4070, driver 610.88, Windows 11 26300, in [a reviewer's run](https://github.com/boykopovar/AnyPS5/pull/26338#issuecomment-7111048519) - [x] AI-assisted: yes <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Improved multisample resolve behavior when memory publication is in progress. Resolve operations can now complete without waiting on unrelated import activity, while destination updates are published afterward. This helps keep resolve completion and memory updates in the expected order. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
MarcZX10 commented 2026-11-25 10:08:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T10:08:49Z.

Review: APPROVED


Reviewed — looks good

The reviewed change is sound at head e86e39e2c265ae07f9a676a0c9927303fa0c0de8; the scope change releases source publication and target locks before destination dirtying, and the supplied focused test reports passing on multiple configurations.

What I ran

Read the prepared description, commits, manifest, diff, and the three changed files at the pinned head. No tests or repository commands were run; test results below are author- or reviewer-reported.

Results

Check Result Note
Change review passed All changed files read
Focused tests not run Reported passing by author and reviewers
Automated checks not run Not run in this review

Findings

Blocking

None.

Non-blocking

None.

Not verified

Tests, the Windows/Linux/NVIDIA/AMD runs and their controls, and physical-console behavior were not independently verified. No files were excluded by the manifest; files.json was not available through the reader.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6055557752 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26338#pullrequestreview-6055557752). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T10:08:49Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed change is sound at head `e86e39e2c265ae07f9a676a0c9927303fa0c0de8`; the scope change releases source publication and target locks before destination dirtying, and the supplied focused test reports passing on multiple configurations. ## What I ran Read the prepared description, commits, manifest, diff, and the three changed files at the pinned head. No tests or repository commands were run; test results below are author- or reviewer-reported. ## Results | Check | Result | Note | |---|---|---| | Change review | passed | All changed files read | | Focused tests | not run | Reported passing by author and reviewers | | Automated checks | not run | Not run in this review | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Tests, the Windows/Linux/NVIDIA/AMD runs and their controls, and physical-console behavior were not independently verified. No files were excluded by the manifest; `files.json` was not available through the reader. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-27 17:22:09 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this change; the points below are optional.

What I ran

Reviewed head 2f00c78e66c65463e4a4ee781efe4122c7b554e1. I did not run commands or tests; I inspected the prepared diff and relevant source through repo_read.py.

Results

Check Result Note
Change and targeted source review passed Three changed files and related lock/publication code read
Automated tests not run Hardware-dependent execution tests not run here

Findings

Blocking

None.

Non-blocking

None.

Not verified

The prepared files.json was not available through the reader, so I could not compare the files read with its reviewed list. The full text of all three changed files was also not available in the prepared review folder; I read the relevant changed lines through the pinned-head reader. I did not run the reported Windows or Linux test suites, a negative control, or console/game testing. Author-reported test results were not independently verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6091496500 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26338#pullrequestreview-6091496500). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-27T17:22:09Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this change; the points below are optional. ## What I ran Reviewed head `2f00c78e66c65463e4a4ee781efe4122c7b554e1`. I did not run commands or tests; I inspected the prepared diff and relevant source through `repo_read.py`. ## Results | Check | Result | Note | |---|---|---| | Change and targeted source review | passed | Three changed files and related lock/publication code read | | Automated tests | not run | Hardware-dependent execution tests not run here | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The prepared `files.json` was not available through the reader, so I could not compare the files read with its `reviewed` list. The full text of all three changed files was also not available in the prepared review folder; I read the relevant changed lines through the pinned-head reader. I did not run the reported Windows or Linux test suites, a negative control, or console/game testing. Author-reported test results were not independently verified. ## To get this to a good state Nothing is required.
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!26338
No description provided.