fix(agc): run an indirect buffer a GPU write already landed in as memory holds it #22401

Merged
milescoviello merged 6 commits from upstream-pr/22401 into main 2026-11-21 11:01:48 +00:00
milescoviello commented 2026-11-17 14:12:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-17T14:12:23Z.


What

A queue-0 submission copies the INDIRECT_BUFFERs it calls when it is submitted. When GPU work writes one of those buffers after the submit, Driver::refreshIndirectSegment re-reads it as execution reaches it (#11346). It re-read only while that GPU write was still pending: in the draw pipeline, the draw finisher or an unreaped recorder batch. If the write had landed and its batch had been reaped by the time the queue reached the buffer, nothing counted as pending, and the submit-time copy ran.

MXGP 26 (PPSA30839) hits this. Its frame command buffer (about 6740 dwords) is written by GPU work after the submission that calls it. When the stale copy runs, a whole frame of command chunks is skipped, with their releases to graphics' timeline label. The next frame waits for one of those values (WAIT_REG_MEM_64 ... function 5) on graphics and on compute queue 0x20, nothing writes it again, and Unreal's 120 s RenderThread watchdog ends the title. Traced on a diagnostic build, the timeline values in queue 0's submission copies jump by about 198 per frame, and in a stalled run the last value graphics executed equalled memory, 0xc0 below the awaited value.

Each indirect segment now records the write tracker generation at its copy, and whether a recorded GPU write overlapped it then (Recorder::SnapshotWriteOverlaps, or the draw pipeline's queued writes). At execution the buffer is re-read when a write is pending, as before, and also:

  • when a driver store landed over it since the copy: GuestMemory::DriverStoredOver, a new query over the tracker's driver pieces only, so guest CPU stores do not count. Like StoredOver, it answers yes when the tracker cannot tell: write watching off, a zero generation, or a range outside the write watch. The buffer is then re-read and compared.
  • when the copy was taken while such a write was recorded.

The generation and the pending-write check are taken before the buffer is copied (3a5461d3fd), so a driver store marked while the copy is made is still newer than the segment's generation. One window remains: a store that changes the buffer between the copy and the check that the copy matches memory leaves the segment untracked, and it runs as copied, as on main. The debt entry records it.

A buffer the CPU rewrites after its submission still runs as it was copied where the write watch covers it (CpuRewriteAfterSubmit). Outside the write watch the driver cannot tell that rewrite from a GPU write, so it runs what memory holds, as the console's CP does when it reaches the buffer.

Tested

11-20, 3a5461d3fd (the five earlier commits rebased unchanged onto main fc973e0189, plus the generation-before-copy commit for MarcZX10's ordering point): Linux, RTX 4070 Ti, the 38 tests matching ^agc_driver_gpu_written_indirect_buffer|^agc_write_tracking|^agc_driver_submit|^agc_driver_pm4|^agc_driver$ pass in each of 3 runs; main passes the same 37 (the _unwatched variant is this PR's). There is no deterministic test for the ordering window itself.
Windows 11 VM, NVIDIA GeForce GT 1030 (582.78), WinLibs GCC 16.2.0, Release, the same test set: 45 of 46 pass in each of 3 runs at 3a5461d3fd. The one failure, agc_driver_pm4_order_signal, fails the same way on main f343ff4a51 on that machine (3 of 3).

Linux (Ubuntu 26.04.1, kernel 7.0), RTX 4070 Ti, NVIDIA 615.71, GCC 15.2, Release, -DBUILD_TESTING=ON, ANYPS5_REQUIRE_VULKAN=1:

  • agc_driver_gpu_written_indirect_buffer gains three cases:
    • LandedWriteBeforeRun, for an INDIRECT_BUFFER and a COND_INDIRECT_BUFFER: a dispatch writes the command buffer, the queue waits on a gate, the test waits until the write has landed (FlushGpuWrites), then opens the gate. The buffer must run what the dispatch wrote.
    • WriteBeforeCopyLandedBeforeRun: the dispatch is recorded in an earlier submission and the queue blocks on its gate before the submission calling the buffer is copied. The write then lands, and the buffer must run what it wrote.
  • 3 of 3 runs pass, agc_driver_gpu_written_indirect_buffer and agc_driver_gpu_written_indirect_buffer_queued_writer.
  • Negative controls, with this PR's tests:
    • main's sources: LandedWriteBeforeRun fails with a COND_INDIRECT_BUFFER whose command buffer a dispatch before it wrote, with the write landed before the queue reached it, ran the buffer as it was at submission: the marker is 0; run alone, WriteBeforeCopyLandedBeforeRun fails the same way.
    • The driver-store check without the copy-time flag: WriteBeforeCopyLandedBeforeRun still fails, so the flag is needed.
  • Review follow-ups (4a0bb54289, 39a62e2510, 7022c3118d):
    • agc_write_tracking gains CheckDriverStoredOver: a driver store over the range since the generation counts, one beside it or older does not, a collected CPU store does not, and a zero generation or a range outside the write watch answers yes.
    • agc_driver_gpu_written_indirect_buffer_unwatched runs the indirect-buffer cases with APS5_NO_WRITE_WATCH=1.
    • Linux: these and the two existing tests pass 3 of 3. With 4a0bb54289's change undone (DriverStoredOver answering no when it cannot tell), the unwatched variant fails (a COND_INDIRECT_BUFFER the CPU rewrote after its submission ran as it was copied outside the write watch) and agc_write_tracking fails (a zero generation reads as not stored over by the driver).
    • Windows 11 (VM, GeForce GT 1030, WinLibs GCC 15.2): on aa67dfcb91, LandedWriteBeforeRun failed 3 of 3 there (the marker is 0), because the test's command buffer is outside the write watch on Windows and the check answered no. With the follow-ups, all four tests pass 3 of 3.
  • The 46 tests matching agc_driver_(gpu_written|indirect|submit|pm4|rewind|cond|control_flow|ring|dcb|rendering_wait|flip) pass, CpuRewriteAfterSubmit included.

MXGP 26 (PPSA30839), hold-Square route (MyNacon welcome, then Cross through the menus), 480 s, 20 GB cap, APS5_NET_DISCONNECTED=1, with #22052 merged (without it MXGP stops at 13-24 s on the rect-list error):

  • Diagnostic builds without this change (main e602d6a587 + #22052 + #22187): 6 of 14 runs stalled at 177-335 s on graphics' timeline label as described above. Two more ended on the RenderThread watchdog with no GPU wait stuck, one on an unrelated null dereference; 5 ran to 480 s, 2 of them with APS5_LABEL_SUBMIT_NOW=1.
  • A diagnostic build that re-reads any indirect buffer whose memory changed since its copy, and logs when no GPU write was pending: 4 of 4 runs reached 480 s. Two of them logged a stale copy of the frame buffer (0x1079760020, 6740 dwords; 0x1079848010, 6721 dwords), each time with a driver store over it since the copy, which this PR's check catches. One run ended in a race (the controls tutorial with its HUD); it is upside down because #20827 is not in that build.
  • A/B of this change: main 01c550960a + #22052 (bb8d5cbf2d) against the same plus this branch (a1e661ebb8, the tree of aa67dfcb91), 4 interleaved runs each:
main + #22052 + this PR
Runs reaching 480 s 0 of 4: all end at 320-331 s on the RenderThread watchdog, 3 with no GPU wait stuck and 1 on graphics' timeline label 4 of 4
Furthest screen the menus before the first race a race (3 runs, the controls tutorial on the track); the fourth run's presses ended in the helmet colour picker
Presents per run, 30-190 s (both arms running) 440 494
Median p50 frame time, 30-190 s 180.6 ms 180.6 ms
Median queue worker 0x0 busy, 30-190 s 97.4 % 97.2 %

Contact sheets (last three dumped frames of each run): release indirect-buffer-ab-01c550960a. The in-race geometry is stretched in places; that is a separate issue for a later PR.

  • Lyrnc's Windows run of 3f87785b70 merged onto main f15df3256c (Windows 11, WinLibs GCC 15.2.0): the 14 agc_driver_gpu_written_indirect_buffer and agc_write_tracking tests pass, 3 runs, on an RTX 5080 (NVIDIA 610.88) and on a Ryzen 7 9800X3D iGPU (AMD 2026.04.17). ^agc_|^shader on the RTX 5080 has only the two failures main also has on that card (#22427, #22931).
  • Colewiz7's RADV run of 3f87785b70 merged onto main 26604382a5 as 071febd8d1 (Linux 7.3.4, GCC 16.2.1, Mesa 26.2.6, RX 7900 XT and the Ryzen 7 7800X3D iGPU, Khronos validation layer 1.4.363.1): no new failures against main and no VUID- or SYNC-HAZARD lines. guest_kernel_sys_paths_readlinkat_limits failed once in a parallel full run on the 7900 XT and passes 3/3 solo on both main and this PR.
  • Title A/B on main 7c836568c (11-19, details): with the same route, main ends at 247 s on Unreal's RenderThread watchdog in a 900 s run, while main + this PR runs the full 903 s and reaches the race.

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: PPSA30839 (MXGP 26 reaches a race; on main 7c836568c it ends on the RenderThread watchdog first, see the 11-19 A/B under Tested)
  • GPUs tested: NVIDIA RTX 4070 Ti (Linux, NVIDIA 615.71), NVIDIA RTX 5080 and the Ryzen 7 9800X3D iGPU (Windows, Lyrnc), AMD RX 7900 XT and the Ryzen 7 7800X3D iGPU (gfx1036) (Linux, RADV, Colewiz7)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5358457906 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22401). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-17T14:12:23Z. --- ### What A queue-0 submission copies the INDIRECT_BUFFERs it calls when it is submitted. When GPU work writes one of those buffers after the submit, `Driver::refreshIndirectSegment` re-reads it as execution reaches it (#11346). It re-read only while that GPU write was still pending: in the draw pipeline, the draw finisher or an unreaped recorder batch. If the write had landed and its batch had been reaped by the time the queue reached the buffer, nothing counted as pending, and the submit-time copy ran. MXGP 26 (PPSA30839) hits this. Its frame command buffer (about 6740 dwords) is written by GPU work after the submission that calls it. When the stale copy runs, a whole frame of command chunks is skipped, with their releases to graphics' timeline label. The next frame waits for one of those values (`WAIT_REG_MEM_64 ... function 5`) on graphics and on compute queue 0x20, nothing writes it again, and Unreal's 120 s RenderThread watchdog ends the title. Traced on a diagnostic build, the timeline values in queue 0's submission copies jump by about 198 per frame, and in a stalled run the last value graphics executed equalled memory, 0xc0 below the awaited value. Each indirect segment now records the write tracker generation at its copy, and whether a recorded GPU write overlapped it then (`Recorder::SnapshotWriteOverlaps`, or the draw pipeline's queued writes). At execution the buffer is re-read when a write is pending, as before, and also: - when a driver store landed over it since the copy: `GuestMemory::DriverStoredOver`, a new query over the tracker's driver pieces only, so guest CPU stores do not count. Like `StoredOver`, it answers yes when the tracker cannot tell: write watching off, a zero generation, or a range outside the write watch. The buffer is then re-read and compared. - when the copy was taken while such a write was recorded. The generation and the pending-write check are taken before the buffer is copied (`3a5461d3fd`), so a driver store marked while the copy is made is still newer than the segment's generation. One window remains: a store that changes the buffer between the copy and the check that the copy matches memory leaves the segment untracked, and it runs as copied, as on `main`. The debt entry records it. A buffer the CPU rewrites after its submission still runs as it was copied where the write watch covers it (`CpuRewriteAfterSubmit`). Outside the write watch the driver cannot tell that rewrite from a GPU write, so it runs what memory holds, as the console's CP does when it reaches the buffer. ### Tested **11-20, `3a5461d3fd`** (the five earlier commits rebased unchanged onto `main` `fc973e0189`, plus the generation-before-copy commit for MarcZX10's ordering point): Linux, RTX 4070 Ti, the 38 tests matching `^agc_driver_gpu_written_indirect_buffer|^agc_write_tracking|^agc_driver_submit|^agc_driver_pm4|^agc_driver$` pass in each of 3 runs; `main` passes the same 37 (the `_unwatched` variant is this PR's). There is no deterministic test for the ordering window itself. Windows 11 VM, NVIDIA GeForce GT 1030 (582.78), WinLibs GCC 16.2.0, Release, the same test set: 45 of 46 pass in each of 3 runs at `3a5461d3fd`. The one failure, `agc_driver_pm4_order_signal`, fails the same way on `main` `f343ff4a51` on that machine (3 of 3). Linux (Ubuntu 26.04.1, kernel 7.0), RTX 4070 Ti, NVIDIA 615.71, GCC 15.2, Release, `-DBUILD_TESTING=ON`, `ANYPS5_REQUIRE_VULKAN=1`: - `agc_driver_gpu_written_indirect_buffer` gains three cases: - `LandedWriteBeforeRun`, for an INDIRECT_BUFFER and a COND_INDIRECT_BUFFER: a dispatch writes the command buffer, the queue waits on a gate, the test waits until the write has landed (`FlushGpuWrites`), then opens the gate. The buffer must run what the dispatch wrote. - `WriteBeforeCopyLandedBeforeRun`: the dispatch is recorded in an earlier submission and the queue blocks on its gate before the submission calling the buffer is copied. The write then lands, and the buffer must run what it wrote. - 3 of 3 runs pass, `agc_driver_gpu_written_indirect_buffer` and `agc_driver_gpu_written_indirect_buffer_queued_writer`. - Negative controls, with this PR's tests: - `main`'s sources: `LandedWriteBeforeRun` fails with `a COND_INDIRECT_BUFFER whose command buffer a dispatch before it wrote, with the write landed before the queue reached it, ran the buffer as it was at submission: the marker is 0`; run alone, `WriteBeforeCopyLandedBeforeRun` fails the same way. - The driver-store check without the copy-time flag: `WriteBeforeCopyLandedBeforeRun` still fails, so the flag is needed. - Review follow-ups (4a0bb54289, 39a62e2510, 7022c3118d): - `agc_write_tracking` gains `CheckDriverStoredOver`: a driver store over the range since the generation counts, one beside it or older does not, a collected CPU store does not, and a zero generation or a range outside the write watch answers yes. - `agc_driver_gpu_written_indirect_buffer_unwatched` runs the indirect-buffer cases with `APS5_NO_WRITE_WATCH=1`. - Linux: these and the two existing tests pass 3 of 3. With 4a0bb54289's change undone (`DriverStoredOver` answering no when it cannot tell), the unwatched variant fails (`a COND_INDIRECT_BUFFER the CPU rewrote after its submission ran as it was copied outside the write watch`) and `agc_write_tracking` fails (`a zero generation reads as not stored over by the driver`). - Windows 11 (VM, GeForce GT 1030, WinLibs GCC 15.2): on aa67dfcb91, `LandedWriteBeforeRun` failed 3 of 3 there (`the marker is 0`), because the test's command buffer is outside the write watch on Windows and the check answered no. With the follow-ups, all four tests pass 3 of 3. - The 46 tests matching `agc_driver_(gpu_written|indirect|submit|pm4|rewind|cond|control_flow|ring|dcb|rendering_wait|flip)` pass, `CpuRewriteAfterSubmit` included. MXGP 26 (PPSA30839), hold-Square route (MyNacon welcome, then Cross through the menus), 480 s, 20 GB cap, `APS5_NET_DISCONNECTED=1`, with #22052 merged (without it MXGP stops at 13-24 s on the rect-list error): - Diagnostic builds without this change (`main` e602d6a587 + #22052 + #22187): 6 of 14 runs stalled at 177-335 s on graphics' timeline label as described above. Two more ended on the RenderThread watchdog with no GPU wait stuck, one on an unrelated null dereference; 5 ran to 480 s, 2 of them with `APS5_LABEL_SUBMIT_NOW=1`. - A diagnostic build that re-reads any indirect buffer whose memory changed since its copy, and logs when no GPU write was pending: 4 of 4 runs reached 480 s. Two of them logged a stale copy of the frame buffer (`0x1079760020`, 6740 dwords; `0x1079848010`, 6721 dwords), each time with a driver store over it since the copy, which this PR's check catches. One run ended in a race (the controls tutorial with its HUD); it is upside down because #20827 is not in that build. - A/B of this change: `main` 01c550960a + #22052 (bb8d5cbf2d) against the same plus this branch (a1e661ebb8, the tree of aa67dfcb91), 4 interleaved runs each: | | `main` + #22052 | + this PR | |---|---|---| | Runs reaching 480 s | 0 of 4: all end at 320-331 s on the RenderThread watchdog, 3 with no GPU wait stuck and 1 on graphics' timeline label | 4 of 4 | | Furthest screen | the menus before the first race | a race (3 runs, the controls tutorial on the track); the fourth run's presses ended in the helmet colour picker | | Presents per run, 30-190 s (both arms running) | 440 | 494 | | Median p50 frame time, 30-190 s | 180.6 ms | 180.6 ms | | Median queue worker 0x0 busy, 30-190 s | 97.4 % | 97.2 % | Contact sheets (last three dumped frames of each run): release [indirect-buffer-ab-01c550960a](https://github.com/milescoviello/AnyPS5/releases/tag/indirect-buffer-ab-01c550960a). The in-race geometry is stretched in places; that is a separate issue for a later PR. - Lyrnc's [Windows run](https://github.com/boykopovar/AnyPS5/pull/22401#issuecomment-6989233822) of `3f87785b70` merged onto `main` `f15df3256c` (Windows 11, WinLibs GCC 15.2.0): the 14 `agc_driver_gpu_written_indirect_buffer` and `agc_write_tracking` tests pass, 3 runs, on an RTX 5080 (NVIDIA 610.88) and on a Ryzen 7 9800X3D iGPU (AMD 2026.04.17). `^agc_|^shader` on the RTX 5080 has only the two failures `main` also has on that card (#22427, #22931). - Colewiz7's [RADV run](https://github.com/boykopovar/AnyPS5/pull/22401#issuecomment-7001756243) of `3f87785b70` merged onto `main` `26604382a5` as `071febd8d1` (Linux 7.3.4, GCC 16.2.1, Mesa 26.2.6, RX 7900 XT and the Ryzen 7 7800X3D iGPU, Khronos validation layer 1.4.363.1): no new failures against `main` and no `VUID-` or `SYNC-HAZARD` lines. `guest_kernel_sys_paths_readlinkat_limits` failed once in a parallel full run on the 7900 XT and passes 3/3 solo on both `main` and this PR. - Title A/B on `main` 7c836568c (11-19, [details](https://github.com/boykopovar/AnyPS5/pull/22401#issuecomment-7008623319)): with the same route, `main` ends at 247 s on Unreal's RenderThread watchdog in a 900 s run, while `main` + this PR runs the full 903 s and reaches the race. ### 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) 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: PPSA30839 (MXGP 26 reaches a race; on `main` 7c836568c it ends on the RenderThread watchdog first, see the 11-19 A/B under Tested) - [x] GPUs tested: NVIDIA RTX 4070 Ti (Linux, NVIDIA 615.71), NVIDIA RTX 5080 and the Ryzen 7 9800X3D iGPU (Windows, Lyrnc), AMD RX 7900 XT and the Ryzen 7 7800X3D iGPU (gfx1036) (Linux, RADV, Colewiz7) - [x] AI-assisted: yes
MarcZX10 commented 2026-11-17 14:26:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T14:26:37Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: DriverStoredOver fails open when the tracker is unwatched, the generation is 0 or the range is not covered, so the re-read is skipped in exactly the cases the sibling check treats as stored over.

What I ran

  • Head aa67dfcb91e64f3b59bd1ec4ed4954077ef83607, base main.
  • Read description.md, commits.md, manifest.json and diff.patch from the review folder.
  • Read the house rules sections "Readable reviews", "Standard PR response format" and "Accuracy and evidence".
  • Repository reader, no build and no tests:
    • search for noteIndirectSegment, SnapshotWriteOverlaps, TrackerGeneration, driverPieces, bool covers(, Queue0(), bool Busy(.
    • cat of Submission.cpp lines 225-345, GuestMemory.cpp lines 1526-1534, 1790-1826, 2936-3006.

Results

Check Result Note
Helpers used by the diff exist passed Found at head
Fail-safe default of DriverStoredOver failed Returns false where StoredOver returns true
Build and unit tests not run Author-reported only
Hosted CI not run Not checked

Findings

Blocking

  • core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp:2963: DriverStoredOver returns false when !tracker.watched, generation == 0 or !tracker.covers(...). In those cases the answer is unknown, but refreshIndirectSegment then skips the re-read (core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp:314), and the stale submit-time copy runs. That is the bug this PR fixes. The sibling StoredOver returns true in the same guard (GuestMemory.cpp:2952). A re-read that finds nothing changed costs one compare, so failing closed is cheap.

Non-blocking

  • core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp:314: copiedAt and copiedUnderWrite are read from a local copy of the segment, so a segment copied under a write re-reads and compares its whole buffer on every execution, even when nothing changed. For a frame buffer of about 6740 dwords run every frame, that is a steady cost. This is not a correctness issue. Whether the stored entry is updated after a refresh is not verified (lines past 345 were not read).
  • core/libs/prx/libSceAgcDriver/tests/execution/GpuWrittenIndirectBuffer.cpp:454: the new cases cover a write that landed before the run and a copy taken while a write was recorded. None overwrites a copied buffer with a driver store after the copy, so the DriverStoredOver branch is not exercised by them (from reading the test code).

Sources

Not verified

  • The build, the three test runs, the 46-test regression run and the negative controls in the description: author-reported, not run here.
  • The MXGP A/B: the description says it is still running and gives no results.
  • Hosted CI for this head: not checked.
  • Whether a copy-time generation can be 0 (GuestMemory.cpp:2994; tracker initialisation in Lifecycle.cpp not read).
  • Whether an indirect buffer can lie outside the watched range (GuestMemory.cpp:1528), which decides whether the blocking point is reachable.
  • Lock ordering: noteIndirectSegment runs during the submit-time copy, and DriverStoredOver takes the tracker lock. Not checked.
  • Recorder::SnapshotWriteOverlaps (Recorder.cpp:2030) not read.
  • Test helpers FlushGpuWrites, AgcDriverAwaitedWaits_nid_postfix and AwaitedWait not checked.
  • Files read: Submission.cpp and GuestMemory.cpp at the ranges above. Submission.hpp, GuestMemory.hpp and GpuWrittenIndirectBuffer.cpp were read as diff hunks only. files.json was not read, so the excluded files are not listed.

To get this to a good state

  • In DriverStoredOver, return true when the tracker is unwatched, the generation is 0 or the range is not covered, as StoredOver does.
  • Optional: add a case where a driver store overwrites a copied buffer after its copy, so the new branch runs.
  • Rerun agc_driver_gpu_written_indirect_buffer and agc_driver_gpu_written_indirect_buffer_queued_writer on the new head, and post the MXGP A/B results.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5940236865 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22401#pullrequestreview-5940236865). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-17T14:26:37Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: `DriverStoredOver` fails open when the tracker is unwatched, the generation is 0 or the range is not covered, so the re-read is skipped in exactly the cases the sibling check treats as stored over. ## What I ran - Head `aa67dfcb91e64f3b59bd1ec4ed4954077ef83607`, base `main`. - Read `description.md`, `commits.md`, `manifest.json` and `diff.patch` from the review folder. - Read the house rules sections "Readable reviews", "Standard PR response format" and "Accuracy and evidence". - Repository reader, no build and no tests: - `search` for `noteIndirectSegment`, `SnapshotWriteOverlaps`, `TrackerGeneration`, `driverPieces`, `bool covers(`, `Queue0()`, `bool Busy(`. - `cat` of `Submission.cpp` lines 225-345, `GuestMemory.cpp` lines 1526-1534, 1790-1826, 2936-3006. ## Results | Check | Result | Note | |---|---|---| | Helpers used by the diff exist | passed | Found at head | | Fail-safe default of `DriverStoredOver` | failed | Returns `false` where `StoredOver` returns `true` | | Build and unit tests | not run | Author-reported only | | Hosted CI | not run | Not checked | ## Findings **Blocking** - `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp:2963`: `DriverStoredOver` returns `false` when `!tracker.watched`, `generation == 0` or `!tracker.covers(...)`. In those cases the answer is unknown, but `refreshIndirectSegment` then skips the re-read (`core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp:314`), and the stale submit-time copy runs. That is the bug this PR fixes. The sibling `StoredOver` returns `true` in the same guard (`GuestMemory.cpp:2952`). A re-read that finds nothing changed costs one compare, so failing closed is cheap. **Non-blocking** - `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp:314`: `copiedAt` and `copiedUnderWrite` are read from a local copy of the segment, so a segment copied under a write re-reads and compares its whole buffer on every execution, even when nothing changed. For a frame buffer of about 6740 dwords run every frame, that is a steady cost. This is not a correctness issue. Whether the stored entry is updated after a refresh is not verified (lines past 345 were not read). - `core/libs/prx/libSceAgcDriver/tests/execution/GpuWrittenIndirectBuffer.cpp:454`: the new cases cover a write that landed before the run and a copy taken while a write was recorded. None overwrites a copied buffer with a driver store after the copy, so the `DriverStoredOver` branch is not exercised by them (from reading the test code). ## Sources - [GuestMemory.cpp:2952-2963](https://github.com/boykopovar/AnyPS5/blob/aa67dfcb91e64f3b59bd1ec4ed4954077ef83607/core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp#L2952-L2963) - [Submission.cpp:303-314](https://github.com/boykopovar/AnyPS5/blob/aa67dfcb91e64f3b59bd1ec4ed4954077ef83607/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp#L303-L314) - [GuestMemory.cpp:1528-1534](https://github.com/boykopovar/AnyPS5/blob/aa67dfcb91e64f3b59bd1ec4ed4954077ef83607/core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp#L1528-L1534) ## Not verified - The build, the three test runs, the 46-test regression run and the negative controls in the description: author-reported, not run here. - The MXGP A/B: the description says it is still running and gives no results. - Hosted CI for this head: not checked. - Whether a copy-time generation can be 0 (`GuestMemory.cpp:2994`; tracker initialisation in `Lifecycle.cpp` not read). - Whether an indirect buffer can lie outside the watched range (`GuestMemory.cpp:1528`), which decides whether the blocking point is reachable. - Lock ordering: `noteIndirectSegment` runs during the submit-time copy, and `DriverStoredOver` takes the tracker lock. Not checked. - `Recorder::SnapshotWriteOverlaps` (`Recorder.cpp:2030`) not read. - Test helpers `FlushGpuWrites`, `AgcDriverAwaitedWaits_nid_postfix` and `AwaitedWait` not checked. - Files read: `Submission.cpp` and `GuestMemory.cpp` at the ranges above. `Submission.hpp`, `GuestMemory.hpp` and `GpuWrittenIndirectBuffer.cpp` were read as diff hunks only. `files.json` was not read, so the excluded files are not listed. ## To get this to a good state - In `DriverStoredOver`, return `true` when the tracker is unwatched, the generation is 0 or the range is not covered, as `StoredOver` does. - Optional: add a case where a driver store overwrites a copied buffer after its copy, so the new branch runs. - Rerun `agc_driver_gpu_written_indirect_buffer` and `agc_driver_gpu_written_indirect_buffer_queued_writer` on the new head, and post the MXGP A/B results.
MarcZX10 commented 2026-11-17 16:20:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T16:20:04Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

  • Head: 7022c3118d66d1bb7f3dbb36f3cbb582d94af68c, base main.
  • Read the diff in diff.patch for all seven files in files.json under reviewed.
  • Read the head of the surrounding code with repo_read.py: refreshIndirectSegment, DriverStoredOver and StoredOver, IndirectSegment, and the callers of the helpers the diff uses.
  • No build and no tests were run (this review does not build).

Results

Check Result Note
Diff of changed files passed 7 of 7 files read
Helper definitions at head passed SnapshotWriteOverlaps, Overlaps, TrackerGeneration found
Build and unit tests not run No-build review

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp:314: every indirect segment with no pending write now calls GuestMemory::DriverStoredOver, which takes the tracker lock. With write watching off it answers yes, so each run re-reads the whole buffer (up to about 6740 dwords in the reported case) and compares it. The result is correct, but the cost is paid on every submission of such a buffer. Consider a comment or a counter so the cost stays visible.

Not verified

  • The test results in the description (Linux 3 of 3, Windows 11 3 of 3) and the A/B table are the author's reports. I did not run them.
  • The order of noteIndirectSegment (Submission.cpp:37-38) against the copy's read of the words. If a driver store lands between that read and TrackerGeneration(), its generation is not newer than copiedAt and the store would be missed. I did not read the copy routine to settle this.
  • The semantics of Recorder::SnapshotWriteOverlaps and DrawPipeline::Queue0().Busy() were not read beyond their signatures.
  • The full texts under files/ were not opened; the review uses diff.patch and targeted head reads.
  • The game-level claims (MXGP 26 reaching a race, the watchdog stall) are outside what this review can check.

To get this to a good state

Nothing is required.

Optional: state the cost of the unwatched path in the description or a comment, and confirm the copy-time generation ordering in the copy routine.

Sources

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5942233266 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22401#pullrequestreview-5942233266). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-17T16:20:04Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this; the points below are optional. ## What I ran - Head: `7022c3118d66d1bb7f3dbb36f3cbb582d94af68c`, base `main`. - Read the diff in `diff.patch` for all seven files in `files.json` under `reviewed`. - Read the head of the surrounding code with `repo_read.py`: `refreshIndirectSegment`, `DriverStoredOver` and `StoredOver`, `IndirectSegment`, and the callers of the helpers the diff uses. - No build and no tests were run (this review does not build). ## Results | Check | Result | Note | |---|---|---| | Diff of changed files | passed | 7 of 7 files read | | Helper definitions at head | passed | `SnapshotWriteOverlaps`, `Overlaps`, `TrackerGeneration` found | | Build and unit tests | not run | No-build review | ## Findings ### Blocking None. ### Non-blocking - `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp:314`: every indirect segment with no pending write now calls `GuestMemory::DriverStoredOver`, which takes the tracker lock. With write watching off it answers yes, so each run re-reads the whole buffer (up to about 6740 dwords in the reported case) and compares it. The result is correct, but the cost is paid on every submission of such a buffer. Consider a comment or a counter so the cost stays visible. ## Not verified - The test results in the description (Linux 3 of 3, Windows 11 3 of 3) and the A/B table are the author's reports. I did not run them. - The order of `noteIndirectSegment` (`Submission.cpp:37-38`) against the copy's read of the words. If a driver store lands between that read and `TrackerGeneration()`, its generation is not newer than `copiedAt` and the store would be missed. I did not read the copy routine to settle this. - The semantics of `Recorder::SnapshotWriteOverlaps` and `DrawPipeline::Queue0().Busy()` were not read beyond their signatures. - The full texts under `files/` were not opened; the review uses `diff.patch` and targeted head reads. - The game-level claims (MXGP 26 reaching a race, the watchdog stall) are outside what this review can check. ## To get this to a good state Nothing is required. Optional: state the cost of the unwatched path in the description or a comment, and confirm the copy-time generation ordering in the copy routine. ## Sources - Head: https://github.com/boykopovar/AnyPS5/blob/7022c3118d66d1bb7f3dbb36f3cbb582d94af68c/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp#L303-L320
MarcZX10 commented 2026-11-17 18:21:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T18:21:16Z.

Review: COMMENTED


fix(agc): run an indirect buffer a GPU write already landed in as memory holds it — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

  • Read the change description, the commit list, manifest.json, files.json and diff.patch in the run folder.
  • Read the head source with the reader: refreshIndirectSegment (core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp:295-340), StoredOver and the new DriverStoredOver (core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp:2940-2970), and the helpers the diff calls (TrackerGeneration, Recorder::SnapshotWriteOverlaps).
  • Did not build or run the tests. The results below are the author's, not mine.

Results

Check Result Note
Helpers used by the diff exist at head Pass TrackerGeneration, Recorder::SnapshotWriteOverlaps and DriverStoredOver found at head
Build and test suite Not run Author reports 3 of 3 passes on Linux and Windows; not reproduced here
Logic of the re-read condition Pass by reading Re-read path is gated by the new copiedUnderWrite and DriverStoredOver checks

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp:314: with write watching off, or for a range outside the write watch, DriverStoredOver answers yes. Every execution of such an indirect buffer then reads it and compares it with its copy. This is the cost the debt note records; it is a performance trade-off, not a defect.
  • core/libs/prx/libSceAgcDriver/tests/execution/GpuWrittenIndirectBuffer.cpp:242-251: for a CPU rewrite outside the write watch, a buffer now runs what memory holds, where it used to run as copied. The new test and the debt note both state this. Worth a second look by whoever owns the console's CP behaviour, since it changes an existing expectation.

Not verified

  • The test bodies beyond the changed hunks: AgcDriverAwaitedWaits_nid_postfix, Pm4, Dispatching and the WriteBeforeCopyLandedBeforeRun gate logic.
  • tracker.covers, driverPieces, possiblePieces and entry.whole / entry.dropped / entry.possibleWhole / entry.possibleDropped in driverStoredOver: I read the hunk, not their definitions.
  • DrawPipeline::Queue0().Overlaps and Busy, and DrawFinisher::PendingOverlaps: used in the new lines of Submission.cpp:37 and :307-314, not read.
  • That agc_driver_gpu_written_indirect_buffer_tests.cmake is included by the test build. The new file is added, but I did not check the CMakeLists that loads it.
  • The A/B performance table and the Windows results: taken from the description.

Files

  • Read through diff.patch hunks and reader spot-checks: all 8 files in files.json reviewed.
  • Read in full: none. Excluded by rule: none.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5944190530 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22401#pullrequestreview-5944190530). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-17T18:21:16Z. **Review:** COMMENTED --- # fix(agc): run an indirect buffer a GPU write already landed in as memory holds it — no blocking findings Nothing blocks this; the points below are optional. ## What I ran - Read the change description, the commit list, `manifest.json`, `files.json` and `diff.patch` in the run folder. - Read the head source with the reader: `refreshIndirectSegment` (`core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp:295-340`), `StoredOver` and the new `DriverStoredOver` (`core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp:2940-2970`), and the helpers the diff calls (`TrackerGeneration`, `Recorder::SnapshotWriteOverlaps`). - Did not build or run the tests. The results below are the author's, not mine. ## Results | Check | Result | Note | |---|---|---| | Helpers used by the diff exist at head | Pass | `TrackerGeneration`, `Recorder::SnapshotWriteOverlaps` and `DriverStoredOver` found at head | | Build and test suite | Not run | Author reports 3 of 3 passes on Linux and Windows; not reproduced here | | Logic of the re-read condition | Pass by reading | Re-read path is gated by the new `copiedUnderWrite` and `DriverStoredOver` checks | ## Findings ### Blocking None. ### Non-blocking - `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp:314`: with write watching off, or for a range outside the write watch, `DriverStoredOver` answers yes. Every execution of such an indirect buffer then reads it and compares it with its copy. This is the cost the debt note records; it is a performance trade-off, not a defect. - `core/libs/prx/libSceAgcDriver/tests/execution/GpuWrittenIndirectBuffer.cpp:242-251`: for a CPU rewrite outside the write watch, a buffer now runs what memory holds, where it used to run as copied. The new test and the debt note both state this. Worth a second look by whoever owns the console's CP behaviour, since it changes an existing expectation. ## Not verified - The test bodies beyond the changed hunks: `AgcDriverAwaitedWaits_nid_postfix`, `Pm4`, `Dispatching` and the `WriteBeforeCopyLandedBeforeRun` gate logic. - `tracker.covers`, `driverPieces`, `possiblePieces` and `entry.whole` / `entry.dropped` / `entry.possibleWhole` / `entry.possibleDropped` in `driverStoredOver`: I read the hunk, not their definitions. - `DrawPipeline::Queue0().Overlaps` and `Busy`, and `DrawFinisher::PendingOverlaps`: used in the new lines of `Submission.cpp:37` and `:307-314`, not read. - That `agc_driver_gpu_written_indirect_buffer_tests.cmake` is included by the test build. The new file is added, but I did not check the `CMakeLists` that loads it. - The A/B performance table and the Windows results: taken from the description. ## Files - Read through `diff.patch` hunks and reader spot-checks: all 8 files in `files.json` `reviewed`. - Read in full: none. Excluded by rule: none. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-21 01:47:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T01:47:53Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this; the points below are optional.

What I ran

Reviewed head 3a5461d3fd2c5ea63f979a737706796702644875 using the prepared diff and repo_read.py for changed code and targeted tracker context. No commands or tests were run in this review environment; test results below are author reported.

Results

Check Result Note
Changed-code audit passed All eight changed files read
Test execution here not run Author reports Linux, Windows, and RADV runs
Negative control not run Author reports controls against main and altered tracker behavior

Findings

Blocking

None.

Non-blocking

None.

Sources

The review covered Submission.hpp, GuestMemory.hpp, Submission.cpp, GuestMemory.cpp, WriteTracking.cpp, agc_driver_gpu_written_indirect_buffer_tests.cmake, GpuWrittenIndirectBuffer.cpp, and fix-agc-indirect-buffer-landed-gpu-write.md, all included in the prepared bundle. The core change records the tracker generation and pending-write state before copying an indirect segment, then refreshes when a tracked driver store or recorded/pending GPU write may have changed it. The added tests cover landed writes before execution, writes pending at copy time, and tracker uncertainty. Pinned diff

Not verified

I did not independently run the tests, inspect CI output, or validate console behavior. The test and hardware results in the description are author reported. The documented race where a store changes the buffer between copying and the comparison remains acknowledged in the change description.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6001934770 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22401#pullrequestreview-6001934770). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T01:47:53Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this; the points below are optional. ## What I ran Reviewed head `3a5461d3fd2c5ea63f979a737706796702644875` using the prepared diff and `repo_read.py` for changed code and targeted tracker context. No commands or tests were run in this review environment; test results below are author reported. ## Results | Check | Result | Note | |---|---|---| | Changed-code audit | passed | All eight changed files read | | Test execution here | not run | Author reports Linux, Windows, and RADV runs | | Negative control | not run | Author reports controls against `main` and altered tracker behavior | ## Findings ### Blocking None. ### Non-blocking None. ## Sources The review covered `Submission.hpp`, `GuestMemory.hpp`, `Submission.cpp`, `GuestMemory.cpp`, `WriteTracking.cpp`, `agc_driver_gpu_written_indirect_buffer_tests.cmake`, `GpuWrittenIndirectBuffer.cpp`, and `fix-agc-indirect-buffer-landed-gpu-write.md`, all included in the prepared bundle. The core change records the tracker generation and pending-write state before copying an indirect segment, then refreshes when a tracked driver store or recorded/pending GPU write may have changed it. The added tests cover landed writes before execution, writes pending at copy time, and tracker uncertainty. [Pinned diff](https://github.com/boykopovar/AnyPS5/pull/22401/commits/3a5461d3fd2c5ea63f979a737706796702644875) ## Not verified I did not independently run the tests, inspect CI output, or validate console behavior. The test and hardware results in the description are author reported. The documented race where a store changes the buffer between copying and the comparison remains acknowledged in the change description. ## 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!22401
No description provided.