[client] main: remove/fix faulty upsTime code

The implementation was flawed, instead we just update the presentation
time if there was not an early wakeup.
This commit is contained in:
Geoffrey McRae 2021-07-21 16:47:37 +10:00
parent f5dfc264ba
commit 9b472d62a9
2 changed files with 27 additions and 19 deletions

View File

@ -106,22 +106,30 @@ static bool fpsTimerFn(void * unused)
const uint64_t renderCount = atomic_exchange_explicit(&g_state.renderCount, 0, const uint64_t renderCount = atomic_exchange_explicit(&g_state.renderCount, 0,
memory_order_acquire); memory_order_acquire);
const uint64_t frameCount = atomic_exchange_explicit(&g_state.frameCount, 0,
memory_order_acquire);
const uint64_t time = nanotime(); float fps, ups;
const float elapsedNs = time - last; if (renderCount > 0)
last = time; {
const uint64_t frameCount = atomic_exchange_explicit(&g_state.frameCount, 0,
memory_order_acquire);
const float elapsedMs = (float)elapsedNs / 1e6; const uint64_t time = nanotime();
const uint64_t elapsedNs = time - last;
const float elapsedMs = (float)elapsedNs / 1e6f;
const float fps = 1e3f / (elapsedMs / (float)renderCount); last = time;
const float ups = 1e3f / (elapsedMs / (float)frameCount); fps = 1e3f / (elapsedMs / (float)renderCount);
const uint64_t upsTime = elapsedNs / frameCount; ups = 1e3f / (elapsedMs / (float)frameCount);
}
else
{
last = nanotime();
fps = 0.0f;
ups = 0.0f;
}
atomic_store_explicit(&g_state.fps , fps , memory_order_relaxed); atomic_store_explicit(&g_state.fps, fps, memory_order_relaxed);
atomic_store_explicit(&g_state.ups , ups , memory_order_relaxed); atomic_store_explicit(&g_state.ups, ups, memory_order_relaxed);
atomic_store_explicit(&g_state.upsTime, upsTime, memory_order_relaxed);
return true; return true;
} }
@ -157,12 +165,12 @@ static int renderThread(void * unused)
{ {
if (g_params.fpsMin != 0) if (g_params.fpsMin != 0)
{ {
const uint64_t upsTime = atomic_load_explicit(&g_state.upsTime, if (!lgWaitEventAbs(e_frame, &time))
memory_order_relaxed); {
/* only update the time if we woke up early */
lgWaitEventAbs(e_frame, &time); clock_gettime(CLOCK_MONOTONIC, &time);
clock_gettime(CLOCK_MONOTONIC, &time); tsAdd(&time, g_state.frameTime);
tsAdd(&time, g_state.frameTime + upsTime); }
} }
int resize = atomic_load(&g_state.lgrResize); int resize = atomic_load(&g_state.lgrResize);

View File

@ -104,7 +104,7 @@ struct AppState
RingBuffer renderTimings; RingBuffer renderTimings;
RingBuffer frameTimings; RingBuffer frameTimings;
atomic_uint_least64_t renderCount, frameCount, upsTime; atomic_uint_least64_t renderCount, frameCount;
_Atomic(float) fps, ups; _Atomic(float) fps, ups;
uint64_t resizeTimeout; uint64_t resizeTimeout;