1 // 2 // Copyright 2013 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 // SystemInfo.h: gathers information available without starting a GPU driver. 8 9 #ifndef GPU_INFO_UTIL_SYSTEM_INFO_H_ 10 #define GPU_INFO_UTIL_SYSTEM_INFO_H_ 11 12 #include <cstdint> 13 #include <string> 14 #include <vector> 15 16 namespace angle 17 { 18 19 using VendorID = uint32_t; 20 using DeviceID = uint32_t; 21 using RevisionID = uint32_t; 22 23 struct VersionInfo 24 { 25 uint32_t major = 0; 26 uint32_t minor = 0; 27 uint32_t subMinor = 0; 28 uint32_t patch = 0; 29 }; 30 31 struct GPUDeviceInfo 32 { 33 GPUDeviceInfo(); 34 ~GPUDeviceInfo(); 35 36 GPUDeviceInfo(const GPUDeviceInfo &other); 37 38 VendorID vendorId = 0; 39 DeviceID deviceId = 0; 40 RevisionID revisionId = 0; 41 42 std::string driverVendor; 43 std::string driverVersion; 44 std::string driverDate; 45 46 // Only available via GetSystemInfoVulkan currently. 47 VersionInfo detailedDriverVersion; 48 }; 49 50 struct SystemInfo 51 { 52 SystemInfo(); 53 ~SystemInfo(); 54 55 SystemInfo(const SystemInfo &other); 56 57 bool hasNVIDIAGPU() const; 58 bool hasIntelGPU() const; 59 bool hasAMDGPU() const; 60 61 std::vector<GPUDeviceInfo> gpus; 62 63 // Index of the GPU expected to be used for 3D graphics. Based on a best-guess heuristic on 64 // some platforms. On Windows, this is accurate. Note `gpus` must be checked for empty before 65 // indexing. 66 int activeGPUIndex = 0; 67 68 bool isOptimus = false; 69 bool isAMDSwitchable = false; 70 // Only true on dual-GPU Mac laptops. 71 bool isMacSwitchable = false; 72 // Only true on Apple Silicon Macs when running in macCatalyst. 73 bool needsEAGLOnMac = false; 74 75 // Only available on Android 76 std::string machineManufacturer; 77 int androidSdkLevel = 0; 78 79 // Only available on macOS and Android 80 std::string machineModelName; 81 82 // Only available on macOS 83 std::string machineModelVersion; 84 }; 85 86 // Gathers information about the system without starting a GPU driver and returns them in `info`. 87 // Returns true if all info was gathered, false otherwise. Even when false is returned, `info` will 88 // be filled with partial information. 89 bool GetSystemInfo(SystemInfo *info); 90 91 // Vulkan-specific info collection. 92 bool GetSystemInfoVulkan(SystemInfo *info); 93 94 // Known PCI vendor IDs 95 constexpr VendorID kVendorID_AMD = 0x1002; 96 constexpr VendorID kVendorID_ARM = 0x13B5; 97 constexpr VendorID kVendorID_Broadcom = 0x14E4; 98 constexpr VendorID kVendorID_GOOGLE = 0x1AE0; 99 constexpr VendorID kVendorID_ImgTec = 0x1010; 100 constexpr VendorID kVendorID_Intel = 0x8086; 101 constexpr VendorID kVendorID_NVIDIA = 0x10DE; 102 constexpr VendorID kVendorID_Qualcomm = 0x5143; 103 constexpr VendorID kVendorID_VMWare = 0x15ad; 104 constexpr VendorID kVendorID_Apple = 0x106B; 105 106 // Known non-PCI (i.e. Khronos-registered) vendor IDs 107 constexpr VendorID kVendorID_Vivante = 0x10001; 108 constexpr VendorID kVendorID_VeriSilicon = 0x10002; 109 constexpr VendorID kVendorID_Kazan = 0x10003; 110 111 // Known device IDs 112 constexpr DeviceID kDeviceID_Swiftshader = 0xC0DE; 113 constexpr DeviceID kDeviceID_Adreno540 = 0x5040001; 114 constexpr DeviceID kDeviceID_UHD630Mobile = 0x3E9B; 115 116 // Predicates on vendor IDs 117 bool IsAMD(VendorID vendorId); 118 bool IsARM(VendorID vendorId); 119 bool IsBroadcom(VendorID vendorId); 120 bool IsImgTec(VendorID vendorId); 121 bool IsIntel(VendorID vendorId); 122 bool IsKazan(VendorID vendorId); 123 bool IsNVIDIA(VendorID vendorId); 124 bool IsQualcomm(VendorID vendorId); 125 bool IsGoogle(VendorID vendorId); 126 bool IsSwiftshader(VendorID vendorId); 127 bool IsVeriSilicon(VendorID vendorId); 128 bool IsVMWare(VendorID vendorId); 129 bool IsVivante(VendorID vendorId); 130 bool IsApple(VendorID vendorId); 131 132 // Use a heuristic to attempt to find the GPU used for 3D graphics. Sets activeGPUIndex, 133 // isOptimus, and isAMDSwitchable. 134 // Always assumes the non-Intel GPU is active on dual-GPU machines. 135 void GetDualGPUInfo(SystemInfo *info); 136 137 // Dumps the system info to stdout. 138 void PrintSystemInfo(const SystemInfo &info); 139 140 VersionInfo ParseNvidiaDriverVersion(uint32_t version); 141 142 #if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST) 143 // Helper to get the active GPU ID from a given Core Graphics display ID. 144 uint64_t GetGpuIDFromDisplayID(uint32_t displayID); 145 146 // Helper to get the active GPU ID from an OpenGL display mask. 147 uint64_t GetGpuIDFromOpenGLDisplayMask(uint32_t displayMask); 148 149 // Get VendorID from metal device's registry ID 150 VendorID GetVendorIDFromMetalDeviceRegistryID(uint64_t registryID); 151 #endif 152 153 } // namespace angle 154 155 #endif // GPU_INFO_UTIL_SYSTEM_INFO_H_ 156