Skip to content

Commit

Permalink
ImGuiOverlays: Move debug state to auxiliary windows
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Oct 18, 2024
1 parent 6dc2f0a commit 86a28d5
Show file tree
Hide file tree
Showing 19 changed files with 153 additions and 151 deletions.
14 changes: 2 additions & 12 deletions src/core/cdrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3809,18 +3809,10 @@ const std::string* CDROM::LookupFileMap(u32 lba, u32* start_lba, u32* end_lba)
return &iter->second.second;
}

void CDROM::DrawDebugWindow()
void CDROM::DrawDebugWindow(float scale)
{
static const ImVec4 active_color{1.0f, 1.0f, 1.0f, 1.0f};
static const ImVec4 inactive_color{0.4f, 0.4f, 0.4f, 1.0f};
const float framebuffer_scale = ImGuiManager::GetGlobalScale();

ImGui::SetNextWindowSize(ImVec2(800.0f * framebuffer_scale, 580.0f * framebuffer_scale), ImGuiCond_FirstUseEver);
if (!ImGui::Begin("CDROM State", nullptr))
{
ImGui::End();
return;
}

// draw voice states
if (ImGui::CollapsingHeader("Media", ImGuiTreeNodeFlags_DefaultOpen))
Expand Down Expand Up @@ -3916,7 +3908,7 @@ void CDROM::DrawDebugWindow()
else
{
const float end_y = ImGui::GetCursorPosY();
ImGui::SetCursorPosX(ImGui::GetWindowWidth() - 120.0f * framebuffer_scale);
ImGui::SetCursorPosX(ImGui::GetWindowWidth() - 120.0f * scale);
ImGui::SetCursorPosY(start_y);
if (ImGui::Button("Show Current File"))
s_state.show_current_file = true;
Expand Down Expand Up @@ -4081,6 +4073,4 @@ void CDROM::DrawDebugWindow()

ImGui::Text("Audio FIFO Size: %u frames", s_state.audio_fifo.GetSize());
}

ImGui::End();
}
2 changes: 1 addition & 1 deletion src/core/cdrom.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void WriteRegister(u32 offset, u8 value);
void DMARead(u32* words, u32 word_count);

// Render statistics debug window.
void DrawDebugWindow();
void DrawDebugWindow(float scale);

void SetReadaheadSectors(u32 readahead_sectors);

Expand Down
32 changes: 11 additions & 21 deletions src/core/dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,33 +910,24 @@ TickCount DMA::TransferDeviceToMemory(u32 address, u32 increment, u32 word_count
return Bus::GetDMARAMTickCount(word_count);
}

void DMA::DrawDebugStateWindow()
void DMA::DrawDebugStateWindow(float scale)
{
static constexpr u32 NUM_COLUMNS = 10;
static constexpr std::array<const char*, NUM_COLUMNS> column_names = {
{"#", "Req", "Direction", "Chopping", "Mode", "Busy", "Enable", "Priority", "IRQ", "Flag"}};
static constexpr std::array<const char*, 4> sync_mode_names = {{"Manual", "Request", "LinkedList", "Reserved"}};

const float framebuffer_scale = ImGuiManager::GetGlobalScale();

ImGui::SetNextWindowSize(ImVec2(850.0f * framebuffer_scale, 250.0f * framebuffer_scale), ImGuiCond_FirstUseEver);
if (!ImGui::Begin("DMA State", nullptr))
{
ImGui::End();
return;
}

ImGui::Columns(NUM_COLUMNS);
ImGui::SetColumnWidth(0, 100.0f * framebuffer_scale);
ImGui::SetColumnWidth(1, 50.0f * framebuffer_scale);
ImGui::SetColumnWidth(2, 100.0f * framebuffer_scale);
ImGui::SetColumnWidth(3, 150.0f * framebuffer_scale);
ImGui::SetColumnWidth(4, 80.0f * framebuffer_scale);
ImGui::SetColumnWidth(5, 80.0f * framebuffer_scale);
ImGui::SetColumnWidth(6, 80.0f * framebuffer_scale);
ImGui::SetColumnWidth(7, 80.0f * framebuffer_scale);
ImGui::SetColumnWidth(8, 80.0f * framebuffer_scale);
ImGui::SetColumnWidth(9, 80.0f * framebuffer_scale);
ImGui::SetColumnWidth(0, 100.0f * scale);
ImGui::SetColumnWidth(1, 50.0f * scale);
ImGui::SetColumnWidth(2, 100.0f * scale);
ImGui::SetColumnWidth(3, 150.0f * scale);
ImGui::SetColumnWidth(4, 80.0f * scale);
ImGui::SetColumnWidth(5, 80.0f * scale);
ImGui::SetColumnWidth(6, 80.0f * scale);
ImGui::SetColumnWidth(7, 80.0f * scale);
ImGui::SetColumnWidth(8, 80.0f * scale);
ImGui::SetColumnWidth(9, 80.0f * scale);

for (const char* title : column_names)
{
Expand Down Expand Up @@ -984,7 +975,6 @@ void DMA::DrawDebugStateWindow()
}

ImGui::Columns(1);
ImGui::End();
}

// Instantiate channel functions.
Expand Down
2 changes: 1 addition & 1 deletion src/core/dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ void WriteRegister(u32 offset, u32 value);

void SetRequest(Channel channel, bool request);

void DrawDebugStateWindow();
void DrawDebugStateWindow(float scale);

} // namespace DMA
13 changes: 1 addition & 12 deletions src/core/gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2759,17 +2759,8 @@ bool GPU::DumpVRAMToFile(const char* filename, u32 width, u32 height, u32 stride
return image.SaveToFile(filename);
}

void GPU::DrawDebugStateWindow()
void GPU::DrawDebugStateWindow(float scale)
{
const float framebuffer_scale = ImGuiManager::GetGlobalScale();

ImGui::SetNextWindowSize(ImVec2(450.0f * framebuffer_scale, 550.0f * framebuffer_scale), ImGuiCond_FirstUseEver);
if (!ImGui::Begin("GPU", nullptr))
{
ImGui::End();
return;
}

DrawRendererStats();

if (ImGui::CollapsingHeader("GPU", ImGuiTreeNodeFlags_DefaultOpen))
Expand Down Expand Up @@ -2824,8 +2815,6 @@ void GPU::DrawDebugStateWindow()
cs.display_width - cs.display_vram_width - cs.display_origin_left,
cs.display_height - cs.display_vram_height - cs.display_origin_top);
}

ImGui::End();
}

void GPU::DrawRendererStats()
Expand Down
2 changes: 1 addition & 1 deletion src/core/gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class GPU
virtual void RestoreDeviceContext();

// Render statistics debug window.
void DrawDebugStateWindow();
void DrawDebugStateWindow(float scale);
void GetStatsString(SmallStringBase& str);
void GetMemoryStatsString(SmallStringBase& str);
void ResetStatistics();
Expand Down
1 change: 1 addition & 0 deletions src/core/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ void Host::ReleaseGPUDevice()
if (!g_gpu_device)
return;

ImGuiManager::DestroyAllDebugWindows();
ImGuiManager::DestroyOverlayTextures();
FullscreenUI::Shutdown();
ImGuiManager::Shutdown();
Expand Down
107 changes: 94 additions & 13 deletions src/core/imgui_overlays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: CC-BY-NC-ND-4.0

#include "imgui_overlays.h"
#include "achievements.h"
#include "cdrom.h"
#include "controller.h"
#include "cpu_core_private.h"
Expand Down Expand Up @@ -37,6 +38,7 @@
#include "imgui.h"
#include "imgui_internal.h"

#include <array>
#include <atomic>
#include <chrono>
#include <cmath>
Expand All @@ -47,12 +49,43 @@
LOG_CHANNEL(ImGuiManager);

namespace ImGuiManager {

namespace {

#ifndef __ANDROID__

struct DebugWindowInfo
{
const char* name;
const char* window_title;
const char* icon_name;
void (*draw_func)(float);
u32 default_width;
u32 default_height;
};

#endif

} // namespace

static void FormatProcessorStat(SmallStringBase& text, double usage, double time);
static void DrawPerformanceOverlay(float& position_y, float scale, float margin, float spacing);
static void DrawMediaCaptureOverlay(float& position_y, float scale, float margin, float spacing);
static void DrawFrameTimeOverlay(float& position_y, float scale, float margin, float spacing);
static void DrawEnhancementsOverlay();
static void DrawInputsOverlay();

static constexpr size_t NUM_DEBUG_WINDOWS = 6;
static constexpr const char* DEBUG_WINDOW_CONFIG_SECTION = "DebugWindows";
static constexpr const std::array<DebugWindowInfo, NUM_DEBUG_WINDOWS> s_debug_window_info = {{
{"SPU", "SPU State", ":icons/applications-system.png", &SPU::DrawDebugStateWindow, 800, 915},
{"CDROM", "CD-ROM State", ":icons/applications-system.png", &CDROM::DrawDebugWindow, 800, 540},
{"GPU", "GPU State", ":icons/applications-system.png", [](float sc) { g_gpu->DrawDebugStateWindow(sc); }, 450, 550},
{"DMA", "DMA State", ":icons/applications-system.png", &DMA::DrawDebugStateWindow, 860, 180},
{"MDEC", "MDEC State", ":icons/applications-system.png", &MDEC::DrawDebugStateWindow, 300, 350},
{"Timers", "Timers State", ":icons/applications-system.png", &Timers::DrawDebugStateWindow, 800, 95},
}};
static std::array<ImGuiManager::AuxiliaryRenderWindowState, NUM_DEBUG_WINDOWS> s_debug_window_state = {};
} // namespace ImGuiManager

static std::tuple<float, float> GetMinMax(std::span<const float> values)
Expand Down Expand Up @@ -170,23 +203,71 @@ void Host::DisplayLoadingScreen(const char* message, int progress_min /*= -1*/,
ImGui::NewFrame();
}

void ImGuiManager::UpdateDebugWindowConfig()
{
#ifndef __ANDROID__
const bool block_all = Achievements::IsHardcoreModeActive();

for (size_t i = 0; i < NUM_DEBUG_WINDOWS; i++)
{
AuxiliaryRenderWindowState& state = s_debug_window_state[i];
const DebugWindowInfo& info = s_debug_window_info[i];

const bool current = (state.window_handle != nullptr);
const bool enabled = (!block_all && Host::GetBaseBoolSettingValue(DEBUG_WINDOW_CONFIG_SECTION, info.name, false));
if (enabled == current)
continue;

if (!enabled)
{
DestroyAuxiliaryRenderWindow(&state, DEBUG_WINDOW_CONFIG_SECTION, info.name);
}
else
{
Error error;
if (!CreateAuxiliaryRenderWindow(&state, info.window_title, info.icon_name, DEBUG_WINDOW_CONFIG_SECTION,
info.name, info.default_width, info.default_height, &error))
{
ERROR_LOG("Failed to create aux render window for {}: {}", info.name, error.GetDescription());
}
}
}
#endif
}

void ImGuiManager::RenderDebugWindows()
{
if (System::IsValid())
#ifndef __ANDROID__
for (size_t i = 0; i < NUM_DEBUG_WINDOWS; i++)
{
if (g_settings.debugging.show_gpu_state)
g_gpu->DrawDebugStateWindow();
if (g_settings.debugging.show_cdrom_state)
CDROM::DrawDebugWindow();
if (g_settings.debugging.show_timers_state)
Timers::DrawDebugStateWindow();
if (g_settings.debugging.show_spu_state)
SPU::DrawDebugStateWindow();
if (g_settings.debugging.show_mdec_state)
MDEC::DrawDebugStateWindow();
if (g_settings.debugging.show_dma_state)
DMA::DrawDebugStateWindow();
AuxiliaryRenderWindowState& state = s_debug_window_state[i];
if (!state.window_handle)
continue;

if (!RenderAuxiliaryRenderWindow(&state, s_debug_window_info[i].draw_func))
{
// window was closed, destroy it and update the configuration
const DebugWindowInfo& info = s_debug_window_info[i];
DestroyAuxiliaryRenderWindow(&state, DEBUG_WINDOW_CONFIG_SECTION, info.name);
Host::SetBaseBoolSettingValue(DEBUG_WINDOW_CONFIG_SECTION, info.name, false);
Host::CommitBaseSettingChanges();
}
}
#endif
}

void ImGuiManager::DestroyAllDebugWindows()
{
#ifndef __ANDROID__
for (size_t i = 0; i < NUM_DEBUG_WINDOWS; i++)
{
AuxiliaryRenderWindowState& state = s_debug_window_state[i];
if (!state.window_handle)
continue;

ImGuiManager::DestroyAuxiliaryRenderWindow(&state, DEBUG_WINDOW_CONFIG_SECTION, s_debug_window_info[i].name);
}
#endif
}

void ImGuiManager::RenderTextOverlays()
Expand Down
2 changes: 2 additions & 0 deletions src/core/imgui_overlays.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
namespace ImGuiManager {
void RenderTextOverlays();
void RenderDebugWindows();
void UpdateDebugWindowConfig();
void DestroyAllDebugWindows();

void RenderOverlayWindows();
void DestroyOverlayTextures();
Expand Down
13 changes: 1 addition & 12 deletions src/core/mdec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,17 +1125,8 @@ void MDEC::SetScaleMatrix(const u16* values)
}
}

void MDEC::DrawDebugStateWindow()
void MDEC::DrawDebugStateWindow(float scale)
{
const float framebuffer_scale = ImGuiManager::GetGlobalScale();

ImGui::SetNextWindowSize(ImVec2(300.0f * framebuffer_scale, 350.0f * framebuffer_scale), ImGuiCond_FirstUseEver);
if (!ImGui::Begin("MDEC State", nullptr))
{
ImGui::End();
return;
}

static constexpr std::array<const char*, 5> state_names = {
{"None", "Decoding Macroblock", "Writing Macroblock", "SetIqTab", "SetScale"}};
static constexpr std::array<const char*, 4> output_depths = {{"4-bit", "8-bit", "24-bit", "15-bit"}};
Expand Down Expand Up @@ -1163,6 +1154,4 @@ void MDEC::DrawDebugStateWindow()
ImGui::Text("Parameter Words Remaining: %d",
static_cast<s32>(SignExtend32(s_state.status.parameter_words_remaining.GetValue())));
}

ImGui::End();
}
2 changes: 1 addition & 1 deletion src/core/mdec.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ void WriteRegister(u32 offset, u32 value);
void DMARead(u32* words, u32 word_count);
void DMAWrite(const u32* words, u32 word_count);

void DrawDebugStateWindow();
void DrawDebugStateWindow(float scale);

} // namespace MDEC
20 changes: 0 additions & 20 deletions src/core/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,6 @@ void Settings::Load(SettingsInterface& si, SettingsInterface& controller_si)
debugging.gdb_server_port = static_cast<u16>(si.GetUIntValue("Debug", "GDBServerPort", DEFAULT_GDB_SERVER_PORT));
#endif

debugging.show_gpu_state = si.GetBoolValue("Debug", "ShowGPUState");
debugging.show_cdrom_state = si.GetBoolValue("Debug", "ShowCDROMState");
debugging.show_spu_state = si.GetBoolValue("Debug", "ShowSPUState");
debugging.show_timers_state = si.GetBoolValue("Debug", "ShowTimersState");
debugging.show_mdec_state = si.GetBoolValue("Debug", "ShowMDECState");
debugging.show_dma_state = si.GetBoolValue("Debug", "ShowDMAState");

texture_replacements.enable_texture_replacements =
si.GetBoolValue("TextureReplacements", "EnableTextureReplacements", false);
texture_replacements.enable_vram_write_replacements =
Expand Down Expand Up @@ -712,13 +705,6 @@ void Settings::Save(SettingsInterface& si, bool ignore_base) const
si.SetBoolValue("Debug", "EnableGDBServer", debugging.enable_gdb_server);
si.SetUIntValue("Debug", "GDBServerPort", debugging.gdb_server_port);
#endif

si.SetBoolValue("Debug", "ShowGPUState", debugging.show_gpu_state);
si.SetBoolValue("Debug", "ShowCDROMState", debugging.show_cdrom_state);
si.SetBoolValue("Debug", "ShowSPUState", debugging.show_spu_state);
si.SetBoolValue("Debug", "ShowTimersState", debugging.show_timers_state);
si.SetBoolValue("Debug", "ShowMDECState", debugging.show_mdec_state);
si.SetBoolValue("Debug", "ShowDMAState", debugging.show_dma_state);
}

si.SetBoolValue("TextureReplacements", "EnableTextureReplacements", texture_replacements.enable_texture_replacements);
Expand Down Expand Up @@ -1035,12 +1021,6 @@ void Settings::FixIncompatibleSettings(bool display_osd_messages)
}
g_settings.debugging.enable_gdb_server = false;
g_settings.debugging.show_vram = false;
g_settings.debugging.show_gpu_state = false;
g_settings.debugging.show_cdrom_state = false;
g_settings.debugging.show_spu_state = false;
g_settings.debugging.show_timers_state = false;
g_settings.debugging.show_mdec_state = false;
g_settings.debugging.show_dma_state = false;
g_settings.debugging.dump_cpu_to_vram_copies = false;
g_settings.debugging.dump_vram_to_cpu_copies = false;
}
Expand Down
Loading

0 comments on commit 86a28d5

Please sign in to comment.