diff options
| author | 2018-07-14 20:18:11 -0700 | |
|---|---|---|
| committer | 2018-07-14 20:18:11 -0700 | |
| commit | 2cb3fdca86192d5dd2f3c988b5d57732c0bee6dc (patch) | |
| tree | 8004356e5a9cbbeb4e37dcad9d47ddfffc5f3210 /src | |
| parent | Merge pull request #663 from Subv/bsd (diff) | |
| parent | OpenGL: Use MakeCurrent/DoneCurrent for multithreaded rendering. (diff) | |
| download | yuzu-2cb3fdca86192d5dd2f3c988b5d57732c0bee6dc.tar.gz yuzu-2cb3fdca86192d5dd2f3c988b5d57732c0bee6dc.tar.xz yuzu-2cb3fdca86192d5dd2f3c988b5d57732c0bee6dc.zip | |
Merge pull request #598 from bunnei/makedonecurrent
OpenGL: Use MakeCurrent/DoneCurrent for multithreaded rendering.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 6 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.cpp | 15 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.h | 7 | ||||
| -rw-r--r-- | src/yuzu/bootmanager.cpp | 5 | ||||
| -rw-r--r-- | src/yuzu/main.cpp | 3 | ||||
| -rw-r--r-- | src/yuzu_cmd/yuzu.cpp | 5 |
6 files changed, 39 insertions, 2 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 1da9e137c..eecbc5ff0 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -15,6 +15,7 @@ | |||
| 15 | #include "common/microprofile.h" | 15 | #include "common/microprofile.h" |
| 16 | #include "common/scope_exit.h" | 16 | #include "common/scope_exit.h" |
| 17 | #include "core/core.h" | 17 | #include "core/core.h" |
| 18 | #include "core/frontend/emu_window.h" | ||
| 18 | #include "core/hle/kernel/process.h" | 19 | #include "core/hle/kernel/process.h" |
| 19 | #include "core/settings.h" | 20 | #include "core/settings.h" |
| 20 | #include "video_core/engines/maxwell_3d.h" | 21 | #include "video_core/engines/maxwell_3d.h" |
| @@ -22,6 +23,7 @@ | |||
| 22 | #include "video_core/renderer_opengl/gl_shader_gen.h" | 23 | #include "video_core/renderer_opengl/gl_shader_gen.h" |
| 23 | #include "video_core/renderer_opengl/maxwell_to_gl.h" | 24 | #include "video_core/renderer_opengl/maxwell_to_gl.h" |
| 24 | #include "video_core/renderer_opengl/renderer_opengl.h" | 25 | #include "video_core/renderer_opengl/renderer_opengl.h" |
| 26 | #include "video_core/video_core.h" | ||
| 25 | 27 | ||
| 26 | using Maxwell = Tegra::Engines::Maxwell3D::Regs; | 28 | using Maxwell = Tegra::Engines::Maxwell3D::Regs; |
| 27 | using PixelFormat = SurfaceParams::PixelFormat; | 29 | using PixelFormat = SurfaceParams::PixelFormat; |
| @@ -398,6 +400,8 @@ void RasterizerOpenGL::Clear() { | |||
| 398 | if (clear_mask == 0) | 400 | if (clear_mask == 0) |
| 399 | return; | 401 | return; |
| 400 | 402 | ||
| 403 | ScopeAcquireGLContext acquire_context; | ||
| 404 | |||
| 401 | auto [dirty_color_surface, dirty_depth_surface] = | 405 | auto [dirty_color_surface, dirty_depth_surface] = |
| 402 | ConfigureFramebuffers(use_color_fb, use_depth_fb); | 406 | ConfigureFramebuffers(use_color_fb, use_depth_fb); |
| 403 | 407 | ||
| @@ -424,6 +428,8 @@ void RasterizerOpenGL::DrawArrays() { | |||
| 424 | MICROPROFILE_SCOPE(OpenGL_Drawing); | 428 | MICROPROFILE_SCOPE(OpenGL_Drawing); |
| 425 | const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs; | 429 | const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs; |
| 426 | 430 | ||
| 431 | ScopeAcquireGLContext acquire_context; | ||
| 432 | |||
| 427 | auto [dirty_color_surface, dirty_depth_surface] = | 433 | auto [dirty_color_surface, dirty_depth_surface] = |
| 428 | ConfigureFramebuffers(true, regs.zeta.Address() != 0); | 434 | ConfigureFramebuffers(true, regs.zeta.Address() != 0); |
| 429 | 435 | ||
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 00841e937..1930fa6ef 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp | |||
| @@ -92,11 +92,24 @@ static std::array<GLfloat, 3 * 2> MakeOrthographicMatrix(const float width, cons | |||
| 92 | return matrix; | 92 | return matrix; |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | ScopeAcquireGLContext::ScopeAcquireGLContext() { | ||
| 96 | if (Settings::values.use_multi_core) { | ||
| 97 | VideoCore::g_emu_window->MakeCurrent(); | ||
| 98 | } | ||
| 99 | } | ||
| 100 | ScopeAcquireGLContext::~ScopeAcquireGLContext() { | ||
| 101 | if (Settings::values.use_multi_core) { | ||
| 102 | VideoCore::g_emu_window->DoneCurrent(); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 95 | RendererOpenGL::RendererOpenGL() = default; | 106 | RendererOpenGL::RendererOpenGL() = default; |
| 96 | RendererOpenGL::~RendererOpenGL() = default; | 107 | RendererOpenGL::~RendererOpenGL() = default; |
| 97 | 108 | ||
| 98 | /// Swap buffers (render frame) | 109 | /// Swap buffers (render frame) |
| 99 | void RendererOpenGL::SwapBuffers(boost::optional<const Tegra::FramebufferConfig&> framebuffer) { | 110 | void RendererOpenGL::SwapBuffers(boost::optional<const Tegra::FramebufferConfig&> framebuffer) { |
| 111 | ScopeAcquireGLContext acquire_context; | ||
| 112 | |||
| 100 | Core::System::GetInstance().perf_stats.EndSystemFrame(); | 113 | Core::System::GetInstance().perf_stats.EndSystemFrame(); |
| 101 | 114 | ||
| 102 | // Maintain the rasterizer's state as a priority | 115 | // Maintain the rasterizer's state as a priority |
| @@ -418,7 +431,7 @@ static void APIENTRY DebugHandler(GLenum source, GLenum type, GLuint id, GLenum | |||
| 418 | 431 | ||
| 419 | /// Initialize the renderer | 432 | /// Initialize the renderer |
| 420 | bool RendererOpenGL::Init() { | 433 | bool RendererOpenGL::Init() { |
| 421 | render_window->MakeCurrent(); | 434 | ScopeAcquireGLContext acquire_context; |
| 422 | 435 | ||
| 423 | if (GLAD_GL_KHR_debug) { | 436 | if (GLAD_GL_KHR_debug) { |
| 424 | glEnable(GL_DEBUG_OUTPUT); | 437 | glEnable(GL_DEBUG_OUTPUT); |
diff --git a/src/video_core/renderer_opengl/renderer_opengl.h b/src/video_core/renderer_opengl/renderer_opengl.h index 21f0d298c..fd0267cf5 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.h +++ b/src/video_core/renderer_opengl/renderer_opengl.h | |||
| @@ -31,6 +31,13 @@ struct ScreenInfo { | |||
| 31 | TextureInfo texture; | 31 | TextureInfo texture; |
| 32 | }; | 32 | }; |
| 33 | 33 | ||
| 34 | /// Helper class to acquire/release OpenGL context within a given scope | ||
| 35 | class ScopeAcquireGLContext : NonCopyable { | ||
| 36 | public: | ||
| 37 | ScopeAcquireGLContext(); | ||
| 38 | ~ScopeAcquireGLContext(); | ||
| 39 | }; | ||
| 40 | |||
| 34 | class RendererOpenGL : public RendererBase { | 41 | class RendererOpenGL : public RendererBase { |
| 35 | public: | 42 | public: |
| 36 | RendererOpenGL(); | 43 | RendererOpenGL(); |
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 833085559..159b2c32b 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp | |||
| @@ -20,7 +20,10 @@ | |||
| 20 | EmuThread::EmuThread(GRenderWindow* render_window) : render_window(render_window) {} | 20 | EmuThread::EmuThread(GRenderWindow* render_window) : render_window(render_window) {} |
| 21 | 21 | ||
| 22 | void EmuThread::run() { | 22 | void EmuThread::run() { |
| 23 | render_window->MakeCurrent(); | 23 | if (!Settings::values.use_multi_core) { |
| 24 | // Single core mode must acquire OpenGL context for entire emulation session | ||
| 25 | render_window->MakeCurrent(); | ||
| 26 | } | ||
| 24 | 27 | ||
| 25 | MicroProfileOnThreadCreate("EmuThread"); | 28 | MicroProfileOnThreadCreate("EmuThread"); |
| 26 | 29 | ||
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 9ce8d7c27..16812e077 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -374,6 +374,8 @@ bool GMainWindow::LoadROM(const QString& filename) { | |||
| 374 | 374 | ||
| 375 | const Core::System::ResultStatus result{system.Load(render_window, filename.toStdString())}; | 375 | const Core::System::ResultStatus result{system.Load(render_window, filename.toStdString())}; |
| 376 | 376 | ||
| 377 | render_window->DoneCurrent(); | ||
| 378 | |||
| 377 | if (result != Core::System::ResultStatus::Success) { | 379 | if (result != Core::System::ResultStatus::Success) { |
| 378 | switch (result) { | 380 | switch (result) { |
| 379 | case Core::System::ResultStatus::ErrorGetLoader: | 381 | case Core::System::ResultStatus::ErrorGetLoader: |
| @@ -916,6 +918,7 @@ int main(int argc, char* argv[]) { | |||
| 916 | QCoreApplication::setApplicationName("yuzu"); | 918 | QCoreApplication::setApplicationName("yuzu"); |
| 917 | 919 | ||
| 918 | QApplication::setAttribute(Qt::AA_X11InitThreads); | 920 | QApplication::setAttribute(Qt::AA_X11InitThreads); |
| 921 | QApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity); | ||
| 919 | QApplication app(argc, argv); | 922 | QApplication app(argc, argv); |
| 920 | 923 | ||
| 921 | // Qt changes the locale and causes issues in float conversion using std::to_string() when | 924 | // Qt changes the locale and causes issues in float conversion using std::to_string() when |
diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index f126bd277..24db1065a 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp | |||
| @@ -148,6 +148,11 @@ int main(int argc, char** argv) { | |||
| 148 | 148 | ||
| 149 | std::unique_ptr<EmuWindow_SDL2> emu_window{std::make_unique<EmuWindow_SDL2>(fullscreen)}; | 149 | std::unique_ptr<EmuWindow_SDL2> emu_window{std::make_unique<EmuWindow_SDL2>(fullscreen)}; |
| 150 | 150 | ||
| 151 | if (!Settings::values.use_multi_core) { | ||
| 152 | // Single core mode must acquire OpenGL context for entire emulation session | ||
| 153 | emu_window->MakeCurrent(); | ||
| 154 | } | ||
| 155 | |||
| 151 | Core::System& system{Core::System::GetInstance()}; | 156 | Core::System& system{Core::System::GetInstance()}; |
| 152 | 157 | ||
| 153 | SCOPE_EXIT({ system.Shutdown(); }); | 158 | SCOPE_EXIT({ system.Shutdown(); }); |