fix(videoout): pace vblanks with a high-resolution timer #1472
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1472"
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 popcoder565 on 2026-10-08T08:30:57Z.
What
On Windows, vblanks did not come every 16.68 ms. Over 3 × 240 vblanks, intervals ran from 2 ms to 34 ms, and about three quarters were more than 1 ms off the period.
The vblank thread waited for each deadline with
condition_variable::wait_until. With MinGW, that goes through winpthreads, which ends a timed wait only onceGetTickCount64()has advanced by the timeout.GetTickCount64moves in 15.6 ms steps even with the 0.5 ms tickTime.cppsets, so a wait ended on the first tick step after its deadline. When one step passed two deadlines, two vblanks fired back to back. Details and the other host waits this affects are in #1471.The thread now sleeps to each deadline with
PreciseSleepUs(libc/include/PreciseWait.hpp). That uses a high-resolution waitable timer on Windows andthis_thread::sleep_forelsewhere. Deadlines are still counted from the start, so the rate stays 59.94 Hz.A stop request or a presentation failure is now seen when the current sleep ends, at most one vblank later, instead of waking the thread at once.
Shutdowncan therefore take up to 16.7 ms longer.Tested
Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, Intel Core i7-12700H, RTX 3060 Laptop.
I added a mode to
video_out_flip_testslocally (not in this PR). It opens a port, times 240 returns ofsceVideoOutWaitVblankwithsteady_clock, and was run 3 times on each build:maind549f768video_out_flip_tests(not in ctest, #1040), run from a directory with anapp0/sce_sys/param.json, gives the same results with and without this change:decode,controls,present,backtoback,dcc,pacingandaftergpupass.unavailablefails ("failed presentation was marked complete or retained its buffer").lifetimeandreopenterminate ("port is closed").Full ctest: 419 of 421 pass.
agc_driver_dcc_keys_first_writeandagc_driver_srgb8_color_targetfail intermittently without this change too (#1434). Neither loadslibSceVideoOut. Run on their own afterwards, the first passed 3 of 3 times and the second passed 3 of 7.Not run on Linux, where
PreciseSleepUsisthis_thread::sleep_for. No title tested.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T11:57:52Z.
Review: APPROVED
Reviewed the complete diff, PR description, and current Linux, Windows, Conventions, and Progress report checks. The deadline-based high-resolution wait preserves the 59.94 Hz schedule, and the shutdown/failure wakeup delay is clearly documented. I found no issues.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T14:13:46Z.
Checked the diff against the description, build + full ctest (462/462) on top of current main, and CI is green on this head (Linux, Windows, conventions). Deadlines are still counted from
start, so the rate stays 59.94 Hz, and the extra shutdown latency (≤ 1 vblank) is documented. The Windows pacing numbers are yours (not reproducible here); merging.