11#include "flutter/vulkan/procs/vulkan_proc_table.h"
19 std::numeric_limits<uint32_t>::max();
22 const std::vector<VkQueueFamilyProperties>& properties) {
23 for (uint32_t i = 0,
count =
static_cast<uint32_t
>(properties.size());
34 bool enable_validation_layers)
37 graphics_queue_index_(
std::numeric_limits<uint32_t>::
max()),
46 FML_DLOG(INFO) <<
"Could not find the graphics queue index.";
50 const float priorities[1] = {1.0f};
56 .queueFamilyIndex = graphics_queue_index_,
58 .pQueuePriorities = priorities,
61 const char* extensions[] = {
69 VK_FUCHSIA_EXTERNAL_MEMORY_EXTENSION_NAME,
70 VK_FUCHSIA_EXTERNAL_SEMAPHORE_EXTENSION_NAME,
71 VK_FUCHSIA_BUFFER_COLLECTION_EXTENSION_NAME,
78 std::vector<const char*> layers;
80 for (
size_t i = 0; i < enabled_layers.size(); i++) {
81 layers.push_back(enabled_layers[i].c_str());
88 .queueCreateInfoCount = 1,
89 .pQueueCreateInfos = &queue_create,
90 .enabledLayerCount =
static_cast<uint32_t
>(layers.size()),
91 .ppEnabledLayerNames = layers.data(),
92 .enabledExtensionCount =
sizeof(extensions) /
sizeof(
const char*),
93 .ppEnabledExtensionNames = extensions,
94 .pEnabledFeatures =
nullptr,
101 FML_DLOG(INFO) <<
"Could not create device.";
109 FML_DLOG(INFO) <<
"Could not set up device proc addresses.";
115 vk_.GetDeviceQueue(device_, graphics_queue_index_, 0, &
queue);
118 FML_DLOG(INFO) <<
"Could not get the device queue handle.";
124 if (!InitializeCommandPool()) {
146 if (!InitializeCommandPool()) {
153bool VulkanDevice::InitializeCommandPool() {
158 .queueFamilyIndex = 0,
163 device_, &command_pool_create_info,
nullptr, &command_pool)) !=
165 FML_DLOG(INFO) <<
"Could not create the command pool.";
169 command_pool_ = VulkanHandle<VkCommandPool>{
170 command_pool, [
this](VkCommandPool
pool) {
171 vk_.DestroyCommandPool(device_,
pool,
nullptr);
199 return physical_device_;
207 return command_pool_;
211 return graphics_queue_index_;
218 if (!
surface.IsValid() || capabilities ==
nullptr) {
240 if (size.width() == 0 || size.height() == 0) {
254 if (features ==
nullptr || !physical_device_) {
257 vk_.GetPhysicalDeviceFeatures(physical_device_, features);
262 if (sk_features ==
nullptr) {
284 *sk_features =
flags;
288std::vector<VkQueueFamilyProperties> VulkanDevice::GetQueueFamilyProperties()
292 vk_.GetPhysicalDeviceQueueFamilyProperties(physical_device_, &
count,
nullptr);
294 std::vector<VkQueueFamilyProperties> properties;
295 properties.resize(
count, {});
297 vk_.GetPhysicalDeviceQueueFamilyProperties(physical_device_, &
count,
305 const std::vector<VkFormat>& desired_formats,
312 uint32_t format_count = 0;
314 physical_device_,
surface.
Handle(), &format_count,
nullptr)) !=
319 if (format_count == 0) {
323 std::vector<VkSurfaceFormatKHR> formats;
324 formats.resize(format_count);
327 physical_device_,
surface.
Handle(), &format_count, formats.data())) !=
332 std::map<VkFormat, VkSurfaceFormatKHR> supported_formats;
333 for (uint32_t i = 0; i < format_count; i++) {
334 supported_formats[formats[i].format] = formats[i];
338 for (
size_t i = 0; i < desired_formats.size(); ++i) {
339 auto found = supported_formats.find(desired_formats[i]);
340 if (found != supported_formats.end()) {
342 return static_cast<int>(i);
351 if (!
surface.IsValid() || present_mode ==
nullptr) {
370 std::vector<VkPipelineStageFlags> wait_dest_pipeline_stages,
371 const std::vector<VkSemaphore>& wait_semaphores,
372 const std::vector<VkSemaphore>& signal_semaphores,
373 const std::vector<VkCommandBuffer>& command_buffers,
375 if (wait_semaphores.size() != wait_dest_pipeline_stages.size()) {
382 .waitSemaphoreCount =
static_cast<uint32_t
>(wait_semaphores.size()),
383 .pWaitSemaphores = wait_semaphores.data(),
384 .pWaitDstStageMask = wait_dest_pipeline_stages.data(),
385 .commandBufferCount =
static_cast<uint32_t
>(command_buffers.size()),
386 .pCommandBuffers = command_buffers.data(),
387 .signalSemaphoreCount =
static_cast<uint32_t
>(signal_semaphores.size()),
388 .pSignalSemaphores = signal_semaphores.data(),
@ kSampleRateShading_GrVkFeatureFlag
@ kDualSrcBlend_GrVkFeatureFlag
@ kGeometryShader_GrVkFeatureFlag
VulkanDevice(VulkanProcTable &vk, VulkanHandle< VkPhysicalDevice > physical_device, bool enable_validation_layers)
Create a new VkDevice with a resolved VkQueue suitable for rendering with Skia.
const VulkanHandle< VkQueue > & GetQueueHandle() const
const VulkanHandle< VkPhysicalDevice > & GetPhysicalDeviceHandle() const
bool ChoosePresentMode(const VulkanSurface &surface, VkPresentModeKHR *present_mode) const
bool QueueSubmit(std::vector< VkPipelineStageFlags > wait_dest_pipeline_stages, const std::vector< VkSemaphore > &wait_semaphores, const std::vector< VkSemaphore > &signal_semaphores, const std::vector< VkCommandBuffer > &command_buffers, const VulkanHandle< VkFence > &fence) const
bool GetSurfaceCapabilities(const VulkanSurface &surface, VkSurfaceCapabilitiesKHR *capabilities) const
const VulkanHandle< VkDevice > & GetHandle() const
void ReleaseDeviceOwnership()
bool GetPhysicalDeviceFeaturesSkia(uint32_t *features) const
int ChooseSurfaceFormat(const VulkanSurface &surface, const std::vector< VkFormat > &desired_formats, VkSurfaceFormatKHR *format) const
bool GetPhysicalDeviceFeatures(VkPhysicalDeviceFeatures *features) const
const VulkanHandle< VkCommandPool > & GetCommandPool() const
uint32_t GetGraphicsQueueIndex() const
bool AreInstanceProcsSetup() const
bool SetupDeviceProcAddresses(const VulkanHandle< VkDevice > &device)
VkPhysicalDevice physical_device
uint32_t queue_family_index
FlutterSemanticsFlag flags
uint32_t uint32_t * format
#define FML_ALLOW_UNUSED_LOCAL(x)
#define FML_DLOG(severity)
static float max(float r, float g, float b)
static uint32_t FindGraphicsQueueIndex(const std::vector< VkQueueFamilyProperties > &properties)
constexpr auto kVulkanInvalidGraphicsQueueIndex
std::vector< std::string > DeviceLayersToEnable(const VulkanProcTable &vk, const VulkanHandle< VkPhysicalDevice > &physical_device, bool enable_validation_layers)
VkBool32 sampleRateShading
#define VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME
#define VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME
#define VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME
@ VK_PRESENT_MODE_FIFO_KHR
@ VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT
#define VK_KHR_SWAPCHAIN_EXTENSION_NAME
@ VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO
@ VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
@ VK_STRUCTURE_TYPE_SUBMIT_INFO
@ VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO
#define VK_CALL_LOG_ERROR(expression)