From 2e16c237845bf1b5ff89b7b7a3f8bc1a84729eb1 Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 17 Feb 2020 15:35:14 -0500 Subject: frontend: sdl2: emu_window: Implement separate presentation thread. --- src/yuzu_cmd/yuzu.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src/yuzu_cmd/yuzu.cpp') diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index 325795321..babf4c3a4 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp @@ -177,14 +177,16 @@ int main(int argc, char** argv) { Settings::values.use_gdbstub = use_gdbstub; Settings::Apply(); + Core::System& system{Core::System::GetInstance()}; + std::unique_ptr emu_window; switch (Settings::values.renderer_backend) { case Settings::RendererBackend::OpenGL: - emu_window = std::make_unique(fullscreen); + emu_window = std::make_unique(system, fullscreen); break; case Settings::RendererBackend::Vulkan: #ifdef HAS_VULKAN - emu_window = std::make_unique(fullscreen); + emu_window = std::make_unique(system, fullscreen); break; #else LOG_CRITICAL(Frontend, "Vulkan backend has not been compiled!"); @@ -192,12 +194,6 @@ int main(int argc, char** argv) { #endif } - if (!Settings::values.use_multi_core) { - // Single core mode must acquire OpenGL context for entire emulation session - emu_window->MakeCurrent(); - } - - Core::System& system{Core::System::GetInstance()}; system.SetContentProvider(std::make_unique()); system.SetFilesystem(std::make_shared()); system.GetFileSystemController().CreateFactories(*system.GetFilesystem()); @@ -234,12 +230,23 @@ int main(int argc, char** argv) { system.TelemetrySession().AddField(Telemetry::FieldType::App, "Frontend", "SDL"); - emu_window->MakeCurrent(); system.Renderer().Rasterizer().LoadDiskResources(); + // Acquire render context for duration of the thread if this is the rendering thread + if (!Settings::values.use_asynchronous_gpu_emulation) { + emu_window->MakeCurrent(); + } + SCOPE_EXIT({ + if (!Settings::values.use_asynchronous_gpu_emulation) { + emu_window->DoneCurrent(); + } + }); + + std::thread render_thread([&emu_window] { emu_window->Present(); }); while (emu_window->IsOpen()) { system.RunLoop(); } + render_thread.join(); system.Shutdown(); -- cgit v1.2.3