• 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 
15 #if defined(ANGLE_PLATFORM_ANDROID)
16 #    include <sys/system_properties.h>
17 #endif
18 
19 #if defined(ANGLE_PLATFORM_LINUX)
20 #    include <sys/utsname.h>
21 #endif
22 
23 namespace rx
24 {
25 // Intel
26 // Referenced from https://cgit.freedesktop.org/vaapi/intel-driver/tree/src/i965_pciids.h
27 namespace
28 {
29 // gen7
30 const uint32_t IvyBridge[] = {0x0152, 0x0156, 0x015A, 0x0162, 0x0166, 0x016A};
31 
32 const uint32_t Haswell[] = {
33     0x0402, 0x0406, 0x040A, 0x040B, 0x040E, 0x0C02, 0x0C06, 0x0C0A, 0x0C0B, 0x0C0E,
34     0x0A02, 0x0A06, 0x0A0A, 0x0A0B, 0x0A0E, 0x0D02, 0x0D06, 0x0D0A, 0x0D0B, 0x0D0E,  // hsw_gt1
35     0x0412, 0x0416, 0x041A, 0x041B, 0x041E, 0x0C12, 0x0C16, 0x0C1A, 0x0C1B, 0x0C1E,
36     0x0A12, 0x0A16, 0x0A1A, 0x0A1B, 0x0A1E, 0x0D12, 0x0D16, 0x0D1A, 0x0D1B, 0x0D1E,  // hsw_gt2
37     0x0422, 0x0426, 0x042A, 0x042B, 0x042E, 0x0C22, 0x0C26, 0x0C2A, 0x0C2B, 0x0C2E,
38     0x0A22, 0x0A26, 0x0A2A, 0x0A2B, 0x0A2E, 0x0D22, 0x0D26, 0x0D2A, 0x0D2B, 0x0D2E  // hsw_gt3
39 };
40 
41 // gen8
42 const uint32_t Broadwell[] = {0x1602, 0x1606, 0x160A, 0x160B, 0x160D, 0x160E,
43                               0x1612, 0x1616, 0x161A, 0x161B, 0x161D, 0x161E,
44                               0x1622, 0x1626, 0x162A, 0x162B, 0x162D, 0x162E};
45 
46 const uint32_t CherryView[] = {0x22B0, 0x22B1, 0x22B2, 0x22B3};
47 
48 // gen9
49 const uint32_t Skylake[] = {0x1902, 0x1906, 0x190A, 0x190B, 0x190E, 0x1912, 0x1913, 0x1915, 0x1916,
50                             0x1917, 0x191A, 0x191B, 0x191D, 0x191E, 0x1921, 0x1923, 0x1926, 0x1927,
51                             0x192A, 0x192B, 0x192D, 0x1932, 0x193A, 0x193B, 0x193D};
52 
53 const uint32_t Broxton[] = {0x0A84, 0x1A84, 0x1A85, 0x5A84, 0x5A85};
54 
55 // gen9p5
56 const uint32_t Kabylake[] = {0x5916, 0x5913, 0x5906, 0x5926, 0x5921, 0x5915, 0x590E,
57                              0x591E, 0x5912, 0x5917, 0x5902, 0x591B, 0x593B, 0x590B,
58                              0x591A, 0x590A, 0x591D, 0x5908, 0x5923, 0x5927};
59 
60 }  // anonymous namespace
61 
IntelDriverVersion(uint16_t lastPart)62 IntelDriverVersion::IntelDriverVersion(uint16_t lastPart) : mVersionPart(lastPart) {}
63 
operator ==(const IntelDriverVersion & version)64 bool IntelDriverVersion::operator==(const IntelDriverVersion &version)
65 {
66     return mVersionPart == version.mVersionPart;
67 }
68 
operator !=(const IntelDriverVersion & version)69 bool IntelDriverVersion::operator!=(const IntelDriverVersion &version)
70 {
71     return !(*this == version);
72 }
73 
operator <(const IntelDriverVersion & version)74 bool IntelDriverVersion::operator<(const IntelDriverVersion &version)
75 {
76     // See http://www.intel.com/content/www/us/en/support/graphics-drivers/000005654.html to
77     // understand the Intel graphics driver version number on Windows.
78     // mVersionPart1 changes with OS version. mVersionPart2 changes with DirectX version.
79     // mVersionPart3 stands for release year. mVersionPart4 is driver specific unique version
80     // number.
81     // For example: Intel driver version '20.19.15.4539'
82     //              20   -> windows 10 driver
83     //              19   -> DirectX 12 first version(12.0) supported
84     //              15   -> Driver released in 2015
85     //              4539 -> Driver specific unique version number
86     // For linux, Intel graphics driver version is the mesa version. The version number has three
87     // parts: major revision, minor revision, release number. So, for linux, we need to compare
88     // three parts.
89     // Currently, it's only used in windows. So, checking the last part is enough. Once it's needed
90     // in other platforms, it's easy to be extended.
91     return mVersionPart < version.mVersionPart;
92 }
93 
operator >=(const IntelDriverVersion & version)94 bool IntelDriverVersion::operator>=(const IntelDriverVersion &version)
95 {
96     return !(*this < version);
97 }
98 
IsIvyBridge(uint32_t DeviceId)99 bool IsIvyBridge(uint32_t DeviceId)
100 {
101     return std::find(std::begin(IvyBridge), std::end(IvyBridge), DeviceId) != std::end(IvyBridge);
102 }
103 
IsHaswell(uint32_t DeviceId)104 bool IsHaswell(uint32_t DeviceId)
105 {
106     return std::find(std::begin(Haswell), std::end(Haswell), DeviceId) != std::end(Haswell);
107 }
108 
IsBroadwell(uint32_t DeviceId)109 bool IsBroadwell(uint32_t DeviceId)
110 {
111     return std::find(std::begin(Broadwell), std::end(Broadwell), DeviceId) != std::end(Broadwell);
112 }
113 
IsCherryView(uint32_t DeviceId)114 bool IsCherryView(uint32_t DeviceId)
115 {
116     return std::find(std::begin(CherryView), std::end(CherryView), DeviceId) !=
117            std::end(CherryView);
118 }
119 
IsSkylake(uint32_t DeviceId)120 bool IsSkylake(uint32_t DeviceId)
121 {
122     return std::find(std::begin(Skylake), std::end(Skylake), DeviceId) != std::end(Skylake);
123 }
124 
IsBroxton(uint32_t DeviceId)125 bool IsBroxton(uint32_t DeviceId)
126 {
127     return std::find(std::begin(Broxton), std::end(Broxton), DeviceId) != std::end(Broxton);
128 }
129 
IsKabylake(uint32_t DeviceId)130 bool IsKabylake(uint32_t DeviceId)
131 {
132     return std::find(std::begin(Kabylake), std::end(Kabylake), DeviceId) != std::end(Kabylake);
133 }
134 
GetVendorString(uint32_t vendorId)135 const char *GetVendorString(uint32_t vendorId)
136 {
137     switch (vendorId)
138     {
139         case VENDOR_ID_AMD:
140             return "Advanced Micro Devices";
141         case VENDOR_ID_ARM:
142             return "ARM";
143         case VENDOR_ID_BROADCOM:
144             return "Broadcom";
145         case VENDOR_ID_GOOGLE:
146             return "Google";
147         case VENDOR_ID_INTEL:
148             return "Intel";
149         case VENDOR_ID_NVIDIA:
150             return "NVIDIA";
151         case VENDOR_ID_QUALCOMM:
152             return "Qualcomm";
153         default:
154             // TODO(jmadill): More vendor IDs.
155             ASSERT(vendorId == 0xba5eba11);  // Mock vendor ID used for tests.
156             return "Unknown";
157     }
158 }
159 
GetAndroidSDKVersion()160 int GetAndroidSDKVersion()
161 {
162 #if defined(ANGLE_PLATFORM_ANDROID)
163     char apiVersion[PROP_VALUE_MAX];
164     int length = __system_property_get("ro.build.version.sdk", apiVersion);
165     if (length == 0)
166     {
167         return 0;
168     }
169     return atoi(apiVersion);
170 #else
171     return 0;
172 #endif
173 }
174 
OSVersion()175 OSVersion::OSVersion() {}
OSVersion(int major,int minor,int patch)176 OSVersion::OSVersion(int major, int minor, int patch)
177     : majorVersion(major), minorVersion(minor), patchVersion(patch)
178 {}
179 
operator ==(const OSVersion & a,const OSVersion & b)180 bool operator==(const OSVersion &a, const OSVersion &b)
181 {
182     return std::tie(a.majorVersion, a.minorVersion, a.patchVersion) ==
183            std::tie(b.majorVersion, b.minorVersion, b.patchVersion);
184 }
operator !=(const OSVersion & a,const OSVersion & b)185 bool operator!=(const OSVersion &a, const OSVersion &b)
186 {
187     return std::tie(a.majorVersion, a.minorVersion, a.patchVersion) !=
188            std::tie(b.majorVersion, b.minorVersion, b.patchVersion);
189 }
operator <(const OSVersion & a,const OSVersion & b)190 bool operator<(const OSVersion &a, const OSVersion &b)
191 {
192     return std::tie(a.majorVersion, a.minorVersion, a.patchVersion) <
193            std::tie(b.majorVersion, b.minorVersion, b.patchVersion);
194 }
operator >=(const OSVersion & a,const OSVersion & b)195 bool operator>=(const OSVersion &a, const OSVersion &b)
196 {
197     return std::tie(a.majorVersion, a.minorVersion, a.patchVersion) >=
198            std::tie(b.majorVersion, b.minorVersion, b.patchVersion);
199 }
200 
201 #if !defined(ANGLE_PLATFORM_APPLE)
GetMacOSVersion()202 OSVersion GetMacOSVersion()
203 {
204     // Return a default version
205     return OSVersion(0, 0, 0);
206 }
207 #endif
208 
209 #if defined(ANGLE_PLATFORM_LINUX)
ParseLinuxOSVersion(const char * version,int * major,int * minor,int * patch)210 bool ParseLinuxOSVersion(const char *version, int *major, int *minor, int *patch)
211 {
212     errno = 0;  // reset global error flag.
213     char *next;
214     *major = static_cast<int>(strtol(version, &next, 10));
215     if (next == nullptr || *next != '.' || errno != 0)
216     {
217         return false;
218     }
219 
220     *minor = static_cast<int>(strtol(next + 1, &next, 10));
221     if (next == nullptr || *next != '.' || errno != 0)
222     {
223         return false;
224     }
225 
226     *patch = static_cast<int>(strtol(next + 1, &next, 10));
227     if (errno != 0)
228     {
229         return false;
230     }
231 
232     return true;
233 }
234 #endif
235 
GetLinuxOSVersion()236 OSVersion GetLinuxOSVersion()
237 {
238 #if defined(ANGLE_PLATFORM_LINUX)
239     struct utsname uname_info;
240     if (uname(&uname_info) != 0)
241     {
242         return OSVersion(0, 0, 0);
243     }
244 
245     int majorVersion = 0, minorVersion = 0, patchVersion = 0;
246     if (ParseLinuxOSVersion(uname_info.release, &majorVersion, &minorVersion, &patchVersion))
247     {
248         return OSVersion(majorVersion, minorVersion, patchVersion);
249     }
250 #endif
251 
252     return OSVersion(0, 0, 0);
253 }
254 
255 }  // namespace rx
256