From 8d4ffc071345a48a62708ec085c31ffb16878447 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Thu, 21 Oct 2021 23:16:09 -0500 Subject: [PATCH] GSDumpGUI: Add framelimiter --- pcsx2/gui/Dialogs/GSDumpDialog.cpp | 46 ++++++++++++++++++++++++++++-- pcsx2/gui/Dialogs/ModalPopups.h | 8 +++++- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/pcsx2/gui/Dialogs/GSDumpDialog.cpp b/pcsx2/gui/Dialogs/GSDumpDialog.cpp index 9f467931b8..4b4291853b 100644 --- a/pcsx2/gui/Dialogs/GSDumpDialog.cpp +++ b/pcsx2/gui/Dialogs/GSDumpDialog.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -184,6 +185,7 @@ Dialogs::GSDumpDialog::GSDumpDialog(wxWindow* parent) , m_preview_image(new wxStaticBitmap(this, wxID_ANY, wxBitmap(EmbeddedImage().Get()), wxDefaultPosition, wxSize(400,250))) , m_debug_mode(new wxCheckBox(this, ID_DEBUG_MODE, _("Debug Mode"))) , m_renderer_overrides(new wxRadioBox()) + , m_framerate_selector(new wxSpinCtrl(this, ID_FRAMERATE, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 999, 0)) , m_gif_list(new wxTreeCtrl(this, ID_SEL_PACKET, wxDefaultPosition, wxSize(400, 300), wxTR_HIDE_ROOT | wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT)) , m_gif_packet(new wxTreeCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(400, 300), wxTR_HIDE_ROOT | wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT)) , m_start(new wxButton(this, ID_RUN_START, _("Go to Start"), wxDefaultPosition, wxSize(150,50))) @@ -201,6 +203,9 @@ Dialogs::GSDumpDialog::GSDumpDialog(wxWindow* parent) wxBoxSizer* dbg_actions = new wxBoxSizer(wxVERTICAL); wxBoxSizer* gif = new wxBoxSizer(wxVERTICAL); wxBoxSizer* dumps_list = new wxBoxSizer(wxVERTICAL); + wxBoxSizer* framerate_sel = new wxBoxSizer(wxHORIZONTAL); + framerate_sel->Add(new wxStaticText(this, wxID_ANY, _("Framerate:")), wxSizerFlags().Centre()); + framerate_sel->Add(m_framerate_selector, wxSizerFlags(1).Expand()); m_run->SetDefault(); wxArrayString rdoverrides; @@ -228,6 +233,7 @@ Dialogs::GSDumpDialog::GSDumpDialog(wxWindow* parent) dumps_list->Add(new wxStaticText(this, wxID_ANY, _("GS Dumps List")), StdExpand()); dumps_list->Add(m_dump_list, StdExpand()); dump_info->Add(m_renderer_overrides, StdExpand()); + dump_info->Add(framerate_sel, StdExpand()); dump_info->Add(m_settings, StdExpand()); dump_info->Add(m_run, StdExpand()); dump_preview->Add(new wxStaticText(this, wxID_ANY, _("Preview")), StdExpand()); @@ -269,7 +275,10 @@ Dialogs::GSDumpDialog::GSDumpDialog(wxWindow* parent) Bind(wxEVT_BUTTON, &Dialogs::GSDumpDialog::OpenSettings, this, ID_SETTINGS); Bind(wxEVT_TREE_SEL_CHANGED, &Dialogs::GSDumpDialog::ParsePacket, this, ID_SEL_PACKET); Bind(wxEVT_CHECKBOX, &Dialogs::GSDumpDialog::CheckDebug, this, ID_DEBUG_MODE); + Bind(wxEVT_SPINCTRL, &Dialogs::GSDumpDialog::UpdateFramerate, this, ID_FRAMERATE); Bind(EVT_CLOSE_DUMP, &Dialogs::GSDumpDialog::CloseDump, this); + + UpdateFramerate(m_framerate_selector->GetValue()); } void Dialogs::GSDumpDialog::GetDumpsList() @@ -299,6 +308,19 @@ void Dialogs::GSDumpDialog::GetDumpsList() m_dump_list->InsertItem(i, dumps[i]); } +void Dialogs::GSDumpDialog::UpdateFramerate(int val) +{ + if (val) + m_thread->m_frame_ticks = (GetTickFrequency() + (val/2)) / val; + else + m_thread->m_frame_ticks = 0; +} + +void Dialogs::GSDumpDialog::UpdateFramerate(wxCommandEvent& evt) +{ + UpdateFramerate(evt.GetInt()); +} + void Dialogs::GSDumpDialog::SelectedDump(wxListEvent& evt) { wxString filename_preview = g_Conf->Folders.Snapshots.ToAscii() + ("/" + evt.GetText()) + ".png"; @@ -1021,9 +1043,27 @@ void Dialogs::GSDumpDialog::GSThread::ExecuteTaskInThread() } else if (m_root_window->m_dump_packets.size()) { - do - m_root_window->ProcessDumpEvent(m_root_window->m_dump_packets[i++], regs); - while (i < m_root_window->m_dump_packets.size() && m_root_window->m_dump_packets[i].id != GSType::VSync); + while (i < m_root_window->m_dump_packets.size()) + { + GSData& packet = m_root_window->m_dump_packets[i++]; + m_root_window->ProcessDumpEvent(packet, regs); + if (packet.id == GSType::VSync) + { + if (m_frame_ticks) + { + // Frame limiter + u64 now = GetCPUTicks(); + s64 ms = GetTickFrequency() / 1000; + s64 sleep = m_next_frame_time - now - ms; + if (sleep > ms) + Threading::Sleep(sleep / ms); + while ((now = GetCPUTicks()) < m_next_frame_time) + ShortSpin(); + m_next_frame_time = std::max(now, m_next_frame_time + m_frame_ticks); + } + break; + } + } if (i >= m_root_window->m_dump_packets.size()) i = 0; diff --git a/pcsx2/gui/Dialogs/ModalPopups.h b/pcsx2/gui/Dialogs/ModalPopups.h index b601d64c88..f90949ce63 100644 --- a/pcsx2/gui/Dialogs/ModalPopups.h +++ b/pcsx2/gui/Dialogs/ModalPopups.h @@ -108,6 +108,7 @@ namespace Dialogs wxString m_selected_dump; wxCheckBox* m_debug_mode; wxRadioBox* m_renderer_overrides; + wxSpinCtrl* m_framerate_selector; wxTreeCtrl* m_gif_list; wxTreeCtrl* m_gif_packet; wxButton* m_start; @@ -120,6 +121,8 @@ namespace Dialogs wxFileSystemWatcher m_fs_watcher; void GetDumpsList(); + void UpdateFramerate(int val); + void UpdateFramerate(wxCommandEvent& evt); void SelectedDump(wxListEvent& evt); void RunDump(wxCommandEvent& event); void ToStart(wxCommandEvent& event); @@ -140,7 +143,8 @@ namespace Dialogs ID_RUN_VSYNC, ID_SEL_PACKET, ID_DEBUG_MODE, - ID_SETTINGS + ID_SETTINGS, + ID_FRAMERATE, }; // clang-format off @@ -275,6 +279,8 @@ namespace Dialogs public: int m_renderer = 0; + u64 m_frame_ticks = 0; + u64 m_next_frame_time = 0; bool m_debug = false; size_t m_debug_index; std::unique_ptr m_dump_file;