From fc6879674ec01c60fc963380888f9d09bcbb4515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 2 Aug 2023 13:02:44 +0200 Subject: [PATCH] Refactor overlays into an enum --- Core/Config.cpp | 5 --- Core/Config.h | 5 +-- Core/ConfigValues.h | 13 +++++++ Core/HLE/sceDisplay.cpp | 6 +-- Core/HW/Display.cpp | 2 +- GPU/Common/TextureCacheCommon.cpp | 2 +- UI/DevScreens.cpp | 63 ++++++++++++++++--------------- UI/DevScreens.h | 4 +- UI/EmuScreen.cpp | 51 +++++++++++++------------ UI/GameSettingsScreen.cpp | 7 ++-- UI/NativeApp.cpp | 2 +- Windows/MainWindowMenu.cpp | 10 ++++- headless/Headless.cpp | 2 +- 13 files changed, 95 insertions(+), 77 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index cfd4c6aa85..fcff184572 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -848,13 +848,10 @@ static const ConfigSetting debuggerSettings[] = { ConfigSetting("DisplayStatusBar", &g_Config.bDisplayStatusBar, true, CfgFlag::DEFAULT), ConfigSetting("ShowBottomTabTitles",&g_Config.bShowBottomTabTitles, true, CfgFlag::DEFAULT), ConfigSetting("ShowDeveloperMenu", &g_Config.bShowDeveloperMenu, false, CfgFlag::DEFAULT), - ConfigSetting("ShowAllocatorDebug", &g_Config.bShowAllocatorDebug, false, CfgFlag::DONT_SAVE), - ConfigSetting("ShowGpuProfile", &g_Config.bShowGpuProfile, false, CfgFlag::DONT_SAVE), ConfigSetting("SkipDeadbeefFilling", &g_Config.bSkipDeadbeefFilling, false, CfgFlag::DEFAULT), ConfigSetting("FuncHashMap", &g_Config.bFuncHashMap, false, CfgFlag::DEFAULT), ConfigSetting("SkipFuncHashMap", &g_Config.sSkipFuncHashMap, "", CfgFlag::DEFAULT), ConfigSetting("MemInfoDetailed", &g_Config.bDebugMemInfoDetailed, false, CfgFlag::DEFAULT), - ConfigSetting("DrawFrameGraph", &g_Config.bDrawFrameGraph, false, CfgFlag::DEFAULT), }; static const ConfigSetting jitSettings[] = { @@ -1060,8 +1057,6 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { INFO_LOG(LOADER, "Loading config: %s", iniFilename_.c_str()); bSaveSettings = true; - bShowFrameProfiler = true; - IniFile iniFile; if (!iniFile.Load(iniFilename_)) { ERROR_LOG(LOADER, "Failed to read '%s'. Setting config to default.", iniFilename_.c_str()); diff --git a/Core/Config.h b/Core/Config.h index 2c45283c25..ed1a7af88e 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -465,16 +465,15 @@ public: bool bDisplayStatusBar; bool bShowBottomTabTitles; bool bShowDeveloperMenu; - bool bShowAllocatorDebug; // Double edged sword: much easier debugging, but not accurate. bool bSkipDeadbeefFilling; bool bFuncHashMap; std::string sSkipFuncHashMap; bool bDebugMemInfoDetailed; - bool bDrawFrameGraph; // Volatile development settings - bool bShowFrameProfiler; + // Overlays + DebugOverlay iDebugOverlay; bool bGpuLogProfiler; // Controls the Vulkan logging profiler (profiles textures uploads etc). // Retro Achievement settings diff --git a/Core/ConfigValues.h b/Core/ConfigValues.h index 083c3f83d8..78d980273a 100644 --- a/Core/ConfigValues.h +++ b/Core/ConfigValues.h @@ -175,3 +175,16 @@ enum class ScreenEdgePosition { CENTER_RIGHT = 7, VALUE_COUNT, }; + +enum class DebugOverlay : int { + OFF, + DEBUG_STATS, + FRAME_GRAPH, +#ifdef USE_PROFILER + FRAME_PROFILE, +#endif + CONTROL, + AUDIO, + GPU_PROFILE, + GPU_ALLOCATOR, +}; diff --git a/Core/HLE/sceDisplay.cpp b/Core/HLE/sceDisplay.cpp index 70fbc0796f..7e50d991ef 100644 --- a/Core/HLE/sceDisplay.cpp +++ b/Core/HLE/sceDisplay.cpp @@ -496,7 +496,7 @@ static void DoFrameIdleTiming() { #endif } - if (g_Config.bDrawFrameGraph || coreCollectDebugStats) { + if (g_Config.iDebugOverlay == DebugOverlay::FRAME_GRAPH || coreCollectDebugStats) { DisplayNotifySleep(time_now_d() - before); } } @@ -662,7 +662,7 @@ void __DisplayFlip(int cyclesLate) { CoreTiming::ScheduleEvent(0 - cyclesLate, afterFlipEvent, 0); numVBlanksSinceFlip = 0; - if (g_Config.bDrawFrameGraph || coreCollectDebugStats) { + if (g_Config.iDebugOverlay == DebugOverlay::FRAME_GRAPH || coreCollectDebugStats) { // Track how long we sleep (whether vsync or sleep_ms.) DisplayNotifySleep(time_now_d() - frameSleepStart, frameSleepPos); } @@ -726,7 +726,7 @@ void hleLagSync(u64 userdata, int cyclesLate) { const int over = (int)((now - goal) * 1000000); ScheduleLagSync(over - emuOver); - if (g_Config.bDrawFrameGraph || coreCollectDebugStats) { + if (g_Config.iDebugOverlay == DebugOverlay::FRAME_GRAPH || coreCollectDebugStats) { DisplayNotifySleep(now - before); } } diff --git a/Core/HW/Display.cpp b/Core/HW/Display.cpp index acead8d785..4738affd72 100644 --- a/Core/HW/Display.cpp +++ b/Core/HW/Display.cpp @@ -92,7 +92,7 @@ static void CalculateFPS() { } } - if (g_Config.bDrawFrameGraph || coreCollectDebugStats) { + if (g_Config.iDebugOverlay == DebugOverlay::FRAME_GRAPH || coreCollectDebugStats) { frameTimeHistory[frameTimeHistoryPos++] = now - lastFrameTimeHistory; lastFrameTimeHistory = now; frameTimeHistoryPos = frameTimeHistoryPos % frameTimeHistorySize; diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index bf05e7a02e..ebc642cd4d 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -142,7 +142,7 @@ void TextureCacheCommon::StartFrame() { timesInvalidatedAllThisFrame_ = 0; replacementTimeThisFrame_ = 0.0; - if (g_Config.bShowDebugStats) { + if (g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS) { gpuStats.numReplacerTrackedTex = replacer_.GetNumTrackedTextures(); gpuStats.numCachedReplacedTextures = replacer_.GetNumCachedReplacedTextures(); } diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index edcb26af20..c04cc855ea 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -88,6 +88,29 @@ static const char *logLevelList[] = { "Verb." }; +static const char *g_debugOverlayList[] = { + "Off", + "Debug stats", + "Draw Frametimes Graph", +#ifdef USE_PROFILER + "Frame profile", +#endif + "Toggle Control Debug", + "Toggle Audio Debug", + "GPU Profile", + "GPU Allocator Viewer", +}; + +void AddOverlayList(UI::ViewGroup *items, ScreenManager *screenManager) { + using namespace UI; + auto dev = GetI18NCategory(I18NCat::DEVELOPER); + int numOverlays = ARRAY_SIZE(g_debugOverlayList); + if (!(g_Config.iGPUBackend == (int)GPUBackend::VULKAN || g_Config.iGPUBackend == (int)GPUBackend::OPENGL)) { + numOverlays -= 2; // skip the last 2. + } + items->Add(new PopupMultiChoice((int *)&g_Config.iDebugOverlay, dev->T("Debug overlay"), g_debugOverlayList, 0, numOverlays, I18NCat::DEVELOPER, screenManager)); +} + void DevMenuScreen::CreatePopupContents(UI::ViewGroup *parent) { using namespace UI; auto dev = GetI18NCategory(I18NCat::DEVELOPER); @@ -103,27 +126,21 @@ void DevMenuScreen::CreatePopupContents(UI::ViewGroup *parent) { items->Add(new Choice(sy->T("Developer Tools")))->OnClick.Handle(this, &DevMenuScreen::OnDeveloperTools); items->Add(new Choice(dev->T("Jit Compare")))->OnClick.Handle(this, &DevMenuScreen::OnJitCompare); items->Add(new Choice(dev->T("Shader Viewer")))->OnClick.Handle(this, &DevMenuScreen::OnShaderView); - if (g_Config.iGPUBackend == (int)GPUBackend::VULKAN || g_Config.iGPUBackend == (int)GPUBackend::OPENGL) { - items->Add(new CheckBox(&g_Config.bShowAllocatorDebug, dev->T("GPU Allocator Viewer"))); - } - if (g_Config.iGPUBackend == (int)GPUBackend::VULKAN || g_Config.iGPUBackend == (int)GPUBackend::OPENGL) { - items->Add(new CheckBox(&g_Config.bShowGpuProfile, dev->T("GPU Profile"))); - } - items->Add(new Choice(dev->T("Toggle Freeze")))->OnClick.Handle(this, &DevMenuScreen::OnFreezeFrame); - items->Add(new Choice(dev->T("Dump next frame to log")))->OnClick.Handle(this, &DevMenuScreen::OnDumpFrame); - items->Add(new Choice(dev->T("Toggle Audio Debug")))->OnClick.Add([](UI::EventParams &) { - g_Config.bShowAudioDebug = !g_Config.bShowAudioDebug; + AddOverlayList(items, screenManager()); + items->Add(new Choice(dev->T("Toggle Freeze")))->OnClick.Add([](UI::EventParams &e) { + if (PSP_CoreParameter().frozen) { + PSP_CoreParameter().frozen = false; + } else { + PSP_CoreParameter().freezeNext = true; + } return UI::EVENT_DONE; }); - items->Add(new Choice(dev->T("Toggle Control Debug")))->OnClick.Add([](UI::EventParams &) { - g_Config.bShowControlDebug = !g_Config.bShowControlDebug; + + items->Add(new Choice(dev->T("Dump next frame to log")))->OnClick.Add([](UI::EventParams &e) { + gpu->DumpNextFrame(); return UI::EVENT_DONE; }); -#ifdef USE_PROFILER - items->Add(new CheckBox(&g_Config.bShowFrameProfiler, dev->T("Frame Profiler"), "")); -#endif - items->Add(new CheckBox(&g_Config.bDrawFrameGraph, dev->T("Draw Frametimes Graph"))); items->Add(new Choice(dev->T("Reset limited logging")))->OnClick.Handle(this, &DevMenuScreen::OnResetLimitedLogging); scroll->Add(items); @@ -171,20 +188,6 @@ UI::EventReturn DevMenuScreen::OnShaderView(UI::EventParams &e) { return UI::EVENT_DONE; } -UI::EventReturn DevMenuScreen::OnFreezeFrame(UI::EventParams &e) { - if (PSP_CoreParameter().frozen) { - PSP_CoreParameter().frozen = false; - } else { - PSP_CoreParameter().freezeNext = true; - } - return UI::EVENT_DONE; -} - -UI::EventReturn DevMenuScreen::OnDumpFrame(UI::EventParams &e) { - gpu->DumpNextFrame(); - return UI::EVENT_DONE; -} - void DevMenuScreen::dialogFinished(const Screen *dialog, DialogResult result) { UpdateUIState(UISTATE_INGAME); // Close when a subscreen got closed. diff --git a/UI/DevScreens.h b/UI/DevScreens.h index fdf2964574..d000bfb594 100644 --- a/UI/DevScreens.h +++ b/UI/DevScreens.h @@ -42,8 +42,6 @@ protected: UI::EventReturn OnLogConfig(UI::EventParams &e); UI::EventReturn OnJitCompare(UI::EventParams &e); UI::EventReturn OnShaderView(UI::EventParams &e); - UI::EventReturn OnFreezeFrame(UI::EventParams &e); - UI::EventReturn OnDumpFrame(UI::EventParams &e); UI::EventReturn OnDeveloperTools(UI::EventParams &e); UI::EventReturn OnResetLimitedLogging(UI::EventParams &e); @@ -226,3 +224,5 @@ private: void DrawProfile(UIContext &ui); const char *GetCompilerABI(); + +void AddOverlayList(UI::ViewGroup *items, ScreenManager *screenManager); diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 46d59e5038..09430cac3d 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -1515,7 +1515,7 @@ void EmuScreen::render() { } } - Core_UpdateDebugStats(g_Config.bShowDebugStats || g_Config.bLogFrameDrops); + Core_UpdateDebugStats(g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS || g_Config.bLogFrameDrops); bool blockedExecution = Achievements::IsBlockingExecution(); if (!blockedExecution) { @@ -1591,7 +1591,7 @@ bool EmuScreen::hasVisibleUI() { if (g_Config.bEnableCardboardVR || g_Config.bEnableNetworkChat) return true; // Debug UI. - if (g_Config.bShowDebugStats || g_Config.bShowDeveloperMenu || g_Config.bShowAudioDebug || g_Config.bShowFrameProfiler || g_Config.bShowControlDebug) + if (g_Config.iDebugOverlay != DebugOverlay::OFF) return true; // Exception information. @@ -1626,38 +1626,39 @@ void EmuScreen::renderUI() { } if (!invalid_) { - if (g_Config.bShowDebugStats) { + switch (g_Config.iDebugOverlay) { + case DebugOverlay::DEBUG_STATS: DrawDebugStats(ctx, ctx->GetLayoutBounds()); - } - - if (g_Config.bShowAudioDebug) { + break; + case DebugOverlay::FRAME_GRAPH: + DrawFrameTimes(ctx, ctx->GetLayoutBounds()); + break; + case DebugOverlay::AUDIO: DrawAudioDebugStats(ctx, ctx->GetLayoutBounds()); + break; + case DebugOverlay::CONTROL: + DrawControlDebug(ctx, controlMapper_, ctx->GetLayoutBounds()); + break; +#if !PPSSPP_PLATFORM(UWP) && !PPSSPP_PLATFORM(SWITCH) + + case DebugOverlay::GPU_PROFILE: + if (g_Config.iGPUBackend == (int)GPUBackend::VULKAN || g_Config.iGPUBackend == (int)GPUBackend::OPENGL) { + DrawGPUProfilerVis(ctx, gpu); + } + break; + case DebugOverlay::GPU_ALLOCATOR: + if (g_Config.iGPUBackend == (int)GPUBackend::VULKAN || g_Config.iGPUBackend == (int)GPUBackend::OPENGL) { + DrawGPUMemoryVis(ctx, gpu); + } + break; +#endif } if (g_Config.iShowStatusFlags) { DrawFPS(ctx, ctx->GetLayoutBounds()); } - - if (g_Config.bDrawFrameGraph) { - DrawFrameTimes(ctx, ctx->GetLayoutBounds()); - } - - if (g_Config.bShowControlDebug) { - DrawControlDebug(ctx, controlMapper_, ctx->GetLayoutBounds()); - } } -#if !PPSSPP_PLATFORM(UWP) && !PPSSPP_PLATFORM(SWITCH) - if ((g_Config.iGPUBackend == (int)GPUBackend::VULKAN || g_Config.iGPUBackend == (int)GPUBackend::OPENGL) && g_Config.bShowAllocatorDebug) { - DrawGPUMemoryVis(ctx, gpu); - } - - if ((g_Config.iGPUBackend == (int)GPUBackend::VULKAN || g_Config.iGPUBackend == (int)GPUBackend::OPENGL) && g_Config.bShowGpuProfile) { - DrawGPUProfilerVis(ctx, gpu); - } - -#endif - #ifdef USE_PROFILER if (g_Config.bShowFrameProfiler && !invalid_) { DrawProfile(*ctx); diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 16209e60d8..c7626c0eb5 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -562,8 +562,7 @@ void GameSettingsScreen::CreateGraphicsSettings(UI::ViewGroup *graphicsSettings) #ifdef CAN_DISPLAY_CURRENT_BATTERY_CAPACITY BitCheckBox *showBattery = graphicsSettings->Add(new BitCheckBox(&g_Config.iShowStatusFlags, (int)ShowStatusFlags::BATTERY_PERCENT, gr->T("Show Battery %"))); #endif - - graphicsSettings->Add(new CheckBox(&g_Config.bShowDebugStats, gr->T("Show Debug Statistics")))->OnClick.Handle(this, &GameSettingsScreen::OnJitAffectingSetting); + AddOverlayList(graphicsSettings, screenManager()); } void GameSettingsScreen::CreateAudioSettings(UI::ViewGroup *audioSettings) { @@ -1658,6 +1657,8 @@ void DeveloperToolsScreen::CreateViews() { cpuTests->SetEnabled(TestsAvailable()); #endif + AddOverlayList(list, screenManager()); + if (g_Config.iGPUBackend == (int)GPUBackend::VULKAN) { list->Add(new CheckBox(&g_Config.bRenderMultiThreading, dev->T("Multi-threaded rendering"), ""))->OnClick.Add([](UI::EventParams &e) { // TODO: Not translating yet. Will combine with other translations of settings that need restart. @@ -1873,7 +1874,7 @@ UI::EventReturn DeveloperToolsScreen::OnRemoteDebugger(UI::EventParams &e) { } // Persist the setting. Maybe should separate? g_Config.bRemoteDebuggerOnStartup = allowDebugger_; - return UI::EVENT_CONTINUE; + return UI::EVENT_DONE; } void DeveloperToolsScreen::update() { diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index c06aa59fa9..ff64a03c16 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1098,7 +1098,7 @@ void NativeRender(GraphicsContext *graphicsContext) { g_screenManager->getUIContext()->SetTintSaturation(g_Config.fUITint, g_Config.fUISaturation); Draw::DebugFlags debugFlags = Draw::DebugFlags::NONE; - if (g_Config.bShowGpuProfile) + if (g_Config.iDebugOverlay == DebugOverlay::GPU_PROFILE) debugFlags |= Draw::DebugFlags::PROFILE_TIMESTAMPS; if (g_Config.bGpuLogProfiler) debugFlags |= Draw::DebugFlags::PROFILE_SCOPES; diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index 2e7101f76f..9837a5a583 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -709,7 +709,13 @@ namespace MainWindow { break; case ID_DEBUG_SHOWDEBUGSTATISTICS: - g_Config.bShowDebugStats = !g_Config.bShowDebugStats; + // This is still useful as a shortcut to tell users to use. + // So let's fake the enum. + if (g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS) { + g_Config.iDebugOverlay = DebugOverlay::OFF; + } else { + g_Config.iDebugOverlay = DebugOverlay::DEBUG_STATS; + } System_PostUIMessage("clear jit", ""); break; @@ -958,7 +964,7 @@ namespace MainWindow { HMENU menu = GetMenu(GetHWND()); #define CHECKITEM(item,value) CheckMenuItem(menu,item,MF_BYCOMMAND | ((value) ? MF_CHECKED : MF_UNCHECKED)); CHECKITEM(ID_DEBUG_IGNOREILLEGALREADS, g_Config.bIgnoreBadMemAccess); - CHECKITEM(ID_DEBUG_SHOWDEBUGSTATISTICS, g_Config.bShowDebugStats); + CHECKITEM(ID_DEBUG_SHOWDEBUGSTATISTICS, g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS); CHECKITEM(ID_OPTIONS_HARDWARETRANSFORM, g_Config.bHardwareTransform); CHECKITEM(ID_DEBUG_BREAKONLOAD, !g_Config.bAutoRun); CHECKITEM(ID_OPTIONS_VERTEXCACHE, g_Config.bVertexCache); diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 4a79bad5d8..20c17ca162 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -234,7 +234,7 @@ bool RunAutoTest(HeadlessHost *headlessHost, CoreParameter &coreParameter, const System_Notify(SystemNotification::BOOT_DONE); - Core_UpdateDebugStats(g_Config.bShowDebugStats || g_Config.bLogFrameDrops); + Core_UpdateDebugStats(g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS || g_Config.bLogFrameDrops); PSP_BeginHostFrame(); Draw::DrawContext *draw = coreParameter.graphicsContext ? coreParameter.graphicsContext->GetDrawContext() : nullptr;