• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2016 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 // driver_utils.h : provides more information about current driver.
8 
9 #ifndef LIBANGLE_RENDERER_DRIVER_UTILS_H_
10 #define LIBANGLE_RENDERER_DRIVER_UTILS_H_
11 
12 #include "common/platform.h"
13 #include "libANGLE/angletypes.h"
14 
15 namespace rx
16 {
17 
18 enum VendorID : uint32_t
19 {
20     VENDOR_ID_UNKNOWN = 0x0,
21     VENDOR_ID_AMD     = 0x1002,
22     VENDOR_ID_APPLE   = 0x106B,
23     VENDOR_ID_ARM     = 0x13B5,
24     // Broadcom devices won't use PCI, but this is their Vulkan vendor id.
25     VENDOR_ID_BROADCOM = 0x14E4,
26     VENDOR_ID_GOOGLE   = 0x1AE0,
27     VENDOR_ID_INTEL    = 0x8086,
28     VENDOR_ID_MESA     = 0x10005,
29     VENDOR_ID_NVIDIA   = 0x10DE,
30     VENDOR_ID_POWERVR  = 0x1010,
31     // This is Qualcomm PCI Vendor ID.
32     // Android doesn't have a PCI bus, but all we need is a unique id.
33     VENDOR_ID_QUALCOMM = 0x5143,
34     VENDOR_ID_SAMSUNG  = 0x144D,
35     VENDOR_ID_VMWARE   = 0x15AD,
36     VENDOR_ID_VIVANTE  = 0x9999,
37 };
38 
39 enum AndroidDeviceID : uint32_t
40 {
41     ANDROID_DEVICE_ID_UNKNOWN     = 0x0,
42     ANDROID_DEVICE_ID_NEXUS5X     = 0x4010800,
43     ANDROID_DEVICE_ID_PIXEL2      = 0x5040001,
44     ANDROID_DEVICE_ID_PIXEL1XL    = 0x5030004,
45     ANDROID_DEVICE_ID_PIXEL4      = 0x6040001,
46     ANDROID_DEVICE_ID_SWIFTSHADER = 0xC0DE,
47 };
48 
IsAMD(uint32_t vendorId)49 inline bool IsAMD(uint32_t vendorId)
50 {
51     return vendorId == VENDOR_ID_AMD;
52 }
53 
IsApple(uint32_t vendorId)54 inline bool IsApple(uint32_t vendorId)
55 {
56     return vendorId == VENDOR_ID_APPLE;
57 }
58 
IsARM(uint32_t vendorId)59 inline bool IsARM(uint32_t vendorId)
60 {
61     return vendorId == VENDOR_ID_ARM;
62 }
63 
IsBroadcom(uint32_t vendorId)64 inline bool IsBroadcom(uint32_t vendorId)
65 {
66     return vendorId == VENDOR_ID_BROADCOM;
67 }
68 
IsIntel(uint32_t vendorId)69 inline bool IsIntel(uint32_t vendorId)
70 {
71     return vendorId == VENDOR_ID_INTEL;
72 }
73 
IsGoogle(uint32_t vendorId)74 inline bool IsGoogle(uint32_t vendorId)
75 {
76     return vendorId == VENDOR_ID_GOOGLE;
77 }
78 
IsNvidia(uint32_t vendorId)79 inline bool IsNvidia(uint32_t vendorId)
80 {
81     return vendorId == VENDOR_ID_NVIDIA;
82 }
83 
IsPowerVR(uint32_t vendorId)84 inline bool IsPowerVR(uint32_t vendorId)
85 {
86     return vendorId == VENDOR_ID_POWERVR;
87 }
88 
IsQualcomm(uint32_t vendorId)89 inline bool IsQualcomm(uint32_t vendorId)
90 {
91     return vendorId == VENDOR_ID_QUALCOMM;
92 }
93 
IsVMWare(uint32_t vendorId)94 inline bool IsVMWare(uint32_t vendorId)
95 {
96     return vendorId == VENDOR_ID_VMWARE;
97 }
98 
IsSamsung(uint32_t vendorId)99 inline bool IsSamsung(uint32_t vendorId)
100 {
101     return vendorId == VENDOR_ID_SAMSUNG;
102 }
103 
IsVivante(uint32_t vendorId)104 inline bool IsVivante(uint32_t vendorId)
105 {
106     return vendorId == VENDOR_ID_VIVANTE;
107 }
108 
IsNexus5X(uint32_t vendorId,uint32_t deviceId)109 inline bool IsNexus5X(uint32_t vendorId, uint32_t deviceId)
110 {
111     return IsQualcomm(vendorId) && deviceId == ANDROID_DEVICE_ID_NEXUS5X;
112 }
113 
IsPixel1XL(uint32_t vendorId,uint32_t deviceId)114 inline bool IsPixel1XL(uint32_t vendorId, uint32_t deviceId)
115 {
116     return IsQualcomm(vendorId) && deviceId == ANDROID_DEVICE_ID_PIXEL1XL;
117 }
118 
IsPixel2(uint32_t vendorId,uint32_t deviceId)119 inline bool IsPixel2(uint32_t vendorId, uint32_t deviceId)
120 {
121     return IsQualcomm(vendorId) && deviceId == ANDROID_DEVICE_ID_PIXEL2;
122 }
123 
IsPixel4(uint32_t vendorId,uint32_t deviceId)124 inline bool IsPixel4(uint32_t vendorId, uint32_t deviceId)
125 {
126     return IsQualcomm(vendorId) && deviceId == ANDROID_DEVICE_ID_PIXEL4;
127 }
128 
IsSwiftshader(uint32_t vendorId,uint32_t deviceId)129 inline bool IsSwiftshader(uint32_t vendorId, uint32_t deviceId)
130 {
131     return IsGoogle(vendorId) && deviceId == ANDROID_DEVICE_ID_SWIFTSHADER;
132 }
133 
134 const char *GetVendorString(uint32_t vendorId);
135 
136 // For Linux, Intel graphics driver version is the Mesa version. The version number has three
137 // fields: major revision, minor revision and release number.
138 // For Windows, The version number includes 3rd and 4th fields. Please refer the details at
139 // http://www.intel.com/content/www/us/en/support/graphics-drivers/000005654.html.
140 // Current implementation only supports Windows.
141 class IntelDriverVersion
142 {
143   public:
144     IntelDriverVersion(uint32_t buildNumber);
145     bool operator==(const IntelDriverVersion &);
146     bool operator!=(const IntelDriverVersion &);
147     bool operator<(const IntelDriverVersion &);
148     bool operator>=(const IntelDriverVersion &);
149 
150   private:
151     uint32_t mBuildNumber;
152 };
153 
154 bool IsSandyBridge(uint32_t DeviceId);
155 bool IsIvyBridge(uint32_t DeviceId);
156 bool IsHaswell(uint32_t DeviceId);
157 bool IsBroadwell(uint32_t DeviceId);
158 bool IsCherryView(uint32_t DeviceId);
159 bool IsSkylake(uint32_t DeviceId);
160 bool IsBroxton(uint32_t DeviceId);
161 bool IsKabylake(uint32_t DeviceId);
162 bool Is9thGenIntel(uint32_t DeviceId);
163 
164 // Platform helpers
IsWindows()165 inline bool IsWindows()
166 {
167 #if defined(ANGLE_PLATFORM_WINDOWS)
168     return true;
169 #else
170     return false;
171 #endif
172 }
173 
IsLinux()174 inline bool IsLinux()
175 {
176 #if defined(ANGLE_PLATFORM_LINUX)
177     return true;
178 #else
179     return false;
180 #endif
181 }
182 
IsApple()183 inline bool IsApple()
184 {
185 #if defined(ANGLE_PLATFORM_APPLE)
186     return true;
187 #else
188     return false;
189 #endif
190 }
191 
IsMac()192 inline bool IsMac()
193 {
194 #if defined(ANGLE_PLATFORM_APPLE) && defined(ANGLE_PLATFORM_MACOS)
195     return true;
196 #else
197     return false;
198 #endif
199 }
200 
IsFuchsia()201 inline bool IsFuchsia()
202 {
203 #if defined(ANGLE_PLATFORM_FUCHSIA)
204     return true;
205 #else
206     return false;
207 #endif
208 }
209 
IsIOS()210 inline bool IsIOS()
211 {
212 #if defined(ANGLE_PLATFORM_IOS)
213     return true;
214 #else
215     return false;
216 #endif
217 }
218 
219 bool IsWayland();
220 bool IsWin10OrGreater();
221 
222 struct OSVersion
223 {
224     OSVersion();
225     OSVersion(int major, int minor, int patch);
226 
227     int majorVersion = 0;
228     int minorVersion = 0;
229     int patchVersion = 0;
230 };
231 bool operator==(const OSVersion &a, const OSVersion &b);
232 bool operator!=(const OSVersion &a, const OSVersion &b);
233 bool operator<(const OSVersion &a, const OSVersion &b);
234 bool operator>=(const OSVersion &a, const OSVersion &b);
235 
236 OSVersion GetMacOSVersion();
237 
238 OSVersion GetiOSVersion();
239 
240 OSVersion GetLinuxOSVersion();
241 
IsAndroid()242 inline bool IsAndroid()
243 {
244 #if defined(ANGLE_PLATFORM_ANDROID)
245     return true;
246 #else
247     return false;
248 #endif
249 }
250 
251 int GetAndroidSDKVersion();
252 
253 }  // namespace rx
254 #endif  // LIBANGLE_RENDERER_DRIVER_UTILS_H_
255