perf(agc): keep occlusion counter dumps inside the open render pass #2469

Merged
oneandonlydean merged 1 commit from upstream-pr/2469 into main 2026-10-10 04:47:43 +00:00
oneandonlydean commented 2026-10-09 22:25:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T22:25:28Z.


What

Occlusion counter dumps (EVENT_WRITE PIXEL_PIPE_STAT_DUMP, Recorder::DumpSamples) no longer end the open render pass:

  • Samples are counted in segments: one slot of a per-batch occlusion query pool (128 slots, reset outside any pass when the batch's first pass needs one). A segment begins at the first draw after a pass begins or after a dump, inside the pass's subpass, and ends at the next dump or right before vkCmdEndRenderPass. A pass whose pool has no free slot is not continued, so a new pool can be reset.
  • A dump ends the open segment and is queued in the batch's store run with the number of segments before it. DumpSamplesOnGpu no longer flushes the queued stores over the slot first.
  • The run is recorded where queued stores already are: at Submit, or earlier when later work reads or writes the queued bytes. It copies the segment results the dumps need (one vkCmdCopyQueryPoolResults per contiguous slot range) and the dump list, then records the queue in groups: a group's stores, then one dispatch of the new SampleDumps kernel, which adds each dump's segments to the running total and stores its 16 counters in queue order. A store over bytes a dump of the current group writes starts a new group (Recorder::QueuedWriteGroups), so every byte ends with its last write in program order.
  • At Submit, segments no dump consumed are folded the same way once 64 are pending.
  • Without the GPU sample counter (no buffer device addresses) the batch-long query stays as before.

Why

Each dump ended the open render pass, copied the batch query's result and ran the fold kernel (two barriers), and the store-run flush before it recorded the queued label stores (more barriers). A title that clears each query slot with WRITE_DATA and brackets each bounding-box draw with a begin and an end dump gets a render pass, two copy barriers and a label run per draw.

No reader sees a dump later than before: a CPU reader of the dumped bytes still syncs the batch (the dump notes them as a pending write) and Submit records the run before the batch ends; a later label or store is queued after the dump in the same run; GPU work that reads or writes the queued bytes flushes the run first, as for queued labels. None sees it earlier: the dump is recorded after every draw whose samples it counts.

Tested

  • Linux (CachyOS, GCC, RTX 4090, NVIDIA 610.57.04), on main 1c1c585722: ctest 501/501. tools/check_conventions.py passes.

  • agc_driver_recorder_tests (ctest builds it but does not run it; run by hand, also under the Khronos validation layer with no query or render pass errors):

    • QueuedWriteGroups keeps the program order's final bytes for 20,000 random sequences of stores and dumps.
    • A queued dump does not land before its run is recorded; a reader of other bytes leaves it queued and a reader of its bytes records it; clear, dump and store orders over shared bytes.
    • Two dumps inside one render pass keep it open (the next draw continues it) and split its three draws' samples exactly (64, 128, 192 with precise queries). On main the first dump ends the pass, so an occlusion dump ended the render pass fails.
    • A reader flushing a dump inside a pass ends the pass; 160 dumps in one pass, past a pool's 128 slots; 70 passes without a dump folded at Submit.
    • The run stops later at importWindowTests "(w) a cache over the pages the import reported sees no change", which fails the same way on main; with that test skipped every test passes.
  • A heavier title, one level, frames per second over level start +30 to +150 s, warm caches, frame-clock windows. It does not reach the level on main alone, so this was measured with the fixes it needs to get there (boot fixes, #425, #1059, #1274, #1745 and two pending perf changes); "base" is that build. Per presented frame, from APS5_PROFILE_DRAW:

    build level fps GPU busy per frame render passes barriers copy-class barriers
    base 0.669 / 0.620 1,350 ms ~4.0k ~32k ~10k
    base + this 0.664 / 0.676 1,310 ms ~1.7k ~12.7k 0
    base + a depth-copy fix for #425 2.492 / 2.625 142 ms ~4.2k ~31k ~11k
    base + that fix + this 2.821 / 2.860 102 ms ~1.6k ~9.5k 0

    In that level the GPU time was dominated by a depth-plane copy (#425's code, review input there), so pass breaks only show in frame rate once that is fixed: +11% (2.56 to 2.84 fps), GPU busy 142 to 102 ms per frame with it.

  • A lighter title that runs at 60 fps, on main + this: all screen checks pass, 60.0 fps menu and 59.9 fps gameplay, no skipped draws, no single-frame flashes.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4806507864 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2469). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T22:25:28Z. --- ### What Occlusion counter dumps (`EVENT_WRITE` `PIXEL_PIPE_STAT_DUMP`, `Recorder::DumpSamples`) no longer end the open render pass: - Samples are counted in segments: one slot of a per-batch occlusion query pool (128 slots, reset outside any pass when the batch's first pass needs one). A segment begins at the first draw after a pass begins or after a dump, inside the pass's subpass, and ends at the next dump or right before `vkCmdEndRenderPass`. A pass whose pool has no free slot is not continued, so a new pool can be reset. - A dump ends the open segment and is queued in the batch's store run with the number of segments before it. `DumpSamplesOnGpu` no longer flushes the queued stores over the slot first. - The run is recorded where queued stores already are: at `Submit`, or earlier when later work reads or writes the queued bytes. It copies the segment results the dumps need (one `vkCmdCopyQueryPoolResults` per contiguous slot range) and the dump list, then records the queue in groups: a group's stores, then one dispatch of the new `SampleDumps` kernel, which adds each dump's segments to the running total and stores its 16 counters in queue order. A store over bytes a dump of the current group writes starts a new group (`Recorder::QueuedWriteGroups`), so every byte ends with its last write in program order. - At `Submit`, segments no dump consumed are folded the same way once 64 are pending. - Without the GPU sample counter (no buffer device addresses) the batch-long query stays as before. ### Why Each dump ended the open render pass, copied the batch query's result and ran the fold kernel (two barriers), and the store-run flush before it recorded the queued label stores (more barriers). A title that clears each query slot with `WRITE_DATA` and brackets each bounding-box draw with a begin and an end dump gets a render pass, two copy barriers and a label run per draw. No reader sees a dump later than before: a CPU reader of the dumped bytes still syncs the batch (the dump notes them as a pending write) and `Submit` records the run before the batch ends; a later label or store is queued after the dump in the same run; GPU work that reads or writes the queued bytes flushes the run first, as for queued labels. None sees it earlier: the dump is recorded after every draw whose samples it counts. ### Tested - Linux (CachyOS, GCC, RTX 4090, NVIDIA 610.57.04), on `main` 1c1c585722: ctest 501/501. `tools/check_conventions.py` passes. - `agc_driver_recorder_tests` (ctest builds it but does not run it; run by hand, also under the Khronos validation layer with no query or render pass errors): - `QueuedWriteGroups` keeps the program order's final bytes for 20,000 random sequences of stores and dumps. - A queued dump does not land before its run is recorded; a reader of other bytes leaves it queued and a reader of its bytes records it; clear, dump and store orders over shared bytes. - Two dumps inside one render pass keep it open (the next draw continues it) and split its three draws' samples exactly (64, 128, 192 with precise queries). On `main` the first dump ends the pass, so `an occlusion dump ended the render pass` fails. - A reader flushing a dump inside a pass ends the pass; 160 dumps in one pass, past a pool's 128 slots; 70 passes without a dump folded at `Submit`. - The run stops later at `importWindowTests` "(w) a cache over the pages the import reported sees no change", which fails the same way on `main`; with that test skipped every test passes. - A heavier title, one level, frames per second over level start +30 to +150 s, warm caches, frame-clock windows. It does not reach the level on `main` alone, so this was measured with the fixes it needs to get there (boot fixes, #425, #1059, #1274, #1745 and two pending perf changes); "base" is that build. Per presented frame, from `APS5_PROFILE_DRAW`: | build | level fps | GPU busy per frame | render passes | barriers | copy-class barriers | |---|---|---|---|---|---| | base | 0.669 / 0.620 | 1,350 ms | ~4.0k | ~32k | ~10k | | base + this | 0.664 / 0.676 | 1,310 ms | ~1.7k | ~12.7k | 0 | | base + a depth-copy fix for #425 | 2.492 / 2.625 | 142 ms | ~4.2k | ~31k | ~11k | | base + that fix + this | 2.821 / 2.860 | 102 ms | ~1.6k | ~9.5k | 0 | In that level the GPU time was dominated by a depth-plane copy (#425's code, review input there), so pass breaks only show in frame rate once that is fixed: +11% (2.56 to 2.84 fps), GPU busy 142 to 102 ms per frame with it. - A lighter title that runs at 60 fps, on `main` + this: all screen checks pass, 60.0 fps menu and 59.9 fps gameplay, no skipped draws, no single-frame flashes. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
popcoder565 commented 2026-10-09 22:46:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T22:46:58Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head 8dac4e61, merged onto main 09a3462e in one build with #2473, which current main needs to build on Windows, and 3 other new PRs.

  • agc_driver_recorder_tests (not in ctest), which holds this PR's test change, passes 10 of 10, built explicitly. #2248 was merged too, because main fails that test for other reasons (#2155).
  • Full ctest in that build: 546 of 546.

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090559532 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2469#issuecomment-6090559532). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T22:46:58Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `8dac4e61`, merged onto `main` 09a3462e in one build with #2473, which current `main` needs to build on Windows, and 3 other new PRs. - `agc_driver_recorder_tests` (not in ctest), which holds this PR's test change, passes 10 of 10, built explicitly. #2248 was merged too, because `main` fails that test for other reasons (#2155). - Full ctest in that build: 546 of 546. No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
Kikoarl commented 2026-10-09 22:50:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-09T22:50:01Z.


Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at 8dac4e61:

  • Build: Built cleanly in RAM (/tmp/anyps5_build) with zero warnings/errors.
  • Conventions: python3 tools/check_conventions.py --base origin/main --head HEAD -> PASS (0 errors).
  • Verification: Verified SampleDumps.comp and occlusion query recorder in libSceAgcDriver. Keeping occlusion counter dumps inside the active render pass prevents spurious render pass splits.

LGTM!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090592444 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2469#issuecomment-6090592444). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-09T22:50:01Z. --- Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at `8dac4e61`: - **Build**: Built cleanly in RAM (`/tmp/anyps5_build`) with zero warnings/errors. - **Conventions**: `python3 tools/check_conventions.py --base origin/main --head HEAD` -> **PASS (0 errors)**. - **Verification**: Verified `SampleDumps.comp` and occlusion query recorder in `libSceAgcDriver`. Keeping occlusion counter dumps inside the active render pass prevents spurious render pass splits. LGTM!
github-actions[bot] commented 2026-10-09 23:01:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T23:01:42Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#2470 core/libs/prx/libSceAgcDriver/tests/shaders/Cover.frag
core/libs/prx/libSceAgcDriver/tests/shaders/Cover.vert
#2545 core/libs/prx/libSceAgcDriver/Graphics/shaders/SampleDumps.comp
core/libs/prx/libSceAgcDriver/tests/shaders/Cover.frag
core/libs/prx/libSceAgcDriver/tests/shaders/Cover.vert
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090728103 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2469#issuecomment-6090728103). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T23:01:42Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #2470 | | | `core/libs/prx/libSceAgcDriver/tests/shaders/Cover.frag`<br>`core/libs/prx/libSceAgcDriver/tests/shaders/Cover.vert` | | #2545 | | | `core/libs/prx/libSceAgcDriver/Graphics/shaders/SampleDumps.comp`<br>`core/libs/prx/libSceAgcDriver/tests/shaders/Cover.frag`<br>`core/libs/prx/libSceAgcDriver/tests/shaders/Cover.vert` |
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!2469
No description provided.