Hash :
d83f64f5
Author :
Date :
2017-02-16T10:58:46
gpu_info_util: Implement GetSystemInfo on OSX Also adds a test that prints the gathered information for manual checking and to help know what the system is when looking at the logs. BUG=angleproject:1874 Change-Id: Icb0cc390c9808fd8db0f966d667b94dde4b94e62 Reviewed-on: https://chromium-review.googlesource.com/443845 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Zhenyao Mo <zmo@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
//
// Copyright (c) 2013-2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// SystemInfo.cpp: implementation of the system-agnostic parts of SystemInfo.h
#include "gpu_info_util/SystemInfo.h"
#include <cstring>
#include <sstream>
#include "common/debug.h"
namespace angle
{
bool IsAMD(VendorID vendorId)
{
return vendorId == kVendorID_AMD;
}
bool IsIntel(VendorID vendorId)
{
return vendorId == kVendorID_Intel;
}
bool IsNvidia(VendorID vendorId)
{
return vendorId == kVendorID_Nvidia;
}
bool IsQualcomm(VendorID vendorId)
{
return vendorId == kVendorID_Qualcomm;
}
bool ParseAMDBrahmaDriverVersion(const std::string &content, std::string *version)
{
const size_t begin = content.find_first_of("0123456789");
if (begin == std::string::npos)
{
return false;
}
const size_t end = content.find_first_not_of("0123456789.", begin);
if (end == std::string::npos)
{
*version = content.substr(begin);
}
else
{
*version = content.substr(begin, end - begin);
}
return true;
}
bool ParseAMDCatalystDriverVersion(const std::string &content, std::string *version)
{
std::istringstream stream(content);
std::string line;
while (std::getline(stream, line))
{
static const char kReleaseVersion[] = "ReleaseVersion=";
if (line.compare(0, std::strlen(kReleaseVersion), kReleaseVersion) != 0)
{
continue;
}
if (ParseAMDBrahmaDriverVersion(line, version))
{
return true;
}
}
return false;
}
bool ParseMacMachineModel(const std::string &identifier,
std::string *type,
int32_t *major,
int32_t *minor)
{
size_t numberLoc = identifier.find_first_of("0123456789");
if (numberLoc == std::string::npos)
{
return false;
}
size_t commaLoc = identifier.find(',', numberLoc);
if (commaLoc == std::string::npos || commaLoc >= identifier.size())
{
return false;
}
const char *numberPtr = &identifier[numberLoc];
const char *commaPtr = &identifier[commaLoc + 1];
char *endPtr = nullptr;
int32_t majorTmp = std::strtol(numberPtr, &endPtr, 10);
if (endPtr == numberPtr)
{
return false;
}
int32_t minorTmp = std::strtol(commaPtr, &endPtr, 10);
if (endPtr == commaPtr)
{
return false;
}
*major = majorTmp;
*minor = minorTmp;
*type = identifier.substr(0, numberLoc);
return true;
}
void FindPrimaryGPU(SystemInfo *info)
{
ASSERT(!info->gpus.empty());
// On dual-GPU systems we assume the non-Intel GPU is the primary one.
int primary = 0;
bool hasIntel = false;
for (size_t i = 0; i < info->gpus.size(); ++i)
{
if (IsIntel(info->gpus[i].vendorId))
{
hasIntel = true;
}
if (IsIntel(info->gpus[primary].vendorId))
{
primary = static_cast<int>(i);
}
}
// Assume that a combination of AMD or Nvidia with Intel means Optimus or AMD Switchable
info->primaryGPUIndex = primary;
info->isOptimus = hasIntel && IsNvidia(info->gpus[primary].vendorId);
info->isAMDSwitchable = hasIntel && IsAMD(info->gpus[primary].vendorId);
}
} // namespace angle