[App] Request high-performance timer resolution on Windows

This commit is contained in:
DrChat 2018-05-22 16:41:05 -05:00
parent cb4b1bae1b
commit 73c30d87a8
1 changed files with 30 additions and 0 deletions

View File

@ -22,6 +22,8 @@
#include "xenia/base/platform_win.h" #include "xenia/base/platform_win.h"
#include "xenia/base/string.h" #include "xenia/base/string.h"
#include <bcrypt.h>
namespace xe { namespace xe {
bool has_console_attached_ = true; bool has_console_attached_ = true;
@ -52,9 +54,37 @@ void AttachConsole() {
setvbuf(stderr, nullptr, _IONBF, 0); setvbuf(stderr, nullptr, _IONBF, 0);
} }
static void RequestHighPerformance() {
#if XE_PLATFORM_WIN32
NTSTATUS(*NtQueryTimerResolution)
(OUT PULONG MinimumResolution, OUT PULONG MaximumResolution,
OUT PULONG CurrentResolution);
NTSTATUS(*NtSetTimerResolution)
(IN ULONG DesiredResolution, IN BOOLEAN SetResolution,
OUT PULONG CurrentResolution);
NtQueryTimerResolution = (decltype(NtQueryTimerResolution))GetProcAddress(
GetModuleHandle(L"ntdll.dll"), "NtQueryTimerResolution");
NtSetTimerResolution = (decltype(NtSetTimerResolution))GetProcAddress(
GetModuleHandle(L"ntdll.dll"), "NtSetTimerResolution");
if (!NtQueryTimerResolution || !NtSetTimerResolution) {
return;
}
ULONG minimum_resolution, maximum_resolution, current_resolution;
NtQueryTimerResolution(&minimum_resolution, &maximum_resolution,
&current_resolution);
NtSetTimerResolution(minimum_resolution, TRUE, &current_resolution);
#endif
}
int Main() { int Main() {
auto entry_info = xe::GetEntryInfo(); auto entry_info = xe::GetEntryInfo();
// Request high performance timing.
RequestHighPerformance();
// Convert command line to an argv-like format so we can share code/use // Convert command line to an argv-like format so we can share code/use
// gflags. // gflags.
auto command_line = GetCommandLineW(); auto command_line = GetCommandLineW();