This commit is contained in:
Jordan Woyak 2025-04-27 01:27:36 -05:00 committed by GitHub
commit 5251d15306
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View file

@ -28,6 +28,7 @@
#include "VideoCommon/PerformanceMetrics.h" #include "VideoCommon/PerformanceMetrics.h"
#include "VideoCommon/VideoBackendBase.h" #include "VideoCommon/VideoBackendBase.h"
#include "VideoCommon/VideoConfig.h" #include "VideoCommon/VideoConfig.h"
#include "VideoCommon/VideoEvents.h"
namespace CoreTiming namespace CoreTiming
{ {
@ -103,6 +104,13 @@ void CoreTimingManager::Init()
m_event_fifo_id = 0; m_event_fifo_id = 0;
m_ev_lost = RegisterEvent("_lost_event", &EmptyTimedCallback); m_ev_lost = RegisterEvent("_lost_event", &EmptyTimedCallback);
m_throttled_since_presentation = false;
m_frame_hook = AfterPresentEvent::Register(
[this](const PresentInfo&) {
m_throttled_since_presentation.store(false, std::memory_order_relaxed);
},
"CoreTiming AfterPresentEvent");
} }
void CoreTimingManager::Shutdown() void CoreTimingManager::Shutdown()
@ -112,6 +120,7 @@ void CoreTimingManager::Shutdown()
ClearPendingEvents(); ClearPendingEvents();
UnregisterAllEvents(); UnregisterAllEvents();
CPUThreadConfigCallback::RemoveConfigChangedCallback(m_registered_config_callback_id); CPUThreadConfigCallback::RemoveConfigChangedCallback(m_registered_config_callback_id);
m_frame_hook.reset();
} }
void CoreTimingManager::RefreshConfig() void CoreTimingManager::RefreshConfig()
@ -399,6 +408,21 @@ void CoreTimingManager::SleepUntil(TimePoint time_point)
void CoreTimingManager::Throttle(const s64 target_cycle) void CoreTimingManager::Throttle(const s64 target_cycle)
{ {
const TimePoint time = Clock::now();
const bool already_throttled =
m_throttled_since_presentation.exchange(true, std::memory_order_relaxed);
// When Immediate XFB is enabled, try to Throttle just once since each presentation.
// This lowers latency by speeding through to the next presentation after grabbing input.
// Make sure we don't get too far ahead of proper timing though,
// otherwise the emulator unreasonably speeds through loading screens that don't have XFB copies.
const bool skip_throttle = already_throttled && g_ActiveConfig.bImmediateXFB &&
((GetTargetHostTime(target_cycle) - time) < (m_max_fallback / 2));
if (skip_throttle)
return;
// Based on number of cycles and emulation speed, increase the target deadline // Based on number of cycles and emulation speed, increase the target deadline
const s64 cycles = target_cycle - m_throttle_last_cycle; const s64 cycles = target_cycle - m_throttle_last_cycle;
m_throttle_last_cycle = target_cycle; m_throttle_last_cycle = target_cycle;
@ -409,7 +433,6 @@ void CoreTimingManager::Throttle(const s64 target_cycle)
m_throttle_deadline += m_throttle_deadline +=
std::chrono::duration_cast<DT>(DT_s(cycles) / (speed * m_throttle_clock_per_sec)); std::chrono::duration_cast<DT>(DT_s(cycles) / (speed * m_throttle_clock_per_sec));
const TimePoint time = Clock::now();
const TimePoint min_deadline = time - m_max_fallback; const TimePoint min_deadline = time - m_max_fallback;
const TimePoint max_deadline = time + m_max_fallback; const TimePoint max_deadline = time + m_max_fallback;

View file

@ -23,6 +23,7 @@
#include <vector> #include <vector>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/HookableEvent.h"
#include "Common/SPSCQueue.h" #include "Common/SPSCQueue.h"
#include "Common/Timer.h" #include "Common/Timer.h"
#include "Core/CPUThreadConfigCallback.h" #include "Core/CPUThreadConfigCallback.h"
@ -219,6 +220,9 @@ private:
std::atomic_bool m_use_precision_timer = false; std::atomic_bool m_use_precision_timer = false;
Common::PrecisionTimer m_precision_cpu_timer; Common::PrecisionTimer m_precision_cpu_timer;
Common::PrecisionTimer m_precision_gpu_timer; Common::PrecisionTimer m_precision_gpu_timer;
Common::EventHook m_frame_hook;
std::atomic<bool> m_throttled_since_presentation = false;
}; };
} // namespace CoreTiming } // namespace CoreTiming