VERY experimental Nintendo Switch 2 emulator
C++
Add cmake option to enable microprofile (#179)
Gamer641f34d836b4fb
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 0c2a880ae0..f775cdf87b 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -86,6 +86,8 @@ option(ENABLE_CUBEB "Enables the cubeb audio backend" ON)option(USE_DISCORD_PRESENCE "Enables Discord Rich Presence" OFF)+option(ENABLE_MICROPROFILE "Enables microprofile capabilities" OFF)+option(YUZU_TESTS "Compile tests" "${BUILD_TESTING}")if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txtindex cd7b80a33c..c15bd6eefc 100644--- a/externals/CMakeLists.txt+++ b/externals/CMakeLists.txt@@ -1,3 +1,6 @@+# SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project+# SPDX-License-Identifier: GPL-3.0-or-later+# SPDX-FileCopyrightText: 2016 Citra Emulator Project# SPDX-License-Identifier: GPL-2.0-or-later@@ -51,6 +54,11 @@ endif()# MicroProfileadd_library(microprofile INTERFACE)target_include_directories(microprofile INTERFACE ./microprofile)+if (ENABLE_MICROPROFILE)+ target_compile_definitions(microprofile INTERFACE MICROPROFILE_ENABLED=1)+else()+ target_compile_definitions(microprofile INTERFACE MICROPROFILE_ENABLED=0)+endif()# GCC bugsif (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "12" AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND MINGW)diff --git a/src/core/core.cpp b/src/core/core.cppindex ae184f8a88..8aef26d93f 100644--- a/src/core/core.cpp+++ b/src/core/core.cpp@@ -289,10 +289,12 @@ struct System::Impl {exit_locked = false;exit_requested = false;+#if MICROPROFILE_ENABLEDmicroprofile_cpu[0] = MICROPROFILE_TOKEN(ARM_CPU0);microprofile_cpu[1] = MICROPROFILE_TOKEN(ARM_CPU1);microprofile_cpu[2] = MICROPROFILE_TOKEN(ARM_CPU2);microprofile_cpu[3] = MICROPROFILE_TOKEN(ARM_CPU3);+#endifif (Settings::values.enable_renderdoc_hotkey) {renderdoc_api = std::make_unique<Tools::RenderdocAPI>();@@ -573,7 +575,9 @@ struct System::Impl {std::stop_source stop_event;std::array<u64, Core::Hardware::NUM_CPU_CORES> dynarmic_ticks{};+#if MICROPROFILE_ENABLEDstd::array<MicroProfileToken, Core::Hardware::NUM_CPU_CORES> microprofile_cpu{};+#endifstd::array<Core::GPUDirtyMemoryManager, Core::Hardware::NUM_CPU_CORES>gpu_dirty_memory_managers;@@ -952,6 +956,7 @@ void System::RegisterHostThread() {impl->kernel.RegisterHostThread();}+#if MICROPROFILE_ENABLEDvoid System::EnterCPUProfile() {std::size_t core = impl->kernel.GetCurrentHostThreadID();impl->dynarmic_ticks[core] = MicroProfileEnter(impl->microprofile_cpu[core]);@@ -961,6 +966,7 @@ void System::ExitCPUProfile() {std::size_t core = impl->kernel.GetCurrentHostThreadID();MicroProfileLeave(impl->microprofile_cpu[core], impl->dynarmic_ticks[core]);}+#endifbool System::IsMulticore() const {return impl->is_multicore;diff --git a/src/core/core.h b/src/core/core.hindex b33cb0c4f7..3f1a3f0388 100644--- a/src/core/core.h+++ b/src/core/core.h@@ -396,11 +396,13 @@ public:/// Register a host thread as an auxiliary thread.void RegisterHostThread();+#if MICROPROFILE_ENABLED/// Enter CPU Microprofilevoid EnterCPUProfile();/// Exit CPU Microprofilevoid ExitCPUProfile();+#endif/// Tells if system is running on multicore.[[nodiscard]] bool IsMulticore() const;diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cppindex ed07e80ce2..646f12708e 100644--- a/src/core/core_timing.cpp+++ b/src/core/core_timing.cpp@@ -61,7 +61,9 @@ void CoreTiming::ThreadEntry(CoreTiming& instance) {Common::SetCurrentThreadPriority(Common::ThreadPriority::High);instance.on_thread_init();instance.ThreadLoop();+#if MICROPROFILE_ENABLEDMicroProfileOnThreadExit();+#endif}void CoreTiming::Initialize(std::function<void()>&& on_thread_init_) {diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cppindex 9b1c773877..1b838eea59 100644--- a/src/core/cpu_manager.cpp+++ b/src/core/cpu_manager.cpp@@ -201,7 +201,9 @@ void CpuManager::RunThread(std::stop_token token, std::size_t core) {// CleanupSCOPE_EXIT {data.host_context->Exit();+#if MICROPROFILE_ENABLEDMicroProfileOnThreadExit();+#endif};// Runningdiff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cppindex 9e5eaeec43..7a851e9b02 100644--- a/src/core/hle/kernel/kernel.cpp+++ b/src/core/hle/kernel/kernel.cpp@@ -1278,6 +1278,7 @@ void KernelCore::ExceptionalExitApplication() {SuspendEmulation(true);}+#if MICROPROFILE_ENABLEDvoid KernelCore::EnterSVCProfile() {impl->svc_ticks[CurrentPhysicalCoreIndex()] = MicroProfileEnter(MICROPROFILE_TOKEN(Kernel_SVC));}@@ -1285,6 +1286,7 @@ void KernelCore::EnterSVCProfile() {void KernelCore::ExitSVCProfile() {MicroProfileLeave(MICROPROFILE_TOKEN(Kernel_SVC), impl->svc_ticks[CurrentPhysicalCoreIndex()]);}+#endifInit::KSlabResourceCounts& KernelCore::SlabResourceCounts() {return impl->slab_resource_counts;diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.hindex 57182c0c8d..e11241d6aa 100644--- a/src/core/hle/kernel/kernel.h+++ b/src/core/hle/kernel/kernel.h@@ -271,9 +271,11 @@ public:bool IsShuttingDown() const;+#if MICROPROFILE_ENABLEDvoid EnterSVCProfile();void ExitSVCProfile();+#endif/// Workaround for single-core mode when preempting threads while idle.bool IsPhantomModeForSingleCore() const;diff --git a/src/core/hle/kernel/physical_core.cpp b/src/core/hle/kernel/physical_core.cppindex 0f45a32494..3321032563 100644--- a/src/core/hle/kernel/physical_core.cpp+++ b/src/core/hle/kernel/physical_core.cpp@@ -27,7 +27,9 @@ void PhysicalCore::RunThread(Kernel::KThread* thread) {interface->Initialize();const auto EnterContext = [&]() {+#if MICROPROFILE_ENABLEDsystem.EnterCPUProfile();+#endif// Lock the core context.std::scoped_lock lk{m_guard};@@ -59,7 +61,9 @@ void PhysicalCore::RunThread(Kernel::KThread* thread) {m_arm_interface = nullptr;m_current_thread = nullptr;+#if MICROPROFILE_ENABLEDsystem.ExitCPUProfile();+#endif};while (true) {diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cppindex c55dc0c8ad..b1ce1e9daa 100644--- a/src/core/hle/kernel/svc.cpp+++ b/src/core/hle/kernel/svc.cpp@@ -4428,7 +4428,9 @@ void Call(Core::System& system, u32 imm) {std::array<uint64_t, 8> args;kernel.CurrentPhysicalCore().SaveSvcArguments(process, args);+#if MICROPROFILE_ENABLEDkernel.EnterSVCProfile();+#endifif (process.Is64Bit()) {Call64(system, imm, args);@@ -4436,7 +4438,9 @@ void Call(Core::System& system, u32 imm) {Call32(system, imm, args);}+#if MICROPROFILE_ENABLEDkernel.ExitSVCProfile();+#endifkernel.CurrentPhysicalCore().LoadSvcArguments(process, args);}diff --git a/src/video_core/fence_manager.h b/src/video_core/fence_manager.hindex dd67bc6d9b..322dfe832b 100644--- a/src/video_core/fence_manager.h+++ b/src/video_core/fence_manager.h@@ -219,9 +219,11 @@ private:MicroProfileOnThreadCreate(name.c_str());// Cleanup+#if MICROPROFILE_ENABLEDSCOPE_EXIT {MicroProfileOnThreadExit();};+#endifCommon::SetCurrentThreadName(name.c_str());Common::SetCurrentThreadPriority(Common::ThreadPriority::High);diff --git a/src/video_core/gpu_thread.cpp b/src/video_core/gpu_thread.cppindex e2bfdcd7fd..2b4bce4f8d 100644--- a/src/video_core/gpu_thread.cpp+++ b/src/video_core/gpu_thread.cpp@@ -23,9 +23,11 @@ static void RunThread(std::stop_token stop_token, Core::System& system,Tegra::Control::Scheduler& scheduler, SynchState& state) {std::string name = "GPU";MicroProfileOnThreadCreate(name.c_str());+#if MICROPROFILE_ENABLEDSCOPE_EXIT {MicroProfileOnThreadExit();};+#endifCommon::SetCurrentThreadName(name.c_str());Common::SetCurrentThreadPriority(Common::ThreadPriority::Critical);diff --git a/src/yuzu/debugger/profiler.cpp b/src/yuzu/debugger/profiler.cppindex 493ee0b178..55d4298fa6 100644--- a/src/yuzu/debugger/profiler.cpp+++ b/src/yuzu/debugger/profiler.cpp@@ -1,6 +1,11 @@+// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project+// SPDX-License-Identifier: GPL-3.0-or-later+// SPDX-FileCopyrightText: 2015 Citra Emulator Project// SPDX-License-Identifier: GPL-2.0-or-later+#if MICROPROFILE_ENABLED+#include <QAction>#include <QLayout>#include <QMouseEvent>@@ -14,7 +19,7 @@// Include the implementation of the UI in this file. This isn't in microprofile.cpp because the// non-Qt frontends don't need it (and don't implement the UI drawing hooks either).-#if MICROPROFILE_ENABLED+#define MICROPROFILEUI_IMPL 1#include "common/microprofileui.h"@@ -43,8 +48,6 @@ private:qreal x_scale = 1.0, y_scale = 1.0;};-#endif-MicroProfileDialog::MicroProfileDialog(QWidget* parent) : QWidget(parent, Qt::Dialog) {setObjectName(QStringLiteral("MicroProfile"));setWindowTitle(tr("&MicroProfile"));@@ -52,8 +55,6 @@ MicroProfileDialog::MicroProfileDialog(QWidget* parent) : QWidget(parent, Qt::Di// Enable the maximize buttonsetWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint);-#if MICROPROFILE_ENABLED-MicroProfileWidget* widget = new MicroProfileWidget(this);QLayout* layout = new QVBoxLayout(this);@@ -66,7 +67,6 @@ MicroProfileDialog::MicroProfileDialog(QWidget* parent) : QWidget(parent, Qt::DisetFocusProxy(widget);widget->setFocusPolicy(Qt::StrongFocus);widget->setFocus();-#endif}QAction* MicroProfileDialog::toggleViewAction() {@@ -94,8 +94,6 @@ void MicroProfileDialog::hideEvent(QHideEvent* ev) {QWidget::hideEvent(ev);}-#if MICROPROFILE_ENABLED-/// There's no way to pass a user pointer to MicroProfile, so this variable is used to make the/// QPainter available inside the drawing callbacks.static QPainter* mp_painter = nullptr;diff --git a/src/yuzu/debugger/profiler.h b/src/yuzu/debugger/profiler.hindex 4c8ccd3c2f..caf81bdd9b 100644--- a/src/yuzu/debugger/profiler.h+++ b/src/yuzu/debugger/profiler.h@@ -1,8 +1,13 @@+// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project+// SPDX-License-Identifier: GPL-3.0-or-later+// SPDX-FileCopyrightText: 2015 Citra Emulator Project// SPDX-License-Identifier: GPL-2.0-or-later#pragma once+#if MICROPROFILE_ENABLED+#include <QWidget>class QAction;@@ -25,3 +30,4 @@ protected:private:QAction* toggle_view_action = nullptr;};+#endifdiff --git a/src/yuzu/main.cpp b/src/yuzu/main.cppindex 9b35069307..a46c5cd881 100644--- a/src/yuzu/main.cpp+++ b/src/yuzu/main.cpp@@ -1348,6 +1348,11 @@ void GMainWindow::InitializeDebugWidgets() {microProfileDialog = new MicroProfileDialog(this);microProfileDialog->hide();debug_menu->addAction(microProfileDialog->toggleViewAction());+#else+ auto micro_profile_stub = new QAction(tr("MicroProfile (unavailable)"), this);+ micro_profile_stub->setEnabled(false);+ micro_profile_stub->setChecked(false);+ debug_menu->addAction(micro_profile_stub);#endifwaitTreeWidget = new WaitTreeWidget(*system, this);@@ -5630,10 +5635,13 @@ int main(int argc, char* argv[]) {#endifCommon::DetachedTasks detached_tasks;++#if MICROPROFILE_ENABLEDMicroProfileOnThreadCreate("Frontend");SCOPE_EXIT {MicroProfileShutdown();};+#endifCommon::ConfigureNvidiaEnvironmentFlags();diff --git a/src/yuzu/main.h b/src/yuzu/main.hindex 7e7c00ec0b..b6f818099a 100644--- a/src/yuzu/main.h+++ b/src/yuzu/main.h@@ -43,7 +43,9 @@ class GameList;class GImageInfo;class GRenderWindow;class LoadingScreen;+#if MICROPROFILE_ENABLEDclass MicroProfileDialog;+#endifclass OverlayDialog;class ProfilerWidget;class ControllerDialog;@@ -565,7 +567,9 @@ private:// Debugger panesProfilerWidget* profilerWidget;+#if MICROPROFILE_ENABLEDMicroProfileDialog* microProfileDialog;+#endifWaitTreeWidget* waitTreeWidget;ControllerDialog* controller_dialog;diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cppindex 9bf88c5d9f..6acf7c0ace 100644--- a/src/yuzu_cmd/yuzu.cpp+++ b/src/yuzu_cmd/yuzu.cpp@@ -4,9 +4,6 @@// SPDX-FileCopyrightText: 2014 Citra Emulator Project// SPDX-License-Identifier: GPL-2.0-or-later-// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project-// SPDX-License-Identifier: GPL-3.0-or-later-#include <chrono>#include <iostream>#include <memory>@@ -338,10 +335,12 @@ int main(int argc, char** argv) {LocalFree(argv_w);#endif+#if MICROPROFILE_ENABLEDMicroProfileOnThreadCreate("EmuThread");SCOPE_EXIT {MicroProfileShutdown();};+#endifCommon::ConfigureNvidiaEnvironmentFlags();