Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
vulkan::VulkanApplication Class Reference

#include <vulkan_application.h>

Public Member Functions

 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)
 
 ~VulkanApplication ()
 
bool IsValid () const
 
uint32_t GetAPIVersion () const
 
const VulkanHandle< VkInstance > & GetInstance () const
 
void ReleaseInstanceOwnership ()
 
std::unique_ptr< VulkanDeviceAcquireFirstCompatibleLogicalDevice () const
 

Detailed Description

Applications using Vulkan acquire a VulkanApplication that attempts to create a VkInstance (with debug reporting optionally enabled).

Definition at line 25 of file vulkan_application.h.

Constructor & Destructor Documentation

◆ VulkanApplication()

vulkan::VulkanApplication::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 
)

Definition at line 16 of file vulkan_application.cc.

23 : vk_(p_vk),
24 api_version_(api_version),
25 valid_(false),
26 enable_validation_layers_(enable_validation_layers) {
27 // Check if we want to enable debugging.
28 std::vector<VkExtensionProperties> supported_extensions =
29 GetSupportedInstanceExtensions(vk_);
30 bool enable_instance_debugging =
31 enable_validation_layers_ &&
32 ExtensionSupported(supported_extensions,
34
35 // Configure extensions.
36
37 if (enable_instance_debugging) {
38 enabled_extensions.emplace_back(VulkanDebugReport::DebugExtensionName());
39 }
40#if OS_FUCHSIA
41 if (ExtensionSupported(supported_extensions,
43 // VK_KHR_get_physical_device_properties2 is a dependency of the memory
44 // capabilities extension, so the validation layers require that it be
45 // enabled.
46 enabled_extensions.emplace_back(
48 enabled_extensions.emplace_back(
50 }
51#endif
52
53 std::vector<const char*> extensions;
54
55 for (size_t i = 0; i < enabled_extensions.size(); i++) {
56 extensions.push_back(enabled_extensions[i].c_str());
57 }
58
59 // Configure layers.
60
61 const std::vector<std::string> enabled_layers =
62 InstanceLayersToEnable(vk_, enable_validation_layers_);
63
64 std::vector<const char*> layers;
65
66 for (size_t i = 0; i < enabled_layers.size(); i++) {
67 layers.push_back(enabled_layers[i].c_str());
68 }
69
70 // Configure init structs.
71
72 const VkApplicationInfo info = {
74 .pNext = nullptr,
75 .pApplicationName = application_name.c_str(),
76 .applicationVersion = application_version,
77 .pEngineName = "FlutterEngine",
78 .engineVersion = VK_MAKE_VERSION(1, 0, 0),
79 .apiVersion = api_version_,
80 };
81
82 const VkInstanceCreateInfo create_info = {
84 .pNext = nullptr,
85 .flags = 0,
86 .pApplicationInfo = &info,
87 .enabledLayerCount = static_cast<uint32_t>(layers.size()),
88 .ppEnabledLayerNames = layers.data(),
89 .enabledExtensionCount = static_cast<uint32_t>(extensions.size()),
90 .ppEnabledExtensionNames = extensions.data(),
91 };
92
93 // Perform initialization.
94
95 VkInstance instance = VK_NULL_HANDLE;
96
97 if (VK_CALL_LOG_ERROR(vk_.CreateInstance(&create_info, nullptr, &instance)) !=
98 VK_SUCCESS) {
99 FML_DLOG(INFO) << "Could not create application instance.";
100 return;
101 }
102
103 // Now that we have an instance, set up instance proc table entries.
104 if (!vk_.SetupInstanceProcAddresses(VulkanHandle<VkInstance>(instance))) {
105 FML_DLOG(INFO) << "Could not set up instance proc addresses.";
106 return;
107 }
108
109 instance_ = VulkanHandle<VkInstance>{instance, [this](VkInstance i) {
110 FML_DLOG(INFO)
111 << "Destroying Vulkan instance";
112 vk_.DestroyInstance(i, nullptr);
113 }};
114
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.";
120 } else {
121 debug_report_ = std::move(debug_report);
122 FML_DLOG(INFO) << "Debug reporting is enabled.";
123 }
124 }
125
126 valid_ = true;
127}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static std::string DebugExtensionName()
bool SetupInstanceProcAddresses(const VulkanHandle< VkInstance > &instance)
VkInstance instance
Definition: main.cc:48
#define FML_DLOG(severity)
Definition: logging.h:102
std::vector< std::string > InstanceLayersToEnable(const VulkanProcTable &vk, bool enable_validation_layers)
VkStructureType sType
Definition: vulkan_core.h:3027
#define VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME
Definition: vulkan_core.h:8673
#define VK_MAKE_VERSION(major, minor, patch)
Definition: vulkan_core.h:78
#define VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME
Definition: vulkan_core.h:8511
@ VK_SUCCESS
Definition: vulkan_core.h:141
#define VK_NULL_HANDLE
Definition: vulkan_core.h:46
@ VK_STRUCTURE_TYPE_APPLICATION_INFO
Definition: vulkan_core.h:202
@ VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
Definition: vulkan_core.h:203
#define VK_CALL_LOG_ERROR(expression)

◆ ~VulkanApplication()

vulkan::VulkanApplication::~VulkanApplication ( )
default

Member Function Documentation

◆ AcquireFirstCompatibleLogicalDevice()

std::unique_ptr< VulkanDevice > vulkan::VulkanApplication::AcquireFirstCompatibleLogicalDevice ( ) const

Definition at line 179 of file vulkan_application.cc.

179 {
180 for (auto device_handle : GetPhysicalDevices()) {
181 auto logical_device = std::make_unique<VulkanDevice>(
182 vk_, VulkanHandle<VkPhysicalDevice>(device_handle),
183 enable_validation_layers_);
184 if (logical_device->IsValid()) {
185 return logical_device;
186 }
187 }
188 FML_DLOG(INFO) << "Could not acquire compatible logical device.";
189 return nullptr;
190}

◆ GetAPIVersion()

uint32_t vulkan::VulkanApplication::GetAPIVersion ( ) const

Definition at line 135 of file vulkan_application.cc.

135 {
136 return api_version_;
137}

◆ GetInstance()

const VulkanHandle< VkInstance > & vulkan::VulkanApplication::GetInstance ( ) const

Definition at line 139 of file vulkan_application.cc.

139 {
140 return instance_;
141}

◆ IsValid()

bool vulkan::VulkanApplication::IsValid ( ) const

Definition at line 131 of file vulkan_application.cc.

131 {
132 return valid_;
133}

◆ ReleaseInstanceOwnership()

void vulkan::VulkanApplication::ReleaseInstanceOwnership ( )

Definition at line 143 of file vulkan_application.cc.

143 {
144 instance_.ReleaseOwnership();
145}

The documentation for this class was generated from the following files: