[Impeller] Allow identifying device driver and vendor information. (flutter/engine#51498)

Fixes https://github.com/flutter/flutter/issues/145119
This commit is contained in:
Chinmay Garde
2024-03-18 15:37:29 -07:00
committed by GitHub
parent cf0b9e869c
commit df4c56a538
13 changed files with 293 additions and 2 deletions

View File

@@ -174,6 +174,7 @@
../../../flutter/impeller/renderer/backend/vulkan/command_pool_vk_unittests.cc
../../../flutter/impeller/renderer/backend/vulkan/context_vk_unittests.cc
../../../flutter/impeller/renderer/backend/vulkan/descriptor_pool_vk_unittests.cc
../../../flutter/impeller/renderer/backend/vulkan/driver_info_vk_unittests.cc
../../../flutter/impeller/renderer/backend/vulkan/fence_waiter_vk_unittests.cc
../../../flutter/impeller/renderer/backend/vulkan/render_pass_cache_unittests.cc
../../../flutter/impeller/renderer/backend/vulkan/resource_manager_vk_unittests.cc

View File

@@ -39969,6 +39969,8 @@ ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/descriptor_pool_vk.h +
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/device_buffer_vk.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/device_buffer_vk.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/device_holder_vk.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/driver_info_vk.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/driver_info_vk.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/fence_waiter_vk.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/fence_waiter_vk.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/formats_vk.cc + ../../../flutter/LICENSE
@@ -42838,6 +42840,8 @@ FILE: ../../../flutter/impeller/renderer/backend/vulkan/descriptor_pool_vk.h
FILE: ../../../flutter/impeller/renderer/backend/vulkan/device_buffer_vk.cc
FILE: ../../../flutter/impeller/renderer/backend/vulkan/device_buffer_vk.h
FILE: ../../../flutter/impeller/renderer/backend/vulkan/device_holder_vk.h
FILE: ../../../flutter/impeller/renderer/backend/vulkan/driver_info_vk.cc
FILE: ../../../flutter/impeller/renderer/backend/vulkan/driver_info_vk.h
FILE: ../../../flutter/impeller/renderer/backend/vulkan/fence_waiter_vk.cc
FILE: ../../../flutter/impeller/renderer/backend/vulkan/fence_waiter_vk.h
FILE: ../../../flutter/impeller/renderer/backend/vulkan/formats_vk.cc

View File

@@ -28,7 +28,7 @@ struct Version {
static std::optional<Version> FromVector(const std::vector<size_t>& version);
constexpr bool IsAtLeast(const Version& other) {
constexpr bool IsAtLeast(const Version& other) const {
return std::tie(major_version, minor_version, patch_version) >=
std::tie(other.major_version, other.minor_version,
other.patch_version);

View File

@@ -67,6 +67,33 @@ class PlaygroundTest : public Playground,
return PlaygroundBackendToString(info.param); \
});
#define INSTANTIATE_METAL_PLAYGROUND_SUITE(playground) \
[[maybe_unused]] const char* kYouInstantiated##playground##MultipleTimes = \
""; \
INSTANTIATE_TEST_SUITE_P( \
Play, playground, ::testing::Values(PlaygroundBackend::kMetal), \
[](const ::testing::TestParamInfo<PlaygroundTest::ParamType>& info) { \
return PlaygroundBackendToString(info.param); \
});
#define INSTANTIATE_VULKAN_PLAYGROUND_SUITE(playground) \
[[maybe_unused]] const char* kYouInstantiated##playground##MultipleTimes = \
""; \
INSTANTIATE_TEST_SUITE_P( \
Play, playground, ::testing::Values(PlaygroundBackend::kVulkan), \
[](const ::testing::TestParamInfo<PlaygroundTest::ParamType>& info) { \
return PlaygroundBackendToString(info.param); \
});
#define INSTANTIATE_OPENGLES_PLAYGROUND_SUITE(playground) \
[[maybe_unused]] const char* kYouInstantiated##playground##MultipleTimes = \
""; \
INSTANTIATE_TEST_SUITE_P( \
Play, playground, ::testing::Values(PlaygroundBackend::kOpenGLES), \
[](const ::testing::TestParamInfo<PlaygroundTest::ParamType>& info) { \
return PlaygroundBackendToString(info.param); \
});
} // namespace impeller
#endif // FLUTTER_IMPELLER_PLAYGROUND_PLAYGROUND_TEST_H_

View File

@@ -14,6 +14,7 @@ impeller_component("vulkan_unittests") {
"command_pool_vk_unittests.cc",
"context_vk_unittests.cc",
"descriptor_pool_vk_unittests.cc",
"driver_info_vk_unittests.cc",
"fence_waiter_vk_unittests.cc",
"render_pass_cache_unittests.cc",
"resource_manager_vk_unittests.cc",
@@ -63,6 +64,8 @@ impeller_component("vulkan") {
"device_buffer_vk.cc",
"device_buffer_vk.h",
"device_holder_vk.h",
"driver_info_vk.cc",
"driver_info_vk.h",
"fence_waiter_vk.cc",
"fence_waiter_vk.h",
"formats_vk.cc",

View File

@@ -439,6 +439,8 @@ void ContextVK::Setup(Settings settings) {
/// All done!
///
device_holder_ = std::move(device_holder);
driver_info_ =
std::make_unique<DriverInfoVK>(device_holder_->physical_device);
debug_report_ = std::move(debug_report);
allocator_ = std::move(allocator);
shader_library_ = std::move(shader_library);
@@ -621,4 +623,8 @@ ContextVK::GetYUVConversionLibrary() const {
return yuv_conversion_library_;
}
const std::unique_ptr<DriverInfoVK>& ContextVK::GetDriverInfo() const {
return driver_info_;
}
} // namespace impeller

View File

@@ -15,6 +15,7 @@
#include "impeller/core/formats.h"
#include "impeller/renderer/backend/vulkan/command_pool_vk.h"
#include "impeller/renderer/backend/vulkan/device_holder_vk.h"
#include "impeller/renderer/backend/vulkan/driver_info_vk.h"
#include "impeller/renderer/backend/vulkan/pipeline_library_vk.h"
#include "impeller/renderer/backend/vulkan/queue_vk.h"
#include "impeller/renderer/backend/vulkan/sampler_library_vk.h"
@@ -138,6 +139,8 @@ class ContextVK final : public Context,
const vk::Device& GetDevice() const;
const std::unique_ptr<DriverInfoVK>& GetDriverInfo() const;
const std::shared_ptr<fml::ConcurrentTaskRunner>
GetConcurrentWorkerTaskRunner() const;
@@ -178,6 +181,7 @@ class ContextVK final : public Context,
};
std::shared_ptr<DeviceHolderImpl> device_holder_;
std::unique_ptr<DriverInfoVK> driver_info_;
std::unique_ptr<DebugReportVK> debug_report_;
std::shared_ptr<Allocator> allocator_;
std::shared_ptr<ShaderLibraryVK> shader_library_;

View File

@@ -0,0 +1,95 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "impeller/renderer/backend/vulkan/driver_info_vk.h"
namespace impeller {
constexpr VendorVK IdentifyVendor(uint32_t vendor) {
// Check if the vendor has a PCI ID:
// https://pcisig.com/membership/member-companies
switch (vendor) {
case 0x1AE0:
return VendorVK::kGoogle;
case 0x168C:
case 0x17CB:
case 0x1969:
case 0x5143:
return VendorVK::kQualcomm;
case 0x13B5:
return VendorVK::kARM;
case 0x1010:
return VendorVK::kImgTec;
case 0x1002:
case 0x1022:
return VendorVK::kAMD;
case 0x10DE:
return VendorVK::kNvidia;
case 0x8086: // :)
return VendorVK::kIntel;
case 0x106B:
return VendorVK::kApple;
}
// Check if the ID is a known Khronos vendor.
switch (vendor) {
case VK_VENDOR_ID_MESA:
return VendorVK::kMesa;
// There are others but have never been observed. These can be added as
// needed.
}
return VendorVK::kUnknown;
}
constexpr DeviceTypeVK ToDeviceType(const vk::PhysicalDeviceType& type) {
switch (type) {
case vk::PhysicalDeviceType::eOther:
return DeviceTypeVK::kUnknown;
case vk::PhysicalDeviceType::eIntegratedGpu:
return DeviceTypeVK::kIntegratedGPU;
case vk::PhysicalDeviceType::eDiscreteGpu:
return DeviceTypeVK::kDiscreteGPU;
case vk::PhysicalDeviceType::eVirtualGpu:
return DeviceTypeVK::kVirtualGPU;
case vk::PhysicalDeviceType::eCpu:
return DeviceTypeVK::kCPU;
break;
}
return DeviceTypeVK::kUnknown;
}
DriverInfoVK::DriverInfoVK(const vk::PhysicalDevice& device) {
auto props = device.getProperties();
api_version_ = Version{VK_API_VERSION_MAJOR(props.apiVersion),
VK_API_VERSION_MINOR(props.apiVersion),
VK_API_VERSION_PATCH(props.apiVersion)};
vendor_ = IdentifyVendor(props.vendorID);
if (vendor_ == VendorVK::kUnknown) {
FML_LOG(WARNING) << "Unknown GPU Driver Vendor: " << props.vendorID
<< ". This is not an error.";
}
type_ = ToDeviceType(props.deviceType);
if (props.deviceName.data() != nullptr) {
driver_name_ = props.deviceName.data();
}
}
DriverInfoVK::~DriverInfoVK() = default;
const Version& DriverInfoVK::GetAPIVersion() const {
return api_version_;
}
const VendorVK& DriverInfoVK::GetVendor() const {
return vendor_;
}
const DeviceTypeVK& DriverInfoVK::GetDeviceType() const {
return type_;
}
const std::string& DriverInfoVK::GetDriverName() const {
return driver_name_;
}
} // namespace impeller

View File

@@ -0,0 +1,120 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_DRIVER_INFO_VK_H_
#define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_DRIVER_INFO_VK_H_
#include "impeller/base/version.h"
#include "impeller/renderer/backend/vulkan/vk.h"
namespace impeller {
enum class VendorVK {
kUnknown,
//----------------------------------------------------------------------------
/// Includes the SwiftShader CPU implementation.
///
kGoogle,
kQualcomm,
kARM,
kImgTec,
kPowerVR = kImgTec,
kAMD,
kNvidia,
kIntel,
//----------------------------------------------------------------------------
/// Includes the LLVM Pipe CPU implementation.
///
kMesa,
//----------------------------------------------------------------------------
/// Includes Vulkan on Metal via MoltenVK.
///
kApple,
};
enum class DeviceTypeVK {
kUnknown,
//----------------------------------------------------------------------------
/// The device is an integrated GPU. Typically mobile GPUs.
///
kIntegratedGPU,
//----------------------------------------------------------------------------
/// The device is a discrete GPU. Typically desktop GPUs.
///
kDiscreteGPU,
//----------------------------------------------------------------------------
/// The device is a GPU in a virtualized environment.
///
kVirtualGPU,
//----------------------------------------------------------------------------
/// There is no GPU. Vulkan is implemented on the CPU. This is typically
/// emulators like SwiftShader and LLVMPipe.
///
kCPU,
};
//------------------------------------------------------------------------------
/// @brief Get information about the Vulkan driver.
///
/// @warning Be extremely cautious about the information reported here. This
/// is self-reported information (by the driver) and may be
/// inaccurate and or inconsistent.
///
/// Before gating features behind any of the information reported by
/// the driver, consider alternatives (extensions checks perhaps)
/// and try to get a reviewer buddy to convince you to avoid using
/// this.
///
class DriverInfoVK {
public:
explicit DriverInfoVK(const vk::PhysicalDevice& device);
~DriverInfoVK();
DriverInfoVK(const DriverInfoVK&) = delete;
DriverInfoVK& operator=(const DriverInfoVK&) = delete;
//----------------------------------------------------------------------------
/// @brief Gets the Vulkan API version. Should be at or above Vulkan 1.1
/// which is the Impeller baseline.
///
/// @return The Vulkan API version.
///
const Version& GetAPIVersion() const;
//----------------------------------------------------------------------------
/// @brief Get the vendor of the Vulkan implementation. This is a broad
/// check and includes multiple drivers and platforms.
///
/// @return The vendor.
///
const VendorVK& GetVendor() const;
//----------------------------------------------------------------------------
/// @brief Get the device type. Typical use might be to check if the
/// device is a CPU implementation.
///
/// @return The device type.
///
const DeviceTypeVK& GetDeviceType() const;
//----------------------------------------------------------------------------
/// @brief Get the self-reported name of the graphics driver.
///
/// @return The driver name.
///
const std::string& GetDriverName() const;
private:
bool is_valid_ = false;
Version api_version_;
VendorVK vendor_ = VendorVK::kUnknown;
DeviceTypeVK type_ = DeviceTypeVK::kUnknown;
std::string driver_name_;
};
} // namespace impeller
#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_DRIVER_INFO_VK_H_

View File

@@ -0,0 +1,26 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "impeller/playground/playground_test.h"
#include "impeller/renderer/backend/vulkan/context_vk.h"
#include "impeller/renderer/backend/vulkan/surface_context_vk.h"
namespace impeller::testing {
using DriverInfoVKTest = PlaygroundTest;
INSTANTIATE_VULKAN_PLAYGROUND_SUITE(DriverInfoVKTest);
TEST_P(DriverInfoVKTest, CanQueryDriverInfo) {
ASSERT_TRUE(GetContext());
const auto& driver_info =
SurfaceContextVK::Cast(*GetContext()).GetParent().GetDriverInfo();
ASSERT_NE(driver_info, nullptr);
// 1.1 is the base Impeller version. The driver can't be lower than that.
ASSERT_TRUE(driver_info->GetAPIVersion().IsAtLeast(Version{1, 1, 0}));
ASSERT_NE(driver_info->GetVendor(), VendorVK::kUnknown);
ASSERT_NE(driver_info->GetDeviceType(), DeviceTypeVK::kUnknown);
ASSERT_NE(driver_info->GetDriverName(), "");
}
} // namespace impeller::testing

View File

@@ -127,4 +127,8 @@ void SurfaceContextVK::InitializeCommonlyUsedShadersIfNeeded() const {
parent_->InitializeCommonlyUsedShadersIfNeeded();
}
const ContextVK& SurfaceContextVK::GetParent() const {
return *parent_;
}
} // namespace impeller

View File

@@ -86,6 +86,8 @@ class SurfaceContextVK : public Context,
const vk::Device& GetDevice() const;
const ContextVK& GetParent() const;
private:
std::shared_ptr<ContextVK> parent_;
std::shared_ptr<KHRSwapchainVK> swapchain_;

View File

@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "flutter/fml/logging.h"
#include "impeller/core/device_buffer_descriptor.h"
#include "impeller/core/formats.h"
#include "impeller/core/host_buffer.h"