Hash :
3a7904e1
Author :
Date :
2023-01-25T23:56:56
Vulkan: Use VMA suballocation for images
There is a maximum limit for device memory object allocation. On some
platforms, there can be an error regarding too many object allocations
when 4096 device memory handles have been allocated. Suballocation can
help mitigate this issue. In this CL, some images will be allocated
using VMA API calls, which use suballocation.
* Added a new feature (useVmaForImageSuballocation).
* Added VMA allocation for ImageHelper, which is used in initMemory().
* Suballocation is used for VMA image allocation.
* If enabled, mVmaAllocation will be initialized in the ImageHelper
object (instead of mDeviceMemory).
* It is currently used for all platforms.
* Minor change to the name of an arg in CreateBuffer() declaration.
* Added test to make sure we can allocate at least 4096 images on
supported platforms (8000 in the test).
* Skipped the test "NonZeroBaseEmulatedClear" when run on Linux/Intel
if this feature is enabled (due to output color mismatch).
* Skipped several tests for capture/replay on Windows.
Bug: b/218891184
Change-Id: Ibf80c9c8c485b301da7d23b5ba4bcbb1a8e3194f
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4191202
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Charlie Lao <cclao@google.com>
Commit-Queue: Amirali Abdolrashidi <abdolrashidi@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
//
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// vma_allocator_wrapper.h:
// Hides VMA functions so we can use separate warning sets.
//
#ifndef LIBANGLE_RENDERER_VULKAN_VK_MEM_ALLOC_WRAPPER_H_
#define LIBANGLE_RENDERER_VULKAN_VK_MEM_ALLOC_WRAPPER_H_
#include "common/vulkan/vk_headers.h"
VK_DEFINE_HANDLE(VmaAllocator)
VK_DEFINE_HANDLE(VmaAllocation)
VK_DEFINE_HANDLE(VmaPool)
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VmaVirtualAllocation)
VK_DEFINE_HANDLE(VmaVirtualBlock)
namespace vma
{
typedef VkFlags VirtualBlockCreateFlags;
typedef enum VirtualBlockCreateFlagBits
{
GENERAL = 0x0000000,
LINEAR = 0x00000001,
BUDDY = 0x00000002
} VirtualBlockCreateFlagBits;
typedef struct StatInfo
{
// Number of VkDeviceMemory Vulkan memory blocks allocated.
uint32_t blockCount;
// Number of VmaAllocation allocation objects allocated.
uint32_t allocationCount;
// Number of free ranges of memory between allocations.
uint32_t unusedRangeCount;
// Total number of bytes occupied by all allocations.
VkDeviceSize usedBytes;
// Total number of bytes occupied by unused ranges.
VkDeviceSize unusedBytes;
VkDeviceSize allocationSizeMin, allocationSizeAvg, allocationSizeMax;
VkDeviceSize unusedRangeSizeMin, unusedRangeSizeAvg, unusedRangeSizeMax;
} StatInfo;
VkResult InitAllocator(VkPhysicalDevice physicalDevice,
VkDevice device,
VkInstance instance,
uint32_t apiVersion,
VkDeviceSize preferredLargeHeapBlockSize,
VmaAllocator *pAllocator);
void DestroyAllocator(VmaAllocator allocator);
VkResult CreatePool(VmaAllocator allocator,
uint32_t memoryTypeIndex,
#if ANGLE_VMA_VERSION < 3000000
bool buddyAlgorithm,
#endif // ANGLE_VMA_VERSION < 3000000
VkDeviceSize blockSize,
VmaPool *pPool);
void DestroyPool(VmaAllocator allocator, VmaPool pool);
void FreeMemory(VmaAllocator allocator, VmaAllocation allocation);
VkResult CreateBuffer(VmaAllocator allocator,
const VkBufferCreateInfo *pBufferCreateInfo,
VkMemoryPropertyFlags requiredFlags,
VkMemoryPropertyFlags preferredFlags,
bool persistentlyMapped,
uint32_t *pMemoryTypeIndexOut,
VkBuffer *pBuffer,
VmaAllocation *pAllocation);
VkResult AllocateAndBindMemoryForImage(VmaAllocator allocator,
VkImage *pImage,
VkMemoryPropertyFlags requiredFlags,
VkMemoryPropertyFlags preferredFlags,
VmaAllocation *pAllocationOut,
uint32_t *pMemoryTypeIndexOut,
VkDeviceSize *sizeOut);
VkResult FindMemoryTypeIndexForBufferInfo(VmaAllocator allocator,
const VkBufferCreateInfo *pBufferCreateInfo,
VkMemoryPropertyFlags requiredFlags,
VkMemoryPropertyFlags preferredFlags,
bool persistentlyMappedBuffers,
uint32_t *pMemoryTypeIndexOut);
void GetMemoryTypeProperties(VmaAllocator allocator,
uint32_t memoryTypeIndex,
VkMemoryPropertyFlags *pFlags);
VkResult MapMemory(VmaAllocator allocator, VmaAllocation allocation, void **ppData);
void UnmapMemory(VmaAllocator allocator, VmaAllocation allocation);
void FlushAllocation(VmaAllocator allocator,
VmaAllocation allocation,
VkDeviceSize offset,
VkDeviceSize size);
void InvalidateAllocation(VmaAllocator allocator,
VmaAllocation allocation,
VkDeviceSize offset,
VkDeviceSize size);
void BuildStatsString(VmaAllocator allocator, char **statsString, VkBool32 detailedMap);
void FreeStatsString(VmaAllocator allocator, char *statsString);
// VMA virtual block
VkResult CreateVirtualBlock(VkDeviceSize size,
VirtualBlockCreateFlags flags,
VmaVirtualBlock *pVirtualBlock);
void DestroyVirtualBlock(VmaVirtualBlock virtualBlock);
VkResult VirtualAllocate(VmaVirtualBlock virtualBlock,
VkDeviceSize size,
VkDeviceSize alignment,
VmaVirtualAllocation *pAllocation,
VkDeviceSize *pOffset);
void VirtualFree(VmaVirtualBlock virtualBlock,
VmaVirtualAllocation allocation,
VkDeviceSize offset);
VkBool32 IsVirtualBlockEmpty(VmaVirtualBlock virtualBlock);
void GetVirtualAllocationInfo(VmaVirtualBlock virtualBlock,
VmaVirtualAllocation allocation,
VkDeviceSize offset,
VkDeviceSize *sizeOut,
void **pUserDataOut);
void ClearVirtualBlock(VmaVirtualBlock virtualBlock);
void SetVirtualAllocationUserData(VmaVirtualBlock virtualBlock,
VkDeviceSize offset,
void *pUserData);
void CalculateVirtualBlockStats(VmaVirtualBlock virtualBlock, StatInfo *pStatInfo);
void BuildVirtualBlockStatsString(VmaVirtualBlock virtualBlock,
char **ppStatsString,
VkBool32 detailedMap);
void FreeVirtualBlockStatsString(VmaVirtualBlock virtualBlock, char *pStatsString);
} // namespace vma
#endif // LIBANGLE_RENDERER_VULKAN_VK_MEM_ALLOC_WRAPPER_H_