From 8c3c9a121979c5b9823fba211504272a7e0534f4 Mon Sep 17 00:00:00 2001 From: refractionpcsx2 Date: Tue, 7 Feb 2023 20:12:13 +0000 Subject: [PATCH] GSDumpRunner: Tweaks to reduce console messages and redundant frame dumps --- pcsx2-gsrunner/Main.cpp | 17 +++++++++++------ pcsx2/GS/Renderers/Common/GSRenderer.cpp | 10 +++++++--- pcsx2/GSDumpReplayer.cpp | 16 ++++++++++++++++ pcsx2/GSDumpReplayer.h | 3 +++ 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/pcsx2-gsrunner/Main.cpp b/pcsx2-gsrunner/Main.cpp index 82fee15521..c123033c35 100644 --- a/pcsx2-gsrunner/Main.cpp +++ b/pcsx2-gsrunner/Main.cpp @@ -79,6 +79,7 @@ static std::optional s_use_window; // Owned by the GS thread. static u32 s_dump_frame_number = 0; +static u32 s_loop_number = s_loop_count; bool GSRunner::InitializeConfig() { @@ -273,13 +274,15 @@ void Host::ReleaseHostDisplay(bool clear_state) bool Host::BeginPresentFrame(bool frame_skip) { - // when we wrap around, don't race other files - GSJoinSnapshotThreads(); - - // queue dumping of this frame - std::string dump_path(fmt::format("{}_frame{}.png", s_output_prefix, s_dump_frame_number)); - GSQueueSnapshot(dump_path); + if (s_loop_number == 0) + { + // when we wrap around, don't race other files + GSJoinSnapshotThreads(); + // queue dumping of this frame + std::string dump_path(fmt::format("{}_frame{}.png", s_output_prefix, s_dump_frame_number)); + GSQueueSnapshot(dump_path); + } if (g_host_display->BeginPresent(frame_skip)) return true; @@ -627,6 +630,7 @@ int main(int argc, char* argv[]) // apply new settings (e.g. pick up renderer change) VMManager::ApplySettings(); + GSDumpReplayer::SetIsDumpRunner(true); if (VMManager::Initialize(params)) { @@ -651,6 +655,7 @@ void Host::CPUThreadVSync() { // update GS thread copy of frame number GetMTGS().RunOnGSThread([frame_number = GSDumpReplayer::GetFrameNumber()]() { s_dump_frame_number = frame_number; }); + GetMTGS().RunOnGSThread([loop_number = GSDumpReplayer::GetLoopCount()]() { s_loop_number = loop_number; }); // process any window messages (but we shouldn't really have any) GSRunner::PumpPlatformMessages(); diff --git a/pcsx2/GS/Renderers/Common/GSRenderer.cpp b/pcsx2/GS/Renderers/Common/GSRenderer.cpp index ab9f5bb555..a16b15fc62 100644 --- a/pcsx2/GS/Renderers/Common/GSRenderer.cpp +++ b/pcsx2/GS/Renderers/Common/GSRenderer.cpp @@ -17,6 +17,7 @@ #include "GSRenderer.h" #include "GS/GSCapture.h" #include "GS/GSGL.h" +#include "GSDumpReplayer.h" #include "Host.h" #include "HostDisplay.h" #include "PerformanceMetrics.h" @@ -554,15 +555,18 @@ static void CompressAndWriteScreenshot(std::string filename, u32 width, u32 heig image.SetPixels(width, height, std::move(pixels)); std::string key(fmt::format("GSScreenshot_{}", filename)); - Host::AddIconOSDMessage(key, ICON_FA_CAMERA, fmt::format("Saving screenshot to '{}'.", Path::GetFileName(filename)), 60.0f); + + if(!GSDumpReplayer::IsRunner()) + Host::AddIconOSDMessage(key, ICON_FA_CAMERA, fmt::format("Saving screenshot to '{}'.", Path::GetFileName(filename)), 60.0f); // maybe std::async would be better here.. but it's definitely worth threading, large screenshots take a while to compress. std::unique_lock lock(s_screenshot_threads_mutex); s_screenshot_threads.emplace_back([key = std::move(key), filename = std::move(filename), image = std::move(image), quality = GSConfig.ScreenshotQuality]() { if (image.SaveToFile(filename.c_str(), quality)) { - Host::AddIconOSDMessage(std::move(key), ICON_FA_CAMERA, - fmt::format("Saved screenshot to '{}'.", Path::GetFileName(filename)), Host::OSD_INFO_DURATION); + if(!GSDumpReplayer::IsRunner()) + Host::AddIconOSDMessage(std::move(key), ICON_FA_CAMERA, + fmt::format("Saved screenshot to '{}'.", Path::GetFileName(filename)), Host::OSD_INFO_DURATION); } else { diff --git a/pcsx2/GSDumpReplayer.cpp b/pcsx2/GSDumpReplayer.cpp index 66d180d2f7..2781ca7ef4 100644 --- a/pcsx2/GSDumpReplayer.cpp +++ b/pcsx2/GSDumpReplayer.cpp @@ -58,6 +58,7 @@ static bool s_dump_running = false; static bool s_needs_state_loaded = false; static u64 s_frame_ticks = 0; static u64 s_next_frame_time = 0; +static bool s_is_dump_runner = false; R5900cpu GSDumpReplayerCpu = { GSDumpReplayerCpuReserve, @@ -77,11 +78,26 @@ bool GSDumpReplayer::IsReplayingDump() return static_cast(s_dump_file); } +bool GSDumpReplayer::IsRunner() +{ + return s_is_dump_runner; +} + +void GSDumpReplayer::SetIsDumpRunner(bool is_runner) +{ + s_is_dump_runner = is_runner; +} + void GSDumpReplayer::SetLoopCount(s32 loop_count) { s_dump_loop_count = loop_count - 1; } +int GSDumpReplayer::GetLoopCount() +{ + return s_dump_loop_count; +} + bool GSDumpReplayer::Initialize(const char* filename) { Common::Timer timer; diff --git a/pcsx2/GSDumpReplayer.h b/pcsx2/GSDumpReplayer.h index cd95d64ae7..fc78944a64 100644 --- a/pcsx2/GSDumpReplayer.h +++ b/pcsx2/GSDumpReplayer.h @@ -25,6 +25,9 @@ bool IsReplayingDump(); /// If set, playback will repeat once it reaches the last frame. void SetLoopCount(s32 loop_count = 0); +int GetLoopCount(); +bool IsRunner(); +void SetIsDumpRunner(bool is_runner); bool Initialize(const char* filename); void Reset();