Hash :
d193d51b
Author :
Date :
2024-06-17T22:46:08
Replace issue ids post migration to new issue tracker This change replaces anglebug.com/NNNN links. Bug: None Change-Id: I8ac3aec8d2a8a844b3d7b99fc0a6b2be8da31761 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5637912 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
//
// 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_vulkan.cpp: Generic vulkan implementation of SystemInfo.h
// TODO: Use VK_KHR_driver_properties. http://anglebug.com/42263671
#include "gpu_info_util/SystemInfo_vulkan.h"
#include <vulkan/vulkan.h>
#include "gpu_info_util/SystemInfo_internal.h"
#include <algorithm>
#include <cstring>
#include <fstream>
#include <string>
#include <vector>
#include "common/angleutils.h"
#include "common/debug.h"
#include "common/platform_helpers.h"
#include "common/system_utils.h"
#include "common/vulkan/libvulkan_loader.h"
namespace angle
{
class VulkanLibrary final : NonCopyable
{
public:
VulkanLibrary() = default;
~VulkanLibrary()
{
if (mInstance != VK_NULL_HANDLE)
{
auto pfnDestroyInstance = getProc<PFN_vkDestroyInstance>("vkDestroyInstance");
if (pfnDestroyInstance)
{
pfnDestroyInstance(mInstance, nullptr);
}
}
CloseSystemLibrary(mLibVulkan);
}
std::vector<std::string> GetInstanceExtensionNames() const
{
std::vector<std::string> extensionNames;
auto pfnEnumerateInstanceExtensionProperties =
getProc<PFN_vkEnumerateInstanceExtensionProperties>(
"vkEnumerateInstanceExtensionProperties");
if (!pfnEnumerateInstanceExtensionProperties)
{
return extensionNames;
}
uint32_t extensionCount = 0;
if (pfnEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr) !=
VK_SUCCESS)
{
return extensionNames;
}
std::vector<VkExtensionProperties> extensions(extensionCount);
if (pfnEnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensions.data()) !=
VK_SUCCESS)
{
return extensionNames;
}
for (const auto &extension : extensions)
{
extensionNames.emplace_back(extension.extensionName);
}
std::sort(extensionNames.begin(), extensionNames.end());
return extensionNames;
}
bool ExtensionFound(std::string const &needle, const std::vector<std::string> &haystack)
{
// NOTE: The list must be sorted.
return std::binary_search(haystack.begin(), haystack.end(), needle);
}
VkInstance getVulkanInstance()
{
mLibVulkan = vk::OpenLibVulkan();
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)
auto pfnEnumerateInstanceVersion =
getProc<PFN_vkEnumerateInstanceVersion>("vkEnumerateInstanceVersion");
if (!pfnEnumerateInstanceVersion ||
pfnEnumerateInstanceVersion(&instanceVersion) != VK_SUCCESS)
{
instanceVersion = VK_API_VERSION_1_0;
}
#endif // VK_VERSION_1_1
std::vector<std::string> availableInstanceExtensions = GetInstanceExtensionNames();
std::vector<const char *> enabledInstanceExtensions;
bool hasPortabilityEnumeration = false;
if (IsApple() && ExtensionFound(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME,
availableInstanceExtensions))
{
// On iOS/macOS, there is no native Vulkan driver, so we need to
// enable the portability enumeration extension to allow use of
// MoltenVK.
enabledInstanceExtensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
hasPortabilityEnumeration = true;
}
// 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 =
static_cast<uint32_t>(enabledInstanceExtensions.size());
createInstanceInfo.ppEnabledExtensionNames =
enabledInstanceExtensions.empty() ? nullptr : enabledInstanceExtensions.data();
if (hasPortabilityEnumeration)
{
createInstanceInfo.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
}
auto pfnCreateInstance = getProc<PFN_vkCreateInstance>("vkCreateInstance");
if (!pfnCreateInstance ||
pfnCreateInstance(&createInstanceInfo, nullptr, &mInstance) != VK_SUCCESS)
{
return VK_NULL_HANDLE;
}
return mInstance;
}
template <typename Func>
Func getProc(const char *fn) const
{
return reinterpret_cast<Func>(angle::GetLibrarySymbol(mLibVulkan, 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;
size_t len = FormatStringIntoVector(fmt, vararg, buffer);
va_end(vararg);
return std::string(&buffer[0], len);
}
bool GetSystemInfoVulkan(SystemInfo *info)
{
return GetSystemInfoVulkanWithICD(info, vk::ICD::Default);
}
bool GetSystemInfoVulkanWithICD(SystemInfo *info, vk::ICD preferredICD)
{
const bool enableValidationLayers = false;
vk::ScopedVkLoaderEnvironment scopedEnvironment(enableValidationLayers, preferredICD);
// 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:
auto pfnEnumeratePhysicalDevices =
vkLibrary.getProc<PFN_vkEnumeratePhysicalDevices>("vkEnumeratePhysicalDevices");
auto pfnGetPhysicalDeviceProperties =
vkLibrary.getProc<PFN_vkGetPhysicalDeviceProperties>("vkGetPhysicalDeviceProperties");
auto pfnGetPhysicalDeviceProperties2 =
vkLibrary.getProc<PFN_vkGetPhysicalDeviceProperties2>("vkGetPhysicalDeviceProperties2");
uint32_t physicalDeviceCount = 0;
if (!pfnEnumeratePhysicalDevices || !pfnGetPhysicalDeviceProperties ||
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++)
{
VkPhysicalDeviceDriverProperties driverProperties = {};
driverProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES;
VkPhysicalDeviceProperties2 properties2 = {};
properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
properties2.pNext = &driverProperties;
VkPhysicalDeviceProperties &properties = properties2.properties;
pfnGetPhysicalDeviceProperties(physicalDevices[i], &properties);
// vkGetPhysicalDeviceProperties2() is supported since 1.1
// Use vkGetPhysicalDeviceProperties2() to get driver information.
if (properties.apiVersion >= VK_API_VERSION_1_1)
{
pfnGetPhysicalDeviceProperties2(physicalDevices[i], &properties2);
}
// 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/42261385)
// TODO(http://anglebug.com/42266143): Use driverID instead of the hardware vendorID to
// detect driveVendor, etc.
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_GOOGLE:
gpu.driverVendor = "Google";
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_Samsung:
gpu.driverVendor = "Samsung";
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;
case kVendorID_Mesa:
gpu.driverVendor = "Mesa";
gpu.driverVersion = FormatString("0x%x", properties.driverVersion);
gpu.detailedDriverVersion.major = properties.driverVersion;
break;
case kVendorID_Apple:
// Note: this is the version extraction for MoltenVK, which
// formulates its version number as a decimal number like so:
// (major * 10000) + (minor * 100) + patch
gpu.driverVendor = "Apple";
gpu.detailedDriverVersion.major = properties.driverVersion / 10000;
gpu.detailedDriverVersion.minor = (properties.driverVersion / 100) % 100;
gpu.detailedDriverVersion.patch = properties.driverVersion % 100;
gpu.driverVersion =
FormatString("%d.%d.%d", gpu.detailedDriverVersion.major,
gpu.detailedDriverVersion.minor, gpu.detailedDriverVersion.patch);
break;
default:
return false;
}
gpu.driverId = static_cast<DriverID>(driverProperties.driverID);
gpu.driverApiVersion = properties.apiVersion;
gpu.driverDate = "";
}
return true;
}
} // namespace angle