Frontends: Add frame time performance counters

This commit is contained in:
Connor McLaughlin 2020-01-24 14:49:47 +10:00
parent 67710ca184
commit 9562cbea56
8 changed files with 150 additions and 49 deletions

View File

@ -433,26 +433,43 @@ void HostInterface::UpdateSpeedLimiterState()
m_last_throttle_time = 0;
}
void HostInterface::OnPerformanceCountersUpdated() {}
void HostInterface::RunFrame()
{
m_frame_timer.Reset();
m_system->RunFrame();
UpdatePerformanceCounters();
}
void HostInterface::UpdatePerformanceCounters()
{
if (!m_system)
return;
const float frame_time = static_cast<float>(m_frame_timer.GetTimeMilliseconds());
m_average_frame_time_accumulator += frame_time;
m_worst_frame_time_accumulator = std::max(m_worst_frame_time_accumulator, frame_time);
// update fps counter
const double time = m_fps_timer.GetTimeSeconds();
if (time >= 0.25f)
{
m_vps = static_cast<float>(static_cast<double>(m_system->GetFrameNumber() - m_last_frame_number) / time);
m_last_frame_number = m_system->GetFrameNumber();
m_fps =
static_cast<float>(static_cast<double>(m_system->GetInternalFrameNumber() - m_last_internal_frame_number) / time);
m_last_internal_frame_number = m_system->GetInternalFrameNumber();
m_speed = static_cast<float>(static_cast<double>(m_system->GetGlobalTickCounter() - m_last_global_tick_counter) /
(static_cast<double>(MASTER_CLOCK) * time)) *
100.0f;
m_last_global_tick_counter = m_system->GetGlobalTickCounter();
m_fps_timer.Reset();
}
const float time = static_cast<float>(m_fps_timer.GetTimeSeconds());
if (time < 1.0f)
return;
const float frames_presented = static_cast<float>(m_system->GetFrameNumber() - m_last_frame_number);
m_worst_frame_time = m_worst_frame_time_accumulator;
m_worst_frame_time_accumulator = 0.0f;
m_average_frame_time = m_average_frame_time_accumulator / frames_presented;
m_average_frame_time_accumulator = 0.0f;
m_vps = static_cast<float>(frames_presented / time);
m_last_frame_number = m_system->GetFrameNumber();
m_fps = static_cast<float>(m_system->GetInternalFrameNumber() - m_last_internal_frame_number) / time;
m_last_internal_frame_number = m_system->GetInternalFrameNumber();
m_speed = static_cast<float>(static_cast<double>(m_system->GetGlobalTickCounter() - m_last_global_tick_counter) /
(static_cast<double>(MASTER_CLOCK) * time)) *
100.0f;
m_last_global_tick_counter = m_system->GetGlobalTickCounter();
m_fps_timer.Reset();
OnPerformanceCountersUpdated();
}
void HostInterface::ResetPerformanceCounters()
@ -469,5 +486,7 @@ void HostInterface::ResetPerformanceCounters()
m_last_internal_frame_number = 0;
m_last_global_tick_counter = 0;
}
m_average_frame_time_accumulator = 0.0f;
m_worst_frame_time_accumulator = 0.0f;
m_fps_timer.Reset();
}

View File

@ -72,6 +72,10 @@ protected:
float duration;
};
virtual void OnPerformanceCountersUpdated();
void RunFrame();
/// Throttles the system, i.e. sleeps until it's time to execute the next frame.
void Throttle();
@ -95,18 +99,24 @@ protected:
Common::Timer m_throttle_timer;
Common::Timer m_speed_lost_time_timestamp;
bool m_paused = false;
bool m_speed_limiter_temp_disabled = false;
bool m_speed_limiter_enabled = false;
float m_average_frame_time_accumulator = 0.0f;
float m_worst_frame_time_accumulator = 0.0f;
float m_vps = 0.0f;
float m_fps = 0.0f;
float m_speed = 0.0f;
float m_worst_frame_time = 0.0f;
float m_average_frame_time = 0.0f;
u32 m_last_frame_number = 0;
u32 m_last_internal_frame_number = 0;
u32 m_last_global_tick_counter = 0;
Common::Timer m_fps_timer;
Common::Timer m_frame_timer;
std::deque<OSDMessage> m_osd_messages;
std::mutex m_osd_messages_lock;
bool m_paused = false;
bool m_speed_limiter_temp_disabled = false;
bool m_speed_limiter_enabled = false;
};

View File

@ -6,6 +6,7 @@
#include "qtsettingsinterface.h"
#include "settingsdialog.h"
#include <QtWidgets/QFileDialog>
#include <cmath>
static constexpr char DISC_IMAGE_FILTER[] =
"All File Types (*.bin *.img *.cue *.exe *.psexe);;Single-Track Raw Images (*.bin *.img);;Cue Sheets "
@ -124,6 +125,16 @@ void MainWindow::switchRenderer()
}
}
void MainWindow::onPerformanceCountersUpdated(float speed, float fps, float vps, float average_frame_time,
float worst_frame_time)
{
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));
}
void MainWindow::onStartDiscActionTriggered()
{
QString filename =
@ -183,6 +194,21 @@ void MainWindow::setupAdditionalUi()
m_ui.mainContainer->setCurrentIndex(0);
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->hide();
m_status_fps_widget = new QLabel(m_ui.statusBar);
m_status_fps_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
m_status_fps_widget->setFixedSize(80, 16);
m_status_fps_widget->hide();
m_status_frame_time_widget = new QLabel(m_ui.statusBar);
m_status_frame_time_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
m_status_frame_time_widget->setFixedSize(190, 16);
m_status_frame_time_widget->hide();
for (u32 i = 0; i < static_cast<u32>(GPURenderer::Count); i++)
{
const GPURenderer renderer = static_cast<GPURenderer>(i);
@ -215,6 +241,27 @@ void MainWindow::updateEmulationActions(bool starting, bool running)
m_ui.actionSaveState->setDisabled(starting);
m_ui.actionFullscreen->setDisabled(starting || !running);
if (running && m_status_speed_widget->isHidden())
{
m_status_speed_widget->show();
m_status_fps_widget->show();
m_status_frame_time_widget->show();
m_ui.statusBar->addPermanentWidget(m_status_speed_widget);
m_ui.statusBar->addPermanentWidget(m_status_fps_widget);
m_ui.statusBar->addPermanentWidget(m_status_frame_time_widget);
}
else if (!running && m_status_speed_widget->isVisible())
{
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_ui.statusBar->clearMessage();
}
void MainWindow::switchToGameListView()
@ -259,6 +306,8 @@ void MainWindow::connectSignals()
connect(m_host_interface, &QtHostInterface::emulationStopped, this, &MainWindow::onEmulationStopped);
connect(m_host_interface, &QtHostInterface::emulationPaused, this, &MainWindow::onEmulationPaused);
connect(m_host_interface, &QtHostInterface::toggleFullscreenRequested, this, &MainWindow::toggleFullscreen);
connect(m_host_interface, &QtHostInterface::performanceCountersUpdated, this,
&MainWindow::onPerformanceCountersUpdated);
connect(m_game_list_widget, &GameListWidget::bootEntryRequested, [this](const GameList::GameListEntry* entry) {
// if we're not running, boot the system, otherwise swap discs
@ -274,6 +323,15 @@ void MainWindow::connectSignals()
switchToEmulationView();
}
});
connect(m_game_list_widget, &GameListWidget::entrySelected, [this](const GameList::GameListEntry* entry) {
if (!entry)
{
m_ui.statusBar->clearMessage();
return;
}
m_ui.statusBar->showMessage(QString::fromStdString(entry->path));
});
}
void MainWindow::doSettings(SettingsDialog::Category category)
@ -289,4 +347,4 @@ void MainWindow::doSettings(SettingsDialog::Category category)
if (category != SettingsDialog::Category::Count)
m_settings_dialog->setCategory(category);
}
}

View File

@ -7,6 +7,8 @@
#include "settingsdialog.h"
#include "ui_mainwindow.h"
class QLabel;
class GameList;
class GameListWidget;
class QtHostInterface;
@ -26,6 +28,8 @@ private Q_SLOTS:
void onEmulationPaused(bool paused);
void toggleFullscreen();
void switchRenderer();
void onPerformanceCountersUpdated(float speed, float fps, float vps, float average_frame_time,
float worst_frame_time);
void onStartDiscActionTriggered();
void onChangeDiscActionTriggered();
@ -53,6 +57,10 @@ private:
GameListWidget* m_game_list_widget = nullptr;
QWidget* m_display_widget = nullptr;
QLabel* m_status_speed_widget = nullptr;
QLabel* m_status_fps_widget = nullptr;
QLabel* m_status_frame_time_widget = nullptr;
SettingsDialog* m_settings_dialog = nullptr;
bool m_emulation_running = false;

View File

@ -14,7 +14,7 @@
<string>DuckStation</string>
</property>
<property name="windowIcon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/duck.png</normaloff>:/icons/duck.png</iconset>
</property>
<widget class="QStackedWidget" name="mainContainer">
@ -30,7 +30,7 @@
<x>0</x>
<y>0</y>
<width>754</width>
<height>21</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuSystem">
@ -128,9 +128,10 @@
<addaction name="actionFullscreen"/>
<addaction name="actionSettings"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="actionStartDisc">
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/drive-optical.png</normaloff>:/icons/drive-optical.png</iconset>
</property>
<property name="text">
@ -139,7 +140,7 @@
</action>
<action name="actionStartBios">
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/drive-removable-media.png</normaloff>:/icons/drive-removable-media.png</iconset>
</property>
<property name="text">
@ -148,7 +149,7 @@
</action>
<action name="actionPowerOff">
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/system-shutdown.png</normaloff>:/icons/system-shutdown.png</iconset>
</property>
<property name="text">
@ -157,7 +158,7 @@
</action>
<action name="actionReset">
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/view-refresh.png</normaloff>:/icons/view-refresh.png</iconset>
</property>
<property name="text">
@ -169,7 +170,7 @@
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/media-playback-pause.png</normaloff>:/icons/media-playback-pause.png</iconset>
</property>
<property name="text">
@ -178,7 +179,7 @@
</action>
<action name="actionLoadState">
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/document-open.png</normaloff>:/icons/document-open.png</iconset>
</property>
<property name="text">
@ -187,7 +188,7 @@
</action>
<action name="actionSaveState">
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/document-save.png</normaloff>:/icons/document-save.png</iconset>
</property>
<property name="text">
@ -201,7 +202,7 @@
</action>
<action name="actionConsoleSettings">
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/utilities-system-monitor.png</normaloff>:/icons/utilities-system-monitor.png</iconset>
</property>
<property name="text">
@ -210,7 +211,7 @@
</action>
<action name="actionPortSettings">
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/input-gaming.png</normaloff>:/icons/input-gaming.png</iconset>
</property>
<property name="text">
@ -219,7 +220,7 @@
</action>
<action name="actionHotkeySettings">
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/applications-other.png</normaloff>:/icons/applications-other.png</iconset>
</property>
<property name="text">
@ -228,7 +229,7 @@
</action>
<action name="actionGPUSettings">
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/video-display.png</normaloff>:/icons/video-display.png</iconset>
</property>
<property name="text">
@ -237,7 +238,7 @@
</action>
<action name="actionFullscreen">
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/view-fullscreen.png</normaloff>:/icons/view-fullscreen.png</iconset>
</property>
<property name="text">
@ -290,7 +291,7 @@
</action>
<action name="actionChangeDisc">
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/media-optical.png</normaloff>:/icons/media-optical.png</iconset>
</property>
<property name="text">
@ -299,7 +300,7 @@
</action>
<action name="actionAudioSettings">
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/audio-card.png</normaloff>:/icons/audio-card.png</iconset>
</property>
<property name="text">
@ -308,7 +309,7 @@
</action>
<action name="actionGameListSettings">
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/folder-open.png</normaloff>:/icons/folder-open.png</iconset>
</property>
<property name="text">
@ -317,7 +318,7 @@
</action>
<action name="actionOpenDirectory">
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/edit-find.png</normaloff>:/icons/edit-find.png</iconset>
</property>
<property name="text">
@ -326,7 +327,7 @@
</action>
<action name="actionSettings">
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/applications-system.png</normaloff>:/icons/applications-system.png</iconset>
</property>
<property name="text">
@ -335,7 +336,7 @@
</action>
</widget>
<resources>
<include location="icons.qrc"/>
<include location="resources/icons.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -185,6 +185,13 @@ void QtHostInterface::onDisplayWindowResized(int width, int height)
m_display_window->onWindowResized(width, height);
}
void QtHostInterface::OnPerformanceCountersUpdated()
{
HostInterface::OnPerformanceCountersUpdated();
emit performanceCountersUpdated(m_speed, m_fps, m_vps, m_average_frame_time, m_worst_frame_time);
}
void QtHostInterface::updateInputMap()
{
if (!isOnWorkerThread())
@ -508,8 +515,7 @@ void QtHostInterface::threadEntryPoint()
// execute the system, polling events inbetween frames
// simulate the system if not paused
if (m_system && !m_paused)
m_system->RunFrame();
RunFrame();
// rendering
{
@ -519,7 +525,6 @@ void QtHostInterface::threadEntryPoint()
m_system->GetGPU()->ResetGraphicsAPIState();
}
DrawFPSWindow();
DrawOSDMessages();
m_display->Render();
@ -531,8 +536,6 @@ void QtHostInterface::threadEntryPoint()
if (m_speed_limiter_enabled)
Throttle();
}
UpdatePerformanceCounters();
}
m_worker_thread_event_loop->processEvents(QEventLoop::AllEvents);

View File

@ -71,6 +71,7 @@ Q_SIGNALS:
void gameListRefreshed();
void toggleFullscreenRequested();
void switchRendererRequested();
void performanceCountersUpdated(float speed, float fps, float vps, float avg_frame_time, float worst_frame_time);
public Q_SLOTS:
void powerOffSystem();
@ -87,6 +88,9 @@ private Q_SLOTS:
void doHandleKeyEvent(int key, bool pressed);
void onDisplayWindowResized(int width, int height);
protected:
void OnPerformanceCountersUpdated() override;
private:
using InputButtonHandler = std::function<void(bool)>;

View File

@ -1614,7 +1614,7 @@ void SDLHostInterface::Run()
if (m_system && !m_paused)
{
m_system->RunFrame();
RunFrame();
if (m_frame_step_request)
{
m_frame_step_request = false;
@ -1644,8 +1644,6 @@ void SDLHostInterface::Run()
Throttle();
}
}
UpdatePerformanceCounters();
}
// Save state on exit so it can be resumed