19 VkPhysicalDevice physicalDevice,
21 uint32_t physicalDeviceVersion,
31 VkPhysicalDevice physicalDevice,
33 uint32_t physicalDeviceVersion,
37#define SKGPU_COPY_FUNCTION(NAME) functions.vk##NAME = interface->fFunctions.f##NAME
38#define SKGPU_COPY_FUNCTION_KHR(NAME) functions.vk##NAME##KHR = interface->fFunctions.f##NAME
40 VmaVulkanFunctions functions;
43 memset(&functions, 0,
sizeof(VmaVulkanFunctions));
47 functions.vkGetInstanceProcAddr =
nullptr;
48 functions.vkGetDeviceProcAddr =
nullptr;
72 VmaAllocatorCreateInfo
info;
75 info.flags |= VMA_ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT;
80 info.flags |= VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT;
83 info.physicalDevice = physicalDevice;
89 info.preferredLargeHeapBlockSize = 64*1024;
90 info.pAllocationCallbacks =
nullptr;
91 info.pDeviceMemoryCallbacks =
nullptr;
92 info.pHeapSizeLimit =
nullptr;
93 info.pVulkanFunctions = &functions;
98 info.pTypeExternalMemoryHandleTypes =
nullptr;
100 VmaAllocator allocator;
101 vmaCreateAllocator(&
info, &allocator);
106VulkanAMDMemoryAllocator::VulkanAMDMemoryAllocator(VmaAllocator allocator)
107 : fAllocator(allocator) {}
109VulkanAMDMemoryAllocator::~VulkanAMDMemoryAllocator() {
110 vmaDestroyAllocator(fAllocator);
114VkResult VulkanAMDMemoryAllocator::allocateImageMemory(VkImage
image,
115 uint32_t allocationPropertyFlags,
118 VmaAllocationCreateInfo
info;
120 info.usage = VMA_MEMORY_USAGE_UNKNOWN;
122 info.preferredFlags = 0;
123 info.memoryTypeBits = 0;
125 info.pUserData =
nullptr;
127 if (kDedicatedAllocation_AllocationPropertyFlag & allocationPropertyFlags) {
128 info.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
130 if (kLazyAllocation_AllocationPropertyFlag & allocationPropertyFlags) {
133 if (kProtected_AllocationPropertyFlag & allocationPropertyFlags) {
137 VmaAllocation allocation;
145VkResult VulkanAMDMemoryAllocator::allocateBufferMemory(VkBuffer
buffer,
147 uint32_t allocationPropertyFlags,
150 VmaAllocationCreateInfo
info;
152 info.usage = VMA_MEMORY_USAGE_UNKNOWN;
153 info.memoryTypeBits = 0;
155 info.pUserData =
nullptr;
158 case BufferUsage::kGpuOnly:
160 info.preferredFlags = 0;
162 case BufferUsage::kCpuWritesGpuReads:
179 case BufferUsage::kTransfersFromCpuToGpu:
182 info.preferredFlags = 0;
184 case BufferUsage::kTransfersFromGpuToCpu:
190 if (kDedicatedAllocation_AllocationPropertyFlag & allocationPropertyFlags) {
191 info.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
193 if ((kLazyAllocation_AllocationPropertyFlag & allocationPropertyFlags) &&
194 BufferUsage::kGpuOnly ==
usage) {
198 if (kPersistentlyMapped_AllocationPropertyFlag & allocationPropertyFlags) {
200 info.flags |= VMA_ALLOCATION_CREATE_MAPPED_BIT;
203 VmaAllocation allocation;
214 const VmaAllocation allocation = (VmaAllocation)memoryHandle;
215 vmaFreeMemory(fAllocator, allocation);
219 VulkanAlloc* alloc)
const {
220 const VmaAllocation allocation = (VmaAllocation)memoryHandle;
221 VmaAllocationInfo vmaInfo;
222 vmaGetAllocationInfo(fAllocator, allocation, &vmaInfo);
225 vmaGetMemoryTypeProperties(fAllocator, vmaInfo.memoryType, &memFlags);
238 alloc->fMemory = vmaInfo.deviceMemory;
239 alloc->fOffset = vmaInfo.offset;
240 alloc->fSize = vmaInfo.size;
241 alloc->fFlags =
flags;
242 alloc->fBackendMemory = memoryHandle;
248 const VmaAllocation allocation = (VmaAllocation)memoryHandle;
249 return vmaMapMemory(fAllocator, allocation, data);
254 const VmaAllocation allocation = (VmaAllocation)memoryHandle;
255 vmaUnmapMemory(fAllocator, allocation);
261 const VmaAllocation allocation = (VmaAllocation)memoryHandle;
262 return vmaFlushAllocation(fAllocator, allocation,
offset, size);
268 const VmaAllocation allocation = (VmaAllocation)memoryHandle;
269 return vmaInvalidateAllocation(fAllocator, allocation,
offset, size);
272std::pair<uint64_t, uint64_t> VulkanAMDMemoryAllocator::totalAllocatedAndUsedMemory()
const {
273 VmaTotalStatistics
stats;
274 vmaCalculateStatistics(fAllocator, &stats);
275 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)
static sk_sp< VulkanMemoryAllocator > Make(VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device, uint32_t physicalDeviceVersion, const VulkanExtensions *extensions, const VulkanInterface *interface, bool threadSafe)
FlutterSemanticsFlag flags
static const uint8_t buffer[]
VulkanMemoryAllocator::BufferUsage BufferUsage
intptr_t VulkanBackendMemory
static void usage(char *argv0)
#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