fix(videoout): pace vblanks with a high-resolution timer

On Windows the vblank thread's condition_variable::wait_until went
through winpthreads, which ends a timed wait on a 15.6 ms
GetTickCount64 step even with the scheduler tick raised to 0.5 ms.
Vblank intervals ranged from 2 ms to 34 ms instead of 16.68 ms. The
thread now sleeps to each deadline with PreciseSleepUs and checks for
a stop or a presentation failure after each sleep.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
popcoder565
2026-10-08 04:29:57 -04:00
parent d549f76855
commit b8084b4f02
@@ -20,6 +20,7 @@
#include "prx/libSceAgcDriver/Execution/include/Presentation.hpp"
#include "prx/libSceAgcDriver/Execution/include/PerformanceTimer.hpp"
#include "prx/libSceAgcDriver/Submit/include/Dcb.hpp"
#include "prx/libc/include/PreciseWait.hpp"
#include "prx/libc/include/Shutdown.hpp"
namespace {
@@ -541,9 +542,10 @@ void VideoOutDriver::vblankLoop(std::stop_token token) {
try {
for (int64_t frame = 1; !token.stop_requested(); ++frame) {
const auto next = start + std::chrono::duration_cast<std::chrono::steady_clock::duration>(Frame(frame));
const auto remaining = std::chrono::duration_cast<std::chrono::microseconds>(next - std::chrono::steady_clock::now()).count();
if (remaining > 0) PreciseSleepUs(static_cast<unsigned long long>(remaining));
{
std::unique_lock lock(flipQueue->mutex);
flipQueue->changed.wait_until(lock, next, [&] { return token.stop_requested() || flipQueue->failure; });
std::lock_guard lock(flipQueue->mutex);
if (token.stop_requested() || flipQueue->failure) return;
}
vblankEnd();