From 8662083cf4130922732aa8fba655310664b80d8b Mon Sep 17 00:00:00 2001 From: mobserveur Date: Fri, 5 Jul 2024 20:17:25 +0200 Subject: Fix for the fps limiter on intel and amd cpus This commit fixes the fps limiter for intel and amd cpus --- indra/newview/llappviewer.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'indra/newview/llappviewer.cpp') diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index 0f1b5a789b..86da40fcf5 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -256,6 +256,8 @@ using namespace LL; #include "llcoproceduremanager.h" #include "llviewereventrecorder.h" +#include + // *FIX: These extern globals should be cleaned up. // The globals either represent state/config/resource-storage of either // this app, or another 'component' of the viewer. App globals should be @@ -1374,9 +1376,10 @@ bool LLAppViewer::doFrame() { static LLCachedControl fpsLimitMaxFps(gSavedSettings, "MaxFPS", 0); + using TimePoint = std::chrono::steady_clock::time_point; + U64 fpsLimitSleepFor = 0; - U64 fpsLimitFrameStartTime = 0; - if(fpsLimitMaxFps > 0) fpsLimitFrameStartTime = LLTrace::BlockTimer::getCPUClockCount64(); + TimePoint fpsLimitFrameStartTime = std::chrono::steady_clock::now(); LL_RECORD_BLOCK_TIME(FTM_FRAME); { @@ -1550,12 +1553,13 @@ bool LLAppViewer::doFrame() if(fpsLimitMaxFps > 0) { - U64 fpsLimitFrameTime = LLTrace::BlockTimer::getCPUClockCount64() - fpsLimitFrameStartTime; - U64 desired_time_ns = (U32)(1000000.f / fpsLimitMaxFps); + auto elapsed = std::chrono::steady_clock::now() - fpsLimitFrameStartTime; - if((fpsLimitFrameTime+1000) < desired_time_ns) + long long fpsLimitFrameTime = std::chrono::duration_cast(elapsed).count(); + U64 desired_time_us = (U32)(1000000.f / fpsLimitMaxFps); + if((fpsLimitFrameTime+1000) < desired_time_us) { - fpsLimitSleepFor = (desired_time_ns - fpsLimitFrameTime - 1000) * 1.0; + fpsLimitSleepFor = (desired_time_us - fpsLimitFrameTime - 1000) * 1.0; } } -- cgit v1.2.3