main: (Windows) Set the current timer resolution to the maximum

Increases the precision of thread sleeps on Windows.
This commit is contained in:
Morph 2023-03-01 20:07:59 -05:00
parent 7fffdf83b7
commit 7e353082ac
2 changed files with 13 additions and 0 deletions

View file

@ -91,6 +91,9 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual
#include "common/microprofile.h" #include "common/microprofile.h"
#include "common/scm_rev.h" #include "common/scm_rev.h"
#include "common/scope_exit.h" #include "common/scope_exit.h"
#ifdef _WIN32
#include "common/windows/timer_resolution.h"
#endif
#ifdef ARCHITECTURE_x86_64 #ifdef ARCHITECTURE_x86_64
#include "common/x64/cpu_detect.h" #include "common/x64/cpu_detect.h"
#endif #endif
@ -377,6 +380,12 @@ GMainWindow::GMainWindow(std::unique_ptr<Config> config_, bool has_broken_vulkan
LOG_INFO(Frontend, "Host RAM: {:.2f} GiB", LOG_INFO(Frontend, "Host RAM: {:.2f} GiB",
Common::GetMemInfo().TotalPhysicalMemory / f64{1_GiB}); Common::GetMemInfo().TotalPhysicalMemory / f64{1_GiB});
LOG_INFO(Frontend, "Host Swap: {:.2f} GiB", Common::GetMemInfo().TotalSwapMemory / f64{1_GiB}); LOG_INFO(Frontend, "Host Swap: {:.2f} GiB", Common::GetMemInfo().TotalSwapMemory / f64{1_GiB});
#ifdef _WIN32
LOG_INFO(Frontend, "Host Timer Resolution: {:.4f} ms",
std::chrono::duration_cast<std::chrono::duration<f64, std::milli>>(
Common::Windows::SetCurrentTimerResolutionToMaximum())
.count());
#endif
UpdateWindowTitle(); UpdateWindowTitle();
show(); show();

View file

@ -42,6 +42,8 @@
#include <windows.h> #include <windows.h>
#include <shellapi.h> #include <shellapi.h>
#include "common/windows/timer_resolution.h"
#endif #endif
#undef _UNICODE #undef _UNICODE
@ -314,6 +316,8 @@ int main(int argc, char** argv) {
#ifdef _WIN32 #ifdef _WIN32
LocalFree(argv_w); LocalFree(argv_w);
Common::Windows::SetCurrentTimerResolutionToMaximum();
#endif #endif
MicroProfileOnThreadCreate("EmuThread"); MicroProfileOnThreadCreate("EmuThread");