|
4 | 4 |
|
5 | 5 | #include "impeller/renderer/backend/vulkan/driver_info_vk.h" |
6 | 6 |
|
| 7 | +#include <iomanip> |
| 8 | +#include <sstream> |
| 9 | + |
| 10 | +#include "flutter/fml/build_config.h" |
| 11 | + |
7 | 12 | namespace impeller { |
8 | 13 |
|
9 | 14 | constexpr VendorVK IdentifyVendor(uint32_t vendor) { |
@@ -41,6 +46,48 @@ constexpr VendorVK IdentifyVendor(uint32_t vendor) { |
41 | 46 | return VendorVK::kUnknown; |
42 | 47 | } |
43 | 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 | + |
44 | 91 | constexpr DeviceTypeVK ToDeviceType(const vk::PhysicalDeviceType& type) { |
45 | 92 | switch (type) { |
46 | 93 | case vk::PhysicalDeviceType::eOther: |
@@ -92,4 +139,49 @@ const std::string& DriverInfoVK::GetDriverName() const { |
92 | 139 | return driver_name_; |
93 | 140 | } |
94 | 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 | + |
95 | 187 | } // namespace impeller |
0 commit comments