| Flutter Impeller |

driver_info_vk.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "impeller/renderer/backend/vulkan/driver_info_vk.h"
6
7 #include <iomanip>
8 #include <sstream>
9 #include <string_view>
10 #include <unordered_map>
11
12 #include "flutter/fml/build_config.h"
13
14 namespace impeller {
15
16 const std::unordered_map<std::string_view, AdrenoGPU> kAdrenoVersions = {
17 // X
18 // Note: I don't know if these strings actually match as there don't seem to
19 // be any android devices that use these GPUs.
20 {"X185", AdrenoGPU::kAdrenoX185},
21 {"X145", AdrenoGPU::kAdrenoX145},
22 // 700
23 {"750", AdrenoGPU::kAdreno750},
24 {"740", AdrenoGPU::kAdreno740},
25 {"735", AdrenoGPU::kAdreno735},
26 {"721", AdrenoGPU::kAdreno732},
27 {"730", AdrenoGPU::kAdreno730},
28 {"725", AdrenoGPU::kAdreno725},
29 {"720", AdrenoGPU::kAdreno720},
30 {"710", AdrenoGPU::kAdreno710},
31 {"702", AdrenoGPU::kAdreno702},
32
33 // 600
34 {"695", AdrenoGPU::kAdreno695},
35 {"690", AdrenoGPU::kAdreno690},
36 {"685", AdrenoGPU::kAdreno685},
37 {"680", AdrenoGPU::kAdreno680},
38 {"675", AdrenoGPU::kAdreno675},
39 {"663", AdrenoGPU::kAdreno663},
40 {"660", AdrenoGPU::kAdreno660},
41 {"650", AdrenoGPU::kAdreno650},
42 {"644", AdrenoGPU::kAdreno644},
43 {"643L", AdrenoGPU::kAdreno643L},
44 {"642", AdrenoGPU::kAdreno642},
45 {"642L", AdrenoGPU::kAdreno642L},
46 {"640", AdrenoGPU::kAdreno640},
47 {"630", AdrenoGPU::kAdreno630},
48 {"620", AdrenoGPU::kAdreno620},
49 {"619", AdrenoGPU::kAdreno619},
50 {"619L", AdrenoGPU::kAdreno619L},
51 {"618", AdrenoGPU::kAdreno618},
52 {"616", AdrenoGPU::kAdreno616},
53 {"615", AdrenoGPU::kAdreno615},
54 {"613", AdrenoGPU::kAdreno613},
55 {"612", AdrenoGPU::kAdreno612},
56 {"610", AdrenoGPU::kAdreno610},
57 {"608", AdrenoGPU::kAdreno608},
58 {"605", AdrenoGPU::kAdreno605},
59 // 500
60 {"540", AdrenoGPU::kAdreno540},
61 {"530", AdrenoGPU::kAdreno530},
62 {"512", AdrenoGPU::kAdreno512},
63 {"510", AdrenoGPU::kAdreno510},
64 {"509", AdrenoGPU::kAdreno509},
65 {"508", AdrenoGPU::kAdreno508},
66 {"506", AdrenoGPU::kAdreno506},
67 {"505", AdrenoGPU::kAdreno505},
68 {"504", AdrenoGPU::kAdreno504},
69 };
70
71 const std::unordered_map<std::string_view, MaliGPU> kMaliVersions = {
72 // 5th Gen.
73 {"G925", MaliGPU::kG925},
74 {"G725", MaliGPU::kG725},
75 {"G625", MaliGPU::kG625},
76 {"G720", MaliGPU::kG720},
77 {"G620", MaliGPU::kG620},
78
79 // Valhall
80 // Note: there is an Immortalis-G715 a Mali-G715
81 {"G715", MaliGPU::kG715},
82 {"G615", MaliGPU::kG615},
83 {"G710", MaliGPU::kG710},
84 {"G610", MaliGPU::kG610},
85 {"G510", MaliGPU::kG510},
86 {"G310", MaliGPU::kG310},
87 {"G78", MaliGPU::kG78},
88 {"G68", MaliGPU::kG68},
89 {"G77", MaliGPU::kG77},
90 {"G57", MaliGPU::kG57},
91
92 // Bifrost
93 {"G76", MaliGPU::kG76},
94 {"G72", MaliGPU::kG72},
95 {"G52", MaliGPU::kG52},
96 {"G71", MaliGPU::kG71},
97 {"G51", MaliGPU::kG51},
98 {"G31", MaliGPU::kG31},
99
100 // These might be Vulkan 1.0 Only.
101 {"T880", MaliGPU::kT880},
102 {"T860", MaliGPU::kT860},
103 {"T830", MaliGPU::kT830},
104 {"T820", MaliGPU::kT820},
105 {"T760", MaliGPU::kT760},
106 };
107
108 AdrenoGPU GetAdrenoVersion(std::string_view version) {
109 /// The format that Adreno names follow is "Adreno (TM) VERSION".
110 auto paren_pos = version.find("Adreno (TM) ");
111 if (paren_pos == std::string::npos) {
112 return AdrenoGPU::kUnknown;
113 }
114 auto version_string = version.substr(paren_pos + 12);
115 const auto& result = kAdrenoVersions.find(version_string);
116 if (result == kAdrenoVersions.end()) {
117 return AdrenoGPU::kUnknown;
118 }
119 return result->second;
120 }
121
122 MaliGPU GetMaliVersion(std::string_view version) {
123 // These names are usually Mali-VERSION or Mali-Version-EXTRA_CRAP.
124 auto dash_pos = version.find("Mali-");
125 if (dash_pos == std::string::npos) {
126 return MaliGPU::kUnknown;
127 }
128 auto version_string_with_trailing = version.substr(dash_pos + 5);
129 // Remove any trailing crap if present.
130 auto more_dash_pos = version_string_with_trailing.find("-");
131 if (more_dash_pos != std::string::npos) {
132 version_string_with_trailing =
133 version_string_with_trailing.substr(0, more_dash_pos);
134 }
135
136 const auto& result = kMaliVersions.find(version_string_with_trailing);
137 if (result == kMaliVersions.end()) {
138 return MaliGPU::kUnknown;
139 }
140 return result->second;
141 }
142
143 constexpr VendorVK IdentifyVendor(uint32_t vendor) {
144 // Check if the vendor has a PCI ID:
145 // https://pcisig.com/membership/member-companies
146 switch (vendor) {
147 case 0x1AE0:
148 return VendorVK::kGoogle;
149 case 0x168C:
150 case 0x17CB:
151 case 0x1969:
152 case 0x5143:
153 return VendorVK::kQualcomm;
154 case 0x13B5:
155 return VendorVK::kARM;
156 case 0x1010:
157 return VendorVK::kImgTec;
158 case 0x1002:
159 case 0x1022:
160 return VendorVK::kAMD;
161 case 0x10DE:
162 return VendorVK::kNvidia;
163 case 0x8086: // :)
164 return VendorVK::kIntel;
165 case 0x106B:
166 return VendorVK::kApple;
167 case 0x19E5:
168 return VendorVK::kHuawei;
169 case 0x144D:
170 return VendorVK::kSamsung;
171 }
172 // Check if the ID is a known Khronos vendor.
173 switch (vendor) {
174 case VK_VENDOR_ID_MESA:
175 return VendorVK::kMesa;
176 // There are others but have never been observed. These can be added as
177 // needed.
178 }
179 return VendorVK::kUnknown;
180 }
181
182 constexpr const char* VendorToString(VendorVK vendor) {
183 switch (vendor) {
184 case VendorVK::kUnknown:
185 return "Unknown";
186 case VendorVK::kGoogle:
187 return "Google";
188 case VendorVK::kQualcomm:
189 return "Qualcomm";
190 case VendorVK::kARM:
191 return "ARM";
192 case VendorVK::kImgTec:
193 return "ImgTec PowerVR";
194 case VendorVK::kAMD:
195 return "AMD";
196 case VendorVK::kNvidia:
197 return "Nvidia";
198 case VendorVK::kIntel:
199 return "Intel";
200 case VendorVK::kMesa:
201 return "Mesa";
202 case VendorVK::kApple:
203 return "Apple";
204 case VendorVK::kHuawei:
205 return "Huawei";
206 case VendorVK::kSamsung:
207 return "Samsung";
208 }
209 FML_UNREACHABLE();
210 }
211
212 constexpr const char* DeviceTypeToString(DeviceTypeVK type) {
213 switch (type) {
214 case DeviceTypeVK::kUnknown:
215 return "Unknown";
216 case DeviceTypeVK::kIntegratedGPU:
217 return "Integrated GPU";
218 case DeviceTypeVK::kDiscreteGPU:
219 return "Discrete GPU";
220 case DeviceTypeVK::kVirtualGPU:
221 return "Virtual GPU";
222 case DeviceTypeVK::kCPU:
223 return "CPU";
224 }
225 FML_UNREACHABLE();
226 }
227
228 constexpr DeviceTypeVK ToDeviceType(const vk::PhysicalDeviceType& type) {
229 switch (type) {
230 case vk::PhysicalDeviceType::eOther:
231 return DeviceTypeVK::kUnknown;
232 case vk::PhysicalDeviceType::eIntegratedGpu:
233 return DeviceTypeVK::kIntegratedGPU;
234 case vk::PhysicalDeviceType::eDiscreteGpu:
235 return DeviceTypeVK::kDiscreteGPU;
236 case vk::PhysicalDeviceType::eVirtualGpu:
237 return DeviceTypeVK::kVirtualGPU;
238 case vk::PhysicalDeviceType::eCpu:
239 return DeviceTypeVK::kCPU;
240 break;
241 }
242 return DeviceTypeVK::kUnknown;
243 }
244
245 DriverInfoVK::DriverInfoVK(const vk::PhysicalDevice& device) {
246 auto props = device.getProperties();
247 api_version_ = Version{VK_API_VERSION_MAJOR(props.apiVersion),
248 VK_API_VERSION_MINOR(props.apiVersion),
249 VK_API_VERSION_PATCH(props.apiVersion)};
250 vendor_ = IdentifyVendor(props.vendorID);
251 if (vendor_ == VendorVK::kUnknown) {
252 FML_LOG(WARNING) << "Unknown GPU Driver Vendor: " << props.vendorID
253 << ". This is not an error.";
254 }
255 type_ = ToDeviceType(props.deviceType);
256 if (props.deviceName.data() != nullptr) {
257 driver_name_ = props.deviceName.data();
258 }
259
260 switch (vendor_) {
261 case VendorVK::kQualcomm:
262 adreno_gpu_ = GetAdrenoVersion(driver_name_);
263 break;
264 case VendorVK::kARM:
265 mali_gpu_ = GetMaliVersion(driver_name_);
266 break;
267 default:
268 break;
269 }
270 }
271
272 DriverInfoVK::~DriverInfoVK() = default;
273
274 const Version& DriverInfoVK::GetAPIVersion() const {
275 return api_version_;
276 }
277
278 const VendorVK& DriverInfoVK::GetVendor() const {
279 return vendor_;
280 }
281
282 const DeviceTypeVK& DriverInfoVK::GetDeviceType() const {
283 return type_;
284 }
285
286 const std::string& DriverInfoVK::GetDriverName() const {
287 return driver_name_;
288 }
289
290 void DriverInfoVK::DumpToLog() const {
291 std::vector<std::pair<std::string, std::string>> items;
292 items.emplace_back("Name", driver_name_);
293 items.emplace_back("API Version", api_version_.ToString());
294 items.emplace_back("Vendor", VendorToString(vendor_));
295 items.emplace_back("Device Type", DeviceTypeToString(type_));
296 items.emplace_back("Is Emulator", std::to_string(IsEmulator()));
297
298 size_t padding = 0;
299
300 for (const auto& item : items) {
301 padding = std::max(padding, item.first.size());
302 }
303
304 padding += 1;
305
306 std::stringstream stream;
307
308 stream << std::endl;
309
310 stream << "--- Driver Information ------------------------------------------";
311
312 stream << std::endl;
313
314 for (const auto& item : items) {
315 stream << "| " << std::setw(static_cast<int>(padding)) << item.first
316 << std::setw(0) << ": " << item.second << std::endl;
317 }
318
319 stream << "-----------------------------------------------------------------";
320
321 FML_LOG(IMPORTANT) << stream.str();
322 }
323
324 bool DriverInfoVK::IsEmulator() const {
325 #if FML_OS_ANDROID
326 // Google SwiftShader on Android.
327 if (type_ == DeviceTypeVK::kCPU && vendor_ == VendorVK::kGoogle &&
328 driver_name_.find("SwiftShader") != std::string::npos) {
329 return true;
330 }
331 #endif // FML_OS_ANDROID
332 return false;
333 }
334
335 bool DriverInfoVK::IsKnownBadDriver() const {
336 // Disable Maleoon series GPUs, see:
337 // https://github.com/flutter/flutter/issues/156623
338 if (vendor_ == VendorVK::kHuawei) {
339 return true;
340 }
341
342 if (vendor_ == VendorVK::kSamsung) {
343 // The first version of the Xclipse series GPU has reported
344 // bugs, unfortunately all versions of this GPU report the
345 // same driver version. Instead we use the Vulkan version
346 // as a proxy, assuming that any newer devices would not
347 // lower the supported Vulkan API level.
348 // See
349 // https://vulkan.gpuinfo.org/listreports.php?devicename=samsung+SM-S906B&platform=android
350 // https://github.com/flutter/flutter/issues/161334
351 return !api_version_.IsAtLeast(Version{1, 3, 0});
352 }
353
354 // https://github.com/flutter/flutter/issues/161122
355 // https://github.com/flutter/flutter/issues/160960
356 // https://github.com/flutter/flutter/issues/160866
357 // https://github.com/flutter/flutter/issues/160804
358 // https://github.com/flutter/flutter/issues/160406
359 if (vendor_ == VendorVK::kImgTec) {
360 return true;
361 }
362 return false;
363 }
364
365 std::optional<MaliGPU> DriverInfoVK::GetMaliGPUInfo() const {
366 return mali_gpu_;
367 }
368
369 std::optional<AdrenoGPU> DriverInfoVK::GetAdrenoGPUInfo() const {
370 return adreno_gpu_;
371 }
372
373 } // namespace impeller
type
GLenum type
Definition: blit_command_gles.cc:151
impeller::DriverInfoVK::GetVendor
const VendorVK & GetVendor() const
Get the vendor of the Vulkan implementation. This is a broad check and includes multiple drivers and ...
Definition: driver_info_vk.cc:278
impeller::DriverInfoVK::DriverInfoVK
DriverInfoVK(const vk::PhysicalDevice &device)
Definition: driver_info_vk.cc:245
impeller::DriverInfoVK::IsKnownBadDriver
bool IsKnownBadDriver() const
Determines if the driver has been tested and determined to be non-functional.
Definition: driver_info_vk.cc:335
impeller::DriverInfoVK::~DriverInfoVK
~DriverInfoVK()
impeller::DriverInfoVK::GetDriverName
const std::string & GetDriverName() const
Get the self-reported name of the graphics driver.
Definition: driver_info_vk.cc:286
impeller::DriverInfoVK::GetAdrenoGPUInfo
std::optional< AdrenoGPU > GetAdrenoGPUInfo() const
Returns Adreno GPU info if this is a Adreno GPU, otherwise std::nullopt.
Definition: driver_info_vk.cc:369
impeller::DriverInfoVK::DumpToLog
void DumpToLog() const
Dumps the current driver info to the log.
Definition: driver_info_vk.cc:290
impeller::DriverInfoVK::GetMaliGPUInfo
std::optional< MaliGPU > GetMaliGPUInfo() const
Returns Mali GPU info if this is a Mali GPU, otherwise std::nullopt.
Definition: driver_info_vk.cc:365
impeller::DriverInfoVK::IsEmulator
bool IsEmulator() const
Determines if the driver represents an emulator. There is no definitive way to tell if a driver is an...
Definition: driver_info_vk.cc:324
impeller::DriverInfoVK::GetDeviceType
const DeviceTypeVK & GetDeviceType() const
Get the device type. Typical use might be to check if the device is a CPU implementation.
Definition: driver_info_vk.cc:282
impeller::DriverInfoVK::GetAPIVersion
const Version & GetAPIVersion() const
Gets the Vulkan API version. Should be at or above Vulkan 1.1 which is the Impeller baseline.
Definition: driver_info_vk.cc:274
driver_info_vk.h
padding
Vector2 padding
The halo padding in source space.
Definition: gaussian_blur_filter_contents.cc:86
impeller
Definition: allocation.cc:12
impeller::MaliGPU
MaliGPU
Definition: driver_info_vk.h:73
impeller::MaliGPU::kG310
@ kG310
impeller::MaliGPU::kG77
@ kG77
impeller::MaliGPU::kG620
@ kG620
impeller::MaliGPU::kUnknown
@ kUnknown
impeller::MaliGPU::kT820
@ kT820
impeller::MaliGPU::kG51
@ kG51
impeller::MaliGPU::kG720
@ kG720
impeller::MaliGPU::kG725
@ kG725
impeller::MaliGPU::kG610
@ kG610
impeller::MaliGPU::kG68
@ kG68
impeller::MaliGPU::kG715
@ kG715
impeller::MaliGPU::kT830
@ kT830
impeller::MaliGPU::kG57
@ kG57
impeller::MaliGPU::kG625
@ kG625
impeller::MaliGPU::kT880
@ kT880
impeller::MaliGPU::kT860
@ kT860
impeller::MaliGPU::kG615
@ kG615
impeller::MaliGPU::kG78
@ kG78
impeller::MaliGPU::kG52
@ kG52
impeller::MaliGPU::kG925
@ kG925
impeller::MaliGPU::kG72
@ kG72
impeller::MaliGPU::kG510
@ kG510
impeller::MaliGPU::kG76
@ kG76
impeller::MaliGPU::kT760
@ kT760
impeller::MaliGPU::kG71
@ kG71
impeller::MaliGPU::kG710
@ kG710
impeller::MaliGPU::kG31
@ kG31
impeller::VendorVK
VendorVK
Definition: driver_info_vk.h:111
impeller::VendorVK::kUnknown
@ kUnknown
impeller::VendorVK::kImgTec
@ kImgTec
impeller::VendorVK::kIntel
@ kIntel
impeller::VendorVK::kSamsung
@ kSamsung
impeller::VendorVK::kGoogle
@ kGoogle
impeller::VendorVK::kHuawei
@ kHuawei
impeller::VendorVK::kApple
@ kApple
impeller::VendorVK::kQualcomm
@ kQualcomm
impeller::VendorVK::kNvidia
@ kNvidia
impeller::VendorVK::kMesa
@ kMesa
impeller::VendorVK::kARM
@ kARM
impeller::VendorVK::kAMD
@ kAMD
impeller::kMaliVersions
const std::unordered_map< std::string_view, MaliGPU > kMaliVersions
Definition: driver_info_vk.cc:71
impeller::AdrenoGPU
AdrenoGPU
Definition: driver_info_vk.h:14
impeller::AdrenoGPU::kAdrenoX145
@ kAdrenoX145
impeller::AdrenoGPU::kAdreno618
@ kAdreno618
impeller::AdrenoGPU::kAdreno690
@ kAdreno690
impeller::AdrenoGPU::kAdreno630
@ kAdreno630
impeller::AdrenoGPU::kAdreno642
@ kAdreno642
impeller::AdrenoGPU::kAdreno730
@ kAdreno730
impeller::AdrenoGPU::kAdreno509
@ kAdreno509
impeller::AdrenoGPU::kAdreno642L
@ kAdreno642L
impeller::AdrenoGPU::kAdreno750
@ kAdreno750
impeller::AdrenoGPU::kUnknown
@ kUnknown
impeller::AdrenoGPU::kAdreno615
@ kAdreno615
impeller::AdrenoGPU::kAdreno510
@ kAdreno510
impeller::AdrenoGPU::kAdreno610
@ kAdreno610
impeller::AdrenoGPU::kAdreno680
@ kAdreno680
impeller::AdrenoGPU::kAdreno695
@ kAdreno695
impeller::AdrenoGPU::kAdreno725
@ kAdreno725
impeller::AdrenoGPU::kAdreno740
@ kAdreno740
impeller::AdrenoGPU::kAdreno720
@ kAdreno720
impeller::AdrenoGPU::kAdreno685
@ kAdreno685
impeller::AdrenoGPU::kAdreno613
@ kAdreno613
impeller::AdrenoGPU::kAdrenoX185
@ kAdrenoX185
impeller::AdrenoGPU::kAdreno506
@ kAdreno506
impeller::AdrenoGPU::kAdreno505
@ kAdreno505
impeller::AdrenoGPU::kAdreno702
@ kAdreno702
impeller::AdrenoGPU::kAdreno605
@ kAdreno605
impeller::AdrenoGPU::kAdreno619L
@ kAdreno619L
impeller::AdrenoGPU::kAdreno732
@ kAdreno732
impeller::AdrenoGPU::kAdreno650
@ kAdreno650
impeller::AdrenoGPU::kAdreno643L
@ kAdreno643L
impeller::AdrenoGPU::kAdreno540
@ kAdreno540
impeller::AdrenoGPU::kAdreno620
@ kAdreno620
impeller::AdrenoGPU::kAdreno530
@ kAdreno530
impeller::AdrenoGPU::kAdreno619
@ kAdreno619
impeller::AdrenoGPU::kAdreno735
@ kAdreno735
impeller::AdrenoGPU::kAdreno612
@ kAdreno612
impeller::AdrenoGPU::kAdreno710
@ kAdreno710
impeller::AdrenoGPU::kAdreno640
@ kAdreno640
impeller::AdrenoGPU::kAdreno663
@ kAdreno663
impeller::AdrenoGPU::kAdreno508
@ kAdreno508
impeller::AdrenoGPU::kAdreno675
@ kAdreno675
impeller::AdrenoGPU::kAdreno608
@ kAdreno608
impeller::AdrenoGPU::kAdreno644
@ kAdreno644
impeller::AdrenoGPU::kAdreno616
@ kAdreno616
impeller::AdrenoGPU::kAdreno660
@ kAdreno660
impeller::AdrenoGPU::kAdreno504
@ kAdreno504
impeller::AdrenoGPU::kAdreno512
@ kAdreno512
impeller::IdentifyVendor
constexpr VendorVK IdentifyVendor(uint32_t vendor)
Definition: driver_info_vk.cc:143
impeller::GetMaliVersion
MaliGPU GetMaliVersion(std::string_view version)
Definition: driver_info_vk.cc:122
impeller::GetAdrenoVersion
AdrenoGPU GetAdrenoVersion(std::string_view version)
Definition: driver_info_vk.cc:108
impeller::VendorToString
constexpr const char * VendorToString(VendorVK vendor)
Definition: driver_info_vk.cc:182
impeller::DeviceTypeVK
DeviceTypeVK
Definition: driver_info_vk.h:136
impeller::DeviceTypeVK::kVirtualGPU
@ kVirtualGPU
impeller::DeviceTypeVK::kUnknown
@ kUnknown
impeller::DeviceTypeVK::kCPU
@ kCPU
impeller::DeviceTypeVK::kIntegratedGPU
@ kIntegratedGPU
impeller::DeviceTypeVK::kDiscreteGPU
@ kDiscreteGPU
impeller::DeviceTypeToString
constexpr const char * DeviceTypeToString(DeviceTypeVK type)
Definition: driver_info_vk.cc:212
impeller::kAdrenoVersions
const std::unordered_map< std::string_view, AdrenoGPU > kAdrenoVersions
Definition: driver_info_vk.cc:16
impeller::ToDeviceType
constexpr DeviceTypeVK ToDeviceType(const vk::PhysicalDeviceType &type)
Definition: driver_info_vk.cc:228
impeller::Version
Definition: version.h:16
impeller::Version::IsAtLeast
constexpr bool IsAtLeast(const Version &other) const
Definition: version.h:31
impeller::Version::ToString
std::string ToString() const
Definition: version.cc:27