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_helpers.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_MICROSOFT = 0x1414,
30 VENDOR_ID_NVIDIA = 0x10DE,
31 VENDOR_ID_POWERVR = 0x1010,
32 // This is Qualcomm PCI Vendor ID.
33 // Android doesn't have a PCI bus, but all we need is a unique id.
34 VENDOR_ID_QUALCOMM = 0x5143,
35 VENDOR_ID_SAMSUNG = 0x144D,
36 VENDOR_ID_VIVANTE = 0x9999,
37 VENDOR_ID_VMWARE = 0x15AD,
38 VENDOR_ID_VIRTIO = 0x1AF4,
39 };
40
41 enum AndroidDeviceID : uint32_t
42 {
43 ANDROID_DEVICE_ID_UNKNOWN = 0x0,
44 ANDROID_DEVICE_ID_NEXUS5X = 0x4010800,
45 ANDROID_DEVICE_ID_PIXEL2 = 0x5040001,
46 ANDROID_DEVICE_ID_PIXEL1XL = 0x5030004,
47 ANDROID_DEVICE_ID_PIXEL4 = 0x6040001,
48 ANDROID_DEVICE_ID_GALAXYA23 = 0x6010901,
49 ANDROID_DEVICE_ID_GALAXYS23 = 0x43050A01,
50 ANDROID_DEVICE_ID_SWIFTSHADER = 0xC0DE,
51 };
52
IsAMD(uint32_t vendorId)53 inline bool IsAMD(uint32_t vendorId)
54 {
55 return vendorId == VENDOR_ID_AMD;
56 }
57
IsAppleGPU(uint32_t vendorId)58 inline bool IsAppleGPU(uint32_t vendorId)
59 {
60 return vendorId == VENDOR_ID_APPLE;
61 }
62
IsARM(uint32_t vendorId)63 inline bool IsARM(uint32_t vendorId)
64 {
65 return vendorId == VENDOR_ID_ARM;
66 }
67
IsBroadcom(uint32_t vendorId)68 inline bool IsBroadcom(uint32_t vendorId)
69 {
70 return vendorId == VENDOR_ID_BROADCOM;
71 }
72
IsIntel(uint32_t vendorId)73 inline bool IsIntel(uint32_t vendorId)
74 {
75 return vendorId == VENDOR_ID_INTEL;
76 }
77
IsGoogle(uint32_t vendorId)78 inline bool IsGoogle(uint32_t vendorId)
79 {
80 return vendorId == VENDOR_ID_GOOGLE;
81 }
82
IsMicrosoft(uint32_t vendorId)83 inline bool IsMicrosoft(uint32_t vendorId)
84 {
85 return vendorId == VENDOR_ID_MICROSOFT;
86 }
87
IsNvidia(uint32_t vendorId)88 inline bool IsNvidia(uint32_t vendorId)
89 {
90 return vendorId == VENDOR_ID_NVIDIA;
91 }
92
IsPowerVR(uint32_t vendorId)93 inline bool IsPowerVR(uint32_t vendorId)
94 {
95 return vendorId == VENDOR_ID_POWERVR;
96 }
97
IsQualcomm(uint32_t vendorId)98 inline bool IsQualcomm(uint32_t vendorId)
99 {
100 return vendorId == VENDOR_ID_QUALCOMM;
101 }
102
IsSamsung(uint32_t vendorId)103 inline bool IsSamsung(uint32_t vendorId)
104 {
105 return vendorId == VENDOR_ID_SAMSUNG;
106 }
107
IsVivante(uint32_t vendorId)108 inline bool IsVivante(uint32_t vendorId)
109 {
110 return vendorId == VENDOR_ID_VIVANTE;
111 }
112
IsVMWare(uint32_t vendorId)113 inline bool IsVMWare(uint32_t vendorId)
114 {
115 return vendorId == VENDOR_ID_VMWARE;
116 }
117
IsVirtIO(uint32_t vendorId)118 inline bool IsVirtIO(uint32_t vendorId)
119 {
120 return vendorId == VENDOR_ID_VIRTIO;
121 }
122
IsNexus5X(uint32_t vendorId,uint32_t deviceId)123 inline bool IsNexus5X(uint32_t vendorId, uint32_t deviceId)
124 {
125 return IsQualcomm(vendorId) && deviceId == ANDROID_DEVICE_ID_NEXUS5X;
126 }
127
IsPixel1XL(uint32_t vendorId,uint32_t deviceId)128 inline bool IsPixel1XL(uint32_t vendorId, uint32_t deviceId)
129 {
130 return IsQualcomm(vendorId) && deviceId == ANDROID_DEVICE_ID_PIXEL1XL;
131 }
132
IsPixel2(uint32_t vendorId,uint32_t deviceId)133 inline bool IsPixel2(uint32_t vendorId, uint32_t deviceId)
134 {
135 return IsQualcomm(vendorId) && deviceId == ANDROID_DEVICE_ID_PIXEL2;
136 }
137
IsPixel4(uint32_t vendorId,uint32_t deviceId)138 inline bool IsPixel4(uint32_t vendorId, uint32_t deviceId)
139 {
140 return IsQualcomm(vendorId) && deviceId == ANDROID_DEVICE_ID_PIXEL4;
141 }
142
IsGalaxyA23(uint32_t vendorId,uint32_t deviceId)143 inline bool IsGalaxyA23(uint32_t vendorId, uint32_t deviceId)
144 {
145 return IsQualcomm(vendorId) && deviceId == ANDROID_DEVICE_ID_GALAXYA23;
146 }
147
IsGalaxyS23(uint32_t vendorId,uint32_t deviceId)148 inline bool IsGalaxyS23(uint32_t vendorId, uint32_t deviceId)
149 {
150 return IsQualcomm(vendorId) && deviceId == ANDROID_DEVICE_ID_GALAXYS23;
151 }
152
IsSwiftshader(uint32_t vendorId,uint32_t deviceId)153 inline bool IsSwiftshader(uint32_t vendorId, uint32_t deviceId)
154 {
155 return IsGoogle(vendorId) && deviceId == ANDROID_DEVICE_ID_SWIFTSHADER;
156 }
157
158 const char *GetVendorString(uint32_t vendorId);
159
160 // For Linux, Intel graphics driver version is the Mesa version. The version number has three
161 // fields: major revision, minor revision and release number.
162 // For Windows, The version number includes 3rd and 4th fields. Please refer the details at
163 // http://www.intel.com/content/www/us/en/support/graphics-drivers/000005654.html.
164 // Current implementation only supports Windows.
165 class IntelDriverVersion
166 {
167 public:
168 IntelDriverVersion(uint32_t buildNumber);
169 bool operator==(const IntelDriverVersion &);
170 bool operator!=(const IntelDriverVersion &);
171 bool operator<(const IntelDriverVersion &);
172 bool operator>=(const IntelDriverVersion &);
173
174 private:
175 uint32_t mBuildNumber;
176 };
177
178 bool IsSandyBridge(uint32_t DeviceId);
179 bool IsIvyBridge(uint32_t DeviceId);
180 bool IsHaswell(uint32_t DeviceId);
181 bool IsBroadwell(uint32_t DeviceId);
182 bool IsCherryView(uint32_t DeviceId);
183 bool IsSkylake(uint32_t DeviceId);
184 bool IsBroxton(uint32_t DeviceId);
185 bool IsKabyLake(uint32_t DeviceId);
186 bool IsGeminiLake(uint32_t DeviceId);
187 bool IsCoffeeLake(uint32_t DeviceId);
188 bool Is9thGenIntel(uint32_t DeviceId);
189 bool Is11thGenIntel(uint32_t DeviceId);
190 bool Is12thGenIntel(uint32_t DeviceId);
191
192 using ARMDriverVersion = angle::VersionTriple;
193 ARMDriverVersion ParseARMDriverVersion(uint32_t driverVersion);
194
195 // Platform helpers
196 using angle::IsAndroid;
197 using angle::IsApple;
198 using angle::IsChromeOS;
199 using angle::IsFuchsia;
200 using angle::IsIOS;
201 using angle::IsLinux;
202 using angle::IsMac;
203 using angle::IsWindows;
204 using angle::IsWindows10OrLater;
205 using angle::IsWindows8OrLater;
206 using angle::IsWindowsVistaOrLater;
207
208 bool IsWayland();
209
210 using OSVersion = angle::VersionTriple;
211
212 OSVersion GetMacOSVersion();
213
214 OSVersion GetiOSVersion();
215
216 OSVersion GetLinuxOSVersion();
217
218 int GetAndroidSDKVersion();
219
220 } // namespace rx
221 #endif // LIBANGLE_RENDERER_DRIVER_UTILS_H_
222