Merge pull request #15575 from amerhifi/feature/platform

case BUGZ-57: Populate macos gpu _name
This commit is contained in:
Shannon Romano 2019-05-16 22:07:16 -04:00 committed by GitHub
commit 4e9852f9f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 89 additions and 25 deletions

View file

@ -8,9 +8,8 @@
#include "AndroidPlatform.h"
#include "platformJsonKeys.h"
#include <GPUIdent.h>
#include <string>
using namespace platform;
void AndroidInstance::enumerateCpu() {
@ -35,6 +34,11 @@ void AndroidInstance::enumerateGpu() {
void AndroidInstance::enumerateMemory() {
json ram = {};
ram["totalMemory"]="";
_memory.push_back(ram);
}
void AndroidInstance::enumerateComputer(){
//no implememntation at this time
}

View file

@ -18,6 +18,7 @@ namespace platform {
void enumerateCpu() override;
void enumerateMemory() override;
void enumerateGpu() override;
void enumerateComputer () override;
};
} // namespace platform

View file

@ -9,7 +9,6 @@
#include "LinuxPlatform.h"
#include "platformJsonKeys.h"
#include <GPUIdent.h>
#include <string>
using namespace platform;
void LinuxInstance::enumerateCpu() {
@ -36,7 +35,12 @@ void LinuxInstance::enumerateGpu() {
void LinuxInstance::enumerateMemory() {
json ram = {};
ram["totalMemory"]="";
_memory.push_back(ram);
}
void LinuxInstance::enumerateComputer(){
//no implememntation at this time
}

View file

@ -18,6 +18,7 @@ namespace platform {
void enumerateCpu() override;
void enumerateMemory() override;
void enumerateGpu() override;
void enumerateComputer () override;
};
} // namespace platform

View file

@ -8,6 +8,7 @@
#include "MACOSPlatform.h"
#include "platformJsonKeys.h"
#include <thread>
#include <GPUIdent.h>
#include <string>
@ -15,6 +16,7 @@
#ifdef Q_OS_MAC
#include <unistd.h>
#include <cpuid.h>
#include <sys/sysctl.h>
#endif
using namespace platform;
@ -33,6 +35,7 @@ static void getCpuId( uint32_t* p, uint32_t ax )
#endif
}
void MACOSInstance::enumerateCpu() {
json cpu = {};
uint32_t cpuInfo[4]={0,0,0,0};
@ -72,6 +75,7 @@ void MACOSInstance::enumerateGpu() {
_gpu.push_back(gpu);
_display = ident->getOutput();
}
void MACOSInstance::enumerateMemory() {
@ -84,3 +88,20 @@ void MACOSInstance::enumerateMemory() {
#endif
_memory.push_back(ram);
}
void MACOSInstance::enumerateComputer(){
#ifdef Q_OS_MAC
//get system name
size_t len=0;
sysctlbyname("hw.model",NULL, &len, NULL, 0);
char* model = (char *) malloc(sizeof(char)*len+1);
sysctlbyname("hw.model", model, &len, NULL,0);
_computer["computerModel"]=std::string(model);
free(model);
#endif
}

View file

@ -18,8 +18,9 @@ namespace platform {
void enumerateCpu() override;
void enumerateMemory() override;
void enumerateGpu() override;
void enumerateComputer () override;
};
} // namespace platform
#endif //hifi_winplatform_h
#endif //hifi_macosplatform_h

View file

@ -8,6 +8,7 @@
#include "WINPlatform.h"
#include "platformJsonKeys.h"
#ifdef Q_OS_WINDOWS
#include <intrin.h>
#include <Windows.h>
@ -76,7 +77,12 @@ void WINInstance::enumerateMemory() {
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex);
int totalRam = statex.ullTotalPhys / 1024 / 1024;
ram[jsonKeys::totalMemory] = totalRam;
ram["totalMemory"] = totalRam;
#endif
_memory.push_back(ram);
}
void WINInstance::enumerateComputer(){
//no implememntation at this time
}

View file

@ -18,7 +18,7 @@ namespace platform {
void enumerateCpu() override;
void enumerateMemory() override;
void enumerateGpu() override;
void enumerateComputer () override;
};
} // namespace platform

View file

@ -77,3 +77,7 @@ int platform::getNumMemory() {
json platform::getMemory(int index) {
return _instance->getMemory(index);
}
json platform::getComputer(){
return _instance->getComputer();
}

View file

@ -9,8 +9,7 @@
#ifndef hifi_Platform_h
#define hifi_Platform_h
#include "platformInstance.h"
#include <vector>
#include <nlohmann/json.hpp>
namespace platform {
@ -32,6 +31,8 @@ json getDisplay(int index);
int getNumMemory();
json getMemory(int index);
json getComputer();
} // namespace platform
#endif // hifi_platform_h

View file

@ -7,24 +7,13 @@
//
#include "platform.h"
#include "platformInstance.h"
#include <QtGlobal>
#ifdef Q_OS_WIN
#include "WINPlatform.h"
#endif
#ifdef Q_OS_MACOS
#include "MACOSPlatform.h"
#endif
#ifdef Q_OS_LINUX
#endif
using namespace platform;
bool Instance::enumeratePlatform() {
enumerateComputer();
enumerateCpu();
enumerateGpu();
enumerateMemory();
@ -75,7 +64,6 @@ Instance::~Instance() {
_memory.clear();
}
if (_gpu.size() > 0) {
_gpu.clear();
}

View file

@ -31,9 +31,13 @@ public:
int getNumDisplay() { return (int)_display.size(); }
json getDisplay(int index);
json getComputer() {return _computer;}
void virtual enumerateCpu()=0;
void virtual enumerateMemory()=0;
void virtual enumerateGpu()=0;
void virtual enumerateComputer()=0;
virtual ~Instance();
@ -42,6 +46,7 @@ protected:
std::vector<json> _memory;
std::vector<json> _gpu;
std::vector<json> _display;
json _computer;
};
} // namespace platform

View file

@ -26,9 +26,12 @@ namespace platform {
static const char* displayCoordsRight { "coordinatesright"};
static const char* displayCoordsTop { "coordinatestop"};
static const char* displayCoordsBottom { "coordinatesbottom"};
static const char* computerModel { "computerModel"};
#endif
}
} // namespace platform
} // namespace plaform::jsonKeys
#endif

View file

@ -22,6 +22,10 @@
#elif defined(Q_OS_MAC)
#include <OpenGL/OpenGL.h>
#include <sstream>
#include <QString>
#include <qstringlist.h>
#endif
#include <QtCore/QtGlobal>
@ -56,6 +60,27 @@ GPUIdent* GPUIdent::ensureQuery(const QString& vendor, const QString& renderer)
}
}
}
//get gpu name
FILE* stream = popen("system_profiler SPDisplaysDataType | grep Chipset", "r");
std::ostringstream hostStream;
while (!feof(stream) && !ferror(stream)) {
char buf[128];
int bytesRead = fread(buf, 1, 128, stream);
hostStream.write(buf, bytesRead);
}
QString result = QString::fromStdString(hostStream.str());
QStringList parts = result.split('\n');
std::string name;
for (int i = 0; i < parts.size(); ++i) {
if (parts[i].toLower().contains("radeon") || parts[i].toLower().contains("nvidia")) {
_name=parts[i];
}
}
_dedicatedMemoryMB = bestVRAM;
CGLDestroyRendererInfo(rendererInfo);