From a32249a3cfdfc776ee5d1d42ae15b193dfa1dd5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 3 Aug 2023 16:19:18 +0200 Subject: [PATCH] Move DebugOverlay rendering to the overlay screen, allowing drawing it on top of the menu --- Core/Config.cpp | 1 + Core/Config.h | 2 +- Core/HLE/sceDisplay.cpp | 6 +++--- Core/HW/Display.cpp | 6 +++++- GPU/Common/TextureCacheCommon.cpp | 2 +- SDL/CocoaBarItems.mm | 8 ++++---- UI/DebugOverlay.cpp | 12 +++++++----- UI/DebugOverlay.h | 3 ++- UI/DevScreens.cpp | 2 +- UI/EmuScreen.cpp | 9 +++++---- UI/NativeApp.cpp | 2 +- UI/OnScreenDisplay.cpp | 13 +++++++++++++ UI/OnScreenDisplay.h | 1 + Windows/MainWindowMenu.cpp | 8 ++++---- headless/Headless.cpp | 2 +- 15 files changed, 50 insertions(+), 27 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index fcff184572..c21b82a315 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -179,6 +179,7 @@ static const ConfigSetting generalSettings[] = { ConfigSetting("CwCheatRefreshRate", &g_Config.iCwCheatRefreshRate, 77, CfgFlag::PER_GAME), ConfigSetting("CwCheatScrollPosition", &g_Config.fCwCheatScrollPosition, 0.0f, CfgFlag::PER_GAME), ConfigSetting("GameListScrollPosition", &g_Config.fGameListScrollPosition, 0.0f, CfgFlag::DEFAULT), + ConfigSetting("DebugOverlay", &g_Config.iDebugOverlay, 0, CfgFlag::DONT_SAVE), ConfigSetting("ScreenshotsAsPNG", &g_Config.bScreenshotsAsPNG, false, CfgFlag::PER_GAME), ConfigSetting("UseFFV1", &g_Config.bUseFFV1, false, CfgFlag::DEFAULT), diff --git a/Core/Config.h b/Core/Config.h index 75786fcb34..eeb6d51f2f 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -471,7 +471,7 @@ public: // Volatile development settings // Overlays - DebugOverlay iDebugOverlay; + int iDebugOverlay; bool bGpuLogProfiler; // Controls the Vulkan logging profiler (profiles textures uploads etc). diff --git a/Core/HLE/sceDisplay.cpp b/Core/HLE/sceDisplay.cpp index 7e50d991ef..be8551c7fd 100644 --- a/Core/HLE/sceDisplay.cpp +++ b/Core/HLE/sceDisplay.cpp @@ -496,7 +496,7 @@ static void DoFrameIdleTiming() { #endif } - if (g_Config.iDebugOverlay == DebugOverlay::FRAME_GRAPH || coreCollectDebugStats) { + if ((DebugOverlay)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.iDebugOverlay == DebugOverlay::FRAME_GRAPH || coreCollectDebugStats) { + if ((DebugOverlay)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.iDebugOverlay == DebugOverlay::FRAME_GRAPH || coreCollectDebugStats) { + if ((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::FRAME_GRAPH || coreCollectDebugStats) { DisplayNotifySleep(now - before); } } diff --git a/Core/HW/Display.cpp b/Core/HW/Display.cpp index 4738affd72..1831ee3f23 100644 --- a/Core/HW/Display.cpp +++ b/Core/HW/Display.cpp @@ -92,7 +92,7 @@ static void CalculateFPS() { } } - if (g_Config.iDebugOverlay == DebugOverlay::FRAME_GRAPH || coreCollectDebugStats) { + if ((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::FRAME_GRAPH || coreCollectDebugStats) { frameTimeHistory[frameTimeHistoryPos++] = now - lastFrameTimeHistory; lastFrameTimeHistory = now; frameTimeHistoryPos = frameTimeHistoryPos % frameTimeHistorySize; @@ -182,6 +182,10 @@ void DisplayNotifySleep(double t, int pos) { void __DisplayGetDebugStats(char *stats, size_t bufsize) { char statbuf[4096]; + if (!gpu) { + snprintf(stats, bufsize, "N/A"); + return; + } gpu->GetStats(statbuf, sizeof(statbuf)); snprintf(stats, bufsize, diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index ebc642cd4d..5afc2b5be7 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.iDebugOverlay == DebugOverlay::DEBUG_STATS) { + if ((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS) { gpuStats.numReplacerTrackedTex = replacer_.GetNumTrackedTextures(); gpuStats.numCachedReplacedTextures = replacer_.GetNumCachedReplacedTextures(); } diff --git a/SDL/CocoaBarItems.mm b/SDL/CocoaBarItems.mm index 57e38d55b5..2e6a5b6632 100644 --- a/SDL/CocoaBarItems.mm +++ b/SDL/CocoaBarItems.mm @@ -217,7 +217,7 @@ void OSXOpenURL(const char *url) { item.state = [self controlStateForBool:g_Config.bIgnoreBadMemAccess]; break; case 12: - item.state = [self controlStateForBool:g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS]; + item.state = [self controlStateForBool:(DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS]; break; default: item.enabled = state == UISTATE_INGAME ? YES : NO; @@ -405,7 +405,7 @@ void OSXOpenURL(const char *url) { copyBaseAddr.target = self; copyBaseAddr.tag = 11; - MENU_ITEM(showDebugStatsAction, DESKTOPUI_LOCALIZED("Show Debug Statistics"), @selector(toggleShowDebugStats:), (g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS), 12) + MENU_ITEM(showDebugStatsAction, DESKTOPUI_LOCALIZED("Show Debug Statistics"), @selector(toggleShowDebugStats:), ((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS), 12) [parent addItem:loadSymbolMapAction]; [parent addItem:saveMapFileAction]; @@ -544,13 +544,13 @@ TOGGLE_METHOD(FullScreen, g_Config.bFullScreen, System_MakeRequest(SystemRequest #undef TOGGLE_METHOD -(void)toggleShowDebugStats: (NSMenuItem *)item { \ - if (g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS) { + if ((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS) { g_Config.iDebugOverlay = DebugOverlay::OFF; } else { g_Config.iDebugOverlay = DebugOverlay::DEBUG_STATS; } System_PostUIMessage("clear jit", ""); - item.state = [self controlStateForBool: g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS]; \ + item.state = [self controlStateForBool: (DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS]; \ } -(void)setToggleShowCounterItem: (NSMenuItem *)item { diff --git a/UI/DebugOverlay.cpp b/UI/DebugOverlay.cpp index e5e34033e1..3e78f2dbad 100644 --- a/UI/DebugOverlay.cpp +++ b/UI/DebugOverlay.cpp @@ -150,7 +150,11 @@ static void DrawFrameTiming(UIContext *ctx, const Bounds &bounds) { ctx->RebindTexture(); } -void DrawDebugOverlay(UIContext *ctx, const Bounds &bounds, const ControlMapper &controlMapper, DebugOverlay overlay) { +void DrawControlMapperOverlay(UIContext *ctx, const Bounds &bounds, const ControlMapper &controlMapper) { + DrawControlDebug(ctx, controlMapper, ctx->GetLayoutBounds()); +} + +void DrawDebugOverlay(UIContext *ctx, const Bounds &bounds, DebugOverlay overlay) { switch (overlay) { case DebugOverlay::DEBUG_STATS: DrawDebugStats(ctx, ctx->GetLayoutBounds()); @@ -164,11 +168,7 @@ void DrawDebugOverlay(UIContext *ctx, const Bounds &bounds, const ControlMapper 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); @@ -180,5 +180,7 @@ void DrawDebugOverlay(UIContext *ctx, const Bounds &bounds, const ControlMapper } break; #endif + default: + break; } } diff --git a/UI/DebugOverlay.h b/UI/DebugOverlay.h index 0723734195..119f220fc4 100644 --- a/UI/DebugOverlay.h +++ b/UI/DebugOverlay.h @@ -4,4 +4,5 @@ #include "Core/ConfigValues.h" #include "Core/ControlMapper.h" -void DrawDebugOverlay(UIContext *ctx, const Bounds &bounds, const ControlMapper &controlMapper, DebugOverlay overlay); +void DrawControlMapperOverlay(UIContext *ctx, const Bounds &bounds, const ControlMapper &controlMapper); +void DrawDebugOverlay(UIContext *ctx, const Bounds &bounds, DebugOverlay overlay); diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index 43ac0224a4..f1bb0dea3b 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -776,7 +776,7 @@ void SystemInfoScreen::CreateTabs() { if (mode == vk->GetPresentMode()) { str += std::string(" (") + di->T("Current") + ")"; } - presentModes->Add(new TextView(VulkanPresentModeToString(mode), new LayoutParams(FILL_PARENT, WRAP_CONTENT)))->SetFocusable(true); + presentModes->Add(new TextView(str, new LayoutParams(FILL_PARENT, WRAP_CONTENT)))->SetFocusable(true); } CollapsibleSection *colorFormats = gpuExtensions->Add(new CollapsibleSection(si->T("Display Color Formats"))); diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 2d55bdd763..85cf652041 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -1427,7 +1427,7 @@ void EmuScreen::render() { } } - Core_UpdateDebugStats(g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS || g_Config.bLogFrameDrops); + Core_UpdateDebugStats((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS || g_Config.bLogFrameDrops); bool blockedExecution = Achievements::IsBlockingExecution(); if (!blockedExecution) { @@ -1503,7 +1503,7 @@ bool EmuScreen::hasVisibleUI() { if (g_Config.bEnableCardboardVR || g_Config.bEnableNetworkChat) return true; // Debug UI. - if (g_Config.iDebugOverlay != DebugOverlay::OFF) + if ((DebugOverlay)g_Config.iDebugOverlay != DebugOverlay::OFF) return true; // Exception information. @@ -1538,8 +1538,9 @@ void EmuScreen::renderUI() { } if (!invalid_) { - DrawDebugOverlay(ctx, ctx->GetLayoutBounds(), controlMapper_, g_Config.iDebugOverlay); - + if ((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::CONTROL) { + DrawControlMapperOverlay(ctx, ctx->GetLayoutBounds(), controlMapper_); + } if (g_Config.iShowStatusFlags) { DrawFPS(ctx, ctx->GetLayoutBounds()); } diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index ff64a03c16..dbb551ec84 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.iDebugOverlay == DebugOverlay::GPU_PROFILE) + if ((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::GPU_PROFILE) debugFlags |= Draw::DebugFlags::PROFILE_TIMESTAMPS; if (g_Config.bGpuLogProfiler) debugFlags |= Draw::DebugFlags::PROFILE_SCOPES; diff --git a/UI/OnScreenDisplay.cpp b/UI/OnScreenDisplay.cpp index 6a5baa784c..0302515a3c 100644 --- a/UI/OnScreenDisplay.cpp +++ b/UI/OnScreenDisplay.cpp @@ -10,6 +10,7 @@ #include "Common/Math/math_util.h" #include "Common/UI/IconCache.h" #include "UI/RetroAchievementScreens.h" +#include "UI/DebugOverlay.h" #include "Common/UI/Context.h" #include "Common/System/OSD.h" @@ -456,6 +457,18 @@ void OSDOverlayScreen::CreateViews() { root_->Add(new OnScreenMessagesView(new UI::AnchorLayoutParams(0.0f, 0.0f, 0.0f, 0.0f))); } +void OSDOverlayScreen::render() { + UIScreen::render(); + + DebugOverlay debugOverlay = (DebugOverlay)g_Config.iDebugOverlay; + + // Special case control for now, since it uses the control mapper that's owned by EmuScreen. + if (debugOverlay != DebugOverlay::OFF && debugOverlay != DebugOverlay::CONTROL) { + UIContext *uiContext = screenManager()->getUIContext(); + DrawDebugOverlay(uiContext, uiContext->GetLayoutBounds(), debugOverlay); + } +} + void NoticeView::GetContentDimensionsBySpec(const UIContext &dc, UI::MeasureSpec horiz, UI::MeasureSpec vert, float &w, float &h) const { Bounds bounds(0, 0, layoutParams_->width, layoutParams_->height); if (bounds.w < 0) { diff --git a/UI/OnScreenDisplay.h b/UI/OnScreenDisplay.h index 24c819da01..5cde5cf585 100644 --- a/UI/OnScreenDisplay.h +++ b/UI/OnScreenDisplay.h @@ -28,6 +28,7 @@ class OSDOverlayScreen : public UIScreen { public: const char *tag() const override { return "OSDOverlayScreen"; } void CreateViews() override; + void render() override; }; enum class NoticeLevel { diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index 9837a5a583..551e3495de 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -711,10 +711,10 @@ namespace MainWindow { case ID_DEBUG_SHOWDEBUGSTATISTICS: // 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; + if ((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS) { + g_Config.iDebugOverlay = (int)DebugOverlay::OFF; } else { - g_Config.iDebugOverlay = DebugOverlay::DEBUG_STATS; + g_Config.iDebugOverlay = (int)DebugOverlay::DEBUG_STATS; } System_PostUIMessage("clear jit", ""); break; @@ -964,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.iDebugOverlay == DebugOverlay::DEBUG_STATS); + CHECKITEM(ID_DEBUG_SHOWDEBUGSTATISTICS, (DebugOverlay)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 20c17ca162..1eb353f625 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.iDebugOverlay == DebugOverlay::DEBUG_STATS || g_Config.bLogFrameDrops); + Core_UpdateDebugStats((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS || g_Config.bLogFrameDrops); PSP_BeginHostFrame(); Draw::DrawContext *draw = coreParameter.graphicsContext ? coreParameter.graphicsContext->GetDrawContext() : nullptr;