From e1f1af62231d1843bda49ae7b64c3bc9984dddeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 18 Dec 2023 13:56:34 +0100 Subject: [PATCH] Defer waits. Add sanity check --- Core/FrameTiming.cpp | 4 +++- Core/HLE/sceDisplay.cpp | 12 ++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Core/FrameTiming.cpp b/Core/FrameTiming.cpp index f89119daef39..f926cae09577 100644 --- a/Core/FrameTiming.cpp +++ b/Core/FrameTiming.cpp @@ -39,7 +39,9 @@ void WaitUntil(double now, double timestamp) { } #else const double left = timestamp - now; - usleep((long)(left * 1000000)); + if (left > 0.0) { + usleep((long)(left * 1000000)); + } #endif } diff --git a/Core/HLE/sceDisplay.cpp b/Core/HLE/sceDisplay.cpp index 671b096589bf..38e877810aa9 100644 --- a/Core/HLE/sceDisplay.cpp +++ b/Core/HLE/sceDisplay.cpp @@ -438,11 +438,15 @@ static void DoFrameTiming(bool throttle, bool *skipFrame, float scaledTimestep, nextFrameTime = curFrameTime; } else { // Wait until we've caught up. - // TODO: This is the wait we actually move to after the frame. - // But watch out, curFrameTime below must be updated correctly - I think. - WaitUntil(curFrameTime, nextFrameTime); + // If we're ending the frame here, we'll defer the sleep until after the command buffers + // have been handed off to the render thread, for some more overlap. + if (endOfFrame) { + g_frameTiming.DeferWaitUntil(nextFrameTime, &curFrameTime); + } else { + WaitUntil(curFrameTime, nextFrameTime); + curFrameTime = time_now_d(); // I guess we could also just set it to nextFrameTime... + } } - curFrameTime = time_now_d(); } lastFrameTime = nextFrameTime;