diff --git a/src/common/timer.cpp b/src/common/timer.cpp index 92eea500..ac8a0928 100644 --- a/src/common/timer.cpp +++ b/src/common/timer.cpp @@ -15,23 +15,10 @@ namespace Common { #ifdef _WIN32 static double s_counter_frequency; -static bool s_counter_initialized = false; - -static HANDLE GetSleepTimer(void) -{ - // This gets leaked... oh well. - static thread_local HANDLE s_sleep_timer; - static thread_local bool s_sleep_timer_created = false; - if (s_sleep_timer_created) - return s_sleep_timer; - - s_sleep_timer_created = true; - s_sleep_timer = CreateWaitableTimer(nullptr, TRUE, nullptr); - return s_sleep_timer; -} Timer::Value Timer::GetValue(void) { + static bool s_counter_initialized = false; // even if this races, it should still result in the same value.. if (!s_counter_initialized) { @@ -65,57 +52,7 @@ Timer::Value Timer::ConvertSecondsToValue(double s) { return static_cast((s * 1000000000.0) * s_counter_frequency); } - -Timer::Value Timer::ConvertMillisecondsToValue(double ms) -{ - return static_cast((ms * 1000000.0) * s_counter_frequency); -} - -Timer::Value Timer::ConvertNanosecondsToValue(double ns) -{ - return static_cast(ns * s_counter_frequency); -} - -void Timer::SleepUntil(Value value, bool exact) -{ - if (exact) - { - while (GetValue() < value) - SleepUntil(value, false); - } - else - { - const std::int64_t diff = static_cast(value - GetValue()); - if (diff <= 0) - return; - -#ifndef _UWP - HANDLE timer = GetSleepTimer(); - if (timer) - { - FILETIME ft; - GetSystemTimeAsFileTime(&ft); - - LARGE_INTEGER fti; - fti.LowPart = ft.dwLowDateTime; - fti.HighPart = ft.dwHighDateTime; - fti.QuadPart += diff; - - if (SetWaitableTimer(timer, &fti, 0, nullptr, nullptr, FALSE)) - { - WaitForSingleObject(timer, INFINITE); - return; - } - } -#endif - - // falling back to sleep... bad. - Sleep(static_cast(static_cast(diff) / 1000000)); - } -} - #else - Timer::Value Timer::GetValue(void) { struct timespec tv; @@ -142,46 +79,6 @@ Timer::Value Timer::ConvertSecondsToValue(double s) { return static_cast(s * 1000000000.0); } - -Timer::Value Timer::ConvertMillisecondsToValue(double ms) -{ - return static_cast(ms * 1000000.0); -} - -Timer::Value Timer::ConvertNanosecondsToValue(double ns) -{ - return static_cast(ns); -} - -void Timer::SleepUntil(Value value, bool exact) -{ - if (exact) - { - while (GetValue() < value) - SleepUntil(value, false); - } - else - { - // Apple doesn't have TIMER_ABSTIME, so fall back to nanosleep in such a case. -#ifdef __APPLE__ - const Value current_time = GetValue(); - if (value <= current_time) - return; - - const Value diff = value - current_time; - struct timespec ts; - ts.tv_sec = diff / UINT64_C(1000000000); - ts.tv_nsec = diff % UINT64_C(1000000000); - nanosleep(&ts, nullptr); -#else - struct timespec ts; - ts.tv_sec = value / UINT64_C(1000000000); - ts.tv_nsec = value % UINT64_C(1000000000); - clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, nullptr); -#endif - } -} - #endif Timer::Timer() diff --git a/src/common/timer.h b/src/common/timer.h index 4ee3d67f..f1da4744 100644 --- a/src/common/timer.h +++ b/src/common/timer.h @@ -15,9 +15,6 @@ public: static double ConvertValueToMilliseconds(Value value); static double ConvertValueToNanoseconds(Value value); static Value ConvertSecondsToValue(double s); - static Value ConvertMillisecondsToValue(double s); - static Value ConvertNanosecondsToValue(double ns); - static void SleepUntil(Value value, bool exact); void Reset(void); diff --git a/src/core/gpu_backend.cpp b/src/core/gpu_backend.cpp index 42673e31..50718e2c 100644 --- a/src/core/gpu_backend.cpp +++ b/src/core/gpu_backend.cpp @@ -224,10 +224,9 @@ void GPUBackend::RunGPULoop() m_wake_gpu_thread_cv.wait(lock, [this]() { return m_gpu_loop_done.load() || GetPendingCommandSize() > 0; }); m_gpu_thread_sleeping.store(false); - if (m_gpu_loop_done.load()) - break; - else + if (!m_gpu_loop_done.load()) continue; + break; } if (write_ptr < read_ptr) diff --git a/src/core/host_display.cpp b/src/core/host_display.cpp index 5a557b2c..32a7416f 100644 --- a/src/core/host_display.cpp +++ b/src/core/host_display.cpp @@ -17,31 +17,6 @@ HostDisplayTexture::~HostDisplayTexture() = default; HostDisplay::~HostDisplay() = default; -bool HostDisplay::UsesLowerLeftOrigin() const -{ - const RenderAPI api = GetRenderAPI(); - return (api == RenderAPI::OpenGL || api == RenderAPI::OpenGLES); -} - -void HostDisplay::SetDisplayMaxFPS(float max_fps) -{ - m_display_frame_interval = (max_fps > 0.0f) ? (1.0f / max_fps) : 0.0f; -} - -bool HostDisplay::ShouldSkipDisplayingFrame() -{ - if (m_display_frame_interval == 0.0f) - return false; - - const u64 now = Common::Timer::GetValue(); - const double diff = Common::Timer::ConvertValueToSeconds(now - m_last_frame_displayed_time); - if (diff < m_display_frame_interval) - return true; - - m_last_frame_displayed_time = now; - return false; -} - u32 HostDisplay::GetDisplayPixelFormatSize(HostDisplayPixelFormat format) { switch (format) diff --git a/src/core/host_display.h b/src/core/host_display.h index 94a2cfbc..e464fa6c 100644 --- a/src/core/host_display.h +++ b/src/core/host_display.h @@ -66,7 +66,6 @@ public: ALWAYS_INLINE s32 GetWindowWidth() const { return static_cast(m_window_info.surface_width); } ALWAYS_INLINE s32 GetWindowHeight() const { return static_cast(m_window_info.surface_height); } - ALWAYS_INLINE float GetWindowScale() const { return m_window_info.surface_scale; } // Position is relative to the top-left corner of the window. ALWAYS_INLINE s32 GetMousePositionX() const { return m_mouse_position_x; } @@ -118,10 +117,6 @@ public: const s32 GetDisplayHeight() const { return m_display_height; } const float GetDisplayAspectRatio() const { return m_display_aspect_ratio; } - bool UsesLowerLeftOrigin() const; - void SetDisplayMaxFPS(float max_fps); - bool ShouldSkipDisplayingFrame(); - void ClearDisplayTexture() { m_display_texture_handle = nullptr; @@ -215,8 +210,6 @@ protected: WindowInfo m_window_info; - u64 m_last_frame_displayed_time = 0; - s32 m_mouse_position_x = 0; s32 m_mouse_position_y = 0; @@ -227,7 +220,6 @@ protected: s32 m_display_active_width = 0; s32 m_display_active_height = 0; float m_display_aspect_ratio = 1.0f; - float m_display_frame_interval = 0.0f; void* m_display_texture_handle = nullptr; HostDisplayPixelFormat m_display_texture_format = HostDisplayPixelFormat::Count;