3
0
Fork 0
mirror of https://github.com/JulianGro/overte.git synced 2025-04-29 17:02:57 +02:00

working on dxgi gpu info stuff

This commit is contained in:
amer cerkic 2019-05-06 16:16:20 -07:00
parent 26b38f5950
commit f557e58224
4 changed files with 113 additions and 28 deletions

View file

@ -11,36 +11,33 @@
#include <Windows.h>
#include <thread>
#ifdef Q_OS_WINDOWS
#include <dxgi.h>
#include <d3d11.h>
#endif
using namespace platform;
using namespace nlohmann;
bool WINInstance::enumerateProcessors() {
json cpu;
getCpuDetails(cpu);
cpu["numCores"] = getNumLogicalCores();
_processors.push_back(cpu);
json mem;
mem["totalRam"] = getTotalSystemRam();
_memory.push_back(mem);
enumerateCpu();
enumerateGpu();
enumerateRam();
return true;
}
void WINInstance::getCpuDetails(json &cpu) {
void WINInstance::enumerateCpu() {
json cpu;
int CPUInfo[4] = { -1 };
unsigned nExIds;
unsigned int i = 0;
char CPUBrandString[16];
char CPUModelString[16];
char CPUClockString[16];
// Get the information associated with each extended ID.
__cpuid(CPUInfo, 0x80000000);
nExIds = CPUInfo[0];
@ -56,24 +53,79 @@ void WINInstance::getCpuDetails(json &cpu) {
memcpy(CPUClockString, CPUInfo, sizeof(CPUInfo));
}
}
cpu["brand"] = CPUBrandString;
cpu["model"] = CPUModelString;
cpu["clockSpeed"] = CPUClockString;
cpu["numCores"] = getNumLogicalCores();
_processors.push_back(cpu);
}
unsigned int WINInstance::getNumLogicalCores() {
return std::thread::hardware_concurrency();
}
int WINInstance::getTotalSystemRam() {
void WINInstance::enumerateGpu() {
#ifdef Q_OS_WINDOWS
IDXGIAdapter* adapter;
std::vector<IDXGIAdapter*> adapters;
IDXGIFactory* factory = NULL;
HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
_gpu.clear();
if (SUCCEEDED(hr)) {
for (UINT i = 0; factory->EnumAdapters(i, &adapter) != DXGI_ERROR_NOT_FOUND; ++i) {
DXGI_ADAPTER_DESC* desc;
if (SUCCEEDED(adapter->GetDesc(desc))) {
json* gpu = new json();
(*gpu)["BrandModel"] = desc->Description;
(*gpu)["DedicatedRam"] = desc->DedicatedVideoMemory/1024/1024;
(*gpu)["SharedRam"] = desc->SharedSystemMemory / 1024 / 1024;
UINT numModes = 0;
DXGI_MODE_DESC* displayModes = NULL;
DXGI_FORMAT format = DXGI_FORMAT_R32G32B32A32_FLOAT;
IDXGIOutput* output = NULL;
if (SUCCEEDED(adapter->EnumOutputs(0, &output))) {
output->GetDisplayModeList(format, 0, &numModes, displayModes);
DXGI_OUTPUT_DESC* desc;
output->GetDesc(desc);
//auto a = desc->Monitor;
//auto b = desc->DeviceName;
//figure out monitor info here
}
_gpu.push_back(gpu);
}
}
}
if (adapter) {
adapter->Release();
}
if (factory) {
factory->Release();
}
#endif
}
void WINInstance::enumerateRam() {
json ram;
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex);
return statex.ullTotalPhys / 1024 / 1024;
int totalRam = statex.ullTotalPhys / 1024 / 1024;
ram["totalMem"] = totalRam;
_memory.push_back(ram);
}

View file

@ -23,9 +23,10 @@ namespace platform {
private:
unsigned int getNumLogicalCores();
void getCpuDetails(nlohmann::json& cpu);
int getTotalSystemRam();
};
void enumerateCpu();
void enumerateRam();
void enumerateGpu();
};
} // namespace platform

View file

@ -69,6 +69,37 @@ json Instance::getGPU(int index) {
}
Instance::~Instance() {
//if (_processors.size() > 0) {
// for (std::vector<json*>::iterator it = _processors.begin(); it != _processors.end(); ++it) {
// delete (*it);
// }
//
// _processors.clear();
//
// }
//
// if (_memory.size() > 0) {
// for (std::vector<json*>::iterator it = _memory.begin(); it != _memory.end(); ++it) {
// delete (*it);
// }
//
// _memory.clear();
// }
if (_gpu.size() > 0) {
for (std::vector<json*>::iterator it = _gpu.begin(); it != _gpu.end(); ++it) {
delete (*it);
}
_gpu.clear();
}
}
bool platform::enumerateProcessors() {
return _instance->enumerateProcessors();
}

View file

@ -27,11 +27,12 @@ public:
int getNumGPU() { return _gpu.size(); }
nlohmann::json getGPU(int index);
~Instance();
protected:
std::vector<nlohmann::json> _processors;
std::vector<nlohmann::json> _memory;
std::vector<nlohmann::json> _gpu;
std::vector<nlohmann::json*> _gpu;
};
//Platform level functions