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

View File

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