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 
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) {
215  return "Unknown";
217  return "Integrated GPU";
219  return "Discrete GPU";
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:
234  case vk::PhysicalDeviceType::eDiscreteGpu:
236  case vk::PhysicalDeviceType::eVirtualGpu:
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 
275  return api_version_;
276 }
277 
279  return vendor_;
280 }
281 
283  return type_;
284 }
285 
286 const std::string& DriverInfoVK::GetDriverName() const {
287  return driver_name_;
288 }
289 
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 
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 
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
GLenum type
const VendorVK & GetVendor() const
Get the vendor of the Vulkan implementation. This is a broad check and includes multiple drivers and ...
DriverInfoVK(const vk::PhysicalDevice &device)
bool IsKnownBadDriver() const
Determines if the driver has been tested and determined to be non-functional.
const std::string & GetDriverName() const
Get the self-reported name of the graphics driver.
std::optional< AdrenoGPU > GetAdrenoGPUInfo() const
Returns Adreno GPU info if this is a Adreno GPU, otherwise std::nullopt.
void DumpToLog() const
Dumps the current driver info to the log.
std::optional< MaliGPU > GetMaliGPUInfo() const
Returns Mali GPU info if this is a Mali GPU, otherwise std::nullopt.
bool IsEmulator() const
Determines if the driver represents an emulator. There is no definitive way to tell if a driver is an...
const DeviceTypeVK & GetDeviceType() const
Get the device type. Typical use might be to check if the device is a CPU implementation.
const Version & GetAPIVersion() const
Gets the Vulkan API version. Should be at or above Vulkan 1.1 which is the Impeller baseline.
Vector2 padding
The halo padding in source space.
const std::unordered_map< std::string_view, MaliGPU > kMaliVersions
constexpr VendorVK IdentifyVendor(uint32_t vendor)
MaliGPU GetMaliVersion(std::string_view version)
AdrenoGPU GetAdrenoVersion(std::string_view version)
constexpr const char * VendorToString(VendorVK vendor)
constexpr const char * DeviceTypeToString(DeviceTypeVK type)
const std::unordered_map< std::string_view, AdrenoGPU > kAdrenoVersions
constexpr DeviceTypeVK ToDeviceType(const vk::PhysicalDeviceType &type)
constexpr bool IsAtLeast(const Version &other) const
Definition: version.h:31
std::string ToString() const
Definition: version.cc:27