diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 8953056ae..9546e6c8f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -91,6 +91,7 @@ if(WIN32) gpu_hw_d3d11.cpp gpu_hw_d3d11.h ) + target_link_libraries(core PRIVATE winmm.lib) endif() if(${CPU_ARCH} STREQUAL "x64") diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index 7005a2a2b..5d5f65e69 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -296,6 +296,9 @@ SDL2.lib;SDL2main.lib;%(AdditionalDependencies) $(SolutionDir)dep\lib32-debug;%(AdditionalLibraryDirectories) + + winmm.lib;%(AdditionalDependencies) + @@ -318,6 +321,9 @@ SDL2.lib;SDL2main.lib;%(AdditionalDependencies) $(SolutionDir)dep\lib64-debug;%(AdditionalLibraryDirectories) + + winmm.lib;%(AdditionalDependencies) + @@ -343,6 +349,9 @@ SDL2.lib;SDL2main.lib;%(AdditionalDependencies) $(SolutionDir)dep\lib32-debug;%(AdditionalLibraryDirectories) + + winmm.lib;%(AdditionalDependencies) + @@ -368,6 +377,9 @@ SDL2.lib;SDL2main.lib;%(AdditionalDependencies) $(SolutionDir)dep\lib64-debug;%(AdditionalLibraryDirectories) + + winmm.lib;%(AdditionalDependencies) + @@ -391,6 +403,9 @@ SDL2.lib;SDL2main.lib;%(AdditionalDependencies) $(SolutionDir)dep\lib32;%(AdditionalLibraryDirectories) + + winmm.lib;%(AdditionalDependencies) + @@ -415,6 +430,9 @@ SDL2.lib;SDL2main.lib;%(AdditionalDependencies) $(SolutionDir)dep\lib32;%(AdditionalLibraryDirectories) + + winmm.lib;%(AdditionalDependencies) + @@ -438,6 +456,9 @@ SDL2.lib;SDL2main.lib;%(AdditionalDependencies) $(SolutionDir)dep\lib64;%(AdditionalLibraryDirectories) + + winmm.lib;%(AdditionalDependencies) + @@ -462,6 +483,9 @@ SDL2.lib;SDL2main.lib;%(AdditionalDependencies) $(SolutionDir)dep\lib64;%(AdditionalLibraryDirectories) + + winmm.lib;%(AdditionalDependencies) + diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index 4022d441a..a1abb5ed5 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -20,6 +20,11 @@ #include Log_SetChannel(HostInterface); +#ifdef WIN32 +#include "common/windows_headers.h" +#include +#endif + #if defined(ANDROID) || (defined(__GNUC__) && __GNUC__ < 8) static std::string GetRelativePath(const std::string& path, const char* new_filename) @@ -129,8 +134,10 @@ void HostInterface::DestroySystem() if (!m_system) return; - m_system.reset(); + SetTimerResolutionIncreased(false); + m_paused = false; + m_system.reset(); m_audio_stream.reset(); ReleaseHostDisplay(); OnSystemDestroyed(); @@ -485,8 +492,11 @@ void HostInterface::UpdateSpeedLimiterState() m_audio_stream->EmptyBuffers(); m_display->SetVSync(video_sync_enabled); - if (m_system) - m_system->ResetPerformanceCounters(); + + if (m_settings.increase_timer_resolution) + SetTimerResolutionIncreased(m_speed_limiter_enabled); + + m_system->ResetPerformanceCounters(); } void HostInterface::OnSystemCreated() {} @@ -670,6 +680,7 @@ void HostInterface::SetDefaultSettings() m_settings.emulation_speed = 1.0f; m_settings.speed_limiter_enabled = true; m_settings.start_paused = false; + m_settings.increase_timer_resolution = true; m_settings.gpu_renderer = Settings::DEFAULT_GPU_RENDERER; m_settings.gpu_resolution_scale = 1; @@ -799,3 +810,18 @@ void HostInterface::RecreateSystem() m_system->ResetPerformanceCounters(); } + +void HostInterface::SetTimerResolutionIncreased(bool enabled) +{ + if (m_timer_resolution_increased == enabled) + return; + + m_timer_resolution_increased = enabled; + +#ifdef WIN32 + if (enabled) + timeBeginPeriod(1); + else + timeEndPeriod(1); +#endif +} diff --git a/src/core/host_interface.h b/src/core/host_interface.h index 0892bcf93..a1978ea10 100644 --- a/src/core/host_interface.h +++ b/src/core/host_interface.h @@ -153,6 +153,9 @@ protected: /// Switches the GPU renderer by saving state, recreating the display window, and restoring state (if needed). void RecreateSystem(); + /// Increases timer resolution when supported by the host OS. + void SetTimerResolutionIncreased(bool enabled); + void UpdateSpeedLimiterState(); void DrawFPSWindow(); @@ -169,6 +172,7 @@ protected: bool m_paused = false; bool m_speed_limiter_temp_disabled = false; bool m_speed_limiter_enabled = false; + bool m_timer_resolution_increased = false; std::deque m_osd_messages; std::mutex m_osd_messages_lock; diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 0797ae7e5..5822ef651 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -11,6 +11,7 @@ void Settings::Load(SettingsInterface& si) emulation_speed = si.GetFloatValue("General", "EmulationSpeed", 1.0f); speed_limiter_enabled = si.GetBoolValue("General", "SpeedLimiterEnabled", true); + increase_timer_resolution = si.GetBoolValue("General", "IncreaseTimerResolution", true); start_paused = si.GetBoolValue("General", "StartPaused", false); cpu_execution_mode = ParseCPUExecutionMode(si.GetStringValue("CPU", "ExecutionMode", "Interpreter").c_str()) @@ -60,6 +61,7 @@ void Settings::Save(SettingsInterface& si) const si.SetFloatValue("General", "EmulationSpeed", emulation_speed); si.SetBoolValue("General", "SpeedLimiterEnabled", speed_limiter_enabled); + si.SetBoolValue("General", "IncreaseTimerResolution", increase_timer_resolution); si.SetBoolValue("General", "StartPaused", start_paused); si.SetStringValue("CPU", "ExecutionMode", GetCPUExecutionModeName(cpu_execution_mode)); diff --git a/src/core/settings.h b/src/core/settings.h index d979bceae..2f0d12616 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -38,6 +38,7 @@ struct Settings float emulation_speed = 1.0f; bool start_paused = false; bool speed_limiter_enabled = true; + bool increase_timer_resolution = true; GPURenderer gpu_renderer = GPURenderer::Software; u32 gpu_resolution_scale = 1; diff --git a/src/duckstation-sdl/CMakeLists.txt b/src/duckstation-sdl/CMakeLists.txt index 35bd899d1..d24ccc3b3 100644 --- a/src/duckstation-sdl/CMakeLists.txt +++ b/src/duckstation-sdl/CMakeLists.txt @@ -18,6 +18,6 @@ if(WIN32) d3d11_host_display.cpp d3d11_host_display.h ) - target_link_libraries(duckstation-sdl PRIVATE d3d11.lib dxgi.lib winmm.lib ${SDL2MAIN_LIBRARIES}) + target_link_libraries(duckstation-sdl PRIVATE d3d11.lib dxgi.lib ${SDL2MAIN_LIBRARIES}) endif() diff --git a/src/duckstation-sdl/duckstation-sdl.vcxproj b/src/duckstation-sdl/duckstation-sdl.vcxproj index 80db3b834..b924b00c4 100644 --- a/src/duckstation-sdl/duckstation-sdl.vcxproj +++ b/src/duckstation-sdl/duckstation-sdl.vcxproj @@ -220,7 +220,7 @@ Console true - d3d11.lib;dxgi.lib;winmm.lib;%(AdditionalDependencies) + d3d11.lib;dxgi.lib;%(AdditionalDependencies) @@ -241,7 +241,7 @@ Console true - d3d11.lib;dxgi.lib;winmm.lib;%(AdditionalDependencies) + d3d11.lib;dxgi.lib;%(AdditionalDependencies) @@ -265,7 +265,7 @@ Console true - d3d11.lib;dxgi.lib;winmm.lib;%(AdditionalDependencies) + d3d11.lib;dxgi.lib;%(AdditionalDependencies) @@ -289,7 +289,7 @@ Console true - d3d11.lib;dxgi.lib;winmm.lib;%(AdditionalDependencies) + d3d11.lib;dxgi.lib;%(AdditionalDependencies) @@ -311,7 +311,7 @@ true true true - d3d11.lib;dxgi.lib;winmm.lib;%(AdditionalDependencies) + d3d11.lib;dxgi.lib;%(AdditionalDependencies) Default @@ -335,7 +335,7 @@ true true true - d3d11.lib;dxgi.lib;winmm.lib;%(AdditionalDependencies) + d3d11.lib;dxgi.lib;%(AdditionalDependencies) UseLinkTimeCodeGeneration @@ -358,7 +358,7 @@ true true true - d3d11.lib;dxgi.lib;winmm.lib;%(AdditionalDependencies) + d3d11.lib;dxgi.lib;%(AdditionalDependencies) Default @@ -382,7 +382,7 @@ true true true - d3d11.lib;dxgi.lib;winmm.lib;%(AdditionalDependencies) + d3d11.lib;dxgi.lib;%(AdditionalDependencies) UseLinkTimeCodeGeneration diff --git a/src/duckstation-sdl/sdl_host_interface.cpp b/src/duckstation-sdl/sdl_host_interface.cpp index facbb32e7..d7795efaf 100644 --- a/src/duckstation-sdl/sdl_host_interface.cpp +++ b/src/duckstation-sdl/sdl_host_interface.cpp @@ -21,18 +21,11 @@ Log_SetChannel(SDLHostInterface); #ifdef WIN32 -#include "common/windows_headers.h" #include "d3d11_host_display.h" -#include #endif SDLHostInterface::SDLHostInterface() { - // Increase timer/sleep resolution since we use it for throttling. -#ifdef WIN32 - timeBeginPeriod(1); -#endif - m_update_settings_event_id = SDL_RegisterEvents(1); } @@ -47,10 +40,6 @@ SDLHostInterface::~SDLHostInterface() if (m_window) DestroySDLWindow(); - -#ifdef WIN32 - timeEndPeriod(1); -#endif } bool SDLHostInterface::CreateSDLWindow()