summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Rodrigo Locatti2020-04-02 01:38:25 -0300
committerGravatar GitHub2020-04-02 01:38:25 -0300
commit825a6e2615f86742b2e5182af1329da4a2bae413 (patch)
tree0b5d26f82b65067f0562b14a65b0d34aba688e01 /src/core
parentMerge pull request #3591 from ReinUsesLisp/vk-wrapper-part2 (diff)
parentFrontend: Don't call DoneCurrent if the context isnt already current (diff)
downloadyuzu-825a6e2615f86742b2e5182af1329da4a2bae413.tar.gz
yuzu-825a6e2615f86742b2e5182af1329da4a2bae413.tar.xz
yuzu-825a6e2615f86742b2e5182af1329da4a2bae413.zip
Merge pull request #3552 from jroweboy/single-context
Refactor Context management (Fixes renderdoc on opengl issues)
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CMakeLists.txt2
-rw-r--r--src/core/core.cpp22
-rw-r--r--src/core/frontend/emu_window.h44
-rw-r--r--src/core/frontend/scope_acquire_context.cpp18
-rw-r--r--src/core/frontend/scope_acquire_context.h23
5 files changed, 34 insertions, 75 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index e836bf396..66497a386 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -131,8 +131,6 @@ add_library(core STATIC
131 frontend/framebuffer_layout.cpp 131 frontend/framebuffer_layout.cpp
132 frontend/framebuffer_layout.h 132 frontend/framebuffer_layout.h
133 frontend/input.h 133 frontend/input.h
134 frontend/scope_acquire_context.cpp
135 frontend/scope_acquire_context.h
136 gdbstub/gdbstub.cpp 134 gdbstub/gdbstub.cpp
137 gdbstub/gdbstub.h 135 gdbstub/gdbstub.h
138 hardware_interrupt_manager.cpp 136 hardware_interrupt_manager.cpp
diff --git a/src/core/core.cpp b/src/core/core.cpp
index d1bc9340d..3bd90d79f 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -24,7 +24,6 @@
24#include "core/file_sys/sdmc_factory.h" 24#include "core/file_sys/sdmc_factory.h"
25#include "core/file_sys/vfs_concat.h" 25#include "core/file_sys/vfs_concat.h"
26#include "core/file_sys/vfs_real.h" 26#include "core/file_sys/vfs_real.h"
27#include "core/frontend/scope_acquire_context.h"
28#include "core/gdbstub/gdbstub.h" 27#include "core/gdbstub/gdbstub.h"
29#include "core/hardware_interrupt_manager.h" 28#include "core/hardware_interrupt_manager.h"
30#include "core/hle/kernel/client_port.h" 29#include "core/hle/kernel/client_port.h"
@@ -168,13 +167,12 @@ struct System::Impl {
168 Service::Init(service_manager, system); 167 Service::Init(service_manager, system);
169 GDBStub::DeferStart(); 168 GDBStub::DeferStart();
170 169
171 renderer = VideoCore::CreateRenderer(emu_window, system); 170 interrupt_manager = std::make_unique<Core::Hardware::InterruptManager>(system);
172 if (!renderer->Init()) { 171 gpu_core = VideoCore::CreateGPU(emu_window, system);
172 if (!gpu_core) {
173 return ResultStatus::ErrorVideoCore; 173 return ResultStatus::ErrorVideoCore;
174 } 174 }
175 interrupt_manager = std::make_unique<Core::Hardware::InterruptManager>(system); 175 gpu_core->Renderer().Rasterizer().SetupDirtyFlags();
176 gpu_core = VideoCore::CreateGPU(system);
177 renderer->Rasterizer().SetupDirtyFlags();
178 176
179 is_powered_on = true; 177 is_powered_on = true;
180 exit_lock = false; 178 exit_lock = false;
@@ -186,8 +184,6 @@ struct System::Impl {
186 184
187 ResultStatus Load(System& system, Frontend::EmuWindow& emu_window, 185 ResultStatus Load(System& system, Frontend::EmuWindow& emu_window,
188 const std::string& filepath) { 186 const std::string& filepath) {
189 Core::Frontend::ScopeAcquireContext acquire_context{emu_window};
190
191 app_loader = Loader::GetLoader(GetGameFileFromPath(virtual_filesystem, filepath)); 187 app_loader = Loader::GetLoader(GetGameFileFromPath(virtual_filesystem, filepath));
192 if (!app_loader) { 188 if (!app_loader) {
193 LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath); 189 LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath);
@@ -216,10 +212,6 @@ struct System::Impl {
216 AddGlueRegistrationForProcess(*app_loader, *main_process); 212 AddGlueRegistrationForProcess(*app_loader, *main_process);
217 kernel.MakeCurrentProcess(main_process.get()); 213 kernel.MakeCurrentProcess(main_process.get());
218 214
219 // Main process has been loaded and been made current.
220 // Begin GPU and CPU execution.
221 gpu_core->Start();
222
223 // Initialize cheat engine 215 // Initialize cheat engine
224 if (cheat_engine) { 216 if (cheat_engine) {
225 cheat_engine->Initialize(); 217 cheat_engine->Initialize();
@@ -277,7 +269,6 @@ struct System::Impl {
277 } 269 }
278 270
279 // Shutdown emulation session 271 // Shutdown emulation session
280 renderer.reset();
281 GDBStub::Shutdown(); 272 GDBStub::Shutdown();
282 Service::Shutdown(); 273 Service::Shutdown();
283 service_manager.reset(); 274 service_manager.reset();
@@ -353,7 +344,6 @@ struct System::Impl {
353 Service::FileSystem::FileSystemController fs_controller; 344 Service::FileSystem::FileSystemController fs_controller;
354 /// AppLoader used to load the current executing application 345 /// AppLoader used to load the current executing application
355 std::unique_ptr<Loader::AppLoader> app_loader; 346 std::unique_ptr<Loader::AppLoader> app_loader;
356 std::unique_ptr<VideoCore::RendererBase> renderer;
357 std::unique_ptr<Tegra::GPU> gpu_core; 347 std::unique_ptr<Tegra::GPU> gpu_core;
358 std::unique_ptr<Hardware::InterruptManager> interrupt_manager; 348 std::unique_ptr<Hardware::InterruptManager> interrupt_manager;
359 Memory::Memory memory; 349 Memory::Memory memory;
@@ -536,11 +526,11 @@ const Core::Hardware::InterruptManager& System::InterruptManager() const {
536} 526}
537 527
538VideoCore::RendererBase& System::Renderer() { 528VideoCore::RendererBase& System::Renderer() {
539 return *impl->renderer; 529 return impl->gpu_core->Renderer();
540} 530}
541 531
542const VideoCore::RendererBase& System::Renderer() const { 532const VideoCore::RendererBase& System::Renderer() const {
543 return *impl->renderer; 533 return impl->gpu_core->Renderer();
544} 534}
545 535
546Kernel::KernelCore& System::Kernel() { 536Kernel::KernelCore& System::Kernel() {
diff --git a/src/core/frontend/emu_window.h b/src/core/frontend/emu_window.h
index 5eb87fb63..72294d4d8 100644
--- a/src/core/frontend/emu_window.h
+++ b/src/core/frontend/emu_window.h
@@ -13,19 +13,39 @@
13namespace Core::Frontend { 13namespace Core::Frontend {
14 14
15/** 15/**
16 * Represents a graphics context that can be used for background computation or drawing. If the 16 * Represents a drawing context that supports graphics operations.
17 * graphics backend doesn't require the context, then the implementation of these methods can be
18 * stubs
19 */ 17 */
20class GraphicsContext { 18class GraphicsContext {
21public: 19public:
22 virtual ~GraphicsContext(); 20 virtual ~GraphicsContext();
23 21
22 /// Inform the driver to swap the front/back buffers and present the current image
23 virtual void SwapBuffers() {}
24
24 /// Makes the graphics context current for the caller thread 25 /// Makes the graphics context current for the caller thread
25 virtual void MakeCurrent() = 0; 26 virtual void MakeCurrent() {}
26 27
27 /// Releases (dunno if this is the "right" word) the context from the caller thread 28 /// Releases (dunno if this is the "right" word) the context from the caller thread
28 virtual void DoneCurrent() = 0; 29 virtual void DoneCurrent() {}
30
31 class Scoped {
32 public:
33 explicit Scoped(GraphicsContext& context_) : context(context_) {
34 context.MakeCurrent();
35 }
36 ~Scoped() {
37 context.DoneCurrent();
38 }
39
40 private:
41 GraphicsContext& context;
42 };
43
44 /// Calls MakeCurrent on the context and calls DoneCurrent when the scope for the returned value
45 /// ends
46 Scoped Acquire() {
47 return Scoped{*this};
48 }
29}; 49};
30 50
31/** 51/**
@@ -46,7 +66,7 @@ public:
46 * - DO NOT TREAT THIS CLASS AS A GUI TOOLKIT ABSTRACTION LAYER. That's not what it is. Please 66 * - DO NOT TREAT THIS CLASS AS A GUI TOOLKIT ABSTRACTION LAYER. That's not what it is. Please
47 * re-read the upper points again and think about it if you don't see this. 67 * re-read the upper points again and think about it if you don't see this.
48 */ 68 */
49class EmuWindow : public GraphicsContext { 69class EmuWindow {
50public: 70public:
51 /// Data structure to store emuwindow configuration 71 /// Data structure to store emuwindow configuration
52 struct WindowConfig { 72 struct WindowConfig {
@@ -60,17 +80,9 @@ public:
60 virtual void PollEvents() = 0; 80 virtual void PollEvents() = 0;
61 81
62 /** 82 /**
63 * Returns a GraphicsContext that the frontend provides that is shared with the emu window. This 83 * Returns a GraphicsContext that the frontend provides to be used for rendering.
64 * context can be used from other threads for background graphics computation. If the frontend
65 * is using a graphics backend that doesn't need anything specific to run on a different thread,
66 * then it can use a stubbed implemenation for GraphicsContext.
67 *
68 * If the return value is null, then the core should assume that the frontend cannot provide a
69 * Shared Context
70 */ 84 */
71 virtual std::unique_ptr<GraphicsContext> CreateSharedContext() const { 85 virtual std::unique_ptr<GraphicsContext> CreateSharedContext() const = 0;
72 return nullptr;
73 }
74 86
75 /// Returns if window is shown (not minimized) 87 /// Returns if window is shown (not minimized)
76 virtual bool IsShown() const = 0; 88 virtual bool IsShown() const = 0;
diff --git a/src/core/frontend/scope_acquire_context.cpp b/src/core/frontend/scope_acquire_context.cpp
deleted file mode 100644
index 878c3157c..000000000
--- a/src/core/frontend/scope_acquire_context.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
1// Copyright 2019 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "core/frontend/emu_window.h"
6#include "core/frontend/scope_acquire_context.h"
7
8namespace Core::Frontend {
9
10ScopeAcquireContext::ScopeAcquireContext(Core::Frontend::GraphicsContext& context)
11 : context{context} {
12 context.MakeCurrent();
13}
14ScopeAcquireContext::~ScopeAcquireContext() {
15 context.DoneCurrent();
16}
17
18} // namespace Core::Frontend
diff --git a/src/core/frontend/scope_acquire_context.h b/src/core/frontend/scope_acquire_context.h
deleted file mode 100644
index 7a65c0623..000000000
--- a/src/core/frontend/scope_acquire_context.h
+++ /dev/null
@@ -1,23 +0,0 @@
1// Copyright 2019 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/common_types.h"
8
9namespace Core::Frontend {
10
11class GraphicsContext;
12
13/// Helper class to acquire/release window context within a given scope
14class ScopeAcquireContext : NonCopyable {
15public:
16 explicit ScopeAcquireContext(Core::Frontend::GraphicsContext& context);
17 ~ScopeAcquireContext();
18
19private:
20 Core::Frontend::GraphicsContext& context;
21};
22
23} // namespace Core::Frontend