diff --git a/docs/html/custom_memory_pools.html b/docs/html/custom_memory_pools.html index 573c0fb..017fcf6 100644 --- a/docs/html/custom_memory_pools.html +++ b/docs/html/custom_memory_pools.html @@ -80,7 +80,11 @@ $(function() {
Example:
You have to free all allocations made from this pool before destroying it.
-When creating a pool, you must explicitly specify memory type index. To find the one suitable for your buffers or images, you can use code similar to the following:
+Dummy buffer is needed to query driver for memReq.memoryTypeBits
. Memory is never allocated for this buffer. You should fill structures dummyBufCreateInfo
and allocCreateInfo
with the same parameters as you are going to use for buffers created in your pool.
Enumerator | |
---|---|
VMA_MEMORY_USAGE_UNKNOWN | No intended memory usage specified. Use other members of VmaAllocationCreateInfo to specify your requirements. |
VMA_MEMORY_USAGE_GPU_ONLY | Memory will be used on device only, so fast access from the device is preferred. It usually means device-local GPU (video) memory. No need to be mappable on host. + |
VMA_MEMORY_USAGE_GPU_ONLY | Memory will be used on device only, so fast access from the device is preferred. It usually means device-local GPU (video) memory. No need to be mappable on host. It is roughly equivalent of D3D12_HEAP_TYPE_DEFAULT. Usage:
|
VMA_MEMORY_USAGE_CPU_ONLY | Memory will be mappable on host. It usually means CPU (system) memory. Resources created in this pool are still accessible to the device, but access to them can be slower. Guarantees to be |
VMA_MEMORY_USAGE_CPU_ONLY | Memory will be mappable on host. It usually means CPU (system) memory. Resources created in this pool are still accessible to the device, but access to them can be slower. Guarantees to be Usage: Staging copy of resources used as transfer source. |
VMA_MEMORY_USAGE_CPU_TO_GPU | Memory that is both mappable on host (guarantees to be Usage: Resources written frequently by host (dynamic), read by device. E.g. textures, vertex buffers, uniform buffers updated every frame or every draw call. |
VMA_MEMORY_USAGE_GPU_TO_CPU | Memory mappable on host (guarantees to be |
VMA_MEMORY_USAGE_GPU_TO_CPU | Memory mappable on host (guarantees to be Usage:
vk_mem_alloc.h
-Go to the documentation of this file. 1655 // Define this macro to 1 to make the library use STL containers instead of its own implementation. 1893 // Aligns given value up to nearest multiply of align value. For example: VmaAlignUp(11, 8) = 16. 1952 Algorithm is based on "Vulkan 1.0.39 - A Specification (with all registered Vulkan extensions)" 1961 VMA_ASSERT(resourceAOffset + resourceASize <= resourceBOffset && resourceASize > 0 && pageSize > 0); 2021 // Helper RAII class to lock a mutex in constructor and unlock it in destructor (at the end of scope). 2048 #define VMA_DEBUG_GLOBAL_MUTEX_LOCK VmaMutexLock debugGlobalMutexLock(gDebugGlobalMutex, true); 2087 static void* VmaMalloc(const VkAllocationCallbacks* pAllocationCallbacks, size_t size, size_t alignment) 2131 #define vma_new_array(allocator, type, count) new(VmaAllocateArray<type>((allocator), (count)))(type) 2141 static void vma_delete_array(const VkAllocationCallbacks* pAllocationCallbacks, T* ptr, size_t count) 2162 template<typename U> VmaStlAllocator(const VmaStlAllocator<U>& src) : m_pCallbacks(src.m_pCallbacks) { } 2226 m_pArray(src.m_Count ? (T*)VmaAllocateArray<T>(src.m_Allocator.m_pCallbacks, src.m_Count) : VMA_NULL), 2327 T* const newArray = newCapacity ? VmaAllocateArray<T>(m_Allocator.m_pCallbacks, newCapacity) : VMA_NULL; 2507 VmaPoolAllocator<T>::VmaPoolAllocator(const VkAllocationCallbacks* pAllocationCallbacks, size_t itemsPerBlock) : 3056 iterator insert(iterator it, const T& value) { return iterator(&m_RawList, m_RawList.InsertBefore(it.m_pItem, value)); } 3075 std::unordered_map< KeyT, ValueT, std::hash<KeyT>, std::equal_to<KeyT>, VmaStlAllocator< std::pair<KeyT, ValueT> > > 3117 bool operator()(const VmaPair<FirstT, SecondT>& lhs, const VmaPair<FirstT, SecondT>& rhs) const 3202 VMA_ASSERT((m_MapCount & ~MAP_COUNT_FLAG_PERSISTENT_MAP) == 0 && "Allocation was not unmapped before destruction."); 3278 VmaSuballocationType GetSuballocationType() const { return (VmaSuballocationType)m_SuballocationType; } 3337 // Bits with mask 0x7F, used only when ALLOCATION_TYPE_DEDICATED, are reference counter for vmaMapMemory()/vmaUnmapMemory(). 3403 VkDeviceSize sumItemSize; // Sum size of items to make lost that overlap with proposed allocation. 3480 VmaVector< VmaSuballocationList::iterator, VmaStlAllocator< VmaSuballocationList::iterator > > m_FreeSuballocationsBySize; 3484 // Checks if requested suballocation with given parameters can be placed in given pFreeSuballocItem. 3783 if(pLhsBlockInfo->m_pBlock->m_Metadata.GetSumFreeSize() < pRhsBlockInfo->m_pBlock->m_Metadata.GetSumFreeSize()) 3925 VkResult AllocateVulkanMemory(const VkMemoryAllocateInfo* pAllocateInfo, VkDeviceMemory* pMemory); 4027 VmaStringBuilder(VmaAllocator alloc) : m_Data(VmaStlAllocator<char>(alloc->GetAllocationCallbacks())) { } 4131 VmaJsonWriter::VmaJsonWriter(const VkAllocationCallbacks* pAllocationCallbacks, VmaStringBuilder& sb) : 4499 // Setting hAllocation.LastUseFrameIndex atomic to VMA_FRAME_INDEX_LOST is enough to mark it as LOST. 4691 m_FreeSuballocationsBySize(VmaStlAllocator<VmaSuballocationList::iterator>(hAllocator->GetAllocationCallbacks())) 4867 inoutStats.unusedRangeSizeMax = VMA_MAX(inoutStats.unusedRangeSizeMax, GetUnusedRangeSizeMax()); 5115 uint32_t VmaBlockMetadata::MakeAllocationsLost(uint32_t currentFrameIndex, uint32_t frameInUseCount) 5158 // If there are any free bytes remaining at the end, insert new free suballocation after current one. 5172 // If there are any free bytes remaining at the beginning, insert new free suballocation before current one. 5301 const VkDeviceSize alignment = VMA_MAX(allocAlignment, static_cast<VkDeviceSize>(VMA_DEBUG_ALIGNMENT)); 5314 if(VmaBlocksOnSamePage(prevSuballoc.offset, prevSuballoc.size, *pOffset, bufferImageGranularity)) 5333 // If yes, return false - this function should be called for another suballocItem as starting point. 5448 const VkDeviceSize alignment = VMA_MAX(allocAlignment, static_cast<VkDeviceSize>(VMA_DEBUG_ALIGNMENT)); 5461 if(VmaBlocksOnSamePage(prevSuballoc.offset, prevSuballoc.size, *pOffset, bufferImageGranularity)) 5488 // Fail if requested size plus margin before and after is bigger than size of this suballocation. 5539 VmaSuballocationList::iterator VmaBlockMetadata::FreeSuballocation(VmaSuballocationList::iterator suballocItem) 5660 VMA_ASSERT(m_MapCount == 0 && "VkDeviceMemory block is being destroyed while it is still mapped."); 5663 VkResult VmaDeviceMemoryMapping::Map(VmaAllocator hAllocator, VkDeviceMemory hMemory, void **ppData) 5741 VMA_ASSERT(m_Metadata.IsEmpty() && "Some allocations were not freed before destruction of this memory block!"); 5786 inoutInfo.unusedRangeSizeMin = VMA_MIN(inoutInfo.unusedRangeSizeMin, srcInfo.unusedRangeSizeMin); 5787 inoutInfo.unusedRangeSizeMax = VMA_MAX(inoutInfo.unusedRangeSizeMax, srcInfo.unusedRangeSizeMax); 5807 (createInfo.flags & VMA_POOL_CREATE_IGNORE_BUFFER_IMAGE_GRANULARITY_BIT) != 0 ? 1 : hAllocator->GetBufferImageGranularity(), 5898 const bool isUserDataString = (createInfo.flags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0; 6044 const bool canMakeOtherLost = (createInfo.flags & VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT) != 0; 6264 VmaDeviceMemoryBlock* const pBlock = vma_new(m_hAllocator, VmaDeviceMemoryBlock)(m_hAllocator); 6427 lostAllocationCount += pBlock->m_Metadata.MakeAllocationsLost(currentFrameIndex, m_FrameInUseCount); 6488 VkResult VmaDefragmentator::BlockInfo::EnsureMapping(VmaAllocator hAllocator, void** ppMappedData) 6532 // 1.1. Start from last to first m_Blocks - they are sorted from most "destination" to most "source". 6533 // 1.2. Then start from last to first m_Allocations - they are sorted from largest to smallest. 6609 pDstBlockInfo->m_pBlock->m_Metadata.Alloc(dstAllocRequest, suballocType, size, allocInfo.m_hAllocation); 6612 allocInfo.m_hAllocation->ChangeBlockAllocation(pDstBlockInfo->m_pBlock, dstAllocRequest.offset); 6662 BlockInfo* pBlockInfo = vma_new(m_hAllocator, BlockInfo)(m_hAllocator->GetAllocationCallbacks()); 6670 // Move allocation infos from m_Allocations to appropriate m_Blocks[memTypeIndex].m_Allocations. 6671 for(size_t blockIndex = 0, allocCount = m_Allocations.size(); blockIndex < allocCount; ++blockIndex) 6674 // Now as we are inside VmaBlockVector::m_Mutex, we can make final check if this allocation was not lost. 6678 BlockInfoVector::iterator it = VmaBinaryFindFirstNotLess(m_Blocks.begin(), m_Blocks.end(), pBlock, BlockPointerLess()); 6698 // Sort m_Blocks this time by the main criterium, from most "destination" to most "source" blocks. 6741 m_UseKhrDedicatedAllocation((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT) != 0), 6773 (*m_VulkanFunctions.vkGetPhysicalDeviceProperties)(m_PhysicalDevice, &m_PhysicalDeviceProperties); 6777 pCreateInfo->preferredLargeHeapBlockSize : static_cast<VkDeviceSize>(VMA_DEFAULT_LARGE_HEAP_BLOCK_SIZE); 6810 m_pDedicatedAllocations[memTypeIndex] = vma_new(this, AllocationVectorType)(VmaStlAllocator<VmaAllocation>(GetAllocationCallbacks())); 6845 (PFN_vkGetBufferMemoryRequirements2KHR)vkGetDeviceProcAddr(m_hDevice, "vkGetBufferMemoryRequirements2KHR"); 6847 (PFN_vkGetImageMemoryRequirements2KHR)vkGetDeviceProcAddr(m_hDevice, "vkGetImageMemoryRequirements2KHR"); 6852 if(pVulkanFunctions->funcName != VMA_NULL) m_VulkanFunctions.funcName = pVulkanFunctions->funcName; 6924 (m_MemProps.memoryTypes[memTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0) 6936 // Heuristics: Allocate dedicated memory if requested size if greater than half of preferred block size. 7030 VkMemoryDedicatedAllocateInfoKHR dedicatedAllocInfo = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR }; 7074 (*pAllocation)->InitDedicatedAllocation(memTypeIndex, hMemory, suballocType, pMappedData, size); 7098 VkBufferMemoryRequirementsInfo2KHR memReqInfo = { VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2_KHR }; 7101 VkMemoryDedicatedRequirementsKHR memDedicatedReq = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR }; 7128 VkImageMemoryRequirementsInfo2KHR memReqInfo = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2_KHR }; 7131 VkMemoryDedicatedRequirementsKHR memDedicatedReq = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR }; 7163 VMA_ASSERT(0 && "Specifying VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT together with VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT makes no sense."); 7169 VMA_ASSERT(0 && "Specifying VMA_ALLOCATION_CREATE_MAPPED_BIT together with VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT is invalid."); 7176 VMA_ASSERT(0 && "VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT specified while dedicated allocation is required."); 7188 VMA_ASSERT(0 && "Specifying VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT when pool != null is invalid."); 7254 // Not returning res, which is VK_ERROR_FEATURE_NOT_PRESENT, because we already failed to allocate once. 7260 // Can't find any single memory type maching requirements. res is VK_ERROR_FEATURE_NOT_PRESENT. 7336 for(size_t allocIndex = 0, allocCount = pDedicatedAllocVector->size(); allocIndex < allocCount; ++allocIndex) 7387 ((m_MemProps.memoryTypes[memTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0) && 7405 VmaDefragmentator* const pDefragmentator = pAllocBlockVector->EnsureDefragmentator(this, currentFrameIndex); 7431 if((m_MemProps.memoryTypes[memTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0) 7460 if((m_MemProps.memoryTypes[memTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0) 7469 void VmaAllocator_T::GetAllocationInfo(VmaAllocation hAllocation, VmaAllocationInfo* pAllocationInfo) 7592 VkResult VmaAllocator_T::AllocateVulkanMemory(const VkMemoryAllocateInfo* pAllocateInfo, VkDeviceMemory* pMemory) 7602 res = (*m_VulkanFunctions.vkAllocateMemory)(m_hDevice, pAllocateInfo, GetAllocationCallbacks(), pMemory); 7615 res = (*m_VulkanFunctions.vkAllocateMemory)(m_hDevice, pAllocateInfo, GetAllocationCallbacks(), pMemory); 7620 (*m_DeviceMemoryCallbacks.pfnAllocate)(this, pAllocateInfo->memoryTypeIndex, *pMemory, pAllocateInfo->allocationSize); 7626 void VmaAllocator_T::FreeVulkanMemory(uint32_t memoryType, VkDeviceSize size, VkDeviceMemory hMemory) 7953 if((allocator->m_MemProps.memoryHeaps[heapIndex].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0) 8358 return allocator->Defragment(pAllocations, allocationCount, pAllocationsChanged, pDefragmentationInfo, pDefragmentationStats); 8440 (*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, *pBuffer, allocator->GetAllocationCallbacks()); 8444 (*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, *pBuffer, allocator->GetAllocationCallbacks()); 8464 (*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, buffer, allocator->GetAllocationCallbacks()); 8500 res = AllocateMemoryForImage(allocator, *pImage, pAllocationCreateInfo, suballocType, pAllocation); 8520 (*allocator->GetVulkanFunctions().vkDestroyImage)(allocator->m_hDevice, *pImage, allocator->GetAllocationCallbacks()); 8524 (*allocator->GetVulkanFunctions().vkDestroyImage)(allocator->m_hDevice, *pImage, allocator->GetAllocationCallbacks()); 8544 (*allocator->GetVulkanFunctions().vkDestroyImage)(allocator->m_hDevice, image, allocator->GetAllocationCallbacks()); PFN_vkGetPhysicalDeviceProperties vkGetPhysicalDeviceProperties Definition: vk_mem_alloc.h:758 Set this flag if the allocation should have its own memory block. Definition: vk_mem_alloc.h:1009 1693 // Define this macro to 1 to make the library use STL containers instead of its own implementation. 1931 // Aligns given value up to nearest multiply of align value. For example: VmaAlignUp(11, 8) = 16. 1990 Algorithm is based on "Vulkan 1.0.39 - A Specification (with all registered Vulkan extensions)" 1999 VMA_ASSERT(resourceAOffset + resourceASize <= resourceBOffset && resourceASize > 0 && pageSize > 0); 2059 // Helper RAII class to lock a mutex in constructor and unlock it in destructor (at the end of scope). 2086 #define VMA_DEBUG_GLOBAL_MUTEX_LOCK VmaMutexLock debugGlobalMutexLock(gDebugGlobalMutex, true); 2125 static void* VmaMalloc(const VkAllocationCallbacks* pAllocationCallbacks, size_t size, size_t alignment) 2169 #define vma_new_array(allocator, type, count) new(VmaAllocateArray<type>((allocator), (count)))(type) 2179 static void vma_delete_array(const VkAllocationCallbacks* pAllocationCallbacks, T* ptr, size_t count) 2200 template<typename U> VmaStlAllocator(const VmaStlAllocator<U>& src) : m_pCallbacks(src.m_pCallbacks) { } 2264 m_pArray(src.m_Count ? (T*)VmaAllocateArray<T>(src.m_Allocator.m_pCallbacks, src.m_Count) : VMA_NULL), 2365 T* const newArray = newCapacity ? VmaAllocateArray<T>(m_Allocator.m_pCallbacks, newCapacity) : VMA_NULL; 2545 VmaPoolAllocator<T>::VmaPoolAllocator(const VkAllocationCallbacks* pAllocationCallbacks, size_t itemsPerBlock) : 3094 iterator insert(iterator it, const T& value) { return iterator(&m_RawList, m_RawList.InsertBefore(it.m_pItem, value)); } 3113 std::unordered_map< KeyT, ValueT, std::hash<KeyT>, std::equal_to<KeyT>, VmaStlAllocator< std::pair<KeyT, ValueT> > > 3155 bool operator()(const VmaPair<FirstT, SecondT>& lhs, const VmaPair<FirstT, SecondT>& rhs) const 3240 VMA_ASSERT((m_MapCount & ~MAP_COUNT_FLAG_PERSISTENT_MAP) == 0 && "Allocation was not unmapped before destruction."); 3311 VmaSuballocationType GetSuballocationType() const { return (VmaSuballocationType)m_SuballocationType; } 3436 VkDeviceSize sumItemSize; // Sum size of items to make lost that overlap with proposed allocation. 3514 VmaVector< VmaSuballocationList::iterator, VmaStlAllocator< VmaSuballocationList::iterator > > m_FreeSuballocationsBySize; 3518 // Checks if requested suballocation with given parameters can be placed in given pFreeSuballocItem. 3817 if(pLhsBlockInfo->m_pBlock->m_Metadata.GetSumFreeSize() < pRhsBlockInfo->m_pBlock->m_Metadata.GetSumFreeSize()) 3959 VkResult AllocateVulkanMemory(const VkMemoryAllocateInfo* pAllocateInfo, VkDeviceMemory* pMemory); 4061 VmaStringBuilder(VmaAllocator alloc) : m_Data(VmaStlAllocator<char>(alloc->GetAllocationCallbacks())) { } 4165 VmaJsonWriter::VmaJsonWriter(const VkAllocationCallbacks* pAllocationCallbacks, VmaStringBuilder& sb) : 4555 // Setting hAllocation.LastUseFrameIndex atomic to VMA_FRAME_INDEX_LOST is enough to mark it as LOST. 4747 m_FreeSuballocationsBySize(VmaStlAllocator<VmaSuballocationList::iterator>(hAllocator->GetAllocationCallbacks())) 4938 inoutStats.unusedRangeSizeMax = VMA_MAX(inoutStats.unusedRangeSizeMax, GetUnusedRangeSizeMax()); 5186 uint32_t VmaBlockMetadata::MakeAllocationsLost(uint32_t currentFrameIndex, uint32_t frameInUseCount) 5229 // If there are any free bytes remaining at the end, insert new free suballocation after current one. 5243 // If there are any free bytes remaining at the beginning, insert new free suballocation before current one. 5388 const VkDeviceSize alignment = VMA_MAX(allocAlignment, static_cast<VkDeviceSize>(VMA_DEBUG_ALIGNMENT)); 5401 if(VmaBlocksOnSamePage(prevSuballoc.offset, prevSuballoc.size, *pOffset, bufferImageGranularity)) 5420 // If yes, return false - this function should be called for another suballocItem as starting point. 5535 const VkDeviceSize alignment = VMA_MAX(allocAlignment, static_cast<VkDeviceSize>(VMA_DEBUG_ALIGNMENT)); 5548 if(VmaBlocksOnSamePage(prevSuballoc.offset, prevSuballoc.size, *pOffset, bufferImageGranularity)) 5575 // Fail if requested size plus margin before and after is bigger than size of this suballocation. 5626 VmaSuballocationList::iterator VmaBlockMetadata::FreeSuballocation(VmaSuballocationList::iterator suballocItem) 5747 VMA_ASSERT(m_MapCount == 0 && "VkDeviceMemory block is being destroyed while it is still mapped."); 5750 VkResult VmaDeviceMemoryMapping::Map(VmaAllocator hAllocator, VkDeviceMemory hMemory, uint32_t count, void **ppData) 5789 void VmaDeviceMemoryMapping::Unmap(VmaAllocator hAllocator, VkDeviceMemory hMemory, uint32_t count) 5839 VMA_ASSERT(m_Metadata.IsEmpty() && "Some allocations were not freed before destruction of this memory block!"); 5884 inoutInfo.unusedRangeSizeMin = VMA_MIN(inoutInfo.unusedRangeSizeMin, srcInfo.unusedRangeSizeMin); 5885 inoutInfo.unusedRangeSizeMax = VMA_MAX(inoutInfo.unusedRangeSizeMax, srcInfo.unusedRangeSizeMax); 5905 (createInfo.flags & VMA_POOL_CREATE_IGNORE_BUFFER_IMAGE_GRANULARITY_BIT) != 0 ? 1 : hAllocator->GetBufferImageGranularity(), 5996 const bool isUserDataString = (createInfo.flags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0; 6142 const bool canMakeOtherLost = (createInfo.flags & VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT) != 0; 6362 VmaDeviceMemoryBlock* const pBlock = vma_new(m_hAllocator, VmaDeviceMemoryBlock)(m_hAllocator); 6525 lostAllocationCount += pBlock->m_Metadata.MakeAllocationsLost(currentFrameIndex, m_FrameInUseCount); 6586 VkResult VmaDefragmentator::BlockInfo::EnsureMapping(VmaAllocator hAllocator, void** ppMappedData) 6630 // 1.1. Start from last to first m_Blocks - they are sorted from most "destination" to most "source". 6631 // 1.2. Then start from last to first m_Allocations - they are sorted from largest to smallest. 6707 pDstBlockInfo->m_pBlock->m_Metadata.Alloc(dstAllocRequest, suballocType, size, allocInfo.m_hAllocation); 6710 allocInfo.m_hAllocation->ChangeBlockAllocation(m_hAllocator, pDstBlockInfo->m_pBlock, dstAllocRequest.offset); 6760 BlockInfo* pBlockInfo = vma_new(m_hAllocator, BlockInfo)(m_hAllocator->GetAllocationCallbacks()); 6768 // Move allocation infos from m_Allocations to appropriate m_Blocks[memTypeIndex].m_Allocations. 6769 for(size_t blockIndex = 0, allocCount = m_Allocations.size(); blockIndex < allocCount; ++blockIndex) 6772 // Now as we are inside VmaBlockVector::m_Mutex, we can make final check if this allocation was not lost. 6776 BlockInfoVector::iterator it = VmaBinaryFindFirstNotLess(m_Blocks.begin(), m_Blocks.end(), pBlock, BlockPointerLess()); 6796 // Sort m_Blocks this time by the main criterium, from most "destination" to most "source" blocks. 6839 m_UseKhrDedicatedAllocation((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT) != 0), 6871 (*m_VulkanFunctions.vkGetPhysicalDeviceProperties)(m_PhysicalDevice, &m_PhysicalDeviceProperties); 6875 pCreateInfo->preferredLargeHeapBlockSize : static_cast<VkDeviceSize>(VMA_DEFAULT_LARGE_HEAP_BLOCK_SIZE); 6908 m_pDedicatedAllocations[memTypeIndex] = vma_new(this, AllocationVectorType)(VmaStlAllocator<VmaAllocation>(GetAllocationCallbacks())); 6943 (PFN_vkGetBufferMemoryRequirements2KHR)vkGetDeviceProcAddr(m_hDevice, "vkGetBufferMemoryRequirements2KHR"); 6945 (PFN_vkGetImageMemoryRequirements2KHR)vkGetDeviceProcAddr(m_hDevice, "vkGetImageMemoryRequirements2KHR"); 6950 if(pVulkanFunctions->funcName != VMA_NULL) m_VulkanFunctions.funcName = pVulkanFunctions->funcName; 7022 (m_MemProps.memoryTypes[memTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0) 7034 // Heuristics: Allocate dedicated memory if requested size if greater than half of preferred block size. 7128 VkMemoryDedicatedAllocateInfoKHR dedicatedAllocInfo = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR }; 7172 (*pAllocation)->InitDedicatedAllocation(memTypeIndex, hMemory, suballocType, pMappedData, size); 7196 VkBufferMemoryRequirementsInfo2KHR memReqInfo = { VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2_KHR }; 7199 VkMemoryDedicatedRequirementsKHR memDedicatedReq = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR }; 7226 VkImageMemoryRequirementsInfo2KHR memReqInfo = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2_KHR }; 7229 VkMemoryDedicatedRequirementsKHR memDedicatedReq = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR }; 7261 VMA_ASSERT(0 && "Specifying VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT together with VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT makes no sense."); 7267 VMA_ASSERT(0 && "Specifying VMA_ALLOCATION_CREATE_MAPPED_BIT together with VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT is invalid."); 7274 VMA_ASSERT(0 && "VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT specified while dedicated allocation is required."); 7286 VMA_ASSERT(0 && "Specifying VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT when pool != null is invalid."); 7352 // Not returning res, which is VK_ERROR_FEATURE_NOT_PRESENT, because we already failed to allocate once. 7358 // Can't find any single memory type maching requirements. res is VK_ERROR_FEATURE_NOT_PRESENT. 7434 for(size_t allocIndex = 0, allocCount = pDedicatedAllocVector->size(); allocIndex < allocCount; ++allocIndex) 7485 ((m_MemProps.memoryTypes[memTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0) && 7503 VmaDefragmentator* const pDefragmentator = pAllocBlockVector->EnsureDefragmentator(this, currentFrameIndex); 7529 if((m_MemProps.memoryTypes[memTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0) 7558 if((m_MemProps.memoryTypes[memTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0) 7567 void VmaAllocator_T::GetAllocationInfo(VmaAllocation hAllocation, VmaAllocationInfo* pAllocationInfo) 7690 VkResult VmaAllocator_T::AllocateVulkanMemory(const VkMemoryAllocateInfo* pAllocateInfo, VkDeviceMemory* pMemory) 7700 res = (*m_VulkanFunctions.vkAllocateMemory)(m_hDevice, pAllocateInfo, GetAllocationCallbacks(), pMemory); 7713 res = (*m_VulkanFunctions.vkAllocateMemory)(m_hDevice, pAllocateInfo, GetAllocationCallbacks(), pMemory); 7718 (*m_DeviceMemoryCallbacks.pfnAllocate)(this, pAllocateInfo->memoryTypeIndex, *pMemory, pAllocateInfo->allocationSize); 7724 void VmaAllocator_T::FreeVulkanMemory(uint32_t memoryType, VkDeviceSize size, VkDeviceMemory hMemory) 8051 if((allocator->m_MemProps.memoryHeaps[heapIndex].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0) 8456 return allocator->Defragment(pAllocations, allocationCount, pAllocationsChanged, pDefragmentationInfo, pDefragmentationStats); 8538 (*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, *pBuffer, allocator->GetAllocationCallbacks()); 8542 (*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, *pBuffer, allocator->GetAllocationCallbacks()); 8562 (*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, buffer, allocator->GetAllocationCallbacks()); 8598 res = AllocateMemoryForImage(allocator, *pImage, pAllocationCreateInfo, suballocType, pAllocation); 8618 (*allocator->GetVulkanFunctions().vkDestroyImage)(allocator->m_hDevice, *pImage, allocator->GetAllocationCallbacks()); 8622 (*allocator->GetVulkanFunctions().vkDestroyImage)(allocator->m_hDevice, *pImage, allocator->GetAllocationCallbacks()); 8642 (*allocator->GetVulkanFunctions().vkDestroyImage)(allocator->m_hDevice, image, allocator->GetAllocationCallbacks()); PFN_vkGetPhysicalDeviceProperties vkGetPhysicalDeviceProperties Definition: vk_mem_alloc.h:793 Set this flag if the allocation should have its own memory block. Definition: vk_mem_alloc.h:1047 void vmaUnmapMemory(VmaAllocator allocator, VmaAllocation allocation) Unmaps memory represented by given allocation, mapped previously using vmaMapMemory(). VkPhysicalDevice physicalDevice Vulkan physical device. Definition: vk_mem_alloc.h:783 VkPhysicalDevice physicalDevice Vulkan physical device. Definition: vk_mem_alloc.h:818 VkResult vmaDefragment(VmaAllocator allocator, VmaAllocation *pAllocations, size_t allocationCount, VkBool32 *pAllocationsChanged, const VmaDefragmentationInfo *pDefragmentationInfo, VmaDefragmentationStats *pDefragmentationStats) Compacts memory by moving allocations. void vmaFreeStatsString(VmaAllocator allocator, char *pStatsString) Definition: vk_mem_alloc.h:968 VkDeviceMemory deviceMemory Handle to Vulkan memory object. Definition: vk_mem_alloc.h:1277 VmaAllocatorCreateFlags flags Flags for created allocator. Use VmaAllocatorCreateFlagBits enum. Definition: vk_mem_alloc.h:780 uint32_t maxAllocationsToMove Maximum number of allocations that can be moved to different place. Definition: vk_mem_alloc.h:1443 Use this flag if you always allocate only buffers and linear images or only optimal images out of thi... Definition: vk_mem_alloc.h:1147 Definition: vk_mem_alloc.h:1004 VkDeviceMemory deviceMemory Handle to Vulkan memory object. Definition: vk_mem_alloc.h:1315 VmaAllocatorCreateFlags flags Flags for created allocator. Use VmaAllocatorCreateFlagBits enum. Definition: vk_mem_alloc.h:815 uint32_t maxAllocationsToMove Maximum number of allocations that can be moved to different place. Definition: vk_mem_alloc.h:1481 Use this flag if you always allocate only buffers and linear images or only optimal images out of thi... Definition: vk_mem_alloc.h:1185 void vmaMakePoolAllocationsLost(VmaAllocator allocator, VmaPool pool, size_t *pLostAllocationCount) Marks all allocations in given pool as lost if they are not used in current frame or VmaPoolCreateInf... VkDeviceSize size Total amount of VkDeviceMemory allocated from Vulkan for this pool, in bytes. Definition: vk_mem_alloc.h:1201 Definition: vk_mem_alloc.h:1046 VkMemoryPropertyFlags preferredFlags Flags that preferably should be set in a memory type chosen for an allocation. Definition: vk_mem_alloc.h:1084 Definition: vk_mem_alloc.h:993 const VkAllocationCallbacks * pAllocationCallbacks Custom CPU memory allocation callbacks. Definition: vk_mem_alloc.h:792 VkDeviceSize size Total amount of VkDeviceMemory allocated from Vulkan for this pool, in bytes. Definition: vk_mem_alloc.h:1239 Definition: vk_mem_alloc.h:1084 VkMemoryPropertyFlags preferredFlags Flags that preferably should be set in a memory type chosen for an allocation. Definition: vk_mem_alloc.h:1122 Definition: vk_mem_alloc.h:1031 const VkAllocationCallbacks * pAllocationCallbacks Custom CPU memory allocation callbacks. Definition: vk_mem_alloc.h:827 void vmaCalculateStats(VmaAllocator allocator, VmaStats *pStats) Retrieves statistics from current state of the Allocator. const VmaVulkanFunctions * pVulkanFunctions Pointers to Vulkan functions. Can be null if you leave define VMA_STATIC_VULKAN_FUNCTIONS 1... Definition: vk_mem_alloc.h:845 const VmaVulkanFunctions * pVulkanFunctions Pointers to Vulkan functions. Can be null if you leave define VMA_STATIC_VULKAN_FUNCTIONS 1... Definition: vk_mem_alloc.h:880 VmaAllocationCreateFlagBits Flags to be passed as VmaAllocationCreateInfo::flags. Definition: vk_mem_alloc.h:997 VmaAllocationCreateFlagBits Flags to be passed as VmaAllocationCreateInfo::flags. Definition: vk_mem_alloc.h:1035 void vmaGetAllocationInfo(VmaAllocator allocator, VmaAllocation allocation, VmaAllocationInfo *pAllocationInfo) Returns current information about specified allocation. PFN_vkBindImageMemory vkBindImageMemory Definition: vk_mem_alloc.h:765 VkDeviceSize unusedBytes Total number of bytes occupied by unused ranges. Definition: vk_mem_alloc.h:909 PFN_vkGetImageMemoryRequirements2KHR vkGetImageMemoryRequirements2KHR Definition: vk_mem_alloc.h:773 Statistics returned by function vmaDefragment(). Definition: vk_mem_alloc.h:1447 PFN_vkBindImageMemory vkBindImageMemory Definition: vk_mem_alloc.h:800 VkDeviceSize unusedBytes Total number of bytes occupied by unused ranges. Definition: vk_mem_alloc.h:944 PFN_vkGetImageMemoryRequirements2KHR vkGetImageMemoryRequirements2KHR Definition: vk_mem_alloc.h:808 Statistics returned by function vmaDefragment(). Definition: vk_mem_alloc.h:1485 void vmaFreeMemory(VmaAllocator allocator, VmaAllocation allocation) Frees memory previously allocated using vmaAllocateMemory(), vmaAllocateMemoryForBuffer(), or vmaAllocateMemoryForImage(). uint32_t frameInUseCount Maximum number of additional frames that are in use at the same time as current frame. Definition: vk_mem_alloc.h:809 uint32_t deviceMemoryBlocksFreed Number of empty VkDeviceMemory objects that have been released to the system. Definition: vk_mem_alloc.h:1455 VmaAllocationCreateFlags flags Use VmaAllocationCreateFlagBits enum. Definition: vk_mem_alloc.h:1068 VkDeviceSize maxBytesToMove Maximum total numbers of bytes that can be copied while moving allocations to different places... Definition: vk_mem_alloc.h:1438 PFN_vkGetBufferMemoryRequirements vkGetBufferMemoryRequirements Definition: vk_mem_alloc.h:766 void(VKAPI_PTR * PFN_vmaAllocateDeviceMemoryFunction)(VmaAllocator allocator, uint32_t memoryType, VkDeviceMemory memory, VkDeviceSize size) Callback function called after successful vkAllocateMemory. Definition: vk_mem_alloc.h:693 Definition: vk_mem_alloc.h:1149 VkDeviceSize size Size of this allocation, in bytes. Definition: vk_mem_alloc.h:1287 uint32_t frameInUseCount Maximum number of additional frames that are in use at the same time as current frame. Definition: vk_mem_alloc.h:844 uint32_t deviceMemoryBlocksFreed Number of empty VkDeviceMemory objects that have been released to the system. Definition: vk_mem_alloc.h:1493 VmaAllocationCreateFlags flags Use VmaAllocationCreateFlagBits enum. Definition: vk_mem_alloc.h:1106 VkDeviceSize maxBytesToMove Maximum total numbers of bytes that can be copied while moving allocations to different places... Definition: vk_mem_alloc.h:1476 PFN_vkGetBufferMemoryRequirements vkGetBufferMemoryRequirements Definition: vk_mem_alloc.h:801 void(VKAPI_PTR * PFN_vmaAllocateDeviceMemoryFunction)(VmaAllocator allocator, uint32_t memoryType, VkDeviceMemory memory, VkDeviceSize size) Callback function called after successful vkAllocateMemory. Definition: vk_mem_alloc.h:728 Definition: vk_mem_alloc.h:1187 VkDeviceSize size Size of this allocation, in bytes. Definition: vk_mem_alloc.h:1325 void vmaGetMemoryTypeProperties(VmaAllocator allocator, uint32_t memoryTypeIndex, VkMemoryPropertyFlags *pFlags) Given Memory Type Index, returns Property Flags of this memory type. void * pUserData Custom general-purpose pointer that will be stored in VmaAllocation, can be read as VmaAllocationInfo... Definition: vk_mem_alloc.h:1105 size_t minBlockCount Minimum number of blocks to be always allocated in this pool, even if they stay empty. Definition: vk_mem_alloc.h:1171 size_t allocationCount Number of VmaAllocation objects created from this pool that were not destroyed or lost... Definition: vk_mem_alloc.h:1207 void * pUserData Custom general-purpose pointer that will be stored in VmaAllocation, can be read as VmaAllocationInfo... Definition: vk_mem_alloc.h:1143 size_t minBlockCount Minimum number of blocks to be always allocated in this pool, even if they stay empty. Definition: vk_mem_alloc.h:1209 size_t allocationCount Number of VmaAllocation objects created from this pool that were not destroyed or lost... Definition: vk_mem_alloc.h:1245 struct VmaVulkanFunctions VmaVulkanFunctions Pointers to some Vulkan functions - a subset used by the library. Definition: vk_mem_alloc.h:749 uint32_t memoryTypeIndex Vulkan memory type index to allocate this pool from. Definition: vk_mem_alloc.h:1158 Definition: vk_mem_alloc.h:784 uint32_t memoryTypeIndex Vulkan memory type index to allocate this pool from. Definition: vk_mem_alloc.h:1196 VkResult vmaFindMemoryTypeIndex(VmaAllocator allocator, uint32_t memoryTypeBits, const VmaAllocationCreateInfo *pAllocationCreateInfo, uint32_t *pMemoryTypeIndex) struct VmaAllocationInfo VmaAllocationInfo Parameters of VmaAllocation objects, that can be retrieved using function vmaGetAllocationInfo(). Optional configuration parameters to be passed to function vmaDefragment(). Definition: vk_mem_alloc.h:1433 Optional configuration parameters to be passed to function vmaDefragment(). Definition: vk_mem_alloc.h:1471 void vmaDestroyPool(VmaAllocator allocator, VmaPool pool) Destroys VmaPool object and frees Vulkan device memory. VkDeviceSize bytesFreed Total number of bytes that have been released to the system by freeing empty VkDeviceMemory objects... Definition: vk_mem_alloc.h:1451 Definition: vk_mem_alloc.h:984 uint32_t memoryTypeBits Bitmask containing one bit set for every memory type acceptable for this allocation. Definition: vk_mem_alloc.h:1092 PFN_vkBindBufferMemory vkBindBufferMemory Definition: vk_mem_alloc.h:764 VkDeviceSize bytesFreed Total number of bytes that have been released to the system by freeing empty VkDeviceMemory objects... Definition: vk_mem_alloc.h:1489 Definition: vk_mem_alloc.h:1021 uint32_t memoryTypeBits Bitmask containing one bit set for every memory type acceptable for this allocation. Definition: vk_mem_alloc.h:1130 PFN_vkBindBufferMemory vkBindBufferMemory Definition: vk_mem_alloc.h:799 void vmaGetPoolStats(VmaAllocator allocator, VmaPool pool, VmaPoolStats *pPoolStats) Retrieves statistics of existing VmaPool object. struct VmaDefragmentationInfo VmaDefragmentationInfo Optional configuration parameters to be passed to function vmaDefragment(). void(VKAPI_PTR * PFN_vmaFreeDeviceMemoryFunction)(VmaAllocator allocator, uint32_t memoryType, VkDeviceMemory memory, VkDeviceSize size) Callback function called before vkFreeMemory. Definition: vk_mem_alloc.h:699 void(VKAPI_PTR * PFN_vmaFreeDeviceMemoryFunction)(VmaAllocator allocator, uint32_t memoryType, VkDeviceMemory memory, VkDeviceSize size) Callback function called before vkFreeMemory. Definition: vk_mem_alloc.h:734 void vmaSetAllocationUserData(VmaAllocator allocator, VmaAllocation allocation, void *pUserData) Sets pUserData in given allocation to new value. VkResult vmaCreatePool(VmaAllocator allocator, const VmaPoolCreateInfo *pCreateInfo, VmaPool *pPool) Allocates Vulkan device memory and creates VmaPool object. VmaAllocatorCreateFlagBits Flags for created VmaAllocator. Definition: vk_mem_alloc.h:720 VmaAllocatorCreateFlagBits Flags for created VmaAllocator. Definition: vk_mem_alloc.h:755 Allocator and all objects created from it will not be synchronized internally, so you must guarantee ... Definition: vk_mem_alloc.h:725 uint32_t allocationsMoved Number of allocations that have been moved to different places. Definition: vk_mem_alloc.h:1453 Allocator and all objects created from it will not be synchronized internally, so you must guarantee ... Definition: vk_mem_alloc.h:760 uint32_t allocationsMoved Number of allocations that have been moved to different places. Definition: vk_mem_alloc.h:1491 void vmaCreateLostAllocation(VmaAllocator allocator, VmaAllocation *pAllocation) Creates new allocation that is in lost state from the beginning. VkMemoryPropertyFlags requiredFlags Flags that must be set in a Memory Type chosen for an allocation. Definition: vk_mem_alloc.h:1079 VkDeviceSize unusedRangeSizeMax Size of the largest continuous free memory region. Definition: vk_mem_alloc.h:1217 VkMemoryPropertyFlags requiredFlags Flags that must be set in a Memory Type chosen for an allocation. Definition: vk_mem_alloc.h:1117 VkDeviceSize unusedRangeSizeMax Size of the largest continuous free memory region. Definition: vk_mem_alloc.h:1255 void vmaBuildStatsString(VmaAllocator allocator, char **ppStatsString, VkBool32 detailedMap) Builds and returns statistics as string in JSON format. PFN_vkGetPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties Definition: vk_mem_alloc.h:759 Calculated statistics of memory usage in entire allocator. Definition: vk_mem_alloc.h:898 VkDeviceSize blockSize Size of a single VkDeviceMemory block to be allocated as part of this pool, in bytes. Definition: vk_mem_alloc.h:1166 Set of callbacks that the library will call for vkAllocateMemory and vkFreeMemory. Definition: vk_mem_alloc.h:712 PFN_vkGetPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties Definition: vk_mem_alloc.h:794 Calculated statistics of memory usage in entire allocator. Definition: vk_mem_alloc.h:933 VkDeviceSize blockSize Size of a single VkDeviceMemory block to be allocated as part of this pool, in bytes. Definition: vk_mem_alloc.h:1204 Set of callbacks that the library will call for vkAllocateMemory and vkFreeMemory. Definition: vk_mem_alloc.h:747 VkResult vmaCreateBuffer(VmaAllocator allocator, const VkBufferCreateInfo *pBufferCreateInfo, const VmaAllocationCreateInfo *pAllocationCreateInfo, VkBuffer *pBuffer, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo) Definition: vk_mem_alloc.h:1053 PFN_vmaFreeDeviceMemoryFunction pfnFree Optional, can be null. Definition: vk_mem_alloc.h:716 VmaPoolCreateFlags flags Use combination of VmaPoolCreateFlagBits. Definition: vk_mem_alloc.h:1161 Definition: vk_mem_alloc.h:992 Definition: vk_mem_alloc.h:1091 PFN_vmaFreeDeviceMemoryFunction pfnFree Optional, can be null. Definition: vk_mem_alloc.h:751 VmaPoolCreateFlags flags Use combination of VmaPoolCreateFlagBits. Definition: vk_mem_alloc.h:1199 Definition: vk_mem_alloc.h:1030 VkResult vmaCreateImage(VmaAllocator allocator, const VkImageCreateInfo *pImageCreateInfo, const VmaAllocationCreateInfo *pAllocationCreateInfo, VkImage *pImage, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo) Function similar to vmaCreateBuffer(). VmaMemoryUsage usage Intended usage of memory. Definition: vk_mem_alloc.h:1074 Definition: vk_mem_alloc.h:1065 uint32_t blockCount Number of VkDeviceMemory Vulkan memory blocks allocated. Definition: vk_mem_alloc.h:901 size_t maxBlockCount Maximum number of blocks that can be allocated in this pool. Definition: vk_mem_alloc.h:1179 const VmaDeviceMemoryCallbacks * pDeviceMemoryCallbacks Informative callbacks for vkAllocateMemory, vkFreeMemory. Definition: vk_mem_alloc.h:795 size_t unusedRangeCount Number of continuous memory ranges in the pool not used by any VmaAllocation. Definition: vk_mem_alloc.h:1210 VmaPool pool Pool that this allocation should be created in. Definition: vk_mem_alloc.h:1098 VmaMemoryUsage usage Intended usage of memory. Definition: vk_mem_alloc.h:1112 Definition: vk_mem_alloc.h:1103 uint32_t blockCount Number of VkDeviceMemory Vulkan memory blocks allocated. Definition: vk_mem_alloc.h:936 size_t maxBlockCount Maximum number of blocks that can be allocated in this pool. Definition: vk_mem_alloc.h:1217 const VmaDeviceMemoryCallbacks * pDeviceMemoryCallbacks Informative callbacks for vkAllocateMemory, vkFreeMemory. Definition: vk_mem_alloc.h:830 size_t unusedRangeCount Number of continuous memory ranges in the pool not used by any VmaAllocation. Definition: vk_mem_alloc.h:1248 VmaPool pool Pool that this allocation should be created in. Definition: vk_mem_alloc.h:1136 void vmaGetMemoryProperties(VmaAllocator allocator, const VkPhysicalDeviceMemoryProperties **ppPhysicalDeviceMemoryProperties) const VkDeviceSize * pHeapSizeLimit Either NULL or a pointer to an array of limits on maximum number of bytes that can be allocated out o... Definition: vk_mem_alloc.h:833 Set this flag to use a memory that will be persistently mapped and retrieve pointer to it... Definition: vk_mem_alloc.h:1033 PFN_vmaAllocateDeviceMemoryFunction pfnAllocate Optional, can be null. Definition: vk_mem_alloc.h:714 PFN_vkDestroyBuffer vkDestroyBuffer Definition: vk_mem_alloc.h:769 const VkDeviceSize * pHeapSizeLimit Either NULL or a pointer to an array of limits on maximum number of bytes that can be allocated out o... Definition: vk_mem_alloc.h:868 Set this flag to use a memory that will be persistently mapped and retrieve pointer to it... Definition: vk_mem_alloc.h:1071 PFN_vmaAllocateDeviceMemoryFunction pfnAllocate Optional, can be null. Definition: vk_mem_alloc.h:749 PFN_vkDestroyBuffer vkDestroyBuffer Definition: vk_mem_alloc.h:804 VkResult vmaMapMemory(VmaAllocator allocator, VmaAllocation allocation, void **ppData) Maps memory represented by given allocation and returns pointer to it. uint32_t frameInUseCount Maximum number of additional frames that are in use at the same time as current frame. Definition: vk_mem_alloc.h:1193 uint32_t frameInUseCount Maximum number of additional frames that are in use at the same time as current frame. Definition: vk_mem_alloc.h:1231 VkResult vmaAllocateMemoryForImage(VmaAllocator allocator, VkImage image, const VmaAllocationCreateInfo *pCreateInfo, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo) Function similar to vmaAllocateMemoryForBuffer(). struct VmaAllocatorCreateInfo VmaAllocatorCreateInfo Description of a Allocator to be created. void * pUserData Custom general-purpose pointer that was passed as VmaAllocationCreateInfo::pUserData or set using vma... Definition: vk_mem_alloc.h:1301 VkDeviceSize preferredLargeHeapBlockSize Preferred size of a single VkDeviceMemory block to be allocated from large heaps > 1 GiB... Definition: vk_mem_alloc.h:789 VkDeviceSize usedBytes Total number of bytes occupied by all allocations. Definition: vk_mem_alloc.h:907 void * pUserData Custom general-purpose pointer that was passed as VmaAllocationCreateInfo::pUserData or set using vma... Definition: vk_mem_alloc.h:1339 VkDeviceSize preferredLargeHeapBlockSize Preferred size of a single VkDeviceMemory block to be allocated from large heaps > 1 GiB... Definition: vk_mem_alloc.h:824 VkDeviceSize usedBytes Total number of bytes occupied by all allocations. Definition: vk_mem_alloc.h:942 struct VmaDeviceMemoryCallbacks VmaDeviceMemoryCallbacks Set of callbacks that the library will call for vkAllocateMemory and vkFreeMemory. VkDeviceSize offset Offset into deviceMemory object to the beginning of this allocation, in bytes. (deviceMemory, offset) pair is unique to this allocation. Definition: vk_mem_alloc.h:1282 Definition: vk_mem_alloc.h:1061 VkDeviceSize bytesMoved Total number of bytes that have been copied while moving allocations to different places... Definition: vk_mem_alloc.h:1449 Pointers to some Vulkan functions - a subset used by the library. Definition: vk_mem_alloc.h:757 VkDeviceSize offset Offset into deviceMemory object to the beginning of this allocation, in bytes. (deviceMemory, offset) pair is unique to this allocation. Definition: vk_mem_alloc.h:1320 Definition: vk_mem_alloc.h:1099 VkDeviceSize bytesMoved Total number of bytes that have been copied while moving allocations to different places... Definition: vk_mem_alloc.h:1487 Pointers to some Vulkan functions - a subset used by the library. Definition: vk_mem_alloc.h:792 VkResult vmaCreateAllocator(const VmaAllocatorCreateInfo *pCreateInfo, VmaAllocator *pAllocator) Creates Allocator object. PFN_vkGetBufferMemoryRequirements2KHR vkGetBufferMemoryRequirements2KHR Definition: vk_mem_alloc.h:772 uint32_t unusedRangeCount Number of free ranges of memory between allocations. Definition: vk_mem_alloc.h:905 Definition: vk_mem_alloc.h:952 PFN_vkGetBufferMemoryRequirements2KHR vkGetBufferMemoryRequirements2KHR Definition: vk_mem_alloc.h:807 uint32_t unusedRangeCount Number of free ranges of memory between allocations. Definition: vk_mem_alloc.h:940 Definition: vk_mem_alloc.h:987 void vmaGetPhysicalDeviceProperties(VmaAllocator allocator, const VkPhysicalDeviceProperties **ppPhysicalDeviceProperties) uint32_t allocationCount Number of VmaAllocation allocation objects allocated. Definition: vk_mem_alloc.h:903 PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements Definition: vk_mem_alloc.h:767 Set this flag to only try to allocate from existing VkDeviceMemory blocks and never create new such b... Definition: vk_mem_alloc.h:1020 Definition: vk_mem_alloc.h:977 void * pMappedData Pointer to the beginning of this allocation as mapped data. Definition: vk_mem_alloc.h:1296 uint32_t allocationCount Number of VmaAllocation allocation objects allocated. Definition: vk_mem_alloc.h:938 PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements Definition: vk_mem_alloc.h:802 Set this flag to only try to allocate from existing VkDeviceMemory blocks and never create new such b... Definition: vk_mem_alloc.h:1058 Definition: vk_mem_alloc.h:1014 void * pMappedData Pointer to the beginning of this allocation as mapped data. Definition: vk_mem_alloc.h:1334 void vmaDestroyImage(VmaAllocator allocator, VkImage image, VmaAllocation allocation) Destroys Vulkan image and frees allocated memory. Enables usage of VK_KHR_dedicated_allocation extension. Definition: vk_mem_alloc.h:747 Enables usage of VK_KHR_dedicated_allocation extension. Definition: vk_mem_alloc.h:782 struct VmaDefragmentationStats VmaDefragmentationStats Statistics returned by function vmaDefragment(). PFN_vkAllocateMemory vkAllocateMemory Definition: vk_mem_alloc.h:760 Parameters of VmaAllocation objects, that can be retrieved using function vmaGetAllocationInfo(). Definition: vk_mem_alloc.h:1263 PFN_vkAllocateMemory vkAllocateMemory Definition: vk_mem_alloc.h:795 Parameters of VmaAllocation objects, that can be retrieved using function vmaGetAllocationInfo(). Definition: vk_mem_alloc.h:1301 VkResult vmaAllocateMemory(VmaAllocator allocator, const VkMemoryRequirements *pVkMemoryRequirements, const VmaAllocationCreateInfo *pCreateInfo, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo) General purpose memory allocation. void vmaSetCurrentFrameIndex(VmaAllocator allocator, uint32_t frameIndex) Sets index of the current frame. struct VmaAllocationCreateInfo VmaAllocationCreateInfo VkResult vmaAllocateMemoryForBuffer(VmaAllocator allocator, VkBuffer buffer, const VmaAllocationCreateInfo *pCreateInfo, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo) VmaPoolCreateFlagBits Flags to be passed as VmaPoolCreateInfo::flags. Definition: vk_mem_alloc.h:1129 Definition: vk_mem_alloc.h:1059 VmaPoolCreateFlagBits Flags to be passed as VmaPoolCreateInfo::flags. Definition: vk_mem_alloc.h:1167 Definition: vk_mem_alloc.h:1097 void vmaDestroyBuffer(VmaAllocator allocator, VkBuffer buffer, VmaAllocation allocation) Destroys Vulkan buffer and frees allocated memory. VkDeviceSize unusedSize Total number of bytes in the pool not used by any VmaAllocation. Definition: vk_mem_alloc.h:1204 uint32_t memoryType Memory type index that this allocation was allocated from. Definition: vk_mem_alloc.h:1268 VkDeviceSize unusedSize Total number of bytes in the pool not used by any VmaAllocation. Definition: vk_mem_alloc.h:1242 uint32_t memoryType Memory type index that this allocation was allocated from. Definition: vk_mem_alloc.h:1306 diff --git a/src/vk_mem_alloc.h b/src/vk_mem_alloc.h index a7eb730..9dc5e97 100644 --- a/src/vk_mem_alloc.h +++ b/src/vk_mem_alloc.h @@ -363,6 +363,41 @@ vmaDestroyBuffer(allocator, buf, alloc); vmaDestroyPool(allocator, pool); \endcode +\section custom_memory_pools_MemTypeIndex Choosing memory type index + +When creating a pool, you must explicitly specify memory type index. +To find the one suitable for your buffers or images, you can use code similar to the following: + +\code +VkBufferCreateInfo dummyBufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO }; +dummyBufCreateInfo.size = 1024; // Whatever. +dummyBufCreateInfo.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; // Change if needed. + +VkBuffer dummyBuf; +vkCreateBuffer(device, &dummyBufCreateInfo, nullptr, &dummyBuf); + +VkMemoryRequirements memReq; +vkGetBufferMemoryRequirements(device, dummyBuf, &memReq); + +VmaAllocationCreateInfo allocCreateInfo = {}; +allocCreateInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY; // Change if needed. + +uint32_t memTypeIndex; +vmaFindMemoryTypeIndex(allocator, memReq.memoryTypeBits, &allocCreateInfo, &memTypeIndex); + +vkDestroyBuffer(device, dummyBuf, nullptr); + +VmaPoolCreateInfo poolCreateInfo = {}; +poolCreateInfo.memoryTypeIndex = memTypeIndex; +// ... +\endcode + +Dummy buffer is needed to query driver for `memReq.memoryTypeBits`. +Memory is never allocated for this buffer. +You should fill structures `dummyBufCreateInfo` and `allocCreateInfo` with the same parameters +as you are going to use for buffers created in your pool. + + \page defragmentation Defragmentation Interleaved allocations and deallocations of many objects of varying size can |