| 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
10 #include "flutter/fml/build_config.h"
11
12 namespace impeller {
13
14 constexpr 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:
24 return VendorVK::kQualcomm;
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) {
41 case VK_VENDOR_ID_MESA:
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
49 constexpr const char* VendorToString(VendorVK vendor) {
50 switch (vendor) {
51 case VendorVK::kUnknown:
52 return "Unknown";
53 case VendorVK::kGoogle:
54 return "Google";
55 case VendorVK::kQualcomm:
56 return "Qualcomm";
57 case VendorVK::kARM:
58 return "ARM";
59 case VendorVK::kImgTec:
60 return "ImgTec PowerVR";
61 case VendorVK::kAMD:
62 return "AMD";
63 case VendorVK::kNvidia:
64 return "Nvidia";
65 case VendorVK::kIntel:
66 return "Intel";
67 case VendorVK::kMesa:
68 return "Mesa";
69 case VendorVK::kApple:
70 return "Apple";
71 }
72 FML_UNREACHABLE();
73 }
74
75 constexpr const char* DeviceTypeToString(DeviceTypeVK type) {
76 switch (type) {
77 case DeviceTypeVK::kUnknown:
78 return "Unknown";
79 case DeviceTypeVK::kIntegratedGPU:
80 return "Integrated GPU";
81 case DeviceTypeVK::kDiscreteGPU:
82 return "Discrete GPU";
83 case DeviceTypeVK::kVirtualGPU:
84 return "Virtual GPU";
85 case DeviceTypeVK::kCPU:
86 return "CPU";
87 }
88 FML_UNREACHABLE();
89 }
90
91 constexpr DeviceTypeVK ToDeviceType(const vk::PhysicalDeviceType& type) {
92 switch (type) {
93 case vk::PhysicalDeviceType::eOther:
94 return DeviceTypeVK::kUnknown;
95 case vk::PhysicalDeviceType::eIntegratedGpu:
96 return DeviceTypeVK::kIntegratedGPU;
97 case vk::PhysicalDeviceType::eDiscreteGpu:
98 return DeviceTypeVK::kDiscreteGPU;
99 case vk::PhysicalDeviceType::eVirtualGpu:
100 return DeviceTypeVK::kVirtualGPU;
101 case vk::PhysicalDeviceType::eCpu:
102 return DeviceTypeVK::kCPU;
103 break;
104 }
105 return DeviceTypeVK::kUnknown;
106 }
107
108 DriverInfoVK::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
124 DriverInfoVK::~DriverInfoVK() = default;
125
126 const Version& DriverInfoVK::GetAPIVersion() const {
127 return api_version_;
128 }
129
130 const VendorVK& DriverInfoVK::GetVendor() const {
131 return vendor_;
132 }
133
134 const DeviceTypeVK& DriverInfoVK::GetDeviceType() const {
135 return type_;
136 }
137
138 const std::string& DriverInfoVK::GetDriverName() const {
139 return driver_name_;
140 }
141
142 void DriverInfoVK::DumpToLog() const {
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
176 bool DriverInfoVK::IsEmulator() const {
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
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:130
impeller::DeviceTypeVK::kDiscreteGPU
@ kDiscreteGPU
impeller::DeviceTypeVK::kIntegratedGPU
@ kIntegratedGPU
impeller::DriverInfoVK::~DriverInfoVK
~DriverInfoVK()
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:134
impeller::DriverInfoVK::DriverInfoVK
DriverInfoVK(const vk::PhysicalDevice &device)
Definition: driver_info_vk.cc:108
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:176
impeller::DriverInfoVK::DumpToLog
void DumpToLog() const
Dumps the current driver info to the log.
Definition: driver_info_vk.cc:142
padding
Vector2 padding
The halo padding in source space.
Definition: gaussian_blur_filter_contents.cc:91
impeller::Version
Definition: version.h:16
impeller::VendorVK::kARM
@ kARM
impeller::VendorVK::kGoogle
@ kGoogle
impeller::VendorVK::kAMD
@ kAMD
impeller::Version::ToString
std::string ToString() const
Definition: version.cc:27
impeller::VendorVK::kMesa
@ kMesa
impeller::VendorVK::kApple
@ kApple
impeller::VendorVK::kImgTec
@ kImgTec
type
GLenum type
Definition: blit_command_gles.cc:126
impeller::VendorToString
constexpr const char * VendorToString(VendorVK vendor)
Definition: driver_info_vk.cc:49
impeller::VendorVK::kQualcomm
@ kQualcomm
impeller::DeviceTypeVK::kVirtualGPU
@ kVirtualGPU
driver_info_vk.h
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:126
impeller::DeviceTypeVK
DeviceTypeVK
Definition: driver_info_vk.h:36
impeller::DeviceTypeVK::kCPU
@ kCPU
impeller::VendorVK::kIntel
@ kIntel
impeller::VendorVK
VendorVK
Definition: driver_info_vk.h:13
impeller::VendorVK::kUnknown
@ kUnknown
impeller::IdentifyVendor
constexpr VendorVK IdentifyVendor(uint32_t vendor)
Definition: driver_info_vk.cc:14
impeller::VendorVK::kNvidia
@ kNvidia
impeller::DeviceTypeVK::kUnknown
@ kUnknown
impeller::DriverInfoVK::GetDriverName
const std::string & GetDriverName() const
Get the self-reported name of the graphics driver.
Definition: driver_info_vk.cc:138
impeller::DeviceTypeToString
constexpr const char * DeviceTypeToString(DeviceTypeVK type)
Definition: driver_info_vk.cc:75
impeller
Definition: aiks_blend_unittests.cc:18
impeller::ToDeviceType
constexpr DeviceTypeVK ToDeviceType(const vk::PhysicalDeviceType &type)
Definition: driver_info_vk.cc:91