Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] add explicit VMA flush to device memory writes. #42685

Merged
merged 4 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions impeller/renderer/backend/vulkan/allocator_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,12 @@ static constexpr VmaMemoryUsage ToVMAMemoryUsage() {
}

static constexpr VkMemoryPropertyFlags ToVKMemoryPropertyFlags(
StorageMode mode,
bool is_texture) {
StorageMode mode) {
switch (mode) {
case StorageMode::kHostVisible:
if (is_texture) {
return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
} else {
return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
}
// 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;
case StorageMode::kDevicePrivate:
return VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
case StorageMode::kDeviceTransient:
Expand Down Expand Up @@ -236,7 +232,7 @@ class AllocatedTextureSourceVK final : public TextureSourceVK {
VmaAllocationCreateInfo alloc_nfo = {};

alloc_nfo.usage = ToVMAMemoryUsage();
alloc_nfo.preferredFlags = ToVKMemoryPropertyFlags(desc.storage_mode, true);
alloc_nfo.preferredFlags = ToVKMemoryPropertyFlags(desc.storage_mode);
alloc_nfo.flags = ToVmaAllocationCreateFlags(desc.storage_mode, true);

auto create_info_native =
Expand Down Expand Up @@ -366,8 +362,7 @@ std::shared_ptr<DeviceBuffer> AllocatorVK::OnCreateBuffer(

VmaAllocationCreateInfo allocation_info = {};
allocation_info.usage = ToVMAMemoryUsage();
allocation_info.preferredFlags =
ToVKMemoryPropertyFlags(desc.storage_mode, false);
allocation_info.preferredFlags = ToVKMemoryPropertyFlags(desc.storage_mode);
allocation_info.flags = ToVmaAllocationCreateFlags(desc.storage_mode, false);

VkBuffer buffer = {};
Expand Down
3 changes: 3 additions & 0 deletions impeller/renderer/backend/vulkan/device_buffer_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ bool DeviceBufferVK::OnCopyHostBuffer(const uint8_t* source,
if (source) {
::memmove(dest + offset, source + source_range.offset, source_range.length);
}
// See https://github.com/flutter/flutter/issues/128556 . Some devices do not
// have support for coherent host memory and require an explicit flush.
::vmaFlushAllocation(allocator_, allocation_, offset, source_range.length);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#ifdef FML_OS_ANDROID?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure? we can't actually test all the devices this will run on, and this will always be safe to call...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably just not request coherent memory if we don't need it and add the explict flushes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

It looks like we should be querying vmaGetMemoryProperties to see if the https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkPhysicalDeviceMemoryProperties.html has a VkMemoryType that supports host coherent.


return true;
}
Expand Down