Commit 878baf90 by Corentin Wallez Committed by Commit Bot

gpu_info_util: address comments for CL 438940

BUG=angleproject:1874 Change-Id: I6397d9141a7c25f818ce970212a4a8e8afbd5a27 Reviewed-on: https://chromium-review.googlesource.com/442676Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
parent 38a24a94
...@@ -171,7 +171,10 @@ static_library("angle_image_util") { ...@@ -171,7 +171,10 @@ static_library("angle_image_util") {
sources = rebase_path(gles_gypi.libangle_image_util_sources, ".", "src") sources = rebase_path(gles_gypi.libangle_image_util_sources, ".", "src")
configs -= angle_undefine_configs configs -= angle_undefine_configs
configs += [ ":internal_config" ] configs += [
":internal_config",
":extra_warnings",
]
public_configs = [ ":angle_image_util_config" ] public_configs = [ ":angle_image_util_config" ]
...@@ -189,7 +192,10 @@ config("angle_gpu_info_util_config") { ...@@ -189,7 +192,10 @@ config("angle_gpu_info_util_config") {
static_library("angle_gpu_info_util") { static_library("angle_gpu_info_util") {
configs -= angle_undefine_configs configs -= angle_undefine_configs
configs += [ ":internal_config" ] configs += [
":internal_config",
":extra_warnings",
]
public_configs = [ ":angle_gpu_info_util_config" ] public_configs = [ ":angle_gpu_info_util_config" ]
...@@ -207,9 +213,8 @@ static_library("angle_gpu_info_util") { ...@@ -207,9 +213,8 @@ static_library("angle_gpu_info_util") {
rebase_path(gles_gypi.libangle_gpu_info_util_linux_sources, ".", "src") rebase_path(gles_gypi.libangle_gpu_info_util_linux_sources, ".", "src")
if (use_x11) { if (use_x11) {
sources += rebase_path(gles_gypi.libangle_gpu_info_util_x11_sources, sources +=
".", rebase_path(gles_gypi.libangle_gpu_info_util_x11_sources, ".", "src")
"src")
deps += [ "src/third_party/libXNVCtrl:libXNVCtrl" ] deps += [ "src/third_party/libXNVCtrl:libXNVCtrl" ]
defines += [ "GPU_INFO_USE_X11" ] defines += [ "GPU_INFO_USE_X11" ]
libs += [ libs += [
...@@ -369,8 +374,8 @@ static_library("libANGLE") { ...@@ -369,8 +374,8 @@ static_library("libANGLE") {
":angle_common", ":angle_common",
] ]
deps = [ deps = [
":angle_image_util",
":angle_gpu_info_util", ":angle_gpu_info_util",
":angle_image_util",
":commit_id", ":commit_id",
":includes", ":includes",
":translator", ":translator",
......
...@@ -237,7 +237,8 @@ ...@@ -237,7 +237,8 @@
[ [
'<(angle_path)/src/third_party/libXNVCtrl/libXNVCtrl.gyp:libXNVCtrl', '<(angle_path)/src/third_party/libXNVCtrl/libXNVCtrl.gyp:libXNVCtrl',
], ],
'link_settings': { 'link_settings':
{
'ldflags': 'ldflags':
[ [
'<!@(<(pkg-config) --libs-only-L --libs-only-other x11 xi xext)', '<!@(<(pkg-config) --libs-only-L --libs-only-other x11 xi xext)',
...@@ -258,7 +259,8 @@ ...@@ -258,7 +259,8 @@
[ [
'GPU_INFO_USE_LIBPCI', 'GPU_INFO_USE_LIBPCI',
], ],
'link_settings': { 'link_settings':
{
'ldflags': 'ldflags':
[ [
'<!@(<(pkg-config) --libs-only-L --libs-only-other libpci)', '<!@(<(pkg-config) --libs-only-L --libs-only-other libpci)',
......
...@@ -14,24 +14,24 @@ ...@@ -14,24 +14,24 @@
namespace angle namespace angle
{ {
bool IsAMD(uint32_t vendorId) bool IsAMD(VendorID vendorId)
{ {
return vendorId == VENDOR_ID_AMD; return vendorId == kVendorID_AMD;
} }
bool IsIntel(uint32_t vendorId) bool IsIntel(VendorID vendorId)
{ {
return vendorId == VENDOR_ID_INTEL; return vendorId == kVendorID_Intel;
} }
bool IsNvidia(uint32_t vendorId) bool IsNvidia(VendorID vendorId)
{ {
return vendorId == VENDOR_ID_NVIDIA; return vendorId == kVendorID_Nvidia;
} }
bool IsQualcomm(uint32_t vendorId) bool IsQualcomm(VendorID vendorId)
{ {
return vendorId == VENDOR_ID_QUALCOMM; return vendorId == kVendorID_Qualcomm;
} }
bool ParseAMDBrahmaDriverVersion(const std::string &content, std::string *version) bool ParseAMDBrahmaDriverVersion(const std::string &content, std::string *version)
......
...@@ -16,10 +16,18 @@ ...@@ -16,10 +16,18 @@
namespace angle namespace angle
{ {
using VendorID = uint32_t;
using DeviceID = uint32_t;
constexpr VendorID kVendorID_AMD = 0x1002;
constexpr VendorID kVendorID_Intel = 0x8086;
constexpr VendorID kVendorID_Nvidia = 0x10DE;
constexpr VendorID kVendorID_Qualcomm = 0x5143;
struct GPUDeviceInfo struct GPUDeviceInfo
{ {
uint32_t vendorId; VendorID vendorId;
uint32_t deviceId; DeviceID deviceId;
std::string driverVendor; std::string driverVendor;
std::string driverVersion; std::string driverVersion;
...@@ -39,21 +47,10 @@ struct SystemInfo ...@@ -39,21 +47,10 @@ struct SystemInfo
bool GetSystemInfo(SystemInfo *info); bool GetSystemInfo(SystemInfo *info);
enum VendorID : uint32_t bool IsAMD(VendorID vendorId);
{ bool IsIntel(VendorID vendorId);
VENDOR_ID_UNKNOWN = 0x0, bool IsNvidia(VendorID vendorId);
VENDOR_ID_AMD = 0x1002, bool IsQualcomm(VendorID vendorId);
VENDOR_ID_INTEL = 0x8086,
VENDOR_ID_NVIDIA = 0x10DE,
// This is Qualcomm PCI Vendor ID.
// Android doesn't have a PCI bus, but all we need is a unique id.
VENDOR_ID_QUALCOMM = 0x5143,
};
bool IsAMD(uint32_t vendorId);
bool IsIntel(uint32_t vendorId);
bool IsNvidia(uint32_t vendorId);
bool IsQualcomm(uint32_t vendorId);
} // namespace angle } // namespace angle
......
...@@ -27,13 +27,13 @@ namespace ...@@ -27,13 +27,13 @@ namespace
struct LibPCI : angle::NonCopyable struct LibPCI : angle::NonCopyable
{ {
static bool IsSupported() LibPCI()
{ {
return access("/sys/bus/pci/", F_OK) == 0 || access("/sys/bs/pci_express/", F_OK) == 0; if (access("/sys/bus/pci/", F_OK) != 0 && access("/sys/bs/pci_express/", F_OK) != 0)
} {
return;
}
bool Load()
{
mHandle = dlopen("libpci.so.3", RTLD_LAZY); mHandle = dlopen("libpci.so.3", RTLD_LAZY);
if (mHandle == nullptr) if (mHandle == nullptr)
...@@ -43,22 +43,24 @@ struct LibPCI : angle::NonCopyable ...@@ -43,22 +43,24 @@ struct LibPCI : angle::NonCopyable
if (mHandle == nullptr) if (mHandle == nullptr)
{ {
return false; return;
} }
return (Alloc = reinterpret_cast<decltype(Alloc)>(dlsym(mHandle, "pci_alloc"))) != mValid =
nullptr && (Alloc = reinterpret_cast<decltype(Alloc)>(dlsym(mHandle, "pci_alloc"))) != nullptr &&
(Init = reinterpret_cast<decltype(Init)>(dlsym(mHandle, "pci_init"))) != nullptr && (Init = reinterpret_cast<decltype(Init)>(dlsym(mHandle, "pci_init"))) != nullptr &&
(Cleanup = reinterpret_cast<decltype(Cleanup)>(dlsym(mHandle, "pci_cleanup"))) != (Cleanup = reinterpret_cast<decltype(Cleanup)>(dlsym(mHandle, "pci_cleanup"))) !=
nullptr && nullptr &&
(ScanBus = reinterpret_cast<decltype(ScanBus)>(dlsym(mHandle, "pci_scan_bus"))) != (ScanBus = reinterpret_cast<decltype(ScanBus)>(dlsym(mHandle, "pci_scan_bus"))) !=
nullptr && nullptr &&
(FillInfo = reinterpret_cast<decltype(FillInfo)>(dlsym(mHandle, "pci_fill_info"))) != (FillInfo = reinterpret_cast<decltype(FillInfo)>(dlsym(mHandle, "pci_fill_info"))) !=
nullptr && nullptr &&
(LookupName = reinterpret_cast<decltype(LookupName)>( (LookupName = reinterpret_cast<decltype(LookupName)>(
dlsym(mHandle, "pci_lookup_name"))) != nullptr; dlsym(mHandle, "pci_lookup_name"))) != nullptr;
} }
bool IsValid() const { return mValid; }
~LibPCI() ~LibPCI()
{ {
if (mHandle != nullptr) if (mHandle != nullptr)
...@@ -76,6 +78,7 @@ struct LibPCI : angle::NonCopyable ...@@ -76,6 +78,7 @@ struct LibPCI : angle::NonCopyable
private: private:
void *mHandle = nullptr; void *mHandle = nullptr;
bool mValid = false;
}; };
} // anonymous namespace } // anonymous namespace
...@@ -83,13 +86,8 @@ struct LibPCI : angle::NonCopyable ...@@ -83,13 +86,8 @@ struct LibPCI : angle::NonCopyable
// Adds an entry per PCI GPU found and fills the device and vendor ID. // Adds an entry per PCI GPU found and fills the device and vendor ID.
bool GetPCIDevicesWithLibPCI(std::vector<GPUDeviceInfo> *devices) bool GetPCIDevicesWithLibPCI(std::vector<GPUDeviceInfo> *devices)
{ {
if (!LibPCI::IsSupported())
{
return false;
}
LibPCI pci; LibPCI pci;
if (!pci.Load()) if (!pci.IsValid())
{ {
return false; return false;
} }
......
...@@ -106,7 +106,7 @@ bool GetSystemInfo(SystemInfo *info) ...@@ -106,7 +106,7 @@ bool GetSystemInfo(SystemInfo *info)
GPUDeviceInfo *gpu = &info->gpus[i]; GPUDeviceInfo *gpu = &info->gpus[i];
// New GPUs might be added inside this loop, don't query for their driver version again // New GPUs might be added inside this loop, don't query for their driver version again
if (gpu->driverVendor.empty()) if (!gpu->driverVendor.empty())
{ {
continue; continue;
} }
...@@ -116,12 +116,12 @@ bool GetSystemInfo(SystemInfo *info) ...@@ -116,12 +116,12 @@ bool GetSystemInfo(SystemInfo *info)
std::string version; std::string version;
if (GetAMDBrahmaDriverVersion(&version)) if (GetAMDBrahmaDriverVersion(&version))
{ {
gpu->driverVendor = "ATI / AMD (Brahma)"; gpu->driverVendor = "AMD (Brahma)";
gpu->driverVersion = std::move(version); gpu->driverVersion = std::move(version);
} }
else if (GetAMDCatalystDriverVersion(&version)) else if (GetAMDCatalystDriverVersion(&version))
{ {
gpu->driverVendor = "ATI / AMD (Catalyst)"; gpu->driverVendor = "AMD (Catalyst)";
gpu->driverVersion = std::move(version); gpu->driverVersion = std::move(version);
} }
} }
...@@ -145,7 +145,7 @@ bool GetSystemInfo(SystemInfo *info) ...@@ -145,7 +145,7 @@ bool GetSystemInfo(SystemInfo *info)
if (GetNvidiaDriverVersionWithXNVCtrl(&version)) if (GetNvidiaDriverVersionWithXNVCtrl(&version))
{ {
GPUDeviceInfo nvidiaInfo; GPUDeviceInfo nvidiaInfo;
nvidiaInfo.vendorId = VENDOR_ID_NVIDIA; nvidiaInfo.vendorId = kVendorID_Nvidia;
nvidiaInfo.deviceId = 0; nvidiaInfo.deviceId = 0;
gpu->driverVendor = "Nvidia"; gpu->driverVendor = "Nvidia";
gpu->driverVersion = std::move(version); gpu->driverVersion = std::move(version);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment