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