Skip to content

Commit

Permalink
Fuchsia: Implement SystemInfo on Fuchsia
Browse files Browse the repository at this point in the history
The Android vulkan code is reusable, so move that to a new file
SystemInfo_vulkan.cpp and call it in the Android & Fuchsia
implementations. This is necessary to skip tests based on GPU.

Bug: angleproject:4349, angleproject:4352
Change-Id: I8330cfcdbd41f4d51391bd5ed7f0820c55e02801
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2023909
Commit-Queue: Michael Spang <spang@chromium.org>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
  • Loading branch information
mspang authored and Commit Bot committed Jan 28, 2020
1 parent e3ba0d7 commit b630bf9
Show file tree
Hide file tree
Showing 6 changed files with 305 additions and 215 deletions.
14 changes: 12 additions & 2 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,18 @@ angle_static_library("angle_gpu_info_util") {
libs = []
defines = []

if (is_android || is_fuchsia) {
sources += libangle_gpu_info_util_vulkan_sources
}

if (is_android) {
sources += [ "src/gpu_info_util/SystemInfo_android.cpp" ]
sources += libangle_gpu_info_util_android_sources
}

if (is_fuchsia) {
sources += libangle_gpu_info_util_fuchsia_sources
deps +=
[ "$angle_root/src/libANGLE/renderer/vulkan:angle_vulkan_entry_points" ]
}

if (is_win) {
Expand All @@ -363,7 +373,7 @@ angle_static_library("angle_gpu_info_util") {
libs += [ "dxgi.lib" ]
}

if (is_linux || is_fuchsia) {
if (is_linux) {
sources += libangle_gpu_info_util_linux_sources

if (angle_use_x11) {
Expand Down
215 changes: 2 additions & 213 deletions src/gpu_info_util/SystemInfo_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <dlfcn.h>
#include <vulkan/vulkan.h>
#include "gpu_info_util/SystemInfo_internal.h"
#include "gpu_info_util/SystemInfo_vulkan.h"

#include <sys/system_properties.h>
#include <cstring>
Expand All @@ -19,97 +20,6 @@

namespace angle
{
class VulkanLibrary final : NonCopyable
{
public:
VulkanLibrary() {}
~VulkanLibrary()
{
if (mInstance != VK_NULL_HANDLE)
{
PFN_vkDestroyInstance pfnDestroyInstance =
reinterpret_cast<PFN_vkDestroyInstance>(dlsym(mLibVulkan, "vkDestroyInstance"));
if (pfnDestroyInstance)
{
pfnDestroyInstance(mInstance, nullptr);
}
}
if (mLibVulkan)
dlclose(mLibVulkan);
}
VkInstance getVulkanInstance()
{
// Find the system's Vulkan library and open it:
mLibVulkan = dlopen("libvulkan.so", RTLD_NOW | RTLD_LOCAL);
if (!mLibVulkan)
{
// If Vulkan doesn't exist, bail-out early:
return VK_NULL_HANDLE;
}

// Determine the available Vulkan instance version:
uint32_t instanceVersion = VK_API_VERSION_1_0;
#if defined(VK_VERSION_1_1)
PFN_vkEnumerateInstanceVersion pfnEnumerateInstanceVersion =
reinterpret_cast<PFN_vkEnumerateInstanceVersion>(
dlsym(mLibVulkan, "vkEnumerateInstanceVersion"));
if (!pfnEnumerateInstanceVersion ||
pfnEnumerateInstanceVersion(&instanceVersion) != VK_SUCCESS)
{
instanceVersion = VK_API_VERSION_1_0;
}
#endif // VK_VERSION_1_1

// Create a Vulkan instance:
VkApplicationInfo appInfo;
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pNext = nullptr;
appInfo.pApplicationName = "";
appInfo.applicationVersion = 1;
appInfo.pEngineName = "";
appInfo.engineVersion = 1;
appInfo.apiVersion = instanceVersion;

VkInstanceCreateInfo createInstanceInfo;
createInstanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInstanceInfo.pNext = nullptr;
createInstanceInfo.flags = 0;
createInstanceInfo.pApplicationInfo = &appInfo;
createInstanceInfo.enabledLayerCount = 0;
createInstanceInfo.ppEnabledLayerNames = nullptr;
createInstanceInfo.enabledExtensionCount = 0;
createInstanceInfo.ppEnabledExtensionNames = nullptr;

PFN_vkCreateInstance pfnCreateInstance =
reinterpret_cast<PFN_vkCreateInstance>(dlsym(mLibVulkan, "vkCreateInstance"));
if (!pfnCreateInstance ||
pfnCreateInstance(&createInstanceInfo, nullptr, &mInstance) != VK_SUCCESS)
{
return VK_NULL_HANDLE;
}

return mInstance;
}
void *gpa(std::string fn) { return dlsym(mLibVulkan, fn.c_str()); }
#define GPA(ob, type, fn) reinterpret_cast<type>(ob.gpa(fn))

private:
void *mLibVulkan = nullptr;
VkInstance mInstance = VK_NULL_HANDLE;
};

ANGLE_FORMAT_PRINTF(1, 2)
std::string FormatString(const char *fmt, ...)
{
va_list vararg;
va_start(vararg, fmt);

std::vector<char> buffer(512);
size_t len = FormatStringIntoVector(fmt, vararg, buffer);
va_end(vararg);

return std::string(&buffer[0], len);
}

bool GetAndroidSystemProperty(const std::string &propertyName, std::string *value)
{
Expand All @@ -134,128 +44,7 @@ bool GetSystemInfo(SystemInfo *info)
isFullyPopulated =
GetAndroidSystemProperty("ro.product.model", &info->machineModelName) && isFullyPopulated;

// This implementation builds on top of the Vulkan API, but cannot assume the existence of the
// Vulkan library. ANGLE can be installed on versions of Android as old as Ice Cream Sandwich.
// Therefore, we need to use dlopen()/dlsym() in order to see if Vulkan is installed on the
// system, and if so, to use it:
VulkanLibrary vkLibrary;
VkInstance instance = vkLibrary.getVulkanInstance();
if (instance == VK_NULL_HANDLE)
{
// If Vulkan doesn't exist, bail-out early:
return false;
}

// Enumerate the Vulkan physical devices, which are ANGLE gpus:
PFN_vkEnumeratePhysicalDevices pfnEnumeratePhysicalDevices =
GPA(vkLibrary, PFN_vkEnumeratePhysicalDevices, "vkEnumeratePhysicalDevices");
PFN_vkGetPhysicalDeviceProperties pfnGetPhysicalDeviceProperties =
GPA(vkLibrary, PFN_vkGetPhysicalDeviceProperties, "vkGetPhysicalDeviceProperties");
uint32_t physicalDeviceCount = 0;
if (!pfnEnumeratePhysicalDevices ||
pfnEnumeratePhysicalDevices(instance, &physicalDeviceCount, nullptr) != VK_SUCCESS)
{
return false;
}
std::vector<VkPhysicalDevice> physicalDevices(physicalDeviceCount);
if (pfnEnumeratePhysicalDevices(instance, &physicalDeviceCount, physicalDevices.data()) !=
VK_SUCCESS)
{
return false;
}

// If we get to here, we will likely provide a valid answer (unless an unknown vendorID):
info->gpus.resize(physicalDeviceCount);

for (uint32_t i = 0; i < physicalDeviceCount; i++)
{
VkPhysicalDeviceProperties properties;
pfnGetPhysicalDeviceProperties(physicalDevices[i], &properties);
// Fill in data for a given physical device (a.k.a. gpu):
GPUDeviceInfo &gpu = info->gpus[i];
gpu.vendorId = properties.vendorID;
gpu.deviceId = properties.deviceID;
// Need to parse/re-format properties.driverVersion.
//
// TODO(ianelliott): Determine the formatting used for each vendor
// (http://anglebug.com/2677)
switch (properties.vendorID)
{
case kVendorID_AMD:
gpu.driverVendor = "Advanced Micro Devices, Inc";
gpu.driverVersion = FormatString("0x%x", properties.driverVersion);
gpu.detailedDriverVersion.major = properties.driverVersion;
break;
case kVendorID_ARM:
gpu.driverVendor = "Arm Holdings";
gpu.driverVersion = FormatString("0x%x", properties.driverVersion);
gpu.detailedDriverVersion.major = properties.driverVersion;
break;
case kVendorID_Broadcom:
gpu.driverVendor = "Broadcom";
gpu.driverVersion = FormatString("0x%x", properties.driverVersion);
gpu.detailedDriverVersion.major = properties.driverVersion;
break;
case kVendorID_ImgTec:
gpu.driverVendor = "Imagination Technologies Limited";
gpu.driverVersion = FormatString("0x%x", properties.driverVersion);
gpu.detailedDriverVersion.major = properties.driverVersion;
break;
case kVendorID_Intel:
gpu.driverVendor = "Intel Corporation";
gpu.driverVersion = FormatString("0x%x", properties.driverVersion);
gpu.detailedDriverVersion.major = properties.driverVersion;
break;
case kVendorID_Kazan:
gpu.driverVendor = "Kazan Software";
gpu.driverVersion = FormatString("0x%x", properties.driverVersion);
gpu.detailedDriverVersion.major = properties.driverVersion;
break;
case kVendorID_NVIDIA:
gpu.driverVendor = "NVIDIA Corporation";
gpu.driverVersion = FormatString("%d.%d.%d.%d", properties.driverVersion >> 22,
(properties.driverVersion >> 14) & 0XFF,
(properties.driverVersion >> 6) & 0XFF,
properties.driverVersion & 0x3F);
gpu.detailedDriverVersion.major = properties.driverVersion >> 22;
gpu.detailedDriverVersion.minor = (properties.driverVersion >> 14) & 0xFF;
gpu.detailedDriverVersion.subMinor = (properties.driverVersion >> 6) & 0xFF;
gpu.detailedDriverVersion.patch = properties.driverVersion & 0x3F;
break;
case kVendorID_Qualcomm:
gpu.driverVendor = "Qualcomm Technologies, Inc";
if (properties.driverVersion & 0x80000000)
{
gpu.driverVersion = FormatString("%d.%d.%d", properties.driverVersion >> 22,
(properties.driverVersion >> 12) & 0X3FF,
properties.driverVersion & 0xFFF);
gpu.detailedDriverVersion.major = properties.driverVersion >> 22;
gpu.detailedDriverVersion.minor = (properties.driverVersion >> 12) & 0x3FF;
gpu.detailedDriverVersion.subMinor = properties.driverVersion & 0xFFF;
}
else
{
gpu.driverVersion = FormatString("0x%x", properties.driverVersion);
gpu.detailedDriverVersion.major = properties.driverVersion;
}
break;
case kVendorID_VeriSilicon:
gpu.driverVendor = "VeriSilicon";
gpu.driverVersion = FormatString("0x%x", properties.driverVersion);
gpu.detailedDriverVersion.major = properties.driverVersion;
break;
case kVendorID_Vivante:
gpu.driverVendor = "Vivante";
gpu.driverVersion = FormatString("0x%x", properties.driverVersion);
gpu.detailedDriverVersion.major = properties.driverVersion;
break;
default:
return false;
}
gpu.driverDate = "";
}

return isFullyPopulated;
return GetSystemInfoVulkan(info) && isFullyPopulated;
}

} // namespace angle
19 changes: 19 additions & 0 deletions src/gpu_info_util/SystemInfo_fuchsia.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Copyright 2020 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_fuchsia.cpp: implementation of the Fuchsia-specific parts of SystemInfo.h

#include "gpu_info_util/SystemInfo_vulkan.h"

namespace angle
{

bool GetSystemInfo(SystemInfo *info)
{
return GetSystemInfoVulkan(info);
}

} // namespace angle
Loading

0 comments on commit b630bf9

Please sign in to comment.