Merge pull request #4940 from jroweboy/presentation-thread
Split Presentation thread from Render thread
This commit is contained in:
commit
439d550850
27 changed files with 899 additions and 243 deletions
|
@ -35,6 +35,7 @@
|
|||
#include "core/file_sys/cia_container.h"
|
||||
#include "core/frontend/applets/default_applets.h"
|
||||
#include "core/frontend/framebuffer_layout.h"
|
||||
#include "core/frontend/scope_acquire_context.h"
|
||||
#include "core/gdbstub/gdbstub.h"
|
||||
#include "core/hle/service/am/am.h"
|
||||
#include "core/hle/service/cfg/cfg.h"
|
||||
|
@ -347,7 +348,7 @@ int main(int argc, char** argv) {
|
|||
Core::System::GetInstance().RegisterImageInterface(std::make_shared<LodePNGImageInterface>());
|
||||
|
||||
std::unique_ptr<EmuWindow_SDL2> emu_window{std::make_unique<EmuWindow_SDL2>(fullscreen)};
|
||||
|
||||
Frontend::ScopeAcquireContext scope(*emu_window);
|
||||
Core::System& system{Core::System::GetInstance()};
|
||||
|
||||
const Core::System::ResultStatus load_result{system.Load(*emu_window, filepath)};
|
||||
|
@ -411,9 +412,11 @@ int main(int argc, char** argv) {
|
|||
system.VideoDumper().StartDumping(dump_video, "webm", layout);
|
||||
}
|
||||
|
||||
std::thread render_thread([&emu_window] { emu_window->Present(); });
|
||||
while (emu_window->IsOpen()) {
|
||||
system.RunLoop();
|
||||
}
|
||||
render_thread.join();
|
||||
|
||||
Core::Movie::GetInstance().Shutdown();
|
||||
if (system.VideoDumper().IsDumping()) {
|
||||
|
|
|
@ -121,10 +121,11 @@ void Config::ReadValues() {
|
|||
Settings::values.use_shader_jit = sdl2_config->GetBoolean("Renderer", "use_shader_jit", true);
|
||||
Settings::values.resolution_factor =
|
||||
static_cast<u16>(sdl2_config->GetInteger("Renderer", "resolution_factor", 1));
|
||||
Settings::values.vsync_enabled = sdl2_config->GetBoolean("Renderer", "vsync_enabled", false);
|
||||
Settings::values.use_frame_limit = sdl2_config->GetBoolean("Renderer", "use_frame_limit", true);
|
||||
Settings::values.frame_limit =
|
||||
static_cast<u16>(sdl2_config->GetInteger("Renderer", "frame_limit", 100));
|
||||
Settings::values.use_vsync_new =
|
||||
static_cast<u16>(sdl2_config->GetInteger("Renderer", "use_vsync_new", 1));
|
||||
|
||||
Settings::values.render_3d = static_cast<Settings::StereoRenderOption>(
|
||||
sdl2_config->GetInteger("Renderer", "render_3d", 0));
|
||||
|
|
|
@ -112,15 +112,16 @@ shaders_accurate_mul =
|
|||
# 0: Interpreter (slow), 1 (default): JIT (fast)
|
||||
use_shader_jit =
|
||||
|
||||
# Forces VSync on the display thread. Usually doesn't impact performance, but on some drivers it can
|
||||
# so only turn this off if you notice a speed difference.
|
||||
# 0: Off, 1 (default): On
|
||||
use_vsync_new =
|
||||
|
||||
# Resolution scale factor
|
||||
# 0: Auto (scales resolution to window size), 1: Native 3DS screen resolution, Otherwise a scale
|
||||
# factor for the 3DS resolution
|
||||
resolution_factor =
|
||||
|
||||
# Whether to enable V-Sync (caps the framerate at 60FPS) or not.
|
||||
# 0 (default): Off, 1: On
|
||||
vsync_enabled =
|
||||
|
||||
# Turns on the frame limiter, which will limit frames output to the target game speed
|
||||
# 0: Off, 1: On (default)
|
||||
use_frame_limit =
|
||||
|
|
|
@ -20,6 +20,28 @@
|
|||
#include "input_common/motion_emu.h"
|
||||
#include "input_common/sdl/sdl.h"
|
||||
#include "network/network.h"
|
||||
#include "video_core/renderer_base.h"
|
||||
#include "video_core/video_core.h"
|
||||
|
||||
SharedContext_SDL2::SharedContext_SDL2() {
|
||||
window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 0, 0,
|
||||
SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL);
|
||||
context = SDL_GL_CreateContext(window);
|
||||
}
|
||||
|
||||
SharedContext_SDL2::~SharedContext_SDL2() {
|
||||
DoneCurrent();
|
||||
SDL_GL_DeleteContext(context);
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
|
||||
void SharedContext_SDL2::MakeCurrent() {
|
||||
SDL_GL_MakeCurrent(window, context);
|
||||
}
|
||||
|
||||
void SharedContext_SDL2::DoneCurrent() {
|
||||
SDL_GL_MakeCurrent(window, nullptr);
|
||||
}
|
||||
|
||||
void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) {
|
||||
TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0));
|
||||
|
@ -135,6 +157,10 @@ EmuWindow_SDL2::EmuWindow_SDL2(bool fullscreen) {
|
|||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
|
||||
// Enable context sharing for the shared context
|
||||
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
|
||||
// Enable vsync
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
|
||||
std::string window_title = fmt::format("Citra {} | {}-{}", Common::g_build_fullname,
|
||||
Common::g_scm_branch, Common::g_scm_desc);
|
||||
|
@ -150,16 +176,24 @@ EmuWindow_SDL2::EmuWindow_SDL2(bool fullscreen) {
|
|||
exit(1);
|
||||
}
|
||||
|
||||
dummy_window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 0, 0,
|
||||
SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL);
|
||||
|
||||
if (fullscreen) {
|
||||
Fullscreen();
|
||||
}
|
||||
|
||||
gl_context = SDL_GL_CreateContext(render_window);
|
||||
window_context = SDL_GL_CreateContext(render_window);
|
||||
core_context = CreateSharedContext();
|
||||
|
||||
if (gl_context == nullptr) {
|
||||
if (window_context == nullptr) {
|
||||
LOG_CRITICAL(Frontend, "Failed to create SDL2 GL context: {}", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
if (core_context == nullptr) {
|
||||
LOG_CRITICAL(Frontend, "Failed to create shared SDL2 GL context: {}", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
auto gl_load_func = Settings::values.use_gles ? gladLoadGLES2Loader : gladLoadGLLoader;
|
||||
|
||||
|
@ -171,23 +205,31 @@ EmuWindow_SDL2::EmuWindow_SDL2(bool fullscreen) {
|
|||
OnResize();
|
||||
OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
|
||||
SDL_PumpEvents();
|
||||
SDL_GL_SetSwapInterval(Settings::values.vsync_enabled);
|
||||
LOG_INFO(Frontend, "Citra Version: {} | {}-{}", Common::g_build_fullname, Common::g_scm_branch,
|
||||
Common::g_scm_desc);
|
||||
Settings::LogSettings();
|
||||
|
||||
DoneCurrent();
|
||||
}
|
||||
|
||||
EmuWindow_SDL2::~EmuWindow_SDL2() {
|
||||
core_context.reset();
|
||||
Network::Shutdown();
|
||||
InputCommon::Shutdown();
|
||||
SDL_GL_DeleteContext(gl_context);
|
||||
SDL_GL_DeleteContext(window_context);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
void EmuWindow_SDL2::SwapBuffers() {
|
||||
SDL_GL_SwapWindow(render_window);
|
||||
std::unique_ptr<Frontend::GraphicsContext> EmuWindow_SDL2::CreateSharedContext() const {
|
||||
return std::make_unique<SharedContext_SDL2>();
|
||||
}
|
||||
|
||||
void EmuWindow_SDL2::Present() {
|
||||
SDL_GL_MakeCurrent(render_window, window_context);
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
while (IsOpen()) {
|
||||
VideoCore::g_renderer->TryPresent(100);
|
||||
SDL_GL_SwapWindow(render_window);
|
||||
}
|
||||
SDL_GL_MakeCurrent(render_window, nullptr);
|
||||
}
|
||||
|
||||
void EmuWindow_SDL2::PollEvents() {
|
||||
|
@ -256,11 +298,11 @@ void EmuWindow_SDL2::PollEvents() {
|
|||
}
|
||||
|
||||
void EmuWindow_SDL2::MakeCurrent() {
|
||||
SDL_GL_MakeCurrent(render_window, gl_context);
|
||||
core_context->MakeCurrent();
|
||||
}
|
||||
|
||||
void EmuWindow_SDL2::DoneCurrent() {
|
||||
SDL_GL_MakeCurrent(render_window, nullptr);
|
||||
core_context->DoneCurrent();
|
||||
}
|
||||
|
||||
void EmuWindow_SDL2::OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) {
|
||||
|
|
|
@ -10,13 +10,29 @@
|
|||
|
||||
struct SDL_Window;
|
||||
|
||||
class SharedContext_SDL2 : public Frontend::GraphicsContext {
|
||||
public:
|
||||
using SDL_GLContext = void*;
|
||||
|
||||
SharedContext_SDL2();
|
||||
|
||||
~SharedContext_SDL2() override;
|
||||
|
||||
void MakeCurrent() override;
|
||||
|
||||
void DoneCurrent() override;
|
||||
|
||||
private:
|
||||
SDL_GLContext context;
|
||||
SDL_Window* window;
|
||||
};
|
||||
|
||||
class EmuWindow_SDL2 : public Frontend::EmuWindow {
|
||||
public:
|
||||
explicit EmuWindow_SDL2(bool fullscreen);
|
||||
~EmuWindow_SDL2();
|
||||
|
||||
/// Swap buffers to display the next frame
|
||||
void SwapBuffers() override;
|
||||
void Present();
|
||||
|
||||
/// Polls window events
|
||||
void PollEvents() override;
|
||||
|
@ -30,6 +46,9 @@ public:
|
|||
/// Whether the window is still open, and a close request hasn't yet been sent
|
||||
bool IsOpen() const;
|
||||
|
||||
/// Creates a new context that is shared with the current context
|
||||
std::unique_ptr<GraphicsContext> CreateSharedContext() const override;
|
||||
|
||||
private:
|
||||
/// Called by PollEvents when a key is pressed or released.
|
||||
void OnKeyEvent(int key, u8 state);
|
||||
|
@ -67,9 +86,16 @@ private:
|
|||
/// Internal SDL2 render window
|
||||
SDL_Window* render_window;
|
||||
|
||||
/// Fake hidden window for the core context
|
||||
SDL_Window* dummy_window;
|
||||
|
||||
using SDL_GLContext = void*;
|
||||
|
||||
/// The OpenGL context associated with the window
|
||||
SDL_GLContext gl_context;
|
||||
SDL_GLContext window_context;
|
||||
|
||||
/// The OpenGL context associated with the core
|
||||
std::unique_ptr<Frontend::GraphicsContext> core_context;
|
||||
|
||||
/// Keeps track of how often to update the title bar during gameplay
|
||||
u32 last_time = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue