From db7f3f8f250987c243d5dfc1f92aa730e7326c84 Mon Sep 17 00:00:00 2001 From: Minty-Meeo <45425365+Minty-Meeo@users.noreply.github.com> Date: Thu, 18 Mar 2021 22:31:28 -0500 Subject: [PATCH] Apply More Core::RunAsCPUThread In places where applicable, Core::RunAsCPUThread has replaced Core::SetState workarounds to pause and resume emulation for thread-sensitive operations. - void Core::SaveScreenShot() - void Core::SaveScreenShot(std::string_view name) - void JitInterface::GetProfileResults(Profiler::ProfileStats *prof_stats) - void MainWindow::OnExportRecording() --- Source/Core/Core/Core.cpp | 20 +++----------- Source/Core/Core/PowerPC/JitInterface.cpp | 32 ++++++++++------------- Source/Core/DolphinQt/MainWindow.cpp | 19 +++++--------- 3 files changed, 24 insertions(+), 47 deletions(-) diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index 99e7624b55..7a67af3018 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -732,26 +732,14 @@ static std::string GenerateScreenshotName() void SaveScreenShot() { - const bool bPaused = GetState() == State::Paused; - - SetState(State::Paused); - - g_renderer->SaveScreenshot(GenerateScreenshotName()); - - if (!bPaused) - SetState(State::Running); + Core::RunAsCPUThread([] { g_renderer->SaveScreenshot(GenerateScreenshotName()); }); } void SaveScreenShot(std::string_view name) { - const bool bPaused = GetState() == State::Paused; - - SetState(State::Paused); - - g_renderer->SaveScreenshot(fmt::format("{}{}.png", GenerateScreenshotFolderPath(), name)); - - if (!bPaused) - SetState(State::Running); + Core::RunAsCPUThread([&name] { + g_renderer->SaveScreenshot(fmt::format("{}{}.png", GenerateScreenshotFolderPath(), name)); + }); } void RequestRefreshInfo() diff --git a/Source/Core/Core/PowerPC/JitInterface.cpp b/Source/Core/Core/PowerPC/JitInterface.cpp index 33c481fdf5..e36b27314c 100644 --- a/Source/Core/Core/PowerPC/JitInterface.cpp +++ b/Source/Core/Core/PowerPC/JitInterface.cpp @@ -131,26 +131,22 @@ void GetProfileResults(Profiler::ProfileStats* prof_stats) prof_stats->timecost_sum = 0; prof_stats->block_stats.clear(); - Core::State old_state = Core::GetState(); - if (old_state == Core::State::Running) - Core::SetState(Core::State::Paused); + Core::RunAsCPUThread([&prof_stats] { + QueryPerformanceFrequency((LARGE_INTEGER*)&prof_stats->countsPerSec); + g_jit->GetBlockCache()->RunOnBlocks([&prof_stats](const JitBlock& block) { + const auto& data = block.profile_data; + u64 cost = data.downcountCounter; + u64 timecost = data.ticCounter; + // Todo: tweak. + if (data.runCount >= 1) + prof_stats->block_stats.emplace_back(block.effectiveAddress, cost, timecost, data.runCount, + block.codeSize); + prof_stats->cost_sum += cost; + prof_stats->timecost_sum += timecost; + }); - QueryPerformanceFrequency((LARGE_INTEGER*)&prof_stats->countsPerSec); - g_jit->GetBlockCache()->RunOnBlocks([&prof_stats](const JitBlock& block) { - const auto& data = block.profile_data; - u64 cost = data.downcountCounter; - u64 timecost = data.ticCounter; - // Todo: tweak. - if (data.runCount >= 1) - prof_stats->block_stats.emplace_back(block.effectiveAddress, cost, timecost, data.runCount, - block.codeSize); - prof_stats->cost_sum += cost; - prof_stats->timecost_sum += timecost; + sort(prof_stats->block_stats.begin(), prof_stats->block_stats.end()); }); - - sort(prof_stats->block_stats.begin(), prof_stats->block_stats.end()); - if (old_state == Core::State::Running) - Core::SetState(Core::State::Running); } int GetHostCode(u32* address, const u8** code, u32* code_size) diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index 43dc09f9e9..afe1c2a07b 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -1675,19 +1675,12 @@ void MainWindow::OnStopRecording() void MainWindow::OnExportRecording() { - bool was_paused = Core::GetState() == Core::State::Paused; - - if (!was_paused) - Core::SetState(Core::State::Paused); - - QString dtm_file = QFileDialog::getSaveFileName(this, tr("Select the Recording File"), QString(), - tr("Dolphin TAS Movies (*.dtm)")); - - if (!dtm_file.isEmpty()) - Movie::SaveRecording(dtm_file.toStdString()); - - if (!was_paused) - Core::SetState(Core::State::Running); + Core::RunAsCPUThread([this] { + QString dtm_file = QFileDialog::getSaveFileName(this, tr("Select the Recording File"), + QString(), tr("Dolphin TAS Movies (*.dtm)")); + if (!dtm_file.isEmpty()) + Movie::SaveRecording(dtm_file.toStdString()); + }); } void MainWindow::OnActivateChat()