feat(videoout): add ANYPS5_FPS_LIMIT to cap the rate the window presents #12536

Merged
MarcZX10 merged 24 commits from upstream-pr/12536 into main 2026-11-01 03:44:08 +00:00
MarcZX10 commented 2026-10-28 18:38:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T18:38:25Z.


What

Adds ANYPS5_FPS_LIMIT, a host-side cap on how many frames per second the window presents. It needs no console behaviour: unset, empty or 0 is exactly today's behaviour; a number from 0.5 to 1000000 (at most three decimals) holds each flip of the window until its turn; any other value stops the title at its first flip with an error that names the variable.

Where it sits: flips are already paced by the vblank thread (59.94 Hz, 119.88 Hz in that output mode, every second or third vblank for sceVideoOutSetFlipRate 1 or 2) in every present mode, including immediate and mailbox. The limit is applied in VideoOutDriver::processFlip after that vblank wait and before the frame is presented, so it delays the presentation and the flip's completion event (which is what paces the title), takes no lock while waiting, and does not touch the title's own CPU work. It lowers the rate below the output's refresh and does nothing above it; the docs say so.

Commits, in order:

  • FramePacer (new header-only core/libs/prx/libSceAgcDriver/Execution/include/FrameLimit.hpp): exact deadlines (integer quotient plus carried remainder, so frame n is at exactly floor(n * 1e12 / limit) ns and nothing drifts), then the bounded catch-up (a frame late by under a period is made up by the next; a stall of any length is made up by at most one early frame, never a burst), Reset, and Pace with an injected clock and sleeper that waits in slices and can be abandoned. Each feature is followed by its test commit.
  • ParseFrameLimit and ConfiguredFrameLimit (parse once per process); test commit for accepted, disabled and refused spellings.
  • docs/dev/ENVIRONMENT.md row.
  • VideoOut hook: waits with the existing PreciseSleepUs (sleep until shortly before the deadline, then a short spin; Windows high-resolution path included) in 20 ms slices, re-checking between slices whether the output closed or failed; the wait is its own frame_limit phase in the flip timing.
  • Overlay: the present's limit travels in OverlayPresentInfo to the detailed page, which draws an FPS LIMIT line after TITLE/PRESENT only when a limit is set (existing lines and tests unchanged).
  • video_out_flip_fps_limit: six flips under ANYPS5_FPS_LIMIT=20 may not finish in under five periods (a lower bound only).
  • docs/user/USAGE.md: the variable, how it meets flip pacing and the present modes, and the overlay row; the cap is a host choice, the console has none.

Overlaps: open #12379 touches the VideoOut flip loop, the VulkanDevice present region and CMake, #9676 the same VideoOut/VulkanDevice/Flip test files, #11948 docs/dev/ENVIRONMENT.md and the VideoOut CMake. The edits here are local (one block in processFlip, one added line in the OverlayPresentInfo initialiser, one table row, one added test and CMake entry), branched from main. No open PR implements a frame limit.

Tested

Linux x86-64, GCC 12, throwaway archive build (the host CPU gate patched as usual), SDL x11 on Xvfb with lavapipe so the VideoOut flip tests run for real (without a display they skip):

  • New: agc_frame_limit (1.7 s), the new overlay assertions in agc_performance_overlay_statistics, video_out_flip_fps_limit: all pass.
  • Existing present-mode and overlay tests, agc_driver_present_mode, agc_performance_overlay, agc_performance_overlay_device_selection(_cpu), agc_keyboard_overlay, video_out_output_mode_policy and every video_out_flip_*: 26/26 pass on this branch; on main's sources for the five changed files the same tests (24 of them, video_out_output_mode_policy was not built there) pass too, so the unlimited default is unchanged.
  • Negative controls: each new test was broken in a scratch copy and failed at the intended case (no catch-up cap, rounding the remainder away, first frame delayed, no slicing, ignoring a refusing sleeper, no clock re-read, no-op Reset, parser bounds and each refusal rule, the overlay line and its thousands format, and the VideoOut hook switched off for video_out_flip_fps_limit). Not negative-controlled: handing info.fpsLimit to the detail sample and the value VulkanDevice.cpp passes (no headless test renders page 2 with a limit).
  • Run by hand: ANYPS5_FPS_LIMIT=abc, 0.1, -5, 30fps each stop the flip test with [videoout] presentation failed: ANYPS5_FPS_LIMIT must be 0 or a number ... not '<value>'; 0 and an empty value run normally.
  • check_conventions.py, git diff --check, env_reference.py --check and the public-header audit are clean.
  • Validation run on the head aa5cb52af2 and on main 319621ba2e, same machine, Vulkan device llvmpipe (LLVM 15.0.6, 256 bits), ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (validation layers 1.3.239.0), xvfb-run -a ctest --test-dir build -R '<pattern>' -V for video_out_flip_, agc_driver_present_mode, agc_performance_overlay, video_out_flip_fps_limit and agc_frame_limit, each tree configured with -DANYPS5_VIDEO_OUT_TEST_DRIVER=x11. Branch: 18/18, 1/1, 4/4, 1/1, 1/1 pass. main: 17/17, 1/1, 4/4 pass; the last two patterns match no test there. Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS (a VK_LOADER_DEBUG=layer run shows libVkLayer_khronos_validation.so loading), and both contain 0 VUID- lines, so the branch adds none. Full details are in the comment below.

Not run: Windows, macOS, a real GPU or window system (Xvfb and lavapipe only), a console, and real pacing accuracy on a loaded host (the flip test checks a lower bound only). Reasoned and not measured: that the Windows and macOS paths of PreciseSleepUs meet the deadlines, and that under fifo a limit that does not divide the refresh rate shows frames for uneven numbers of refreshes. The tests ran on main as of e4da19aff0 and the branch was then rebased onto 319621ba2e, which adds one unrelated test file in these directories.

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: none
  • Unblocks: none
  • GPUs tested: llvmpipe (LLVM 15.0.6, 256 bits), Mesa 22.3.6 software Vulkan driver, Linux x86-64 on Xvfb (no hardware GPU)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5055767599 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12536). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T18:38:25Z. --- ### What Adds `ANYPS5_FPS_LIMIT`, a host-side cap on how many frames per second the window presents. It needs no console behaviour: unset, empty or `0` is exactly today's behaviour; a number from 0.5 to 1000000 (at most three decimals) holds each flip of the window until its turn; any other value stops the title at its first flip with an error that names the variable. Where it sits: flips are already paced by the vblank thread (59.94 Hz, 119.88 Hz in that output mode, every second or third vblank for `sceVideoOutSetFlipRate` 1 or 2) in every present mode, including `immediate` and `mailbox`. The limit is applied in `VideoOutDriver::processFlip` after that vblank wait and before the frame is presented, so it delays the presentation and the flip's completion event (which is what paces the title), takes no lock while waiting, and does not touch the title's own CPU work. It lowers the rate below the output's refresh and does nothing above it; the docs say so. Commits, in order: - `FramePacer` (new header-only `core/libs/prx/libSceAgcDriver/Execution/include/FrameLimit.hpp`): exact deadlines (integer quotient plus carried remainder, so frame n is at exactly floor(n * 1e12 / limit) ns and nothing drifts), then the bounded catch-up (a frame late by under a period is made up by the next; a stall of any length is made up by at most one early frame, never a burst), `Reset`, and `Pace` with an injected clock and sleeper that waits in slices and can be abandoned. Each feature is followed by its test commit. - `ParseFrameLimit` and `ConfiguredFrameLimit` (parse once per process); test commit for accepted, disabled and refused spellings. - `docs/dev/ENVIRONMENT.md` row. - VideoOut hook: waits with the existing `PreciseSleepUs` (sleep until shortly before the deadline, then a short spin; Windows high-resolution path included) in 20 ms slices, re-checking between slices whether the output closed or failed; the wait is its own `frame_limit` phase in the flip timing. - Overlay: the present's limit travels in `OverlayPresentInfo` to the detailed page, which draws an `FPS LIMIT` line after `TITLE`/`PRESENT` only when a limit is set (existing lines and tests unchanged). - `video_out_flip_fps_limit`: six flips under `ANYPS5_FPS_LIMIT=20` may not finish in under five periods (a lower bound only). - `docs/user/USAGE.md`: the variable, how it meets flip pacing and the present modes, and the overlay row; the cap is a host choice, the console has none. Overlaps: open #12379 touches the VideoOut flip loop, the VulkanDevice present region and CMake, #9676 the same VideoOut/VulkanDevice/Flip test files, #11948 `docs/dev/ENVIRONMENT.md` and the VideoOut CMake. The edits here are local (one block in `processFlip`, one added line in the `OverlayPresentInfo` initialiser, one table row, one added test and CMake entry), branched from `main`. No open PR implements a frame limit. ### Tested Linux x86-64, GCC 12, throwaway archive build (the host CPU gate patched as usual), SDL x11 on Xvfb with lavapipe so the VideoOut flip tests run for real (without a display they skip): - New: `agc_frame_limit` (1.7 s), the new overlay assertions in `agc_performance_overlay_statistics`, `video_out_flip_fps_limit`: all pass. - Existing present-mode and overlay tests, `agc_driver_present_mode`, `agc_performance_overlay`, `agc_performance_overlay_device_selection(_cpu)`, `agc_keyboard_overlay`, `video_out_output_mode_policy` and every `video_out_flip_*`: 26/26 pass on this branch; on `main`'s sources for the five changed files the same tests (24 of them, `video_out_output_mode_policy` was not built there) pass too, so the unlimited default is unchanged. - Negative controls: each new test was broken in a scratch copy and failed at the intended case (no catch-up cap, rounding the remainder away, first frame delayed, no slicing, ignoring a refusing sleeper, no clock re-read, no-op `Reset`, parser bounds and each refusal rule, the overlay line and its thousands format, and the VideoOut hook switched off for `video_out_flip_fps_limit`). Not negative-controlled: handing `info.fpsLimit` to the detail sample and the value `VulkanDevice.cpp` passes (no headless test renders page 2 with a limit). - Run by hand: `ANYPS5_FPS_LIMIT=abc`, `0.1`, `-5`, `30fps` each stop the flip test with `[videoout] presentation failed: ANYPS5_FPS_LIMIT must be 0 or a number ... not '<value>'`; `0` and an empty value run normally. - `check_conventions.py`, `git diff --check`, `env_reference.py --check` and the public-header audit are clean. - Validation run on the head `aa5cb52af2` and on `main` `319621ba2e`, same machine, Vulkan device `llvmpipe (LLVM 15.0.6, 256 bits)`, `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (validation layers 1.3.239.0), `xvfb-run -a ctest --test-dir build -R '<pattern>' -V` for `video_out_flip_`, `agc_driver_present_mode`, `agc_performance_overlay`, `video_out_flip_fps_limit` and `agc_frame_limit`, each tree configured with `-DANYPS5_VIDEO_OUT_TEST_DRIVER=x11`. Branch: 18/18, 1/1, 4/4, 1/1, 1/1 pass. `main`: 17/17, 1/1, 4/4 pass; the last two patterns match no test there. Neither log contains `was not found but was requested by env var VK_INSTANCE_LAYERS` (a `VK_LOADER_DEBUG=layer` run shows `libVkLayer_khronos_validation.so` loading), and both contain 0 `VUID-` lines, so the branch adds none. Full details are in the comment below. Not run: Windows, macOS, a real GPU or window system (Xvfb and lavapipe only), a console, and real pacing accuracy on a loaded host (the flip test checks a lower bound only). Reasoned and not measured: that the Windows and macOS paths of `PreciseSleepUs` meet the deadlines, and that under `fifo` a limit that does not divide the refresh rate shows frames for uneven numbers of refreshes. The tests ran on `main` as of e4da19aff0 and the branch was then rebased onto 319621ba2e, which adds one unrelated test file in these directories. ### 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: none - [x] Unblocks: none - [x] GPUs tested: llvmpipe (LLVM 15.0.6, 256 bits), Mesa 22.3.6 software Vulkan driver, Linux x86-64 on Xvfb (no hardware GPU) - [x] AI-assisted: yes
adriadam10 commented 2026-10-28 18:40:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-28T18:40:31Z.

Review: CHANGES_REQUESTED


Thanks, the pacer, parser and the abandon-on-close path read correctly, and video_out_flip_fps_limit would fail on main (six flips at the output's 59.94 Hz finish in about 100 ms, under the 245 ms bound). One thing is missing before merge:

  • This changes VideoOut (VideoOutDriver::processFlip) and the present path (VulkanDevice.cpp), but GPUs tested says n/a and Tested has no validation run. Please run the focused tests (video_out_flip_*, agc_driver_present_mode, agc_performance_overlay*, video_out_flip_fps_limit) on main and on this branch with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation via ctest --test-dir build -R <pattern> -V on the same machine and GPU. Confirm neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS, that the branch adds no new VUID- errors, and fill GPUs tested with the GPU (CONTRIBUTING / AGENTS.md).

The Windows job and Conventions were still pending on this head; they need to be green too.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5687862448 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12536#pullrequestreview-5687862448). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-28T18:40:31Z. **Review:** CHANGES_REQUESTED --- Thanks, the pacer, parser and the abandon-on-close path read correctly, and `video_out_flip_fps_limit` would fail on `main` (six flips at the output's 59.94 Hz finish in about 100 ms, under the 245 ms bound). One thing is missing before merge: - This changes VideoOut (`VideoOutDriver::processFlip`) and the present path (`VulkanDevice.cpp`), but `GPUs tested` says n/a and Tested has no validation run. Please run the focused tests (`video_out_flip_*`, `agc_driver_present_mode`, `agc_performance_overlay*`, `video_out_flip_fps_limit`) on `main` and on this branch with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` via `ctest --test-dir build -R <pattern> -V` on the same machine and GPU. Confirm neither log contains `was not found but was requested by env var VK_INSTANCE_LAYERS`, that the branch adds no new `VUID-` errors, and fill `GPUs tested` with the GPU (CONTRIBUTING / AGENTS.md). The Windows job and Conventions were still pending on this head; they need to be green too.
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!12536
No description provided.