• 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 <string>
14 #include <vector>
15 
16 namespace angle
17 {
18 
19 using VendorID = uint32_t;
20 using DeviceID = uint32_t;
21 
22 struct VersionInfo
23 {
24     uint32_t major    = 0;
25     uint32_t minor    = 0;
26     uint32_t subMinor = 0;
27     uint32_t patch    = 0;
28 };
29 
30 struct GPUDeviceInfo
31 {
32     GPUDeviceInfo();
33     ~GPUDeviceInfo();
34 
35     GPUDeviceInfo(const GPUDeviceInfo &other);
36 
37     VendorID vendorId = 0;
38     DeviceID deviceId = 0;
39 
40     std::string driverVendor;
41     std::string driverVersion;
42     std::string driverDate;
43 
44     // Only available on Android
45     VersionInfo detailedDriverVersion;
46 };
47 
48 struct SystemInfo
49 {
50     SystemInfo();
51     ~SystemInfo();
52 
53     SystemInfo(const SystemInfo &other);
54 
55     bool hasNVIDIAGPU() const;
56     bool hasIntelGPU() const;
57     bool hasAMDGPU() const;
58 
59     std::vector<GPUDeviceInfo> gpus;
60 
61     // Index of the GPU expected to be used for 3D graphics. Based on a best-guess heuristic on
62     // some platforms. On Windows, this is accurate. Note `gpus` must be checked for empty before
63     // indexing.
64     int activeGPUIndex = 0;
65 
66     bool isOptimus       = false;
67     bool isAMDSwitchable = false;
68     // Only true on dual-GPU Mac laptops.
69     bool isMacSwitchable = false;
70 
71     // Only available on Android
72     std::string machineManufacturer;
73 
74     // Only available on macOS and Android
75     std::string machineModelName;
76 
77     // Only available on macOS
78     std::string machineModelVersion;
79 };
80 
81 // Gathers information about the system without starting a GPU driver and returns them in `info`.
82 // Returns true if all info was gathered, false otherwise. Even when false is returned, `info` will
83 // be filled with partial information.
84 bool GetSystemInfo(SystemInfo *info);
85 
86 // Known PCI vendor IDs
87 constexpr VendorID kVendorID_AMD      = 0x1002;
88 constexpr VendorID kVendorID_ARM      = 0x13B5;
89 constexpr VendorID kVendorID_Broadcom = 0x14E4;
90 constexpr VendorID kVendorID_GOOGLE   = 0x1AE0;
91 constexpr VendorID kVendorID_ImgTec   = 0x1010;
92 constexpr VendorID kVendorID_Intel    = 0x8086;
93 constexpr VendorID kVendorID_NVIDIA   = 0x10DE;
94 constexpr VendorID kVendorID_Qualcomm = 0x5143;
95 constexpr VendorID kVendorID_VMWare   = 0x15ad;
96 
97 // Known non-PCI (i.e. Khronos-registered) vendor IDs
98 constexpr VendorID kVendorID_Vivante     = 0x10001;
99 constexpr VendorID kVendorID_VeriSilicon = 0x10002;
100 constexpr VendorID kVendorID_Kazan       = 0x10003;
101 
102 // Known device IDs
103 constexpr DeviceID kDeviceID_Swiftshader = 0xC0DE;
104 
105 // Predicates on vendor IDs
106 bool IsAMD(VendorID vendorId);
107 bool IsARM(VendorID vendorId);
108 bool IsBroadcom(VendorID vendorId);
109 bool IsImgTec(VendorID vendorId);
110 bool IsIntel(VendorID vendorId);
111 bool IsKazan(VendorID vendorId);
112 bool IsNVIDIA(VendorID vendorId);
113 bool IsQualcomm(VendorID vendorId);
114 bool IsGoogle(VendorID vendorId);
115 bool IsSwiftshader(VendorID vendorId);
116 bool IsVeriSilicon(VendorID vendorId);
117 bool IsVMWare(VendorID vendorId);
118 bool IsVivante(VendorID vendorId);
119 
120 // Use a heuristic to attempt to find the GPU used for 3D graphics. Sets activeGPUIndex,
121 // isOptimus, and isAMDSwitchable.
122 // Always assumes the non-Intel GPU is active on dual-GPU machines.
123 void GetDualGPUInfo(SystemInfo *info);
124 
125 // Dumps the system info to stdout.
126 void PrintSystemInfo(const SystemInfo &info);
127 
128 VersionInfo ParseNvidiaDriverVersion(uint32_t version);
129 }  // namespace angle
130 
131 #endif  // GPU_INFO_UTIL_SYSTEM_INFO_H_
132