System: Use cpuinfo for cache line size check
This commit is contained in:
@@ -15,9 +15,6 @@ void ResumeScreensaver();
|
||||
/// Returns the size of pages for the current host.
|
||||
size_t GetRuntimePageSize();
|
||||
|
||||
/// Returns the size of a cache line for the current host.
|
||||
size_t GetRuntimeCacheLineSize();
|
||||
|
||||
/// Abstracts platform-specific code for asynchronously playing a sound.
|
||||
/// On Windows, this will use PlaySound(). On Linux, it will shell out to aplay. On MacOS, it uses NSSound.
|
||||
bool PlaySoundAsync(const char* path);
|
||||
|
||||
@@ -93,11 +93,6 @@ size_t PlatformMisc::GetRuntimePageSize()
|
||||
return sysctlbyname<u32>("hw.pagesize").value_or(0);
|
||||
}
|
||||
|
||||
size_t PlatformMisc::GetRuntimeCacheLineSize()
|
||||
{
|
||||
return static_cast<size_t>(std::max<s64>(sysctlbyname<s64>("hw.cachelinesize").value_or(0), 0));
|
||||
}
|
||||
|
||||
bool PlatformMisc::PlaySoundAsync(const char* path)
|
||||
{
|
||||
NSString* nspath = [[NSString alloc] initWithUTF8String:path];
|
||||
|
||||
@@ -132,28 +132,6 @@ size_t PlatformMisc::GetRuntimePageSize()
|
||||
return (res > 0) ? static_cast<size_t>(res) : 0;
|
||||
}
|
||||
|
||||
size_t PlatformMisc::GetRuntimeCacheLineSize()
|
||||
{
|
||||
int l1i = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
|
||||
int l1d = sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
|
||||
int res = (l1i > l1d) ? l1i : l1d;
|
||||
for (int index = 0; index < 16; index++)
|
||||
{
|
||||
char buf[128];
|
||||
snprintf(buf, sizeof(buf), "/sys/devices/system/cpu/cpu0/cache/index%d/coherency_line_size", index);
|
||||
std::FILE* fp = std::fopen(buf, "rb");
|
||||
if (!fp)
|
||||
break;
|
||||
|
||||
std::fread(buf, sizeof(buf), 1, fp);
|
||||
std::fclose(fp);
|
||||
int val = std::atoi(buf);
|
||||
res = (val > res) ? val : res;
|
||||
}
|
||||
|
||||
return (res > 0) ? static_cast<size_t>(res) : 0;
|
||||
}
|
||||
|
||||
bool PlatformMisc::PlaySoundAsync(const char* path)
|
||||
{
|
||||
#ifdef __linux__
|
||||
|
||||
@@ -85,28 +85,6 @@ size_t PlatformMisc::GetRuntimePageSize()
|
||||
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));
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>%(PreprocessorDefinitions);SOUNDTOUCH_FLOAT_SAMPLES;SOUNDTOUCH_ALLOW_SSE;ST_NO_EXCEPTION_HANDLING=1;ENABLE_VULKAN=1</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>%(PreprocessorDefinitions);SOUNDTOUCH_FLOAT_SAMPLES;SOUNDTOUCH_ALLOW_SSE;ST_NO_EXCEPTION_HANDLING=1;CPUINFO_SHARED=1;ENABLE_VULKAN=1</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions Condition="'$(Platform)'!='ARM64'">%(PreprocessorDefinitions);ENABLE_OPENGL=1</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions Condition="'$(Platform)'=='ARM64'">%(PreprocessorDefinitions);SOUNDTOUCH_USE_NEON</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SolutionDir)dep\xxhash\include;$(SolutionDir)dep\freesurround\include;$(SolutionDir)dep\kissfft\include;$(SolutionDir)dep\soundtouch\include;$(SolutionDir)dep\imgui\include;$(SolutionDir)dep\simpleini\include;$(SolutionDir)dep\libchdr\include;$(SolutionDir)dep\cubeb\include;$(SolutionDir)dep\d3d12ma\include;$(SolutionDir)dep\vulkan\include</AdditionalIncludeDirectories>
|
||||
@@ -27,10 +27,11 @@
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DepsIncludeDir)SDL2</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>%(AdditionalDependencies);freetype.lib;libjpeg.lib;libpng16.lib;libwebp.lib;SDL2.lib;zlib.lib;zstd.lib</AdditionalDependencies>
|
||||
<AdditionalDependencies>%(AdditionalDependencies);cpuinfo.lib;freetype.lib;libjpeg.lib;libpng16.lib;libwebp.lib;SDL2.lib;zlib.lib;zstd.lib</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<DepsDLLs Include="$(DepsBinDir)cpuinfo.dll" />
|
||||
<DepsDLLs Include="$(DepsBinDir)freetype.dll" />
|
||||
<DepsDLLs Include="$(DepsBinDir)harfbuzz.dll" />
|
||||
<DepsDLLs Include="$(DepsBinDir)libjpeg.dll" />
|
||||
|
||||
Reference in New Issue
Block a user