aboutsummaryrefslogtreecommitdiff
path: root/src/qt_common/render/emu_thread.cpp
diff options
context:
space:
mode:
authorcrueter <crueter@eden-emu.dev>2026-05-20 04:49:16 +0200
committercrueter <crueter@eden-emu.dev>2026-05-20 04:49:16 +0200
commitfeb8c5f88eae046c1b76f46e4fa103a844fb0f23 (patch)
tree70f71937a8930c1a5b562f69047e35491d6156b4 /src/qt_common/render/emu_thread.cpp
parent300a646a34b6729879e3fb71d53e625a09683bb2 (diff)
[desktop] More qt_common reorganization (#3916)
Ported from QML branch. Main "big" change is that EmuThread is now a shared state in QtCommon, not individually managed/passed around by GRenderWindow and MainWindow. Signed-off-by: crueter <crueter@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3916 Reviewed-by: Lizzie <lizzie@eden-emu.dev> Reviewed-by: MaranBr <maranbr@eden-emu.dev>
Diffstat (limited to 'src/qt_common/render/emu_thread.cpp')
-rw-r--r--src/qt_common/render/emu_thread.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/qt_common/render/emu_thread.cpp b/src/qt_common/render/emu_thread.cpp
new file mode 100644
index 0000000000..1b65867509
--- /dev/null
+++ b/src/qt_common/render/emu_thread.cpp
@@ -0,0 +1,83 @@
+// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include <qdebug.h>
+#include "core/core.h"
+#include "core/cpu_manager.h"
+#include "emu_thread.h"
+#include "qt_common/qt_common.h"
+#include "video_core/gpu.h"
+#include "video_core/rasterizer_interface.h"
+#include "video_core/renderer_base.h"
+
+EmuThread::EmuThread() {}
+
+EmuThread::~EmuThread() = default;
+
+void EmuThread::run() {
+ Common::SetCurrentThreadName("EmuControlThread");
+
+ auto& gpu = QtCommon::system->GPU();
+ auto stop_token = m_stop_source.get_token();
+
+ QtCommon::system->RegisterHostThread();
+
+ // Main process has been loaded. Make the context current to this thread and begin GPU and CPU
+ // execution.
+ gpu.ObtainContext();
+
+ emit LoadProgress(VideoCore::LoadCallbackStage::Prepare, 0, 0);
+ if (Settings::values.use_disk_shader_cache.GetValue()) {
+ QtCommon::system->Renderer().ReadRasterizer()->LoadDiskResources(
+ QtCommon::system->GetApplicationProcessProgramID(), stop_token,
+ [this](VideoCore::LoadCallbackStage stage, std::size_t value, std::size_t total) {
+ emit LoadProgress(stage, value, total);
+ });
+ }
+ emit LoadProgress(VideoCore::LoadCallbackStage::Complete, 0, 0);
+
+ gpu.ReleaseContext();
+ gpu.Start();
+
+ QtCommon::system->GetCpuManager().OnGpuReady();
+
+ if (QtCommon::system->DebuggerEnabled()) {
+ QtCommon::system->InitializeDebugger();
+ }
+
+ while (!stop_token.stop_requested()) {
+ std::unique_lock lk{m_should_run_mutex};
+ if (m_should_run) {
+ QtCommon::system->Run();
+ m_stopped.Reset();
+
+ m_should_run_cv.wait(lk, stop_token, [&] { return !m_should_run; });
+ } else {
+ QtCommon::system->Pause();
+ m_stopped.Set();
+
+ EmulationPaused(lk);
+ m_should_run_cv.wait(lk, stop_token, [&] { return m_should_run; });
+ EmulationResumed(lk);
+ }
+ }
+
+ // Shutdown the main emulated process
+ QtCommon::system->DetachDebugger();
+ QtCommon::system->ShutdownMainProcess();
+}
+
+// Unlock while emitting signals so that the main thread can
+// continue pumping events.
+
+void EmuThread::EmulationPaused(std::unique_lock<std::mutex>& lk) {
+ lk.unlock();
+ emit DebugModeEntered();
+ lk.lock();
+}
+
+void EmuThread::EmulationResumed(std::unique_lock<std::mutex>& lk) {
+ lk.unlock();
+ emit DebugModeLeft();
+ lk.lock();
+}