From 695b7b793c5999415ff4380debafe864ad5a630a Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sun, 1 Aug 2021 19:32:01 +1000 Subject: [PATCH] [client] main: allow 'catchup' when using jitRender --- client/src/main.c | 20 +++++++++++++++++--- client/src/main.h | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/client/src/main.c b/client/src/main.c index c8845a5f..6134ce40 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -171,13 +171,19 @@ static int renderThread(void * unused) if (g_state.jitRender) { g_state.ds->waitFrame(); - if (!lgResetEvent(g_state.frameEvent) && !g_state.overlayInput && - !g_state.lgr->needs_render(g_state.lgrData)) + + const uint64_t pending = + atomic_load_explicit(&g_state.pendingCount, memory_order_acquire); + if (!lgResetEvent(g_state.frameEvent) && !pending && !g_state.overlayInput + && !g_state.lgr->needs_render(g_state.lgrData)) { if (g_state.ds->skipFrame) g_state.ds->skipFrame(); continue; } + + if (pending > 0) + atomic_fetch_sub(&g_state.pendingCount, 1); } else if (g_params.fpsMin != 0) { @@ -696,7 +702,15 @@ int main_frameThread(void * unused) g_state.lastFrameTimeValid = true; atomic_fetch_add_explicit(&g_state.frameCount, 1, memory_order_relaxed); - lgSignalEvent(g_state.frameEvent); + if (g_state.jitRender) + { + if (atomic_load_explicit(&g_state.pendingCount, memory_order_acquire) < 10) + atomic_fetch_add_explicit(&g_state.pendingCount, 1, + memory_order_release); + } + else + lgSignalEvent(g_state.frameEvent); + lgmpClientMessageDone(queue); } diff --git a/client/src/main.h b/client/src/main.h index 7062a98c..9d280fa5 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -120,6 +120,7 @@ struct AppState RingBuffer renderTimings; RingBuffer frameTimings; + atomic_uint_least64_t pendingCount; atomic_uint_least64_t renderCount, frameCount; _Atomic(float) fps, ups;