GSRunner: Kick screenshots on the GS thread

Instead of from the "CPU" thread.
This commit is contained in:
Connor McLaughlin 2022-12-12 22:17:26 +10:00 committed by refractionpcsx2
parent 06081ca18b
commit fa2db10e44
1 changed files with 12 additions and 9 deletions

View File

@ -77,6 +77,9 @@ static std::string s_output_prefix;
static s32 s_loop_count = 1;
static std::optional<bool> 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();