System: Check host page size on startup

This commit is contained in:
Stenzek
2024-05-16 17:24:42 +10:00
parent a5b1ee4f04
commit 35bdbf2a55
8 changed files with 182 additions and 25 deletions

View File

@ -8,7 +8,9 @@
#include "common/small_string.h"
#include "common/string_util.h"
#include <algorithm>
#include <cinttypes>
#include <memory>
#include "common/windows_headers.h"
#include <mmsystem.h>
@ -53,6 +55,35 @@ void PlatformMisc::ResumeScreensaver()
s_screensaver_suspended = false;
}
size_t PlatformMisc::GetRuntimePageSize()
{
SYSTEM_INFO si = {};
GetSystemInfo(&si);
return si.dwPageSize;
}
size_t PlatformMisc::GetRuntimeCacheLineSize()
{
DWORD size = 0;
if (!GetLogicalProcessorInformation(nullptr, &size) && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
return 0;
std::unique_ptr<SYSTEM_LOGICAL_PROCESSOR_INFORMATION[]> lpi =
std::make_unique<SYSTEM_LOGICAL_PROCESSOR_INFORMATION[]>(
(size + (sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) - 1)) / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION));
if (!GetLogicalProcessorInformation(lpi.get(), &size))
return 0;
u32 max_line_size = 0;
for (u32 i = 0; i < size / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); i++)
{
if (lpi[i].Relationship == RelationCache)
max_line_size = std::max<u32>(max_line_size, lpi[i].Cache.LineSize);
}
return max_line_size;
}
bool PlatformMisc::PlaySoundAsync(const char* path)
{
const std::wstring wpath(FileSystem::GetWin32Path(path));