feat(videoout): add ANYPS5_FPS_LIMIT to cap the rate the window presents #12536
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12536"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 or0is 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
sceVideoOutSetFlipRate1 or 2) in every present mode, includingimmediateandmailbox. The limit is applied inVideoOutDriver::processFlipafter 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-onlycore/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, andPacewith an injected clock and sleeper that waits in slices and can be abandoned. Each feature is followed by its test commit.ParseFrameLimitandConfiguredFrameLimit(parse once per process); test commit for accepted, disabled and refused spellings.docs/dev/ENVIRONMENT.mdrow.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 ownframe_limitphase in the flip timing.OverlayPresentInfoto the detailed page, which draws anFPS LIMITline afterTITLE/PRESENTonly when a limit is set (existing lines and tests unchanged).video_out_flip_fps_limit: six flips underANYPS5_FPS_LIMIT=20may 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.mdand the VideoOut CMake. The edits here are local (one block inprocessFlip, one added line in theOverlayPresentInfoinitialiser, one table row, one added test and CMake entry), branched frommain. 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):
agc_frame_limit(1.7 s), the new overlay assertions inagc_performance_overlay_statistics,video_out_flip_fps_limit: all pass.agc_driver_present_mode,agc_performance_overlay,agc_performance_overlay_device_selection(_cpu),agc_keyboard_overlay,video_out_output_mode_policyand everyvideo_out_flip_*: 26/26 pass on this branch; onmain's sources for the five changed files the same tests (24 of them,video_out_output_mode_policywas not built there) pass too, so the unlimited default is unchanged.Reset, parser bounds and each refusal rule, the overlay line and its thousands format, and the VideoOut hook switched off forvideo_out_flip_fps_limit). Not negative-controlled: handinginfo.fpsLimitto the detail sample and the valueVulkanDevice.cpppasses (no headless test renders page 2 with a limit).ANYPS5_FPS_LIMIT=abc,0.1,-5,30fpseach stop the flip test with[videoout] presentation failed: ANYPS5_FPS_LIMIT must be 0 or a number ... not '<value>';0and an empty value run normally.check_conventions.py,git diff --check,env_reference.py --checkand the public-header audit are clean.aa5cb52af2and onmain319621ba2e, same machine, Vulkan devicellvmpipe (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>' -Vforvideo_out_flip_,agc_driver_present_mode,agc_performance_overlay,video_out_flip_fps_limitandagc_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 containswas not found but was requested by env var VK_INSTANCE_LAYERS(aVK_LOADER_DEBUG=layerrun showslibVkLayer_khronos_validation.soloading), and both contain 0VUID-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
PreciseSleepUsmeet the deadlines, and that underfifoa limit that does not divide the refresh rate shows frames for uneven numbers of refreshes. The tests ran onmainas ofe4da19aff0and the branch was then rebased onto319621ba2e, which adds one unrelated test file in these directories.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)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_limitwould fail onmain(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:VideoOutDriver::processFlip) and the present path (VulkanDevice.cpp), butGPUs testedsays 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) onmainand on this branch withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationviactest --test-dir build -R <pattern> -Von the same machine and GPU. Confirm neither log containswas not found but was requested by env var VK_INSTANCE_LAYERS, that the branch adds no newVUID-errors, and fillGPUs testedwith the GPU (CONTRIBUTING / AGENTS.md).The Windows job and Conventions were still pending on this head; they need to be green too.