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.
This commit is contained in:
Geoffrey McRae 2022-05-26 00:40:13 +10:00
parent c737b12a3b
commit 8aa36144dc
6 changed files with 29 additions and 18 deletions

View File

@ -280,7 +280,6 @@ static void egl_deinitialize(LG_Renderer * renderer)
if (this->imgui) if (this->imgui)
ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplOpenGL3_Shutdown();
app_unregisterGraph(this->importGraph);
ringbuffer_free(&this->importTimings); ringbuffer_free(&this->importTimings);
egl_desktopFree(&this->desktop); egl_desktopFree(&this->desktop);

View File

@ -980,6 +980,9 @@ void app_overlayConfigRegisterTab(const char * title,
void app_invalidateOverlay(bool renderTwice) void app_invalidateOverlay(bool renderTwice)
{ {
if (g_state.state == APP_STATE_SHUTDOWN)
return;
if (renderTwice) if (renderTwice)
g_state.renderImGuiTwice = true; g_state.renderImGuiTwice = true;
app_invalidateWindow(false); app_invalidateWindow(false);

View File

@ -201,6 +201,8 @@ static int renderThread(void * unused)
LG_LOCK_INIT(g_state.lgrLock); LG_LOCK_INIT(g_state.lgrLock);
app_initOverlays();
/* signal to other threads that the renderer is ready */ /* signal to other threads that the renderer is ready */
lgSignalEvent(e_startup); lgSignalEvent(e_startup);
@ -322,6 +324,13 @@ static int renderThread(void * unused)
g_state.state = APP_STATE_SHUTDOWN; g_state.state = APP_STATE_SHUTDOWN;
if (g_state.overlays)
{
app_freeOverlays();
ll_free(g_state.overlays);
g_state.overlays = NULL;
}
lgTimerDestroy(tickTimer); lgTimerDestroy(tickTimer);
lgTimerDestroy(fpsTimer); lgTimerDestroy(fpsTimer);
@ -1125,8 +1134,6 @@ static int lg_run(void)
ImFontGlyphRangesBuilder_BuildRanges(rangeBuilder, &g_state.fontRange); ImFontGlyphRangesBuilder_BuildRanges(rangeBuilder, &g_state.fontRange);
ImFontGlyphRangesBuilder_destroy(rangeBuilder); ImFontGlyphRangesBuilder_destroy(rangeBuilder);
app_initOverlays();
// initialize metrics ringbuffers // initialize metrics ringbuffers
g_state.renderTimings = ringbuffer_new(256, sizeof(float)); g_state.renderTimings = ringbuffer_new(256, sizeof(float));
g_state.uploadTimings = 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) if (g_state.dsInitialized)
g_state.ds->free(); g_state.ds->free();
if (g_state.overlays)
{
app_freeOverlays();
ll_free(g_state.overlays);
g_state.overlays = NULL;
}
ivshmemClose(&g_state.shm); ivshmemClose(&g_state.shm);
renderQueue_free(); renderQueue_free();

View File

@ -46,16 +46,14 @@ OverlayConfig;
static OverlayConfig cfg = { 0 }; static OverlayConfig cfg = { 0 };
static bool config_init(void ** udata, const void * params) static void config_earlyInit(void)
{ {
cfg.callbacks = ll_new(); cfg.callbacks = ll_new();
cfg.tabCallbacks = 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; return true;
} }
@ -239,6 +237,7 @@ static int config_render(void * udata, bool interactive, struct Rect * windowRec
struct LG_OverlayOps LGOverlayConfig = struct LG_OverlayOps LGOverlayConfig =
{ {
.name = "Config", .name = "Config",
.earlyInit = config_earlyInit,
.init = config_init, .init = config_init,
.free = config_free, .free = config_free,
.render = config_render .render = config_render

View File

@ -70,9 +70,13 @@ static void showTimingKeybind(int sc, void * opaque)
app_invalidateWindow(false); app_invalidateWindow(false);
} }
static bool graphs_init(void ** udata, const void * params) static void graphs_earlyInit(void)
{ {
gs.graphs = ll_new(); gs.graphs = ll_new();
}
static bool graphs_init(void ** udata, const void * params)
{
app_overlayConfigRegister("Performance Metrics", configCallback, NULL); app_overlayConfigRegister("Performance Metrics", configCallback, NULL);
app_registerKeybind(KEY_T, showTimingKeybind, NULL, app_registerKeybind(KEY_T, showTimingKeybind, NULL,
"Show frame timing information"); "Show frame timing information");
@ -207,6 +211,7 @@ static int graphs_render(void * udata, bool interactive,
struct LG_OverlayOps LGOverlayGraphs = struct LG_OverlayOps LGOverlayGraphs =
{ {
.name = "Graphs", .name = "Graphs",
.earlyInit = graphs_earlyInit,
.init = graphs_init, .init = graphs_init,
.free = graphs_free, .free = graphs_free,
.render = graphs_render .render = graphs_render

View File

@ -46,9 +46,13 @@ struct MsgState
struct MsgState l_msg = { 0 }; struct MsgState l_msg = { 0 };
static bool msg_init(void ** udata, const void * params) static void msg_earlyInit(void)
{ {
l_msg.messages = ll_new(); l_msg.messages = ll_new();
}
static bool msg_init(void ** udata, const void * params)
{
return true; return true;
} }
@ -168,6 +172,7 @@ static int msg_render(void * udata, bool interactive, struct Rect * windowRects,
struct LG_OverlayOps LGOverlayMsg = struct LG_OverlayOps LGOverlayMsg =
{ {
.name = "msg", .name = "msg",
.earlyInit = msg_earlyInit,
.init = msg_init, .init = msg_init,
.free = msg_free, .free = msg_free,
.needs_overlay = msg_needsOverlay, .needs_overlay = msg_needsOverlay,