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()
add_crashpad()
target_breakpad()
target_json()
# perform standard include and linking for found externals
foreach(EXTERNAL ${OPTIONAL_EXTERNALS})

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -12,6 +12,7 @@
#ifdef Q_OS_WIN
#include <string>
#include <nlohmann/json.hpp>
//#include <atlbase.h>
//#include <Wbemidl.h>
@ -250,6 +251,26 @@ GPUIdent* GPUIdent::ensureQuery(const QString& vendor, const QString& renderer)
*/
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()];
std::wstring wDescription(adapterEntry.first.first.Description);

View file

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