code cleanup based on discussion with Sam. Adding implementation for graphics and display info from gpuiden. removed dxgi references in platform

This commit is contained in:
amerhifi 2019-05-09 12:04:41 -07:00
parent 58cff374d7
commit 0d97543ece
10 changed files with 161 additions and 106 deletions

View file

@ -228,6 +228,7 @@ target_bullet()
target_opengl() target_opengl()
add_crashpad() add_crashpad()
target_breakpad() target_breakpad()
target_json()
# perform standard include and linking for found externals # perform standard include and linking for found externals
foreach(EXTERNAL ${OPTIONAL_EXTERNALS}) foreach(EXTERNAL ${OPTIONAL_EXTERNALS})

View file

@ -196,6 +196,8 @@
#include "scripting/RefreshRateScriptingInterface.h" #include "scripting/RefreshRateScriptingInterface.h"
#include <platform.h>
#include <nlohmann/json.hpp>
#if defined(Q_OS_MAC) || defined(Q_OS_WIN) #if defined(Q_OS_MAC) || defined(Q_OS_WIN)
#include "SpeechRecognizer.h" #include "SpeechRecognizer.h"
@ -245,7 +247,7 @@
#include "webbrowser/WebBrowserSuggestionsEngine.h" #include "webbrowser/WebBrowserSuggestionsEngine.h"
#include <DesktopPreviewProvider.h> #include <DesktopPreviewProvider.h>
#include <nlohmann/json.hpp>
#include "AboutUtil.h" #include "AboutUtil.h"
#include <DisableDeferred.h> #include <DisableDeferred.h>
@ -1032,6 +1034,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
_sampleSound(nullptr) _sampleSound(nullptr)
{ {
initPlatform();
auto steamClient = PluginManager::getInstance()->getSteamClientPlugin(); auto steamClient = PluginManager::getInstance()->getSteamClientPlugin();
setProperty(hifi::properties::STEAM, (steamClient && steamClient->isRunning())); setProperty(hifi::properties::STEAM, (steamClient && steamClient->isRunning()));
setProperty(hifi::properties::CRASHED, _previousSessionCrashed); setProperty(hifi::properties::CRASHED, _previousSessionCrashed);
@ -2486,6 +2489,18 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
pauseUntilLoginDetermined(); pauseUntilLoginDetermined();
} }
void Application::initPlatform() {
platform::create();
platform::enumeratePlatform();
nlohmann::json test = platform::getGraphics(0);
nlohmann::json test1 = platform::getProcessor(0);
nlohmann::json test2 = platform::getMemory(0);
nlohmann::json test3 = platform::getDisplay(0);
}
void Application::updateVerboseLogging() { void Application::updateVerboseLogging() {
auto menu = Menu::getInstance(); auto menu = Menu::getInstance();
if (!menu) { if (!menu) {

View file

@ -130,6 +130,9 @@ public:
virtual bool makeRenderingContextCurrent() override; virtual bool makeRenderingContextCurrent() override;
virtual bool isForeground() const override; virtual bool isForeground() const override;
//test
void initPlatform();
virtual DisplayPluginPointer getActiveDisplayPlugin() const override; virtual DisplayPluginPointer getActiveDisplayPlugin() const override;
// FIXME? Empty methods, do we still need them? // FIXME? Empty methods, do we still need them?

View file

@ -10,27 +10,22 @@
#include <intrin.h> #include <intrin.h>
#include <Windows.h> #include <Windows.h>
#include <thread> #include <thread>
#include <GPUIdent.h>
#include <string>
#ifdef Q_OS_WINDOWS
#include <dxgi.h>
#include <d3d11.h>
#endif
using namespace platform; using namespace platform;
using namespace nlohmann; using namespace nlohmann;
bool WINInstance::enumerateProcessors() { bool WINInstance::enumeratePlatform() {
enumerateCpu(); enumerateCpu();
enumerateGpu(); enumerateGpu();
enumerateRam(); enumerateRam();
return true; return true;
} }
void WINInstance::enumerateCpu() { void WINInstance::enumerateCpu() {
json cpu; json *cpu= new json();
int CPUInfo[4] = { -1 }; int CPUInfo[4] = { -1 };
unsigned nExIds; unsigned nExIds;
unsigned int i = 0; unsigned int i = 0;
@ -54,12 +49,12 @@ void WINInstance::enumerateCpu() {
} }
} }
cpu["brand"] = CPUBrandString; (*cpu)["brand"] = CPUBrandString;
cpu["model"] = CPUModelString; (*cpu)["model"] = CPUModelString;
cpu["clockSpeed"] = CPUClockString; (*cpu)["clockSpeed"] = CPUClockString;
cpu["numCores"] = getNumLogicalCores(); (*cpu)["numCores"] = getNumLogicalCores();
_processors.push_back(cpu); _cpu.push_back(cpu);
} }
unsigned int WINInstance::getNumLogicalCores() { unsigned int WINInstance::getNumLogicalCores() {
@ -67,65 +62,26 @@ unsigned int WINInstance::getNumLogicalCores() {
} }
void WINInstance::enumerateGpu() { void WINInstance::enumerateGpu() {
#ifdef Q_OS_WINDOWS
IDXGIAdapter* adapter;
std::vector<IDXGIAdapter*> adapters;
IDXGIFactory* factory = NULL;
HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory); GPUIdent* ident = GPUIdent::getInstance();
_gpu.clear();
if (SUCCEEDED(hr)) { json *gpu = new json();
for (UINT i = 0; factory->EnumAdapters(i, &adapter) != DXGI_ERROR_NOT_FOUND; ++i) { (*gpu)["name"] = ident->getName().toUtf8().constData();
DXGI_ADAPTER_DESC* desc; (*gpu)["memory"] = ident->getMemory();
(*gpu)["driver"] = ident->getDriver().toUtf8().constData();
if (SUCCEEDED(adapter->GetDesc(desc))) { _gpu.push_back(gpu);
json* gpu = new json(); _display = ident->getOutput();
(*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() { void WINInstance::enumerateRam() {
json ram; json* ram = new json();
MEMORYSTATUSEX statex; MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex); statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex); GlobalMemoryStatusEx(&statex);
int totalRam = statex.ullTotalPhys / 1024 / 1024; int totalRam = statex.ullTotalPhys / 1024 / 1024;
ram["totalMem"] = totalRam; (*ram)["totalMem"] = totalRam;
_memory.push_back(ram); _memory.push_back(ram);
} }

View file

@ -19,7 +19,7 @@ namespace platform {
class WINInstance : public Instance { class WINInstance : public Instance {
public: public:
bool enumerateProcessors(); bool enumeratePlatform();
private: private:
unsigned int getNumLogicalCores(); unsigned int getNumLogicalCores();

View file

@ -35,19 +35,23 @@ void platform::create() {
#endif #endif
} }
json Instance::getProcessor(int index) { void platform::destroy() {
delete _instance;
}
json Instance::getCPU(int index) {
assert(index < _processor.size()); assert(index < _processor.size());
json result; json result;
if (index >= _processors.size()) if (index >= _cpu.size())
return result; return result;
return _processors.at(index); return _cpu.at(index);
} }
//These are ripe for template.. will work on that next //These are ripe for template.. will work on that next
json Instance::getSystemRam(int index) { json Instance::getMemory(int index) {
assert(index < _memory.size()); assert(index < _memory.size());
@ -68,25 +72,34 @@ json Instance::getGPU(int index) {
return _gpu.at(index); return _gpu.at(index);
} }
json Instance::getDisplay(int index) {
assert(index < _display.size());
json result;
if (index >= _display.size())
return result;
return _display.at(index);
}
Instance::~Instance() { Instance::~Instance() {
//if (_processors.size() > 0) { if (_cpu.size() > 0) {
// for (std::vector<json*>::iterator it = _processors.begin(); it != _processors.end(); ++it) { for (std::vector<json*>::iterator it = _cpu.begin(); it != _cpu.end(); ++it) {
// delete (*it); delete (*it);
// } }
//
// _processors.clear(); _cpu.clear();
//
// } }
//
// if (_memory.size() > 0) { if (_memory.size() > 0) {
// for (std::vector<json*>::iterator it = _memory.begin(); it != _memory.end(); ++it) { for (std::vector<json*>::iterator it = _memory.begin(); it != _memory.end(); ++it) {
// delete (*it); delete (*it);
// } }
//
// _memory.clear(); _memory.clear();
// } }
if (_gpu.size() > 0) { if (_gpu.size() > 0) {
@ -97,25 +110,48 @@ Instance::~Instance() {
_gpu.clear(); _gpu.clear();
} }
if (_display.size() > 0) {
for (std::vector<json*>::iterator it = _display.begin(); it != _display.end(); ++it) {
delete (*it);
}
_display.clear();
}
} }
bool platform::enumerateProcessors() { bool platform::enumeratePlatform() {
return _instance->enumerateProcessors(); return _instance->enumeratePlatform();
}
int platform::getNumProcessor() {
return _instance->getNumCPU();
} }
json platform::getProcessor(int index) { json platform::getProcessor(int index) {
return _instance->getProcessor(index); return _instance->getCPU(index);
} }
json platform::getSystemRam(int index) { int platform::getNumGraphics() {
return _instance->getSystemRam(index); return _instance->getNumGPU();
}
nlohmann::json platform::getGraphics(int index) {
return _instance->getGPU(index);
}
int platform::getNumDisplay() {
return _instance->getNumDisplay();
}
nlohmann::json platform::getDisplay(int index) {
return _instance->getDisplay(index);
}
json platform::getMemory(int index) {
return _instance->getMemory(index);
} }
int platform::getNumMemory() { int platform::getNumMemory() {
return _instance->getNumMemory(); return _instance->getNumMemory();
} }
int platform::getNumProcessor() {
return _instance->getNumProcessor();
}

View file

@ -12,37 +12,53 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
namespace platform { namespace platform {
class Instance { class Instance {
public: public:
bool virtual enumerateProcessors() = 0; bool virtual enumeratePlatform() = 0;
int getNumProcessor() { return _processors.size(); } int getNumCPU() { return _cpu.size(); }
nlohmann::json getProcessor(int index); nlohmann::json getCPU(int index);
int getNumMemory() { return _memory.size(); }
nlohmann::json getSystemRam(int index);
int getNumGPU() { return _gpu.size(); } int getNumGPU() { return _gpu.size(); }
nlohmann::json getGPU(int index); nlohmann::json getGPU(int index);
int getNumMemory() { return _memory.size(); }
nlohmann::json getMemory(int index);
int getNumDisplay() { return _display.size(); }
nlohmann::json getDisplay(int index);
~Instance(); ~Instance();
protected: protected:
std::vector<nlohmann::json> _processors; std::vector<nlohmann::json*> _cpu;
std::vector<nlohmann::json> _memory; std::vector<nlohmann::json*> _memory;
std::vector<nlohmann::json*> _gpu; std::vector<nlohmann::json*> _gpu;
std::vector<nlohmann::json*> _display;
}; };
//Platform level functions //Platform level functions
void create(); void create();
void destroy();
bool enumeratePlatform();
bool enumerateProcessors();
int getNumProcessor(); int getNumProcessor();
nlohmann::json getProcessor(int index); nlohmann::json getProcessor(int index);
int getNumGraphics();
nlohmann::json getGraphics(int index);
int getNumDisplay();
nlohmann::json getDisplay(int index);
int getNumMemory(); int getNumMemory();
nlohmann::json getSystemRam(int index); nlohmann::json getMemory(int index);
} // namespace platform } // namespace platform

View file

@ -13,3 +13,4 @@ endif()
target_zlib() target_zlib()
target_nsight() target_nsight()
target_json()

View file

@ -12,6 +12,7 @@
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <string> #include <string>
#include <nlohmann/json.hpp>
//#include <atlbase.h> //#include <atlbase.h>
//#include <Wbemidl.h> //#include <Wbemidl.h>
@ -250,6 +251,26 @@ GPUIdent* GPUIdent::ensureQuery(const QString& vendor, const QString& renderer)
*/ */
if (!validAdapterList.empty()) { if (!validAdapterList.empty()) {
for (auto outy = adapterToOutputs.begin(); outy != adapterToOutputs.end(); outy++) {
AdapterEntry entry = *outy;
entry.first.first.Description;
for (auto test = entry.second.begin(); test != entry.second.end(); test++) {
nlohmann::json* output = new nlohmann::json();
(*output)["description"] = entry.first.first.Description;
(*output)["deviceName"]= test->DeviceName;
(*output)["coordinatesleft"] = test->DesktopCoordinates.left;
(*output)["coordinatesright"] = test->DesktopCoordinates.right;
(*output)["coordinatestop"] = test->DesktopCoordinates.top;
(*output)["coordinatesbottom"] = test->DesktopCoordinates.bottom;
_output.push_back(output);
}
}
auto& adapterEntry = adapterToOutputs[validAdapterList.front()]; auto& adapterEntry = adapterToOutputs[validAdapterList.front()];
std::wstring wDescription(adapterEntry.first.first.Description); std::wstring wDescription(adapterEntry.first.first.Description);

View file

@ -15,19 +15,25 @@
#define hifi_GPUIdent_h #define hifi_GPUIdent_h
#include <cstdint> #include <cstdint>
#include <QString> #include <QString>
#include <memory>
#include <nlohmann\json.hpp>
#include <vector>
class GPUIdent class GPUIdent
{ {
public: public:
uint64_t getMemory() { return _dedicatedMemoryMB; } uint64_t getMemory() { return _dedicatedMemoryMB; }
QString getName() { return _name; } QString getName() { return _name; }
QString getDriver() { return _driver; } QString getDriver() { return _driver; }
bool isValid() { return _isValid; } bool isValid() { return _isValid; }
std::vector<nlohmann::json*> getOutput() { return _output; }
// E.g., GPUIdent::getInstance()->getMemory(); // E.g., GPUIdent::getInstance()->getMemory();
static GPUIdent* getInstance(const QString& vendor = "", const QString& renderer = "") { return _instance.ensureQuery(vendor, renderer); } static GPUIdent* getInstance(const QString& vendor = "", const QString& renderer = "") { return _instance.ensureQuery(vendor, renderer); }
private: private:
std::vector<nlohmann::json*> _output;
uint64_t _dedicatedMemoryMB { 0 }; uint64_t _dedicatedMemoryMB { 0 };
QString _name { "" }; QString _name { "" };
QString _driver { "" }; QString _driver { "" };