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