diff --git a/pcsx2-gsrunner/Main.cpp b/pcsx2-gsrunner/Main.cpp index 80a4996a43..93dedcb50a 100644 --- a/pcsx2-gsrunner/Main.cpp +++ b/pcsx2-gsrunner/Main.cpp @@ -77,6 +77,9 @@ static std::string s_output_prefix; static s32 s_loop_count = 1; static std::optional s_use_window; +// Owned by the GS thread. +static u32 s_dump_frame_number = 0; + bool GSRunner::SetCriticalFolders() { EmuFolders::AppRoot = Path::Canonicalize(Path::GetDirectory(FileSystem::GetProgramPath())); @@ -286,6 +289,13 @@ 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 (g_host_display->BeginPresent(frame_skip)) return true; @@ -657,15 +667,8 @@ int main(int argc, char* argv[]) void Host::CPUThreadVSync() { - if (!s_output_prefix.empty()) - { - // wait for the previous frame to complete (and thus dump) - GetMTGS().WaitGS(false, false, false); - - // queue dumping of this frame - std::string dump_path(fmt::format("{}_frame{}.png", s_output_prefix, GSDumpReplayer::GetFrameNumber())); - GetMTGS().RunOnGSThread([dump_path = std::move(dump_path)]() { GSQueueSnapshot(dump_path); }); - } + // update GS thread copy of frame number + GetMTGS().RunOnGSThread([frame_number = GSDumpReplayer::GetFrameNumber()]() { s_dump_frame_number = frame_number; }); // process any window messages (but we shouldn't really have any) GSRunner::PumpPlatformMessages();