From ddea2818d94b32837f0d7ad33535c7290ee23ef8 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 28 Mar 2021 13:47:10 +1000 Subject: [PATCH] Qt: Add renderer/resolution to status bar --- src/core/gpu.cpp | 6 ++++++ src/core/gpu.h | 3 ++- src/core/gpu_hw.cpp | 5 ----- src/core/gpu_hw.h | 2 -- src/core/gpu_hw_d3d11.cpp | 5 +++++ src/core/gpu_hw_d3d11.h | 2 ++ src/core/gpu_hw_opengl.cpp | 5 +++++ src/core/gpu_hw_opengl.h | 2 ++ src/core/gpu_hw_vulkan.cpp | 5 +++++ src/core/gpu_hw_vulkan.h | 2 ++ src/core/gpu_sw.cpp | 4 ++-- src/core/gpu_sw.h | 2 +- src/duckstation-qt/mainwindow.cpp | 28 ++++++++++++++++++++++++-- src/duckstation-qt/mainwindow.h | 6 +++++- src/duckstation-qt/qthostinterface.cpp | 16 ++++++++++++++- src/duckstation-qt/qthostinterface.h | 6 ++++-- 16 files changed, 82 insertions(+), 17 deletions(-) diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index 4dec13568..f1e85083b 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -63,6 +63,12 @@ void GPU::UpdateSettings() UpdateCRTCDisplayParameters(); } +bool GPU::IsHardwareRenderer() +{ + const GPURenderer renderer = GetRendererType(); + return (renderer != GPURenderer::Software); +} + void GPU::CPUClockChanged() { UpdateCRTCConfig(); diff --git a/src/core/gpu.h b/src/core/gpu.h index a81d0e63d..66c019f2b 100644 --- a/src/core/gpu.h +++ b/src/core/gpu.h @@ -73,7 +73,7 @@ public: GPU(); virtual ~GPU(); - virtual bool IsHardwareRenderer() const = 0; + virtual GPURenderer GetRendererType() const = 0; virtual bool Initialize(HostDisplay* host_display); virtual void Reset(bool clear_vram); @@ -86,6 +86,7 @@ public: // Render statistics debug window. void DrawDebugStateWindow(); + bool IsHardwareRenderer(); void CPUClockChanged(); // MMIO access diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index a41c92d73..b45a1601a 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -36,11 +36,6 @@ GPU_HW::GPU_HW() : GPU() GPU_HW::~GPU_HW() = default; -bool GPU_HW::IsHardwareRenderer() const -{ - return true; -} - bool GPU_HW::Initialize(HostDisplay* host_display) { if (!GPU::Initialize(host_display)) diff --git a/src/core/gpu_hw.h b/src/core/gpu_hw.h index d19703049..2e40b2f39 100644 --- a/src/core/gpu_hw.h +++ b/src/core/gpu_hw.h @@ -29,8 +29,6 @@ public: GPU_HW(); virtual ~GPU_HW(); - virtual bool IsHardwareRenderer() const override; - virtual bool Initialize(HostDisplay* host_display) override; virtual void Reset(bool clear_vram) override; virtual bool DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display) override; diff --git a/src/core/gpu_hw_d3d11.cpp b/src/core/gpu_hw_d3d11.cpp index 2e7a9c10f..9b2a87018 100644 --- a/src/core/gpu_hw_d3d11.cpp +++ b/src/core/gpu_hw_d3d11.cpp @@ -25,6 +25,11 @@ GPU_HW_D3D11::~GPU_HW_D3D11() DestroyStateObjects(); } +GPURenderer GPU_HW_D3D11::GetRendererType() const +{ + return GPURenderer::HardwareD3D11; +} + bool GPU_HW_D3D11::Initialize(HostDisplay* host_display) { if (host_display->GetRenderAPI() != HostDisplay::RenderAPI::D3D11) diff --git a/src/core/gpu_hw_d3d11.h b/src/core/gpu_hw_d3d11.h index fab7a7e7f..eec2867b2 100644 --- a/src/core/gpu_hw_d3d11.h +++ b/src/core/gpu_hw_d3d11.h @@ -20,6 +20,8 @@ public: GPU_HW_D3D11(); ~GPU_HW_D3D11() override; + GPURenderer GetRendererType() const override; + bool Initialize(HostDisplay* host_display) override; void Reset(bool clear_vram) override; bool DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display) override; diff --git a/src/core/gpu_hw_opengl.cpp b/src/core/gpu_hw_opengl.cpp index 06a58c0b5..2e417f44a 100644 --- a/src/core/gpu_hw_opengl.cpp +++ b/src/core/gpu_hw_opengl.cpp @@ -35,6 +35,11 @@ GPU_HW_OpenGL::~GPU_HW_OpenGL() glUseProgram(0); } +GPURenderer GPU_HW_OpenGL::GetRendererType() const +{ + return GPURenderer::HardwareOpenGL; +} + bool GPU_HW_OpenGL::Initialize(HostDisplay* host_display) { if (host_display->GetRenderAPI() != HostDisplay::RenderAPI::OpenGL && diff --git a/src/core/gpu_hw_opengl.h b/src/core/gpu_hw_opengl.h index 35725d0ac..1d6751f7f 100644 --- a/src/core/gpu_hw_opengl.h +++ b/src/core/gpu_hw_opengl.h @@ -16,6 +16,8 @@ public: GPU_HW_OpenGL(); ~GPU_HW_OpenGL() override; + GPURenderer GetRendererType() const override; + bool Initialize(HostDisplay* host_display) override; void Reset(bool clear_vram) override; bool DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display) override; diff --git a/src/core/gpu_hw_vulkan.cpp b/src/core/gpu_hw_vulkan.cpp index ebbd3bf04..8ab248f24 100644 --- a/src/core/gpu_hw_vulkan.cpp +++ b/src/core/gpu_hw_vulkan.cpp @@ -27,6 +27,11 @@ GPU_HW_Vulkan::~GPU_HW_Vulkan() DestroyResources(); } +GPURenderer GPU_HW_Vulkan::GetRendererType() const +{ + return GPURenderer::HardwareVulkan; +} + bool GPU_HW_Vulkan::Initialize(HostDisplay* host_display) { if (host_display->GetRenderAPI() != HostDisplay::RenderAPI::Vulkan) diff --git a/src/core/gpu_hw_vulkan.h b/src/core/gpu_hw_vulkan.h index e74e4d0a0..cb0fe82d9 100644 --- a/src/core/gpu_hw_vulkan.h +++ b/src/core/gpu_hw_vulkan.h @@ -15,6 +15,8 @@ public: GPU_HW_Vulkan(); ~GPU_HW_Vulkan() override; + GPURenderer GetRendererType() const override; + bool Initialize(HostDisplay* host_display) override; void Reset(bool clear_vram) override; bool DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display) override; diff --git a/src/core/gpu_sw.cpp b/src/core/gpu_sw.cpp index 9eed97cd0..26d85b212 100644 --- a/src/core/gpu_sw.cpp +++ b/src/core/gpu_sw.cpp @@ -40,9 +40,9 @@ GPU_SW::~GPU_SW() m_host_display->ClearDisplayTexture(); } -bool GPU_SW::IsHardwareRenderer() const +GPURenderer GPU_SW::GetRendererType() const { - return false; + return GPURenderer::Software; } bool GPU_SW::Initialize(HostDisplay* host_display) diff --git a/src/core/gpu_sw.h b/src/core/gpu_sw.h index 1d14fb3e0..c59db3584 100644 --- a/src/core/gpu_sw.h +++ b/src/core/gpu_sw.h @@ -15,7 +15,7 @@ public: GPU_SW(); ~GPU_SW() override; - bool IsHardwareRenderer() const override; + GPURenderer GetRendererType() const override; bool Initialize(HostDisplay* host_display) override; bool DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display) override; diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index 569daf1ae..409e1e882 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -403,13 +403,19 @@ void MainWindow::onStateSaved(const QString& game_code, bool global, qint32 slot } void MainWindow::onSystemPerformanceCountersUpdated(float speed, float fps, float vps, float average_frame_time, - float worst_frame_time) + float worst_frame_time, GPURenderer renderer, quint32 render_width, + quint32 render_height, bool render_interlaced) { m_status_speed_widget->setText(QStringLiteral("%1%").arg(speed, 0, 'f', 0)); m_status_fps_widget->setText( QStringLiteral("FPS: %1/%2").arg(std::round(fps), 0, 'f', 0).arg(std::round(vps), 0, 'f', 0)); m_status_frame_time_widget->setText( QStringLiteral("%1ms average, %2ms worst").arg(average_frame_time, 0, 'f', 2).arg(worst_frame_time, 0, 'f', 2)); + m_status_renderer_widget->setText(QString::fromUtf8(Settings::GetRendererName(renderer))); + m_status_resolution_widget->setText( + (render_interlaced ? QStringLiteral("%1x%2 (Interlaced)") : QStringLiteral("%1x%2 (Progressive)")) + .arg(render_width) + .arg(render_height)); } void MainWindow::onRunningGameChanged(const QString& filename, const QString& game_code, const QString& game_title) @@ -746,7 +752,7 @@ void MainWindow::setupAdditionalUi() m_status_speed_widget = new QLabel(m_ui.statusBar); m_status_speed_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - m_status_speed_widget->setFixedSize(40, 16); + m_status_speed_widget->setFixedSize(50, 16); m_status_speed_widget->hide(); m_status_fps_widget = new QLabel(m_ui.statusBar); @@ -759,6 +765,16 @@ void MainWindow::setupAdditionalUi() m_status_frame_time_widget->setFixedSize(190, 16); m_status_frame_time_widget->hide(); + m_status_renderer_widget = new QLabel(m_ui.statusBar); + m_status_renderer_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + m_status_renderer_widget->setFixedSize(50, 16); + m_status_renderer_widget->hide(); + + m_status_resolution_widget = new QLabel(m_ui.statusBar); + m_status_resolution_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + m_status_resolution_widget->setFixedSize(140, 16); + m_status_resolution_widget->hide(); + m_ui.actionGridViewShowTitles->setChecked(m_game_list_widget->getShowGridCoverTitles()); updateDebugMenuVisibility(); @@ -867,18 +883,26 @@ void MainWindow::updateEmulationActions(bool starting, bool running, bool cheevo m_status_speed_widget->show(); m_status_fps_widget->show(); m_status_frame_time_widget->show(); + m_status_renderer_widget->show(); + m_status_resolution_widget->show(); m_ui.statusBar->addPermanentWidget(m_status_speed_widget); m_ui.statusBar->addPermanentWidget(m_status_fps_widget); + m_ui.statusBar->addPermanentWidget(m_status_resolution_widget); + m_ui.statusBar->addPermanentWidget(m_status_renderer_widget); m_ui.statusBar->addPermanentWidget(m_status_frame_time_widget); } else if (!running && m_status_speed_widget->isVisible()) { + m_ui.statusBar->removeWidget(m_status_renderer_widget); + m_ui.statusBar->removeWidget(m_status_resolution_widget); m_ui.statusBar->removeWidget(m_status_speed_widget); m_ui.statusBar->removeWidget(m_status_fps_widget); m_ui.statusBar->removeWidget(m_status_frame_time_widget); m_status_speed_widget->hide(); m_status_fps_widget->hide(); m_status_frame_time_widget->hide(); + m_status_renderer_widget->hide(); + m_status_resolution_widget->hide(); } if (starting || running) diff --git a/src/duckstation-qt/mainwindow.h b/src/duckstation-qt/mainwindow.h index 2bfb2be1f..5ade7da59 100644 --- a/src/duckstation-qt/mainwindow.h +++ b/src/duckstation-qt/mainwindow.h @@ -4,6 +4,7 @@ #include #include +#include "core/types.h" #include "settingsdialog.h" #include "ui_mainwindow.h" @@ -70,7 +71,8 @@ private Q_SLOTS: void onEmulationPaused(bool paused); void onStateSaved(const QString& game_code, bool global, qint32 slot); void onSystemPerformanceCountersUpdated(float speed, float fps, float vps, float average_frame_time, - float worst_frame_time); + float worst_frame_time, GPURenderer renderer, quint32 render_width, + quint32 render_height, bool render_interlaced); void onRunningGameChanged(const QString& filename, const QString& game_code, const QString& game_title); void onApplicationStateChanged(Qt::ApplicationState state); @@ -150,6 +152,8 @@ private: QLabel* m_status_speed_widget = nullptr; QLabel* m_status_fps_widget = nullptr; QLabel* m_status_frame_time_widget = nullptr; + QLabel* m_status_renderer_widget = nullptr; + QLabel* m_status_resolution_widget = nullptr; SettingsDialog* m_settings_dialog = nullptr; AutoUpdaterDialog* m_auto_updater_dialog = nullptr; diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index 9061e22a7..5e87f8c7d 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -52,6 +52,7 @@ Log_SetChannel(QtHostInterface); QtHostInterface::QtHostInterface(QObject* parent) : QObject(parent), CommonHostInterface() { qRegisterMetaType>(); + qRegisterMetaType(); } QtHostInterface::~QtHostInterface() @@ -724,8 +725,21 @@ void QtHostInterface::OnSystemPerformanceCountersUpdated() { HostInterface::OnSystemPerformanceCountersUpdated(); + GPURenderer renderer = GPURenderer::Count; + u32 render_width = 0; + u32 render_height = 0; + bool render_interlaced = false; + + if (g_gpu) + { + renderer = g_gpu->GetRendererType(); + std::tie(render_width, render_height) = g_gpu->GetEffectiveDisplayResolution(); + render_interlaced = g_gpu->IsInterlacedDisplayEnabled(); + } + emit systemPerformanceCountersUpdated(System::GetEmulationSpeed(), System::GetFPS(), System::GetVPS(), - System::GetAverageFrameTime(), System::GetWorstFrameTime()); + System::GetAverageFrameTime(), System::GetWorstFrameTime(), renderer, + render_width, render_height, render_interlaced); } void QtHostInterface::OnRunningGameChanged(const std::string& path, CDImage* image, const std::string& game_code, diff --git a/src/duckstation-qt/qthostinterface.h b/src/duckstation-qt/qthostinterface.h index ec0d32a7a..c9b3c33a3 100644 --- a/src/duckstation-qt/qthostinterface.h +++ b/src/duckstation-qt/qthostinterface.h @@ -34,6 +34,7 @@ class MainWindow; class QtDisplayWidget; Q_DECLARE_METATYPE(std::shared_ptr); +Q_DECLARE_METATYPE(GPURenderer); class QtHostInterface final : public QObject, public CommonHostInterface { @@ -134,8 +135,9 @@ Q_SIGNALS: void displaySizeRequested(qint32 width, qint32 height); void focusDisplayWidgetRequested(); void destroyDisplayRequested(); - void systemPerformanceCountersUpdated(float speed, float fps, float vps, float avg_frame_time, - float worst_frame_time); + void systemPerformanceCountersUpdated(float speed, float fps, float vps, float avg_frame_time, float worst_frame_time, + GPURenderer renderer, quint32 render_width, quint32 render_height, + bool render_interlaced); void runningGameChanged(const QString& filename, const QString& game_code, const QString& game_title); void exitRequested(); void inputProfileLoaded();