Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions impeller/renderer/backend/vulkan/driver_info_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

#include "impeller/renderer/backend/vulkan/driver_info_vk.h"

#include <iomanip>
#include <sstream>

#include "flutter/fml/build_config.h"

namespace impeller {

constexpr VendorVK IdentifyVendor(uint32_t vendor) {
Expand Down Expand Up @@ -41,6 +46,48 @@ constexpr VendorVK IdentifyVendor(uint32_t vendor) {
return VendorVK::kUnknown;
}

constexpr const char* VendorToString(VendorVK vendor) {
switch (vendor) {
case VendorVK::kUnknown:
return "Unknown";
case VendorVK::kGoogle:
return "Google";
case VendorVK::kQualcomm:
return "Qualcomm";
case VendorVK::kARM:
return "ARM";
case VendorVK::kImgTec:
return "ImgTec PowerVR";
case VendorVK::kAMD:
return "AMD";
case VendorVK::kNvidia:
return "Nvidia";
case VendorVK::kIntel:
return "Intel";
case VendorVK::kMesa:
return "Mesa";
case VendorVK::kApple:
return "Apple";
}
FML_UNREACHABLE();
}

constexpr const char* DeviceTypeToString(DeviceTypeVK type) {
switch (type) {
case DeviceTypeVK::kUnknown:
return "Unknown";
case DeviceTypeVK::kIntegratedGPU:
return "Integrated GPU";
case DeviceTypeVK::kDiscreteGPU:
return "Discrete GPU";
case DeviceTypeVK::kVirtualGPU:
return "Virtual GPU";
case DeviceTypeVK::kCPU:
return "CPU";
}
FML_UNREACHABLE();
}

constexpr DeviceTypeVK ToDeviceType(const vk::PhysicalDeviceType& type) {
switch (type) {
case vk::PhysicalDeviceType::eOther:
Expand Down Expand Up @@ -92,4 +139,49 @@ const std::string& DriverInfoVK::GetDriverName() const {
return driver_name_;
}

void DriverInfoVK::DumpToLog() const {
std::vector<std::pair<std::string, std::string>> items;
items.emplace_back("Name", driver_name_);
items.emplace_back("API Version", api_version_.ToString());
items.emplace_back("Vendor", VendorToString(vendor_));
items.emplace_back("Device Type", DeviceTypeToString(type_));
items.emplace_back("Is Emulator", std::to_string(IsEmulator()));

size_t padding = 0;

for (const auto& item : items) {
padding = std::max(padding, item.first.size());
}

padding += 1;

std::stringstream stream;

stream << std::endl;

stream << "--- Driver Information ------------------------------------------";

stream << std::endl;

for (const auto& item : items) {
stream << "| " << std::setw(static_cast<int>(padding)) << item.first
<< std::setw(0) << ": " << item.second << std::endl;
}

stream << "-----------------------------------------------------------------";

FML_LOG(IMPORTANT) << stream.str();
}

bool DriverInfoVK::IsEmulator() const {
#if FML_OS_ANDROID
// Google SwiftShader on Android.
if (type_ == DeviceTypeVK::kCPU && vendor_ == VendorVK::kGoogle &&
driver_name_.find("SwiftShader") != std::string::npos) {
return true;
}
#endif // FML_OS_ANDROID
return false;
}

} // namespace impeller
15 changes: 15 additions & 0 deletions impeller/renderer/backend/vulkan/driver_info_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ class DriverInfoVK {
///
const std::string& GetDriverName() const;

//----------------------------------------------------------------------------
/// @brief Dumps the current driver info to the log.
///
void DumpToLog() const;

//----------------------------------------------------------------------------
/// @brief Determines if the driver represents an emulator. There is no
/// definitive way to tell if a driver is an emulator and drivers
/// don't self identify as emulators. So take this information
/// with a pinch of salt.
///
/// @return True if emulator, False otherwise.
///
bool IsEmulator() const;

private:
bool is_valid_ = false;
Version api_version_;
Expand Down
10 changes: 10 additions & 0 deletions impeller/renderer/backend/vulkan/driver_info_vk_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,14 @@ TEST_P(DriverInfoVKTest, CanQueryDriverInfo) {
ASSERT_NE(driver_info->GetDriverName(), "");
}

TEST_P(DriverInfoVKTest, CanDumpToLog) {
ASSERT_TRUE(GetContext());
const auto& driver_info =
SurfaceContextVK::Cast(*GetContext()).GetParent().GetDriverInfo();
ASSERT_NE(driver_info, nullptr);
fml::testing::LogCapture log;
driver_info->DumpToLog();
ASSERT_TRUE(log.str().find("Driver Information") != std::string::npos);
}

} // namespace impeller::testing