perf(agc): rule out pending write overlaps from the published union #6609

Merged
meh7an merged 1 commit from upstream-pr/6609 into main 2026-10-19 08:14:19 +00:00
meh7an commented 2026-10-15 22:47:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by meh7an on 2026-10-15T22:47:43Z.


What

Recorder::PendingWriteOverlaps answers whether a range overlaps a GPU write the recorder has noted for its open or in-flight batches. It walks every noted write of every batch, and the draw path asks it from 25 places (in-place draw inputs, texture refreshes, DCC keys, descriptor builds among them).

The recorder already merges those writes into the snapshot it publishes (publishPendingWrites). It now also keeps the union it last published, published, for as long as that union covers every write noted since:

  • publishPendingWrites sets it to the union it publishes;
  • noteWrite and noteWriteOn, which add every batch write, drop it when the new write falls outside it;
  • a recorder that is not active publishes nothing, so once one of its writes falls outside the old union it keeps none.

PendingWriteOverlaps answers no overlap from that union with one binary search when the range is clear of it, and walks the batches otherwise. The union may still hold the writes of batches that finished since it was built; that only sends a query to the walk. #4889's publishedWriteRanges is a weak reference that only lets the next publish extend the snapshot, and it is not dropped when a write falls outside it, so this keeps its own strong pointer.

On the S2 page of Sonic Origins Plus's main menu, PendingWriteOverlaps cost the queue worker (APS5 sampler, 15 s, samples per frame):

  • without this change, in three runs: 0.44, 0.42 and 0.24;
  • with it, in five runs: 0.06, 0.04, 0.07, 0.16 and 0.06.

That is about 1% of the worker's frame (34 to 37 samples), so the frame times below move within run-to-run noise.

Tested

Windows 11 (10.0.26300), WinLibs GCC 15.2.0 (UCRT), Release, NVIDIA GeForce RTX 2080 Ti, driver 617.14.

  • On main 5d9dcc42d with this change, the full ctest suite passes 1298 of 1300 tests.
    • agc_driver_gpu_indirect_arguments_misaligned_writer_ahead is not run: main itself does not compile it with MinGW (alignas(65536)).
    • agc_driver_multisample_fill_host_only failed once ("the sentinel fill did not land"). That is main's own race, #6512, which #6522 fixes. With this change it failed 42 of 200 runs (8 at a time), as main does (46 of 200 on b7cedd900). With #6522's line added it failed 0 of 200.
  • Sonic Origins Plus, main menu, S2 page (the 3D background), 1233x694 window.
    • Captured with APS5_TRACE_SECONDS=200:15 on the same machine in one session, caches warm. Traces attached.
    • Baseline e3b8d1c52, this change a0dd42cf9 (the summaries name the commits before them, see the note):
Metric Baseline This PR Change
frame_ms.p50 114.380 112.276 -1.8%
frame_ms.p90 131.070 115.733 -11.7%
mean_frame_ms 117.931 113.900 -3.4%
gpu_busy_ms_per_present 83.714 83.003 -0.8%
Driver.Packet (ms per frame) 115.666 111.728 -3.4%
Driver.Draw (ms per frame) 103.821 99.869 -3.8%

The FPS shown in the title went from 9.38 to 9.53 (median of six readings). The p90 gap comes from slower frames in the baseline's window; the median moved within noise.

I captured the baseline twice. The first window caught a stretch where the page's draws repeated exactly and the draw cache hit: frames of 74 ms, no shader_compile_and_link phase, and the GPU fence as the limit. The second, used above, shows the moving background like the change's window.

Note: measuring base. These numbers come from my fork's dev, on main 0a56aaaf4. The code this change touches is the same on main 5d9dcc42d, except #4889's incremental snapshot extension, which dev does not have.

  • The baseline is measure/drawkey-2026-10-16 (e3b8d1c52).
  • This change is measure/union-2026-10-16 (a0dd42cf9).
  • Each build was made before its commit, so the summaries name the commit before it, dirty: a21a3ce81 for the baseline and e3b8d1c52 for this change.

Both carry these commits from my fork:

  • the fixes a71073ce3, c0d875634, e3c68960e, 604f0f373 and 10ff693aa (#5778);
  • make-exe and the stage dumps (522230d62, deee71fde);
  • the crash-report sampler (8d9c3103e..f641e1ec9), which took the profiles;
  • #6037, #6066, #6077, #6067, #6082 (its first version, before #5906), #6095, #6266, #6292 and #6312;
  • smaller steps kept in my fork: e83260247, 97b1ff6c9, 84f5bf0ff, 3b47f7743 (covered on main by #5062), ce567bc3d, a79e58a7c, a0a891697, 63f7a8ed0, b04806167, 719fb71dd, a21a3ce81 and e3b8d1c52 (which #6566 covers).

The comparison tool marks the window's first present as a configuration difference: the window opens 200 s into each run. Both summaries set trace_dropped, because the worker filled its event buffer at about 2,700 draws per frame. The phase totals above stay complete.

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
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 2080 Ti, driver 617.14, Windows 11
  • AI-assisted: yes

Traces and summary lines (baseline e3b8d1c52, whose summary says a21a3ce81e18; this change a0dd42cf9, whose summary says e3b8d1c5245e):
union-traces.zip

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4880841944 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6609). Originally posted by [meh7an](https://github.com/meh7an) on 2026-10-15T22:47:43Z. --- ### What `Recorder::PendingWriteOverlaps` answers whether a range overlaps a GPU write the recorder has noted for its open or in-flight batches. It walks every noted write of every batch, and the draw path asks it from 25 places (in-place draw inputs, texture refreshes, DCC keys, descriptor builds among them). The recorder already merges those writes into the snapshot it publishes (`publishPendingWrites`). It now also keeps the union it last published, `published`, for as long as that union covers every write noted since: - `publishPendingWrites` sets it to the union it publishes; - `noteWrite` and `noteWriteOn`, which add every batch write, drop it when the new write falls outside it; - a recorder that is not active publishes nothing, so once one of its writes falls outside the old union it keeps none. `PendingWriteOverlaps` answers no overlap from that union with one binary search when the range is clear of it, and walks the batches otherwise. The union may still hold the writes of batches that finished since it was built; that only sends a query to the walk. #4889's `publishedWriteRanges` is a weak reference that only lets the next publish extend the snapshot, and it is not dropped when a write falls outside it, so this keeps its own strong pointer. On the S2 page of Sonic Origins Plus's main menu, `PendingWriteOverlaps` cost the queue worker (APS5 sampler, 15 s, samples per frame): - without this change, in three runs: 0.44, 0.42 and 0.24; - with it, in five runs: 0.06, 0.04, 0.07, 0.16 and 0.06. That is about 1% of the worker's frame (34 to 37 samples), so the frame times below move within run-to-run noise. ### Tested Windows 11 (10.0.26300), WinLibs GCC 15.2.0 (UCRT), Release, NVIDIA GeForce RTX 2080 Ti, driver 617.14. - On main 5d9dcc42d with this change, the full ctest suite passes 1298 of 1300 tests. - `agc_driver_gpu_indirect_arguments_misaligned_writer_ahead` is not run: main itself does not compile it with MinGW (`alignas(65536)`). - `agc_driver_multisample_fill_host_only` failed once ("the sentinel fill did not land"). That is main's own race, #6512, which #6522 fixes. With this change it failed 42 of 200 runs (8 at a time), as main does (46 of 200 on b7cedd900). With #6522's line added it failed 0 of 200. - Sonic Origins Plus, main menu, S2 page (the 3D background), 1233x694 window. - Captured with `APS5_TRACE_SECONDS=200:15` on the same machine in one session, caches warm. Traces attached. - Baseline e3b8d1c52, this change a0dd42cf9 (the summaries name the commits before them, see the note): | Metric | Baseline | This PR | Change | | --- | ---: | ---: | ---: | | frame_ms.p50 | 114.380 | 112.276 | -1.8% | | frame_ms.p90 | 131.070 | 115.733 | -11.7% | | mean_frame_ms | 117.931 | 113.900 | -3.4% | | gpu_busy_ms_per_present | 83.714 | 83.003 | -0.8% | | Driver.Packet (ms per frame) | 115.666 | 111.728 | -3.4% | | Driver.Draw (ms per frame) | 103.821 | 99.869 | -3.8% | The FPS shown in the title went from 9.38 to 9.53 (median of six readings). The p90 gap comes from slower frames in the baseline's window; the median moved within noise. I captured the baseline twice. The first window caught a stretch where the page's draws repeated exactly and the draw cache hit: frames of 74 ms, no `shader_compile_and_link` phase, and the GPU fence as the limit. The second, used above, shows the moving background like the change's window. > **Note: measuring base.** These numbers come from my fork's dev, on main 0a56aaaf4. The code this change touches is the same on main 5d9dcc42d, except #4889's incremental snapshot extension, which dev does not have. > - The baseline is [measure/drawkey-2026-10-16](https://github.com/meh7an/AnyPS5/commits/measure/drawkey-2026-10-16) (e3b8d1c52). > - This change is [measure/union-2026-10-16](https://github.com/meh7an/AnyPS5/commits/measure/union-2026-10-16) (a0dd42cf9). > - Each build was made before its commit, so the summaries name the commit before it, `dirty`: a21a3ce81 for the baseline and e3b8d1c52 for this change. > > Both carry these commits from my fork: > - the fixes a71073ce3, c0d875634, e3c68960e, 604f0f373 and 10ff693aa (#5778); > - make-exe and the stage dumps (522230d62, deee71fde); > - the crash-report sampler (8d9c3103e..f641e1ec9), which took the profiles; > - #6037, #6066, #6077, #6067, #6082 (its first version, before #5906), #6095, #6266, #6292 and #6312; > - smaller steps kept in my fork: e83260247, 97b1ff6c9, 84f5bf0ff, 3b47f7743 (covered on main by #5062), ce567bc3d, a79e58a7c, a0a891697, 63f7a8ed0, b04806167, 719fb71dd, a21a3ce81 and e3b8d1c52 (which #6566 covers). > > The comparison tool marks the window's first present as a configuration difference: the window opens 200 s into each run. Both summaries set `trace_dropped`, because the worker filled its event buffer at about 2,700 draws per frame. The phase totals above stay complete. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical 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] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 2080 Ti, driver 617.14, Windows 11 - [x] AI-assisted: yes Traces and summary lines (baseline e3b8d1c52, whose summary says a21a3ce81e18; this change a0dd42cf9, whose summary says e3b8d1c5245e): [union-traces.zip](https://github.com/user-attachments/files/33517851/union-traces.zip)
github-actions[bot] commented 2026-10-15 23:30:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T23:30:03Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5609 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 6185 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 6186 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 6539 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 6946 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 6947 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 7340 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 7622 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6204440455 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6609#issuecomment-6204440455). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T23:30:03Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5609](https://www.github.com/boykopovar/AnyPS5/pull/5609) | `core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 6185](https://www.github.com/boykopovar/AnyPS5/pull/6185) | `core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 6186](https://www.github.com/boykopovar/AnyPS5/pull/6186) | `core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 6188](https://www.github.com/boykopovar/AnyPS5/pull/6188) | `core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 6539](https://www.github.com/boykopovar/AnyPS5/pull/6539) | `core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 6946](https://www.github.com/boykopovar/AnyPS5/pull/6946) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 6947](https://www.github.com/boykopovar/AnyPS5/pull/6947) | `core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 7340](https://www.github.com/boykopovar/AnyPS5/pull/7340) | `core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 7622](https://www.github.com/boykopovar/AnyPS5/pull/7622) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 7642](https://www.github.com/boykopovar/AnyPS5/pull/7642) | `core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` |
adriadam10 commented 2026-10-19 08:15:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T08:15:22Z.


Checked the published-union fast path against noteWrite, noteWriteOn and publishPendingWrites: the union always covers every noted write (full rebuild includes open, in-flight and finishing batches; a write outside it drops the pointer; an inactive recorder publishes nothing), and a union that still holds finished batches only sends the query to the old walk. Re-checked against current main: the new Recorder changes there (barrier batching) add no noted writes. Merging through the queue.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6262777958 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6609#issuecomment-6262777958). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T08:15:22Z. --- Checked the published-union fast path against `noteWrite`, `noteWriteOn` and `publishPendingWrites`: the union always covers every noted write (full rebuild includes open, in-flight and finishing batches; a write outside it drops the pointer; an inactive recorder publishes nothing), and a union that still holds finished batches only sends the query to the old walk. Re-checked against current main: the new Recorder changes there (barrier batching) add no noted writes. Merging through the queue.
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!6609
No description provided.