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 <optional> 14 #include <string> 15 #include <vector> 16 17 namespace angle 18 { 19 20 using VendorID = uint32_t; 21 using DeviceID = uint32_t; 22 using RevisionID = uint32_t; 23 using SystemDeviceID = uint64_t; 24 using DriverID = uint32_t; 25 26 struct VersionInfo 27 { 28 uint32_t major = 0; 29 uint32_t minor = 0; 30 uint32_t subMinor = 0; 31 uint32_t patch = 0; 32 }; 33 34 struct GPUDeviceInfo 35 { 36 GPUDeviceInfo(); 37 ~GPUDeviceInfo(); 38 39 GPUDeviceInfo(const GPUDeviceInfo &other); 40 41 VendorID vendorId = 0; 42 DeviceID deviceId = 0; 43 RevisionID revisionId = 0; 44 SystemDeviceID systemDeviceId = 0; 45 46 std::string driverVendor; 47 std::string driverVersion; 48 std::string driverDate; 49 50 // Fields only available via GetSystemInfoVulkan: 51 VersionInfo detailedDriverVersion; 52 DriverID driverId = 0; 53 uint32_t driverApiVersion = 0; 54 }; 55 56 struct SystemInfo 57 { 58 SystemInfo(); 59 ~SystemInfo(); 60 61 SystemInfo(const SystemInfo &other); 62 63 bool hasNVIDIAGPU() const; 64 bool hasIntelGPU() const; 65 bool hasAMDGPU() const; 66 67 // Returns the index to `gpus` if the entry matches the preferred device string. 68 std::optional<size_t> getPreferredGPUIndex() const; 69 70 std::vector<GPUDeviceInfo> gpus; 71 72 // Index of the GPU expected to be used for 3D graphics. Based on a best-guess heuristic on 73 // some platforms. On Windows, this is accurate. Note `gpus` must be checked for empty before 74 // indexing. 75 int activeGPUIndex = 0; 76 77 bool isOptimus = false; 78 bool isAMDSwitchable = false; 79 // Only true on dual-GPU Mac laptops. 80 bool isMacSwitchable = false; 81 82 // Only available on Android 83 std::string machineManufacturer; 84 int androidSdkLevel = 0; 85 86 // Only available on macOS and Android 87 std::string machineModelName; 88 89 // Only available on macOS 90 std::string machineModelVersion; 91 }; 92 93 // Gathers information about the system without starting a GPU driver and returns them in `info`. 94 // Returns true if all info was gathered, false otherwise. Even when false is returned, `info` will 95 // be filled with partial information. 96 bool GetSystemInfo(SystemInfo *info); 97 98 // Vulkan-specific info collection. 99 bool GetSystemInfoVulkan(SystemInfo *info); 100 101 // Known PCI vendor IDs 102 constexpr VendorID kVendorID_AMD = 0x1002; 103 constexpr VendorID kVendorID_ARM = 0x13B5; 104 constexpr VendorID kVendorID_Broadcom = 0x14E4; 105 constexpr VendorID kVendorID_GOOGLE = 0x1AE0; 106 constexpr VendorID kVendorID_ImgTec = 0x1010; 107 constexpr VendorID kVendorID_Intel = 0x8086; 108 constexpr VendorID kVendorID_NVIDIA = 0x10DE; 109 constexpr VendorID kVendorID_Qualcomm = 0x5143; 110 constexpr VendorID kVendorID_Samsung = 0x144D; 111 constexpr VendorID kVendorID_VMWare = 0x15ad; 112 constexpr VendorID kVendorID_Apple = 0x106B; 113 constexpr VendorID kVendorID_Microsoft = 0x1414; 114 constexpr VendorID kVendorID_VirtIO = 0x1AF4; 115 116 // Known non-PCI (i.e. Khronos-registered) vendor IDs 117 constexpr VendorID kVendorID_Vivante = 0x10001; 118 constexpr VendorID kVendorID_VeriSilicon = 0x10002; 119 constexpr VendorID kVendorID_Kazan = 0x10003; 120 constexpr VendorID kVendorID_CodePlay = 0x10004; 121 constexpr VendorID kVendorID_Mesa = 0x10005; 122 constexpr VendorID kVendorID_PoCL = 0x10006; 123 124 // Known device IDs 125 constexpr DeviceID kDeviceID_Swiftshader = 0xC0DE; 126 constexpr DeviceID kDeviceID_Adreno540 = 0x5040001; 127 constexpr DeviceID kDeviceID_UHD630Mobile = 0x3E9B; 128 129 // Predicates on vendor IDs 130 bool IsAMD(VendorID vendorId); 131 bool IsARM(VendorID vendorId); 132 bool IsBroadcom(VendorID vendorId); 133 bool IsImgTec(VendorID vendorId); 134 bool IsIntel(VendorID vendorId); 135 bool IsKazan(VendorID vendorId); 136 bool IsNVIDIA(VendorID vendorId); 137 bool IsQualcomm(VendorID vendorId); 138 bool IsSamsung(VendorID vendorId); 139 bool IsGoogle(VendorID vendorId); 140 bool IsSwiftshader(VendorID vendorId); 141 bool IsVeriSilicon(VendorID vendorId); 142 bool IsVMWare(VendorID vendorId); 143 bool IsVirtIO(VendorID vendorId); 144 bool IsVivante(VendorID vendorId); 145 bool IsAppleGPU(VendorID vendorId); 146 bool IsMicrosoft(VendorID vendorId); 147 148 // Returns a readable vendor name given the VendorID 149 std::string VendorName(VendorID vendor); 150 151 // Use a heuristic to attempt to find the GPU used for 3D graphics. Sets activeGPUIndex, 152 // isOptimus, and isAMDSwitchable. 153 // Always assumes the non-Intel GPU is active on dual-GPU machines. 154 void GetDualGPUInfo(SystemInfo *info); 155 156 // Dumps the system info to stdout. 157 void PrintSystemInfo(const SystemInfo &info); 158 159 VersionInfo ParseNvidiaDriverVersion(uint32_t version); 160 VersionInfo ParseMesaDriverVersion(uint32_t version); 161 162 uint64_t GetSystemDeviceIdFromParts(uint32_t highPart, uint32_t lowPart); 163 uint32_t GetSystemDeviceIdHighPart(uint64_t systemDeviceId); 164 uint32_t GetSystemDeviceIdLowPart(uint64_t systemDeviceId); 165 166 // Returns lower-case of ANGLE_PREFERRED_DEVICE environment variable contents. 167 std::string GetPreferredDeviceString(); 168 169 } // namespace angle 170 171 #endif // GPU_INFO_UTIL_SYSTEM_INFO_H_ 172