Remove unnecessary buffer collection image constraints. (flutter/engine#24347)

This commit is contained in:
David Reveman 2021-02-11 18:56:02 -05:00 committed by GitHub
parent 61aba2ec6d
commit 3d688d6424
3 changed files with 17 additions and 47 deletions

View File

@ -27,19 +27,12 @@ namespace flutter_runner {
namespace {
constexpr SkColorType kSkiaColorType = kRGBA_8888_SkColorType;
constexpr fuchsia::sysmem::PixelFormatType kSysmemPixelFormat =
fuchsia::sysmem::PixelFormatType::R8G8B8A8;
constexpr VkFormat kVulkanFormat = VK_FORMAT_R8G8B8A8_UNORM;
constexpr VkImageCreateFlags kVulkanImageCreateFlags = 0;
// TODO: We should only keep usages that are actually required by Skia.
constexpr VkImageUsageFlags kVkImageUsage =
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
constexpr uint32_t kSysmemImageUsage =
fuchsia::sysmem::VULKAN_IMAGE_USAGE_COLOR_ATTACHMENT |
fuchsia::sysmem::VULKAN_IMAGE_USAGE_TRANSFER_DST |
fuchsia::sysmem::VULKAN_IMAGE_USAGE_TRANSFER_SRC |
fuchsia::sysmem::VULKAN_IMAGE_USAGE_SAMPLED;
} // namespace
@ -233,50 +226,19 @@ bool VulkanSurface::AllocateDeviceMemory(
return false;
}
fuchsia::sysmem::BufferCollectionTokenSyncPtr local_token;
fuchsia::sysmem::BufferCollectionTokenSyncPtr vulkan_token;
zx_status_t status =
sysmem_allocator->AllocateSharedCollection(local_token.NewRequest());
sysmem_allocator->AllocateSharedCollection(vulkan_token.NewRequest());
LOG_AND_RETURN(status != ZX_OK, "Failed to allocate collection");
fuchsia::sysmem::BufferCollectionTokenSyncPtr scenic_token;
status = local_token->Duplicate(std::numeric_limits<uint32_t>::max(),
scenic_token.NewRequest());
status = vulkan_token->Duplicate(std::numeric_limits<uint32_t>::max(),
scenic_token.NewRequest());
LOG_AND_RETURN(status != ZX_OK, "Failed to duplicate token");
status = local_token->Sync();
LOG_AND_RETURN(status != ZX_OK, "Failed to sync token");
fuchsia::sysmem::BufferCollectionTokenSyncPtr vulkan_token;
status = local_token->Duplicate(std::numeric_limits<uint32_t>::max(),
vulkan_token.NewRequest());
LOG_AND_RETURN(status != ZX_OK, "Failed to duplicate token");
status = local_token->Sync();
status = vulkan_token->Sync();
LOG_AND_RETURN(status != ZX_OK, "Failed to sync token");
session_->RegisterBufferCollection(buffer_id_, std::move(scenic_token));
fuchsia::sysmem::BufferCollectionSyncPtr buffer_collection;
status = sysmem_allocator->BindSharedCollection(
std::move(local_token), buffer_collection.NewRequest());
LOG_AND_RETURN(status != ZX_OK, "Failed to bind collection");
fuchsia::sysmem::BufferCollectionConstraints constraints;
constraints.min_buffer_count = 1;
constraints.usage.vulkan = kSysmemImageUsage;
constraints.image_format_constraints_count = 1;
fuchsia::sysmem::ImageFormatConstraints& image_constraints =
constraints.image_format_constraints[0];
image_constraints = fuchsia::sysmem::ImageFormatConstraints();
image_constraints.min_coded_width = size.width();
image_constraints.min_coded_height = size.height();
image_constraints.max_coded_width = size.width();
image_constraints.max_coded_height = size.height();
image_constraints.min_bytes_per_row = 0;
image_constraints.pixel_format.type = kSysmemPixelFormat;
image_constraints.color_spaces_count = 1;
image_constraints.color_space[0].type = fuchsia::sysmem::ColorSpaceType::SRGB;
status = buffer_collection->SetConstraints(true, constraints);
LOG_AND_RETURN(status != ZX_OK, "Failed to set constraints");
VkBufferCollectionCreateInfoFUCHSIA import_info;
import_info.collectionToken = vulkan_token.Unbind().TakeChannel().release();
if (VK_CALL_LOG_ERROR(vulkan_provider_.vk().CreateBufferCollectionFUCHSIA(
@ -289,21 +251,27 @@ bool VulkanSurface::AllocateDeviceMemory(
LOG_AND_RETURN(!CreateVulkanImage(vulkan_provider_, size, &vulkan_image),
"Failed to create VkImage");
status = buffer_collection->Close();
LOG_AND_RETURN(status != ZX_OK, "Failed to close collection");
vulkan_image_ = std::move(vulkan_image);
const VkMemoryRequirements& memory_requirements =
vulkan_image_.vk_memory_requirements;
VkImageCreateInfo& image_create_info = vulkan_image_.vk_image_create_info;
VkBufferCollectionPropertiesFUCHSIA properties = {
.sType = VK_STRUCTURE_TYPE_BUFFER_COLLECTION_PROPERTIES_FUCHSIA};
if (VK_CALL_LOG_ERROR(
vulkan_provider_.vk().GetBufferCollectionPropertiesFUCHSIA(
vulkan_provider_.vk_device(), collection_, &properties)) !=
VK_SUCCESS) {
return false;
}
VkImportMemoryBufferCollectionFUCHSIA import_memory_info = {
.sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_BUFFER_COLLECTION_FUCHSIA,
.pNext = nullptr,
.collection = collection_,
.index = 0,
};
auto bits = memory_requirements.memoryTypeBits;
auto bits = memory_requirements.memoryTypeBits & properties.memoryTypeBits;
FML_DCHECK(bits != 0);
VkMemoryAllocateInfo allocation_info = {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,

View File

@ -141,6 +141,7 @@ bool VulkanProcTable::SetupDeviceProcAddresses(
ACQUIRE_PROC(GetMemoryZirconHandleFUCHSIA, handle);
ACQUIRE_PROC(ImportSemaphoreZirconHandleFUCHSIA, handle);
ACQUIRE_PROC(SetBufferCollectionConstraintsFUCHSIA, handle);
ACQUIRE_PROC(GetBufferCollectionPropertiesFUCHSIA, handle);
#endif // OS_FUCHSIA
device_ = {handle, nullptr};
return true;

View File

@ -119,6 +119,7 @@ class VulkanProcTable : public fml::RefCountedThreadSafe<VulkanProcTable> {
DEFINE_PROC(GetMemoryZirconHandleFUCHSIA);
DEFINE_PROC(ImportSemaphoreZirconHandleFUCHSIA);
DEFINE_PROC(SetBufferCollectionConstraintsFUCHSIA);
DEFINE_PROC(GetBufferCollectionPropertiesFUCHSIA);
#endif // OS_FUCHSIA
#undef DEFINE_PROC