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

[Impeller] Wire Flutter's own VulkanMemoryAllocator implementation #37018

Merged
merged 21 commits into from
Oct 27, 2022

Conversation

iskakaushik
Copy link
Contributor

@iskakaushik iskakaushik commented Oct 25, 2022

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@flutter-dashboard flutter-dashboard bot added embedder Related to the embedder API needs tests labels Oct 25, 2022
@iskakaushik iskakaushik force-pushed the engine_vma branch 3 times, most recently from 030a7ed to 6abf1dd Compare October 26, 2022 14:20
@iskakaushik iskakaushik force-pushed the engine_vma branch 2 times, most recently from 10b160b to b80cffe Compare October 26, 2022 16:58
@iskakaushik iskakaushik changed the title [WIP] Wire Flutter's own VulkanMemoryAllocator implementation [Impeller] Wire Flutter's own VulkanMemoryAllocator implementation Oct 27, 2022
@iskakaushik iskakaushik self-assigned this Oct 27, 2022
@iskakaushik iskakaushik requested review from dnfield and bdero October 27, 2022 18:16
Copy link
Member

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

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

Oof, didn't realize chasing all the uses of Vulkan context creation would be so tedious. Thanks for doing this!

Left some comments on how Impeller ought to use VMA but there are just informational.


namespace flutter {

class FlutterSkiaVulkanMemoryAllocator : public skgpu::VulkanMemoryAllocator {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Perhaps just call this SkiaVulkanMemoryAllocator?

// devices are required to support a host visible and coherent memory type.
// This is used to work around bugs for devices that don't handle non coherent
// memory correctly.
bool must_use_coherent_host_visible_memory_;
Copy link
Member

Choose a reason for hiding this comment

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

Disallow copy and assign here?

// this type of memory. But if we ever do we could pass in an
// AllocationPropertyFlag that requests the cached property.
info.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
Copy link
Member

Choose a reason for hiding this comment

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

In case of Impeller, we should never require VK_MEMORY_PROPERTY_HOST_COHERENT_BIT as we will always have the corresponding map-unmap pairs.

info.requiredFlags |= VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
}
if (kDedicatedAllocation_AllocationPropertyFlag & allocationPropertyFlags) {
info.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
Copy link
Member

Choose a reason for hiding this comment

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

This reminds me, perhaps we should do this for all images from the image decoder (the ui.Images)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted, will fix this in allocator_vk.cc

}
if ((kLazyAllocation_AllocationPropertyFlag & allocationPropertyFlags) &&
BufferUsage::kGpuOnly == usage) {
info.preferredFlags |= VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT;
Copy link
Member

Choose a reason for hiding this comment

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

In Impellers case, this would be the device transient types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted, will fix this in allocator_vk.cc


if (kPersistentlyMapped_AllocationPropertyFlag & allocationPropertyFlags) {
SkASSERT(BufferUsage::kGpuOnly != usage);
info.flags |= VMA_ALLOCATION_CREATE_MAPPED_BIT;
Copy link
Member

Choose a reason for hiding this comment

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

We should never needs this with Impeller.

]

if (disable_vma_stl_shared_mutex) {
defines = [ "VMA_USE_STL_SHARED_MUTEX=0" ]
Copy link
Member

Choose a reason for hiding this comment

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

Is this correct? Does this mean there is no thread safety around VMA access? Or does it mean there is a non-STL implementation of mutexes? If there is no thread safety, we'll need to follow up on implementing external synchronization in the Impeller case. Which might be the right thing to do anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This means that they use non-stl mutexes. For context, Impeller doesn't use flutter_skia_vma.cc stuff at all. We just use allocator_vk.cc copy of the vma.

@iskakaushik iskakaushik added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 27, 2022
@auto-submit
Copy link
Contributor

auto-submit bot commented Oct 27, 2022

auto label is removed for flutter/engine, pr: 37018, due to - The status or check suite Mac Host clang-tidy has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 27, 2022
@iskakaushik iskakaushik added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 27, 2022
@auto-submit auto-submit bot merged commit ff05a31 into flutter:main Oct 27, 2022
@zanderso
Copy link
Member

Is this flake a couple of commits past this change related? https://ci.chromium.org/ui/p/flutter/builders/prod/Linux%20Production%20Engine%20Drone/5722/overview

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App e: impeller embedder Related to the embedder API needs tests platform-fuchsia
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Impeller] Vulkan Memory Allocator conflicts
3 participants