Flutter Engine
The Flutter Engine
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
10#include "flutter/fml/build_config.h"
11
12namespace impeller {
13
14constexpr VendorVK IdentifyVendor(uint32_t vendor) {
15 // Check if the vendor has a PCI ID:
16 // https://pcisig.com/membership/member-companies
17 switch (vendor) {
18 case 0x1AE0:
19 return VendorVK::kGoogle;
20 case 0x168C:
21 case 0x17CB:
22 case 0x1969:
23 case 0x5143:
25 case 0x13B5:
26 return VendorVK::kARM;
27 case 0x1010:
28 return VendorVK::kImgTec;
29 case 0x1002:
30 case 0x1022:
31 return VendorVK::kAMD;
32 case 0x10DE:
33 return VendorVK::kNvidia;
34 case 0x8086: // :)
35 return VendorVK::kIntel;
36 case 0x106B:
37 return VendorVK::kApple;
38 }
39 // Check if the ID is a known Khronos vendor.
40 switch (vendor) {
42 return VendorVK::kMesa;
43 // There are others but have never been observed. These can be added as
44 // needed.
45 }
46 return VendorVK::kUnknown;
47}
48
49constexpr const char* VendorToString(VendorVK vendor) {
50 switch (vendor) {
52 return "Unknown";
54 return "Google";
56 return "Qualcomm";
57 case VendorVK::kARM:
58 return "ARM";
60 return "ImgTec PowerVR";
61 case VendorVK::kAMD:
62 return "AMD";
64 return "Nvidia";
66 return "Intel";
67 case VendorVK::kMesa:
68 return "Mesa";
70 return "Apple";
71 }
73}
74
75constexpr const char* DeviceTypeToString(DeviceTypeVK type) {
76 switch (type) {
78 return "Unknown";
80 return "Integrated GPU";
82 return "Discrete GPU";
84 return "Virtual GPU";
86 return "CPU";
87 }
89}
90
91constexpr DeviceTypeVK ToDeviceType(const vk::PhysicalDeviceType& type) {
92 switch (type) {
93 case vk::PhysicalDeviceType::eOther:
95 case vk::PhysicalDeviceType::eIntegratedGpu:
97 case vk::PhysicalDeviceType::eDiscreteGpu:
99 case vk::PhysicalDeviceType::eVirtualGpu:
101 case vk::PhysicalDeviceType::eCpu:
102 return DeviceTypeVK::kCPU;
103 break;
104 }
106}
107
108DriverInfoVK::DriverInfoVK(const vk::PhysicalDevice& device) {
109 auto props = device.getProperties();
110 api_version_ = Version{VK_API_VERSION_MAJOR(props.apiVersion),
111 VK_API_VERSION_MINOR(props.apiVersion),
112 VK_API_VERSION_PATCH(props.apiVersion)};
113 vendor_ = IdentifyVendor(props.vendorID);
114 if (vendor_ == VendorVK::kUnknown) {
115 FML_LOG(WARNING) << "Unknown GPU Driver Vendor: " << props.vendorID
116 << ". This is not an error.";
117 }
118 type_ = ToDeviceType(props.deviceType);
119 if (props.deviceName.data() != nullptr) {
120 driver_name_ = props.deviceName.data();
121 }
122}
123
125
127 return api_version_;
128}
129
131 return vendor_;
132}
133
135 return type_;
136}
137
138const std::string& DriverInfoVK::GetDriverName() const {
139 return driver_name_;
140}
141
143 std::vector<std::pair<std::string, std::string>> items;
144 items.emplace_back("Name", driver_name_);
145 items.emplace_back("API Version", api_version_.ToString());
146 items.emplace_back("Vendor", VendorToString(vendor_));
147 items.emplace_back("Device Type", DeviceTypeToString(type_));
148 items.emplace_back("Is Emulator", std::to_string(IsEmulator()));
149
150 size_t padding = 0;
151
152 for (const auto& item : items) {
153 padding = std::max(padding, item.first.size());
154 }
155
156 padding += 1;
157
158 std::stringstream stream;
159
160 stream << std::endl;
161
162 stream << "--- Driver Information ------------------------------------------";
163
164 stream << std::endl;
165
166 for (const auto& item : items) {
167 stream << "| " << std::setw(static_cast<int>(padding)) << item.first
168 << std::setw(0) << ": " << item.second << std::endl;
169 }
170
171 stream << "-----------------------------------------------------------------";
172
173 FML_LOG(IMPORTANT) << stream.str();
174}
175
177#if FML_OS_ANDROID
178 // Google SwiftShader on Android.
179 if (type_ == DeviceTypeVK::kCPU && vendor_ == VendorVK::kGoogle &&
180 driver_name_.find("SwiftShader") != std::string::npos) {
181 return true;
182 }
183#endif // FML_OS_ANDROID
184 return false;
185}
186
187} // 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)
const std::string & GetDriverName() const
Get the self-reported name of the graphics driver.
void DumpToLog() const
Dumps the current driver info to the log.
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.
VkDevice device
Definition: main.cc:53
#define FML_LOG(severity)
Definition: logging.h:82
#define FML_UNREACHABLE()
Definition: logging.h:109
static float max(float r, float g, float b)
Definition: hsl.cpp:49
constexpr VendorVK IdentifyVendor(uint32_t vendor)
constexpr const char * DeviceTypeToString(DeviceTypeVK type)
constexpr const char * VendorToString(VendorVK vendor)
constexpr DeviceTypeVK ToDeviceType(const vk::PhysicalDeviceType &type)
static SkString to_string(int n)
Definition: nanobench.cpp:119
std::string ToString() const
#define VK_API_VERSION_PATCH(version)
Definition: vulkan_core.h:93
#define VK_API_VERSION_MINOR(version)
Definition: vulkan_core.h:92
@ VK_VENDOR_ID_MESA
Definition: vulkan_core.h:1438
#define VK_API_VERSION_MAJOR(version)
Definition: vulkan_core.h:91