diff --git a/Utilities/sync.h b/Utilities/sync.h index 7f74bd9abd..5d7e3ae461 100644 --- a/Utilities/sync.h +++ b/Utilities/sync.h @@ -24,6 +24,7 @@ #include #ifdef _WIN32 +DYNAMIC_IMPORT("ntdll.dll", NtQueryTimerResolution, NTSTATUS(PULONG MinimumResolution, PULONG MaximumResolution, PULONG CurrentResolution)); DYNAMIC_IMPORT("ntdll.dll", NtSetTimerResolution, NTSTATUS(ULONG DesiredResolution, BOOLEAN SetResolution, PULONG CurrentResolution)); DYNAMIC_IMPORT("ntdll.dll", NtWaitForKeyedEvent, NTSTATUS(HANDLE Handle, PVOID Key, BOOLEAN Alertable, PLARGE_INTEGER Timeout)); DYNAMIC_IMPORT("ntdll.dll", NtReleaseKeyedEvent, NTSTATUS(HANDLE Handle, PVOID Key, BOOLEAN Alertable, PLARGE_INTEGER Timeout)); diff --git a/rpcs3/main.cpp b/rpcs3/main.cpp index 3e326306e2..b749408c65 100644 --- a/rpcs3/main.cpp +++ b/rpcs3/main.cpp @@ -79,13 +79,6 @@ int main(int argc, char** argv) // I think there was an issue with gsframe if I recall correctly, so look out for that //QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); SetProcessDPIAware(); - - timeBeginPeriod(1); - - atexit([] - { - timeEndPeriod(1); - }); #else qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1"); #endif diff --git a/rpcs3/rpcs3_app.cpp b/rpcs3/rpcs3_app.cpp index 4441c89727..87624aa7cd 100644 --- a/rpcs3/rpcs3_app.cpp +++ b/rpcs3/rpcs3_app.cpp @@ -57,6 +57,12 @@ #include "Emu/Audio/Pulse/PulseThread.h" #endif +#ifdef _WIN32 +#include "Utilities/dynamic_library.h" +DYNAMIC_IMPORT("ntdll.dll", NtQueryTimerResolution, NTSTATUS(PULONG MinimumResolution, PULONG MaximumResolution, PULONG CurrentResolution)); +DYNAMIC_IMPORT("ntdll.dll", NtSetTimerResolution, NTSTATUS(ULONG DesiredResolution, BOOLEAN SetResolution, PULONG CurrentResolution)); +#endif + // For now, a trivial constructor/destructor. May add command line usage later. rpcs3_app::rpcs3_app(int& argc, char** argv) : QApplication(argc, argv) { @@ -101,6 +107,17 @@ void rpcs3_app::Init() Discord_Initialize("424004941485572097", &handlers, 1, NULL); } #endif + +#ifdef _WIN32 + // Set 0.5 msec timer resolution for best performance + // - As QT5 timers (QTimer) sets the timer resolution to 1 msec, override it here. + // - Don't bother "unsetting" the timer resolution after the emulator stops as QT5 will still require the timer resolution to be set to 1 msec. + ULONG min_res, max_res, orig_res, new_res; + if (NtQueryTimerResolution(&min_res, &max_res, &orig_res) == 0) + { + NtSetTimerResolution(max_res, TRUE, &new_res); + } +#endif } /** RPCS3 emulator has functions it desires to call from the GUI at times. Initialize them in here.