perf(agc): skip the register read log while no log is open #6066

Merged
meh7an merged 1 commit from upstream-pr/6066 into main 2026-10-15 08:45:35 +00:00
meh7an commented 2026-10-14 21:09:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by meh7an on 2026-10-14T21:09:26Z.


What

Every register read of a draw's decode goes through NoteRegisterRead, which checks the thread's register read log (RegisterReadLog(), thread-local). Only the draw recipe verification and the tests ever open one. Under MinGW a thread-local access is an __emutls_get_address call, and a draw decode reads a few hundred registers.

A process-wide count of open logs (RegisterReadLogsOpen(), kept by the new RegisterReadLogScope) now lets a read skip the thread-local lookup while no log is open. Logs are per thread, so a count of zero means no thread has one. The decode and the tests open their logs through the scope.

On the S2 page of Sonic Origins Plus's main menu, the queue worker's samples per frame (APS5 sampler, 15 s) fell as follows: __emutls_get_address 6.09 to 2.35, pthread_getspecific 2.69 to 1.09, and Driver::decodeDraw 5.61 to 2.88.

Tested

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

  • agc_driver_graphics on main fa539dd9b with this change. Its register read checks open their logs through the new scope.
  • Sonic Origins Plus, main menu, S2 page (the 3D background), 1233x694 window.
    • Captured with APS5_TRACE_SECONDS=200:5 on the same machine in one session, caches warm. Traces attached.
    • Baseline 910f3bc97cde, this change 9b08cb001ad5:
Metric Baseline This PR Change
frame_ms.p50 222.257 204.139 -8.2%
frame_ms.p90 230.192 209.037 -9.2%
mean_frame_ms 220.917 203.179 -8.0%
gpu_busy_ms_per_present 74.687 73.102 -2.1%
Driver.Packet (ms per frame) 218.178 200.483 -8.1%

The FPS shown in the title went from 4.66 to 5.00 (median of six readings).

Note: measuring base. These numbers come from main 0a56aaaf4, the last main before #5596. On Windows, later mains compare direct imports on every use, which keeps this menu at 3-4 FPS and hides a change of this size. The base also carries these commits from my fork, in both captures:

  • the fixes a71073ce3, c0d875634, e3c68960e, 604f0f373, 726827880 and 943138569 (#5778);
  • make-exe and the stage dumps (b1931a2d5, c6f670d7f);
  • the crash-report sampler (2bb4555a9..d21f22596), which took the profiles;
  • #6037 (910f3bc97).

All of them are on measure/fresh-dev-2026-10-14: the baseline is 910f3bc97 and this change is 9b08cb001.

The comparison tool marks the window's first present (2148 vs 2229) 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 910f3bc97cde, this change 9b08cb001ad5):
regread-traces.zip

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4864556528 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6066). Originally posted by [meh7an](https://github.com/meh7an) on 2026-10-14T21:09:26Z. --- ### What Every register read of a draw's decode goes through `NoteRegisterRead`, which checks the thread's register read log (`RegisterReadLog()`, thread-local). Only the draw recipe verification and the tests ever open one. Under MinGW a thread-local access is an `__emutls_get_address` call, and a draw decode reads a few hundred registers. A process-wide count of open logs (`RegisterReadLogsOpen()`, kept by the new `RegisterReadLogScope`) now lets a read skip the thread-local lookup while no log is open. Logs are per thread, so a count of zero means no thread has one. The decode and the tests open their logs through the scope. On the S2 page of Sonic Origins Plus's main menu, the queue worker's samples per frame (APS5 sampler, 15 s) fell as follows: `__emutls_get_address` 6.09 to 2.35, `pthread_getspecific` 2.69 to 1.09, and `Driver::decodeDraw` 5.61 to 2.88. ### Tested Windows 11 (10.0.26300), WinLibs GCC 15.2.0 (UCRT), Release, NVIDIA GeForce RTX 2080 Ti, driver 617.14. - `agc_driver_graphics` on main fa539dd9b with this change. Its register read checks open their logs through the new scope. - Sonic Origins Plus, main menu, S2 page (the 3D background), 1233x694 window. - Captured with `APS5_TRACE_SECONDS=200:5` on the same machine in one session, caches warm. Traces attached. - Baseline 910f3bc97cde, this change 9b08cb001ad5: | Metric | Baseline | This PR | Change | | --- | ---: | ---: | ---: | | frame_ms.p50 | 222.257 | 204.139 | -8.2% | | frame_ms.p90 | 230.192 | 209.037 | -9.2% | | mean_frame_ms | 220.917 | 203.179 | -8.0% | | gpu_busy_ms_per_present | 74.687 | 73.102 | -2.1% | | Driver.Packet (ms per frame) | 218.178 | 200.483 | -8.1% | The FPS shown in the title went from 4.66 to 5.00 (median of six readings). > **Note: measuring base.** These numbers come from main 0a56aaaf4, the last main before #5596. On Windows, later mains compare direct imports on every use, which keeps this menu at 3-4 FPS and hides a change of this size. The base also carries these commits from my fork, in both captures: > - the fixes a71073ce3, c0d875634, e3c68960e, 604f0f373, 726827880 and 943138569 (#5778); > - make-exe and the stage dumps (b1931a2d5, c6f670d7f); > - the crash-report sampler (2bb4555a9..d21f22596), which took the profiles; > - #6037 (910f3bc97). > > All of them are on [measure/fresh-dev-2026-10-14](https://github.com/meh7an/AnyPS5/commits/measure/fresh-dev-2026-10-14): the baseline is 910f3bc97 and this change is 9b08cb001. > > The comparison tool marks the window's first present (2148 vs 2229) 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 910f3bc97cde, this change 9b08cb001ad5): [regread-traces.zip](https://github.com/user-attachments/files/33458680/regread-traces.zip)
Dextroid17 commented 2026-10-14 22:02:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-14T22:02:17Z.


Measured on main 0ae1deb85 and on this branch (ec615c145), default CMake build (CMAKE_BUILD_TYPE empty, so unoptimized), lavapipe (llvmpipe), CachyOS Linux 7.2.9, agc_driver_graphics_tests, rebuilt for each ref: 5 of 5 runs pass on both.

I read the diff. RegisterReadLogsOpen() counts open scopes, and the register hook returns early when it is 0. Because the log pointer is thread-local and the counter is global, a scope open on another thread only makes the hook fall through to the old thread-local check, so it never records wrongly.

Limits: the added assertion (the register facade recorded without an open log) does not show the speedup; by reading, the same check holds on main's code too (the pointer is null after the scope). I did not measure the performance change, and I ran only this one test target.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6179462116 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6066#issuecomment-6179462116). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-14T22:02:17Z. --- Measured on main 0ae1deb85 and on this branch (ec615c145), default CMake build (CMAKE_BUILD_TYPE empty, so unoptimized), lavapipe (llvmpipe), CachyOS Linux 7.2.9, `agc_driver_graphics_tests`, rebuilt for each ref: 5 of 5 runs pass on both. I read the diff. `RegisterReadLogsOpen()` counts open scopes, and the register hook returns early when it is 0. Because the log pointer is thread-local and the counter is global, a scope open on another thread only makes the hook fall through to the old thread-local check, so it never records wrongly. Limits: the added assertion (`the register facade recorded without an open log`) does not show the speedup; by reading, the same check holds on main's code too (the pointer is null after the scope). I did not measure the performance change, and I ran only this one test target. AI-assisted: yes
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!6066
No description provided.