From f86053d02027441d72d0bc40e0bcf119edf110b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 16 Aug 2023 15:53:24 +0200 Subject: [PATCH] Fix falling back to the old timing, also show audio timing in the frame timing overlay --- Common/TimeUtil.cpp | 2 ++ Core/Config.h | 2 +- Core/FrameTiming.cpp | 20 +++++++++++--------- Core/FrameTiming.h | 1 + Core/HLE/sceDisplay.cpp | 7 ++++--- UI/DebugOverlay.cpp | 8 +++++++- 6 files changed, 26 insertions(+), 14 deletions(-) diff --git a/Common/TimeUtil.cpp b/Common/TimeUtil.cpp index e22b225828..3eeb250648 100644 --- a/Common/TimeUtil.cpp +++ b/Common/TimeUtil.cpp @@ -150,6 +150,8 @@ void sleep_ms(int ms) { } void sleep_s(double s) { + if (s <= 0.0) + return; #if defined(_WIN32) || defined(__EMSCRIPTEN__) || defined(HAVE_LIBNX) sleep_ms((int)(s * 1000.0)); #else diff --git a/Core/Config.h b/Core/Config.h index eeb6d51f2f..43ef2023d7 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -471,7 +471,7 @@ public: // Volatile development settings // Overlays - int iDebugOverlay; + int iDebugOverlay; // enum DebugOverlay bool bGpuLogProfiler; // Controls the Vulkan logging profiler (profiles textures uploads etc). diff --git a/Core/FrameTiming.cpp b/Core/FrameTiming.cpp index 04e5ec0cc0..23d56448a7 100644 --- a/Core/FrameTiming.cpp +++ b/Core/FrameTiming.cpp @@ -133,6 +133,11 @@ void FrameTiming::SetTimeStep(float scaledTimeStep) { setTimestepCalled_ = true; } +void FrameTiming::DontUse() { + usePresentTiming = false; + setTimestepCalled_ = true; +} + void FrameTiming::AfterCPUSlice() { if (!setTimestepCalled_) { // We're in the menu or something. @@ -147,17 +152,17 @@ void FrameTiming::BeforePresent() { // Wait until we hit the next present time. Ideally we'll be fairly close here due to the previous AfterPresent wait. nextPresentTime = lastPresentTime + this->timeStep + nudge_; - while (true) { - double remaining = nextPresentTime - time_now_d(); - if (remaining <= 0.0) - break; - sleep_s(remaining); - } + // Not sure we need the while loop. + double remaining = nextPresentTime - time_now_d(); + sleep_s(remaining); lastPresentTime = nextPresentTime; } void FrameTiming::AfterPresent() { + if (!usePresentTiming) + return; + // Sleep slightly less time than all of the available room, in case of a CPU spike. // This should be a tweakable. const double margin = 2.0 * 0.001; // 4 ms @@ -166,7 +171,4 @@ void FrameTiming::AfterPresent() { if (postSleep > 0.0) { sleep_s(postSleep); } - - if (!usePresentTiming) - return; } diff --git a/Core/FrameTiming.h b/Core/FrameTiming.h index 60afe65f71..007c278618 100644 --- a/Core/FrameTiming.h +++ b/Core/FrameTiming.h @@ -29,6 +29,7 @@ public: void BeforeCPUSlice(const FrameHistoryBuffer &frameHistory); void SetTimeStep(float scaledTimeStep); + void DontUse(); void AfterCPUSlice(); void BeforePresent(); void AfterPresent(); diff --git a/Core/HLE/sceDisplay.cpp b/Core/HLE/sceDisplay.cpp index e8d70116f5..ef68149322 100644 --- a/Core/HLE/sceDisplay.cpp +++ b/Core/HLE/sceDisplay.cpp @@ -646,7 +646,7 @@ void __DisplayFlip(int cyclesLate) { int frameSkipNum; // If the ideal case, use the new timing path. - g_frameTiming.usePresentTiming = g_Config.iFrameSkip == 0 && !refreshRateNeedsSkip; + g_frameTiming.usePresentTiming = g_Config.iFrameSkip == 0 && !refreshRateNeedsSkip && throttle; if (g_frameTiming.usePresentTiming) { if (Core_NextFrame()) { @@ -657,11 +657,12 @@ void __DisplayFlip(int cyclesLate) { goto finishUp; } else { // This should only happen if we're stepping in the debugger. - // Go to the old path. - g_frameTiming.usePresentTiming = false; + // Fall through to the old path. } } + g_frameTiming.DontUse(); + // Setting CORE_NEXTFRAME (which Core_NextFrame does) causes a swap. if (fbReallyDirty || noRecentFlip || postEffectRequiresFlip) { // Check first though, might've just quit / been paused. diff --git a/UI/DebugOverlay.cpp b/UI/DebugOverlay.cpp index aa3e6a6ceb..1038abbbf0 100644 --- a/UI/DebugOverlay.cpp +++ b/UI/DebugOverlay.cpp @@ -108,7 +108,7 @@ static void DrawFrameTimes(UIContext *ctx, const Bounds &bounds) { static void DrawFrameTiming(UIContext *ctx, const Bounds &bounds) { FontID ubuntu24("UBUNTU24"); - char statBuf[1024]{}; + char statBuf[2048]{}; ctx->Flush(); ctx->BindFontTexture(); @@ -174,6 +174,12 @@ static void DrawFrameTiming(UIContext *ctx, const Bounds &bounds) { } ctx->Draw()->DrawTextRect(ubuntu24, statBuf, bounds.x + 10 + i * 150, bounds.y + 150, bounds.w - 20, bounds.h - 30, 0xFFFFFFFF, FLAG_DYNAMIC_ASCII); } + + // Also draw audio stats, because they're quite relevant. + + System_AudioGetDebugStats(statBuf, sizeof(statBuf)); + ctx->Draw()->DrawTextRect(ubuntu24, statBuf, bounds.x + 10, bounds.y + 360, bounds.w - 20, bounds.h - 30, 0xFFFFFFFF, FLAG_DYNAMIC_ASCII); + ctx->Draw()->SetFontScale(1.0f, 1.0f); ctx->Flush(); ctx->RebindTexture();