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_ARM = 0x13B5,
23 // Broadcom devices won't use PCI, but this is their Vulkan vendor id.
24 VENDOR_ID_BROADCOM = 0x14E4,
25 VENDOR_ID_GOOGLE = 0x1AE0,
26 VENDOR_ID_INTEL = 0x8086,
27 VENDOR_ID_NVIDIA = 0x10DE,
28 // This is Qualcomm PCI Vendor ID.
29 // Android doesn't have a PCI bus, but all we need is a unique id.
30 VENDOR_ID_QUALCOMM = 0x5143,
31 };
32
33 enum AndroidDeviceID : uint32_t
34 {
35 ANDROID_DEVICE_ID_UNKNOWN = 0x0,
36 ANDROID_DEVICE_ID_NEXUS5X = 0x4010800,
37 ANDROID_DEVICE_ID_PIXEL1XL = 0x5040001,
38 ANDROID_DEVICE_ID_PIXEL2 = 0x5030004,
39 ANDROID_DEVICE_ID_SWIFTSHADER = 0xC0DE,
40 };
41
IsAMD(uint32_t vendorId)42 inline bool IsAMD(uint32_t vendorId)
43 {
44 return vendorId == VENDOR_ID_AMD;
45 }
46
IsARM(uint32_t vendorId)47 inline bool IsARM(uint32_t vendorId)
48 {
49 return vendorId == VENDOR_ID_ARM;
50 }
51
IsBroadcom(uint32_t vendorId)52 inline bool IsBroadcom(uint32_t vendorId)
53 {
54 return vendorId == VENDOR_ID_BROADCOM;
55 }
56
IsIntel(uint32_t vendorId)57 inline bool IsIntel(uint32_t vendorId)
58 {
59 return vendorId == VENDOR_ID_INTEL;
60 }
61
IsGoogle(uint32_t vendorId)62 inline bool IsGoogle(uint32_t vendorId)
63 {
64 return vendorId == VENDOR_ID_GOOGLE;
65 }
66
IsNvidia(uint32_t vendorId)67 inline bool IsNvidia(uint32_t vendorId)
68 {
69 return vendorId == VENDOR_ID_NVIDIA;
70 }
71
IsQualcomm(uint32_t vendorId)72 inline bool IsQualcomm(uint32_t vendorId)
73 {
74 return vendorId == VENDOR_ID_QUALCOMM;
75 }
76
IsNexus5X(uint32_t vendorId,uint32_t deviceId)77 inline bool IsNexus5X(uint32_t vendorId, uint32_t deviceId)
78 {
79 return IsQualcomm(vendorId) && deviceId == ANDROID_DEVICE_ID_NEXUS5X;
80 }
81
IsPixel1XL(uint32_t vendorId,uint32_t deviceId)82 inline bool IsPixel1XL(uint32_t vendorId, uint32_t deviceId)
83 {
84 return IsQualcomm(vendorId) && deviceId == ANDROID_DEVICE_ID_PIXEL1XL;
85 }
86
IsPixel2(uint32_t vendorId,uint32_t deviceId)87 inline bool IsPixel2(uint32_t vendorId, uint32_t deviceId)
88 {
89 return IsQualcomm(vendorId) && deviceId == ANDROID_DEVICE_ID_PIXEL2;
90 }
91
IsSwiftshader(uint32_t vendorId,uint32_t deviceId)92 inline bool IsSwiftshader(uint32_t vendorId, uint32_t deviceId)
93 {
94 return IsGoogle(vendorId) && deviceId == ANDROID_DEVICE_ID_SWIFTSHADER;
95 }
96
97 const char *GetVendorString(uint32_t vendorId);
98
99 // Intel
100 class IntelDriverVersion
101 {
102 public:
103 // Currently, We only provide the constructor with one parameter. It mainly used in Intel
104 // version number on windows. If you want to use this class on other platforms, it's easy to
105 // be extended.
106 IntelDriverVersion(uint16_t lastPart);
107 bool operator==(const IntelDriverVersion &);
108 bool operator!=(const IntelDriverVersion &);
109 bool operator<(const IntelDriverVersion &);
110 bool operator>=(const IntelDriverVersion &);
111
112 private:
113 uint16_t mVersionPart;
114 };
115
116 bool IsIvyBridge(uint32_t DeviceId);
117 bool IsHaswell(uint32_t DeviceId);
118 bool IsBroadwell(uint32_t DeviceId);
119 bool IsCherryView(uint32_t DeviceId);
120 bool IsSkylake(uint32_t DeviceId);
121 bool IsBroxton(uint32_t DeviceId);
122 bool IsKabylake(uint32_t DeviceId);
123
124 // Platform helpers
IsWindows()125 inline bool IsWindows()
126 {
127 #if defined(ANGLE_PLATFORM_WINDOWS)
128 return true;
129 #else
130 return false;
131 #endif
132 }
133
IsLinux()134 inline bool IsLinux()
135 {
136 #if defined(ANGLE_PLATFORM_LINUX)
137 return true;
138 #else
139 return false;
140 #endif
141 }
142
IsApple()143 inline bool IsApple()
144 {
145 #if defined(ANGLE_PLATFORM_APPLE)
146 return true;
147 #else
148 return false;
149 #endif
150 }
151
IsFuchsia()152 inline bool IsFuchsia()
153 {
154 #if defined(ANGLE_PLATFORM_FUCHSIA)
155 return true;
156 #else
157 return false;
158 #endif
159 }
160
161 struct OSVersion
162 {
163 OSVersion();
164 OSVersion(int major, int minor, int patch);
165
166 int majorVersion = 0;
167 int minorVersion = 0;
168 int patchVersion = 0;
169 };
170 bool operator==(const OSVersion &a, const OSVersion &b);
171 bool operator!=(const OSVersion &a, const OSVersion &b);
172 bool operator<(const OSVersion &a, const OSVersion &b);
173 bool operator>=(const OSVersion &a, const OSVersion &b);
174
175 OSVersion GetMacOSVersion();
176
177 OSVersion GetLinuxOSVersion();
178
IsAndroid()179 inline bool IsAndroid()
180 {
181 #if defined(ANGLE_PLATFORM_ANDROID)
182 return true;
183 #else
184 return false;
185 #endif
186 }
187
188 int GetAndroidSDKVersion();
189
190 } // namespace rx
191 #endif // LIBANGLE_RENDERER_DRIVER_UTILS_H_
192