diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 6f8d1ae3379b5..7555581201dd0 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -4207,6 +4207,7 @@ FILE: ../../../flutter/impeller/renderer/backend/vulkan/fence_waiter_vk.cc FILE: ../../../flutter/impeller/renderer/backend/vulkan/fence_waiter_vk.h FILE: ../../../flutter/impeller/renderer/backend/vulkan/formats_vk.cc FILE: ../../../flutter/impeller/renderer/backend/vulkan/formats_vk.h +FILE: ../../../flutter/impeller/renderer/backend/vulkan/limits_vk.h FILE: ../../../flutter/impeller/renderer/backend/vulkan/pass_bindings_cache.cc FILE: ../../../flutter/impeller/renderer/backend/vulkan/pass_bindings_cache.h FILE: ../../../flutter/impeller/renderer/backend/vulkan/pipeline_cache_vk.cc diff --git a/impeller/core/device_buffer.cc b/impeller/core/device_buffer.cc index 0498ee3e894bc..741a4d7ee2386 100644 --- a/impeller/core/device_buffer.cc +++ b/impeller/core/device_buffer.cc @@ -39,8 +39,6 @@ std::shared_ptr DeviceBuffer::AsTexture( return texture; } -void DeviceBuffer::Flush() {} - const DeviceBufferDescriptor& DeviceBuffer::GetDeviceBufferDescriptor() const { return desc_; } diff --git a/impeller/core/device_buffer.h b/impeller/core/device_buffer.h index 739d46ca224a8..507a4157d53be 100644 --- a/impeller/core/device_buffer.h +++ b/impeller/core/device_buffer.h @@ -32,8 +32,6 @@ class DeviceBuffer : public Buffer, BufferView AsBufferView() const; - virtual void Flush(); - virtual std::shared_ptr AsTexture( Allocator& allocator, const TextureDescriptor& descriptor, diff --git a/impeller/renderer/backend/vulkan/BUILD.gn b/impeller/renderer/backend/vulkan/BUILD.gn index 4e451c4a233a7..1d21955728e65 100644 --- a/impeller/renderer/backend/vulkan/BUILD.gn +++ b/impeller/renderer/backend/vulkan/BUILD.gn @@ -52,6 +52,7 @@ impeller_component("vulkan") { "fence_waiter_vk.h", "formats_vk.cc", "formats_vk.h", + "limits_vk.h", "pass_bindings_cache.cc", "pass_bindings_cache.h", "pipeline_cache_vk.cc", diff --git a/impeller/renderer/backend/vulkan/allocator_vk.cc b/impeller/renderer/backend/vulkan/allocator_vk.cc index a94eba6b16bd3..36a53d2ce04e1 100644 --- a/impeller/renderer/backend/vulkan/allocator_vk.cc +++ b/impeller/renderer/backend/vulkan/allocator_vk.cc @@ -11,6 +11,7 @@ #include "impeller/core/formats.h" #include "impeller/renderer/backend/vulkan/device_buffer_vk.h" #include "impeller/renderer/backend/vulkan/formats_vk.h" +#include "impeller/renderer/backend/vulkan/limits_vk.h" #include "impeller/renderer/backend/vulkan/texture_vk.h" namespace impeller { @@ -198,9 +199,9 @@ static constexpr VkMemoryPropertyFlags ToVKBufferMemoryPropertyFlags( StorageMode mode) { switch (mode) { case StorageMode::kHostVisible: - // See https://github.com/flutter/flutter/issues/128556 . Some devices do - // not have support for coherent host memory so we don't request it here. - return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; + return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; case StorageMode::kDevicePrivate: return VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; case StorageMode::kDeviceTransient: @@ -210,18 +211,27 @@ static constexpr VkMemoryPropertyFlags ToVKBufferMemoryPropertyFlags( } static VmaAllocationCreateFlags ToVmaAllocationCreateFlags(StorageMode mode, - bool is_texture) { + bool is_texture, + size_t size) { VmaAllocationCreateFlags flags = 0; switch (mode) { case StorageMode::kHostVisible: if (is_texture) { - flags |= {}; + if (size >= kImageSizeThresholdForDedicatedMemoryAllocation) { + flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT; + } else { + flags |= {}; + } } else { - flags |= VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT; + flags |= VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT; flags |= VMA_ALLOCATION_CREATE_MAPPED_BIT; } return flags; case StorageMode::kDevicePrivate: + if (is_texture && + size >= kImageSizeThresholdForDedicatedMemoryAllocation) { + flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT; + } return flags; case StorageMode::kDeviceTransient: return flags; @@ -261,7 +271,9 @@ class AllocatedTextureSourceVK final : public TextureSourceVK { alloc_nfo.usage = ToVMAMemoryUsage(); alloc_nfo.preferredFlags = ToVKTextureMemoryPropertyFlags( desc.storage_mode, supports_memoryless_textures); - alloc_nfo.flags = ToVmaAllocationCreateFlags(desc.storage_mode, true); + alloc_nfo.flags = + ToVmaAllocationCreateFlags(desc.storage_mode, /*is_texture=*/true, + desc.GetByteSizeOfBaseMipLevel()); auto create_info_native = static_cast(image_info); @@ -396,7 +408,8 @@ std::shared_ptr AllocatorVK::OnCreateBuffer( allocation_info.usage = ToVMAMemoryUsage(); allocation_info.preferredFlags = ToVKBufferMemoryPropertyFlags(desc.storage_mode); - allocation_info.flags = ToVmaAllocationCreateFlags(desc.storage_mode, false); + allocation_info.flags = ToVmaAllocationCreateFlags( + desc.storage_mode, /*is_texture=*/false, desc.size); VkBuffer buffer = {}; VmaAllocation buffer_allocation = {}; diff --git a/impeller/renderer/backend/vulkan/device_buffer_vk.cc b/impeller/renderer/backend/vulkan/device_buffer_vk.cc index a362902602b7c..8f1911b10d4b7 100644 --- a/impeller/renderer/backend/vulkan/device_buffer_vk.cc +++ b/impeller/renderer/backend/vulkan/device_buffer_vk.cc @@ -50,18 +50,9 @@ bool DeviceBufferVK::OnCopyHostBuffer(const uint8_t* source, ::memmove(dest + offset, source + source_range.offset, source_range.length); } - // Some devices do not have support for coherent host memory and require an - // explicit flush. - ::vmaFlushAllocation(allocator_, allocation_, offset, source_range.length); - return true; } -void DeviceBufferVK::Flush() { - TRACE_EVENT0("impeller", "FlushDeviceBuffer"); - ::vmaFlushAllocation(allocator_, allocation_, 0, VK_WHOLE_SIZE); -} - bool DeviceBufferVK::SetLabel(const std::string& label) { auto context = context_.lock(); if (!context || !buffer_) { diff --git a/impeller/renderer/backend/vulkan/device_buffer_vk.h b/impeller/renderer/backend/vulkan/device_buffer_vk.h index 25d910beff98f..229a1b6b04325 100644 --- a/impeller/renderer/backend/vulkan/device_buffer_vk.h +++ b/impeller/renderer/backend/vulkan/device_buffer_vk.h @@ -28,11 +28,6 @@ class DeviceBufferVK final : public DeviceBuffer, vk::Buffer GetBuffer() const; - // If the contents of this buffer have been written to with - // `OnGetContents`, then calling flush may be necessary if the memory is - // non-coherent. - void Flush() override; - private: friend class AllocatorVK; diff --git a/impeller/renderer/backend/vulkan/limits_vk.h b/impeller/renderer/backend/vulkan/limits_vk.h new file mode 100644 index 0000000000000..14e2dce906e49 --- /dev/null +++ b/impeller/renderer/backend/vulkan/limits_vk.h @@ -0,0 +1,14 @@ +#pragma once + +#include + +namespace impeller { + +// Maximum size to use VMA image suballocation. Any allocation greater than or +// equal to this value will use a dedicated VkDeviceMemory. +// +// This value was taken from ANGLE. +constexpr size_t kImageSizeThresholdForDedicatedMemoryAllocation = + 4 * 1024 * 1024; + +} // namespace impeller diff --git a/lib/ui/painting/image_decoder_impeller.cc b/lib/ui/painting/image_decoder_impeller.cc index 37f025b7d5061..af111c6ff0341 100644 --- a/lib/ui/painting/image_decoder_impeller.cc +++ b/lib/ui/painting/image_decoder_impeller.cc @@ -510,9 +510,6 @@ ImpellerAllocator::ImpellerAllocator( std::shared_ptr ImpellerAllocator::GetDeviceBuffer() const { - if (buffer_) { - buffer_->Flush(); - } return buffer_; }