1111#include " impeller/core/formats.h"
1212#include " impeller/renderer/backend/vulkan/device_buffer_vk.h"
1313#include " impeller/renderer/backend/vulkan/formats_vk.h"
14+ #include " impeller/renderer/backend/vulkan/limits_vk.h"
1415#include " impeller/renderer/backend/vulkan/texture_vk.h"
1516
1617namespace impeller {
@@ -198,9 +199,9 @@ static constexpr VkMemoryPropertyFlags ToVKBufferMemoryPropertyFlags(
198199 StorageMode mode) {
199200 switch (mode) {
200201 case StorageMode::kHostVisible :
201- // See https://github.com/flutter/flutter/issues/128556 . Some devices do
202- // not have support for coherent host memory so we don't request it here.
203- return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT ;
202+ return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
203+ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
204+ VK_MEMORY_PROPERTY_HOST_COHERENT_BIT ;
204205 case StorageMode::kDevicePrivate :
205206 return VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
206207 case StorageMode::kDeviceTransient :
@@ -210,18 +211,27 @@ static constexpr VkMemoryPropertyFlags ToVKBufferMemoryPropertyFlags(
210211}
211212
212213static VmaAllocationCreateFlags ToVmaAllocationCreateFlags (StorageMode mode,
213- bool is_texture) {
214+ bool is_texture,
215+ size_t size) {
214216 VmaAllocationCreateFlags flags = 0 ;
215217 switch (mode) {
216218 case StorageMode::kHostVisible :
217219 if (is_texture) {
218- flags |= {};
220+ if (size >= kImageSizeThresholdForDedicatedMemoryAllocation ) {
221+ flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
222+ } else {
223+ flags |= {};
224+ }
219225 } else {
220- flags |= VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT ;
226+ flags |= VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT ;
221227 flags |= VMA_ALLOCATION_CREATE_MAPPED_BIT;
222228 }
223229 return flags;
224230 case StorageMode::kDevicePrivate :
231+ if (is_texture &&
232+ size >= kImageSizeThresholdForDedicatedMemoryAllocation ) {
233+ flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
234+ }
225235 return flags;
226236 case StorageMode::kDeviceTransient :
227237 return flags;
@@ -261,7 +271,9 @@ class AllocatedTextureSourceVK final : public TextureSourceVK {
261271 alloc_nfo.usage = ToVMAMemoryUsage ();
262272 alloc_nfo.preferredFlags = ToVKTextureMemoryPropertyFlags (
263273 desc.storage_mode , supports_memoryless_textures);
264- alloc_nfo.flags = ToVmaAllocationCreateFlags (desc.storage_mode , true );
274+ alloc_nfo.flags =
275+ ToVmaAllocationCreateFlags (desc.storage_mode , /* is_texture=*/ true ,
276+ desc.GetByteSizeOfBaseMipLevel ());
265277
266278 auto create_info_native =
267279 static_cast <vk::ImageCreateInfo::NativeType>(image_info);
@@ -396,7 +408,8 @@ std::shared_ptr<DeviceBuffer> AllocatorVK::OnCreateBuffer(
396408 allocation_info.usage = ToVMAMemoryUsage ();
397409 allocation_info.preferredFlags =
398410 ToVKBufferMemoryPropertyFlags (desc.storage_mode );
399- allocation_info.flags = ToVmaAllocationCreateFlags (desc.storage_mode , false );
411+ allocation_info.flags = ToVmaAllocationCreateFlags (
412+ desc.storage_mode , /* is_texture=*/ false , desc.size );
400413
401414 VkBuffer buffer = {};
402415 VmaAllocation buffer_allocation = {};
0 commit comments