5#include "flutter/flutter_vma/flutter_skia_vma.h"
7#include "flutter/fml/memory/ref_ptr.h"
8#include "flutter/vulkan/procs/vulkan_handle.h"
9#include "flutter/vulkan/procs/vulkan_proc_table.h"
14 uint32_t vulkan_api_version,
16 VkPhysicalDevice physicalDevice,
19 bool mustUseCoherentHostVisibleMemory) {
20#define PROVIDE_PROC(tbl, proc, provider) tbl.vk##proc = provider->proc;
22 VmaVulkanFunctions proc_table = {};
23 proc_table.vkGetInstanceProcAddr =
vk->NativeGetInstanceProcAddr();
43#define PROVIDE_PROC_COALESCE(tbl, proc, provider) \
44 tbl.vk##proc##KHR = provider->proc ? provider->proc : provider->proc##KHR;
53#undef PROVIDE_PROC_COALESCE
57 VmaAllocatorCreateInfo allocator_info = {};
58 allocator_info.vulkanApiVersion = vulkan_api_version;
59 allocator_info.physicalDevice = physicalDevice;
60 allocator_info.device =
device;
62 allocator_info.pVulkanFunctions = &proc_table;
64 VmaAllocator allocator;
65 vmaCreateAllocator(&allocator_info, &allocator);
69 mustUseCoherentHostVisibleMemory));
72FlutterSkiaVulkanMemoryAllocator::FlutterSkiaVulkanMemoryAllocator(
74 VmaAllocator allocator,
75 bool mustUseCoherentHostVisibleMemory)
76 : vk_proc_table_(
std::move(vk_proc_table)),
77 allocator_(allocator),
78 must_use_coherent_host_visible_memory_(mustUseCoherentHostVisibleMemory) {
82 vmaDestroyAllocator(allocator_);
88 uint32_t allocationPropertyFlags,
90 VmaAllocationCreateInfo
info;
92 info.usage = VMA_MEMORY_USAGE_UNKNOWN;
94 info.preferredFlags = 0;
95 info.memoryTypeBits = 0;
97 info.pUserData =
nullptr;
100 info.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
109 VmaAllocation allocation;
111 vmaAllocateMemoryForImage(allocator_,
image, &
info, &allocation,
nullptr);
121 uint32_t allocationPropertyFlags,
123 VmaAllocationCreateInfo
info;
125 info.usage = VMA_MEMORY_USAGE_UNKNOWN;
126 info.memoryTypeBits = 0;
128 info.pUserData =
nullptr;
133 info.preferredFlags = 0;
158 info.preferredFlags = 0;
166 if (must_use_coherent_host_visible_memory_ &&
171 info.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
180 info.flags |= VMA_ALLOCATION_CREATE_MAPPED_BIT;
183 VmaAllocation allocation;
185 &allocation,
nullptr);
195 const VmaAllocation allocation =
196 reinterpret_cast<const VmaAllocation
>(memoryHandle);
197 vmaFreeMemory(allocator_, allocation);
203 const VmaAllocation allocation =
204 reinterpret_cast<const VmaAllocation
>(memoryHandle);
205 VmaAllocationInfo vmaInfo;
206 vmaGetAllocationInfo(allocator_, allocation, &vmaInfo);
209 vmaGetMemoryTypeProperties(allocator_, vmaInfo.memoryType, &memFlags);
222 alloc->
fMemory = vmaInfo.deviceMemory;
223 alloc->
fOffset = vmaInfo.offset;
224 alloc->
fSize = vmaInfo.size;
232 const VmaAllocation allocation =
233 reinterpret_cast<const VmaAllocation
>(memoryHandle);
234 return vmaMapMemory(allocator_, allocation,
data);
239 const VmaAllocation allocation =
240 reinterpret_cast<const VmaAllocation
>(memoryHandle);
241 vmaUnmapMemory(allocator_, allocation);
248 const VmaAllocation allocation =
249 reinterpret_cast<const VmaAllocation
>(memoryHandle);
250 return vmaFlushAllocation(allocator_, allocation,
offset,
size);
257 const VmaAllocation allocation =
258 reinterpret_cast<const VmaAllocation
>(memoryHandle);
259 return vmaInvalidateAllocation(allocator_, allocation,
offset,
size);
262std::pair<uint64_t, uint64_t>
264 VmaTotalStatistics
stats;
265 vmaCalculateStatistics(allocator_, &
stats);
266 return {
stats.total.statistics.blockBytes,
267 stats.total.statistics.allocationBytes};
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
VkResult mapMemory(const skgpu::VulkanBackendMemory &, void **data) override
static sk_sp< VulkanMemoryAllocator > Make(uint32_t vulkan_api_version, VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device, const fml::RefPtr< vulkan::VulkanProcTable > &vk, bool mustUseCoherentHostVisibleMemory)
VkResult invalidateMemory(const skgpu::VulkanBackendMemory &, VkDeviceSize offset, VkDeviceSize size) override
void freeMemory(const skgpu::VulkanBackendMemory &) override
VkResult allocateImageMemory(VkImage image, uint32_t allocationPropertyFlags, skgpu::VulkanBackendMemory *) override
~FlutterSkiaVulkanMemoryAllocator() override
VkResult allocateBufferMemory(VkBuffer buffer, BufferUsage usage, uint32_t allocationPropertyFlags, skgpu::VulkanBackendMemory *) override
void getAllocInfo(const skgpu::VulkanBackendMemory &, skgpu::VulkanAlloc *) const override
VkResult flushMemory(const skgpu::VulkanBackendMemory &, VkDeviceSize offset, VkDeviceSize size) override
std::pair< uint64_t, uint64_t > totalAllocatedAndUsedMemory() const override
void unmapMemory(const skgpu::VulkanBackendMemory &) override
@ kLazyAllocation_AllocationPropertyFlag
@ kDedicatedAllocation_AllocationPropertyFlag
@ kProtected_AllocationPropertyFlag
@ kPersistentlyMapped_AllocationPropertyFlag
FlutterSemanticsFlag flags
#define PROVIDE_PROC_COALESCE(tbl, proc, provider)
#define PROVIDE_PROC(tbl, proc, provider)
sk_sp< const SkImage > image
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
intptr_t VulkanBackendMemory
static void usage(char *argv0)
VulkanBackendMemory fBackendMemory
VkFlags VkMemoryPropertyFlags
@ VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT
@ VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
@ VK_MEMORY_PROPERTY_PROTECTED_BIT
@ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
@ VK_MEMORY_PROPERTY_HOST_CACHED_BIT
@ VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT