HostInterface: Move timer resolution increase to base class
This commit is contained in:
parent
1e009133ae
commit
6a0c15b649
|
@ -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")
|
||||
|
|
|
@ -296,6 +296,9 @@
|
|||
<AdditionalDependencies>SDL2.lib;SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)dep\lib32-debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<Lib>
|
||||
<AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
|
@ -318,6 +321,9 @@
|
|||
<AdditionalDependencies>SDL2.lib;SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)dep\lib64-debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<Lib>
|
||||
<AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|Win32'">
|
||||
<ClCompile>
|
||||
|
@ -343,6 +349,9 @@
|
|||
<AdditionalDependencies>SDL2.lib;SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)dep\lib32-debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<Lib>
|
||||
<AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|x64'">
|
||||
<ClCompile>
|
||||
|
@ -368,6 +377,9 @@
|
|||
<AdditionalDependencies>SDL2.lib;SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)dep\lib64-debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<Lib>
|
||||
<AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
|
@ -391,6 +403,9 @@
|
|||
<AdditionalDependencies>SDL2.lib;SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)dep\lib32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<Lib>
|
||||
<AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLTCG|Win32'">
|
||||
<ClCompile>
|
||||
|
@ -415,6 +430,9 @@
|
|||
<AdditionalDependencies>SDL2.lib;SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)dep\lib32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<Lib>
|
||||
<AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
|
@ -438,6 +456,9 @@
|
|||
<AdditionalDependencies>SDL2.lib;SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)dep\lib64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<Lib>
|
||||
<AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLTCG|x64'">
|
||||
<ClCompile>
|
||||
|
@ -462,6 +483,9 @@
|
|||
<AdditionalDependencies>SDL2.lib;SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)dep\lib64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<Lib>
|
||||
<AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets" />
|
||||
|
|
|
@ -20,6 +20,11 @@
|
|||
#include <stdlib.h>
|
||||
Log_SetChannel(HostInterface);
|
||||
|
||||
#ifdef WIN32
|
||||
#include "common/windows_headers.h"
|
||||
#include <mmsystem.h>
|
||||
#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
|
||||
}
|
||||
|
|
|
@ -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<OSDMessage> m_osd_messages;
|
||||
std::mutex m_osd_messages_lock;
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -220,7 +220,7 @@
|
|||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
|
@ -241,7 +241,7 @@
|
|||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|Win32'">
|
||||
|
@ -265,7 +265,7 @@
|
|||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|x64'">
|
||||
|
@ -289,7 +289,7 @@
|
|||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
|
@ -311,7 +311,7 @@
|
|||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
|
@ -335,7 +335,7 @@
|
|||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
|
@ -358,7 +358,7 @@
|
|||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
|
@ -382,7 +382,7 @@
|
|||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
|
|
|
@ -21,18 +21,11 @@
|
|||
Log_SetChannel(SDLHostInterface);
|
||||
|
||||
#ifdef WIN32
|
||||
#include "common/windows_headers.h"
|
||||
#include "d3d11_host_display.h"
|
||||
#include <mmsystem.h>
|
||||
#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()
|
||||
|
|
Loading…
Reference in New Issue