18 VkPhysicalDevice physicalDevice,
20 uint32_t physicalDeviceVersion,
23#define SKGPU_COPY_FUNCTION(NAME) functions.vk##NAME = interface->fFunctions.f##NAME
24#define SKGPU_COPY_FUNCTION_KHR(NAME) functions.vk##NAME##KHR = interface->fFunctions.f##NAME
26 VmaVulkanFunctions functions;
29 memset(&functions, 0,
sizeof(VmaVulkanFunctions));
33 functions.vkGetInstanceProcAddr =
nullptr;
34 functions.vkGetDeviceProcAddr =
nullptr;
58 VmaAllocatorCreateInfo
info;
59 info.flags = VMA_ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT;
63 info.flags |= VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT;
66 info.physicalDevice = physicalDevice;
72 info.preferredLargeHeapBlockSize = 4 * 1024 * 1024;
73 info.pAllocationCallbacks =
nullptr;
74 info.pDeviceMemoryCallbacks =
nullptr;
75 info.pHeapSizeLimit =
nullptr;
76 info.pVulkanFunctions = &functions;
81 info.pTypeExternalMemoryHandleTypes =
nullptr;
83 VmaAllocator allocator;
84 vmaCreateAllocator(&
info, &allocator);
89VkTestMemoryAllocator::VkTestMemoryAllocator(VmaAllocator allocator) : fAllocator(allocator) {}
92 vmaDestroyAllocator(fAllocator);
97 uint32_t allocationPropertyFlags,
100 VmaAllocationCreateInfo
info;
102 info.usage = VMA_MEMORY_USAGE_UNKNOWN;
104 info.preferredFlags = 0;
105 info.memoryTypeBits = 0;
107 info.pUserData =
nullptr;
110 info.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
119 VmaAllocation allocation;
129 uint32_t allocationPropertyFlags,
132 VmaAllocationCreateInfo
info;
134 info.usage = VMA_MEMORY_USAGE_UNKNOWN;
135 info.memoryTypeBits = 0;
137 info.pUserData =
nullptr;
142 info.preferredFlags = 0;
164 info.preferredFlags = 0;
173 info.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
182 info.flags |= VMA_ALLOCATION_CREATE_MAPPED_BIT;
185 VmaAllocation allocation;
196 const VmaAllocation allocation = (VmaAllocation)memoryHandle;
197 vmaFreeMemory(fAllocator, allocation);
202 const VmaAllocation allocation = (VmaAllocation)memoryHandle;
203 VmaAllocationInfo vmaInfo;
204 vmaGetAllocationInfo(fAllocator, allocation, &vmaInfo);
207 vmaGetMemoryTypeProperties(fAllocator, vmaInfo.memoryType, &memFlags);
220 alloc->
fMemory = vmaInfo.deviceMemory;
221 alloc->
fOffset = vmaInfo.offset;
222 alloc->
fSize = vmaInfo.size;
230 const VmaAllocation allocation = (VmaAllocation)memoryHandle;
231 return vmaMapMemory(fAllocator, allocation, data);
236 const VmaAllocation allocation = (VmaAllocation)memoryHandle;
237 vmaUnmapMemory(fAllocator, allocation);
244 const VmaAllocation allocation = (VmaAllocation)memoryHandle;
245 return vmaFlushAllocation(fAllocator, allocation,
offset, size);
252 const VmaAllocation allocation = (VmaAllocation)memoryHandle;
253 return vmaInvalidateAllocation(fAllocator, allocation,
offset, size);
257 VmaTotalStatistics stats;
258 vmaCalculateStatistics(fAllocator, &stats);
259 return {stats.total.statistics.blockBytes, stats.total.statistics.allocationBytes};
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static constexpr bool SkToBool(const T &x)
#define TRACE_EVENT0_ALWAYS(category_group, name)
#define SKGPU_COPY_FUNCTION_KHR(NAME)
#define SKGPU_COPY_FUNCTION(NAME)
~VkTestMemoryAllocator() override
void unmapMemory(const skgpu::VulkanBackendMemory &) override
VkResult invalidateMemory(const skgpu::VulkanBackendMemory &, VkDeviceSize offset, VkDeviceSize size) override
VkResult flushMemory(const skgpu::VulkanBackendMemory &, VkDeviceSize offset, VkDeviceSize size) override
static sk_sp< VulkanMemoryAllocator > Make(VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device, uint32_t physicalDeviceVersion, const skgpu::VulkanExtensions *extensions, const skgpu::VulkanInterface *interface)
VkResult allocateBufferMemory(VkBuffer buffer, BufferUsage usage, uint32_t allocationPropertyFlags, skgpu::VulkanBackendMemory *) override
std::pair< uint64_t, uint64_t > totalAllocatedAndUsedMemory() const override
void getAllocInfo(const skgpu::VulkanBackendMemory &, skgpu::VulkanAlloc *) const override
VkResult mapMemory(const skgpu::VulkanBackendMemory &, void **data) override
VkResult allocateImageMemory(VkImage image, uint32_t allocationPropertyFlags, skgpu::VulkanBackendMemory *) override
void freeMemory(const skgpu::VulkanBackendMemory &) override
@ kLazyAllocation_AllocationPropertyFlag
@ kDedicatedAllocation_AllocationPropertyFlag
@ kProtected_AllocationPropertyFlag
@ kPersistentlyMapped_AllocationPropertyFlag
FlutterSemanticsFlag flags
static const uint8_t buffer[]
intptr_t VulkanBackendMemory
static void usage(char *argv0)
VulkanBackendMemory fBackendMemory
#define TRACE_EVENT0(category_group, name)
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
#define VK_MAKE_VERSION(major, minor, patch)
#define VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME
#define VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME