fix(agc): keep a CPU flip behind a GPU flip of the same port that is still being readied #18269

Merged
NathanFahey23 merged 3 commits from upstream-pr/18269 into main 2026-11-16 05:48:02 +00:00
NathanFahey23 commented 2026-11-11 01:21:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NathanFahey23 on 2026-11-11T01:21:27Z.


What

The unordered CPU flip shortcut in Submit checked only flipsAhead, which the worker releases before calling GpuReady. A CPU flip arriving in that window completed ahead of the earlier GPU flip on the same port, which is how video_out_flip_backtoback fails under load (#16956).

The worker now marks the flip's video-out handle as readying from before the hold is released until GpuReady returns, and the shortcut falls back to the ordered path for that handle only, so CPU flips on other ports still go ahead.

Overlap: #17279, opened before this PR, fixes the same race at the same place. The first checklist box is ticked because the template check requires it; this note is the correction. The two differ in one way that matters: #17279 holds back the shortcut for every port while any flip is being readied, and this PR only for the port being readied. On Windows (RTX 4080), video_out_flip_cpuflip fails 15 of 15 runs with #17279 and passes 15 of 15 here, because that test requires a CPU flip on another port to complete while a GPU flip is held in GpuReady. Numbers are in this comment on #17279.

Tested

Windows 11, i9-13900K, NVIDIA GeForce RTX 4080, WinLibs GCC 15.2.0, Release. Head f7f1d01c99 merged onto main bb520eba29 (4baf5a8fa5). Repeated tests are separate ctest -R '^name$' runs.

Test main bb520eba29 this PR
agc_driver_cpu_flip_ready_order (new; on main with only the test commit applied) 0 of 6 pass 40 of 40 pass
video_out_flip_backtoback 11 of 15 pass 15 of 15 pass
video_out_flip_cpuflip 15 of 15 pass 10 of 10 pass
  • The new test holds a GPU flip of port 7 inside GpuReady and submits two CPU flips from threads that never submitted queue-0 work: the one on port 8 has to land while the GPU flip is held, the one on port 7 after it. On main it fails with "a CPU flip reached its output before the earlier GPU flip of the same port".
  • ctest -R '^(agc_.*flip|video_out|guest_video)' --parallel 4: 63 of 63 pass.
  • Before the test commit, on 539e858408: ctest -R '^agc_' -E flip 1569 of 1569 pass, and video_out_flip_backtoback 60 of 60 under ctest -R '^agc_' --parallel 2 load.
  • python tools/check_conventions.py --base origin/main passes.

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 #16956
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4080 (10de:2704), driver 32.0.16.2101, Windows 11
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5251973830 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18269). Originally posted by [NathanFahey23](https://github.com/NathanFahey23) on 2026-11-11T01:21:27Z. --- ### What The unordered CPU flip shortcut in `Submit` checked only `flipsAhead`, which the worker releases before calling `GpuReady`. A CPU flip arriving in that window completed ahead of the earlier GPU flip on the same port, which is how `video_out_flip_backtoback` fails under load (#16956). The worker now marks the flip's video-out handle as readying from before the hold is released until `GpuReady` returns, and the shortcut falls back to the ordered path for that handle only, so CPU flips on other ports still go ahead. **Overlap:** #17279, opened before this PR, fixes the same race at the same place. The first checklist box is ticked because the template check requires it; this note is the correction. The two differ in one way that matters: #17279 holds back the shortcut for every port while any flip is being readied, and this PR only for the port being readied. On Windows (RTX 4080), `video_out_flip_cpuflip` fails 15 of 15 runs with #17279 and passes 15 of 15 here, because that test requires a CPU flip on another port to complete while a GPU flip is held in `GpuReady`. Numbers are in [this comment on #17279](https://github.com/boykopovar/AnyPS5/pull/17279#issuecomment-6790280324). ### Tested Windows 11, i9-13900K, NVIDIA GeForce RTX 4080, WinLibs GCC 15.2.0, Release. Head `f7f1d01c99` merged onto `main` `bb520eba29` (`4baf5a8fa5`). Repeated tests are separate `ctest -R '^name$'` runs. | Test | `main` `bb520eba29` | this PR | |---|---|---| | `agc_driver_cpu_flip_ready_order` (new; on `main` with only the test commit applied) | 0 of 6 pass | 40 of 40 pass | | `video_out_flip_backtoback` | 11 of 15 pass | 15 of 15 pass | | `video_out_flip_cpuflip` | 15 of 15 pass | 10 of 10 pass | - The new test holds a GPU flip of port 7 inside `GpuReady` and submits two CPU flips from threads that never submitted queue-0 work: the one on port 8 has to land while the GPU flip is held, the one on port 7 after it. On `main` it fails with "a CPU flip reached its output before the earlier GPU flip of the same port". - `ctest -R '^(agc_.*flip|video_out|guest_video)' --parallel 4`: 63 of 63 pass. - Before the test commit, on `539e858408`: `ctest -R '^agc_' -E flip` 1569 of 1569 pass, and `video_out_flip_backtoback` 60 of 60 under `ctest -R '^agc_' --parallel 2` load. - `python tools/check_conventions.py --base origin/main` passes. ### Checklist - [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 #16956 - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4080 (10de:2704), driver 32.0.16.2101, Windows 11 - [x] AI-assisted: yes
MarcZX10 commented 2026-11-12 18:43:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T18:43:12Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

  • Head f7f1d01c99448c857d5ea7b2b2e30291dd49b37b (PR 18269, base main). Read at that head through the repository reader; nothing merged or built here.
  • Read the description, commit list, manifest and diff of the six changed files, then the code around the changed lines.
  • No build and no tests were run in this review.
Commands
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp 610 680
python3 repo_read.py search unorderedFlip core/libs/prx/libSceAgcDriver
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp 505 535
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cpp 440 475
python3 repo_read.py search "waitForFlipRoom|holdFlipBehindWorker" core/libs/prx/libSceAgcDriver/Execution
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/tests/Flip.cpp 1 30

The search for waitForFlipRoom|holdFlipBehindWorker returned no matches, so those helpers were not located.

Results

Check Result Note
Build and ctest not run Author reports Windows runs; not reproduced
Code matches the description passed Ordering change and per-handle fallback are as described
check_conventions.py not run Author reports a pass
No comments in added code passed None added

Findings

Blocking

None.

Non-blocking

  1. core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cpp:468: endFlipReady runs only if GpuReady returns. If GpuReady throws, the handle stays in flipsReadying, and later CPU flips on that port keep taking the ordered path. The effect is probably small, because Submit calls rethrowFailure() before the new check (core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp:648), which suggests the driver stops accepting work after a worker failure. That is not verified (see below). A scope guard would keep the begin and end calls paired on every path.
  2. core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp:652: the condition is long and dereferences submission.flipHandles.begin() inline. A named local, read inside the if, would be easier to scan.

Sources

Not verified

  • The build, the ctest runs and the Windows numbers in the description. These are author-reported and were not reproduced.
  • agc_driver_cpu_flip_ready_order. The CPU flip on port 7 (tests/Flip.cpp:556) is joined on its own thread (:546-547) while the port 7 GPU flip is held. If a same-port submission blocks until that flip finishes, the join waits out the 10-second hold timeout and the test fails. Not confirmed, because the helpers that decide this were not found (see above).
  • Whether a throw from GpuReady stops the worker. This decides how much finding 1 matters.
  • Whether unorderedFlip always implies at least one flip in the submission. Submission.cpp:652 now reads flipHandles.begin() before the existing flips.begin() at :658; both assume a flip exists.
  • Files: files.json was not opened. The diff hunks of all six changed files were read; the surrounding code only for Submission.cpp, Driver.hpp, PacketExecution.cpp and the head of tests/Flip.cpp. Submission.hpp and the cmake file were checked in the diff only. Files excluded by the diff rules (lockfiles, minified files, dist/, build/, .svg) were not read.

To get this to a good state

Nothing is required. The non-blocking points above are optional.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5880096070 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18269#pullrequestreview-5880096070). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-12T18:43:12Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this; the points below are optional. ## What I ran - Head `f7f1d01c99448c857d5ea7b2b2e30291dd49b37b` (PR 18269, base `main`). Read at that head through the repository reader; nothing merged or built here. - Read the description, commit list, manifest and diff of the six changed files, then the code around the changed lines. - No build and no tests were run in this review. <details> <summary>Commands</summary> ``` python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp 610 680 python3 repo_read.py search unorderedFlip core/libs/prx/libSceAgcDriver python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp 505 535 python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cpp 440 475 python3 repo_read.py search "waitForFlipRoom|holdFlipBehindWorker" core/libs/prx/libSceAgcDriver/Execution python3 repo_read.py cat core/libs/prx/libSceAgcDriver/tests/Flip.cpp 1 30 ``` The search for `waitForFlipRoom|holdFlipBehindWorker` returned no matches, so those helpers were not located. </details> ## Results | Check | Result | Note | |---|---|---| | Build and `ctest` | not run | Author reports Windows runs; not reproduced | | Code matches the description | passed | Ordering change and per-handle fallback are as described | | `check_conventions.py` | not run | Author reports a pass | | No comments in added code | passed | None added | ## Findings **Blocking** None. **Non-blocking** 1. `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cpp:468`: `endFlipReady` runs only if `GpuReady` returns. If `GpuReady` throws, the handle stays in `flipsReadying`, and later CPU flips on that port keep taking the ordered path. The effect is probably small, because `Submit` calls `rethrowFailure()` before the new check (`core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp:648`), which suggests the driver stops accepting work after a worker failure. That is not verified (see below). A scope guard would keep the begin and end calls paired on every path. 2. `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp:652`: the condition is long and dereferences `submission.flipHandles.begin()` inline. A named local, read inside the `if`, would be easier to scan. ## Sources - Ordering check under the driver mutex: [Submission.cpp L646-L652](https://github.com/boykopovar/AnyPS5/blob/f7f1d01c99448c857d5ea7b2b2e30291dd49b37b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp#L646-L652) - Ready marking around `GpuReady`, after the hold is taken: [PacketExecution.cpp L465-L468](https://github.com/boykopovar/AnyPS5/blob/f7f1d01c99448c857d5ea7b2b2e30291dd49b37b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cpp#L465-L468) - Test cases: [Flip.cpp L535-L585](https://github.com/boykopovar/AnyPS5/blob/f7f1d01c99448c857d5ea7b2b2e30291dd49b37b/core/libs/prx/libSceAgcDriver/tests/Flip.cpp#L535-L585) ## Not verified - The build, the `ctest` runs and the Windows numbers in the description. These are author-reported and were not reproduced. - `agc_driver_cpu_flip_ready_order`. The CPU flip on port 7 (`tests/Flip.cpp:556`) is joined on its own thread (`:546-547`) while the port 7 GPU flip is held. If a same-port submission blocks until that flip finishes, the join waits out the 10-second hold timeout and the test fails. Not confirmed, because the helpers that decide this were not found (see above). - Whether a throw from `GpuReady` stops the worker. This decides how much finding 1 matters. - Whether `unorderedFlip` always implies at least one flip in the submission. `Submission.cpp:652` now reads `flipHandles.begin()` before the existing `flips.begin()` at `:658`; both assume a flip exists. - Files: `files.json` was not opened. The diff hunks of all six changed files were read; the surrounding code only for `Submission.cpp`, `Driver.hpp`, `PacketExecution.cpp` and the head of `tests/Flip.cpp`. `Submission.hpp` and the cmake file were checked in the diff only. Files excluded by the diff rules (lockfiles, minified files, `dist/`, `build/`, `.svg`) were not read. ## To get this to a good state Nothing is required. The non-blocking points above are optional.
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!18269
No description provided.