From 19f8afc6bc0e39abe3c88263e517becb5f752088 Mon Sep 17 00:00:00 2001 From: egdaniel Date: Wed, 14 Oct 2020 16:55:09 -0400 Subject: [PATCH] Update flutter to pass Skia the VkImageUsageFlags and Samples (flutter/engine#21842) Previously Skia did not require the clients to pass in the usage flags and Skia would just assumed they contained specific ones depending on how the client wrapped the VkImage. Now Skia allows the client to pass in the specific usage flags used so that Skia knows exactly what type of operations are legal without having to guess/assume what the client did. Also update to set the sample count as well while I'm in here. --- .../fuchsia/flutter/vulkan_surface.cc | 2 ++ engine/src/flutter/vulkan/vulkan_swapchain.cc | 19 ++++++++++++++----- engine/src/flutter/vulkan/vulkan_swapchain.h | 4 +++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface.cc index ba697d9153..a28b4dad72 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface.cc @@ -344,6 +344,8 @@ bool VulkanSurface::SetupSkiaSurface(sk_sp context, image_info.fImageTiling = image_create_info.tiling; image_info.fImageLayout = image_create_info.initialLayout; image_info.fFormat = image_create_info.format; + image_info.fImageUsageFlags = image_create_info.usage; + image_info.fSampleCount = 1; image_info.fLevelCount = image_create_info.mipLevels; GrBackendRenderTarget sk_render_target(size.width(), size.height(), 0, diff --git a/engine/src/flutter/vulkan/vulkan_swapchain.cc b/engine/src/flutter/vulkan/vulkan_swapchain.cc index 888c1a74f6..fbea31386e 100644 --- a/engine/src/flutter/vulkan/vulkan_swapchain.cc +++ b/engine/src/flutter/vulkan/vulkan_swapchain.cc @@ -113,6 +113,10 @@ VulkanSwapchain::VulkanSwapchain(const VulkanProcTable& p_vk, VkSurfaceKHR surface_handle = surface.Handle(); + VkImageUsageFlags usage_flags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | + VK_IMAGE_USAGE_TRANSFER_SRC_BIT | + VK_IMAGE_USAGE_TRANSFER_DST_BIT; + const VkSwapchainCreateInfoKHR create_info = { .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, .pNext = nullptr, @@ -123,7 +127,7 @@ VulkanSwapchain::VulkanSwapchain(const VulkanProcTable& p_vk, .imageColorSpace = surface_format_.colorSpace, .imageExtent = capabilities_.currentExtent, .imageArrayLayers = 1, - .imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, + .imageUsage = usage_flags, .imageSharingMode = VK_SHARING_MODE_EXCLUSIVE, .queueFamilyIndexCount = 0, // Because of the exclusive sharing mode. .pQueueFamilyIndices = nullptr, @@ -151,7 +155,8 @@ VulkanSwapchain::VulkanSwapchain(const VulkanProcTable& p_vk, if (!CreateSwapchainImages(skia_context, format_infos[format_index].color_type_, - format_infos[format_index].color_space_)) { + format_infos[format_index].color_space_, + usage_flags)) { FML_DLOG(INFO) << "Could not create swapchain images."; return; } @@ -210,6 +215,7 @@ SkISize VulkanSwapchain::GetSize() const { sk_sp VulkanSwapchain::CreateSkiaSurface( GrDirectContext* gr_context, VkImage image, + VkImageUsageFlags usage_flags, const SkISize& size, SkColorType color_type, sk_sp color_space) const { @@ -227,6 +233,8 @@ sk_sp VulkanSwapchain::CreateSkiaSurface( image_info.fImageTiling = VK_IMAGE_TILING_OPTIMAL; image_info.fImageLayout = VK_IMAGE_LAYOUT_UNDEFINED; image_info.fFormat = surface_format_.format; + image_info.fImageUsageFlags = usage_flags; + image_info.fSampleCount = 1; image_info.fLevelCount = 1; // TODO(chinmaygarde): Setup the stencil buffer and the sampleCnt. @@ -246,7 +254,8 @@ sk_sp VulkanSwapchain::CreateSkiaSurface( bool VulkanSwapchain::CreateSwapchainImages(GrDirectContext* skia_context, SkColorType color_type, - sk_sp color_space) { + sk_sp color_space, + VkImageUsageFlags usage_flags) { std::vector images = GetImages(); if (images.size() == 0) { @@ -276,8 +285,8 @@ bool VulkanSwapchain::CreateSwapchainImages(GrDirectContext* skia_context, images_.emplace_back(std::move(vulkan_image)); // Populate the surface. - auto surface = CreateSkiaSurface(skia_context, image, surface_size, - color_type, color_space); + auto surface = CreateSkiaSurface(skia_context, image, usage_flags, + surface_size, color_type, color_space); if (surface == nullptr) { return false; diff --git a/engine/src/flutter/vulkan/vulkan_swapchain.h b/engine/src/flutter/vulkan/vulkan_swapchain.h index 570cbb1092..9c8fc6717e 100644 --- a/engine/src/flutter/vulkan/vulkan_swapchain.h +++ b/engine/src/flutter/vulkan/vulkan_swapchain.h @@ -79,10 +79,12 @@ class VulkanSwapchain { bool CreateSwapchainImages(GrDirectContext* skia_context, SkColorType color_type, - sk_sp color_space); + sk_sp color_space, + VkImageUsageFlags usage_flags); sk_sp CreateSkiaSurface(GrDirectContext* skia_context, VkImage image, + VkImageUsageFlags usage_flags, const SkISize& size, SkColorType color_type, sk_sp color_space) const;