Core: Rework HardwareInfo
This commit is contained in:
@@ -8,9 +8,11 @@
|
||||
#define NAZARA_CORE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/HardwareInfo.hpp>
|
||||
#include <Nazara/Core/ModuleBase.hpp>
|
||||
#include <Nazara/Core/Modules.hpp>
|
||||
#include <Nazara/Utils/TypeList.hpp>
|
||||
#include <optional>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -26,7 +28,11 @@ namespace Nz
|
||||
Core(Config /*config*/);
|
||||
~Core();
|
||||
|
||||
inline const HardwareInfo& GetHardwareInfo() const;
|
||||
|
||||
private:
|
||||
std::optional<HardwareInfo> m_hardwareInfo;
|
||||
|
||||
static Core* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline const HardwareInfo& Core::GetHardwareInfo() const
|
||||
{
|
||||
return *m_hardwareInfo;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -147,10 +147,13 @@ namespace Nz
|
||||
enum class ProcessorCap
|
||||
{
|
||||
x64,
|
||||
AES,
|
||||
AVX,
|
||||
FMA3,
|
||||
FMA4,
|
||||
MMX,
|
||||
Popcnt,
|
||||
RDRAND,
|
||||
XOP,
|
||||
SSE,
|
||||
SSE2,
|
||||
@@ -169,14 +172,24 @@ namespace Nz
|
||||
{
|
||||
Unknown = -1,
|
||||
|
||||
ACRN,
|
||||
AMD,
|
||||
Ao486,
|
||||
AppleRosetta2,
|
||||
Bhyve,
|
||||
Centaur,
|
||||
Cyrix,
|
||||
Elbrus,
|
||||
Hygon,
|
||||
HyperV,
|
||||
Intel,
|
||||
KVM,
|
||||
HyperV,
|
||||
MicrosoftXTA,
|
||||
NSC,
|
||||
NexGen,
|
||||
Parallels,
|
||||
QEMU,
|
||||
QNX,
|
||||
Rise,
|
||||
SIS,
|
||||
Transmeta,
|
||||
@@ -185,8 +198,9 @@ namespace Nz
|
||||
VMware,
|
||||
Vortex,
|
||||
XenHVM,
|
||||
Zhaoxin,
|
||||
|
||||
Max = XenHVM
|
||||
Max = Zhaoxin
|
||||
};
|
||||
|
||||
constexpr std::size_t ProcessorVendorCount = static_cast<std::size_t>(ProcessorVendor::Max) + 1;
|
||||
|
||||
@@ -10,33 +10,45 @@
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <string_view>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API HardwareInfo
|
||||
{
|
||||
public:
|
||||
HardwareInfo() = delete;
|
||||
~HardwareInfo() = delete;
|
||||
HardwareInfo();
|
||||
HardwareInfo(const HardwareInfo&) = delete;
|
||||
HardwareInfo(HardwareInfo&&) = delete;
|
||||
~HardwareInfo() = default;
|
||||
|
||||
inline const char* GetCpuBrandString() const;
|
||||
inline unsigned int GetCpuThreadCount() const;
|
||||
inline ProcessorVendor GetCpuVendor() const;
|
||||
std::string_view GetCpuVendorName() const;
|
||||
inline UInt64 GetSystemTotalMemory() const;
|
||||
|
||||
inline bool HasCapability(ProcessorCap capability) const;
|
||||
|
||||
static void Cpuid(UInt32 functionId, UInt32 subFunctionId, UInt32 result[4]);
|
||||
|
||||
static std::string_view GetProcessorBrandString();
|
||||
static unsigned int GetProcessorCount();
|
||||
static ProcessorVendor GetProcessorVendor();
|
||||
static std::string_view GetProcessorVendorName();
|
||||
static UInt64 GetTotalMemory();
|
||||
|
||||
static bool HasCapability(ProcessorCap capability);
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsCpuidSupported();
|
||||
static bool IsInitialized();
|
||||
|
||||
static void Uninitialize();
|
||||
HardwareInfo& operator=(const HardwareInfo&) = delete;
|
||||
HardwareInfo& operator=(HardwareInfo&&) = delete;
|
||||
|
||||
private:
|
||||
void FetchCPUInfo();
|
||||
void FetchMemoryInfo();
|
||||
|
||||
std::array<bool, ProcessorCapCount> m_cpuCapabilities;
|
||||
std::array<char, 3 * 4 * 4> m_cpuBrandString;
|
||||
ProcessorVendor m_cpuVendor;
|
||||
unsigned int m_cpuThreadCount;
|
||||
UInt64 m_systemTotalMemory;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/HardwareInfo.inl>
|
||||
|
||||
#endif // NAZARA_CORE_HARDWAREINFO_HPP
|
||||
|
||||
37
include/Nazara/Core/HardwareInfo.inl
Normal file
37
include/Nazara/Core/HardwareInfo.inl
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/HardwareInfo.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline const char* HardwareInfo::GetCpuBrandString() const
|
||||
{
|
||||
return m_cpuBrandString.data();
|
||||
}
|
||||
|
||||
inline unsigned int HardwareInfo::GetCpuThreadCount() const
|
||||
{
|
||||
return m_cpuThreadCount;
|
||||
}
|
||||
|
||||
inline ProcessorVendor HardwareInfo::GetCpuVendor() const
|
||||
{
|
||||
return m_cpuVendor;
|
||||
}
|
||||
|
||||
inline UInt64 HardwareInfo::GetSystemTotalMemory() const
|
||||
{
|
||||
return m_systemTotalMemory;
|
||||
}
|
||||
|
||||
inline bool HardwareInfo::HasCapability(ProcessorCap capability) const
|
||||
{
|
||||
return m_cpuCapabilities[UnderlyingCast(capability)];
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
Reference in New Issue
Block a user