[Impeller] Add WSI support for Vulkan on Linux and Windows (flutter/engine#36762)
There are additional instance extensions that need to be enabled for this. Having any one of them is sufficient on each of these platforms. There were also some `VALIDATION_LOG`s that would fail in the process of picking a valid physical device, this would incorrectly exit early when there were multiple devices and a latter device is valid. Also improves logging for playground when glfw fails to get a surface.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "flutter/fml/build_config.h"
|
||||
@@ -22,6 +23,17 @@ namespace fml {
|
||||
using Utf16StringConverter =
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>;
|
||||
|
||||
std::string Join(const std::vector<std::string>& vec, const char* delim) {
|
||||
std::stringstream res;
|
||||
for (size_t i = 0; i < vec.size(); ++i) {
|
||||
res << vec[i];
|
||||
if (i < vec.size() - 1) {
|
||||
res << delim;
|
||||
}
|
||||
}
|
||||
return res.str();
|
||||
}
|
||||
|
||||
std::string Utf16ToUtf8(const std::u16string_view string) {
|
||||
Utf16StringConverter converter;
|
||||
return converter.to_bytes(string.data());
|
||||
|
||||
@@ -6,9 +6,13 @@
|
||||
#define FLUTTER_FML_STRING_CONVERSION_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace fml {
|
||||
|
||||
// Returns a string joined by the given delimiter.
|
||||
std::string Join(const std::vector<std::string>& vec, const char* delimiter);
|
||||
|
||||
// Returns a UTF-8 encoded equivalent of a UTF-16 encoded input string.
|
||||
std::string Utf16ToUtf8(const std::u16string_view string);
|
||||
|
||||
|
||||
@@ -87,7 +87,13 @@ void PlaygroundImplVK::SetupSwapchain() {
|
||||
auto window = reinterpret_cast<GLFWwindow*>(handle_.get());
|
||||
vk::Instance instance = context_vk->GetInstance();
|
||||
VkSurfaceKHR surface_tmp;
|
||||
::glfwCreateWindowSurface(instance, window, nullptr, &surface_tmp);
|
||||
auto res = vk::Result{
|
||||
::glfwCreateWindowSurface(instance, window, nullptr, &surface_tmp)};
|
||||
if (res != vk::Result::eSuccess) {
|
||||
VALIDATION_LOG << "Could not create surface for GLFW window: "
|
||||
<< vk::to_string(res);
|
||||
return;
|
||||
}
|
||||
vk::UniqueSurfaceKHR surface{surface_tmp, instance};
|
||||
context_vk->SetupSwapchain(std::move(surface));
|
||||
}
|
||||
|
||||
@@ -8,8 +8,10 @@
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "flutter/fml/build_config.h"
|
||||
#include "flutter/fml/string_conversion.h"
|
||||
#include "flutter/fml/trace_event.h"
|
||||
#include "impeller/base/validation.h"
|
||||
#include "impeller/base/work_queue_common.h"
|
||||
@@ -32,6 +34,20 @@ static std::set<std::string> kRequiredDeviceExtensions = {
|
||||
#endif
|
||||
};
|
||||
|
||||
std::vector<std::string> kRequiredWSIInstanceExtensions = {
|
||||
#if FML_OS_WIN
|
||||
"VK_KHR_win32_surface",
|
||||
#elif FML_OS_ANDROID
|
||||
"VK_KHR_android_surface",
|
||||
#elif FML_OS_LINUX
|
||||
"VK_KHR_xcb_surface",
|
||||
"VK_KHR_xlib_surface",
|
||||
"VK_KHR_wayland_surface",
|
||||
#elif FML_OS_MACOSX
|
||||
"VK_EXT_metal_surface",
|
||||
#endif
|
||||
};
|
||||
|
||||
#if FML_OS_MACOSX
|
||||
static const char* MVK_MACOS_SURFACE_EXT = "VK_MVK_macos_surface";
|
||||
#endif
|
||||
@@ -50,17 +66,19 @@ static bool HasRequiredQueues(const vk::PhysicalDevice& device) {
|
||||
vk::QueueFlagBits::eTransfer));
|
||||
}
|
||||
|
||||
static bool HasRequiredExtensions(const vk::PhysicalDevice& device) {
|
||||
static std::vector<std::string> HasRequiredExtensions(
|
||||
const vk::PhysicalDevice& device) {
|
||||
std::set<std::string> exts;
|
||||
std::vector<std::string> missing;
|
||||
for (const auto& ext : device.enumerateDeviceExtensionProperties().value) {
|
||||
exts.insert(ext.extensionName);
|
||||
}
|
||||
for (const auto& req_ext : kRequiredDeviceExtensions) {
|
||||
if (exts.count(req_ext) != 1u) {
|
||||
return false;
|
||||
missing.push_back(req_ext);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return missing;
|
||||
}
|
||||
|
||||
static vk::PhysicalDeviceFeatures GetRequiredPhysicalDeviceFeatures() {
|
||||
@@ -80,15 +98,17 @@ static bool HasRequiredProperties(const vk::PhysicalDevice& device) {
|
||||
|
||||
static bool IsPhysicalDeviceCompatible(const vk::PhysicalDevice& device) {
|
||||
if (!HasRequiredQueues(device)) {
|
||||
VALIDATION_LOG << "Device doesn't have required queues.";
|
||||
FML_LOG(ERROR) << "Device doesn't have required queues.";
|
||||
return false;
|
||||
}
|
||||
if (!HasRequiredExtensions(device)) {
|
||||
VALIDATION_LOG << "Device doesn't have required extensions.";
|
||||
auto missing_exts = HasRequiredExtensions(device);
|
||||
if (!missing_exts.empty()) {
|
||||
FML_LOG(ERROR) << "Device doesn't have required extensions: "
|
||||
<< fml::Join(missing_exts, ", ");
|
||||
return false;
|
||||
}
|
||||
if (!HasRequiredProperties(device)) {
|
||||
VALIDATION_LOG << "Device doesn't have required properties.";
|
||||
FML_LOG(ERROR) << "Device doesn't have required properties.";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -251,6 +271,23 @@ ContextVK::ContextVK(
|
||||
}
|
||||
enabled_extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// Enable WSI Instance Extensions. Having any one of these is sufficient.
|
||||
///
|
||||
bool has_wsi_extensions = false;
|
||||
for (const auto& wsi_ext : kRequiredWSIInstanceExtensions) {
|
||||
if (capabilities->HasExtension(wsi_ext)) {
|
||||
enabled_extensions.push_back(wsi_ext.c_str());
|
||||
has_wsi_extensions = true;
|
||||
}
|
||||
}
|
||||
if (!has_wsi_extensions) {
|
||||
VALIDATION_LOG
|
||||
<< "Instance doesn't have any of the required WSI extensions: "
|
||||
<< fml::Join(kRequiredWSIInstanceExtensions, ", ");
|
||||
return;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// Enable any and all validation as well as debug toggles.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user