10#include "flutter/vulkan/procs/vulkan_proc_table.h"
18 const std::string& application_name,
19 std::vector<std::string> enabled_extensions,
20 uint32_t application_version,
22 bool enable_validation_layers)
24 api_version_(api_version),
26 enable_validation_layers_(enable_validation_layers) {
28 std::vector<VkExtensionProperties> supported_extensions =
29 GetSupportedInstanceExtensions(vk_);
30 bool enable_instance_debugging =
31 enable_validation_layers_ &&
32 ExtensionSupported(supported_extensions,
37 if (enable_instance_debugging) {
41 if (ExtensionSupported(supported_extensions,
46 enabled_extensions.emplace_back(
48 enabled_extensions.emplace_back(
55 for (
size_t i = 0;
i < enabled_extensions.size();
i++) {
56 extensions.push_back(enabled_extensions[
i].c_str());
61 const std::vector<std::string> enabled_layers =
64 std::vector<const char*> layers;
66 for (
size_t i = 0;
i < enabled_layers.size();
i++) {
67 layers.push_back(enabled_layers[
i].c_str());
75 .pApplicationName = application_name.c_str(),
76 .applicationVersion = application_version,
77 .pEngineName =
"FlutterEngine",
79 .apiVersion = api_version_,
86 .pApplicationInfo = &
info,
87 .enabledLayerCount =
static_cast<uint32_t
>(layers.size()),
88 .ppEnabledLayerNames = layers.data(),
89 .enabledExtensionCount =
static_cast<uint32_t
>(
extensions.size()),
99 FML_DLOG(INFO) <<
"Could not create application instance.";
105 FML_DLOG(INFO) <<
"Could not set up instance proc addresses.";
111 <<
"Destroying Vulkan instance";
112 vk_.DestroyInstance(
i,
nullptr);
115 if (enable_instance_debugging) {
116 auto debug_report = std::make_unique<VulkanDebugReport>(vk_, instance_);
117 if (!debug_report->IsValid()) {
118 FML_DLOG(INFO) <<
"Vulkan debugging was enabled but could not be set up "
119 "for this instance.";
121 debug_report_ = std::move(debug_report);
122 FML_DLOG(INFO) <<
"Debug reporting is enabled.";
147std::vector<VkPhysicalDevice> VulkanApplication::GetPhysicalDevices()
const {
152 uint32_t device_count = 0;
155 FML_DLOG(INFO) <<
"Could not enumerate physical device.";
159 if (device_count == 0) {
161 FML_DLOG(INFO) <<
"No physical devices found.";
165 std::vector<VkPhysicalDevice> physical_devices;
167 physical_devices.resize(device_count);
170 instance_, &device_count, physical_devices.data())) !=
VK_SUCCESS) {
171 FML_DLOG(INFO) <<
"Could not enumerate physical device.";
175 return physical_devices;
178std::unique_ptr<VulkanDevice>
180 for (
auto device_handle : GetPhysicalDevices()) {
181 auto logical_device = std::make_unique<VulkanDevice>(
183 enable_validation_layers_);
184 if (logical_device->IsValid()) {
185 return logical_device;
188 FML_DLOG(INFO) <<
"Could not acquire compatible logical device.";
192std::vector<VkExtensionProperties>
193VulkanApplication::GetSupportedInstanceExtensions(
195 if (!
vk.EnumerateInstanceExtensionProperties) {
196 return std::vector<VkExtensionProperties>();
202 return std::vector<VkExtensionProperties>();
206 return std::vector<VkExtensionProperties>();
209 std::vector<VkExtensionProperties> properties;
210 properties.resize(
count);
213 return std::vector<VkExtensionProperties>();
219bool VulkanApplication::ExtensionSupported(
220 const std::vector<VkExtensionProperties>& supported_instance_extensions,
221 const std::string& extension_name) {
222 uint32_t
count = supported_instance_extensions.size();
223 for (
size_t i = 0;
i <
count;
i++) {
224 if (strncmp(supported_instance_extensions[
i].extensionName,
225 extension_name.c_str(), extension_name.size()) == 0) {
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
const VulkanHandle< VkInstance > & GetInstance() const
std::unique_ptr< VulkanDevice > AcquireFirstCompatibleLogicalDevice() const
uint32_t GetAPIVersion() const
void ReleaseInstanceOwnership()
VulkanApplication(VulkanProcTable &vk, const std::string &application_name, std::vector< std::string > enabled_extensions, uint32_t application_version=VK_MAKE_VERSION(1, 0, 0), uint32_t api_version=VK_MAKE_VERSION(1, 0, 0), bool enable_validation_layers=false)
static std::string DebugExtensionName()
bool SetupInstanceProcAddresses(const VulkanHandle< VkInstance > &instance)
#define FML_DLOG(severity)
std::vector< std::string > InstanceLayersToEnable(const VulkanProcTable &vk, bool enable_validation_layers)
#define VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME
#define VK_MAKE_VERSION(major, minor, patch)
#define VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME
@ VK_STRUCTURE_TYPE_APPLICATION_INFO
@ VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
#define VK_CALL_LOG_ERROR(expression)