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