• 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 #include <algorithm>
10 
11 #include "libANGLE/renderer/driver_utils.h"
12 
13 #include "common/platform.h"
14 #include "common/system_utils.h"
15 
16 #if defined(ANGLE_PLATFORM_ANDROID)
17 #    include <sys/system_properties.h>
18 #endif
19 
20 #if defined(ANGLE_PLATFORM_LINUX)
21 #    include <sys/utsname.h>
22 #endif
23 
24 #if defined(ANGLE_PLATFORM_WINDOWS)
25 #    include <versionhelpers.h>
26 #endif
27 
28 namespace rx
29 {
30 // Intel
31 // Referenced from https://cgit.freedesktop.org/vaapi/intel-driver/tree/src/i965_pciids.h
32 namespace
33 {
34 // gen6
35 const uint32_t SandyBridge[] = {0x0102, 0x0106, 0x010A, 0x0112, 0x0122, 0x0116, 0x0126};
36 
37 // gen7
38 const uint32_t IvyBridge[] = {0x0152, 0x0156, 0x015A, 0x0162, 0x0166, 0x016A};
39 
40 const uint32_t Haswell[] = {
41     0x0402, 0x0406, 0x040A, 0x040B, 0x040E, 0x0C02, 0x0C06, 0x0C0A, 0x0C0B, 0x0C0E,
42     0x0A02, 0x0A06, 0x0A0A, 0x0A0B, 0x0A0E, 0x0D02, 0x0D06, 0x0D0A, 0x0D0B, 0x0D0E,  // hsw_gt1
43     0x0412, 0x0416, 0x041A, 0x041B, 0x041E, 0x0C12, 0x0C16, 0x0C1A, 0x0C1B, 0x0C1E,
44     0x0A12, 0x0A16, 0x0A1A, 0x0A1B, 0x0A1E, 0x0D12, 0x0D16, 0x0D1A, 0x0D1B, 0x0D1E,  // hsw_gt2
45     0x0422, 0x0426, 0x042A, 0x042B, 0x042E, 0x0C22, 0x0C26, 0x0C2A, 0x0C2B, 0x0C2E,
46     0x0A22, 0x0A26, 0x0A2A, 0x0A2B, 0x0A2E, 0x0D22, 0x0D26, 0x0D2A, 0x0D2B, 0x0D2E  // hsw_gt3
47 };
48 
49 // gen8
50 const uint32_t Broadwell[] = {0x1602, 0x1606, 0x160A, 0x160B, 0x160D, 0x160E,
51                               0x1612, 0x1616, 0x161A, 0x161B, 0x161D, 0x161E,
52                               0x1622, 0x1626, 0x162A, 0x162B, 0x162D, 0x162E};
53 
54 const uint32_t CherryView[] = {0x22B0, 0x22B1, 0x22B2, 0x22B3};
55 
56 // gen9
57 const uint32_t Skylake[] = {0x1902, 0x1906, 0x190A, 0x190B, 0x190E, 0x1912, 0x1913, 0x1915, 0x1916,
58                             0x1917, 0x191A, 0x191B, 0x191D, 0x191E, 0x1921, 0x1923, 0x1926, 0x1927,
59                             0x192A, 0x192B, 0x192D, 0x1932, 0x193A, 0x193B, 0x193D};
60 
61 const uint32_t Broxton[] = {0x0A84, 0x1A84, 0x1A85, 0x5A84, 0x5A85};
62 
63 // gen9p5
64 const uint32_t Kabylake[] = {0x5916, 0x5913, 0x5906, 0x5926, 0x5921, 0x5915, 0x590E,
65                              0x591E, 0x5912, 0x5917, 0x5902, 0x591B, 0x593B, 0x590B,
66                              0x591A, 0x590A, 0x591D, 0x5908, 0x5923, 0x5927};
67 
68 }  // anonymous namespace
69 
IntelDriverVersion(uint32_t buildNumber)70 IntelDriverVersion::IntelDriverVersion(uint32_t buildNumber) : mBuildNumber(buildNumber) {}
71 
operator ==(const IntelDriverVersion & version)72 bool IntelDriverVersion::operator==(const IntelDriverVersion &version)
73 {
74     return mBuildNumber == version.mBuildNumber;
75 }
76 
operator !=(const IntelDriverVersion & version)77 bool IntelDriverVersion::operator!=(const IntelDriverVersion &version)
78 {
79     return !(*this == version);
80 }
81 
operator <(const IntelDriverVersion & version)82 bool IntelDriverVersion::operator<(const IntelDriverVersion &version)
83 {
84     return mBuildNumber < version.mBuildNumber;
85 }
86 
operator >=(const IntelDriverVersion & version)87 bool IntelDriverVersion::operator>=(const IntelDriverVersion &version)
88 {
89     return !(*this < version);
90 }
91 
IsSandyBridge(uint32_t DeviceId)92 bool IsSandyBridge(uint32_t DeviceId)
93 {
94     return std::find(std::begin(SandyBridge), std::end(SandyBridge), DeviceId) !=
95            std::end(SandyBridge);
96 }
97 
IsIvyBridge(uint32_t DeviceId)98 bool IsIvyBridge(uint32_t DeviceId)
99 {
100     return std::find(std::begin(IvyBridge), std::end(IvyBridge), DeviceId) != std::end(IvyBridge);
101 }
102 
IsHaswell(uint32_t DeviceId)103 bool IsHaswell(uint32_t DeviceId)
104 {
105     return std::find(std::begin(Haswell), std::end(Haswell), DeviceId) != std::end(Haswell);
106 }
107 
IsBroadwell(uint32_t DeviceId)108 bool IsBroadwell(uint32_t DeviceId)
109 {
110     return std::find(std::begin(Broadwell), std::end(Broadwell), DeviceId) != std::end(Broadwell);
111 }
112 
IsCherryView(uint32_t DeviceId)113 bool IsCherryView(uint32_t DeviceId)
114 {
115     return std::find(std::begin(CherryView), std::end(CherryView), DeviceId) !=
116            std::end(CherryView);
117 }
118 
IsSkylake(uint32_t DeviceId)119 bool IsSkylake(uint32_t DeviceId)
120 {
121     return std::find(std::begin(Skylake), std::end(Skylake), DeviceId) != std::end(Skylake);
122 }
123 
IsBroxton(uint32_t DeviceId)124 bool IsBroxton(uint32_t DeviceId)
125 {
126     return std::find(std::begin(Broxton), std::end(Broxton), DeviceId) != std::end(Broxton);
127 }
128 
IsKabylake(uint32_t DeviceId)129 bool IsKabylake(uint32_t DeviceId)
130 {
131     return std::find(std::begin(Kabylake), std::end(Kabylake), DeviceId) != std::end(Kabylake);
132 }
133 
Is9thGenIntel(uint32_t DeviceId)134 bool Is9thGenIntel(uint32_t DeviceId)
135 {
136     return IsSkylake(DeviceId) || IsBroxton(DeviceId) || IsKabylake(DeviceId);
137 }
138 
GetVendorString(uint32_t vendorId)139 const char *GetVendorString(uint32_t vendorId)
140 {
141     switch (vendorId)
142     {
143         case VENDOR_ID_AMD:
144             return "AMD";
145         case VENDOR_ID_ARM:
146             return "ARM";
147         case VENDOR_ID_APPLE:
148             return "Apple";
149         case VENDOR_ID_BROADCOM:
150             return "Broadcom";
151         case VENDOR_ID_GOOGLE:
152             return "Google";
153         case VENDOR_ID_INTEL:
154             return "Intel";
155         case VENDOR_ID_MESA:
156             return "Mesa";
157         case VENDOR_ID_MICROSOFT:
158             return "Microsoft";
159         case VENDOR_ID_NVIDIA:
160             return "NVIDIA";
161         case VENDOR_ID_POWERVR:
162             return "Imagination Technologies";
163         case VENDOR_ID_QUALCOMM:
164             return "Qualcomm";
165         case VENDOR_ID_SAMSUNG:
166             return "Samsung Electronics Co., Ltd.";
167         case 0xba5eba11:  // Mock vendor ID used for tests.
168             return "Test";
169         case 0:
170             return "NULL";
171         default:
172             // TODO(jmadill): More vendor IDs.
173             UNIMPLEMENTED();
174             return "Unknown";
175     }
176 }
177 
GetAndroidSDKVersion()178 int GetAndroidSDKVersion()
179 {
180 #if defined(ANGLE_PLATFORM_ANDROID)
181     char apiVersion[PROP_VALUE_MAX];
182     int length = __system_property_get("ro.build.version.sdk", apiVersion);
183     if (length == 0)
184     {
185         return 0;
186     }
187     return atoi(apiVersion);
188 #else
189     return 0;
190 #endif
191 }
192 
OSVersion()193 OSVersion::OSVersion() {}
OSVersion(int major,int minor,int patch)194 OSVersion::OSVersion(int major, int minor, int patch)
195     : majorVersion(major), minorVersion(minor), patchVersion(patch)
196 {}
197 
operator ==(const OSVersion & a,const OSVersion & b)198 bool operator==(const OSVersion &a, const OSVersion &b)
199 {
200     return std::tie(a.majorVersion, a.minorVersion, a.patchVersion) ==
201            std::tie(b.majorVersion, b.minorVersion, b.patchVersion);
202 }
operator !=(const OSVersion & a,const OSVersion & b)203 bool operator!=(const OSVersion &a, const OSVersion &b)
204 {
205     return std::tie(a.majorVersion, a.minorVersion, a.patchVersion) !=
206            std::tie(b.majorVersion, b.minorVersion, b.patchVersion);
207 }
operator <(const OSVersion & a,const OSVersion & b)208 bool operator<(const OSVersion &a, const OSVersion &b)
209 {
210     return std::tie(a.majorVersion, a.minorVersion, a.patchVersion) <
211            std::tie(b.majorVersion, b.minorVersion, b.patchVersion);
212 }
operator >=(const OSVersion & a,const OSVersion & b)213 bool operator>=(const OSVersion &a, const OSVersion &b)
214 {
215     return std::tie(a.majorVersion, a.minorVersion, a.patchVersion) >=
216            std::tie(b.majorVersion, b.minorVersion, b.patchVersion);
217 }
218 
219 #if !defined(ANGLE_PLATFORM_MACOS)
GetMacOSVersion()220 OSVersion GetMacOSVersion()
221 {
222     // Return a default version
223     return OSVersion(0, 0, 0);
224 }
225 #endif
226 
227 #if !defined(ANGLE_PLATFORM_IOS)
GetiOSVersion()228 OSVersion GetiOSVersion()
229 {
230     // Return a default version
231     return OSVersion(0, 0, 0);
232 }
233 #endif
234 
235 #if defined(ANGLE_PLATFORM_LINUX)
ParseLinuxOSVersion(const char * version,int * major,int * minor,int * patch)236 bool ParseLinuxOSVersion(const char *version, int *major, int *minor, int *patch)
237 {
238     errno = 0;  // reset global error flag.
239     char *next;
240     *major = static_cast<int>(strtol(version, &next, 10));
241     if (next == nullptr || *next != '.' || errno != 0)
242     {
243         return false;
244     }
245 
246     *minor = static_cast<int>(strtol(next + 1, &next, 10));
247     if (next == nullptr || *next != '.' || errno != 0)
248     {
249         return false;
250     }
251 
252     *patch = static_cast<int>(strtol(next + 1, &next, 10));
253     if (errno != 0)
254     {
255         return false;
256     }
257 
258     return true;
259 }
260 #endif
261 
GetLinuxOSVersion()262 OSVersion GetLinuxOSVersion()
263 {
264 #if defined(ANGLE_PLATFORM_LINUX)
265     struct utsname uname_info;
266     if (uname(&uname_info) != 0)
267     {
268         return OSVersion(0, 0, 0);
269     }
270 
271     int majorVersion = 0, minorVersion = 0, patchVersion = 0;
272     if (ParseLinuxOSVersion(uname_info.release, &majorVersion, &minorVersion, &patchVersion))
273     {
274         return OSVersion(majorVersion, minorVersion, patchVersion);
275     }
276 #endif
277 
278     return OSVersion(0, 0, 0);
279 }
280 
281 // There are multiple environment variables that may or may not be set during Wayland
282 // sessions, including WAYLAND_DISPLAY, XDG_SESSION_TYPE, and DESKTOP_SESSION
IsWayland()283 bool IsWayland()
284 {
285     static bool checked   = false;
286     static bool isWayland = false;
287     if (!checked)
288     {
289         if (IsLinux())
290         {
291             if (!angle::GetEnvironmentVar("WAYLAND_DISPLAY").empty())
292             {
293                 isWayland = true;
294             }
295             else if (angle::GetEnvironmentVar("XDG_SESSION_TYPE") == "wayland")
296             {
297                 isWayland = true;
298             }
299             else if (angle::GetEnvironmentVar("DESKTOP_SESSION").find("wayland") !=
300                      std::string::npos)
301             {
302                 isWayland = true;
303             }
304         }
305         checked = true;
306     }
307     return isWayland;
308 }
309 
IsWin10OrGreater()310 bool IsWin10OrGreater()
311 {
312 #if defined(ANGLE_ENABLE_WINDOWS_UWP)
313     return true;
314 #elif defined(ANGLE_PLATFORM_WINDOWS)
315     return IsWindows10OrGreater();
316 #else
317     return false;
318 #endif
319 }
320 
321 }  // namespace rx
322