Skip to content

Commit

Permalink
Merge pull request #17833 from hrydgard/debug-overlay-enum
Browse files Browse the repository at this point in the history
Debug overlays: Refactor a pile of bools to an enum
  • Loading branch information
hrydgard committed Aug 2, 2023
2 parents 7538807 + 0636893 commit 354269e
Show file tree
Hide file tree
Showing 58 changed files with 201 additions and 179 deletions.
25 changes: 15 additions & 10 deletions Common/UI/Screen.cpp
Expand Up @@ -156,30 +156,35 @@ void ScreenManager::resized() {
void ScreenManager::render() {
if (!stack_.empty()) {
switch (stack_.back().flags) {
case LAYER_SIDEMENU:
case LAYER_TRANSPARENT:
if (stack_.size() == 1) {
ERROR_LOG(SYSTEM, "Can't have sidemenu over nothing");
break;
} else {
auto iter = stack_.end();
auto last = stack_.end();
auto iter = last;
iter--;
iter--;
Layer backback = *iter;

_assert_(backback.screen);
while (iter->flags == LAYER_TRANSPARENT) {
iter--;
}
auto first = iter;
_assert_(iter->screen);

// TODO: Make really sure that this "mismatched" pre/post only happens
// when screens are "compatible" (both are UIScreens, for example).
backback.screen->preRender();
backback.screen->render();
first->screen->preRender();
while (iter < last) {
iter->screen->render();
iter++;
}
stack_.back().screen->render();
if (postRenderCb_)
if (postRenderCb_) {
postRenderCb_(getUIContext(), postRenderUserdata_);
}
if (overlayScreen_) {
overlayScreen_->render();
}
backback.screen->postRender();
first->screen->postRender();
break;
}
default:
Expand Down
1 change: 0 additions & 1 deletion Common/UI/Screen.h
Expand Up @@ -90,7 +90,6 @@ class Transition {
};

enum {
LAYER_SIDEMENU = 1,
LAYER_TRANSPARENT = 2,
};

Expand Down
5 changes: 0 additions & 5 deletions Core/Config.cpp
Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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());
Expand Down
5 changes: 2 additions & 3 deletions Core/Config.h
Expand Up @@ -465,16 +465,15 @@ struct Config {
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
Expand Down
13 changes: 13 additions & 0 deletions Core/ConfigValues.h
Expand Up @@ -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,
};
6 changes: 3 additions & 3 deletions Core/HLE/sceDisplay.cpp
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Core/HW/Display.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/TextureCacheCommon.cpp
Expand Up @@ -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();
}
Expand Down
63 changes: 33 additions & 30 deletions UI/DevScreens.cpp
Expand Up @@ -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
"Control Debug",
"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);
Expand All @@ -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);
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions UI/DevScreens.h
Expand Up @@ -42,8 +42,6 @@ class DevMenuScreen : public PopupScreen {
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);

Expand Down Expand Up @@ -226,3 +224,5 @@ class FrameDumpTestScreen : public UIDialogScreenWithBackground {

void DrawProfile(UIContext &ui);
const char *GetCompilerABI();

void AddOverlayList(UI::ViewGroup *items, ScreenManager *screenManager);
51 changes: 26 additions & 25 deletions UI/EmuScreen.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions UI/GameSettingsScreen.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion UI/NativeApp.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit 354269e

Please sign in to comment.