1 //
2 // Copyright 2020 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // vma_allocator_wrapper.h:
7 // Hides VMA functions so we can use separate warning sets.
8 //
9
10 #ifndef LIBANGLE_RENDERER_VULKAN_VK_MEM_ALLOC_WRAPPER_H_
11 #define LIBANGLE_RENDERER_VULKAN_VK_MEM_ALLOC_WRAPPER_H_
12
13 #include "common/vulkan/vk_headers.h"
14
15 VK_DEFINE_HANDLE(VmaAllocator)
VK_DEFINE_HANDLE(VmaAllocation)16 VK_DEFINE_HANDLE(VmaAllocation)
17 VK_DEFINE_HANDLE(VmaPool)
18
19 namespace vma
20 {
21 VkResult InitAllocator(VkPhysicalDevice physicalDevice,
22 VkDevice device,
23 VkInstance instance,
24 uint32_t apiVersion,
25 VkDeviceSize preferredLargeHeapBlockSize,
26 VmaAllocator *pAllocator);
27
28 void DestroyAllocator(VmaAllocator allocator);
29
30 VkResult CreatePool(VmaAllocator allocator,
31 uint32_t memoryTypeIndex,
32 bool buddyAlgorithm,
33 VkDeviceSize blockSize,
34 VmaPool *pPool);
35 void DestroyPool(VmaAllocator allocator, VmaPool pool);
36
37 void FreeMemory(VmaAllocator allocator, VmaAllocation allocation);
38
39 VkResult CreateBuffer(VmaAllocator allocator,
40 const VkBufferCreateInfo *pBufferCreateInfo,
41 VkMemoryPropertyFlags requiredFlags,
42 VkMemoryPropertyFlags preferredFlags,
43 bool persistentlyMappedBuffers,
44 uint32_t *pMemoryTypeIndexOut,
45 VkBuffer *pBuffer,
46 VmaAllocation *pAllocation);
47
48 VkResult FindMemoryTypeIndexForBufferInfo(VmaAllocator allocator,
49 const VkBufferCreateInfo *pBufferCreateInfo,
50 VkMemoryPropertyFlags requiredFlags,
51 VkMemoryPropertyFlags preferredFlags,
52 bool persistentlyMappedBuffers,
53 uint32_t *pMemoryTypeIndexOut);
54
55 void GetMemoryTypeProperties(VmaAllocator allocator,
56 uint32_t memoryTypeIndex,
57 VkMemoryPropertyFlags *pFlags);
58
59 VkResult MapMemory(VmaAllocator allocator, VmaAllocation allocation, void **ppData);
60
61 void UnmapMemory(VmaAllocator allocator, VmaAllocation allocation);
62
63 void FlushAllocation(VmaAllocator allocator,
64 VmaAllocation allocation,
65 VkDeviceSize offset,
66 VkDeviceSize size);
67
68 void InvalidateAllocation(VmaAllocator allocator,
69 VmaAllocation allocation,
70 VkDeviceSize offset,
71 VkDeviceSize size);
72
73 void BuildStatsString(VmaAllocator allocator, char **statsString, VkBool32 detailedMap);
74 void FreeStatsString(VmaAllocator allocator, char *statsString);
75
76 } // namespace vma
77
78 #endif // LIBANGLE_RENDERER_VULKAN_VK_MEM_ALLOC_WRAPPER_H_
79