• 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 namespace rx
25 {
26 // Intel
27 // Referenced from
28 // https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/include/pci_ids/crocus_pci_ids.h
29 // https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/include/pci_ids/iris_pci_ids.h
30 namespace
31 {
32 // gen6
33 const uint16_t SandyBridge[] = {
34     0x0102, 0x0106, 0x010A,         // snb_gt1
35     0x0112, 0x0122, 0x0116, 0x0126  // snb_gt2
36 };
37 
38 // gen7
39 const uint16_t IvyBridge[] = {
40     0x0152, 0x0156, 0x015A,  // ivb_gt1
41     0x0162, 0x0166, 0x016A   // ivb_gt2
42 };
43 
44 // gen 7.5
45 const uint16_t Haswell[] = {
46     0x0402, 0x0406, 0x040A, 0x040B, 0x040E, 0x0C02, 0x0C06, 0x0C0A, 0x0C0B, 0x0C0E,
47     0x0A02, 0x0A06, 0x0A0A, 0x0A0B, 0x0A0E, 0x0D02, 0x0D06, 0x0D0A, 0x0D0B, 0x0D0E,  // hsw_gt1
48     0x0412, 0x0416, 0x041A, 0x041B, 0x041E, 0x0C12, 0x0C16, 0x0C1A, 0x0C1B, 0x0C1E,
49     0x0A12, 0x0A16, 0x0A1A, 0x0A1B, 0x0A1E, 0x0D12, 0x0D16, 0x0D1A, 0x0D1B, 0x0D1E,  // hsw_gt2
50     0x0422, 0x0426, 0x042A, 0x042B, 0x042E, 0x0C22, 0x0C26, 0x0C2A, 0x0C2B, 0x0C2E,
51     0x0A22, 0x0A26, 0x0A2A, 0x0A2B, 0x0A2E, 0x0D22, 0x0D26, 0x0D2A, 0x0D2B, 0x0D2E  // hsw_gt3
52 };
53 
54 // gen8
55 const uint16_t Broadwell[] = {
56     0x1602, 0x1606, 0x160A, 0x160B, 0x160D, 0x160E,  // bdw_gt1
57     0x1612, 0x1616, 0x161A, 0x161B, 0x161D, 0x161E,  // bdw_gt2
58     0x1622, 0x1626, 0x162A, 0x162B, 0x162D, 0x162E   // bdw_gt3
59 };
60 
61 const uint16_t CherryView[] = {0x22B0, 0x22B1, 0x22B2, 0x22B3};
62 
63 // gen9
64 const uint16_t Skylake[] = {
65     0x1902, 0x1906, 0x190A, 0x190B, 0x190E,                                          // skl_gt1
66     0x1912, 0x1913, 0x1915, 0x1916, 0x1917, 0x191A, 0x191B, 0x191D, 0x191E, 0x1921,  // skl_gt2
67     0x1923, 0x1926, 0x1927, 0x192B, 0x192D,                                          // skl_gt3
68     0x192A, 0x1932, 0x193A, 0x193B, 0x193D                                           // skl_gt4
69 };
70 
71 // gen9lp
72 const uint16_t Broxton[] = {0x0A84, 0x1A84, 0x1A85, 0x5A84, 0x5A85};
73 
74 const uint16_t GeminiLake[] = {0x3184, 0x3185};
75 
76 // gen9p5
77 const uint16_t KabyLake[] = {
78     // Kaby Lake
79     0x5902, 0x5906, 0x5908, 0x590A, 0x590B, 0x590E,                  // kbl_gt1
80     0x5913, 0x5915,                                                  // kbl_gt1_5
81     0x5912, 0x5916, 0x5917, 0x591A, 0x591B, 0x591D, 0x591E, 0x5921,  // kbl_gt2
82     0x5923, 0x5926, 0x5927,                                          // kbl_gt3
83     0x593B,                                                          // kbl_gt4
84     // Amber Lake
85     0x591C, 0x87C0  // kbl_gt2
86 };
87 
88 const uint16_t CoffeeLake[] = {
89     // Amber Lake
90     0x87CA,  // cfl_gt2
91 
92     // Coffee Lake
93     0x3E90, 0x3E93, 0x3E99, 0x3E9C,                                  // cfl_gt1
94     0x3E91, 0x3E92, 0x3E94, 0x3E96, 0x3E98, 0x3E9A, 0x3E9B, 0x3EA9,  // cfl_gt2
95     0x3EA5, 0x3EA6, 0x3EA7, 0x3EA8,                                  // cfl_gt3
96 
97     // Whisky Lake
98     0x3EA1, 0x3EA4,  // cfl_gt1
99     0x3EA0, 0x3EA3,  // cfl_gt2
100     0x3EA2,          // cfl_gt3
101 
102     // Comet Lake
103     0x9B21, 0x9BA0, 0x9BA2, 0x9BA4, 0x9BA5, 0x9BA8, 0x9BAA, 0x9BAB, 0x9BAC,          // cfl_gt1
104     0x9B41, 0x9BC0, 0x9BC2, 0x9BC4, 0x9BC5, 0x9BC6, 0x9BC8, 0x9BCA, 0x9BCB, 0x9BCC,  // cfl_gt2
105     0x9BE6, 0x9BF6                                                                   // cfl_gt2
106 };
107 
108 const uint16_t IntelGen11[] = {
109     // Ice Lake
110     0x8A71,                                  // icl_gt0_5
111     0x8A56, 0x8A58, 0x8A5B, 0x8A5D,          // icl_gt1
112     0x8A54, 0x8A57, 0x8A59, 0x8A5A, 0x8A5C,  // icl_gt1_5
113     0x8A50, 0x8A51, 0x8A52, 0x8A53,          // icl_gt2
114 
115     // Elkhart Lake
116     0x4500, 0x4541, 0x4551, 0x4555, 0x4557, 0x4571,
117 
118     // Jasper Lake
119     0x4E51, 0x4E55, 0x4E57, 0x4E61, 0x4E71};
120 
121 const uint16_t IntelGen12[] = {
122     // Rocket Lake
123     0x4C8C,                          // rkl_gt05
124     0x4C8A, 0x4C8B, 0x4C90, 0x4C9A,  // rkl_gt1
125 
126     // Alder Lake
127     0x4683, 0x4693,                                                          // adl_gt05
128     0x4680, 0x4681, 0x4682, 0x4688, 0x4689, 0x4690, 0x4691, 0x4692,          // adl_gt1
129     0x4626, 0x4628, 0x462A, 0x46A0, 0x46A1, 0x46A2, 0x46A3, 0x46A6, 0x46A8,  // adl_gt2
130     0x46AA, 0x46B0, 0x46B1, 0x46B2, 0x46B3, 0x46C0, 0x46C1, 0x46C2, 0x46C3,  // adl_gt2
131     0x46D0, 0x46D1, 0x46D2,                                                  // adl_n
132 
133     // Tiger Lake
134     0x9A60, 0x9A68, 0x9A70,                                          // tgl_gt1
135     0x9A40, 0x9A49, 0x9A59, 0x9A78, 0x9AC0, 0x9AC9, 0x9AD9, 0x9AF8,  // tgl_gt2
136 
137     // Raptop Lake
138     0xA780, 0xA781, 0xA782, 0xA783, 0xA788, 0xA789,  // rpl
139     0xA720, 0xA721, 0xA7A0, 0xA7A1, 0xA7A8, 0xA7A9,  // rpl_p
140 
141     // DG1
142     0x4905, 0x4906, 0x4907, 0x4908, 0x4909};
143 
144 }  // anonymous namespace
145 
IntelDriverVersion(uint32_t buildNumber)146 IntelDriverVersion::IntelDriverVersion(uint32_t buildNumber) : mBuildNumber(buildNumber) {}
147 
operator ==(const IntelDriverVersion & version)148 bool IntelDriverVersion::operator==(const IntelDriverVersion &version)
149 {
150     return mBuildNumber == version.mBuildNumber;
151 }
152 
operator !=(const IntelDriverVersion & version)153 bool IntelDriverVersion::operator!=(const IntelDriverVersion &version)
154 {
155     return !(*this == version);
156 }
157 
operator <(const IntelDriverVersion & version)158 bool IntelDriverVersion::operator<(const IntelDriverVersion &version)
159 {
160     return mBuildNumber < version.mBuildNumber;
161 }
162 
operator >=(const IntelDriverVersion & version)163 bool IntelDriverVersion::operator>=(const IntelDriverVersion &version)
164 {
165     return !(*this < version);
166 }
167 
IsSandyBridge(uint32_t DeviceId)168 bool IsSandyBridge(uint32_t DeviceId)
169 {
170     return std::find(std::begin(SandyBridge), std::end(SandyBridge), DeviceId) !=
171            std::end(SandyBridge);
172 }
173 
IsIvyBridge(uint32_t DeviceId)174 bool IsIvyBridge(uint32_t DeviceId)
175 {
176     return std::find(std::begin(IvyBridge), std::end(IvyBridge), DeviceId) != std::end(IvyBridge);
177 }
178 
IsHaswell(uint32_t DeviceId)179 bool IsHaswell(uint32_t DeviceId)
180 {
181     return std::find(std::begin(Haswell), std::end(Haswell), DeviceId) != std::end(Haswell);
182 }
183 
IsBroadwell(uint32_t DeviceId)184 bool IsBroadwell(uint32_t DeviceId)
185 {
186     return std::find(std::begin(Broadwell), std::end(Broadwell), DeviceId) != std::end(Broadwell);
187 }
188 
IsCherryView(uint32_t DeviceId)189 bool IsCherryView(uint32_t DeviceId)
190 {
191     return std::find(std::begin(CherryView), std::end(CherryView), DeviceId) !=
192            std::end(CherryView);
193 }
194 
IsSkylake(uint32_t DeviceId)195 bool IsSkylake(uint32_t DeviceId)
196 {
197     return std::find(std::begin(Skylake), std::end(Skylake), DeviceId) != std::end(Skylake);
198 }
199 
IsBroxton(uint32_t DeviceId)200 bool IsBroxton(uint32_t DeviceId)
201 {
202     return std::find(std::begin(Broxton), std::end(Broxton), DeviceId) != std::end(Broxton);
203 }
204 
IsKabyLake(uint32_t DeviceId)205 bool IsKabyLake(uint32_t DeviceId)
206 {
207     return std::find(std::begin(KabyLake), std::end(KabyLake), DeviceId) != std::end(KabyLake);
208 }
209 
IsGeminiLake(uint32_t DeviceId)210 bool IsGeminiLake(uint32_t DeviceId)
211 {
212     return std::find(std::begin(GeminiLake), std::end(GeminiLake), DeviceId) !=
213            std::end(GeminiLake);
214 }
215 
IsCoffeeLake(uint32_t DeviceId)216 bool IsCoffeeLake(uint32_t DeviceId)
217 {
218     return std::find(std::begin(CoffeeLake), std::end(CoffeeLake), DeviceId) !=
219            std::end(CoffeeLake);
220 }
221 
Is9thGenIntel(uint32_t DeviceId)222 bool Is9thGenIntel(uint32_t DeviceId)
223 {
224     return IsSkylake(DeviceId) || IsBroxton(DeviceId) || IsKabyLake(DeviceId);
225 }
226 
Is11thGenIntel(uint32_t DeviceId)227 bool Is11thGenIntel(uint32_t DeviceId)
228 {
229     return std::find(std::begin(IntelGen11), std::end(IntelGen11), DeviceId) !=
230            std::end(IntelGen11);
231 }
232 
Is12thGenIntel(uint32_t DeviceId)233 bool Is12thGenIntel(uint32_t DeviceId)
234 {
235     return std::find(std::begin(IntelGen12), std::end(IntelGen12), DeviceId) !=
236            std::end(IntelGen12);
237 }
238 
GetVendorString(uint32_t vendorId)239 const char *GetVendorString(uint32_t vendorId)
240 {
241     switch (vendorId)
242     {
243         case VENDOR_ID_AMD:
244             return "AMD";
245         case VENDOR_ID_ARM:
246             return "ARM";
247         case VENDOR_ID_APPLE:
248             return "Apple";
249         case VENDOR_ID_BROADCOM:
250             return "Broadcom";
251         case VENDOR_ID_GOOGLE:
252             return "Google";
253         case VENDOR_ID_INTEL:
254             return "Intel";
255         case VENDOR_ID_MESA:
256             return "Mesa";
257         case VENDOR_ID_MICROSOFT:
258             return "Microsoft";
259         case VENDOR_ID_NVIDIA:
260             return "NVIDIA";
261         case VENDOR_ID_POWERVR:
262             return "Imagination Technologies";
263         case VENDOR_ID_QUALCOMM:
264             return "Qualcomm";
265         case VENDOR_ID_SAMSUNG:
266             return "Samsung Electronics Co., Ltd.";
267         case VENDOR_ID_VIVANTE:
268             return "Vivante";
269         case VENDOR_ID_VMWARE:
270             return "VMware";
271         case VENDOR_ID_VIRTIO:
272             return "VirtIO";
273         case 0xba5eba11:  // Mock vendor ID used for tests.
274             return "Test";
275         case 0:
276             return "NULL";
277         default:
278             // TODO(jmadill): More vendor IDs.
279             UNIMPLEMENTED();
280             return "Unknown";
281     }
282 }
283 
ParseARMDriverVersion(uint32_t driverVersion)284 ARMDriverVersion ParseARMDriverVersion(uint32_t driverVersion)
285 {
286     // ARM driver versions are built with the following macro:
287     // ((((uint32_t)(major)) << 22) | (((uint32_t)(minor)) << 12) | ((uint32_t)(patch)))
288     constexpr uint32_t kMinorVersionMask = angle::BitMask<uint32_t>(10);
289     constexpr uint32_t kPatchMask        = angle::BitMask<uint32_t>(12);
290     return ARMDriverVersion(driverVersion >> 22, (driverVersion >> 12) & kMinorVersionMask,
291                             driverVersion & kPatchMask);
292 }
293 
GetAndroidSDKVersion()294 int GetAndroidSDKVersion()
295 {
296 #if defined(ANGLE_PLATFORM_ANDROID)
297     char apiVersion[PROP_VALUE_MAX];
298     int length = __system_property_get("ro.build.version.sdk", apiVersion);
299     if (length == 0)
300     {
301         return 0;
302     }
303     return atoi(apiVersion);
304 #else
305     return 0;
306 #endif
307 }
308 #if !defined(ANGLE_PLATFORM_MACOS)
GetMacOSVersion()309 OSVersion GetMacOSVersion()
310 {
311     // Return a default version
312     return OSVersion(0, 0, 0);
313 }
314 #endif
315 
316 #if !ANGLE_PLATFORM_IOS_FAMILY
GetiOSVersion()317 OSVersion GetiOSVersion()
318 {
319     // Return a default version
320     return OSVersion(0, 0, 0);
321 }
322 #endif
323 
324 #if defined(ANGLE_PLATFORM_LINUX)
ParseLinuxOSVersion(const char * version,int * major,int * minor,int * patch)325 bool ParseLinuxOSVersion(const char *version, int *major, int *minor, int *patch)
326 {
327     errno = 0;  // reset global error flag.
328     char *next;
329     *major = static_cast<int>(strtol(version, &next, 10));
330     if (next == nullptr || *next != '.' || errno != 0)
331     {
332         return false;
333     }
334 
335     *minor = static_cast<int>(strtol(next + 1, &next, 10));
336     if (next == nullptr || *next != '.' || errno != 0)
337     {
338         return false;
339     }
340 
341     *patch = static_cast<int>(strtol(next + 1, &next, 10));
342     if (errno != 0)
343     {
344         return false;
345     }
346 
347     return true;
348 }
349 #endif
350 
GetLinuxOSVersion()351 OSVersion GetLinuxOSVersion()
352 {
353 #if defined(ANGLE_PLATFORM_LINUX)
354     struct utsname uname_info;
355     if (uname(&uname_info) != 0)
356     {
357         return OSVersion(0, 0, 0);
358     }
359 
360     int majorVersion = 0, minorVersion = 0, patchVersion = 0;
361     if (ParseLinuxOSVersion(uname_info.release, &majorVersion, &minorVersion, &patchVersion))
362     {
363         return OSVersion(majorVersion, minorVersion, patchVersion);
364     }
365 #endif
366 
367     return OSVersion(0, 0, 0);
368 }
369 
370 // There are multiple environment variables that may or may not be set during Wayland
371 // sessions, including WAYLAND_DISPLAY, XDG_SESSION_TYPE, and DESKTOP_SESSION
IsWayland()372 bool IsWayland()
373 {
374     static bool checked   = false;
375     static bool isWayland = false;
376     if (!checked)
377     {
378         if (IsLinux())
379         {
380             if (!angle::GetEnvironmentVar("WAYLAND_DISPLAY").empty())
381             {
382                 isWayland = true;
383             }
384             else if (angle::GetEnvironmentVar("XDG_SESSION_TYPE") == "wayland")
385             {
386                 isWayland = true;
387             }
388             else if (angle::GetEnvironmentVar("DESKTOP_SESSION").find("wayland") !=
389                      std::string::npos)
390             {
391                 isWayland = true;
392             }
393         }
394         checked = true;
395     }
396     return isWayland;
397 }
398 
399 }  // namespace rx
400