From 8aa36144dc19789e1fc66a1213b22809ccfebbe0 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Thu, 26 May 2022 00:40:13 +1000 Subject: [PATCH] overlay: move init/free to the context of the render thread This is done to allow overlays to make use of the renderer during init/free. --- client/renderers/EGL/egl.c | 1 - client/src/app.c | 3 +++ client/src/main.c | 18 +++++++++--------- client/src/overlay/config.c | 11 +++++------ client/src/overlay/graphs.c | 7 ++++++- client/src/overlay/msg.c | 7 ++++++- 6 files changed, 29 insertions(+), 18 deletions(-) diff --git a/client/renderers/EGL/egl.c b/client/renderers/EGL/egl.c index f2b3ac3f..844b984b 100644 --- a/client/renderers/EGL/egl.c +++ b/client/renderers/EGL/egl.c @@ -280,7 +280,6 @@ static void egl_deinitialize(LG_Renderer * renderer) if (this->imgui) ImGui_ImplOpenGL3_Shutdown(); - app_unregisterGraph(this->importGraph); ringbuffer_free(&this->importTimings); egl_desktopFree(&this->desktop); diff --git a/client/src/app.c b/client/src/app.c index fe638409..3e349476 100644 --- a/client/src/app.c +++ b/client/src/app.c @@ -980,6 +980,9 @@ void app_overlayConfigRegisterTab(const char * title, void app_invalidateOverlay(bool renderTwice) { + if (g_state.state == APP_STATE_SHUTDOWN) + return; + if (renderTwice) g_state.renderImGuiTwice = true; app_invalidateWindow(false); diff --git a/client/src/main.c b/client/src/main.c index 4a1ce02b..19f53e20 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -201,6 +201,8 @@ static int renderThread(void * unused) LG_LOCK_INIT(g_state.lgrLock); + app_initOverlays(); + /* signal to other threads that the renderer is ready */ lgSignalEvent(e_startup); @@ -322,6 +324,13 @@ static int renderThread(void * unused) g_state.state = APP_STATE_SHUTDOWN; + if (g_state.overlays) + { + app_freeOverlays(); + ll_free(g_state.overlays); + g_state.overlays = NULL; + } + lgTimerDestroy(tickTimer); lgTimerDestroy(fpsTimer); @@ -1125,8 +1134,6 @@ static int lg_run(void) ImFontGlyphRangesBuilder_BuildRanges(rangeBuilder, &g_state.fontRange); ImFontGlyphRangesBuilder_destroy(rangeBuilder); - app_initOverlays(); - // initialize metrics ringbuffers g_state.renderTimings = ringbuffer_new(256, sizeof(float)); g_state.uploadTimings = ringbuffer_new(256, sizeof(float)); @@ -1666,13 +1673,6 @@ static void lg_shutdown(void) if (g_state.dsInitialized) g_state.ds->free(); - if (g_state.overlays) - { - app_freeOverlays(); - ll_free(g_state.overlays); - g_state.overlays = NULL; - } - ivshmemClose(&g_state.shm); renderQueue_free(); diff --git a/client/src/overlay/config.c b/client/src/overlay/config.c index 4f3cba57..85c93a72 100644 --- a/client/src/overlay/config.c +++ b/client/src/overlay/config.c @@ -46,16 +46,14 @@ OverlayConfig; static OverlayConfig cfg = { 0 }; -static bool config_init(void ** udata, const void * params) +static void config_earlyInit(void) { cfg.callbacks = ll_new(); cfg.tabCallbacks = ll_new(); - if (!cfg.callbacks) - { - DEBUG_ERROR("failed to allocate ram"); - return false; - } +} +static bool config_init(void ** udata, const void * params) +{ return true; } @@ -239,6 +237,7 @@ static int config_render(void * udata, bool interactive, struct Rect * windowRec struct LG_OverlayOps LGOverlayConfig = { .name = "Config", + .earlyInit = config_earlyInit, .init = config_init, .free = config_free, .render = config_render diff --git a/client/src/overlay/graphs.c b/client/src/overlay/graphs.c index 4873e341..8ebbdee4 100644 --- a/client/src/overlay/graphs.c +++ b/client/src/overlay/graphs.c @@ -70,9 +70,13 @@ static void showTimingKeybind(int sc, void * opaque) app_invalidateWindow(false); } -static bool graphs_init(void ** udata, const void * params) +static void graphs_earlyInit(void) { gs.graphs = ll_new(); +} + +static bool graphs_init(void ** udata, const void * params) +{ app_overlayConfigRegister("Performance Metrics", configCallback, NULL); app_registerKeybind(KEY_T, showTimingKeybind, NULL, "Show frame timing information"); @@ -207,6 +211,7 @@ static int graphs_render(void * udata, bool interactive, struct LG_OverlayOps LGOverlayGraphs = { .name = "Graphs", + .earlyInit = graphs_earlyInit, .init = graphs_init, .free = graphs_free, .render = graphs_render diff --git a/client/src/overlay/msg.c b/client/src/overlay/msg.c index e13b2b9f..68765e91 100644 --- a/client/src/overlay/msg.c +++ b/client/src/overlay/msg.c @@ -46,9 +46,13 @@ struct MsgState struct MsgState l_msg = { 0 }; -static bool msg_init(void ** udata, const void * params) +static void msg_earlyInit(void) { l_msg.messages = ll_new(); +} + +static bool msg_init(void ** udata, const void * params) +{ return true; } @@ -168,6 +172,7 @@ static int msg_render(void * udata, bool interactive, struct Rect * windowRects, struct LG_OverlayOps LGOverlayMsg = { .name = "msg", + .earlyInit = msg_earlyInit, .init = msg_init, .free = msg_free, .needs_overlay = msg_needsOverlay,