From 10a46a7fd84e012a6aba29f2a19585057bd75035 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 16 Aug 2020 00:17:10 +1000 Subject: [PATCH] OSD: Add option to show display resolution --- src/core/gpu.cpp | 5 +++ src/core/gpu.h | 39 +++++++++-------- src/core/gpu_hw.cpp | 6 +++ src/core/gpu_hw.h | 4 +- src/core/host_interface.cpp | 1 + src/core/settings.cpp | 2 + src/core/settings.h | 1 + src/duckstation-qt/generalsettingswidget.cpp | 1 + src/duckstation-qt/generalsettingswidget.ui | 7 ++++ src/frontend-common/common_host_interface.cpp | 42 ++++++++++++------- 10 files changed, 73 insertions(+), 35 deletions(-) diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index 0ff029eee..7b3595350 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -59,6 +59,11 @@ void GPU::UpdateSettings() void GPU::UpdateResolutionScale() {} +std::tuple GPU::GetEffectiveDisplayResolution() +{ + return std::tie(m_crtc_state.display_vram_width, m_crtc_state.display_vram_height); +} + void GPU::Reset() { SoftReset(); diff --git a/src/core/gpu.h b/src/core/gpu.h index 274265b34..15ec797bb 100644 --- a/src/core/gpu.h +++ b/src/core/gpu.h @@ -144,6 +144,24 @@ public: } void EndDMAWrite(); + /// Returns false if the DAC is loading any data from VRAM. + ALWAYS_INLINE bool IsDisplayDisabled() const + { + return m_GPUSTAT.display_disable || m_crtc_state.display_vram_width == 0 || m_crtc_state.display_vram_height == 0; + } + + /// Returns true if scanout should be interlaced. + ALWAYS_INLINE bool IsInterlacedDisplayEnabled() const + { + return (!m_force_progressive_scan) & m_GPUSTAT.vertical_interlace; + } + + /// Returns true if interlaced rendering is enabled and force progressive scan is disabled. + ALWAYS_INLINE bool IsInterlacedRenderingEnabled() const + { + return (!m_force_progressive_scan) & m_GPUSTAT.SkipDrawingToActiveField(); + } + /// Returns the number of pending GPU ticks. TickCount GetPendingCRTCTicks() const; TickCount GetPendingCommandTicks() const; @@ -163,6 +181,9 @@ public: /// Updates the resolution scale when it's set to automatic. virtual void UpdateResolutionScale(); + /// Returns the effective display resolution of the GPU. + virtual std::tuple GetEffectiveDisplayResolution(); + // gpu_hw_d3d11.cpp static std::unique_ptr CreateHardwareD3D11Renderer(); @@ -367,24 +388,6 @@ protected: void CRTCTickEvent(TickCount ticks); void CommandTickEvent(TickCount ticks); - /// Returns false if the DAC is loading any data from VRAM. - ALWAYS_INLINE bool IsDisplayDisabled() const - { - return m_GPUSTAT.display_disable || m_crtc_state.display_vram_width == 0 || m_crtc_state.display_vram_height == 0; - } - - /// Returns true if scanout should be interlaced. - ALWAYS_INLINE bool IsInterlacedDisplayEnabled() const - { - return (!m_force_progressive_scan) & m_GPUSTAT.vertical_interlace; - } - - /// Returns true if interlaced rendering is enabled and force progressive scan is disabled. - ALWAYS_INLINE bool IsInterlacedRenderingEnabled() const - { - return (!m_force_progressive_scan) & m_GPUSTAT.SkipDrawingToActiveField(); - } - /// Returns 0 if the currently-displayed field is on odd lines (1,3,5,...) or 1 if even (2,4,6,...). ALWAYS_INLINE u32 GetInterlacedDisplayField() const { return ZeroExtend32(m_crtc_state.interlaced_field); } diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index 3d1601be8..7dfe6f432 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -134,6 +134,12 @@ void GPU_HW::UpdateResolutionScale() UpdateSettings(); } +std::tuple GPU_HW::GetEffectiveDisplayResolution() +{ + return std::make_tuple(m_crtc_state.display_vram_width * m_resolution_scale, + m_resolution_scale * m_crtc_state.display_vram_height); +} + void GPU_HW::PrintSettingsToLog() { Log_InfoPrintf("Resolution Scale: %u (%ux%u), maximum %u", m_resolution_scale, VRAM_WIDTH * m_resolution_scale, diff --git a/src/core/gpu_hw.h b/src/core/gpu_hw.h index 377108f8f..2b6141db3 100644 --- a/src/core/gpu_hw.h +++ b/src/core/gpu_hw.h @@ -34,7 +34,9 @@ public: virtual bool Initialize(HostDisplay* host_display) override; virtual void Reset() override; virtual bool DoState(StateWrapper& sw) override; - virtual void UpdateResolutionScale() override; + + void UpdateResolutionScale() override final; + std::tuple GetEffectiveDisplayResolution() override final; protected: enum : u32 diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index 7fdd83b9f..e72cb1fa1 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -385,6 +385,7 @@ void HostInterface::SetDefaultSettings(SettingsInterface& si) si.SetBoolValue("Display", "ShowFPS", false); si.SetBoolValue("Display", "ShowVPS", false); si.SetBoolValue("Display", "ShowSpeed", false); + si.SetBoolValue("Display", "ShowResolution", false); si.SetBoolValue("Display", "Fullscreen", false); si.SetBoolValue("Display", "VSync", true); diff --git a/src/core/settings.cpp b/src/core/settings.cpp index ecae7daf3..9458112fb 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -121,6 +121,7 @@ void Settings::Load(SettingsInterface& si) display_show_fps = si.GetBoolValue("Display", "ShowFPS", false); display_show_vps = si.GetBoolValue("Display", "ShowVPS", false); display_show_speed = si.GetBoolValue("Display", "ShowSpeed", false); + display_show_resolution = si.GetBoolValue("Display", "ShowResolution", false); video_sync_enabled = si.GetBoolValue("Display", "VSync", true); cdrom_read_thread = si.GetBoolValue("CDROM", "ReadThread", true); @@ -223,6 +224,7 @@ void Settings::Save(SettingsInterface& si) const si.SetBoolValue("Display", "ShowFPS", display_show_fps); si.SetBoolValue("Display", "ShowVPS", display_show_vps); si.SetBoolValue("Display", "ShowSpeed", display_show_speed); + si.SetBoolValue("Display", "ShowResolution", display_show_speed); si.SetBoolValue("Display", "VSync", video_sync_enabled); si.SetBoolValue("CDROM", "ReadThread", cdrom_read_thread); diff --git a/src/core/settings.h b/src/core/settings.h index c936b5e88..ba8ead79a 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -101,6 +101,7 @@ struct Settings bool display_show_fps = false; bool display_show_vps = false; bool display_show_speed = false; + bool display_show_resolution = false; bool video_sync_enabled = true; bool cdrom_read_thread = true; diff --git a/src/duckstation-qt/generalsettingswidget.cpp b/src/duckstation-qt/generalsettingswidget.cpp index 2f3d4e67d..ec44232d6 100644 --- a/src/duckstation-qt/generalsettingswidget.cpp +++ b/src/duckstation-qt/generalsettingswidget.cpp @@ -21,6 +21,7 @@ GeneralSettingsWidget::GeneralSettingsWidget(QtHostInterface* host_interface, QW SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showFPS, "Display", "ShowFPS", false); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showVPS, "Display", "ShowVPS", false); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showSpeed, "Display", "ShowSpeed", false); + SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showResolution, "Display", "ShowResolution", false); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.enableSpeedLimiter, "Main", "SpeedLimiterEnabled", true); diff --git a/src/duckstation-qt/generalsettingswidget.ui b/src/duckstation-qt/generalsettingswidget.ui index 1ea502e73..09b29791c 100644 --- a/src/duckstation-qt/generalsettingswidget.ui +++ b/src/duckstation-qt/generalsettingswidget.ui @@ -173,6 +173,13 @@ + + + + Show Resolution + + + diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index 8721a7817..748a709e4 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -723,11 +723,14 @@ void CommonHostInterface::DrawImGuiWindows() void CommonHostInterface::DrawFPSWindow() { - if (!(g_settings.display_show_fps | g_settings.display_show_vps | g_settings.display_show_speed)) + if (!(g_settings.display_show_fps | g_settings.display_show_vps | g_settings.display_show_speed | + g_settings.display_show_resolution)) + { return; + } const ImVec2 window_size = - ImVec2(175.0f * ImGui::GetIO().DisplayFramebufferScale.x, 16.0f * ImGui::GetIO().DisplayFramebufferScale.y); + ImVec2(175.0f * ImGui::GetIO().DisplayFramebufferScale.x, 48.0f * ImGui::GetIO().DisplayFramebufferScale.y); ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x - window_size.x, 0.0f), ImGuiCond_Always); ImGui::SetNextWindowSize(window_size); @@ -784,6 +787,13 @@ void CommonHostInterface::DrawFPSWindow() ImGui::TextColored(ImVec4(0.4f, 1.0f, 0.4f, 1.0f), "%u%%", rounded_speed); } + if (g_settings.display_show_resolution) + { + const auto [effective_width, effective_height] = g_gpu->GetEffectiveDisplayResolution(); + const bool interlaced = g_gpu->IsInterlacedDisplayEnabled(); + ImGui::Text("%ux%u (%s)", effective_width, effective_height, interlaced ? "interlaced" : "progressive"); + } + ImGui::End(); } @@ -1297,22 +1307,22 @@ void CommonHostInterface::RegisterGraphicsHotkeys() ToggleSoftwareRendering(); }); - RegisterHotkey(StaticString("Graphics"), StaticString("TogglePGXP"), StaticString("Toggle PGXP"), - [this](bool pressed) { - if (!pressed) - { - g_settings.gpu_pgxp_enable = !g_settings.gpu_pgxp_enable; - g_gpu->UpdateSettings(); - AddFormattedOSDMessage(5.0f, "PGXP is now %s.", g_settings.gpu_pgxp_enable ? "enabled" : "disabled"); + RegisterHotkey( + StaticString("Graphics"), StaticString("TogglePGXP"), StaticString("Toggle PGXP"), [this](bool pressed) { + if (!pressed) + { + g_settings.gpu_pgxp_enable = !g_settings.gpu_pgxp_enable; + g_gpu->UpdateSettings(); + AddFormattedOSDMessage(5.0f, "PGXP is now %s.", g_settings.gpu_pgxp_enable ? "enabled" : "disabled"); - if (g_settings.gpu_pgxp_enable) - PGXP::Initialize(); + if (g_settings.gpu_pgxp_enable) + PGXP::Initialize(); - // we need to recompile all blocks if pgxp is toggled on/off - if (g_settings.IsUsingCodeCache()) - CPU::CodeCache::Flush(); - } - }); + // we need to recompile all blocks if pgxp is toggled on/off + if (g_settings.IsUsingCodeCache()) + CPU::CodeCache::Flush(); + } + }); RegisterHotkey(StaticString("Graphics"), StaticString("IncreaseResolutionScale"), StaticString("Increase Resolution Scale"), [this](bool pressed) {