Version 2.3.0 (2019-12-04)
Copyright (c) 2017-2019 Advanced Micro Devices, Inc. All rights reserved.
License: MIT
Documentation of all members: vk_mem_alloc.h
diff --git a/docs/html/vk__mem__alloc_8h_source.html b/docs/html/vk__mem__alloc_8h_source.html
index 4c50d1c8..ec5240e6 100644
--- a/docs/html/vk__mem__alloc_8h_source.html
+++ b/docs/html/vk__mem__alloc_8h_source.html
@@ -3455,7 +3455,7 @@
-
6281 bool IsEmpty()
const {
return m_Blocks.empty(); }
+
6282 bool IsCorruptionDetectionEnabled()
const;
@@ -8994,5927 +8994,5933 @@
-
11830 bool VmaBlockVector::IsCorruptionDetectionEnabled()
const
-
-
11832 const uint32_t requiredMemFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
-
11833 return (VMA_DEBUG_DETECT_CORRUPTION != 0) &&
-
11834 (VMA_DEBUG_MARGIN > 0) &&
-
-
11836 (m_hAllocator->m_MemProps.memoryTypes[m_MemoryTypeIndex].propertyFlags & requiredMemFlags) == requiredMemFlags;
-
-
-
11839 static const uint32_t VMA_ALLOCATION_TRY_COUNT = 32;
-
-
11841 VkResult VmaBlockVector::Allocate(
-
11842 uint32_t currentFrameIndex,
-
-
11844 VkDeviceSize alignment,
-
-
11846 VmaSuballocationType suballocType,
-
11847 size_t allocationCount,
-
-
-
-
11851 VkResult res = VK_SUCCESS;
-
-
11853 if(IsCorruptionDetectionEnabled())
-
-
11855 size = VmaAlignUp<VkDeviceSize>(size,
sizeof(VMA_CORRUPTION_DETECTION_MAGIC_VALUE));
-
11856 alignment = VmaAlignUp<VkDeviceSize>(alignment,
sizeof(VMA_CORRUPTION_DETECTION_MAGIC_VALUE));
-
+
11830 bool VmaBlockVector::IsEmpty()
+
+
11832 VmaMutexLockRead lock(m_Mutex, m_hAllocator->m_UseMutex);
+
11833 return m_Blocks.empty();
+
+
+
11836 bool VmaBlockVector::IsCorruptionDetectionEnabled()
const
+
+
11838 const uint32_t requiredMemFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
+
11839 return (VMA_DEBUG_DETECT_CORRUPTION != 0) &&
+
11840 (VMA_DEBUG_MARGIN > 0) &&
+
+
11842 (m_hAllocator->m_MemProps.memoryTypes[m_MemoryTypeIndex].propertyFlags & requiredMemFlags) == requiredMemFlags;
+
+
+
11845 static const uint32_t VMA_ALLOCATION_TRY_COUNT = 32;
+
+
11847 VkResult VmaBlockVector::Allocate(
+
11848 uint32_t currentFrameIndex,
+
+
11850 VkDeviceSize alignment,
+
+
11852 VmaSuballocationType suballocType,
+
11853 size_t allocationCount,
+
+
+
+
11857 VkResult res = VK_SUCCESS;
-
-
11860 VmaMutexLockWrite lock(m_Mutex, m_hAllocator->m_UseMutex);
-
11861 for(allocIndex = 0; allocIndex < allocationCount; ++allocIndex)
-
-
11863 res = AllocatePage(
-
-
-
-
-
-
11869 pAllocations + allocIndex);
-
11870 if(res != VK_SUCCESS)
-
-
-
-
-
-
-
11877 if(res != VK_SUCCESS)
-
-
-
11880 while(allocIndex--)
-
-
11882 Free(pAllocations[allocIndex]);
-
-
11884 memset(pAllocations, 0,
sizeof(
VmaAllocation) * allocationCount);
-
-
-
-
-
-
11890 VkResult VmaBlockVector::AllocatePage(
-
11891 uint32_t currentFrameIndex,
-
-
11893 VkDeviceSize alignment,
-
-
11895 VmaSuballocationType suballocType,
-
-
-
-
-
-
-
-
-
11904 VkDeviceSize freeMemory;
-
-
11906 const uint32_t heapIndex = m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex);
-
-
11908 m_hAllocator->GetBudget(&heapBudget, heapIndex, 1);
-
-
-
-
11912 const bool canFallbackToDedicated = !IsCustomPool();
-
11913 const bool canCreateNewBlock =
-
-
11915 (m_Blocks.size() < m_MaxBlockCount) &&
-
11916 (freeMemory >= size || !canFallbackToDedicated);
-
-
-
-
-
-
-
11923 canMakeOtherLost =
false;
-
-
-
-
11927 if(isUpperAddress &&
-
-
-
11930 return VK_ERROR_FEATURE_NOT_PRESENT;
-
-
-
-
+
11859 if(IsCorruptionDetectionEnabled())
+
+
11861 size = VmaAlignUp<VkDeviceSize>(size,
sizeof(VMA_CORRUPTION_DETECTION_MAGIC_VALUE));
+
11862 alignment = VmaAlignUp<VkDeviceSize>(alignment,
sizeof(VMA_CORRUPTION_DETECTION_MAGIC_VALUE));
+
+
+
+
11866 VmaMutexLockWrite lock(m_Mutex, m_hAllocator->m_UseMutex);
+
11867 for(allocIndex = 0; allocIndex < allocationCount; ++allocIndex)
+
+
11869 res = AllocatePage(
+
+
+
+
+
+
11875 pAllocations + allocIndex);
+
11876 if(res != VK_SUCCESS)
+
+
+
+
+
+
+
11883 if(res != VK_SUCCESS)
+
+
+
11886 while(allocIndex--)
+
+
11888 Free(pAllocations[allocIndex]);
+
+
11890 memset(pAllocations, 0,
sizeof(
VmaAllocation) * allocationCount);
+
+
+
+
+
+
11896 VkResult VmaBlockVector::AllocatePage(
+
11897 uint32_t currentFrameIndex,
+
+
11899 VkDeviceSize alignment,
+
+
11901 VmaSuballocationType suballocType,
+
+
+
+
+
+
+
+
+
11910 VkDeviceSize freeMemory;
+
+
11912 const uint32_t heapIndex = m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex);
+
+
11914 m_hAllocator->GetBudget(&heapBudget, heapIndex, 1);
+
+
+
+
11918 const bool canFallbackToDedicated = !IsCustomPool();
+
11919 const bool canCreateNewBlock =
+
+
11921 (m_Blocks.size() < m_MaxBlockCount) &&
+
11922 (freeMemory >= size || !canFallbackToDedicated);
+
+
+
+
+
+
+
11929 canMakeOtherLost =
false;
+
+
+
+
11933 if(isUpperAddress &&
+
-
-
-
-
-
-
-
-
-
11944 return VK_ERROR_FEATURE_NOT_PRESENT;
-
-
-
-
11948 if(size + 2 * VMA_DEBUG_MARGIN > m_PreferredBlockSize)
-
-
11950 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
11936 return VK_ERROR_FEATURE_NOT_PRESENT;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
11950 return VK_ERROR_FEATURE_NOT_PRESENT;
-
-
-
-
-
-
11958 if(!canMakeOtherLost || canCreateNewBlock)
-
-
-
-
-
-
-
-
-
11967 if(!m_Blocks.empty())
-
-
11969 VmaDeviceMemoryBlock*
const pCurrBlock = m_Blocks.back();
-
11970 VMA_ASSERT(pCurrBlock);
-
11971 VkResult res = AllocateFromBlock(
-
-
-
-
-
-
-
-
-
-
11981 if(res == VK_SUCCESS)
-
-
11983 VMA_DEBUG_LOG(
" Returned from last block #%u", pCurrBlock->GetId());
-
-
-
-
-
-
-
-
-
-
11993 for(
size_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex )
-
-
11995 VmaDeviceMemoryBlock*
const pCurrBlock = m_Blocks[blockIndex];
-
11996 VMA_ASSERT(pCurrBlock);
-
11997 VkResult res = AllocateFromBlock(
-
-
-
-
-
-
-
-
-
-
12007 if(res == VK_SUCCESS)
-
-
12009 VMA_DEBUG_LOG(
" Returned from existing block #%u", pCurrBlock->GetId());
-
-
-
-
-
-
-
-
12017 for(
size_t blockIndex = m_Blocks.size(); blockIndex--; )
-
-
12019 VmaDeviceMemoryBlock*
const pCurrBlock = m_Blocks[blockIndex];
-
12020 VMA_ASSERT(pCurrBlock);
-
12021 VkResult res = AllocateFromBlock(
-
-
-
-
-
-
-
-
-
-
12031 if(res == VK_SUCCESS)
-
-
12033 VMA_DEBUG_LOG(
" Returned from existing block #%u", pCurrBlock->GetId());
-
-
-
-
-
-
-
-
12041 if(canCreateNewBlock)
-
-
-
12044 VkDeviceSize newBlockSize = m_PreferredBlockSize;
-
12045 uint32_t newBlockSizeShift = 0;
-
12046 const uint32_t NEW_BLOCK_SIZE_SHIFT_MAX = 3;
-
-
12048 if(!m_ExplicitBlockSize)
-
-
-
12051 const VkDeviceSize maxExistingBlockSize = CalcMaxBlockSize();
-
12052 for(uint32_t i = 0; i < NEW_BLOCK_SIZE_SHIFT_MAX; ++i)
-
-
12054 const VkDeviceSize smallerNewBlockSize = newBlockSize / 2;
-
12055 if(smallerNewBlockSize > maxExistingBlockSize && smallerNewBlockSize >= size * 2)
-
-
12057 newBlockSize = smallerNewBlockSize;
-
12058 ++newBlockSizeShift;
-
-
-
-
-
-
-
-
-
12067 size_t newBlockIndex = 0;
-
12068 VkResult res = (newBlockSize <= freeMemory || !canFallbackToDedicated) ?
-
12069 CreateBlock(newBlockSize, &newBlockIndex) : VK_ERROR_OUT_OF_DEVICE_MEMORY;
-
-
12071 if(!m_ExplicitBlockSize)
-
-
12073 while(res < 0 && newBlockSizeShift < NEW_BLOCK_SIZE_SHIFT_MAX)
-
-
12075 const VkDeviceSize smallerNewBlockSize = newBlockSize / 2;
-
12076 if(smallerNewBlockSize >= size)
-
-
12078 newBlockSize = smallerNewBlockSize;
-
12079 ++newBlockSizeShift;
-
12080 res = (newBlockSize <= freeMemory || !canFallbackToDedicated) ?
-
12081 CreateBlock(newBlockSize, &newBlockIndex) : VK_ERROR_OUT_OF_DEVICE_MEMORY;
-
-
-
-
-
-
-
-
-
12090 if(res == VK_SUCCESS)
-
-
12092 VmaDeviceMemoryBlock*
const pBlock = m_Blocks[newBlockIndex];
-
12093 VMA_ASSERT(pBlock->m_pMetadata->GetSize() >= size);
-
-
12095 res = AllocateFromBlock(
-
-
-
-
-
-
-
-
-
-
12105 if(res == VK_SUCCESS)
-
-
12107 VMA_DEBUG_LOG(
" Created new block #%u Size=%llu", pBlock->GetId(), newBlockSize);
-
-
-
-
-
-
12113 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
-
-
-
-
-
-
-
12120 if(canMakeOtherLost)
-
-
12122 uint32_t tryIndex = 0;
-
12123 for(; tryIndex < VMA_ALLOCATION_TRY_COUNT; ++tryIndex)
-
-
12125 VmaDeviceMemoryBlock* pBestRequestBlock = VMA_NULL;
-
12126 VmaAllocationRequest bestRequest = {};
-
12127 VkDeviceSize bestRequestCost = VK_WHOLE_SIZE;
-
-
-
-
-
-
12133 for(
size_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex )
-
-
12135 VmaDeviceMemoryBlock*
const pCurrBlock = m_Blocks[blockIndex];
-
12136 VMA_ASSERT(pCurrBlock);
-
12137 VmaAllocationRequest currRequest = {};
-
12138 if(pCurrBlock->m_pMetadata->CreateAllocationRequest(
-
-
-
12141 m_BufferImageGranularity,
-
-
-
-
-
-
-
-
-
12150 const VkDeviceSize currRequestCost = currRequest.CalcCost();
-
12151 if(pBestRequestBlock == VMA_NULL ||
-
12152 currRequestCost < bestRequestCost)
-
-
12154 pBestRequestBlock = pCurrBlock;
-
12155 bestRequest = currRequest;
-
12156 bestRequestCost = currRequestCost;
-
-
12158 if(bestRequestCost == 0)
-
-
-
-
-
-
-
-
-
-
-
12169 for(
size_t blockIndex = m_Blocks.size(); blockIndex--; )
-
-
12171 VmaDeviceMemoryBlock*
const pCurrBlock = m_Blocks[blockIndex];
-
12172 VMA_ASSERT(pCurrBlock);
-
12173 VmaAllocationRequest currRequest = {};
-
12174 if(pCurrBlock->m_pMetadata->CreateAllocationRequest(
-
-
-
12177 m_BufferImageGranularity,
-
-
-
-
-
-
-
-
-
12186 const VkDeviceSize currRequestCost = currRequest.CalcCost();
-
12187 if(pBestRequestBlock == VMA_NULL ||
-
12188 currRequestCost < bestRequestCost ||
-
-
-
12191 pBestRequestBlock = pCurrBlock;
-
12192 bestRequest = currRequest;
-
12193 bestRequestCost = currRequestCost;
-
-
12195 if(bestRequestCost == 0 ||
-
-
-
-
-
-
-
-
-
-
12205 if(pBestRequestBlock != VMA_NULL)
-
-
-
-
12209 VkResult res = pBestRequestBlock->Map(m_hAllocator, 1, VMA_NULL);
-
12210 if(res != VK_SUCCESS)
-
-
-
-
-
-
12216 if(pBestRequestBlock->m_pMetadata->MakeRequestedAllocationsLost(
-
-
-
-
-
-
12222 *pAllocation = m_hAllocator->m_AllocationObjectAllocator.Allocate();
-
12223 (*pAllocation)->Ctor(currentFrameIndex, isUserDataString);
-
12224 pBestRequestBlock->m_pMetadata->Alloc(bestRequest, suballocType, size, *pAllocation);
-
12225 UpdateHasEmptyBlock();
-
12226 (*pAllocation)->InitBlockAllocation(
-
-
12228 bestRequest.offset,
-
-
-
-
-
-
-
12235 VMA_HEAVY_ASSERT(pBestRequestBlock->Validate());
-
12236 VMA_DEBUG_LOG(
" Returned from existing block");
-
12237 (*pAllocation)->SetUserData(m_hAllocator, createInfo.
pUserData);
-
12238 m_hAllocator->m_Budget.AddAllocation(m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex), size);
-
12239 if(VMA_DEBUG_INITIALIZE_ALLOCATIONS)
-
-
12241 m_hAllocator->FillAllocation(*pAllocation, VMA_ALLOCATION_FILL_PATTERN_CREATED);
-
-
12243 if(IsCorruptionDetectionEnabled())
-
-
12245 VkResult res = pBestRequestBlock->WriteMagicValueAroundAllocation(m_hAllocator, bestRequest.offset, size);
-
12246 VMA_ASSERT(res == VK_SUCCESS &&
"Couldn't map block memory to write magic value.");
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
12261 if(tryIndex == VMA_ALLOCATION_TRY_COUNT)
-
-
12263 return VK_ERROR_TOO_MANY_OBJECTS;
-
-
-
-
12267 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
-
-
-
12270 void VmaBlockVector::Free(
-
-
-
12273 VmaDeviceMemoryBlock* pBlockToDelete = VMA_NULL;
-
-
12275 bool budgetExceeded =
false;
-
-
12277 const uint32_t heapIndex = m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex);
-
-
12279 m_hAllocator->GetBudget(&heapBudget, heapIndex, 1);
-
12280 budgetExceeded = heapBudget.
usage >= heapBudget.
budget;
-
-
-
-
-
12285 VmaMutexLockWrite lock(m_Mutex, m_hAllocator->m_UseMutex);
-
-
12287 VmaDeviceMemoryBlock* pBlock = hAllocation->GetBlock();
+
+
11954 if(size + 2 * VMA_DEBUG_MARGIN > m_PreferredBlockSize)
+
+
11956 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
+
+
+
+
+
+
+
11964 if(!canMakeOtherLost || canCreateNewBlock)
+
+
+
+
+
+
+
+
+
11973 if(!m_Blocks.empty())
+
+
11975 VmaDeviceMemoryBlock*
const pCurrBlock = m_Blocks.back();
+
11976 VMA_ASSERT(pCurrBlock);
+
11977 VkResult res = AllocateFromBlock(
+
+
+
+
+
+
+
+
+
+
11987 if(res == VK_SUCCESS)
+
+
11989 VMA_DEBUG_LOG(
" Returned from last block #%u", pCurrBlock->GetId());
+
+
+
+
+
+
+
+
+
+
11999 for(
size_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex )
+
+
12001 VmaDeviceMemoryBlock*
const pCurrBlock = m_Blocks[blockIndex];
+
12002 VMA_ASSERT(pCurrBlock);
+
12003 VkResult res = AllocateFromBlock(
+
+
+
+
+
+
+
+
+
+
12013 if(res == VK_SUCCESS)
+
+
12015 VMA_DEBUG_LOG(
" Returned from existing block #%u", pCurrBlock->GetId());
+
+
+
+
+
+
+
+
12023 for(
size_t blockIndex = m_Blocks.size(); blockIndex--; )
+
+
12025 VmaDeviceMemoryBlock*
const pCurrBlock = m_Blocks[blockIndex];
+
12026 VMA_ASSERT(pCurrBlock);
+
12027 VkResult res = AllocateFromBlock(
+
+
+
+
+
+
+
+
+
+
12037 if(res == VK_SUCCESS)
+
+
12039 VMA_DEBUG_LOG(
" Returned from existing block #%u", pCurrBlock->GetId());
+
+
+
+
+
+
+
+
12047 if(canCreateNewBlock)
+
+
+
12050 VkDeviceSize newBlockSize = m_PreferredBlockSize;
+
12051 uint32_t newBlockSizeShift = 0;
+
12052 const uint32_t NEW_BLOCK_SIZE_SHIFT_MAX = 3;
+
+
12054 if(!m_ExplicitBlockSize)
+
+
+
12057 const VkDeviceSize maxExistingBlockSize = CalcMaxBlockSize();
+
12058 for(uint32_t i = 0; i < NEW_BLOCK_SIZE_SHIFT_MAX; ++i)
+
+
12060 const VkDeviceSize smallerNewBlockSize = newBlockSize / 2;
+
12061 if(smallerNewBlockSize > maxExistingBlockSize && smallerNewBlockSize >= size * 2)
+
+
12063 newBlockSize = smallerNewBlockSize;
+
12064 ++newBlockSizeShift;
+
+
+
+
+
+
+
+
+
12073 size_t newBlockIndex = 0;
+
12074 VkResult res = (newBlockSize <= freeMemory || !canFallbackToDedicated) ?
+
12075 CreateBlock(newBlockSize, &newBlockIndex) : VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
+
12077 if(!m_ExplicitBlockSize)
+
+
12079 while(res < 0 && newBlockSizeShift < NEW_BLOCK_SIZE_SHIFT_MAX)
+
+
12081 const VkDeviceSize smallerNewBlockSize = newBlockSize / 2;
+
12082 if(smallerNewBlockSize >= size)
+
+
12084 newBlockSize = smallerNewBlockSize;
+
12085 ++newBlockSizeShift;
+
12086 res = (newBlockSize <= freeMemory || !canFallbackToDedicated) ?
+
12087 CreateBlock(newBlockSize, &newBlockIndex) : VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
+
+
+
+
+
+
+
+
12096 if(res == VK_SUCCESS)
+
+
12098 VmaDeviceMemoryBlock*
const pBlock = m_Blocks[newBlockIndex];
+
12099 VMA_ASSERT(pBlock->m_pMetadata->GetSize() >= size);
+
+
12101 res = AllocateFromBlock(
+
+
+
+
+
+
+
+
+
+
12111 if(res == VK_SUCCESS)
+
+
12113 VMA_DEBUG_LOG(
" Created new block #%u Size=%llu", pBlock->GetId(), newBlockSize);
+
+
+
+
+
+
12119 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
+
+
+
+
+
+
12126 if(canMakeOtherLost)
+
+
12128 uint32_t tryIndex = 0;
+
12129 for(; tryIndex < VMA_ALLOCATION_TRY_COUNT; ++tryIndex)
+
+
12131 VmaDeviceMemoryBlock* pBestRequestBlock = VMA_NULL;
+
12132 VmaAllocationRequest bestRequest = {};
+
12133 VkDeviceSize bestRequestCost = VK_WHOLE_SIZE;
+
+
+
+
+
+
12139 for(
size_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex )
+
+
12141 VmaDeviceMemoryBlock*
const pCurrBlock = m_Blocks[blockIndex];
+
12142 VMA_ASSERT(pCurrBlock);
+
12143 VmaAllocationRequest currRequest = {};
+
12144 if(pCurrBlock->m_pMetadata->CreateAllocationRequest(
+
+
+
12147 m_BufferImageGranularity,
+
+
+
+
+
+
+
+
+
12156 const VkDeviceSize currRequestCost = currRequest.CalcCost();
+
12157 if(pBestRequestBlock == VMA_NULL ||
+
12158 currRequestCost < bestRequestCost)
+
+
12160 pBestRequestBlock = pCurrBlock;
+
12161 bestRequest = currRequest;
+
12162 bestRequestCost = currRequestCost;
+
+
12164 if(bestRequestCost == 0)
+
+
+
+
+
+
+
+
+
+
+
12175 for(
size_t blockIndex = m_Blocks.size(); blockIndex--; )
+
+
12177 VmaDeviceMemoryBlock*
const pCurrBlock = m_Blocks[blockIndex];
+
12178 VMA_ASSERT(pCurrBlock);
+
12179 VmaAllocationRequest currRequest = {};
+
12180 if(pCurrBlock->m_pMetadata->CreateAllocationRequest(
+
+
+
12183 m_BufferImageGranularity,
+
+
+
+
+
+
+
+
+
12192 const VkDeviceSize currRequestCost = currRequest.CalcCost();
+
12193 if(pBestRequestBlock == VMA_NULL ||
+
12194 currRequestCost < bestRequestCost ||
+
+
+
12197 pBestRequestBlock = pCurrBlock;
+
12198 bestRequest = currRequest;
+
12199 bestRequestCost = currRequestCost;
+
+
12201 if(bestRequestCost == 0 ||
+
+
+
+
+
+
+
+
+
+
12211 if(pBestRequestBlock != VMA_NULL)
+
+
+
+
12215 VkResult res = pBestRequestBlock->Map(m_hAllocator, 1, VMA_NULL);
+
12216 if(res != VK_SUCCESS)
+
+
+
+
+
+
12222 if(pBestRequestBlock->m_pMetadata->MakeRequestedAllocationsLost(
+
+
+
+
+
+
12228 *pAllocation = m_hAllocator->m_AllocationObjectAllocator.Allocate();
+
12229 (*pAllocation)->Ctor(currentFrameIndex, isUserDataString);
+
12230 pBestRequestBlock->m_pMetadata->Alloc(bestRequest, suballocType, size, *pAllocation);
+
12231 UpdateHasEmptyBlock();
+
12232 (*pAllocation)->InitBlockAllocation(
+
+
12234 bestRequest.offset,
+
+
+
+
+
+
+
12241 VMA_HEAVY_ASSERT(pBestRequestBlock->Validate());
+
12242 VMA_DEBUG_LOG(
" Returned from existing block");
+
12243 (*pAllocation)->SetUserData(m_hAllocator, createInfo.
pUserData);
+
12244 m_hAllocator->m_Budget.AddAllocation(m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex), size);
+
12245 if(VMA_DEBUG_INITIALIZE_ALLOCATIONS)
+
+
12247 m_hAllocator->FillAllocation(*pAllocation, VMA_ALLOCATION_FILL_PATTERN_CREATED);
+
+
12249 if(IsCorruptionDetectionEnabled())
+
+
12251 VkResult res = pBestRequestBlock->WriteMagicValueAroundAllocation(m_hAllocator, bestRequest.offset, size);
+
12252 VMA_ASSERT(res == VK_SUCCESS &&
"Couldn't map block memory to write magic value.");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
12267 if(tryIndex == VMA_ALLOCATION_TRY_COUNT)
+
+
12269 return VK_ERROR_TOO_MANY_OBJECTS;
+
+
+
+
12273 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
+
+
12276 void VmaBlockVector::Free(
+
+
+
12279 VmaDeviceMemoryBlock* pBlockToDelete = VMA_NULL;
+
+
12281 bool budgetExceeded =
false;
+
+
12283 const uint32_t heapIndex = m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex);
+
+
12285 m_hAllocator->GetBudget(&heapBudget, heapIndex, 1);
+
12286 budgetExceeded = heapBudget.
usage >= heapBudget.
budget;
+
-
12289 if(IsCorruptionDetectionEnabled())
-
-
12291 VkResult res = pBlock->ValidateMagicValueAroundAllocation(m_hAllocator, hAllocation->GetOffset(), hAllocation->GetSize());
-
12292 VMA_ASSERT(res == VK_SUCCESS &&
"Couldn't map block memory to validate magic value.");
-
+
+
+
12291 VmaMutexLockWrite lock(m_Mutex, m_hAllocator->m_UseMutex);
+
+
12293 VmaDeviceMemoryBlock* pBlock = hAllocation->GetBlock();
-
12295 if(hAllocation->IsPersistentMap())
+
12295 if(IsCorruptionDetectionEnabled())
-
12297 pBlock->Unmap(m_hAllocator, 1);
-
-
-
12300 pBlock->m_pMetadata->Free(hAllocation);
-
12301 VMA_HEAVY_ASSERT(pBlock->Validate());
-
-
12303 VMA_DEBUG_LOG(
" Freed from MemoryTypeIndex=%u", m_MemoryTypeIndex);
-
-
12305 const bool canDeleteBlock = m_Blocks.size() > m_MinBlockCount;
-
-
12307 if(pBlock->m_pMetadata->IsEmpty())
-
-
-
12310 if((m_HasEmptyBlock || budgetExceeded) && canDeleteBlock)
-
-
12312 pBlockToDelete = pBlock;
-
-
-
-
-
-
-
12319 else if(m_HasEmptyBlock && canDeleteBlock)
-
-
12321 VmaDeviceMemoryBlock* pLastBlock = m_Blocks.back();
-
12322 if(pLastBlock->m_pMetadata->IsEmpty())
-
-
12324 pBlockToDelete = pLastBlock;
-
12325 m_Blocks.pop_back();
-
-
-
-
12329 UpdateHasEmptyBlock();
-
12330 IncrementallySortBlocks();
-
-
-
-
-
12335 if(pBlockToDelete != VMA_NULL)
-
-
12337 VMA_DEBUG_LOG(
" Deleted empty block");
-
12338 pBlockToDelete->Destroy(m_hAllocator);
-
12339 vma_delete(m_hAllocator, pBlockToDelete);
-
-
-
-
12343 VkDeviceSize VmaBlockVector::CalcMaxBlockSize()
const
-
-
12345 VkDeviceSize result = 0;
-
12346 for(
size_t i = m_Blocks.size(); i--; )
-
-
12348 result = VMA_MAX(result, m_Blocks[i]->m_pMetadata->GetSize());
-
12349 if(result >= m_PreferredBlockSize)
-
-
-
-
-
-
-
-
12357 void VmaBlockVector::Remove(VmaDeviceMemoryBlock* pBlock)
-
-
12359 for(uint32_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex)
-
-
12361 if(m_Blocks[blockIndex] == pBlock)
-
-
12363 VmaVectorRemove(m_Blocks, blockIndex);
-
-
-
-
-
-
-
12370 void VmaBlockVector::IncrementallySortBlocks()
-
-
-
-
-
12375 for(
size_t i = 1; i < m_Blocks.size(); ++i)
-
-
12377 if(m_Blocks[i - 1]->m_pMetadata->GetSumFreeSize() > m_Blocks[i]->m_pMetadata->GetSumFreeSize())
-
-
12379 VMA_SWAP(m_Blocks[i - 1], m_Blocks[i]);
-
-
-
-
-
-
-
12386 VkResult VmaBlockVector::AllocateFromBlock(
-
12387 VmaDeviceMemoryBlock* pBlock,
-
12388 uint32_t currentFrameIndex,
-
-
12390 VkDeviceSize alignment,
-
-
-
12393 VmaSuballocationType suballocType,
-
-
-
-
-
-
-
-
-
12402 VmaAllocationRequest currRequest = {};
-
12403 if(pBlock->m_pMetadata->CreateAllocationRequest(
-
-
-
12406 m_BufferImageGranularity,
-
-
-
-
-
-
-
-
-
-
12416 VMA_ASSERT(currRequest.itemsToMakeLostCount == 0);
-
-
-
-
12420 VkResult res = pBlock->Map(m_hAllocator, 1, VMA_NULL);
-
12421 if(res != VK_SUCCESS)
-
-
-
-
-
-
12427 *pAllocation = m_hAllocator->m_AllocationObjectAllocator.Allocate();
-
12428 (*pAllocation)->Ctor(currentFrameIndex, isUserDataString);
-
12429 pBlock->m_pMetadata->Alloc(currRequest, suballocType, size, *pAllocation);
-
12430 UpdateHasEmptyBlock();
-
12431 (*pAllocation)->InitBlockAllocation(
-
-
12433 currRequest.offset,
-
-
-
-
-
-
-
12440 VMA_HEAVY_ASSERT(pBlock->Validate());
-
12441 (*pAllocation)->SetUserData(m_hAllocator, pUserData);
-
12442 m_hAllocator->m_Budget.AddAllocation(m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex), size);
-
12443 if(VMA_DEBUG_INITIALIZE_ALLOCATIONS)
-
-
12445 m_hAllocator->FillAllocation(*pAllocation, VMA_ALLOCATION_FILL_PATTERN_CREATED);
-
-
12447 if(IsCorruptionDetectionEnabled())
-
-
12449 VkResult res = pBlock->WriteMagicValueAroundAllocation(m_hAllocator, currRequest.offset, size);
-
12450 VMA_ASSERT(res == VK_SUCCESS &&
"Couldn't map block memory to write magic value.");
-
-
-
-
12454 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
-
-
-
12457 VkResult VmaBlockVector::CreateBlock(VkDeviceSize blockSize,
size_t* pNewBlockIndex)
-
-
12459 VkMemoryAllocateInfo allocInfo = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO };
-
12460 allocInfo.memoryTypeIndex = m_MemoryTypeIndex;
-
12461 allocInfo.allocationSize = blockSize;
-
12462 VkDeviceMemory mem = VK_NULL_HANDLE;
-
12463 VkResult res = m_hAllocator->AllocateVulkanMemory(&allocInfo, &mem);
-
-
-
-
-
-
-
-
-
12472 VmaDeviceMemoryBlock*
const pBlock = vma_new(m_hAllocator, VmaDeviceMemoryBlock)(m_hAllocator);
-
-
-
-
-
-
12478 allocInfo.allocationSize,
-
-
-
-
12482 m_Blocks.push_back(pBlock);
-
12483 if(pNewBlockIndex != VMA_NULL)
-
-
12485 *pNewBlockIndex = m_Blocks.size() - 1;
-
+
12297 VkResult res = pBlock->ValidateMagicValueAroundAllocation(m_hAllocator, hAllocation->GetOffset(), hAllocation->GetSize());
+
12298 VMA_ASSERT(res == VK_SUCCESS &&
"Couldn't map block memory to validate magic value.");
+
+
+
12301 if(hAllocation->IsPersistentMap())
+
+
12303 pBlock->Unmap(m_hAllocator, 1);
+
+
+
12306 pBlock->m_pMetadata->Free(hAllocation);
+
12307 VMA_HEAVY_ASSERT(pBlock->Validate());
+
+
12309 VMA_DEBUG_LOG(
" Freed from MemoryTypeIndex=%u", m_MemoryTypeIndex);
+
+
12311 const bool canDeleteBlock = m_Blocks.size() > m_MinBlockCount;
+
+
12313 if(pBlock->m_pMetadata->IsEmpty())
+
+
+
12316 if((m_HasEmptyBlock || budgetExceeded) && canDeleteBlock)
+
+
12318 pBlockToDelete = pBlock;
+
+
+
+
+
+
+
12325 else if(m_HasEmptyBlock && canDeleteBlock)
+
+
12327 VmaDeviceMemoryBlock* pLastBlock = m_Blocks.back();
+
12328 if(pLastBlock->m_pMetadata->IsEmpty())
+
+
12330 pBlockToDelete = pLastBlock;
+
12331 m_Blocks.pop_back();
+
+
+
+
12335 UpdateHasEmptyBlock();
+
12336 IncrementallySortBlocks();
+
+
+
+
+
12341 if(pBlockToDelete != VMA_NULL)
+
+
12343 VMA_DEBUG_LOG(
" Deleted empty block");
+
12344 pBlockToDelete->Destroy(m_hAllocator);
+
12345 vma_delete(m_hAllocator, pBlockToDelete);
+
+
+
+
12349 VkDeviceSize VmaBlockVector::CalcMaxBlockSize()
const
+
+
12351 VkDeviceSize result = 0;
+
12352 for(
size_t i = m_Blocks.size(); i--; )
+
+
12354 result = VMA_MAX(result, m_Blocks[i]->m_pMetadata->GetSize());
+
12355 if(result >= m_PreferredBlockSize)
+
+
+
+
+
+
+
+
12363 void VmaBlockVector::Remove(VmaDeviceMemoryBlock* pBlock)
+
+
12365 for(uint32_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex)
+
+
12367 if(m_Blocks[blockIndex] == pBlock)
+
+
12369 VmaVectorRemove(m_Blocks, blockIndex);
+
+
+
+
+
+
+
12376 void VmaBlockVector::IncrementallySortBlocks()
+
+
+
+
+
12381 for(
size_t i = 1; i < m_Blocks.size(); ++i)
+
+
12383 if(m_Blocks[i - 1]->m_pMetadata->GetSumFreeSize() > m_Blocks[i]->m_pMetadata->GetSumFreeSize())
+
+
12385 VMA_SWAP(m_Blocks[i - 1], m_Blocks[i]);
+
+
+
+
+
+
+
12392 VkResult VmaBlockVector::AllocateFromBlock(
+
12393 VmaDeviceMemoryBlock* pBlock,
+
12394 uint32_t currentFrameIndex,
+
+
12396 VkDeviceSize alignment,
+
+
+
12399 VmaSuballocationType suballocType,
+
+
+
+
+
+
+
+
+
12408 VmaAllocationRequest currRequest = {};
+
12409 if(pBlock->m_pMetadata->CreateAllocationRequest(
+
+
+
12412 m_BufferImageGranularity,
+
+
+
+
+
+
+
+
+
+
12422 VMA_ASSERT(currRequest.itemsToMakeLostCount == 0);
+
+
+
+
12426 VkResult res = pBlock->Map(m_hAllocator, 1, VMA_NULL);
+
12427 if(res != VK_SUCCESS)
+
+
+
+
+
+
12433 *pAllocation = m_hAllocator->m_AllocationObjectAllocator.Allocate();
+
12434 (*pAllocation)->Ctor(currentFrameIndex, isUserDataString);
+
12435 pBlock->m_pMetadata->Alloc(currRequest, suballocType, size, *pAllocation);
+
12436 UpdateHasEmptyBlock();
+
12437 (*pAllocation)->InitBlockAllocation(
+
+
12439 currRequest.offset,
+
+
+
+
+
+
+
12446 VMA_HEAVY_ASSERT(pBlock->Validate());
+
12447 (*pAllocation)->SetUserData(m_hAllocator, pUserData);
+
12448 m_hAllocator->m_Budget.AddAllocation(m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex), size);
+
12449 if(VMA_DEBUG_INITIALIZE_ALLOCATIONS)
+
+
12451 m_hAllocator->FillAllocation(*pAllocation, VMA_ALLOCATION_FILL_PATTERN_CREATED);
+
+
12453 if(IsCorruptionDetectionEnabled())
+
+
12455 VkResult res = pBlock->WriteMagicValueAroundAllocation(m_hAllocator, currRequest.offset, size);
+
12456 VMA_ASSERT(res == VK_SUCCESS &&
"Couldn't map block memory to write magic value.");
+
+
+
+
12460 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
+
+
12463 VkResult VmaBlockVector::CreateBlock(VkDeviceSize blockSize,
size_t* pNewBlockIndex)
+
+
12465 VkMemoryAllocateInfo allocInfo = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO };
+
12466 allocInfo.memoryTypeIndex = m_MemoryTypeIndex;
+
12467 allocInfo.allocationSize = blockSize;
+
12468 VkDeviceMemory mem = VK_NULL_HANDLE;
+
12469 VkResult res = m_hAllocator->AllocateVulkanMemory(&allocInfo, &mem);
+
+
+
+
+
+
+
+
+
12478 VmaDeviceMemoryBlock*
const pBlock = vma_new(m_hAllocator, VmaDeviceMemoryBlock)(m_hAllocator);
+
+
+
+
+
+
12484 allocInfo.allocationSize,
+
+
-
-
-
-
12491 void VmaBlockVector::ApplyDefragmentationMovesCpu(
-
12492 class VmaBlockVectorDefragmentationContext* pDefragCtx,
-
12493 const VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves)
-
-
12495 const size_t blockCount = m_Blocks.size();
-
12496 const bool isNonCoherent = m_hAllocator->IsMemoryTypeNonCoherent(m_MemoryTypeIndex);
-
-
-
-
12500 BLOCK_FLAG_USED = 0x00000001,
-
12501 BLOCK_FLAG_MAPPED_FOR_DEFRAGMENTATION = 0x00000002,
-
+
12488 m_Blocks.push_back(pBlock);
+
12489 if(pNewBlockIndex != VMA_NULL)
+
+
12491 *pNewBlockIndex = m_Blocks.size() - 1;
+
+
+
+
+
+
12497 void VmaBlockVector::ApplyDefragmentationMovesCpu(
+
12498 class VmaBlockVectorDefragmentationContext* pDefragCtx,
+
12499 const VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves)
+
+
12501 const size_t blockCount = m_Blocks.size();
+
12502 const bool isNonCoherent = m_hAllocator->IsMemoryTypeNonCoherent(m_MemoryTypeIndex);
-
+
-
-
+
12506 BLOCK_FLAG_USED = 0x00000001,
+
12507 BLOCK_FLAG_MAPPED_FOR_DEFRAGMENTATION = 0x00000002,
-
12509 VmaVector< BlockInfo, VmaStlAllocator<BlockInfo> >
-
12510 blockInfo(blockCount, BlockInfo(), VmaStlAllocator<BlockInfo>(m_hAllocator->GetAllocationCallbacks()));
-
12511 memset(blockInfo.data(), 0, blockCount *
sizeof(BlockInfo));
-
-
-
12514 const size_t moveCount = moves.size();
-
12515 for(
size_t moveIndex = 0; moveIndex < moveCount; ++moveIndex)
-
-
12517 const VmaDefragmentationMove& move = moves[moveIndex];
-
12518 blockInfo[move.srcBlockIndex].flags |= BLOCK_FLAG_USED;
-
12519 blockInfo[move.dstBlockIndex].flags |= BLOCK_FLAG_USED;
-
-
-
12522 VMA_ASSERT(pDefragCtx->res == VK_SUCCESS);
-
-
-
12525 for(
size_t blockIndex = 0; pDefragCtx->res == VK_SUCCESS && blockIndex < blockCount; ++blockIndex)
-
-
12527 BlockInfo& currBlockInfo = blockInfo[blockIndex];
-
12528 VmaDeviceMemoryBlock* pBlock = m_Blocks[blockIndex];
-
12529 if((currBlockInfo.flags & BLOCK_FLAG_USED) != 0)
-
-
12531 currBlockInfo.pMappedData = pBlock->GetMappedData();
-
-
12533 if(currBlockInfo.pMappedData == VMA_NULL)
-
-
12535 pDefragCtx->res = pBlock->Map(m_hAllocator, 1, &currBlockInfo.pMappedData);
-
12536 if(pDefragCtx->res == VK_SUCCESS)
-
-
12538 currBlockInfo.flags |= BLOCK_FLAG_MAPPED_FOR_DEFRAGMENTATION;
-
-
-
-
-
-
-
12545 if(pDefragCtx->res == VK_SUCCESS)
-
-
12547 const VkDeviceSize nonCoherentAtomSize = m_hAllocator->m_PhysicalDeviceProperties.limits.nonCoherentAtomSize;
-
12548 VkMappedMemoryRange memRange = { VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE };
+
+
+
+
+
+
+
12515 VmaVector< BlockInfo, VmaStlAllocator<BlockInfo> >
+
12516 blockInfo(blockCount, BlockInfo(), VmaStlAllocator<BlockInfo>(m_hAllocator->GetAllocationCallbacks()));
+
12517 memset(blockInfo.data(), 0, blockCount *
sizeof(BlockInfo));
+
+
+
12520 const size_t moveCount = moves.size();
+
12521 for(
size_t moveIndex = 0; moveIndex < moveCount; ++moveIndex)
+
+
12523 const VmaDefragmentationMove& move = moves[moveIndex];
+
12524 blockInfo[move.srcBlockIndex].flags |= BLOCK_FLAG_USED;
+
12525 blockInfo[move.dstBlockIndex].flags |= BLOCK_FLAG_USED;
+
+
+
12528 VMA_ASSERT(pDefragCtx->res == VK_SUCCESS);
+
+
+
12531 for(
size_t blockIndex = 0; pDefragCtx->res == VK_SUCCESS && blockIndex < blockCount; ++blockIndex)
+
+
12533 BlockInfo& currBlockInfo = blockInfo[blockIndex];
+
12534 VmaDeviceMemoryBlock* pBlock = m_Blocks[blockIndex];
+
12535 if((currBlockInfo.flags & BLOCK_FLAG_USED) != 0)
+
+
12537 currBlockInfo.pMappedData = pBlock->GetMappedData();
+
+
12539 if(currBlockInfo.pMappedData == VMA_NULL)
+
+
12541 pDefragCtx->res = pBlock->Map(m_hAllocator, 1, &currBlockInfo.pMappedData);
+
12542 if(pDefragCtx->res == VK_SUCCESS)
+
+
12544 currBlockInfo.flags |= BLOCK_FLAG_MAPPED_FOR_DEFRAGMENTATION;
+
+
+
+
-
12550 for(
size_t moveIndex = 0; moveIndex < moveCount; ++moveIndex)
-
-
12552 const VmaDefragmentationMove& move = moves[moveIndex];
-
-
12554 const BlockInfo& srcBlockInfo = blockInfo[move.srcBlockIndex];
-
12555 const BlockInfo& dstBlockInfo = blockInfo[move.dstBlockIndex];
-
-
12557 VMA_ASSERT(srcBlockInfo.pMappedData && dstBlockInfo.pMappedData);
-
-
-
-
-
12562 VmaDeviceMemoryBlock*
const pSrcBlock = m_Blocks[move.srcBlockIndex];
-
12563 memRange.memory = pSrcBlock->GetDeviceMemory();
-
12564 memRange.offset = VmaAlignDown(move.srcOffset, nonCoherentAtomSize);
-
12565 memRange.size = VMA_MIN(
-
12566 VmaAlignUp(move.size + (move.srcOffset - memRange.offset), nonCoherentAtomSize),
-
12567 pSrcBlock->m_pMetadata->GetSize() - memRange.offset);
-
12568 (*m_hAllocator->GetVulkanFunctions().vkInvalidateMappedMemoryRanges)(m_hAllocator->m_hDevice, 1, &memRange);
-
-
-
-
-
12573 reinterpret_cast<char*>(dstBlockInfo.pMappedData) + move.dstOffset,
-
12574 reinterpret_cast<char*>(srcBlockInfo.pMappedData) + move.srcOffset,
-
12575 static_cast<size_t>(move.size));
+
+
12551 if(pDefragCtx->res == VK_SUCCESS)
+
+
12553 const VkDeviceSize nonCoherentAtomSize = m_hAllocator->m_PhysicalDeviceProperties.limits.nonCoherentAtomSize;
+
12554 VkMappedMemoryRange memRange = { VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE };
+
+
12556 for(
size_t moveIndex = 0; moveIndex < moveCount; ++moveIndex)
+
+
12558 const VmaDefragmentationMove& move = moves[moveIndex];
+
+
12560 const BlockInfo& srcBlockInfo = blockInfo[move.srcBlockIndex];
+
12561 const BlockInfo& dstBlockInfo = blockInfo[move.dstBlockIndex];
+
+
12563 VMA_ASSERT(srcBlockInfo.pMappedData && dstBlockInfo.pMappedData);
+
+
+
+
+
12568 VmaDeviceMemoryBlock*
const pSrcBlock = m_Blocks[move.srcBlockIndex];
+
12569 memRange.memory = pSrcBlock->GetDeviceMemory();
+
12570 memRange.offset = VmaAlignDown(move.srcOffset, nonCoherentAtomSize);
+
12571 memRange.size = VMA_MIN(
+
12572 VmaAlignUp(move.size + (move.srcOffset - memRange.offset), nonCoherentAtomSize),
+
12573 pSrcBlock->m_pMetadata->GetSize() - memRange.offset);
+
12574 (*m_hAllocator->GetVulkanFunctions().vkInvalidateMappedMemoryRanges)(m_hAllocator->m_hDevice, 1, &memRange);
+
-
12577 if(IsCorruptionDetectionEnabled())
-
-
12579 VmaWriteMagicValue(dstBlockInfo.pMappedData, move.dstOffset - VMA_DEBUG_MARGIN);
-
12580 VmaWriteMagicValue(dstBlockInfo.pMappedData, move.dstOffset + move.size);
-
+
+
+
12579 reinterpret_cast<char*>(dstBlockInfo.pMappedData) + move.dstOffset,
+
12580 reinterpret_cast<char*>(srcBlockInfo.pMappedData) + move.srcOffset,
+
12581 static_cast<size_t>(move.size));
-
-
-
-
12586 VmaDeviceMemoryBlock*
const pDstBlock = m_Blocks[move.dstBlockIndex];
-
12587 memRange.memory = pDstBlock->GetDeviceMemory();
-
12588 memRange.offset = VmaAlignDown(move.dstOffset, nonCoherentAtomSize);
-
12589 memRange.size = VMA_MIN(
-
12590 VmaAlignUp(move.size + (move.dstOffset - memRange.offset), nonCoherentAtomSize),
-
12591 pDstBlock->m_pMetadata->GetSize() - memRange.offset);
-
12592 (*m_hAllocator->GetVulkanFunctions().vkFlushMappedMemoryRanges)(m_hAllocator->m_hDevice, 1, &memRange);
-
-
-
-
-
-
-
12599 for(
size_t blockIndex = blockCount; blockIndex--; )
-
-
12601 const BlockInfo& currBlockInfo = blockInfo[blockIndex];
-
12602 if((currBlockInfo.flags & BLOCK_FLAG_MAPPED_FOR_DEFRAGMENTATION) != 0)
-
-
12604 VmaDeviceMemoryBlock* pBlock = m_Blocks[blockIndex];
-
12605 pBlock->Unmap(m_hAllocator, 1);
-
-
-
-
-
12610 void VmaBlockVector::ApplyDefragmentationMovesGpu(
-
12611 class VmaBlockVectorDefragmentationContext* pDefragCtx,
-
12612 const VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves,
-
12613 VkCommandBuffer commandBuffer)
-
-
12615 const size_t blockCount = m_Blocks.size();
-
-
12617 pDefragCtx->blockContexts.resize(blockCount);
-
12618 memset(pDefragCtx->blockContexts.data(), 0, blockCount *
sizeof(VmaBlockDefragmentationContext));
-
-
-
12621 const size_t moveCount = moves.size();
-
12622 for(
size_t moveIndex = 0; moveIndex < moveCount; ++moveIndex)
-
-
12624 const VmaDefragmentationMove& move = moves[moveIndex];
-
12625 pDefragCtx->blockContexts[move.srcBlockIndex].flags |= VmaBlockDefragmentationContext::BLOCK_FLAG_USED;
-
12626 pDefragCtx->blockContexts[move.dstBlockIndex].flags |= VmaBlockDefragmentationContext::BLOCK_FLAG_USED;
-
-
-
12629 VMA_ASSERT(pDefragCtx->res == VK_SUCCESS);
-
-
-
-
12633 VkBufferCreateInfo bufCreateInfo;
-
12634 VmaFillGpuDefragmentationBufferCreateInfo(bufCreateInfo);
-
-
12636 for(
size_t blockIndex = 0; pDefragCtx->res == VK_SUCCESS && blockIndex < blockCount; ++blockIndex)
-
-
12638 VmaBlockDefragmentationContext& currBlockCtx = pDefragCtx->blockContexts[blockIndex];
-
12639 VmaDeviceMemoryBlock* pBlock = m_Blocks[blockIndex];
-
12640 if((currBlockCtx.flags & VmaBlockDefragmentationContext::BLOCK_FLAG_USED) != 0)
-
-
12642 bufCreateInfo.size = pBlock->m_pMetadata->GetSize();
-
12643 pDefragCtx->res = (*m_hAllocator->GetVulkanFunctions().vkCreateBuffer)(
-
12644 m_hAllocator->m_hDevice, &bufCreateInfo, m_hAllocator->GetAllocationCallbacks(), &currBlockCtx.hBuffer);
-
12645 if(pDefragCtx->res == VK_SUCCESS)
-
-
12647 pDefragCtx->res = (*m_hAllocator->GetVulkanFunctions().vkBindBufferMemory)(
-
12648 m_hAllocator->m_hDevice, currBlockCtx.hBuffer, pBlock->GetDeviceMemory(), 0);
-
-
-
-
-
-
-
12655 if(pDefragCtx->res == VK_SUCCESS)
-
-
12657 for(
size_t moveIndex = 0; moveIndex < moveCount; ++moveIndex)
-
-
12659 const VmaDefragmentationMove& move = moves[moveIndex];
-
-
12661 const VmaBlockDefragmentationContext& srcBlockCtx = pDefragCtx->blockContexts[move.srcBlockIndex];
-
12662 const VmaBlockDefragmentationContext& dstBlockCtx = pDefragCtx->blockContexts[move.dstBlockIndex];
-
-
12664 VMA_ASSERT(srcBlockCtx.hBuffer && dstBlockCtx.hBuffer);
-
-
12666 VkBufferCopy region = {
-
-
-
-
12670 (*m_hAllocator->GetVulkanFunctions().vkCmdCopyBuffer)(
-
12671 commandBuffer, srcBlockCtx.hBuffer, dstBlockCtx.hBuffer, 1, ®ion);
-
-
-
-
-
12676 if(pDefragCtx->res == VK_SUCCESS && moveCount > 0)
-
-
12678 pDefragCtx->res = VK_NOT_READY;
+
12583 if(IsCorruptionDetectionEnabled())
+
+
12585 VmaWriteMagicValue(dstBlockInfo.pMappedData, move.dstOffset - VMA_DEBUG_MARGIN);
+
12586 VmaWriteMagicValue(dstBlockInfo.pMappedData, move.dstOffset + move.size);
+
+
+
+
+
+
12592 VmaDeviceMemoryBlock*
const pDstBlock = m_Blocks[move.dstBlockIndex];
+
12593 memRange.memory = pDstBlock->GetDeviceMemory();
+
12594 memRange.offset = VmaAlignDown(move.dstOffset, nonCoherentAtomSize);
+
12595 memRange.size = VMA_MIN(
+
12596 VmaAlignUp(move.size + (move.dstOffset - memRange.offset), nonCoherentAtomSize),
+
12597 pDstBlock->m_pMetadata->GetSize() - memRange.offset);
+
12598 (*m_hAllocator->GetVulkanFunctions().vkFlushMappedMemoryRanges)(m_hAllocator->m_hDevice, 1, &memRange);
+
+
+
+
+
+
+
12605 for(
size_t blockIndex = blockCount; blockIndex--; )
+
+
12607 const BlockInfo& currBlockInfo = blockInfo[blockIndex];
+
12608 if((currBlockInfo.flags & BLOCK_FLAG_MAPPED_FOR_DEFRAGMENTATION) != 0)
+
+
12610 VmaDeviceMemoryBlock* pBlock = m_Blocks[blockIndex];
+
12611 pBlock->Unmap(m_hAllocator, 1);
+
+
+
+
+
12616 void VmaBlockVector::ApplyDefragmentationMovesGpu(
+
12617 class VmaBlockVectorDefragmentationContext* pDefragCtx,
+
12618 const VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves,
+
12619 VkCommandBuffer commandBuffer)
+
+
12621 const size_t blockCount = m_Blocks.size();
+
+
12623 pDefragCtx->blockContexts.resize(blockCount);
+
12624 memset(pDefragCtx->blockContexts.data(), 0, blockCount *
sizeof(VmaBlockDefragmentationContext));
+
+
+
12627 const size_t moveCount = moves.size();
+
12628 for(
size_t moveIndex = 0; moveIndex < moveCount; ++moveIndex)
+
+
12630 const VmaDefragmentationMove& move = moves[moveIndex];
+
12631 pDefragCtx->blockContexts[move.srcBlockIndex].flags |= VmaBlockDefragmentationContext::BLOCK_FLAG_USED;
+
12632 pDefragCtx->blockContexts[move.dstBlockIndex].flags |= VmaBlockDefragmentationContext::BLOCK_FLAG_USED;
+
+
+
12635 VMA_ASSERT(pDefragCtx->res == VK_SUCCESS);
+
+
+
+
12639 VkBufferCreateInfo bufCreateInfo;
+
12640 VmaFillGpuDefragmentationBufferCreateInfo(bufCreateInfo);
+
+
12642 for(
size_t blockIndex = 0; pDefragCtx->res == VK_SUCCESS && blockIndex < blockCount; ++blockIndex)
+
+
12644 VmaBlockDefragmentationContext& currBlockCtx = pDefragCtx->blockContexts[blockIndex];
+
12645 VmaDeviceMemoryBlock* pBlock = m_Blocks[blockIndex];
+
12646 if((currBlockCtx.flags & VmaBlockDefragmentationContext::BLOCK_FLAG_USED) != 0)
+
+
12648 bufCreateInfo.size = pBlock->m_pMetadata->GetSize();
+
12649 pDefragCtx->res = (*m_hAllocator->GetVulkanFunctions().vkCreateBuffer)(
+
12650 m_hAllocator->m_hDevice, &bufCreateInfo, m_hAllocator->GetAllocationCallbacks(), &currBlockCtx.hBuffer);
+
12651 if(pDefragCtx->res == VK_SUCCESS)
+
+
12653 pDefragCtx->res = (*m_hAllocator->GetVulkanFunctions().vkBindBufferMemory)(
+
12654 m_hAllocator->m_hDevice, currBlockCtx.hBuffer, pBlock->GetDeviceMemory(), 0);
+
+
+
+
+
+
+
12661 if(pDefragCtx->res == VK_SUCCESS)
+
+
12663 for(
size_t moveIndex = 0; moveIndex < moveCount; ++moveIndex)
+
+
12665 const VmaDefragmentationMove& move = moves[moveIndex];
+
+
12667 const VmaBlockDefragmentationContext& srcBlockCtx = pDefragCtx->blockContexts[move.srcBlockIndex];
+
12668 const VmaBlockDefragmentationContext& dstBlockCtx = pDefragCtx->blockContexts[move.dstBlockIndex];
+
+
12670 VMA_ASSERT(srcBlockCtx.hBuffer && dstBlockCtx.hBuffer);
+
+
12672 VkBufferCopy region = {
+
+
+
+
12676 (*m_hAllocator->GetVulkanFunctions().vkCmdCopyBuffer)(
+
12677 commandBuffer, srcBlockCtx.hBuffer, dstBlockCtx.hBuffer, 1, ®ion);
+
-
-
-
-
-
12684 for(
size_t blockIndex = m_Blocks.size(); blockIndex--; )
-
-
12686 VmaDeviceMemoryBlock* pBlock = m_Blocks[blockIndex];
-
12687 if(pBlock->m_pMetadata->IsEmpty())
-
-
12689 if(m_Blocks.size() > m_MinBlockCount)
-
-
12691 if(pDefragmentationStats != VMA_NULL)
-
-
-
12694 pDefragmentationStats->
bytesFreed += pBlock->m_pMetadata->GetSize();
-
-
-
12697 VmaVectorRemove(m_Blocks, blockIndex);
-
12698 pBlock->Destroy(m_hAllocator);
-
12699 vma_delete(m_hAllocator, pBlock);
-
-
-
-
-
-
-
-
12707 UpdateHasEmptyBlock();
-
-
-
12710 void VmaBlockVector::UpdateHasEmptyBlock()
-
-
12712 m_HasEmptyBlock =
false;
-
12713 for(
size_t index = 0, count = m_Blocks.size(); index < count; ++index)
-
-
12715 VmaDeviceMemoryBlock*
const pBlock = m_Blocks[index];
-
12716 if(pBlock->m_pMetadata->IsEmpty())
-
-
12718 m_HasEmptyBlock =
true;
-
-
-
-
-
-
12724 #if VMA_STATS_STRING_ENABLED
-
-
12726 void VmaBlockVector::PrintDetailedMap(
class VmaJsonWriter& json)
-
-
12728 VmaMutexLockRead lock(m_Mutex, m_hAllocator->m_UseMutex);
+
+
+
12682 if(pDefragCtx->res == VK_SUCCESS && moveCount > 0)
+
+
12684 pDefragCtx->res = VK_NOT_READY;
+
+
+
+
+
+
12690 for(
size_t blockIndex = m_Blocks.size(); blockIndex--; )
+
+
12692 VmaDeviceMemoryBlock* pBlock = m_Blocks[blockIndex];
+
12693 if(pBlock->m_pMetadata->IsEmpty())
+
+
12695 if(m_Blocks.size() > m_MinBlockCount)
+
+
12697 if(pDefragmentationStats != VMA_NULL)
+
+
+
12700 pDefragmentationStats->
bytesFreed += pBlock->m_pMetadata->GetSize();
+
+
+
12703 VmaVectorRemove(m_Blocks, blockIndex);
+
12704 pBlock->Destroy(m_hAllocator);
+
12705 vma_delete(m_hAllocator, pBlock);
+
+
+
+
+
+
+
+
12713 UpdateHasEmptyBlock();
+
+
+
12716 void VmaBlockVector::UpdateHasEmptyBlock()
+
+
12718 m_HasEmptyBlock =
false;
+
12719 for(
size_t index = 0, count = m_Blocks.size(); index < count; ++index)
+
+
12721 VmaDeviceMemoryBlock*
const pBlock = m_Blocks[index];
+
12722 if(pBlock->m_pMetadata->IsEmpty())
+
+
12724 m_HasEmptyBlock =
true;
+
+
+
+
-
12730 json.BeginObject();
+
12730 #if VMA_STATS_STRING_ENABLED
-
-
-
12734 const char* poolName = m_hParentPool->GetName();
-
12735 if(poolName != VMA_NULL && poolName[0] !=
'\0')
-
-
12737 json.WriteString(
"Name");
-
12738 json.WriteString(poolName);
-
-
-
12741 json.WriteString(
"MemoryTypeIndex");
-
12742 json.WriteNumber(m_MemoryTypeIndex);
-
-
12744 json.WriteString(
"BlockSize");
-
12745 json.WriteNumber(m_PreferredBlockSize);
+
12732 void VmaBlockVector::PrintDetailedMap(
class VmaJsonWriter& json)
+
+
12734 VmaMutexLockRead lock(m_Mutex, m_hAllocator->m_UseMutex);
+
+
12736 json.BeginObject();
+
+
+
+
12740 const char* poolName = m_hParentPool->GetName();
+
12741 if(poolName != VMA_NULL && poolName[0] !=
'\0')
+
+
12743 json.WriteString(
"Name");
+
12744 json.WriteString(poolName);
+
-
12747 json.WriteString(
"BlockCount");
-
12748 json.BeginObject(
true);
-
12749 if(m_MinBlockCount > 0)
-
-
12751 json.WriteString(
"Min");
-
12752 json.WriteNumber((uint64_t)m_MinBlockCount);
-
-
12754 if(m_MaxBlockCount < SIZE_MAX)
-
-
12756 json.WriteString(
"Max");
-
12757 json.WriteNumber((uint64_t)m_MaxBlockCount);
-
-
12759 json.WriteString(
"Cur");
-
12760 json.WriteNumber((uint64_t)m_Blocks.size());
-
-
-
12763 if(m_FrameInUseCount > 0)
-
-
12765 json.WriteString(
"FrameInUseCount");
-
12766 json.WriteNumber(m_FrameInUseCount);
-
+
12747 json.WriteString(
"MemoryTypeIndex");
+
12748 json.WriteNumber(m_MemoryTypeIndex);
+
+
12750 json.WriteString(
"BlockSize");
+
12751 json.WriteNumber(m_PreferredBlockSize);
+
+
12753 json.WriteString(
"BlockCount");
+
12754 json.BeginObject(
true);
+
12755 if(m_MinBlockCount > 0)
+
+
12757 json.WriteString(
"Min");
+
12758 json.WriteNumber((uint64_t)m_MinBlockCount);
+
+
12760 if(m_MaxBlockCount < SIZE_MAX)
+
+
12762 json.WriteString(
"Max");
+
12763 json.WriteNumber((uint64_t)m_MaxBlockCount);
+
+
12765 json.WriteString(
"Cur");
+
12766 json.WriteNumber((uint64_t)m_Blocks.size());
+
-
12769 if(m_Algorithm != 0)
+
12769 if(m_FrameInUseCount > 0)
-
12771 json.WriteString(
"Algorithm");
-
12772 json.WriteString(VmaAlgorithmToStr(m_Algorithm));
+
12771 json.WriteString(
"FrameInUseCount");
+
12772 json.WriteNumber(m_FrameInUseCount);
-
-
-
-
12777 json.WriteString(
"PreferredBlockSize");
-
12778 json.WriteNumber(m_PreferredBlockSize);
-
-
-
12781 json.WriteString(
"Blocks");
-
12782 json.BeginObject();
-
12783 for(
size_t i = 0; i < m_Blocks.size(); ++i)
-
-
12785 json.BeginString();
-
12786 json.ContinueString(m_Blocks[i]->GetId());
-
-
-
12789 m_Blocks[i]->m_pMetadata->PrintDetailedMap(json);
-
-
-
-
-
-
-
12796 #endif // #if VMA_STATS_STRING_ENABLED
-
-
12798 void VmaBlockVector::Defragment(
-
12799 class VmaBlockVectorDefragmentationContext* pCtx,
-
-
12801 VkDeviceSize& maxCpuBytesToMove, uint32_t& maxCpuAllocationsToMove,
-
12802 VkDeviceSize& maxGpuBytesToMove, uint32_t& maxGpuAllocationsToMove,
-
12803 VkCommandBuffer commandBuffer)
-
-
12805 pCtx->res = VK_SUCCESS;
-
-
12807 const VkMemoryPropertyFlags memPropFlags =
-
12808 m_hAllocator->m_MemProps.memoryTypes[m_MemoryTypeIndex].propertyFlags;
-
12809 const bool isHostVisible = (memPropFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0;
-
-
12811 const bool canDefragmentOnCpu = maxCpuBytesToMove > 0 && maxCpuAllocationsToMove > 0 &&
-
-
12813 const bool canDefragmentOnGpu = maxGpuBytesToMove > 0 && maxGpuAllocationsToMove > 0 &&
-
12814 !IsCorruptionDetectionEnabled() &&
-
12815 ((1u << m_MemoryTypeIndex) & m_hAllocator->GetGpuDefragmentationMemoryTypeBits()) != 0;
+
+
12775 if(m_Algorithm != 0)
+
+
12777 json.WriteString(
"Algorithm");
+
12778 json.WriteString(VmaAlgorithmToStr(m_Algorithm));
+
+
+
+
+
12783 json.WriteString(
"PreferredBlockSize");
+
12784 json.WriteNumber(m_PreferredBlockSize);
+
+
+
12787 json.WriteString(
"Blocks");
+
12788 json.BeginObject();
+
12789 for(
size_t i = 0; i < m_Blocks.size(); ++i)
+
+
12791 json.BeginString();
+
12792 json.ContinueString(m_Blocks[i]->GetId());
+
+
+
12795 m_Blocks[i]->m_pMetadata->PrintDetailedMap(json);
+
+
+
+
+
+
+
12802 #endif // #if VMA_STATS_STRING_ENABLED
+
+
12804 void VmaBlockVector::Defragment(
+
12805 class VmaBlockVectorDefragmentationContext* pCtx,
+
+
12807 VkDeviceSize& maxCpuBytesToMove, uint32_t& maxCpuAllocationsToMove,
+
12808 VkDeviceSize& maxGpuBytesToMove, uint32_t& maxGpuAllocationsToMove,
+
12809 VkCommandBuffer commandBuffer)
+
+
12811 pCtx->res = VK_SUCCESS;
+
+
12813 const VkMemoryPropertyFlags memPropFlags =
+
12814 m_hAllocator->m_MemProps.memoryTypes[m_MemoryTypeIndex].propertyFlags;
+
12815 const bool isHostVisible = (memPropFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0;
-
-
12818 if(canDefragmentOnCpu || canDefragmentOnGpu)
-
-
12820 bool defragmentOnGpu;
-
-
12822 if(canDefragmentOnGpu != canDefragmentOnCpu)
-
-
12824 defragmentOnGpu = canDefragmentOnGpu;
-
-
-
-
-
12829 defragmentOnGpu = (memPropFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != 0 ||
-
12830 m_hAllocator->IsIntegratedGpu();
+
12817 const bool canDefragmentOnCpu = maxCpuBytesToMove > 0 && maxCpuAllocationsToMove > 0 &&
+
+
12819 const bool canDefragmentOnGpu = maxGpuBytesToMove > 0 && maxGpuAllocationsToMove > 0 &&
+
12820 !IsCorruptionDetectionEnabled() &&
+
12821 ((1u << m_MemoryTypeIndex) & m_hAllocator->GetGpuDefragmentationMemoryTypeBits()) != 0;
+
+
+
12824 if(canDefragmentOnCpu || canDefragmentOnGpu)
+
+
12826 bool defragmentOnGpu;
+
+
12828 if(canDefragmentOnGpu != canDefragmentOnCpu)
+
+
12830 defragmentOnGpu = canDefragmentOnGpu;
-
-
12833 bool overlappingMoveSupported = !defragmentOnGpu;
-
-
12835 if(m_hAllocator->m_UseMutex)
-
-
12837 m_Mutex.LockWrite();
-
12838 pCtx->mutexLocked =
true;
-
+
+
+
+
12835 defragmentOnGpu = (memPropFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != 0 ||
+
12836 m_hAllocator->IsIntegratedGpu();
+
+
+
12839 bool overlappingMoveSupported = !defragmentOnGpu;
-
12841 pCtx->Begin(overlappingMoveSupported);
-
-
-
-
12845 const VkDeviceSize maxBytesToMove = defragmentOnGpu ? maxGpuBytesToMove : maxCpuBytesToMove;
-
12846 const uint32_t maxAllocationsToMove = defragmentOnGpu ? maxGpuAllocationsToMove : maxCpuAllocationsToMove;
-
12847 VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> > moves =
-
12848 VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >(VmaStlAllocator<VmaDefragmentationMove>(m_hAllocator->GetAllocationCallbacks()));
-
12849 pCtx->res = pCtx->GetAlgorithm()->Defragment(moves, maxBytesToMove, maxAllocationsToMove);
+
12841 if(m_hAllocator->m_UseMutex)
+
+
12843 m_Mutex.LockWrite();
+
12844 pCtx->mutexLocked =
true;
+
+
+
12847 pCtx->Begin(overlappingMoveSupported);
+
+
-
-
12852 if(pStats != VMA_NULL)
-
-
12854 const VkDeviceSize bytesMoved = pCtx->GetAlgorithm()->GetBytesMoved();
-
12855 const uint32_t allocationsMoved = pCtx->GetAlgorithm()->GetAllocationsMoved();
-
-
-
12858 VMA_ASSERT(bytesMoved <= maxBytesToMove);
-
12859 VMA_ASSERT(allocationsMoved <= maxAllocationsToMove);
-
12860 if(defragmentOnGpu)
-
-
12862 maxGpuBytesToMove -= bytesMoved;
-
12863 maxGpuAllocationsToMove -= allocationsMoved;
-
-
-
-
12867 maxCpuBytesToMove -= bytesMoved;
-
12868 maxCpuAllocationsToMove -= allocationsMoved;
-
-
-
-
12872 if(pCtx->res >= VK_SUCCESS)
-
-
12874 if(defragmentOnGpu)
-
-
12876 ApplyDefragmentationMovesGpu(pCtx, moves, commandBuffer);
-
-
-
-
12880 ApplyDefragmentationMovesCpu(pCtx, moves);
-
-
-
-
-
-
12886 void VmaBlockVector::DefragmentationEnd(
-
12887 class VmaBlockVectorDefragmentationContext* pCtx,
-
-
-
-
12891 for(
size_t blockIndex = pCtx->blockContexts.size(); blockIndex--; )
-
-
12893 VmaBlockDefragmentationContext& blockCtx = pCtx->blockContexts[blockIndex];
-
12894 if(blockCtx.hBuffer)
-
-
12896 (*m_hAllocator->GetVulkanFunctions().vkDestroyBuffer)(
-
12897 m_hAllocator->m_hDevice, blockCtx.hBuffer, m_hAllocator->GetAllocationCallbacks());
-
-
-
-
12901 if(pCtx->res >= VK_SUCCESS)
-
-
12903 FreeEmptyBlocks(pStats);
-
-
-
12906 if(pCtx->mutexLocked)
-
-
12908 VMA_ASSERT(m_hAllocator->m_UseMutex);
-
12909 m_Mutex.UnlockWrite();
+
12851 const VkDeviceSize maxBytesToMove = defragmentOnGpu ? maxGpuBytesToMove : maxCpuBytesToMove;
+
12852 const uint32_t maxAllocationsToMove = defragmentOnGpu ? maxGpuAllocationsToMove : maxCpuAllocationsToMove;
+
12853 VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> > moves =
+
12854 VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >(VmaStlAllocator<VmaDefragmentationMove>(m_hAllocator->GetAllocationCallbacks()));
+
12855 pCtx->res = pCtx->GetAlgorithm()->Defragment(moves, maxBytesToMove, maxAllocationsToMove);
+
+
+
12858 if(pStats != VMA_NULL)
+
+
12860 const VkDeviceSize bytesMoved = pCtx->GetAlgorithm()->GetBytesMoved();
+
12861 const uint32_t allocationsMoved = pCtx->GetAlgorithm()->GetAllocationsMoved();
+
+
+
12864 VMA_ASSERT(bytesMoved <= maxBytesToMove);
+
12865 VMA_ASSERT(allocationsMoved <= maxAllocationsToMove);
+
12866 if(defragmentOnGpu)
+
+
12868 maxGpuBytesToMove -= bytesMoved;
+
12869 maxGpuAllocationsToMove -= allocationsMoved;
+
+
+
+
12873 maxCpuBytesToMove -= bytesMoved;
+
12874 maxCpuAllocationsToMove -= allocationsMoved;
+
+
+
+
12878 if(pCtx->res >= VK_SUCCESS)
+
+
12880 if(defragmentOnGpu)
+
+
12882 ApplyDefragmentationMovesGpu(pCtx, moves, commandBuffer);
+
+
+
+
12886 ApplyDefragmentationMovesCpu(pCtx, moves);
+
+
+
+
+
+
12892 void VmaBlockVector::DefragmentationEnd(
+
12893 class VmaBlockVectorDefragmentationContext* pCtx,
+
+
+
+
12897 for(
size_t blockIndex = pCtx->blockContexts.size(); blockIndex--; )
+
+
12899 VmaBlockDefragmentationContext& blockCtx = pCtx->blockContexts[blockIndex];
+
12900 if(blockCtx.hBuffer)
+
+
12902 (*m_hAllocator->GetVulkanFunctions().vkDestroyBuffer)(
+
12903 m_hAllocator->m_hDevice, blockCtx.hBuffer, m_hAllocator->GetAllocationCallbacks());
+
+
+
+
12907 if(pCtx->res >= VK_SUCCESS)
+
+
12909 FreeEmptyBlocks(pStats);
-
-
-
12913 size_t VmaBlockVector::CalcAllocationCount()
const
-
-
-
12916 for(
size_t i = 0; i < m_Blocks.size(); ++i)
-
-
12918 result += m_Blocks[i]->m_pMetadata->GetAllocationCount();
-
-
-
-
-
12923 bool VmaBlockVector::IsBufferImageGranularityConflictPossible()
const
-
-
12925 if(m_BufferImageGranularity == 1)
-
-
-
-
12929 VmaSuballocationType lastSuballocType = VMA_SUBALLOCATION_TYPE_FREE;
-
12930 for(
size_t i = 0, count = m_Blocks.size(); i < count; ++i)
-
-
12932 VmaDeviceMemoryBlock*
const pBlock = m_Blocks[i];
-
12933 VMA_ASSERT(m_Algorithm == 0);
-
12934 VmaBlockMetadata_Generic*
const pMetadata = (VmaBlockMetadata_Generic*)pBlock->m_pMetadata;
-
12935 if(pMetadata->IsBufferImageGranularityConflictPossible(m_BufferImageGranularity, lastSuballocType))
-
-
-
-
-
-
-
-
12943 void VmaBlockVector::MakePoolAllocationsLost(
-
12944 uint32_t currentFrameIndex,
-
12945 size_t* pLostAllocationCount)
-
-
12947 VmaMutexLockWrite lock(m_Mutex, m_hAllocator->m_UseMutex);
-
12948 size_t lostAllocationCount = 0;
-
12949 for(uint32_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex)
-
-
12951 VmaDeviceMemoryBlock*
const pBlock = m_Blocks[blockIndex];
-
12952 VMA_ASSERT(pBlock);
-
12953 lostAllocationCount += pBlock->m_pMetadata->MakeAllocationsLost(currentFrameIndex, m_FrameInUseCount);
-
-
12955 if(pLostAllocationCount != VMA_NULL)
+
+
12912 if(pCtx->mutexLocked)
+
+
12914 VMA_ASSERT(m_hAllocator->m_UseMutex);
+
12915 m_Mutex.UnlockWrite();
+
+
+
+
12919 size_t VmaBlockVector::CalcAllocationCount()
const
+
+
+
12922 for(
size_t i = 0; i < m_Blocks.size(); ++i)
+
+
12924 result += m_Blocks[i]->m_pMetadata->GetAllocationCount();
+
+
+
+
+
12929 bool VmaBlockVector::IsBufferImageGranularityConflictPossible()
const
+
+
12931 if(m_BufferImageGranularity == 1)
+
+
+
+
12935 VmaSuballocationType lastSuballocType = VMA_SUBALLOCATION_TYPE_FREE;
+
12936 for(
size_t i = 0, count = m_Blocks.size(); i < count; ++i)
+
+
12938 VmaDeviceMemoryBlock*
const pBlock = m_Blocks[i];
+
12939 VMA_ASSERT(m_Algorithm == 0);
+
12940 VmaBlockMetadata_Generic*
const pMetadata = (VmaBlockMetadata_Generic*)pBlock->m_pMetadata;
+
12941 if(pMetadata->IsBufferImageGranularityConflictPossible(m_BufferImageGranularity, lastSuballocType))
+
+
+
+
+
+
+
+
12949 void VmaBlockVector::MakePoolAllocationsLost(
+
12950 uint32_t currentFrameIndex,
+
12951 size_t* pLostAllocationCount)
+
+
12953 VmaMutexLockWrite lock(m_Mutex, m_hAllocator->m_UseMutex);
+
12954 size_t lostAllocationCount = 0;
+
12955 for(uint32_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex)
-
12957 *pLostAllocationCount = lostAllocationCount;
-
-
-
-
12961 VkResult VmaBlockVector::CheckCorruption()
-
-
12963 if(!IsCorruptionDetectionEnabled())
-
-
12965 return VK_ERROR_FEATURE_NOT_PRESENT;
-
-
-
12968 VmaMutexLockRead lock(m_Mutex, m_hAllocator->m_UseMutex);
-
12969 for(uint32_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex)
+
12957 VmaDeviceMemoryBlock*
const pBlock = m_Blocks[blockIndex];
+
12958 VMA_ASSERT(pBlock);
+
12959 lostAllocationCount += pBlock->m_pMetadata->MakeAllocationsLost(currentFrameIndex, m_FrameInUseCount);
+
+
12961 if(pLostAllocationCount != VMA_NULL)
+
+
12963 *pLostAllocationCount = lostAllocationCount;
+
+
+
+
12967 VkResult VmaBlockVector::CheckCorruption()
+
+
12969 if(!IsCorruptionDetectionEnabled())
-
12971 VmaDeviceMemoryBlock*
const pBlock = m_Blocks[blockIndex];
-
12972 VMA_ASSERT(pBlock);
-
12973 VkResult res = pBlock->CheckCorruption(m_hAllocator);
-
12974 if(res != VK_SUCCESS)
-
-
-
-
-
-
-
-
12982 void VmaBlockVector::AddStats(
VmaStats* pStats)
-
-
12984 const uint32_t memTypeIndex = m_MemoryTypeIndex;
-
12985 const uint32_t memHeapIndex = m_hAllocator->MemoryTypeIndexToHeapIndex(memTypeIndex);
-
-
12987 VmaMutexLockRead lock(m_Mutex, m_hAllocator->m_UseMutex);
-
-
12989 for(uint32_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex)
-
-
12991 const VmaDeviceMemoryBlock*
const pBlock = m_Blocks[blockIndex];
-
12992 VMA_ASSERT(pBlock);
-
12993 VMA_HEAVY_ASSERT(pBlock->Validate());
-
-
12995 pBlock->m_pMetadata->CalcAllocationStatInfo(allocationStatInfo);
-
12996 VmaAddStatInfo(pStats->
total, allocationStatInfo);
-
12997 VmaAddStatInfo(pStats->
memoryType[memTypeIndex], allocationStatInfo);
-
12998 VmaAddStatInfo(pStats->
memoryHeap[memHeapIndex], allocationStatInfo);
-
-
-
-
-
-
13005 VmaDefragmentationAlgorithm_Generic::VmaDefragmentationAlgorithm_Generic(
-
-
13007 VmaBlockVector* pBlockVector,
-
13008 uint32_t currentFrameIndex,
-
13009 bool overlappingMoveSupported) :
-
13010 VmaDefragmentationAlgorithm(hAllocator, pBlockVector, currentFrameIndex),
-
13011 m_AllocationCount(0),
-
13012 m_AllAllocations(false),
-
-
13014 m_AllocationsMoved(0),
-
13015 m_Blocks(VmaStlAllocator<BlockInfo*>(hAllocator->GetAllocationCallbacks()))
-
-
-
13018 const size_t blockCount = m_pBlockVector->m_Blocks.size();
-
13019 for(
size_t blockIndex = 0; blockIndex < blockCount; ++blockIndex)
-
-
13021 BlockInfo* pBlockInfo = vma_new(m_hAllocator, BlockInfo)(m_hAllocator->GetAllocationCallbacks());
-
13022 pBlockInfo->m_OriginalBlockIndex = blockIndex;
-
13023 pBlockInfo->m_pBlock = m_pBlockVector->m_Blocks[blockIndex];
-
13024 m_Blocks.push_back(pBlockInfo);
-
-
-
-
13028 VMA_SORT(m_Blocks.begin(), m_Blocks.end(), BlockPointerLess());
-
-
-
13031 VmaDefragmentationAlgorithm_Generic::~VmaDefragmentationAlgorithm_Generic()
-
-
13033 for(
size_t i = m_Blocks.size(); i--; )
-
-
13035 vma_delete(m_hAllocator, m_Blocks[i]);
-
-
-
-
13039 void VmaDefragmentationAlgorithm_Generic::AddAllocation(
VmaAllocation hAlloc, VkBool32* pChanged)
-
-
-
13042 if(hAlloc->GetLastUseFrameIndex() != VMA_FRAME_INDEX_LOST)
-
-
13044 VmaDeviceMemoryBlock* pBlock = hAlloc->GetBlock();
-
13045 BlockInfoVector::iterator it = VmaBinaryFindFirstNotLess(m_Blocks.begin(), m_Blocks.end(), pBlock, BlockPointerLess());
-
13046 if(it != m_Blocks.end() && (*it)->m_pBlock == pBlock)
-
-
13048 AllocationInfo allocInfo = AllocationInfo(hAlloc, pChanged);
-
13049 (*it)->m_Allocations.push_back(allocInfo);
-
-
-
-
-
-
-
13056 ++m_AllocationCount;
-
-
-
-
13060 VkResult VmaDefragmentationAlgorithm_Generic::DefragmentRound(
-
13061 VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves,
-
13062 VkDeviceSize maxBytesToMove,
-
13063 uint32_t maxAllocationsToMove)
-
-
13065 if(m_Blocks.empty())
-
-
-
-
-
-
-
-
-
-
-
-
-
13078 size_t srcBlockMinIndex = 0;
-
-
-
-
-
-
-
-
-
-
-
-
-
13091 size_t srcBlockIndex = m_Blocks.size() - 1;
-
13092 size_t srcAllocIndex = SIZE_MAX;
-
-
-
-
-
-
13098 while(srcAllocIndex >= m_Blocks[srcBlockIndex]->m_Allocations.size())
-
-
13100 if(m_Blocks[srcBlockIndex]->m_Allocations.empty())
-
-
-
13103 if(srcBlockIndex == srcBlockMinIndex)
-
-
-
-
-
-
-
13110 srcAllocIndex = SIZE_MAX;
-
-
-
-
-
13115 srcAllocIndex = m_Blocks[srcBlockIndex]->m_Allocations.size() - 1;
-
-
-
-
13119 BlockInfo* pSrcBlockInfo = m_Blocks[srcBlockIndex];
-
13120 AllocationInfo& allocInfo = pSrcBlockInfo->m_Allocations[srcAllocIndex];
-
-
13122 const VkDeviceSize size = allocInfo.m_hAllocation->GetSize();
-
13123 const VkDeviceSize srcOffset = allocInfo.m_hAllocation->GetOffset();
-
13124 const VkDeviceSize alignment = allocInfo.m_hAllocation->GetAlignment();
-
13125 const VmaSuballocationType suballocType = allocInfo.m_hAllocation->GetSuballocationType();
-
-
-
13128 for(
size_t dstBlockIndex = 0; dstBlockIndex <= srcBlockIndex; ++dstBlockIndex)
-
-
13130 BlockInfo* pDstBlockInfo = m_Blocks[dstBlockIndex];
-
13131 VmaAllocationRequest dstAllocRequest;
-
13132 if(pDstBlockInfo->m_pBlock->m_pMetadata->CreateAllocationRequest(
-
13133 m_CurrentFrameIndex,
-
13134 m_pBlockVector->GetFrameInUseCount(),
-
13135 m_pBlockVector->GetBufferImageGranularity(),
-
-
-
-
-
-
-
13142 &dstAllocRequest) &&
-
-
13144 dstBlockIndex, dstAllocRequest.offset, srcBlockIndex, srcOffset))
-
-
13146 VMA_ASSERT(dstAllocRequest.itemsToMakeLostCount == 0);
-
-
-
13149 if((m_AllocationsMoved + 1 > maxAllocationsToMove) ||
-
13150 (m_BytesMoved + size > maxBytesToMove))
-
-
-
-
-
13155 VmaDefragmentationMove move;
-
13156 move.srcBlockIndex = pSrcBlockInfo->m_OriginalBlockIndex;
-
13157 move.dstBlockIndex = pDstBlockInfo->m_OriginalBlockIndex;
-
13158 move.srcOffset = srcOffset;
-
13159 move.dstOffset = dstAllocRequest.offset;
-
-
13161 moves.push_back(move);
-
-
13163 pDstBlockInfo->m_pBlock->m_pMetadata->Alloc(
-
-
-
-
13167 allocInfo.m_hAllocation);
-
13168 pSrcBlockInfo->m_pBlock->m_pMetadata->FreeAtOffset(srcOffset);
-
-
13170 allocInfo.m_hAllocation->ChangeBlockAllocation(m_hAllocator, pDstBlockInfo->m_pBlock, dstAllocRequest.offset);
-
-
13172 if(allocInfo.m_pChanged != VMA_NULL)
-
-
13174 *allocInfo.m_pChanged = VK_TRUE;
-
-
-
13177 ++m_AllocationsMoved;
-
13178 m_BytesMoved += size;
-
-
13180 VmaVectorRemove(pSrcBlockInfo->m_Allocations, srcAllocIndex);
-
-
-
-
+
12971 return VK_ERROR_FEATURE_NOT_PRESENT;
+
+
+
12974 VmaMutexLockRead lock(m_Mutex, m_hAllocator->m_UseMutex);
+
12975 for(uint32_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex)
+
+
12977 VmaDeviceMemoryBlock*
const pBlock = m_Blocks[blockIndex];
+
12978 VMA_ASSERT(pBlock);
+
12979 VkResult res = pBlock->CheckCorruption(m_hAllocator);
+
12980 if(res != VK_SUCCESS)
+
+
+
+
+
+
+
+
12988 void VmaBlockVector::AddStats(
VmaStats* pStats)
+
+
12990 const uint32_t memTypeIndex = m_MemoryTypeIndex;
+
12991 const uint32_t memHeapIndex = m_hAllocator->MemoryTypeIndexToHeapIndex(memTypeIndex);
+
+
12993 VmaMutexLockRead lock(m_Mutex, m_hAllocator->m_UseMutex);
+
+
12995 for(uint32_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex)
+
+
12997 const VmaDeviceMemoryBlock*
const pBlock = m_Blocks[blockIndex];
+
12998 VMA_ASSERT(pBlock);
+
12999 VMA_HEAVY_ASSERT(pBlock->Validate());
+
+
13001 pBlock->m_pMetadata->CalcAllocationStatInfo(allocationStatInfo);
+
13002 VmaAddStatInfo(pStats->
total, allocationStatInfo);
+
13003 VmaAddStatInfo(pStats->
memoryType[memTypeIndex], allocationStatInfo);
+
13004 VmaAddStatInfo(pStats->
memoryHeap[memHeapIndex], allocationStatInfo);
+
+
+
+
+
+
13011 VmaDefragmentationAlgorithm_Generic::VmaDefragmentationAlgorithm_Generic(
+
+
13013 VmaBlockVector* pBlockVector,
+
13014 uint32_t currentFrameIndex,
+
13015 bool overlappingMoveSupported) :
+
13016 VmaDefragmentationAlgorithm(hAllocator, pBlockVector, currentFrameIndex),
+
13017 m_AllocationCount(0),
+
13018 m_AllAllocations(false),
+
+
13020 m_AllocationsMoved(0),
+
13021 m_Blocks(VmaStlAllocator<BlockInfo*>(hAllocator->GetAllocationCallbacks()))
+
+
+
13024 const size_t blockCount = m_pBlockVector->m_Blocks.size();
+
13025 for(
size_t blockIndex = 0; blockIndex < blockCount; ++blockIndex)
+
+
13027 BlockInfo* pBlockInfo = vma_new(m_hAllocator, BlockInfo)(m_hAllocator->GetAllocationCallbacks());
+
13028 pBlockInfo->m_OriginalBlockIndex = blockIndex;
+
13029 pBlockInfo->m_pBlock = m_pBlockVector->m_Blocks[blockIndex];
+
13030 m_Blocks.push_back(pBlockInfo);
+
+
+
+
13034 VMA_SORT(m_Blocks.begin(), m_Blocks.end(), BlockPointerLess());
+
+
+
13037 VmaDefragmentationAlgorithm_Generic::~VmaDefragmentationAlgorithm_Generic()
+
+
13039 for(
size_t i = m_Blocks.size(); i--; )
+
+
13041 vma_delete(m_hAllocator, m_Blocks[i]);
+
+
+
+
13045 void VmaDefragmentationAlgorithm_Generic::AddAllocation(
VmaAllocation hAlloc, VkBool32* pChanged)
+
+
+
13048 if(hAlloc->GetLastUseFrameIndex() != VMA_FRAME_INDEX_LOST)
+
+
13050 VmaDeviceMemoryBlock* pBlock = hAlloc->GetBlock();
+
13051 BlockInfoVector::iterator it = VmaBinaryFindFirstNotLess(m_Blocks.begin(), m_Blocks.end(), pBlock, BlockPointerLess());
+
13052 if(it != m_Blocks.end() && (*it)->m_pBlock == pBlock)
+
+
13054 AllocationInfo allocInfo = AllocationInfo(hAlloc, pChanged);
+
13055 (*it)->m_Allocations.push_back(allocInfo);
+
+
+
+
+
+
+
13062 ++m_AllocationCount;
+
+
+
+
13066 VkResult VmaDefragmentationAlgorithm_Generic::DefragmentRound(
+
13067 VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves,
+
13068 VkDeviceSize maxBytesToMove,
+
13069 uint32_t maxAllocationsToMove)
+
+
13071 if(m_Blocks.empty())
+
+
+
+
+
+
+
+
+
+
+
+
+
13084 size_t srcBlockMinIndex = 0;
+
+
+
+
+
+
+
+
+
+
+
+
+
13097 size_t srcBlockIndex = m_Blocks.size() - 1;
+
13098 size_t srcAllocIndex = SIZE_MAX;
+
+
+
+
+
+
13104 while(srcAllocIndex >= m_Blocks[srcBlockIndex]->m_Allocations.size())
+
+
13106 if(m_Blocks[srcBlockIndex]->m_Allocations.empty())
+
+
+
13109 if(srcBlockIndex == srcBlockMinIndex)
+
+
+
+
+
+
+
13116 srcAllocIndex = SIZE_MAX;
+
+
+
+
+
13121 srcAllocIndex = m_Blocks[srcBlockIndex]->m_Allocations.size() - 1;
+
+
+
+
13125 BlockInfo* pSrcBlockInfo = m_Blocks[srcBlockIndex];
+
13126 AllocationInfo& allocInfo = pSrcBlockInfo->m_Allocations[srcAllocIndex];
+
+
13128 const VkDeviceSize size = allocInfo.m_hAllocation->GetSize();
+
13129 const VkDeviceSize srcOffset = allocInfo.m_hAllocation->GetOffset();
+
13130 const VkDeviceSize alignment = allocInfo.m_hAllocation->GetAlignment();
+
13131 const VmaSuballocationType suballocType = allocInfo.m_hAllocation->GetSuballocationType();
+
+
+
13134 for(
size_t dstBlockIndex = 0; dstBlockIndex <= srcBlockIndex; ++dstBlockIndex)
+
+
13136 BlockInfo* pDstBlockInfo = m_Blocks[dstBlockIndex];
+
13137 VmaAllocationRequest dstAllocRequest;
+
13138 if(pDstBlockInfo->m_pBlock->m_pMetadata->CreateAllocationRequest(
+
13139 m_CurrentFrameIndex,
+
13140 m_pBlockVector->GetFrameInUseCount(),
+
13141 m_pBlockVector->GetBufferImageGranularity(),
+
+
+
+
+
+
+
13148 &dstAllocRequest) &&
+
+
13150 dstBlockIndex, dstAllocRequest.offset, srcBlockIndex, srcOffset))
+
+
13152 VMA_ASSERT(dstAllocRequest.itemsToMakeLostCount == 0);
+
+
+
13155 if((m_AllocationsMoved + 1 > maxAllocationsToMove) ||
+
13156 (m_BytesMoved + size > maxBytesToMove))
+
+
+
+
+
13161 VmaDefragmentationMove move;
+
13162 move.srcBlockIndex = pSrcBlockInfo->m_OriginalBlockIndex;
+
13163 move.dstBlockIndex = pDstBlockInfo->m_OriginalBlockIndex;
+
13164 move.srcOffset = srcOffset;
+
13165 move.dstOffset = dstAllocRequest.offset;
+
+
13167 moves.push_back(move);
+
+
13169 pDstBlockInfo->m_pBlock->m_pMetadata->Alloc(
+
+
+
+
13173 allocInfo.m_hAllocation);
+
13174 pSrcBlockInfo->m_pBlock->m_pMetadata->FreeAtOffset(srcOffset);
+
+
13176 allocInfo.m_hAllocation->ChangeBlockAllocation(m_hAllocator, pDstBlockInfo->m_pBlock, dstAllocRequest.offset);
+
+
13178 if(allocInfo.m_pChanged != VMA_NULL)
+
+
13180 *allocInfo.m_pChanged = VK_TRUE;
+
+
+
13183 ++m_AllocationsMoved;
+
13184 m_BytesMoved += size;
-
+
13186 VmaVectorRemove(pSrcBlockInfo->m_Allocations, srcAllocIndex);
-
13188 if(srcAllocIndex > 0)
-
-
-
-
-
-
13194 if(srcBlockIndex > 0)
-
-
-
13197 srcAllocIndex = SIZE_MAX;
-
-
-
-
-
-
-
-
-
-
13207 size_t VmaDefragmentationAlgorithm_Generic::CalcBlocksWithNonMovableCount()
const
-
-
-
13210 for(
size_t i = 0; i < m_Blocks.size(); ++i)
-
-
13212 if(m_Blocks[i]->m_HasNonMovableAllocations)
-
-
-
-
-
-
-
-
13220 VkResult VmaDefragmentationAlgorithm_Generic::Defragment(
-
13221 VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves,
-
13222 VkDeviceSize maxBytesToMove,
-
13223 uint32_t maxAllocationsToMove)
-
-
13225 if(!m_AllAllocations && m_AllocationCount == 0)
-
-
-
-
-
13230 const size_t blockCount = m_Blocks.size();
-
13231 for(
size_t blockIndex = 0; blockIndex < blockCount; ++blockIndex)
+
+
+
+
+
+
+
13194 if(srcAllocIndex > 0)
+
+
+
+
+
+
13200 if(srcBlockIndex > 0)
+
+
+
13203 srcAllocIndex = SIZE_MAX;
+
+
+
+
+
+
+
+
+
+
13213 size_t VmaDefragmentationAlgorithm_Generic::CalcBlocksWithNonMovableCount()
const
+
+
+
13216 for(
size_t i = 0; i < m_Blocks.size(); ++i)
+
+
13218 if(m_Blocks[i]->m_HasNonMovableAllocations)
+
+
+
+
+
+
+
+
13226 VkResult VmaDefragmentationAlgorithm_Generic::Defragment(
+
13227 VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves,
+
13228 VkDeviceSize maxBytesToMove,
+
13229 uint32_t maxAllocationsToMove)
+
+
13231 if(!m_AllAllocations && m_AllocationCount == 0)
-
13233 BlockInfo* pBlockInfo = m_Blocks[blockIndex];
-
-
13235 if(m_AllAllocations)
-
-
13237 VmaBlockMetadata_Generic* pMetadata = (VmaBlockMetadata_Generic*)pBlockInfo->m_pBlock->m_pMetadata;
-
13238 for(VmaSuballocationList::const_iterator it = pMetadata->m_Suballocations.begin();
-
13239 it != pMetadata->m_Suballocations.end();
-
-
-
13242 if(it->type != VMA_SUBALLOCATION_TYPE_FREE)
-
-
13244 AllocationInfo allocInfo = AllocationInfo(it->hAllocation, VMA_NULL);
-
13245 pBlockInfo->m_Allocations.push_back(allocInfo);
-
-
-
-
-
13250 pBlockInfo->CalcHasNonMovableAllocations();
-
-
-
-
13254 pBlockInfo->SortAllocationsByOffsetDescending();
-
-
-
-
-
-
13260 VMA_SORT(m_Blocks.begin(), m_Blocks.end(), BlockInfoCompareMoveDestination());
-
-
-
13263 const uint32_t roundCount = 2;
+
+
+
+
13236 const size_t blockCount = m_Blocks.size();
+
13237 for(
size_t blockIndex = 0; blockIndex < blockCount; ++blockIndex)
+
+
13239 BlockInfo* pBlockInfo = m_Blocks[blockIndex];
+
+
13241 if(m_AllAllocations)
+
+
13243 VmaBlockMetadata_Generic* pMetadata = (VmaBlockMetadata_Generic*)pBlockInfo->m_pBlock->m_pMetadata;
+
13244 for(VmaSuballocationList::const_iterator it = pMetadata->m_Suballocations.begin();
+
13245 it != pMetadata->m_Suballocations.end();
+
+
+
13248 if(it->type != VMA_SUBALLOCATION_TYPE_FREE)
+
+
13250 AllocationInfo allocInfo = AllocationInfo(it->hAllocation, VMA_NULL);
+
13251 pBlockInfo->m_Allocations.push_back(allocInfo);
+
+
+
+
+
13256 pBlockInfo->CalcHasNonMovableAllocations();
+
+
+
+
13260 pBlockInfo->SortAllocationsByOffsetDescending();
+
+
+
-
-
13266 VkResult result = VK_SUCCESS;
-
13267 for(uint32_t round = 0; (round < roundCount) && (result == VK_SUCCESS); ++round)
-
-
13269 result = DefragmentRound(moves, maxBytesToMove, maxAllocationsToMove);
-
-
-
-
-
-
13275 bool VmaDefragmentationAlgorithm_Generic::MoveMakesSense(
-
13276 size_t dstBlockIndex, VkDeviceSize dstOffset,
-
13277 size_t srcBlockIndex, VkDeviceSize srcOffset)
-
-
13279 if(dstBlockIndex < srcBlockIndex)
-
-
-
-
13283 if(dstBlockIndex > srcBlockIndex)
-
-
-
-
13287 if(dstOffset < srcOffset)
-
-
-
-
-
-
-
-
-
13297 VmaDefragmentationAlgorithm_Fast::VmaDefragmentationAlgorithm_Fast(
-
-
13299 VmaBlockVector* pBlockVector,
-
13300 uint32_t currentFrameIndex,
-
13301 bool overlappingMoveSupported) :
-
13302 VmaDefragmentationAlgorithm(hAllocator, pBlockVector, currentFrameIndex),
-
13303 m_OverlappingMoveSupported(overlappingMoveSupported),
-
13304 m_AllocationCount(0),
-
13305 m_AllAllocations(false),
-
-
13307 m_AllocationsMoved(0),
-
13308 m_BlockInfos(VmaStlAllocator<BlockInfo>(hAllocator->GetAllocationCallbacks()))
-
-
13310 VMA_ASSERT(VMA_DEBUG_MARGIN == 0);
-
-
-
-
13314 VmaDefragmentationAlgorithm_Fast::~VmaDefragmentationAlgorithm_Fast()
+
+
13266 VMA_SORT(m_Blocks.begin(), m_Blocks.end(), BlockInfoCompareMoveDestination());
+
+
+
13269 const uint32_t roundCount = 2;
+
+
+
13272 VkResult result = VK_SUCCESS;
+
13273 for(uint32_t round = 0; (round < roundCount) && (result == VK_SUCCESS); ++round)
+
+
13275 result = DefragmentRound(moves, maxBytesToMove, maxAllocationsToMove);
+
+
+
+
+
+
13281 bool VmaDefragmentationAlgorithm_Generic::MoveMakesSense(
+
13282 size_t dstBlockIndex, VkDeviceSize dstOffset,
+
13283 size_t srcBlockIndex, VkDeviceSize srcOffset)
+
+
13285 if(dstBlockIndex < srcBlockIndex)
+
+
+
+
13289 if(dstBlockIndex > srcBlockIndex)
+
+
+
+
13293 if(dstOffset < srcOffset)
+
+
+
+
+
+
+
+
+
13303 VmaDefragmentationAlgorithm_Fast::VmaDefragmentationAlgorithm_Fast(
+
+
13305 VmaBlockVector* pBlockVector,
+
13306 uint32_t currentFrameIndex,
+
13307 bool overlappingMoveSupported) :
+
13308 VmaDefragmentationAlgorithm(hAllocator, pBlockVector, currentFrameIndex),
+
13309 m_OverlappingMoveSupported(overlappingMoveSupported),
+
13310 m_AllocationCount(0),
+
13311 m_AllAllocations(false),
+
+
13313 m_AllocationsMoved(0),
+
13314 m_BlockInfos(VmaStlAllocator<BlockInfo>(hAllocator->GetAllocationCallbacks()))
-
+
13316 VMA_ASSERT(VMA_DEBUG_MARGIN == 0);
-
13318 VkResult VmaDefragmentationAlgorithm_Fast::Defragment(
-
13319 VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves,
-
13320 VkDeviceSize maxBytesToMove,
-
13321 uint32_t maxAllocationsToMove)
-
-
13323 VMA_ASSERT(m_AllAllocations || m_pBlockVector->CalcAllocationCount() == m_AllocationCount);
-
-
13325 const size_t blockCount = m_pBlockVector->GetBlockCount();
-
13326 if(blockCount == 0 || maxBytesToMove == 0 || maxAllocationsToMove == 0)
-
-
-
+
+
+
13320 VmaDefragmentationAlgorithm_Fast::~VmaDefragmentationAlgorithm_Fast()
+
+
+
+
13324 VkResult VmaDefragmentationAlgorithm_Fast::Defragment(
+
13325 VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves,
+
13326 VkDeviceSize maxBytesToMove,
+
13327 uint32_t maxAllocationsToMove)
+
+
13329 VMA_ASSERT(m_AllAllocations || m_pBlockVector->CalcAllocationCount() == m_AllocationCount);
-
13331 PreprocessMetadata();
-
-
-
-
13335 m_BlockInfos.resize(blockCount);
-
13336 for(
size_t i = 0; i < blockCount; ++i)
-
-
13338 m_BlockInfos[i].origBlockIndex = i;
-
+
13331 const size_t blockCount = m_pBlockVector->GetBlockCount();
+
13332 if(blockCount == 0 || maxBytesToMove == 0 || maxAllocationsToMove == 0)
+
+
+
+
+
13337 PreprocessMetadata();
+
+
-
13341 VMA_SORT(m_BlockInfos.begin(), m_BlockInfos.end(), [
this](
const BlockInfo& lhs,
const BlockInfo& rhs) ->
bool {
-
13342 return m_pBlockVector->GetBlock(lhs.origBlockIndex)->m_pMetadata->GetSumFreeSize() <
-
13343 m_pBlockVector->GetBlock(rhs.origBlockIndex)->m_pMetadata->GetSumFreeSize();
-
-
-
-
-
13348 FreeSpaceDatabase freeSpaceDb;
-
-
13350 size_t dstBlockInfoIndex = 0;
-
13351 size_t dstOrigBlockIndex = m_BlockInfos[dstBlockInfoIndex].origBlockIndex;
-
13352 VmaDeviceMemoryBlock* pDstBlock = m_pBlockVector->GetBlock(dstOrigBlockIndex);
-
13353 VmaBlockMetadata_Generic* pDstMetadata = (VmaBlockMetadata_Generic*)pDstBlock->m_pMetadata;
-
13354 VkDeviceSize dstBlockSize = pDstMetadata->GetSize();
-
13355 VkDeviceSize dstOffset = 0;
-
-
-
13358 for(
size_t srcBlockInfoIndex = 0; !end && srcBlockInfoIndex < blockCount; ++srcBlockInfoIndex)
-
-
13360 const size_t srcOrigBlockIndex = m_BlockInfos[srcBlockInfoIndex].origBlockIndex;
-
13361 VmaDeviceMemoryBlock*
const pSrcBlock = m_pBlockVector->GetBlock(srcOrigBlockIndex);
-
13362 VmaBlockMetadata_Generic*
const pSrcMetadata = (VmaBlockMetadata_Generic*)pSrcBlock->m_pMetadata;
-
13363 for(VmaSuballocationList::iterator srcSuballocIt = pSrcMetadata->m_Suballocations.begin();
-
13364 !end && srcSuballocIt != pSrcMetadata->m_Suballocations.end(); )
-
-
13366 VmaAllocation_T*
const pAlloc = srcSuballocIt->hAllocation;
-
13367 const VkDeviceSize srcAllocAlignment = pAlloc->GetAlignment();
-
13368 const VkDeviceSize srcAllocSize = srcSuballocIt->size;
-
13369 if(m_AllocationsMoved == maxAllocationsToMove ||
-
13370 m_BytesMoved + srcAllocSize > maxBytesToMove)
-
-
-
-
-
13375 const VkDeviceSize srcAllocOffset = srcSuballocIt->offset;
-
-
-
13378 size_t freeSpaceInfoIndex;
-
13379 VkDeviceSize dstAllocOffset;
-
13380 if(freeSpaceDb.Fetch(srcAllocAlignment, srcAllocSize,
-
13381 freeSpaceInfoIndex, dstAllocOffset))
-
-
13383 size_t freeSpaceOrigBlockIndex = m_BlockInfos[freeSpaceInfoIndex].origBlockIndex;
-
13384 VmaDeviceMemoryBlock* pFreeSpaceBlock = m_pBlockVector->GetBlock(freeSpaceOrigBlockIndex);
-
13385 VmaBlockMetadata_Generic* pFreeSpaceMetadata = (VmaBlockMetadata_Generic*)pFreeSpaceBlock->m_pMetadata;
-
-
-
13388 if(freeSpaceInfoIndex == srcBlockInfoIndex)
-
-
13390 VMA_ASSERT(dstAllocOffset <= srcAllocOffset);
-
-
-
-
13394 VmaSuballocation suballoc = *srcSuballocIt;
-
13395 suballoc.offset = dstAllocOffset;
-
13396 suballoc.hAllocation->ChangeOffset(dstAllocOffset);
-
13397 m_BytesMoved += srcAllocSize;
-
13398 ++m_AllocationsMoved;
-
-
13400 VmaSuballocationList::iterator nextSuballocIt = srcSuballocIt;
-
-
13402 pSrcMetadata->m_Suballocations.erase(srcSuballocIt);
-
13403 srcSuballocIt = nextSuballocIt;
-
-
13405 InsertSuballoc(pFreeSpaceMetadata, suballoc);
-
-
13407 VmaDefragmentationMove move = {
-
13408 srcOrigBlockIndex, freeSpaceOrigBlockIndex,
-
13409 srcAllocOffset, dstAllocOffset,
-
-
13411 moves.push_back(move);
-
-
-
-
-
-
-
13418 VMA_ASSERT(freeSpaceInfoIndex < srcBlockInfoIndex);
-
-
13420 VmaSuballocation suballoc = *srcSuballocIt;
-
13421 suballoc.offset = dstAllocOffset;
-
13422 suballoc.hAllocation->ChangeBlockAllocation(m_hAllocator, pFreeSpaceBlock, dstAllocOffset);
-
13423 m_BytesMoved += srcAllocSize;
-
13424 ++m_AllocationsMoved;
+
13341 m_BlockInfos.resize(blockCount);
+
13342 for(
size_t i = 0; i < blockCount; ++i)
+
+
13344 m_BlockInfos[i].origBlockIndex = i;
+
+
+
13347 VMA_SORT(m_BlockInfos.begin(), m_BlockInfos.end(), [
this](
const BlockInfo& lhs,
const BlockInfo& rhs) ->
bool {
+
13348 return m_pBlockVector->GetBlock(lhs.origBlockIndex)->m_pMetadata->GetSumFreeSize() <
+
13349 m_pBlockVector->GetBlock(rhs.origBlockIndex)->m_pMetadata->GetSumFreeSize();
+
+
+
+
+
13354 FreeSpaceDatabase freeSpaceDb;
+
+
13356 size_t dstBlockInfoIndex = 0;
+
13357 size_t dstOrigBlockIndex = m_BlockInfos[dstBlockInfoIndex].origBlockIndex;
+
13358 VmaDeviceMemoryBlock* pDstBlock = m_pBlockVector->GetBlock(dstOrigBlockIndex);
+
13359 VmaBlockMetadata_Generic* pDstMetadata = (VmaBlockMetadata_Generic*)pDstBlock->m_pMetadata;
+
13360 VkDeviceSize dstBlockSize = pDstMetadata->GetSize();
+
13361 VkDeviceSize dstOffset = 0;
+
+
+
13364 for(
size_t srcBlockInfoIndex = 0; !end && srcBlockInfoIndex < blockCount; ++srcBlockInfoIndex)
+
+
13366 const size_t srcOrigBlockIndex = m_BlockInfos[srcBlockInfoIndex].origBlockIndex;
+
13367 VmaDeviceMemoryBlock*
const pSrcBlock = m_pBlockVector->GetBlock(srcOrigBlockIndex);
+
13368 VmaBlockMetadata_Generic*
const pSrcMetadata = (VmaBlockMetadata_Generic*)pSrcBlock->m_pMetadata;
+
13369 for(VmaSuballocationList::iterator srcSuballocIt = pSrcMetadata->m_Suballocations.begin();
+
13370 !end && srcSuballocIt != pSrcMetadata->m_Suballocations.end(); )
+
+
13372 VmaAllocation_T*
const pAlloc = srcSuballocIt->hAllocation;
+
13373 const VkDeviceSize srcAllocAlignment = pAlloc->GetAlignment();
+
13374 const VkDeviceSize srcAllocSize = srcSuballocIt->size;
+
13375 if(m_AllocationsMoved == maxAllocationsToMove ||
+
13376 m_BytesMoved + srcAllocSize > maxBytesToMove)
+
+
+
+
+
13381 const VkDeviceSize srcAllocOffset = srcSuballocIt->offset;
+
+
+
13384 size_t freeSpaceInfoIndex;
+
13385 VkDeviceSize dstAllocOffset;
+
13386 if(freeSpaceDb.Fetch(srcAllocAlignment, srcAllocSize,
+
13387 freeSpaceInfoIndex, dstAllocOffset))
+
+
13389 size_t freeSpaceOrigBlockIndex = m_BlockInfos[freeSpaceInfoIndex].origBlockIndex;
+
13390 VmaDeviceMemoryBlock* pFreeSpaceBlock = m_pBlockVector->GetBlock(freeSpaceOrigBlockIndex);
+
13391 VmaBlockMetadata_Generic* pFreeSpaceMetadata = (VmaBlockMetadata_Generic*)pFreeSpaceBlock->m_pMetadata;
+
+
+
13394 if(freeSpaceInfoIndex == srcBlockInfoIndex)
+
+
13396 VMA_ASSERT(dstAllocOffset <= srcAllocOffset);
+
+
+
+
13400 VmaSuballocation suballoc = *srcSuballocIt;
+
13401 suballoc.offset = dstAllocOffset;
+
13402 suballoc.hAllocation->ChangeOffset(dstAllocOffset);
+
13403 m_BytesMoved += srcAllocSize;
+
13404 ++m_AllocationsMoved;
+
+
13406 VmaSuballocationList::iterator nextSuballocIt = srcSuballocIt;
+
+
13408 pSrcMetadata->m_Suballocations.erase(srcSuballocIt);
+
13409 srcSuballocIt = nextSuballocIt;
+
+
13411 InsertSuballoc(pFreeSpaceMetadata, suballoc);
+
+
13413 VmaDefragmentationMove move = {
+
13414 srcOrigBlockIndex, freeSpaceOrigBlockIndex,
+
13415 srcAllocOffset, dstAllocOffset,
+
+
13417 moves.push_back(move);
+
+
+
+
+
+
+
13424 VMA_ASSERT(freeSpaceInfoIndex < srcBlockInfoIndex);
-
13426 VmaSuballocationList::iterator nextSuballocIt = srcSuballocIt;
-
-
13428 pSrcMetadata->m_Suballocations.erase(srcSuballocIt);
-
13429 srcSuballocIt = nextSuballocIt;
-
-
13431 InsertSuballoc(pFreeSpaceMetadata, suballoc);
-
-
13433 VmaDefragmentationMove move = {
-
13434 srcOrigBlockIndex, freeSpaceOrigBlockIndex,
-
13435 srcAllocOffset, dstAllocOffset,
-
-
13437 moves.push_back(move);
-
-
-
-
-
13442 dstAllocOffset = VmaAlignUp(dstOffset, srcAllocAlignment);
-
-
-
13445 while(dstBlockInfoIndex < srcBlockInfoIndex &&
-
13446 dstAllocOffset + srcAllocSize > dstBlockSize)
-
-
-
13449 freeSpaceDb.Register(dstBlockInfoIndex, dstOffset, dstBlockSize - dstOffset);
-
-
13451 ++dstBlockInfoIndex;
-
13452 dstOrigBlockIndex = m_BlockInfos[dstBlockInfoIndex].origBlockIndex;
-
13453 pDstBlock = m_pBlockVector->GetBlock(dstOrigBlockIndex);
-
13454 pDstMetadata = (VmaBlockMetadata_Generic*)pDstBlock->m_pMetadata;
-
13455 dstBlockSize = pDstMetadata->GetSize();
-
-
13457 dstAllocOffset = 0;
-
-
-
-
13461 if(dstBlockInfoIndex == srcBlockInfoIndex)
-
-
13463 VMA_ASSERT(dstAllocOffset <= srcAllocOffset);
-
-
13465 const bool overlap = dstAllocOffset + srcAllocSize > srcAllocOffset;
-
-
13467 bool skipOver = overlap;
-
13468 if(overlap && m_OverlappingMoveSupported && dstAllocOffset < srcAllocOffset)
-
-
-
-
13472 skipOver = (srcAllocOffset - dstAllocOffset) * 64 < srcAllocSize;
-
-
-
-
-
13477 freeSpaceDb.Register(dstBlockInfoIndex, dstOffset, srcAllocOffset - dstOffset);
-
-
13479 dstOffset = srcAllocOffset + srcAllocSize;
-
-
-
-
-
-
13485 srcSuballocIt->offset = dstAllocOffset;
-
13486 srcSuballocIt->hAllocation->ChangeOffset(dstAllocOffset);
-
13487 dstOffset = dstAllocOffset + srcAllocSize;
-
13488 m_BytesMoved += srcAllocSize;
-
13489 ++m_AllocationsMoved;
-
-
13491 VmaDefragmentationMove move = {
-
13492 srcOrigBlockIndex, dstOrigBlockIndex,
-
13493 srcAllocOffset, dstAllocOffset,
-
-
13495 moves.push_back(move);
-
-
-
-
-
-
-
-
13503 VMA_ASSERT(dstBlockInfoIndex < srcBlockInfoIndex);
-
13504 VMA_ASSERT(dstAllocOffset + srcAllocSize <= dstBlockSize);
-
-
13506 VmaSuballocation suballoc = *srcSuballocIt;
-
13507 suballoc.offset = dstAllocOffset;
-
13508 suballoc.hAllocation->ChangeBlockAllocation(m_hAllocator, pDstBlock, dstAllocOffset);
-
13509 dstOffset = dstAllocOffset + srcAllocSize;
-
13510 m_BytesMoved += srcAllocSize;
-
13511 ++m_AllocationsMoved;
-
-
13513 VmaSuballocationList::iterator nextSuballocIt = srcSuballocIt;
-
-
13515 pSrcMetadata->m_Suballocations.erase(srcSuballocIt);
-
13516 srcSuballocIt = nextSuballocIt;
-
-
13518 pDstMetadata->m_Suballocations.push_back(suballoc);
-
-
13520 VmaDefragmentationMove move = {
-
13521 srcOrigBlockIndex, dstOrigBlockIndex,
-
13522 srcAllocOffset, dstAllocOffset,
-
-
13524 moves.push_back(move);
-
-
-
-
-
-
13530 m_BlockInfos.clear();
-
-
13532 PostprocessMetadata();
-
-
-
-
-
13537 void VmaDefragmentationAlgorithm_Fast::PreprocessMetadata()
-
-
13539 const size_t blockCount = m_pBlockVector->GetBlockCount();
-
13540 for(
size_t blockIndex = 0; blockIndex < blockCount; ++blockIndex)
-
-
13542 VmaBlockMetadata_Generic*
const pMetadata =
-
13543 (VmaBlockMetadata_Generic*)m_pBlockVector->GetBlock(blockIndex)->m_pMetadata;
-
13544 pMetadata->m_FreeCount = 0;
-
13545 pMetadata->m_SumFreeSize = pMetadata->GetSize();
-
13546 pMetadata->m_FreeSuballocationsBySize.clear();
-
13547 for(VmaSuballocationList::iterator it = pMetadata->m_Suballocations.begin();
-
13548 it != pMetadata->m_Suballocations.end(); )
-
-
13550 if(it->type == VMA_SUBALLOCATION_TYPE_FREE)
-
-
13552 VmaSuballocationList::iterator nextIt = it;
-
-
13554 pMetadata->m_Suballocations.erase(it);
-
-
-
-
-
-
-
-
-
-
-
13565 void VmaDefragmentationAlgorithm_Fast::PostprocessMetadata()
-
-
13567 const size_t blockCount = m_pBlockVector->GetBlockCount();
-
13568 for(
size_t blockIndex = 0; blockIndex < blockCount; ++blockIndex)
-
-
13570 VmaBlockMetadata_Generic*
const pMetadata =
-
13571 (VmaBlockMetadata_Generic*)m_pBlockVector->GetBlock(blockIndex)->m_pMetadata;
-
13572 const VkDeviceSize blockSize = pMetadata->GetSize();
-
-
-
13575 if(pMetadata->m_Suballocations.empty())
-
-
13577 pMetadata->m_FreeCount = 1;
-
-
13579 VmaSuballocation suballoc = {
-
-
-
-
13583 VMA_SUBALLOCATION_TYPE_FREE };
-
13584 pMetadata->m_Suballocations.push_back(suballoc);
-
13585 pMetadata->RegisterFreeSuballocation(pMetadata->m_Suballocations.begin());
-
-
-
-
-
13590 VkDeviceSize offset = 0;
-
13591 VmaSuballocationList::iterator it;
-
13592 for(it = pMetadata->m_Suballocations.begin();
-
13593 it != pMetadata->m_Suballocations.end();
-
-
-
13596 VMA_ASSERT(it->type != VMA_SUBALLOCATION_TYPE_FREE);
-
13597 VMA_ASSERT(it->offset >= offset);
-
-
-
13600 if(it->offset > offset)
-
-
13602 ++pMetadata->m_FreeCount;
-
13603 const VkDeviceSize freeSize = it->offset - offset;
-
13604 VmaSuballocation suballoc = {
-
-
-
-
13608 VMA_SUBALLOCATION_TYPE_FREE };
-
13609 VmaSuballocationList::iterator precedingFreeIt = pMetadata->m_Suballocations.insert(it, suballoc);
-
13610 if(freeSize >= VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER)
-
-
13612 pMetadata->m_FreeSuballocationsBySize.push_back(precedingFreeIt);
-
-
-
-
13616 pMetadata->m_SumFreeSize -= it->size;
-
13617 offset = it->offset + it->size;
-
-
-
-
13621 if(offset < blockSize)
-
-
13623 ++pMetadata->m_FreeCount;
-
13624 const VkDeviceSize freeSize = blockSize - offset;
-
13625 VmaSuballocation suballoc = {
-
-
-
-
13629 VMA_SUBALLOCATION_TYPE_FREE };
-
13630 VMA_ASSERT(it == pMetadata->m_Suballocations.end());
-
13631 VmaSuballocationList::iterator trailingFreeIt = pMetadata->m_Suballocations.insert(it, suballoc);
-
13632 if(freeSize > VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER)
-
-
13634 pMetadata->m_FreeSuballocationsBySize.push_back(trailingFreeIt);
-
-
-
-
-
13639 pMetadata->m_FreeSuballocationsBySize.begin(),
-
13640 pMetadata->m_FreeSuballocationsBySize.end(),
-
13641 VmaSuballocationItemSizeLess());
-
+
13426 VmaSuballocation suballoc = *srcSuballocIt;
+
13427 suballoc.offset = dstAllocOffset;
+
13428 suballoc.hAllocation->ChangeBlockAllocation(m_hAllocator, pFreeSpaceBlock, dstAllocOffset);
+
13429 m_BytesMoved += srcAllocSize;
+
13430 ++m_AllocationsMoved;
+
+
13432 VmaSuballocationList::iterator nextSuballocIt = srcSuballocIt;
+
+
13434 pSrcMetadata->m_Suballocations.erase(srcSuballocIt);
+
13435 srcSuballocIt = nextSuballocIt;
+
+
13437 InsertSuballoc(pFreeSpaceMetadata, suballoc);
+
+
13439 VmaDefragmentationMove move = {
+
13440 srcOrigBlockIndex, freeSpaceOrigBlockIndex,
+
13441 srcAllocOffset, dstAllocOffset,
+
+
13443 moves.push_back(move);
+
+
+
+
+
13448 dstAllocOffset = VmaAlignUp(dstOffset, srcAllocAlignment);
+
+
+
13451 while(dstBlockInfoIndex < srcBlockInfoIndex &&
+
13452 dstAllocOffset + srcAllocSize > dstBlockSize)
+
+
+
13455 freeSpaceDb.Register(dstBlockInfoIndex, dstOffset, dstBlockSize - dstOffset);
+
+
13457 ++dstBlockInfoIndex;
+
13458 dstOrigBlockIndex = m_BlockInfos[dstBlockInfoIndex].origBlockIndex;
+
13459 pDstBlock = m_pBlockVector->GetBlock(dstOrigBlockIndex);
+
13460 pDstMetadata = (VmaBlockMetadata_Generic*)pDstBlock->m_pMetadata;
+
13461 dstBlockSize = pDstMetadata->GetSize();
+
+
13463 dstAllocOffset = 0;
+
+
+
+
13467 if(dstBlockInfoIndex == srcBlockInfoIndex)
+
+
13469 VMA_ASSERT(dstAllocOffset <= srcAllocOffset);
+
+
13471 const bool overlap = dstAllocOffset + srcAllocSize > srcAllocOffset;
+
+
13473 bool skipOver = overlap;
+
13474 if(overlap && m_OverlappingMoveSupported && dstAllocOffset < srcAllocOffset)
+
+
+
+
13478 skipOver = (srcAllocOffset - dstAllocOffset) * 64 < srcAllocSize;
+
+
+
+
+
13483 freeSpaceDb.Register(dstBlockInfoIndex, dstOffset, srcAllocOffset - dstOffset);
+
+
13485 dstOffset = srcAllocOffset + srcAllocSize;
+
+
+
+
+
+
13491 srcSuballocIt->offset = dstAllocOffset;
+
13492 srcSuballocIt->hAllocation->ChangeOffset(dstAllocOffset);
+
13493 dstOffset = dstAllocOffset + srcAllocSize;
+
13494 m_BytesMoved += srcAllocSize;
+
13495 ++m_AllocationsMoved;
+
+
13497 VmaDefragmentationMove move = {
+
13498 srcOrigBlockIndex, dstOrigBlockIndex,
+
13499 srcAllocOffset, dstAllocOffset,
+
+
13501 moves.push_back(move);
+
+
+
+
+
+
+
+
13509 VMA_ASSERT(dstBlockInfoIndex < srcBlockInfoIndex);
+
13510 VMA_ASSERT(dstAllocOffset + srcAllocSize <= dstBlockSize);
+
+
13512 VmaSuballocation suballoc = *srcSuballocIt;
+
13513 suballoc.offset = dstAllocOffset;
+
13514 suballoc.hAllocation->ChangeBlockAllocation(m_hAllocator, pDstBlock, dstAllocOffset);
+
13515 dstOffset = dstAllocOffset + srcAllocSize;
+
13516 m_BytesMoved += srcAllocSize;
+
13517 ++m_AllocationsMoved;
+
+
13519 VmaSuballocationList::iterator nextSuballocIt = srcSuballocIt;
+
+
13521 pSrcMetadata->m_Suballocations.erase(srcSuballocIt);
+
13522 srcSuballocIt = nextSuballocIt;
+
+
13524 pDstMetadata->m_Suballocations.push_back(suballoc);
+
+
13526 VmaDefragmentationMove move = {
+
13527 srcOrigBlockIndex, dstOrigBlockIndex,
+
13528 srcAllocOffset, dstAllocOffset,
+
+
13530 moves.push_back(move);
+
+
+
+
+
+
13536 m_BlockInfos.clear();
+
+
13538 PostprocessMetadata();
+
+
+
+
+
13543 void VmaDefragmentationAlgorithm_Fast::PreprocessMetadata()
+
+
13545 const size_t blockCount = m_pBlockVector->GetBlockCount();
+
13546 for(
size_t blockIndex = 0; blockIndex < blockCount; ++blockIndex)
+
+
13548 VmaBlockMetadata_Generic*
const pMetadata =
+
13549 (VmaBlockMetadata_Generic*)m_pBlockVector->GetBlock(blockIndex)->m_pMetadata;
+
13550 pMetadata->m_FreeCount = 0;
+
13551 pMetadata->m_SumFreeSize = pMetadata->GetSize();
+
13552 pMetadata->m_FreeSuballocationsBySize.clear();
+
13553 for(VmaSuballocationList::iterator it = pMetadata->m_Suballocations.begin();
+
13554 it != pMetadata->m_Suballocations.end(); )
+
+
13556 if(it->type == VMA_SUBALLOCATION_TYPE_FREE)
+
+
13558 VmaSuballocationList::iterator nextIt = it;
+
+
13560 pMetadata->m_Suballocations.erase(it);
+
+
+
+
+
+
+
+
+
+
+
13571 void VmaDefragmentationAlgorithm_Fast::PostprocessMetadata()
+
+
13573 const size_t blockCount = m_pBlockVector->GetBlockCount();
+
13574 for(
size_t blockIndex = 0; blockIndex < blockCount; ++blockIndex)
+
+
13576 VmaBlockMetadata_Generic*
const pMetadata =
+
13577 (VmaBlockMetadata_Generic*)m_pBlockVector->GetBlock(blockIndex)->m_pMetadata;
+
13578 const VkDeviceSize blockSize = pMetadata->GetSize();
+
+
+
13581 if(pMetadata->m_Suballocations.empty())
+
+
13583 pMetadata->m_FreeCount = 1;
+
+
13585 VmaSuballocation suballoc = {
+
+
+
+
13589 VMA_SUBALLOCATION_TYPE_FREE };
+
13590 pMetadata->m_Suballocations.push_back(suballoc);
+
13591 pMetadata->RegisterFreeSuballocation(pMetadata->m_Suballocations.begin());
+
+
+
+
+
13596 VkDeviceSize offset = 0;
+
13597 VmaSuballocationList::iterator it;
+
13598 for(it = pMetadata->m_Suballocations.begin();
+
13599 it != pMetadata->m_Suballocations.end();
+
+
+
13602 VMA_ASSERT(it->type != VMA_SUBALLOCATION_TYPE_FREE);
+
13603 VMA_ASSERT(it->offset >= offset);
+
+
+
13606 if(it->offset > offset)
+
+
13608 ++pMetadata->m_FreeCount;
+
13609 const VkDeviceSize freeSize = it->offset - offset;
+
13610 VmaSuballocation suballoc = {
+
+
+
+
13614 VMA_SUBALLOCATION_TYPE_FREE };
+
13615 VmaSuballocationList::iterator precedingFreeIt = pMetadata->m_Suballocations.insert(it, suballoc);
+
13616 if(freeSize >= VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER)
+
+
13618 pMetadata->m_FreeSuballocationsBySize.push_back(precedingFreeIt);
+
+
+
+
13622 pMetadata->m_SumFreeSize -= it->size;
+
13623 offset = it->offset + it->size;
+
+
+
+
13627 if(offset < blockSize)
+
+
13629 ++pMetadata->m_FreeCount;
+
13630 const VkDeviceSize freeSize = blockSize - offset;
+
13631 VmaSuballocation suballoc = {
+
+
+
+
13635 VMA_SUBALLOCATION_TYPE_FREE };
+
13636 VMA_ASSERT(it == pMetadata->m_Suballocations.end());
+
13637 VmaSuballocationList::iterator trailingFreeIt = pMetadata->m_Suballocations.insert(it, suballoc);
+
13638 if(freeSize > VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER)
+
+
13640 pMetadata->m_FreeSuballocationsBySize.push_back(trailingFreeIt);
+
+
-
13644 VMA_HEAVY_ASSERT(pMetadata->Validate());
-
-
-
-
13648 void VmaDefragmentationAlgorithm_Fast::InsertSuballoc(VmaBlockMetadata_Generic* pMetadata,
const VmaSuballocation& suballoc)
-
-
-
13651 VmaSuballocationList::iterator it = pMetadata->m_Suballocations.begin();
-
13652 while(it != pMetadata->m_Suballocations.end())
-
-
13654 if(it->offset < suballoc.offset)
-
-
-
-
-
13659 pMetadata->m_Suballocations.insert(it, suballoc);
-
-
-
-
-
13665 VmaBlockVectorDefragmentationContext::VmaBlockVectorDefragmentationContext(
-
-
-
13668 VmaBlockVector* pBlockVector,
-
13669 uint32_t currFrameIndex) :
-
-
13671 mutexLocked(false),
-
13672 blockContexts(VmaStlAllocator<VmaBlockDefragmentationContext>(hAllocator->GetAllocationCallbacks())),
-
13673 m_hAllocator(hAllocator),
-
13674 m_hCustomPool(hCustomPool),
-
13675 m_pBlockVector(pBlockVector),
-
13676 m_CurrFrameIndex(currFrameIndex),
-
13677 m_pAlgorithm(VMA_NULL),
-
13678 m_Allocations(VmaStlAllocator<AllocInfo>(hAllocator->GetAllocationCallbacks())),
-
13679 m_AllAllocations(false)
-
-
-
-
13683 VmaBlockVectorDefragmentationContext::~VmaBlockVectorDefragmentationContext()
-
-
13685 vma_delete(m_hAllocator, m_pAlgorithm);
-
-
-
13688 void VmaBlockVectorDefragmentationContext::AddAllocation(
VmaAllocation hAlloc, VkBool32* pChanged)
-
-
13690 AllocInfo info = { hAlloc, pChanged };
-
13691 m_Allocations.push_back(info);
+
+
13645 pMetadata->m_FreeSuballocationsBySize.begin(),
+
13646 pMetadata->m_FreeSuballocationsBySize.end(),
+
13647 VmaSuballocationItemSizeLess());
+
+
+
13650 VMA_HEAVY_ASSERT(pMetadata->Validate());
+
+
+
+
13654 void VmaDefragmentationAlgorithm_Fast::InsertSuballoc(VmaBlockMetadata_Generic* pMetadata,
const VmaSuballocation& suballoc)
+
+
+
13657 VmaSuballocationList::iterator it = pMetadata->m_Suballocations.begin();
+
13658 while(it != pMetadata->m_Suballocations.end())
+
+
13660 if(it->offset < suballoc.offset)
+
+
+
+
+
13665 pMetadata->m_Suballocations.insert(it, suballoc);
+
+
+
+
+
13671 VmaBlockVectorDefragmentationContext::VmaBlockVectorDefragmentationContext(
+
+
+
13674 VmaBlockVector* pBlockVector,
+
13675 uint32_t currFrameIndex) :
+
+
13677 mutexLocked(false),
+
13678 blockContexts(VmaStlAllocator<VmaBlockDefragmentationContext>(hAllocator->GetAllocationCallbacks())),
+
13679 m_hAllocator(hAllocator),
+
13680 m_hCustomPool(hCustomPool),
+
13681 m_pBlockVector(pBlockVector),
+
13682 m_CurrFrameIndex(currFrameIndex),
+
13683 m_pAlgorithm(VMA_NULL),
+
13684 m_Allocations(VmaStlAllocator<AllocInfo>(hAllocator->GetAllocationCallbacks())),
+
13685 m_AllAllocations(false)
+
+
+
+
13689 VmaBlockVectorDefragmentationContext::~VmaBlockVectorDefragmentationContext()
+
+
13691 vma_delete(m_hAllocator, m_pAlgorithm);
-
13694 void VmaBlockVectorDefragmentationContext::Begin(
bool overlappingMoveSupported)
+
13694 void VmaBlockVectorDefragmentationContext::AddAllocation(
VmaAllocation hAlloc, VkBool32* pChanged)
-
13696 const bool allAllocations = m_AllAllocations ||
-
13697 m_Allocations.size() == m_pBlockVector->CalcAllocationCount();
-
-
-
-
-
-
-
-
-
-
-
-
13709 if(VMA_DEBUG_MARGIN == 0 &&
-
-
13711 !m_pBlockVector->IsBufferImageGranularityConflictPossible())
-
-
13713 m_pAlgorithm = vma_new(m_hAllocator, VmaDefragmentationAlgorithm_Fast)(
-
13714 m_hAllocator, m_pBlockVector, m_CurrFrameIndex, overlappingMoveSupported);
-
-
-
-
13718 m_pAlgorithm = vma_new(m_hAllocator, VmaDefragmentationAlgorithm_Generic)(
-
13719 m_hAllocator, m_pBlockVector, m_CurrFrameIndex, overlappingMoveSupported);
-
-
-
+
13696 AllocInfo info = { hAlloc, pChanged };
+
13697 m_Allocations.push_back(info);
+
+
+
13700 void VmaBlockVectorDefragmentationContext::Begin(
bool overlappingMoveSupported)
+
+
13702 const bool allAllocations = m_AllAllocations ||
+
13703 m_Allocations.size() == m_pBlockVector->CalcAllocationCount();
+
+
+
+
+
+
+
+
+
+
+
+
13715 if(VMA_DEBUG_MARGIN == 0 &&
+
+
13717 !m_pBlockVector->IsBufferImageGranularityConflictPossible())
+
+
13719 m_pAlgorithm = vma_new(m_hAllocator, VmaDefragmentationAlgorithm_Fast)(
+
13720 m_hAllocator, m_pBlockVector, m_CurrFrameIndex, overlappingMoveSupported);
+
+
-
13724 m_pAlgorithm->AddAll();
-
-
-
-
13728 for(
size_t i = 0, count = m_Allocations.size(); i < count; ++i)
-
-
13730 m_pAlgorithm->AddAllocation(m_Allocations[i].hAlloc, m_Allocations[i].pChanged);
-
-
-
-
-
-
-
13738 VmaDefragmentationContext_T::VmaDefragmentationContext_T(
-
-
13740 uint32_t currFrameIndex,
-
-
-
13743 m_hAllocator(hAllocator),
-
13744 m_CurrFrameIndex(currFrameIndex),
-
-
-
13747 m_CustomPoolContexts(VmaStlAllocator<VmaBlockVectorDefragmentationContext*>(hAllocator->GetAllocationCallbacks()))
-
-
13749 memset(m_DefaultPoolContexts, 0,
sizeof(m_DefaultPoolContexts));
-
-
-
13752 VmaDefragmentationContext_T::~VmaDefragmentationContext_T()
-
-
13754 for(
size_t i = m_CustomPoolContexts.size(); i--; )
-
-
13756 VmaBlockVectorDefragmentationContext* pBlockVectorCtx = m_CustomPoolContexts[i];
-
13757 pBlockVectorCtx->GetBlockVector()->DefragmentationEnd(pBlockVectorCtx, m_pStats);
-
13758 vma_delete(m_hAllocator, pBlockVectorCtx);
-
-
13760 for(
size_t i = m_hAllocator->m_MemProps.memoryTypeCount; i--; )
+
13724 m_pAlgorithm = vma_new(m_hAllocator, VmaDefragmentationAlgorithm_Generic)(
+
13725 m_hAllocator, m_pBlockVector, m_CurrFrameIndex, overlappingMoveSupported);
+
+
+
+
+
13730 m_pAlgorithm->AddAll();
+
+
+
+
13734 for(
size_t i = 0, count = m_Allocations.size(); i < count; ++i)
+
+
13736 m_pAlgorithm->AddAllocation(m_Allocations[i].hAlloc, m_Allocations[i].pChanged);
+
+
+
+
+
+
+
13744 VmaDefragmentationContext_T::VmaDefragmentationContext_T(
+
+
13746 uint32_t currFrameIndex,
+
+
+
13749 m_hAllocator(hAllocator),
+
13750 m_CurrFrameIndex(currFrameIndex),
+
+
+
13753 m_CustomPoolContexts(VmaStlAllocator<VmaBlockVectorDefragmentationContext*>(hAllocator->GetAllocationCallbacks()))
+
+
13755 memset(m_DefaultPoolContexts, 0,
sizeof(m_DefaultPoolContexts));
+
+
+
13758 VmaDefragmentationContext_T::~VmaDefragmentationContext_T()
+
+
13760 for(
size_t i = m_CustomPoolContexts.size(); i--; )
-
13762 VmaBlockVectorDefragmentationContext* pBlockVectorCtx = m_DefaultPoolContexts[i];
-
13763 if(pBlockVectorCtx)
-
-
13765 pBlockVectorCtx->GetBlockVector()->DefragmentationEnd(pBlockVectorCtx, m_pStats);
-
13766 vma_delete(m_hAllocator, pBlockVectorCtx);
-
-
-
-
-
13771 void VmaDefragmentationContext_T::AddPools(uint32_t poolCount,
VmaPool* pPools)
-
-
13773 for(uint32_t poolIndex = 0; poolIndex < poolCount; ++poolIndex)
-
-
13775 VmaPool pool = pPools[poolIndex];
-
-
-
13778 if(pool->m_BlockVector.GetAlgorithm() == 0)
-
-
13780 VmaBlockVectorDefragmentationContext* pBlockVectorDefragCtx = VMA_NULL;
-
-
13782 for(
size_t i = m_CustomPoolContexts.size(); i--; )
-
-
13784 if(m_CustomPoolContexts[i]->GetCustomPool() == pool)
-
-
13786 pBlockVectorDefragCtx = m_CustomPoolContexts[i];
-
-
-
-
-
13791 if(!pBlockVectorDefragCtx)
-
-
13793 pBlockVectorDefragCtx = vma_new(m_hAllocator, VmaBlockVectorDefragmentationContext)(
-
-
-
13796 &pool->m_BlockVector,
-
-
13798 m_CustomPoolContexts.push_back(pBlockVectorDefragCtx);
-
-
-
13801 pBlockVectorDefragCtx->AddAll();
-
-
-
-
-
13806 void VmaDefragmentationContext_T::AddAllocations(
-
13807 uint32_t allocationCount,
-
-
13809 VkBool32* pAllocationsChanged)
-
-
-
13812 for(uint32_t allocIndex = 0; allocIndex < allocationCount; ++allocIndex)
-
-
-
13815 VMA_ASSERT(hAlloc);
-
-
13817 if((hAlloc->GetType() == VmaAllocation_T::ALLOCATION_TYPE_BLOCK) &&
-
-
13819 (hAlloc->GetLastUseFrameIndex() != VMA_FRAME_INDEX_LOST))
-
-
13821 VmaBlockVectorDefragmentationContext* pBlockVectorDefragCtx = VMA_NULL;
-
-
13823 const VmaPool hAllocPool = hAlloc->GetBlock()->GetParentPool();
-
-
13825 if(hAllocPool != VK_NULL_HANDLE)
-
-
-
13828 if(hAllocPool->m_BlockVector.GetAlgorithm() == 0)
-
-
13830 for(
size_t i = m_CustomPoolContexts.size(); i--; )
-
-
13832 if(m_CustomPoolContexts[i]->GetCustomPool() == hAllocPool)
-
-
13834 pBlockVectorDefragCtx = m_CustomPoolContexts[i];
-
-
-
-
13838 if(!pBlockVectorDefragCtx)
-
-
13840 pBlockVectorDefragCtx = vma_new(m_hAllocator, VmaBlockVectorDefragmentationContext)(
-
-
-
13843 &hAllocPool->m_BlockVector,
-
-
13845 m_CustomPoolContexts.push_back(pBlockVectorDefragCtx);
-
-
-
-
-
-
-
13852 const uint32_t memTypeIndex = hAlloc->GetMemoryTypeIndex();
-
13853 pBlockVectorDefragCtx = m_DefaultPoolContexts[memTypeIndex];
-
13854 if(!pBlockVectorDefragCtx)
-
-
13856 pBlockVectorDefragCtx = vma_new(m_hAllocator, VmaBlockVectorDefragmentationContext)(
-
-
-
13859 m_hAllocator->m_pBlockVectors[memTypeIndex],
-
-
13861 m_DefaultPoolContexts[memTypeIndex] = pBlockVectorDefragCtx;
-
-
-
-
13865 if(pBlockVectorDefragCtx)
-
-
13867 VkBool32*
const pChanged = (pAllocationsChanged != VMA_NULL) ?
-
13868 &pAllocationsChanged[allocIndex] : VMA_NULL;
-
13869 pBlockVectorDefragCtx->AddAllocation(hAlloc, pChanged);
-
-
-
-
-
-
13875 VkResult VmaDefragmentationContext_T::Defragment(
-
13876 VkDeviceSize maxCpuBytesToMove, uint32_t maxCpuAllocationsToMove,
-
13877 VkDeviceSize maxGpuBytesToMove, uint32_t maxGpuAllocationsToMove,
-
-
-
-
-
-
-
-
13885 if(commandBuffer == VK_NULL_HANDLE)
-
-
13887 maxGpuBytesToMove = 0;
-
13888 maxGpuAllocationsToMove = 0;
+
13762 VmaBlockVectorDefragmentationContext* pBlockVectorCtx = m_CustomPoolContexts[i];
+
13763 pBlockVectorCtx->GetBlockVector()->DefragmentationEnd(pBlockVectorCtx, m_pStats);
+
13764 vma_delete(m_hAllocator, pBlockVectorCtx);
+
+
13766 for(
size_t i = m_hAllocator->m_MemProps.memoryTypeCount; i--; )
+
+
13768 VmaBlockVectorDefragmentationContext* pBlockVectorCtx = m_DefaultPoolContexts[i];
+
13769 if(pBlockVectorCtx)
+
+
13771 pBlockVectorCtx->GetBlockVector()->DefragmentationEnd(pBlockVectorCtx, m_pStats);
+
13772 vma_delete(m_hAllocator, pBlockVectorCtx);
+
+
+
+
+
13777 void VmaDefragmentationContext_T::AddPools(uint32_t poolCount,
VmaPool* pPools)
+
+
13779 for(uint32_t poolIndex = 0; poolIndex < poolCount; ++poolIndex)
+
+
13781 VmaPool pool = pPools[poolIndex];
+
+
+
13784 if(pool->m_BlockVector.GetAlgorithm() == 0)
+
+
13786 VmaBlockVectorDefragmentationContext* pBlockVectorDefragCtx = VMA_NULL;
+
+
13788 for(
size_t i = m_CustomPoolContexts.size(); i--; )
+
+
13790 if(m_CustomPoolContexts[i]->GetCustomPool() == pool)
+
+
13792 pBlockVectorDefragCtx = m_CustomPoolContexts[i];
+
+
+
+
+
13797 if(!pBlockVectorDefragCtx)
+
+
13799 pBlockVectorDefragCtx = vma_new(m_hAllocator, VmaBlockVectorDefragmentationContext)(
+
+
+
13802 &pool->m_BlockVector,
+
+
13804 m_CustomPoolContexts.push_back(pBlockVectorDefragCtx);
+
+
+
13807 pBlockVectorDefragCtx->AddAll();
+
+
+
+
+
13812 void VmaDefragmentationContext_T::AddAllocations(
+
13813 uint32_t allocationCount,
+
+
13815 VkBool32* pAllocationsChanged)
+
+
+
13818 for(uint32_t allocIndex = 0; allocIndex < allocationCount; ++allocIndex)
+
+
+
13821 VMA_ASSERT(hAlloc);
+
+
13823 if((hAlloc->GetType() == VmaAllocation_T::ALLOCATION_TYPE_BLOCK) &&
+
+
13825 (hAlloc->GetLastUseFrameIndex() != VMA_FRAME_INDEX_LOST))
+
+
13827 VmaBlockVectorDefragmentationContext* pBlockVectorDefragCtx = VMA_NULL;
+
+
13829 const VmaPool hAllocPool = hAlloc->GetBlock()->GetParentPool();
+
+
13831 if(hAllocPool != VK_NULL_HANDLE)
+
+
+
13834 if(hAllocPool->m_BlockVector.GetAlgorithm() == 0)
+
+
13836 for(
size_t i = m_CustomPoolContexts.size(); i--; )
+
+
13838 if(m_CustomPoolContexts[i]->GetCustomPool() == hAllocPool)
+
+
13840 pBlockVectorDefragCtx = m_CustomPoolContexts[i];
+
+
+
+
13844 if(!pBlockVectorDefragCtx)
+
+
13846 pBlockVectorDefragCtx = vma_new(m_hAllocator, VmaBlockVectorDefragmentationContext)(
+
+
+
13849 &hAllocPool->m_BlockVector,
+
+
13851 m_CustomPoolContexts.push_back(pBlockVectorDefragCtx);
+
+
+
+
+
+
+
13858 const uint32_t memTypeIndex = hAlloc->GetMemoryTypeIndex();
+
13859 pBlockVectorDefragCtx = m_DefaultPoolContexts[memTypeIndex];
+
13860 if(!pBlockVectorDefragCtx)
+
+
13862 pBlockVectorDefragCtx = vma_new(m_hAllocator, VmaBlockVectorDefragmentationContext)(
+
+
+
13865 m_hAllocator->m_pBlockVectors[memTypeIndex],
+
+
13867 m_DefaultPoolContexts[memTypeIndex] = pBlockVectorDefragCtx;
+
+
+
+
13871 if(pBlockVectorDefragCtx)
+
+
13873 VkBool32*
const pChanged = (pAllocationsChanged != VMA_NULL) ?
+
13874 &pAllocationsChanged[allocIndex] : VMA_NULL;
+
13875 pBlockVectorDefragCtx->AddAllocation(hAlloc, pChanged);
+
+
+
+
+
+
13881 VkResult VmaDefragmentationContext_T::Defragment(
+
13882 VkDeviceSize maxCpuBytesToMove, uint32_t maxCpuAllocationsToMove,
+
13883 VkDeviceSize maxGpuBytesToMove, uint32_t maxGpuAllocationsToMove,
+
+
+
+
+
-
13891 VkResult res = VK_SUCCESS;
-
-
-
13894 for(uint32_t memTypeIndex = 0;
-
13895 memTypeIndex < m_hAllocator->GetMemoryTypeCount() && res >= VK_SUCCESS;
-
-
-
13898 VmaBlockVectorDefragmentationContext* pBlockVectorCtx = m_DefaultPoolContexts[memTypeIndex];
-
13899 if(pBlockVectorCtx)
-
-
13901 VMA_ASSERT(pBlockVectorCtx->GetBlockVector());
-
13902 pBlockVectorCtx->GetBlockVector()->Defragment(
-
-
-
13905 maxCpuBytesToMove, maxCpuAllocationsToMove,
-
13906 maxGpuBytesToMove, maxGpuAllocationsToMove,
-
-
13908 if(pBlockVectorCtx->res != VK_SUCCESS)
-
-
13910 res = pBlockVectorCtx->res;
-
-
-
-
-
-
13916 for(
size_t customCtxIndex = 0, customCtxCount = m_CustomPoolContexts.size();
-
13917 customCtxIndex < customCtxCount && res >= VK_SUCCESS;
-
-
-
13920 VmaBlockVectorDefragmentationContext* pBlockVectorCtx = m_CustomPoolContexts[customCtxIndex];
-
13921 VMA_ASSERT(pBlockVectorCtx && pBlockVectorCtx->GetBlockVector());
-
13922 pBlockVectorCtx->GetBlockVector()->Defragment(
-
-
-
13925 maxCpuBytesToMove, maxCpuAllocationsToMove,
-
13926 maxGpuBytesToMove, maxGpuAllocationsToMove,
-
-
13928 if(pBlockVectorCtx->res != VK_SUCCESS)
-
-
13930 res = pBlockVectorCtx->res;
-
-
-
-
-
-
-
+
13891 if(commandBuffer == VK_NULL_HANDLE)
+
+
13893 maxGpuBytesToMove = 0;
+
13894 maxGpuAllocationsToMove = 0;
+
+
+
13897 VkResult res = VK_SUCCESS;
+
+
+
13900 for(uint32_t memTypeIndex = 0;
+
13901 memTypeIndex < m_hAllocator->GetMemoryTypeCount() && res >= VK_SUCCESS;
+
+
+
13904 VmaBlockVectorDefragmentationContext* pBlockVectorCtx = m_DefaultPoolContexts[memTypeIndex];
+
13905 if(pBlockVectorCtx)
+
+
13907 VMA_ASSERT(pBlockVectorCtx->GetBlockVector());
+
13908 pBlockVectorCtx->GetBlockVector()->Defragment(
+
+
+
13911 maxCpuBytesToMove, maxCpuAllocationsToMove,
+
13912 maxGpuBytesToMove, maxGpuAllocationsToMove,
+
+
13914 if(pBlockVectorCtx->res != VK_SUCCESS)
+
+
13916 res = pBlockVectorCtx->res;
+
+
+
+
+
+
13922 for(
size_t customCtxIndex = 0, customCtxCount = m_CustomPoolContexts.size();
+
13923 customCtxIndex < customCtxCount && res >= VK_SUCCESS;
+
+
+
13926 VmaBlockVectorDefragmentationContext* pBlockVectorCtx = m_CustomPoolContexts[customCtxIndex];
+
13927 VMA_ASSERT(pBlockVectorCtx && pBlockVectorCtx->GetBlockVector());
+
13928 pBlockVectorCtx->GetBlockVector()->Defragment(
+
+
+
13931 maxCpuBytesToMove, maxCpuAllocationsToMove,
+
13932 maxGpuBytesToMove, maxGpuAllocationsToMove,
+
+
13934 if(pBlockVectorCtx->res != VK_SUCCESS)
+
+
13936 res = pBlockVectorCtx->res;
+
+
-
13940 #if VMA_RECORDING_ENABLED
-
-
13942 VmaRecorder::VmaRecorder() :
-
-
-
-
-
13947 m_StartCounter(INT64_MAX)
-
-
-
-
-
-
13953 m_UseMutex = useMutex;
-
13954 m_Flags = settings.
flags;
-
-
13956 QueryPerformanceFrequency((LARGE_INTEGER*)&m_Freq);
-
13957 QueryPerformanceCounter((LARGE_INTEGER*)&m_StartCounter);
-
-
-
13960 errno_t err = fopen_s(&m_File, settings.
pFilePath,
"wb");
-
-
-
13963 return VK_ERROR_INITIALIZATION_FAILED;
-
-
-
-
13967 fprintf(m_File,
"%s\n",
"Vulkan Memory Allocator,Calls recording");
-
13968 fprintf(m_File,
"%s\n",
"1,8");
-
-
-
-
-
13973 VmaRecorder::~VmaRecorder()
-
-
13975 if(m_File != VMA_NULL)
-
-
-
-
-
-
13981 void VmaRecorder::RecordCreateAllocator(uint32_t frameIndex)
-
-
13983 CallParams callParams;
-
13984 GetBasicParams(callParams);
-
-
13986 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
13987 fprintf(m_File,
"%u,%.3f,%u,vmaCreateAllocator\n", callParams.threadId, callParams.time, frameIndex);
-
-
-
-
13991 void VmaRecorder::RecordDestroyAllocator(uint32_t frameIndex)
-
-
13993 CallParams callParams;
-
13994 GetBasicParams(callParams);
-
-
13996 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
13997 fprintf(m_File,
"%u,%.3f,%u,vmaDestroyAllocator\n", callParams.threadId, callParams.time, frameIndex);
-
-
-
-
-
-
14003 CallParams callParams;
-
14004 GetBasicParams(callParams);
-
-
14006 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14007 fprintf(m_File,
"%u,%.3f,%u,vmaCreatePool,%u,%u,%llu,%llu,%llu,%u,%p\n", callParams.threadId, callParams.time, frameIndex,
-
-
-
-
-
-
-
-
-
-
-
14018 void VmaRecorder::RecordDestroyPool(uint32_t frameIndex,
VmaPool pool)
-
-
14020 CallParams callParams;
-
14021 GetBasicParams(callParams);
-
-
14023 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14024 fprintf(m_File,
"%u,%.3f,%u,vmaDestroyPool,%p\n", callParams.threadId, callParams.time, frameIndex,
-
-
-
+
+
+
+
+
+
13946 #if VMA_RECORDING_ENABLED
+
+
13948 VmaRecorder::VmaRecorder() :
+
+
+
+
+
13953 m_StartCounter(INT64_MAX)
+
+
+
+
+
+
13959 m_UseMutex = useMutex;
+
13960 m_Flags = settings.
flags;
+
+
13962 QueryPerformanceFrequency((LARGE_INTEGER*)&m_Freq);
+
13963 QueryPerformanceCounter((LARGE_INTEGER*)&m_StartCounter);
+
+
+
13966 errno_t err = fopen_s(&m_File, settings.
pFilePath,
"wb");
+
+
+
13969 return VK_ERROR_INITIALIZATION_FAILED;
+
+
+
+
13973 fprintf(m_File,
"%s\n",
"Vulkan Memory Allocator,Calls recording");
+
13974 fprintf(m_File,
"%s\n",
"1,8");
+
+
+
+
+
13979 VmaRecorder::~VmaRecorder()
+
+
13981 if(m_File != VMA_NULL)
+
+
+
+
+
+
13987 void VmaRecorder::RecordCreateAllocator(uint32_t frameIndex)
+
+
13989 CallParams callParams;
+
13990 GetBasicParams(callParams);
+
+
13992 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
13993 fprintf(m_File,
"%u,%.3f,%u,vmaCreateAllocator\n", callParams.threadId, callParams.time, frameIndex);
+
+
+
+
13997 void VmaRecorder::RecordDestroyAllocator(uint32_t frameIndex)
+
+
13999 CallParams callParams;
+
14000 GetBasicParams(callParams);
+
+
14002 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14003 fprintf(m_File,
"%u,%.3f,%u,vmaDestroyAllocator\n", callParams.threadId, callParams.time, frameIndex);
+
+
+
+
+
+
14009 CallParams callParams;
+
14010 GetBasicParams(callParams);
+
+
14012 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14013 fprintf(m_File,
"%u,%.3f,%u,vmaCreatePool,%u,%u,%llu,%llu,%llu,%u,%p\n", callParams.threadId, callParams.time, frameIndex,
+
+
+
+
+
+
+
+
+
+
+
14024 void VmaRecorder::RecordDestroyPool(uint32_t frameIndex,
VmaPool pool)
+
+
14026 CallParams callParams;
+
14027 GetBasicParams(callParams);
-
14029 void VmaRecorder::RecordAllocateMemory(uint32_t frameIndex,
-
14030 const VkMemoryRequirements& vkMemReq,
-
-
-
-
14034 CallParams callParams;
-
14035 GetBasicParams(callParams);
-
-
14037 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14038 UserDataString userDataStr(createInfo.
flags, createInfo.
pUserData);
-
14039 fprintf(m_File,
"%u,%.3f,%u,vmaAllocateMemory,%llu,%llu,%u,%u,%u,%u,%u,%u,%p,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
-
-
14041 vkMemReq.alignment,
-
14042 vkMemReq.memoryTypeBits,
-
-
-
-
-
-
-
-
14050 userDataStr.GetString());
-
-
-
-
14054 void VmaRecorder::RecordAllocateMemoryPages(uint32_t frameIndex,
-
14055 const VkMemoryRequirements& vkMemReq,
-
-
14057 uint64_t allocationCount,
-
-
-
14060 CallParams callParams;
-
14061 GetBasicParams(callParams);
-
-
14063 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14064 UserDataString userDataStr(createInfo.
flags, createInfo.
pUserData);
-
14065 fprintf(m_File,
"%u,%.3f,%u,vmaAllocateMemoryPages,%llu,%llu,%u,%u,%u,%u,%u,%u,%p,", callParams.threadId, callParams.time, frameIndex,
-
-
14067 vkMemReq.alignment,
-
14068 vkMemReq.memoryTypeBits,
-
-
-
-
-
-
-
14075 PrintPointerList(allocationCount, pAllocations);
-
14076 fprintf(m_File,
",%s\n", userDataStr.GetString());
-
-
-
-
14080 void VmaRecorder::RecordAllocateMemoryForBuffer(uint32_t frameIndex,
-
14081 const VkMemoryRequirements& vkMemReq,
-
14082 bool requiresDedicatedAllocation,
-
14083 bool prefersDedicatedAllocation,
-
-
-
-
14087 CallParams callParams;
-
14088 GetBasicParams(callParams);
-
-
14090 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14091 UserDataString userDataStr(createInfo.
flags, createInfo.
pUserData);
-
14092 fprintf(m_File,
"%u,%.3f,%u,vmaAllocateMemoryForBuffer,%llu,%llu,%u,%u,%u,%u,%u,%u,%u,%u,%p,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
-
-
14094 vkMemReq.alignment,
-
14095 vkMemReq.memoryTypeBits,
-
14096 requiresDedicatedAllocation ? 1 : 0,
-
14097 prefersDedicatedAllocation ? 1 : 0,
-
-
-
-
-
-
-
-
14105 userDataStr.GetString());
-
-
-
-
14109 void VmaRecorder::RecordAllocateMemoryForImage(uint32_t frameIndex,
-
14110 const VkMemoryRequirements& vkMemReq,
-
14111 bool requiresDedicatedAllocation,
-
14112 bool prefersDedicatedAllocation,
-
-
-
-
14116 CallParams callParams;
-
14117 GetBasicParams(callParams);
-
-
14119 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14120 UserDataString userDataStr(createInfo.
flags, createInfo.
pUserData);
-
14121 fprintf(m_File,
"%u,%.3f,%u,vmaAllocateMemoryForImage,%llu,%llu,%u,%u,%u,%u,%u,%u,%u,%u,%p,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
-
-
14123 vkMemReq.alignment,
-
14124 vkMemReq.memoryTypeBits,
-
14125 requiresDedicatedAllocation ? 1 : 0,
-
14126 prefersDedicatedAllocation ? 1 : 0,
-
-
-
-
-
-
-
-
14134 userDataStr.GetString());
-
-
-
-
14138 void VmaRecorder::RecordFreeMemory(uint32_t frameIndex,
-
-
-
14141 CallParams callParams;
-
14142 GetBasicParams(callParams);
+
14029 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14030 fprintf(m_File,
"%u,%.3f,%u,vmaDestroyPool,%p\n", callParams.threadId, callParams.time, frameIndex,
+
+
+
+
+
14035 void VmaRecorder::RecordAllocateMemory(uint32_t frameIndex,
+
14036 const VkMemoryRequirements& vkMemReq,
+
+
+
+
14040 CallParams callParams;
+
14041 GetBasicParams(callParams);
+
+
14043 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14044 UserDataString userDataStr(createInfo.
flags, createInfo.
pUserData);
+
14045 fprintf(m_File,
"%u,%.3f,%u,vmaAllocateMemory,%llu,%llu,%u,%u,%u,%u,%u,%u,%p,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
+
+
14047 vkMemReq.alignment,
+
14048 vkMemReq.memoryTypeBits,
+
+
+
+
+
+
+
+
14056 userDataStr.GetString());
+
+
+
+
14060 void VmaRecorder::RecordAllocateMemoryPages(uint32_t frameIndex,
+
14061 const VkMemoryRequirements& vkMemReq,
+
+
14063 uint64_t allocationCount,
+
+
+
14066 CallParams callParams;
+
14067 GetBasicParams(callParams);
+
+
14069 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14070 UserDataString userDataStr(createInfo.
flags, createInfo.
pUserData);
+
14071 fprintf(m_File,
"%u,%.3f,%u,vmaAllocateMemoryPages,%llu,%llu,%u,%u,%u,%u,%u,%u,%p,", callParams.threadId, callParams.time, frameIndex,
+
+
14073 vkMemReq.alignment,
+
14074 vkMemReq.memoryTypeBits,
+
+
+
+
+
+
+
14081 PrintPointerList(allocationCount, pAllocations);
+
14082 fprintf(m_File,
",%s\n", userDataStr.GetString());
+
+
+
+
14086 void VmaRecorder::RecordAllocateMemoryForBuffer(uint32_t frameIndex,
+
14087 const VkMemoryRequirements& vkMemReq,
+
14088 bool requiresDedicatedAllocation,
+
14089 bool prefersDedicatedAllocation,
+
+
+
+
14093 CallParams callParams;
+
14094 GetBasicParams(callParams);
+
+
14096 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14097 UserDataString userDataStr(createInfo.
flags, createInfo.
pUserData);
+
14098 fprintf(m_File,
"%u,%.3f,%u,vmaAllocateMemoryForBuffer,%llu,%llu,%u,%u,%u,%u,%u,%u,%u,%u,%p,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
+
+
14100 vkMemReq.alignment,
+
14101 vkMemReq.memoryTypeBits,
+
14102 requiresDedicatedAllocation ? 1 : 0,
+
14103 prefersDedicatedAllocation ? 1 : 0,
+
+
+
+
+
+
+
+
14111 userDataStr.GetString());
+
+
+
+
14115 void VmaRecorder::RecordAllocateMemoryForImage(uint32_t frameIndex,
+
14116 const VkMemoryRequirements& vkMemReq,
+
14117 bool requiresDedicatedAllocation,
+
14118 bool prefersDedicatedAllocation,
+
+
+
+
14122 CallParams callParams;
+
14123 GetBasicParams(callParams);
+
+
14125 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14126 UserDataString userDataStr(createInfo.
flags, createInfo.
pUserData);
+
14127 fprintf(m_File,
"%u,%.3f,%u,vmaAllocateMemoryForImage,%llu,%llu,%u,%u,%u,%u,%u,%u,%u,%u,%p,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
+
+
14129 vkMemReq.alignment,
+
14130 vkMemReq.memoryTypeBits,
+
14131 requiresDedicatedAllocation ? 1 : 0,
+
14132 prefersDedicatedAllocation ? 1 : 0,
+
+
+
+
+
+
+
+
14140 userDataStr.GetString());
+
+
-
14144 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14145 fprintf(m_File,
"%u,%.3f,%u,vmaFreeMemory,%p\n", callParams.threadId, callParams.time, frameIndex,
-
-
-
+
14144 void VmaRecorder::RecordFreeMemory(uint32_t frameIndex,
+
+
+
14147 CallParams callParams;
+
14148 GetBasicParams(callParams);
-
14150 void VmaRecorder::RecordFreeMemoryPages(uint32_t frameIndex,
-
14151 uint64_t allocationCount,
-
-
-
14154 CallParams callParams;
-
14155 GetBasicParams(callParams);
-
-
14157 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14158 fprintf(m_File,
"%u,%.3f,%u,vmaFreeMemoryPages,", callParams.threadId, callParams.time, frameIndex);
-
14159 PrintPointerList(allocationCount, pAllocations);
-
14160 fprintf(m_File,
"\n");
-
-
-
-
14164 void VmaRecorder::RecordSetAllocationUserData(uint32_t frameIndex,
-
-
14166 const void* pUserData)
-
-
14168 CallParams callParams;
-
14169 GetBasicParams(callParams);
-
-
14171 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14172 UserDataString userDataStr(
-
-
-
14175 fprintf(m_File,
"%u,%.3f,%u,vmaSetAllocationUserData,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
-
-
14177 userDataStr.GetString());
-
-
-
-
14181 void VmaRecorder::RecordCreateLostAllocation(uint32_t frameIndex,
-
-
-
14184 CallParams callParams;
-
14185 GetBasicParams(callParams);
+
14150 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14151 fprintf(m_File,
"%u,%.3f,%u,vmaFreeMemory,%p\n", callParams.threadId, callParams.time, frameIndex,
+
+
+
+
+
14156 void VmaRecorder::RecordFreeMemoryPages(uint32_t frameIndex,
+
14157 uint64_t allocationCount,
+
+
+
14160 CallParams callParams;
+
14161 GetBasicParams(callParams);
+
+
14163 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14164 fprintf(m_File,
"%u,%.3f,%u,vmaFreeMemoryPages,", callParams.threadId, callParams.time, frameIndex);
+
14165 PrintPointerList(allocationCount, pAllocations);
+
14166 fprintf(m_File,
"\n");
+
+
+
+
14170 void VmaRecorder::RecordSetAllocationUserData(uint32_t frameIndex,
+
+
14172 const void* pUserData)
+
+
14174 CallParams callParams;
+
14175 GetBasicParams(callParams);
+
+
14177 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14178 UserDataString userDataStr(
+
+
+
14181 fprintf(m_File,
"%u,%.3f,%u,vmaSetAllocationUserData,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
+
+
14183 userDataStr.GetString());
+
+
-
14187 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14188 fprintf(m_File,
"%u,%.3f,%u,vmaCreateLostAllocation,%p\n", callParams.threadId, callParams.time, frameIndex,
-
-
-
+
14187 void VmaRecorder::RecordCreateLostAllocation(uint32_t frameIndex,
+
+
+
14190 CallParams callParams;
+
14191 GetBasicParams(callParams);
-
14193 void VmaRecorder::RecordMapMemory(uint32_t frameIndex,
-
-
-
14196 CallParams callParams;
-
14197 GetBasicParams(callParams);
+
14193 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14194 fprintf(m_File,
"%u,%.3f,%u,vmaCreateLostAllocation,%p\n", callParams.threadId, callParams.time, frameIndex,
+
+
+
-
14199 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14200 fprintf(m_File,
"%u,%.3f,%u,vmaMapMemory,%p\n", callParams.threadId, callParams.time, frameIndex,
-
-
-
+
14199 void VmaRecorder::RecordMapMemory(uint32_t frameIndex,
+
+
+
14202 CallParams callParams;
+
14203 GetBasicParams(callParams);
-
14205 void VmaRecorder::RecordUnmapMemory(uint32_t frameIndex,
-
-
-
14208 CallParams callParams;
-
14209 GetBasicParams(callParams);
+
14205 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14206 fprintf(m_File,
"%u,%.3f,%u,vmaMapMemory,%p\n", callParams.threadId, callParams.time, frameIndex,
+
+
+
-
14211 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14212 fprintf(m_File,
"%u,%.3f,%u,vmaUnmapMemory,%p\n", callParams.threadId, callParams.time, frameIndex,
-
-
-
+
14211 void VmaRecorder::RecordUnmapMemory(uint32_t frameIndex,
+
+
+
14214 CallParams callParams;
+
14215 GetBasicParams(callParams);
-
14217 void VmaRecorder::RecordFlushAllocation(uint32_t frameIndex,
-
14218 VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size)
-
-
14220 CallParams callParams;
-
14221 GetBasicParams(callParams);
+
14217 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14218 fprintf(m_File,
"%u,%.3f,%u,vmaUnmapMemory,%p\n", callParams.threadId, callParams.time, frameIndex,
+
+
+
-
14223 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14224 fprintf(m_File,
"%u,%.3f,%u,vmaFlushAllocation,%p,%llu,%llu\n", callParams.threadId, callParams.time, frameIndex,
-
-
-
-
-
-
-
14231 void VmaRecorder::RecordInvalidateAllocation(uint32_t frameIndex,
-
14232 VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size)
-
-
14234 CallParams callParams;
-
14235 GetBasicParams(callParams);
+
14223 void VmaRecorder::RecordFlushAllocation(uint32_t frameIndex,
+
14224 VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size)
+
+
14226 CallParams callParams;
+
14227 GetBasicParams(callParams);
+
+
14229 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14230 fprintf(m_File,
"%u,%.3f,%u,vmaFlushAllocation,%p,%llu,%llu\n", callParams.threadId, callParams.time, frameIndex,
+
+
+
+
+
-
14237 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14238 fprintf(m_File,
"%u,%.3f,%u,vmaInvalidateAllocation,%p,%llu,%llu\n", callParams.threadId, callParams.time, frameIndex,
-
-
-
-
-
-
-
14245 void VmaRecorder::RecordCreateBuffer(uint32_t frameIndex,
-
14246 const VkBufferCreateInfo& bufCreateInfo,
-
-
-
-
14250 CallParams callParams;
-
14251 GetBasicParams(callParams);
-
-
14253 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14254 UserDataString userDataStr(allocCreateInfo.
flags, allocCreateInfo.
pUserData);
-
14255 fprintf(m_File,
"%u,%.3f,%u,vmaCreateBuffer,%u,%llu,%u,%u,%u,%u,%u,%u,%u,%p,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
-
14256 bufCreateInfo.flags,
-
14257 bufCreateInfo.size,
-
14258 bufCreateInfo.usage,
-
14259 bufCreateInfo.sharingMode,
-
14260 allocCreateInfo.
flags,
-
14261 allocCreateInfo.
usage,
-
-
-
-
14265 allocCreateInfo.
pool,
-
-
14267 userDataStr.GetString());
-
-
-
-
14271 void VmaRecorder::RecordCreateImage(uint32_t frameIndex,
-
14272 const VkImageCreateInfo& imageCreateInfo,
-
-
-
-
14276 CallParams callParams;
-
14277 GetBasicParams(callParams);
-
-
14279 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14280 UserDataString userDataStr(allocCreateInfo.
flags, allocCreateInfo.
pUserData);
-
14281 fprintf(m_File,
"%u,%.3f,%u,vmaCreateImage,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%p,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
-
14282 imageCreateInfo.flags,
-
14283 imageCreateInfo.imageType,
-
14284 imageCreateInfo.format,
-
14285 imageCreateInfo.extent.width,
-
14286 imageCreateInfo.extent.height,
-
14287 imageCreateInfo.extent.depth,
-
14288 imageCreateInfo.mipLevels,
-
14289 imageCreateInfo.arrayLayers,
-
14290 imageCreateInfo.samples,
-
14291 imageCreateInfo.tiling,
-
14292 imageCreateInfo.usage,
-
14293 imageCreateInfo.sharingMode,
-
14294 imageCreateInfo.initialLayout,
-
14295 allocCreateInfo.
flags,
-
14296 allocCreateInfo.
usage,
-
-
-
-
14300 allocCreateInfo.
pool,
-
-
14302 userDataStr.GetString());
-
-
-
-
14306 void VmaRecorder::RecordDestroyBuffer(uint32_t frameIndex,
-
-
-
14309 CallParams callParams;
-
14310 GetBasicParams(callParams);
+
14237 void VmaRecorder::RecordInvalidateAllocation(uint32_t frameIndex,
+
14238 VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size)
+
+
14240 CallParams callParams;
+
14241 GetBasicParams(callParams);
+
+
14243 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14244 fprintf(m_File,
"%u,%.3f,%u,vmaInvalidateAllocation,%p,%llu,%llu\n", callParams.threadId, callParams.time, frameIndex,
+
+
+
+
+
+
+
14251 void VmaRecorder::RecordCreateBuffer(uint32_t frameIndex,
+
14252 const VkBufferCreateInfo& bufCreateInfo,
+
+
+
+
14256 CallParams callParams;
+
14257 GetBasicParams(callParams);
+
+
14259 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14260 UserDataString userDataStr(allocCreateInfo.
flags, allocCreateInfo.
pUserData);
+
14261 fprintf(m_File,
"%u,%.3f,%u,vmaCreateBuffer,%u,%llu,%u,%u,%u,%u,%u,%u,%u,%p,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
+
14262 bufCreateInfo.flags,
+
14263 bufCreateInfo.size,
+
14264 bufCreateInfo.usage,
+
14265 bufCreateInfo.sharingMode,
+
14266 allocCreateInfo.
flags,
+
14267 allocCreateInfo.
usage,
+
+
+
+
14271 allocCreateInfo.
pool,
+
+
14273 userDataStr.GetString());
+
+
+
+
14277 void VmaRecorder::RecordCreateImage(uint32_t frameIndex,
+
14278 const VkImageCreateInfo& imageCreateInfo,
+
+
+
+
14282 CallParams callParams;
+
14283 GetBasicParams(callParams);
+
+
14285 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14286 UserDataString userDataStr(allocCreateInfo.
flags, allocCreateInfo.
pUserData);
+
14287 fprintf(m_File,
"%u,%.3f,%u,vmaCreateImage,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%p,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
+
14288 imageCreateInfo.flags,
+
14289 imageCreateInfo.imageType,
+
14290 imageCreateInfo.format,
+
14291 imageCreateInfo.extent.width,
+
14292 imageCreateInfo.extent.height,
+
14293 imageCreateInfo.extent.depth,
+
14294 imageCreateInfo.mipLevels,
+
14295 imageCreateInfo.arrayLayers,
+
14296 imageCreateInfo.samples,
+
14297 imageCreateInfo.tiling,
+
14298 imageCreateInfo.usage,
+
14299 imageCreateInfo.sharingMode,
+
14300 imageCreateInfo.initialLayout,
+
14301 allocCreateInfo.
flags,
+
14302 allocCreateInfo.
usage,
+
+
+
+
14306 allocCreateInfo.
pool,
+
+
14308 userDataStr.GetString());
+
+
-
14312 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14313 fprintf(m_File,
"%u,%.3f,%u,vmaDestroyBuffer,%p\n", callParams.threadId, callParams.time, frameIndex,
-
-
-
+
14312 void VmaRecorder::RecordDestroyBuffer(uint32_t frameIndex,
+
+
+
14315 CallParams callParams;
+
14316 GetBasicParams(callParams);
-
14318 void VmaRecorder::RecordDestroyImage(uint32_t frameIndex,
-
-
-
14321 CallParams callParams;
-
14322 GetBasicParams(callParams);
+
14318 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14319 fprintf(m_File,
"%u,%.3f,%u,vmaDestroyBuffer,%p\n", callParams.threadId, callParams.time, frameIndex,
+
+
+
-
14324 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14325 fprintf(m_File,
"%u,%.3f,%u,vmaDestroyImage,%p\n", callParams.threadId, callParams.time, frameIndex,
-
-
-
+
14324 void VmaRecorder::RecordDestroyImage(uint32_t frameIndex,
+
+
+
14327 CallParams callParams;
+
14328 GetBasicParams(callParams);
-
14330 void VmaRecorder::RecordTouchAllocation(uint32_t frameIndex,
-
-
-
14333 CallParams callParams;
-
14334 GetBasicParams(callParams);
+
14330 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14331 fprintf(m_File,
"%u,%.3f,%u,vmaDestroyImage,%p\n", callParams.threadId, callParams.time, frameIndex,
+
+
+
-
14336 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14337 fprintf(m_File,
"%u,%.3f,%u,vmaTouchAllocation,%p\n", callParams.threadId, callParams.time, frameIndex,
-
-
-
+
14336 void VmaRecorder::RecordTouchAllocation(uint32_t frameIndex,
+
+
+
14339 CallParams callParams;
+
14340 GetBasicParams(callParams);
-
14342 void VmaRecorder::RecordGetAllocationInfo(uint32_t frameIndex,
-
-
-
14345 CallParams callParams;
-
14346 GetBasicParams(callParams);
+
14342 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14343 fprintf(m_File,
"%u,%.3f,%u,vmaTouchAllocation,%p\n", callParams.threadId, callParams.time, frameIndex,
+
+
+
-
14348 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14349 fprintf(m_File,
"%u,%.3f,%u,vmaGetAllocationInfo,%p\n", callParams.threadId, callParams.time, frameIndex,
-
-
-
+
14348 void VmaRecorder::RecordGetAllocationInfo(uint32_t frameIndex,
+
+
+
14351 CallParams callParams;
+
14352 GetBasicParams(callParams);
-
14354 void VmaRecorder::RecordMakePoolAllocationsLost(uint32_t frameIndex,
-
-
-
14357 CallParams callParams;
-
14358 GetBasicParams(callParams);
+
14354 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14355 fprintf(m_File,
"%u,%.3f,%u,vmaGetAllocationInfo,%p\n", callParams.threadId, callParams.time, frameIndex,
+
+
+
-
14360 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14361 fprintf(m_File,
"%u,%.3f,%u,vmaMakePoolAllocationsLost,%p\n", callParams.threadId, callParams.time, frameIndex,
-
-
-
+
14360 void VmaRecorder::RecordMakePoolAllocationsLost(uint32_t frameIndex,
+
+
+
14363 CallParams callParams;
+
14364 GetBasicParams(callParams);
-
14366 void VmaRecorder::RecordDefragmentationBegin(uint32_t frameIndex,
-
-
-
-
14370 CallParams callParams;
-
14371 GetBasicParams(callParams);
-
-
14373 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14374 fprintf(m_File,
"%u,%.3f,%u,vmaDefragmentationBegin,%u,", callParams.threadId, callParams.time, frameIndex,
-
-
-
14377 fprintf(m_File,
",");
-
-
14379 fprintf(m_File,
",%llu,%u,%llu,%u,%p,%p\n",
-
-
-
-
-
-
-
-
-
-
14389 void VmaRecorder::RecordDefragmentationEnd(uint32_t frameIndex,
-
-
-
14392 CallParams callParams;
-
14393 GetBasicParams(callParams);
+
14366 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14367 fprintf(m_File,
"%u,%.3f,%u,vmaMakePoolAllocationsLost,%p\n", callParams.threadId, callParams.time, frameIndex,
+
+
+
+
+
14372 void VmaRecorder::RecordDefragmentationBegin(uint32_t frameIndex,
+
+
+
+
14376 CallParams callParams;
+
14377 GetBasicParams(callParams);
+
+
14379 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14380 fprintf(m_File,
"%u,%.3f,%u,vmaDefragmentationBegin,%u,", callParams.threadId, callParams.time, frameIndex,
+
+
+
14383 fprintf(m_File,
",");
+
+
14385 fprintf(m_File,
",%llu,%u,%llu,%u,%p,%p\n",
+
+
+
+
+
+
+
+
-
14395 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14396 fprintf(m_File,
"%u,%.3f,%u,vmaDefragmentationEnd,%p\n", callParams.threadId, callParams.time, frameIndex,
-
-
-
+
14395 void VmaRecorder::RecordDefragmentationEnd(uint32_t frameIndex,
+
+
+
14398 CallParams callParams;
+
14399 GetBasicParams(callParams);
-
14401 void VmaRecorder::RecordSetPoolName(uint32_t frameIndex,
-
-
-
-
14405 CallParams callParams;
-
14406 GetBasicParams(callParams);
-
-
14408 VmaMutexLock lock(m_FileMutex, m_UseMutex);
-
14409 fprintf(m_File,
"%u,%.3f,%u,vmaSetPoolName,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
-
14410 pool, name != VMA_NULL ? name :
"");
-
-
+
14401 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14402 fprintf(m_File,
"%u,%.3f,%u,vmaDefragmentationEnd,%p\n", callParams.threadId, callParams.time, frameIndex,
+
+
+
+
+
14407 void VmaRecorder::RecordSetPoolName(uint32_t frameIndex,
+
+
+
+
14411 CallParams callParams;
+
14412 GetBasicParams(callParams);
-
-
-
14416 if(pUserData != VMA_NULL)
-
-
-
-
14420 m_Str = (
const char*)pUserData;
-
-
-
-
14424 sprintf_s(m_PtrStr,
"%p", pUserData);
-
-
-
-
-
-
-
-
-
-
14434 void VmaRecorder::WriteConfiguration(
-
14435 const VkPhysicalDeviceProperties& devProps,
-
14436 const VkPhysicalDeviceMemoryProperties& memProps,
-
14437 uint32_t vulkanApiVersion,
-
14438 bool dedicatedAllocationExtensionEnabled,
-
14439 bool bindMemory2ExtensionEnabled,
-
14440 bool memoryBudgetExtensionEnabled)
-
-
14442 fprintf(m_File,
"Config,Begin\n");
-
-
14444 fprintf(m_File,
"VulkanApiVersion,%u,%u\n", VK_VERSION_MAJOR(vulkanApiVersion), VK_VERSION_MINOR(vulkanApiVersion));
-
-
14446 fprintf(m_File,
"PhysicalDevice,apiVersion,%u\n", devProps.apiVersion);
-
14447 fprintf(m_File,
"PhysicalDevice,driverVersion,%u\n", devProps.driverVersion);
-
14448 fprintf(m_File,
"PhysicalDevice,vendorID,%u\n", devProps.vendorID);
-
14449 fprintf(m_File,
"PhysicalDevice,deviceID,%u\n", devProps.deviceID);
-
14450 fprintf(m_File,
"PhysicalDevice,deviceType,%u\n", devProps.deviceType);
-
14451 fprintf(m_File,
"PhysicalDevice,deviceName,%s\n", devProps.deviceName);
-
-
14453 fprintf(m_File,
"PhysicalDeviceLimits,maxMemoryAllocationCount,%u\n", devProps.limits.maxMemoryAllocationCount);
-
14454 fprintf(m_File,
"PhysicalDeviceLimits,bufferImageGranularity,%llu\n", devProps.limits.bufferImageGranularity);
-
14455 fprintf(m_File,
"PhysicalDeviceLimits,nonCoherentAtomSize,%llu\n", devProps.limits.nonCoherentAtomSize);
-
-
14457 fprintf(m_File,
"PhysicalDeviceMemory,HeapCount,%u\n", memProps.memoryHeapCount);
-
14458 for(uint32_t i = 0; i < memProps.memoryHeapCount; ++i)
-
-
14460 fprintf(m_File,
"PhysicalDeviceMemory,Heap,%u,size,%llu\n", i, memProps.memoryHeaps[i].size);
-
14461 fprintf(m_File,
"PhysicalDeviceMemory,Heap,%u,flags,%u\n", i, memProps.memoryHeaps[i].flags);
-
-
14463 fprintf(m_File,
"PhysicalDeviceMemory,TypeCount,%u\n", memProps.memoryTypeCount);
-
14464 for(uint32_t i = 0; i < memProps.memoryTypeCount; ++i)
+
14414 VmaMutexLock lock(m_FileMutex, m_UseMutex);
+
14415 fprintf(m_File,
"%u,%.3f,%u,vmaSetPoolName,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
+
14416 pool, name != VMA_NULL ? name :
"");
+
+
+
+
+
+
14422 if(pUserData != VMA_NULL)
+
+
+
+
14426 m_Str = (
const char*)pUserData;
+
+
+
+
14430 sprintf_s(m_PtrStr,
"%p", pUserData);
+
+
+
+
+
+
+
+
+
+
14440 void VmaRecorder::WriteConfiguration(
+
14441 const VkPhysicalDeviceProperties& devProps,
+
14442 const VkPhysicalDeviceMemoryProperties& memProps,
+
14443 uint32_t vulkanApiVersion,
+
14444 bool dedicatedAllocationExtensionEnabled,
+
14445 bool bindMemory2ExtensionEnabled,
+
14446 bool memoryBudgetExtensionEnabled)
+
+
14448 fprintf(m_File,
"Config,Begin\n");
+
+
14450 fprintf(m_File,
"VulkanApiVersion,%u,%u\n", VK_VERSION_MAJOR(vulkanApiVersion), VK_VERSION_MINOR(vulkanApiVersion));
+
+
14452 fprintf(m_File,
"PhysicalDevice,apiVersion,%u\n", devProps.apiVersion);
+
14453 fprintf(m_File,
"PhysicalDevice,driverVersion,%u\n", devProps.driverVersion);
+
14454 fprintf(m_File,
"PhysicalDevice,vendorID,%u\n", devProps.vendorID);
+
14455 fprintf(m_File,
"PhysicalDevice,deviceID,%u\n", devProps.deviceID);
+
14456 fprintf(m_File,
"PhysicalDevice,deviceType,%u\n", devProps.deviceType);
+
14457 fprintf(m_File,
"PhysicalDevice,deviceName,%s\n", devProps.deviceName);
+
+
14459 fprintf(m_File,
"PhysicalDeviceLimits,maxMemoryAllocationCount,%u\n", devProps.limits.maxMemoryAllocationCount);
+
14460 fprintf(m_File,
"PhysicalDeviceLimits,bufferImageGranularity,%llu\n", devProps.limits.bufferImageGranularity);
+
14461 fprintf(m_File,
"PhysicalDeviceLimits,nonCoherentAtomSize,%llu\n", devProps.limits.nonCoherentAtomSize);
+
+
14463 fprintf(m_File,
"PhysicalDeviceMemory,HeapCount,%u\n", memProps.memoryHeapCount);
+
14464 for(uint32_t i = 0; i < memProps.memoryHeapCount; ++i)
-
14466 fprintf(m_File,
"PhysicalDeviceMemory,Type,%u,heapIndex,%u\n", i, memProps.memoryTypes[i].heapIndex);
-
14467 fprintf(m_File,
"PhysicalDeviceMemory,Type,%u,propertyFlags,%u\n", i, memProps.memoryTypes[i].propertyFlags);
+
14466 fprintf(m_File,
"PhysicalDeviceMemory,Heap,%u,size,%llu\n", i, memProps.memoryHeaps[i].size);
+
14467 fprintf(m_File,
"PhysicalDeviceMemory,Heap,%u,flags,%u\n", i, memProps.memoryHeaps[i].flags);
-
-
14470 fprintf(m_File,
"Extension,VK_KHR_dedicated_allocation,%u\n", dedicatedAllocationExtensionEnabled ? 1 : 0);
-
14471 fprintf(m_File,
"Extension,VK_KHR_bind_memory2,%u\n", bindMemory2ExtensionEnabled ? 1 : 0);
-
14472 fprintf(m_File,
"Extension,VK_EXT_memory_budget,%u\n", memoryBudgetExtensionEnabled ? 1 : 0);
-
-
14474 fprintf(m_File,
"Macro,VMA_DEBUG_ALWAYS_DEDICATED_MEMORY,%u\n", VMA_DEBUG_ALWAYS_DEDICATED_MEMORY ? 1 : 0);
-
14475 fprintf(m_File,
"Macro,VMA_DEBUG_ALIGNMENT,%llu\n", (VkDeviceSize)VMA_DEBUG_ALIGNMENT);
-
14476 fprintf(m_File,
"Macro,VMA_DEBUG_MARGIN,%llu\n", (VkDeviceSize)VMA_DEBUG_MARGIN);
-
14477 fprintf(m_File,
"Macro,VMA_DEBUG_INITIALIZE_ALLOCATIONS,%u\n", VMA_DEBUG_INITIALIZE_ALLOCATIONS ? 1 : 0);
-
14478 fprintf(m_File,
"Macro,VMA_DEBUG_DETECT_CORRUPTION,%u\n", VMA_DEBUG_DETECT_CORRUPTION ? 1 : 0);
-
14479 fprintf(m_File,
"Macro,VMA_DEBUG_GLOBAL_MUTEX,%u\n", VMA_DEBUG_GLOBAL_MUTEX ? 1 : 0);
-
14480 fprintf(m_File,
"Macro,VMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY,%llu\n", (VkDeviceSize)VMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY);
-
14481 fprintf(m_File,
"Macro,VMA_SMALL_HEAP_MAX_SIZE,%llu\n", (VkDeviceSize)VMA_SMALL_HEAP_MAX_SIZE);
-
14482 fprintf(m_File,
"Macro,VMA_DEFAULT_LARGE_HEAP_BLOCK_SIZE,%llu\n", (VkDeviceSize)VMA_DEFAULT_LARGE_HEAP_BLOCK_SIZE);
-
-
14484 fprintf(m_File,
"Config,End\n");
-
-
-
14487 void VmaRecorder::GetBasicParams(CallParams& outParams)
-
-
14489 outParams.threadId = GetCurrentThreadId();
-
-
14491 LARGE_INTEGER counter;
-
14492 QueryPerformanceCounter(&counter);
-
14493 outParams.time = (double)(counter.QuadPart - m_StartCounter) / (double)m_Freq;
-
-
-
14496 void VmaRecorder::PrintPointerList(uint64_t count,
const VmaAllocation* pItems)
-
-
-
-
14500 fprintf(m_File,
"%p", pItems[0]);
-
14501 for(uint64_t i = 1; i < count; ++i)
-
-
14503 fprintf(m_File,
" %p", pItems[i]);
-
-
-
-
-
14508 void VmaRecorder::Flush()
-
-
-
-
-
-
-
-
14516 #endif // #if VMA_RECORDING_ENABLED
-
-
-
-
14521 VmaAllocationObjectAllocator::VmaAllocationObjectAllocator(
const VkAllocationCallbacks* pAllocationCallbacks) :
-
14522 m_Allocator(pAllocationCallbacks, 1024)
-
-
-
-
-
-
14528 VmaMutexLock mutexLock(m_Mutex);
-
14529 return m_Allocator.Alloc();
+
14469 fprintf(m_File,
"PhysicalDeviceMemory,TypeCount,%u\n", memProps.memoryTypeCount);
+
14470 for(uint32_t i = 0; i < memProps.memoryTypeCount; ++i)
+
+
14472 fprintf(m_File,
"PhysicalDeviceMemory,Type,%u,heapIndex,%u\n", i, memProps.memoryTypes[i].heapIndex);
+
14473 fprintf(m_File,
"PhysicalDeviceMemory,Type,%u,propertyFlags,%u\n", i, memProps.memoryTypes[i].propertyFlags);
+
+
+
14476 fprintf(m_File,
"Extension,VK_KHR_dedicated_allocation,%u\n", dedicatedAllocationExtensionEnabled ? 1 : 0);
+
14477 fprintf(m_File,
"Extension,VK_KHR_bind_memory2,%u\n", bindMemory2ExtensionEnabled ? 1 : 0);
+
14478 fprintf(m_File,
"Extension,VK_EXT_memory_budget,%u\n", memoryBudgetExtensionEnabled ? 1 : 0);
+
+
14480 fprintf(m_File,
"Macro,VMA_DEBUG_ALWAYS_DEDICATED_MEMORY,%u\n", VMA_DEBUG_ALWAYS_DEDICATED_MEMORY ? 1 : 0);
+
14481 fprintf(m_File,
"Macro,VMA_DEBUG_ALIGNMENT,%llu\n", (VkDeviceSize)VMA_DEBUG_ALIGNMENT);
+
14482 fprintf(m_File,
"Macro,VMA_DEBUG_MARGIN,%llu\n", (VkDeviceSize)VMA_DEBUG_MARGIN);
+
14483 fprintf(m_File,
"Macro,VMA_DEBUG_INITIALIZE_ALLOCATIONS,%u\n", VMA_DEBUG_INITIALIZE_ALLOCATIONS ? 1 : 0);
+
14484 fprintf(m_File,
"Macro,VMA_DEBUG_DETECT_CORRUPTION,%u\n", VMA_DEBUG_DETECT_CORRUPTION ? 1 : 0);
+
14485 fprintf(m_File,
"Macro,VMA_DEBUG_GLOBAL_MUTEX,%u\n", VMA_DEBUG_GLOBAL_MUTEX ? 1 : 0);
+
14486 fprintf(m_File,
"Macro,VMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY,%llu\n", (VkDeviceSize)VMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY);
+
14487 fprintf(m_File,
"Macro,VMA_SMALL_HEAP_MAX_SIZE,%llu\n", (VkDeviceSize)VMA_SMALL_HEAP_MAX_SIZE);
+
14488 fprintf(m_File,
"Macro,VMA_DEFAULT_LARGE_HEAP_BLOCK_SIZE,%llu\n", (VkDeviceSize)VMA_DEFAULT_LARGE_HEAP_BLOCK_SIZE);
+
+
14490 fprintf(m_File,
"Config,End\n");
+
+
+
14493 void VmaRecorder::GetBasicParams(CallParams& outParams)
+
+
14495 outParams.threadId = GetCurrentThreadId();
+
+
14497 LARGE_INTEGER counter;
+
14498 QueryPerformanceCounter(&counter);
+
14499 outParams.time = (double)(counter.QuadPart - m_StartCounter) / (double)m_Freq;
+
+
+
14502 void VmaRecorder::PrintPointerList(uint64_t count,
const VmaAllocation* pItems)
+
+
+
+
14506 fprintf(m_File,
"%p", pItems[0]);
+
14507 for(uint64_t i = 1; i < count; ++i)
+
+
14509 fprintf(m_File,
" %p", pItems[i]);
+
+
+
+
+
14514 void VmaRecorder::Flush()
+
+
+
+
+
+
+
+
14522 #endif // #if VMA_RECORDING_ENABLED
+
+
+
+
14527 VmaAllocationObjectAllocator::VmaAllocationObjectAllocator(
const VkAllocationCallbacks* pAllocationCallbacks) :
+
14528 m_Allocator(pAllocationCallbacks, 1024)
+
-
14532 void VmaAllocationObjectAllocator::Free(
VmaAllocation hAlloc)
+
14534 VmaMutexLock mutexLock(m_Mutex);
-
14535 m_Allocator.Free(hAlloc);
+
14535 return m_Allocator.Alloc();
-
-
-
-
-
14543 m_VulkanApiVersion(pCreateInfo->vulkanApiVersion != 0 ? pCreateInfo->vulkanApiVersion : VK_API_VERSION_1_0),
-
-
-
-
14547 m_hDevice(pCreateInfo->device),
-
14548 m_hInstance(pCreateInfo->instance),
-
14549 m_AllocationCallbacksSpecified(pCreateInfo->pAllocationCallbacks != VMA_NULL),
-
14550 m_AllocationCallbacks(pCreateInfo->pAllocationCallbacks ?
-
14551 *pCreateInfo->pAllocationCallbacks : VmaEmptyAllocationCallbacks),
-
14552 m_AllocationObjectAllocator(&m_AllocationCallbacks),
-
14553 m_HeapSizeLimitMask(0),
-
14554 m_PreferredLargeHeapBlockSize(0),
-
14555 m_PhysicalDevice(pCreateInfo->physicalDevice),
-
14556 m_CurrentFrameIndex(0),
-
14557 m_GpuDefragmentationMemoryTypeBits(UINT32_MAX),
-
14558 m_Pools(VmaStlAllocator<
VmaPool>(GetAllocationCallbacks())),
-
-
-
14561 ,m_pRecorder(VMA_NULL)
-
-
-
14564 if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
-
-
14566 m_UseKhrDedicatedAllocation =
false;
-
14567 m_UseKhrBindMemory2 =
false;
-
-
-
14570 if(VMA_DEBUG_DETECT_CORRUPTION)
+
14538 void VmaAllocationObjectAllocator::Free(
VmaAllocation hAlloc)
+
+
14540 VmaMutexLock mutexLock(m_Mutex);
+
14541 m_Allocator.Free(hAlloc);
+
+
+
+
+
+
+
14549 m_VulkanApiVersion(pCreateInfo->vulkanApiVersion != 0 ? pCreateInfo->vulkanApiVersion : VK_API_VERSION_1_0),
+
+
+
+
14553 m_hDevice(pCreateInfo->device),
+
14554 m_hInstance(pCreateInfo->instance),
+
14555 m_AllocationCallbacksSpecified(pCreateInfo->pAllocationCallbacks != VMA_NULL),
+
14556 m_AllocationCallbacks(pCreateInfo->pAllocationCallbacks ?
+
14557 *pCreateInfo->pAllocationCallbacks : VmaEmptyAllocationCallbacks),
+
14558 m_AllocationObjectAllocator(&m_AllocationCallbacks),
+
14559 m_HeapSizeLimitMask(0),
+
14560 m_PreferredLargeHeapBlockSize(0),
+
14561 m_PhysicalDevice(pCreateInfo->physicalDevice),
+
14562 m_CurrentFrameIndex(0),
+
14563 m_GpuDefragmentationMemoryTypeBits(UINT32_MAX),
+
14564 m_Pools(VmaStlAllocator<
VmaPool>(GetAllocationCallbacks())),
+
+
+
14567 ,m_pRecorder(VMA_NULL)
+
+
+
14570 if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
-
-
14573 VMA_ASSERT(VMA_DEBUG_MARGIN %
sizeof(uint32_t) == 0);
+
14572 m_UseKhrDedicatedAllocation =
false;
+
14573 m_UseKhrBindMemory2 =
false;
-
-
-
14578 if(m_VulkanApiVersion < VK_MAKE_VERSION(1, 1, 0))
-
-
14580 #if !(VMA_DEDICATED_ALLOCATION)
-
-
-
14583 VMA_ASSERT(0 &&
"VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT set but required extensions are disabled by preprocessor macros.");
-
-
-
14586 #if !(VMA_BIND_MEMORY2)
-
+
14576 if(VMA_DEBUG_DETECT_CORRUPTION)
+
+
+
14579 VMA_ASSERT(VMA_DEBUG_MARGIN %
sizeof(uint32_t) == 0);
+
+
+
+
+
14584 if(m_VulkanApiVersion < VK_MAKE_VERSION(1, 1, 0))
+
+
14586 #if !(VMA_DEDICATED_ALLOCATION)
+
-
14589 VMA_ASSERT(0 &&
"VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT set but required extension is disabled by preprocessor macros.");
+
14589 VMA_ASSERT(0 &&
"VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT set but required extensions are disabled by preprocessor macros.");
-
-
14593 #if !(VMA_MEMORY_BUDGET)
-
-
-
14596 VMA_ASSERT(0 &&
"VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT set but required extension is disabled by preprocessor macros.");
-
-
-
14599 #if VMA_VULKAN_VERSION < 1001000
-
14600 if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
+
14592 #if !(VMA_BIND_MEMORY2)
+
+
+
14595 VMA_ASSERT(0 &&
"VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT set but required extension is disabled by preprocessor macros.");
+
+
+
+
14599 #if !(VMA_MEMORY_BUDGET)
+
-
14602 VMA_ASSERT(0 &&
"vulkanApiVersion >= VK_API_VERSION_1_1 but required Vulkan version is disabled by preprocessor macros.");
+
14602 VMA_ASSERT(0 &&
"VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT set but required extension is disabled by preprocessor macros.");
-
-
14606 memset(&m_DeviceMemoryCallbacks, 0 ,
sizeof(m_DeviceMemoryCallbacks));
-
14607 memset(&m_PhysicalDeviceProperties, 0,
sizeof(m_PhysicalDeviceProperties));
-
14608 memset(&m_MemProps, 0,
sizeof(m_MemProps));
-
-
14610 memset(&m_pBlockVectors, 0,
sizeof(m_pBlockVectors));
-
14611 memset(&m_pDedicatedAllocations, 0,
sizeof(m_pDedicatedAllocations));
-
14612 memset(&m_VulkanFunctions, 0,
sizeof(m_VulkanFunctions));
-
-
-
-
-
-
+
14605 #if VMA_VULKAN_VERSION < 1001000
+
14606 if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
+
+
14608 VMA_ASSERT(0 &&
"vulkanApiVersion >= VK_API_VERSION_1_1 but required Vulkan version is disabled by preprocessor macros.");
+
+
+
+
14612 memset(&m_DeviceMemoryCallbacks, 0 ,
sizeof(m_DeviceMemoryCallbacks));
+
14613 memset(&m_PhysicalDeviceProperties, 0,
sizeof(m_PhysicalDeviceProperties));
+
14614 memset(&m_MemProps, 0,
sizeof(m_MemProps));
+
+
14616 memset(&m_pBlockVectors, 0,
sizeof(m_pBlockVectors));
+
14617 memset(&m_pDedicatedAllocations, 0,
sizeof(m_pDedicatedAllocations));
+
14618 memset(&m_VulkanFunctions, 0,
sizeof(m_VulkanFunctions));
-
-
-
14622 (*m_VulkanFunctions.vkGetPhysicalDeviceProperties)(m_PhysicalDevice, &m_PhysicalDeviceProperties);
-
14623 (*m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties)(m_PhysicalDevice, &m_MemProps);
-
-
14625 VMA_ASSERT(VmaIsPow2(VMA_DEBUG_ALIGNMENT));
-
14626 VMA_ASSERT(VmaIsPow2(VMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY));
-
14627 VMA_ASSERT(VmaIsPow2(m_PhysicalDeviceProperties.limits.bufferImageGranularity));
-
14628 VMA_ASSERT(VmaIsPow2(m_PhysicalDeviceProperties.limits.nonCoherentAtomSize));
-
-
-
-
-
-
-
14635 for(uint32_t heapIndex = 0; heapIndex < GetMemoryHeapCount(); ++heapIndex)
-
-
14637 const VkDeviceSize limit = pCreateInfo->
pHeapSizeLimit[heapIndex];
-
14638 if(limit != VK_WHOLE_SIZE)
-
-
14640 m_HeapSizeLimitMask |= 1u << heapIndex;
-
14641 if(limit < m_MemProps.memoryHeaps[heapIndex].size)
-
-
14643 m_MemProps.memoryHeaps[heapIndex].size = limit;
-
-
-
-
-
-
14649 for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
-
-
14651 const VkDeviceSize preferredBlockSize = CalcPreferredBlockSize(memTypeIndex);
-
-
14653 m_pBlockVectors[memTypeIndex] = vma_new(
this, VmaBlockVector)(
-
-
-
-
14657 preferredBlockSize,
-
-
-
14660 GetBufferImageGranularity(),
-
-
-
-
-
-
14666 m_pDedicatedAllocations[memTypeIndex] = vma_new(
this, AllocationVectorType)(VmaStlAllocator<VmaAllocation>(GetAllocationCallbacks()));
-
-
-
-
-
-
-
14673 VkResult res = VK_SUCCESS;
-
-
-
-
-
14678 #if VMA_RECORDING_ENABLED
-
14679 m_pRecorder = vma_new(
this, VmaRecorder)();
-
-
14681 if(res != VK_SUCCESS)
-
-
-
-
14685 m_pRecorder->WriteConfiguration(
-
14686 m_PhysicalDeviceProperties,
-
-
14688 m_VulkanApiVersion,
-
14689 m_UseKhrDedicatedAllocation,
-
14690 m_UseKhrBindMemory2,
-
14691 m_UseExtMemoryBudget);
-
14692 m_pRecorder->RecordCreateAllocator(GetCurrentFrameIndex());
-
-
14694 VMA_ASSERT(0 &&
"VmaAllocatorCreateInfo::pRecordSettings used, but not supported due to VMA_RECORDING_ENABLED not defined to 1.");
-
14695 return VK_ERROR_FEATURE_NOT_PRESENT;
-
-
-
-
14699 #if VMA_MEMORY_BUDGET
-
14700 if(m_UseExtMemoryBudget)
-
-
14702 UpdateVulkanBudget();
+
+
+
+
+
+
+
+
+
14628 (*m_VulkanFunctions.vkGetPhysicalDeviceProperties)(m_PhysicalDevice, &m_PhysicalDeviceProperties);
+
14629 (*m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties)(m_PhysicalDevice, &m_MemProps);
+
+
14631 VMA_ASSERT(VmaIsPow2(VMA_DEBUG_ALIGNMENT));
+
14632 VMA_ASSERT(VmaIsPow2(VMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY));
+
14633 VMA_ASSERT(VmaIsPow2(m_PhysicalDeviceProperties.limits.bufferImageGranularity));
+
14634 VMA_ASSERT(VmaIsPow2(m_PhysicalDeviceProperties.limits.nonCoherentAtomSize));
+
+
+
+
+
+
+
14641 for(uint32_t heapIndex = 0; heapIndex < GetMemoryHeapCount(); ++heapIndex)
+
+
14643 const VkDeviceSize limit = pCreateInfo->
pHeapSizeLimit[heapIndex];
+
14644 if(limit != VK_WHOLE_SIZE)
+
+
14646 m_HeapSizeLimitMask |= 1u << heapIndex;
+
14647 if(limit < m_MemProps.memoryHeaps[heapIndex].size)
+
+
14649 m_MemProps.memoryHeaps[heapIndex].size = limit;
+
+
+
+
+
+
14655 for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
+
+
14657 const VkDeviceSize preferredBlockSize = CalcPreferredBlockSize(memTypeIndex);
+
+
14659 m_pBlockVectors[memTypeIndex] = vma_new(
this, VmaBlockVector)(
+
+
+
+
14663 preferredBlockSize,
+
+
+
14666 GetBufferImageGranularity(),
+
+
+
+
+
+
14672 m_pDedicatedAllocations[memTypeIndex] = vma_new(
this, AllocationVectorType)(VmaStlAllocator<VmaAllocation>(GetAllocationCallbacks()));
+
+
+
+
+
+
+
14679 VkResult res = VK_SUCCESS;
+
+
+
+
+
14684 #if VMA_RECORDING_ENABLED
+
14685 m_pRecorder = vma_new(
this, VmaRecorder)();
+
+
14687 if(res != VK_SUCCESS)
+
+
+
+
14691 m_pRecorder->WriteConfiguration(
+
14692 m_PhysicalDeviceProperties,
+
+
14694 m_VulkanApiVersion,
+
14695 m_UseKhrDedicatedAllocation,
+
14696 m_UseKhrBindMemory2,
+
14697 m_UseExtMemoryBudget);
+
14698 m_pRecorder->RecordCreateAllocator(GetCurrentFrameIndex());
+
+
14700 VMA_ASSERT(0 &&
"VmaAllocatorCreateInfo::pRecordSettings used, but not supported due to VMA_RECORDING_ENABLED not defined to 1.");
+
14701 return VK_ERROR_FEATURE_NOT_PRESENT;
+
-
14704 #endif // #if VMA_MEMORY_BUDGET
-
-
-
-
-
14709 VmaAllocator_T::~VmaAllocator_T()
-
-
14711 #if VMA_RECORDING_ENABLED
-
14712 if(m_pRecorder != VMA_NULL)
-
-
14714 m_pRecorder->RecordDestroyAllocator(GetCurrentFrameIndex());
-
14715 vma_delete(
this, m_pRecorder);
-
-
-
-
14719 VMA_ASSERT(m_Pools.empty());
-
-
14721 for(
size_t i = GetMemoryTypeCount(); i--; )
-
-
14723 if(m_pDedicatedAllocations[i] != VMA_NULL && !m_pDedicatedAllocations[i]->empty())
-
-
14725 VMA_ASSERT(0 &&
"Unfreed dedicated allocations found.");
-
-
-
14728 vma_delete(
this, m_pDedicatedAllocations[i]);
-
14729 vma_delete(
this, m_pBlockVectors[i]);
-
-
-
-
14733 void VmaAllocator_T::ImportVulkanFunctions(
const VmaVulkanFunctions* pVulkanFunctions)
-
-
14735 #if VMA_STATIC_VULKAN_FUNCTIONS == 1
-
14736 m_VulkanFunctions.vkGetPhysicalDeviceProperties = (PFN_vkGetPhysicalDeviceProperties)vkGetPhysicalDeviceProperties;
-
14737 m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties = (PFN_vkGetPhysicalDeviceMemoryProperties)vkGetPhysicalDeviceMemoryProperties;
-
14738 m_VulkanFunctions.vkAllocateMemory = (PFN_vkAllocateMemory)vkAllocateMemory;
-
14739 m_VulkanFunctions.vkFreeMemory = (PFN_vkFreeMemory)vkFreeMemory;
-
14740 m_VulkanFunctions.vkMapMemory = (PFN_vkMapMemory)vkMapMemory;
-
14741 m_VulkanFunctions.vkUnmapMemory = (PFN_vkUnmapMemory)vkUnmapMemory;
-
14742 m_VulkanFunctions.vkFlushMappedMemoryRanges = (PFN_vkFlushMappedMemoryRanges)vkFlushMappedMemoryRanges;
-
14743 m_VulkanFunctions.vkInvalidateMappedMemoryRanges = (PFN_vkInvalidateMappedMemoryRanges)vkInvalidateMappedMemoryRanges;
-
14744 m_VulkanFunctions.vkBindBufferMemory = (PFN_vkBindBufferMemory)vkBindBufferMemory;
-
14745 m_VulkanFunctions.vkBindImageMemory = (PFN_vkBindImageMemory)vkBindImageMemory;
-
14746 m_VulkanFunctions.vkGetBufferMemoryRequirements = (PFN_vkGetBufferMemoryRequirements)vkGetBufferMemoryRequirements;
-
14747 m_VulkanFunctions.vkGetImageMemoryRequirements = (PFN_vkGetImageMemoryRequirements)vkGetImageMemoryRequirements;
-
14748 m_VulkanFunctions.vkCreateBuffer = (PFN_vkCreateBuffer)vkCreateBuffer;
-
14749 m_VulkanFunctions.vkDestroyBuffer = (PFN_vkDestroyBuffer)vkDestroyBuffer;
-
14750 m_VulkanFunctions.vkCreateImage = (PFN_vkCreateImage)vkCreateImage;
-
14751 m_VulkanFunctions.vkDestroyImage = (PFN_vkDestroyImage)vkDestroyImage;
-
14752 m_VulkanFunctions.vkCmdCopyBuffer = (PFN_vkCmdCopyBuffer)vkCmdCopyBuffer;
-
14753 #if VMA_VULKAN_VERSION >= 1001000
-
14754 if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
-
-
14756 VMA_ASSERT(m_hInstance != VK_NULL_HANDLE);
-
14757 m_VulkanFunctions.vkGetBufferMemoryRequirements2KHR =
-
14758 (PFN_vkGetBufferMemoryRequirements2KHR)vkGetDeviceProcAddr(m_hDevice,
"vkGetBufferMemoryRequirements2");
-
14759 m_VulkanFunctions.vkGetImageMemoryRequirements2KHR =
-
14760 (PFN_vkGetImageMemoryRequirements2KHR)vkGetDeviceProcAddr(m_hDevice,
"vkGetImageMemoryRequirements2");
-
14761 m_VulkanFunctions.vkBindBufferMemory2KHR =
-
14762 (PFN_vkBindBufferMemory2KHR)vkGetDeviceProcAddr(m_hDevice,
"vkBindBufferMemory2");
-
14763 m_VulkanFunctions.vkBindImageMemory2KHR =
-
14764 (PFN_vkBindImageMemory2KHR)vkGetDeviceProcAddr(m_hDevice,
"vkBindImageMemory2");
-
14765 m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties2KHR =
-
14766 (PFN_vkGetPhysicalDeviceMemoryProperties2KHR)vkGetInstanceProcAddr(m_hInstance,
"vkGetPhysicalDeviceMemoryProperties2");
-
-
-
14769 #if VMA_DEDICATED_ALLOCATION
-
14770 if(m_UseKhrDedicatedAllocation)
-
-
14772 m_VulkanFunctions.vkGetBufferMemoryRequirements2KHR =
-
14773 (PFN_vkGetBufferMemoryRequirements2KHR)vkGetDeviceProcAddr(m_hDevice,
"vkGetBufferMemoryRequirements2KHR");
-
14774 m_VulkanFunctions.vkGetImageMemoryRequirements2KHR =
-
14775 (PFN_vkGetImageMemoryRequirements2KHR)vkGetDeviceProcAddr(m_hDevice,
"vkGetImageMemoryRequirements2KHR");
-
-
-
14778 #if VMA_BIND_MEMORY2
-
14779 if(m_UseKhrBindMemory2)
-
-
14781 m_VulkanFunctions.vkBindBufferMemory2KHR =
-
14782 (PFN_vkBindBufferMemory2KHR)vkGetDeviceProcAddr(m_hDevice,
"vkBindBufferMemory2KHR");
-
14783 m_VulkanFunctions.vkBindImageMemory2KHR =
-
14784 (PFN_vkBindImageMemory2KHR)vkGetDeviceProcAddr(m_hDevice,
"vkBindImageMemory2KHR");
-
-
14786 #endif // #if VMA_BIND_MEMORY2
-
14787 #if VMA_MEMORY_BUDGET
-
14788 if(m_UseExtMemoryBudget && m_VulkanApiVersion < VK_MAKE_VERSION(1, 1, 0))
-
-
14790 VMA_ASSERT(m_hInstance != VK_NULL_HANDLE);
-
14791 m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties2KHR =
-
14792 (PFN_vkGetPhysicalDeviceMemoryProperties2KHR)vkGetInstanceProcAddr(m_hInstance,
"vkGetPhysicalDeviceMemoryProperties2KHR");
-
-
14794 #endif // #if VMA_MEMORY_BUDGET
-
14795 #endif // #if VMA_STATIC_VULKAN_FUNCTIONS == 1
-
-
14797 #define VMA_COPY_IF_NOT_NULL(funcName) \
-
14798 if(pVulkanFunctions->funcName != VMA_NULL) m_VulkanFunctions.funcName = pVulkanFunctions->funcName;
-
-
14800 if(pVulkanFunctions != VMA_NULL)
-
-
14802 VMA_COPY_IF_NOT_NULL(vkGetPhysicalDeviceProperties);
-
14803 VMA_COPY_IF_NOT_NULL(vkGetPhysicalDeviceMemoryProperties);
-
14804 VMA_COPY_IF_NOT_NULL(vkAllocateMemory);
-
14805 VMA_COPY_IF_NOT_NULL(vkFreeMemory);
-
14806 VMA_COPY_IF_NOT_NULL(vkMapMemory);
-
14807 VMA_COPY_IF_NOT_NULL(vkUnmapMemory);
-
14808 VMA_COPY_IF_NOT_NULL(vkFlushMappedMemoryRanges);
-
14809 VMA_COPY_IF_NOT_NULL(vkInvalidateMappedMemoryRanges);
-
14810 VMA_COPY_IF_NOT_NULL(vkBindBufferMemory);
-
14811 VMA_COPY_IF_NOT_NULL(vkBindImageMemory);
-
14812 VMA_COPY_IF_NOT_NULL(vkGetBufferMemoryRequirements);
-
14813 VMA_COPY_IF_NOT_NULL(vkGetImageMemoryRequirements);
-
14814 VMA_COPY_IF_NOT_NULL(vkCreateBuffer);
-
14815 VMA_COPY_IF_NOT_NULL(vkDestroyBuffer);
-
14816 VMA_COPY_IF_NOT_NULL(vkCreateImage);
-
14817 VMA_COPY_IF_NOT_NULL(vkDestroyImage);
-
14818 VMA_COPY_IF_NOT_NULL(vkCmdCopyBuffer);
-
14819 #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
-
14820 VMA_COPY_IF_NOT_NULL(vkGetBufferMemoryRequirements2KHR);
-
14821 VMA_COPY_IF_NOT_NULL(vkGetImageMemoryRequirements2KHR);
-
-
14823 #if VMA_BIND_MEMORY2 || VMA_VULKAN_VERSION >= 1001000
-
14824 VMA_COPY_IF_NOT_NULL(vkBindBufferMemory2KHR);
-
14825 VMA_COPY_IF_NOT_NULL(vkBindImageMemory2KHR);
-
-
14827 #if VMA_MEMORY_BUDGET
-
14828 VMA_COPY_IF_NOT_NULL(vkGetPhysicalDeviceMemoryProperties2KHR);
-
-
-
-
14832 #undef VMA_COPY_IF_NOT_NULL
-
-
-
-
14836 VMA_ASSERT(m_VulkanFunctions.vkGetPhysicalDeviceProperties != VMA_NULL);
-
14837 VMA_ASSERT(m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties != VMA_NULL);
-
14838 VMA_ASSERT(m_VulkanFunctions.vkAllocateMemory != VMA_NULL);
-
14839 VMA_ASSERT(m_VulkanFunctions.vkFreeMemory != VMA_NULL);
-
14840 VMA_ASSERT(m_VulkanFunctions.vkMapMemory != VMA_NULL);
-
14841 VMA_ASSERT(m_VulkanFunctions.vkUnmapMemory != VMA_NULL);
-
14842 VMA_ASSERT(m_VulkanFunctions.vkFlushMappedMemoryRanges != VMA_NULL);
-
14843 VMA_ASSERT(m_VulkanFunctions.vkInvalidateMappedMemoryRanges != VMA_NULL);
-
14844 VMA_ASSERT(m_VulkanFunctions.vkBindBufferMemory != VMA_NULL);
-
14845 VMA_ASSERT(m_VulkanFunctions.vkBindImageMemory != VMA_NULL);
-
14846 VMA_ASSERT(m_VulkanFunctions.vkGetBufferMemoryRequirements != VMA_NULL);
-
14847 VMA_ASSERT(m_VulkanFunctions.vkGetImageMemoryRequirements != VMA_NULL);
-
14848 VMA_ASSERT(m_VulkanFunctions.vkCreateBuffer != VMA_NULL);
-
14849 VMA_ASSERT(m_VulkanFunctions.vkDestroyBuffer != VMA_NULL);
-
14850 VMA_ASSERT(m_VulkanFunctions.vkCreateImage != VMA_NULL);
-
14851 VMA_ASSERT(m_VulkanFunctions.vkDestroyImage != VMA_NULL);
-
14852 VMA_ASSERT(m_VulkanFunctions.vkCmdCopyBuffer != VMA_NULL);
-
14853 #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
-
14854 if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0) || m_UseKhrDedicatedAllocation)
-
-
14856 VMA_ASSERT(m_VulkanFunctions.vkGetBufferMemoryRequirements2KHR != VMA_NULL);
-
14857 VMA_ASSERT(m_VulkanFunctions.vkGetImageMemoryRequirements2KHR != VMA_NULL);
-
-
-
14860 #if VMA_BIND_MEMORY2 || VMA_VULKAN_VERSION >= 1001000
-
14861 if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0) || m_UseKhrBindMemory2)
-
-
14863 VMA_ASSERT(m_VulkanFunctions.vkBindBufferMemory2KHR != VMA_NULL);
-
14864 VMA_ASSERT(m_VulkanFunctions.vkBindImageMemory2KHR != VMA_NULL);
-
-
-
14867 #if VMA_MEMORY_BUDGET || VMA_VULKAN_VERSION >= 1001000
-
14868 if(m_UseExtMemoryBudget || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
-
-
14870 VMA_ASSERT(m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties2KHR != VMA_NULL);
+
+
14705 #if VMA_MEMORY_BUDGET
+
14706 if(m_UseExtMemoryBudget)
+
+
14708 UpdateVulkanBudget();
+
+
14710 #endif // #if VMA_MEMORY_BUDGET
+
+
+
+
+
14715 VmaAllocator_T::~VmaAllocator_T()
+
+
14717 #if VMA_RECORDING_ENABLED
+
14718 if(m_pRecorder != VMA_NULL)
+
+
14720 m_pRecorder->RecordDestroyAllocator(GetCurrentFrameIndex());
+
14721 vma_delete(
this, m_pRecorder);
+
+
+
+
14725 VMA_ASSERT(m_Pools.empty());
+
+
14727 for(
size_t i = GetMemoryTypeCount(); i--; )
+
+
14729 if(m_pDedicatedAllocations[i] != VMA_NULL && !m_pDedicatedAllocations[i]->empty())
+
+
14731 VMA_ASSERT(0 &&
"Unfreed dedicated allocations found.");
+
+
+
14734 vma_delete(
this, m_pDedicatedAllocations[i]);
+
14735 vma_delete(
this, m_pBlockVectors[i]);
+
+
+
+
14739 void VmaAllocator_T::ImportVulkanFunctions(
const VmaVulkanFunctions* pVulkanFunctions)
+
+
14741 #if VMA_STATIC_VULKAN_FUNCTIONS == 1
+
14742 m_VulkanFunctions.vkGetPhysicalDeviceProperties = (PFN_vkGetPhysicalDeviceProperties)vkGetPhysicalDeviceProperties;
+
14743 m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties = (PFN_vkGetPhysicalDeviceMemoryProperties)vkGetPhysicalDeviceMemoryProperties;
+
14744 m_VulkanFunctions.vkAllocateMemory = (PFN_vkAllocateMemory)vkAllocateMemory;
+
14745 m_VulkanFunctions.vkFreeMemory = (PFN_vkFreeMemory)vkFreeMemory;
+
14746 m_VulkanFunctions.vkMapMemory = (PFN_vkMapMemory)vkMapMemory;
+
14747 m_VulkanFunctions.vkUnmapMemory = (PFN_vkUnmapMemory)vkUnmapMemory;
+
14748 m_VulkanFunctions.vkFlushMappedMemoryRanges = (PFN_vkFlushMappedMemoryRanges)vkFlushMappedMemoryRanges;
+
14749 m_VulkanFunctions.vkInvalidateMappedMemoryRanges = (PFN_vkInvalidateMappedMemoryRanges)vkInvalidateMappedMemoryRanges;
+
14750 m_VulkanFunctions.vkBindBufferMemory = (PFN_vkBindBufferMemory)vkBindBufferMemory;
+
14751 m_VulkanFunctions.vkBindImageMemory = (PFN_vkBindImageMemory)vkBindImageMemory;
+
14752 m_VulkanFunctions.vkGetBufferMemoryRequirements = (PFN_vkGetBufferMemoryRequirements)vkGetBufferMemoryRequirements;
+
14753 m_VulkanFunctions.vkGetImageMemoryRequirements = (PFN_vkGetImageMemoryRequirements)vkGetImageMemoryRequirements;
+
14754 m_VulkanFunctions.vkCreateBuffer = (PFN_vkCreateBuffer)vkCreateBuffer;
+
14755 m_VulkanFunctions.vkDestroyBuffer = (PFN_vkDestroyBuffer)vkDestroyBuffer;
+
14756 m_VulkanFunctions.vkCreateImage = (PFN_vkCreateImage)vkCreateImage;
+
14757 m_VulkanFunctions.vkDestroyImage = (PFN_vkDestroyImage)vkDestroyImage;
+
14758 m_VulkanFunctions.vkCmdCopyBuffer = (PFN_vkCmdCopyBuffer)vkCmdCopyBuffer;
+
14759 #if VMA_VULKAN_VERSION >= 1001000
+
14760 if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
+
+
14762 VMA_ASSERT(m_hInstance != VK_NULL_HANDLE);
+
14763 m_VulkanFunctions.vkGetBufferMemoryRequirements2KHR =
+
14764 (PFN_vkGetBufferMemoryRequirements2KHR)vkGetDeviceProcAddr(m_hDevice,
"vkGetBufferMemoryRequirements2");
+
14765 m_VulkanFunctions.vkGetImageMemoryRequirements2KHR =
+
14766 (PFN_vkGetImageMemoryRequirements2KHR)vkGetDeviceProcAddr(m_hDevice,
"vkGetImageMemoryRequirements2");
+
14767 m_VulkanFunctions.vkBindBufferMemory2KHR =
+
14768 (PFN_vkBindBufferMemory2KHR)vkGetDeviceProcAddr(m_hDevice,
"vkBindBufferMemory2");
+
14769 m_VulkanFunctions.vkBindImageMemory2KHR =
+
14770 (PFN_vkBindImageMemory2KHR)vkGetDeviceProcAddr(m_hDevice,
"vkBindImageMemory2");
+
14771 m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties2KHR =
+
14772 (PFN_vkGetPhysicalDeviceMemoryProperties2KHR)vkGetInstanceProcAddr(m_hInstance,
"vkGetPhysicalDeviceMemoryProperties2");
+
+
+
14775 #if VMA_DEDICATED_ALLOCATION
+
14776 if(m_UseKhrDedicatedAllocation)
+
+
14778 m_VulkanFunctions.vkGetBufferMemoryRequirements2KHR =
+
14779 (PFN_vkGetBufferMemoryRequirements2KHR)vkGetDeviceProcAddr(m_hDevice,
"vkGetBufferMemoryRequirements2KHR");
+
14780 m_VulkanFunctions.vkGetImageMemoryRequirements2KHR =
+
14781 (PFN_vkGetImageMemoryRequirements2KHR)vkGetDeviceProcAddr(m_hDevice,
"vkGetImageMemoryRequirements2KHR");
+
+
+
14784 #if VMA_BIND_MEMORY2
+
14785 if(m_UseKhrBindMemory2)
+
+
14787 m_VulkanFunctions.vkBindBufferMemory2KHR =
+
14788 (PFN_vkBindBufferMemory2KHR)vkGetDeviceProcAddr(m_hDevice,
"vkBindBufferMemory2KHR");
+
14789 m_VulkanFunctions.vkBindImageMemory2KHR =
+
14790 (PFN_vkBindImageMemory2KHR)vkGetDeviceProcAddr(m_hDevice,
"vkBindImageMemory2KHR");
+
+
14792 #endif // #if VMA_BIND_MEMORY2
+
14793 #if VMA_MEMORY_BUDGET
+
14794 if(m_UseExtMemoryBudget && m_VulkanApiVersion < VK_MAKE_VERSION(1, 1, 0))
+
+
14796 VMA_ASSERT(m_hInstance != VK_NULL_HANDLE);
+
14797 m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties2KHR =
+
14798 (PFN_vkGetPhysicalDeviceMemoryProperties2KHR)vkGetInstanceProcAddr(m_hInstance,
"vkGetPhysicalDeviceMemoryProperties2KHR");
+
+
14800 #endif // #if VMA_MEMORY_BUDGET
+
14801 #endif // #if VMA_STATIC_VULKAN_FUNCTIONS == 1
+
+
14803 #define VMA_COPY_IF_NOT_NULL(funcName) \
+
14804 if(pVulkanFunctions->funcName != VMA_NULL) m_VulkanFunctions.funcName = pVulkanFunctions->funcName;
+
+
14806 if(pVulkanFunctions != VMA_NULL)
+
+
14808 VMA_COPY_IF_NOT_NULL(vkGetPhysicalDeviceProperties);
+
14809 VMA_COPY_IF_NOT_NULL(vkGetPhysicalDeviceMemoryProperties);
+
14810 VMA_COPY_IF_NOT_NULL(vkAllocateMemory);
+
14811 VMA_COPY_IF_NOT_NULL(vkFreeMemory);
+
14812 VMA_COPY_IF_NOT_NULL(vkMapMemory);
+
14813 VMA_COPY_IF_NOT_NULL(vkUnmapMemory);
+
14814 VMA_COPY_IF_NOT_NULL(vkFlushMappedMemoryRanges);
+
14815 VMA_COPY_IF_NOT_NULL(vkInvalidateMappedMemoryRanges);
+
14816 VMA_COPY_IF_NOT_NULL(vkBindBufferMemory);
+
14817 VMA_COPY_IF_NOT_NULL(vkBindImageMemory);
+
14818 VMA_COPY_IF_NOT_NULL(vkGetBufferMemoryRequirements);
+
14819 VMA_COPY_IF_NOT_NULL(vkGetImageMemoryRequirements);
+
14820 VMA_COPY_IF_NOT_NULL(vkCreateBuffer);
+
14821 VMA_COPY_IF_NOT_NULL(vkDestroyBuffer);
+
14822 VMA_COPY_IF_NOT_NULL(vkCreateImage);
+
14823 VMA_COPY_IF_NOT_NULL(vkDestroyImage);
+
14824 VMA_COPY_IF_NOT_NULL(vkCmdCopyBuffer);
+
14825 #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
+
14826 VMA_COPY_IF_NOT_NULL(vkGetBufferMemoryRequirements2KHR);
+
14827 VMA_COPY_IF_NOT_NULL(vkGetImageMemoryRequirements2KHR);
+
+
14829 #if VMA_BIND_MEMORY2 || VMA_VULKAN_VERSION >= 1001000
+
14830 VMA_COPY_IF_NOT_NULL(vkBindBufferMemory2KHR);
+
14831 VMA_COPY_IF_NOT_NULL(vkBindImageMemory2KHR);
+
+
14833 #if VMA_MEMORY_BUDGET
+
14834 VMA_COPY_IF_NOT_NULL(vkGetPhysicalDeviceMemoryProperties2KHR);
+
+
+
+
14838 #undef VMA_COPY_IF_NOT_NULL
+
+
+
+
14842 VMA_ASSERT(m_VulkanFunctions.vkGetPhysicalDeviceProperties != VMA_NULL);
+
14843 VMA_ASSERT(m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties != VMA_NULL);
+
14844 VMA_ASSERT(m_VulkanFunctions.vkAllocateMemory != VMA_NULL);
+
14845 VMA_ASSERT(m_VulkanFunctions.vkFreeMemory != VMA_NULL);
+
14846 VMA_ASSERT(m_VulkanFunctions.vkMapMemory != VMA_NULL);
+
14847 VMA_ASSERT(m_VulkanFunctions.vkUnmapMemory != VMA_NULL);
+
14848 VMA_ASSERT(m_VulkanFunctions.vkFlushMappedMemoryRanges != VMA_NULL);
+
14849 VMA_ASSERT(m_VulkanFunctions.vkInvalidateMappedMemoryRanges != VMA_NULL);
+
14850 VMA_ASSERT(m_VulkanFunctions.vkBindBufferMemory != VMA_NULL);
+
14851 VMA_ASSERT(m_VulkanFunctions.vkBindImageMemory != VMA_NULL);
+
14852 VMA_ASSERT(m_VulkanFunctions.vkGetBufferMemoryRequirements != VMA_NULL);
+
14853 VMA_ASSERT(m_VulkanFunctions.vkGetImageMemoryRequirements != VMA_NULL);
+
14854 VMA_ASSERT(m_VulkanFunctions.vkCreateBuffer != VMA_NULL);
+
14855 VMA_ASSERT(m_VulkanFunctions.vkDestroyBuffer != VMA_NULL);
+
14856 VMA_ASSERT(m_VulkanFunctions.vkCreateImage != VMA_NULL);
+
14857 VMA_ASSERT(m_VulkanFunctions.vkDestroyImage != VMA_NULL);
+
14858 VMA_ASSERT(m_VulkanFunctions.vkCmdCopyBuffer != VMA_NULL);
+
14859 #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
+
14860 if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0) || m_UseKhrDedicatedAllocation)
+
+
14862 VMA_ASSERT(m_VulkanFunctions.vkGetBufferMemoryRequirements2KHR != VMA_NULL);
+
14863 VMA_ASSERT(m_VulkanFunctions.vkGetImageMemoryRequirements2KHR != VMA_NULL);
+
+
+
14866 #if VMA_BIND_MEMORY2 || VMA_VULKAN_VERSION >= 1001000
+
14867 if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0) || m_UseKhrBindMemory2)
+
+
14869 VMA_ASSERT(m_VulkanFunctions.vkBindBufferMemory2KHR != VMA_NULL);
+
14870 VMA_ASSERT(m_VulkanFunctions.vkBindImageMemory2KHR != VMA_NULL);
-
-
-
14875 VkDeviceSize VmaAllocator_T::CalcPreferredBlockSize(uint32_t memTypeIndex)
-
-
14877 const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(memTypeIndex);
-
14878 const VkDeviceSize heapSize = m_MemProps.memoryHeaps[heapIndex].size;
-
14879 const bool isSmallHeap = heapSize <= VMA_SMALL_HEAP_MAX_SIZE;
-
14880 return VmaAlignUp(isSmallHeap ? (heapSize / 8) : m_PreferredLargeHeapBlockSize, (VkDeviceSize)32);
-
-
-
14883 VkResult VmaAllocator_T::AllocateMemoryOfType(
-
-
14885 VkDeviceSize alignment,
-
14886 bool dedicatedAllocation,
-
14887 VkBuffer dedicatedBuffer,
-
14888 VkImage dedicatedImage,
-
-
14890 uint32_t memTypeIndex,
-
14891 VmaSuballocationType suballocType,
-
14892 size_t allocationCount,
-
-
-
14895 VMA_ASSERT(pAllocations != VMA_NULL);
-
14896 VMA_DEBUG_LOG(
" AllocateMemory: MemoryTypeIndex=%u, AllocationCount=%zu, Size=%llu", memTypeIndex, allocationCount, size);
-
-
-
-
-
-
14902 (m_MemProps.memoryTypes[memTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
-
-
-
-
-
-
-
-
-
-
14912 VmaBlockVector*
const blockVector = m_pBlockVectors[memTypeIndex];
-
14913 VMA_ASSERT(blockVector);
-
-
14915 const VkDeviceSize preferredBlockSize = blockVector->GetPreferredBlockSize();
-
14916 bool preferDedicatedMemory =
-
14917 VMA_DEBUG_ALWAYS_DEDICATED_MEMORY ||
-
14918 dedicatedAllocation ||
-
-
14920 size > preferredBlockSize / 2;
-
-
14922 if(preferDedicatedMemory &&
-
-
14924 finalCreateInfo.
pool == VK_NULL_HANDLE)
-
-
-
-
-
-
-
-
-
14933 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
-
-
-
-
14937 return AllocateDedicatedMemory(
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
14953 VkResult res = blockVector->Allocate(
-
14954 m_CurrentFrameIndex.load(),
-
-
-
-
-
-
-
14961 if(res == VK_SUCCESS)
-
-
-
-
-
-
+
14873 #if VMA_MEMORY_BUDGET || VMA_VULKAN_VERSION >= 1001000
+
14874 if(m_UseExtMemoryBudget || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
+
+
14876 VMA_ASSERT(m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties2KHR != VMA_NULL);
+
+
+
+
+
14881 VkDeviceSize VmaAllocator_T::CalcPreferredBlockSize(uint32_t memTypeIndex)
+
+
14883 const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(memTypeIndex);
+
14884 const VkDeviceSize heapSize = m_MemProps.memoryHeaps[heapIndex].size;
+
14885 const bool isSmallHeap = heapSize <= VMA_SMALL_HEAP_MAX_SIZE;
+
14886 return VmaAlignUp(isSmallHeap ? (heapSize / 8) : m_PreferredLargeHeapBlockSize, (VkDeviceSize)32);
+
+
+
14889 VkResult VmaAllocator_T::AllocateMemoryOfType(
+
+
14891 VkDeviceSize alignment,
+
14892 bool dedicatedAllocation,
+
14893 VkBuffer dedicatedBuffer,
+
14894 VkImage dedicatedImage,
+
+
14896 uint32_t memTypeIndex,
+
14897 VmaSuballocationType suballocType,
+
14898 size_t allocationCount,
+
+
+
14901 VMA_ASSERT(pAllocations != VMA_NULL);
+
14902 VMA_DEBUG_LOG(
" AllocateMemory: MemoryTypeIndex=%u, AllocationCount=%zu, Size=%llu", memTypeIndex, allocationCount, size);
+
+
+
+
+
+
14908 (m_MemProps.memoryTypes[memTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
+
+
+
+
+
+
+
+
+
+
14918 VmaBlockVector*
const blockVector = m_pBlockVectors[memTypeIndex];
+
14919 VMA_ASSERT(blockVector);
+
+
14921 const VkDeviceSize preferredBlockSize = blockVector->GetPreferredBlockSize();
+
14922 bool preferDedicatedMemory =
+
14923 VMA_DEBUG_ALWAYS_DEDICATED_MEMORY ||
+
14924 dedicatedAllocation ||
+
+
14926 size > preferredBlockSize / 2;
+
+
14928 if(preferDedicatedMemory &&
+
+
14930 finalCreateInfo.
pool == VK_NULL_HANDLE)
+
+
+
+
+
+
+
+
+
14939 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
+
+
+
14943 return AllocateDedicatedMemory(
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
14959 VkResult res = blockVector->Allocate(
+
14960 m_CurrentFrameIndex.load(),
+
+
+
+
+
+
+
14967 if(res == VK_SUCCESS)
-
14969 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
-
-
-
14973 res = AllocateDedicatedMemory(
-
-
-
-
-
-
-
14980 finalCreateInfo.pUserData,
-
-
-
-
-
14985 if(res == VK_SUCCESS)
-
-
-
14988 VMA_DEBUG_LOG(
" Allocated as DedicatedMemory");
-
-
-
+
+
+
+
+
14975 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
+
+
+
14979 res = AllocateDedicatedMemory(
+
+
+
+
+
+
+
14986 finalCreateInfo.pUserData,
+
+
+
+
+
14991 if(res == VK_SUCCESS)
-
-
14994 VMA_DEBUG_LOG(
" vkAllocateMemory FAILED");
-
+
+
14994 VMA_DEBUG_LOG(
" Allocated as DedicatedMemory");
+
-
-
-
-
-
15001 VkResult VmaAllocator_T::AllocateDedicatedMemory(
-
-
15003 VmaSuballocationType suballocType,
-
15004 uint32_t memTypeIndex,
-
-
-
15007 bool isUserDataString,
-
-
15009 VkBuffer dedicatedBuffer,
-
15010 VkImage dedicatedImage,
-
15011 size_t allocationCount,
-
-
-
15014 VMA_ASSERT(allocationCount > 0 && pAllocations);
-
-
-
-
15018 const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(memTypeIndex);
-
-
15020 GetBudget(&heapBudget, heapIndex, 1);
-
15021 if(heapBudget.
usage + size * allocationCount > heapBudget.
budget)
-
-
15023 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
-
-
-
-
15027 VkMemoryAllocateInfo allocInfo = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO };
-
15028 allocInfo.memoryTypeIndex = memTypeIndex;
-
15029 allocInfo.allocationSize = size;
-
-
15031 #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
-
15032 VkMemoryDedicatedAllocateInfoKHR dedicatedAllocInfo = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR };
-
15033 if(m_UseKhrDedicatedAllocation || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
-
-
15035 if(dedicatedBuffer != VK_NULL_HANDLE)
-
-
15037 VMA_ASSERT(dedicatedImage == VK_NULL_HANDLE);
-
15038 dedicatedAllocInfo.buffer = dedicatedBuffer;
-
15039 allocInfo.pNext = &dedicatedAllocInfo;
-
-
15041 else if(dedicatedImage != VK_NULL_HANDLE)
+
+
+
+
15000 VMA_DEBUG_LOG(
" vkAllocateMemory FAILED");
+
+
+
+
+
+
+
15007 VkResult VmaAllocator_T::AllocateDedicatedMemory(
+
+
15009 VmaSuballocationType suballocType,
+
15010 uint32_t memTypeIndex,
+
+
+
15013 bool isUserDataString,
+
+
15015 VkBuffer dedicatedBuffer,
+
15016 VkImage dedicatedImage,
+
15017 size_t allocationCount,
+
+
+
15020 VMA_ASSERT(allocationCount > 0 && pAllocations);
+
+
+
+
15024 const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(memTypeIndex);
+
+
15026 GetBudget(&heapBudget, heapIndex, 1);
+
15027 if(heapBudget.
usage + size * allocationCount > heapBudget.
budget)
+
+
15029 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
+
+
+
15033 VkMemoryAllocateInfo allocInfo = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO };
+
15034 allocInfo.memoryTypeIndex = memTypeIndex;
+
15035 allocInfo.allocationSize = size;
+
+
15037 #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
+
15038 VkMemoryDedicatedAllocateInfoKHR dedicatedAllocInfo = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR };
+
15039 if(m_UseKhrDedicatedAllocation || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
+
+
15041 if(dedicatedBuffer != VK_NULL_HANDLE)
-
15043 dedicatedAllocInfo.image = dedicatedImage;
-
15044 allocInfo.pNext = &dedicatedAllocInfo;
-
-
-
15047 #endif // #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
-
-
-
15050 VkResult res = VK_SUCCESS;
-
15051 for(allocIndex = 0; allocIndex < allocationCount; ++allocIndex)
-
-
15053 res = AllocateDedicatedMemoryPage(
-
-
-
-
-
-
-
-
15061 pAllocations + allocIndex);
-
15062 if(res != VK_SUCCESS)
-
-
-
-
-
-
15068 if(res == VK_SUCCESS)
-
-
-
-
15072 VmaMutexLockWrite lock(m_DedicatedAllocationsMutex[memTypeIndex], m_UseMutex);
-
15073 AllocationVectorType* pDedicatedAllocations = m_pDedicatedAllocations[memTypeIndex];
-
15074 VMA_ASSERT(pDedicatedAllocations);
-
15075 for(allocIndex = 0; allocIndex < allocationCount; ++allocIndex)
-
-
15077 VmaVectorInsertSorted<VmaPointerLess>(*pDedicatedAllocations, pAllocations[allocIndex]);
-
-
-
-
15081 VMA_DEBUG_LOG(
" Allocated DedicatedMemory Count=%zu, MemoryTypeIndex=#%u", allocationCount, memTypeIndex);
-
-
-
-
-
15086 while(allocIndex--)
-
-
-
15089 VkDeviceMemory hMemory = currAlloc->GetMemory();
-
-
-
-
-
-
-
-
-
-
-
-
15101 FreeVulkanMemory(memTypeIndex, currAlloc->GetSize(), hMemory);
-
15102 m_Budget.RemoveAllocation(MemoryTypeIndexToHeapIndex(memTypeIndex), currAlloc->GetSize());
-
15103 currAlloc->SetUserData(
this, VMA_NULL);
-
-
15105 m_AllocationObjectAllocator.Free(currAlloc);
-
-
-
15108 memset(pAllocations, 0,
sizeof(
VmaAllocation) * allocationCount);
-
-
-
-
+
15043 VMA_ASSERT(dedicatedImage == VK_NULL_HANDLE);
+
15044 dedicatedAllocInfo.buffer = dedicatedBuffer;
+
15045 allocInfo.pNext = &dedicatedAllocInfo;
+
+
15047 else if(dedicatedImage != VK_NULL_HANDLE)
+
+
15049 dedicatedAllocInfo.image = dedicatedImage;
+
15050 allocInfo.pNext = &dedicatedAllocInfo;
+
+
+
15053 #endif // #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
+
+
+
15056 VkResult res = VK_SUCCESS;
+
15057 for(allocIndex = 0; allocIndex < allocationCount; ++allocIndex)
+
+
15059 res = AllocateDedicatedMemoryPage(
+
+
+
+
+
+
+
+
15067 pAllocations + allocIndex);
+
15068 if(res != VK_SUCCESS)
+
+
+
+
+
+
15074 if(res == VK_SUCCESS)
+
+
+
+
15078 VmaMutexLockWrite lock(m_DedicatedAllocationsMutex[memTypeIndex], m_UseMutex);
+
15079 AllocationVectorType* pDedicatedAllocations = m_pDedicatedAllocations[memTypeIndex];
+
15080 VMA_ASSERT(pDedicatedAllocations);
+
15081 for(allocIndex = 0; allocIndex < allocationCount; ++allocIndex)
+
+
15083 VmaVectorInsertSorted<VmaPointerLess>(*pDedicatedAllocations, pAllocations[allocIndex]);
+
+
+
+
15087 VMA_DEBUG_LOG(
" Allocated DedicatedMemory Count=%zu, MemoryTypeIndex=#%u", allocationCount, memTypeIndex);
+
+
+
+
+
15092 while(allocIndex--)
+
+
+
15095 VkDeviceMemory hMemory = currAlloc->GetMemory();
+
+
+
+
+
+
+
+
+
+
+
+
15107 FreeVulkanMemory(memTypeIndex, currAlloc->GetSize(), hMemory);
+
15108 m_Budget.RemoveAllocation(MemoryTypeIndexToHeapIndex(memTypeIndex), currAlloc->GetSize());
+
15109 currAlloc->SetUserData(
this, VMA_NULL);
+
+
15111 m_AllocationObjectAllocator.Free(currAlloc);
+
-
15114 VkResult VmaAllocator_T::AllocateDedicatedMemoryPage(
-
-
15116 VmaSuballocationType suballocType,
-
15117 uint32_t memTypeIndex,
-
15118 const VkMemoryAllocateInfo& allocInfo,
-
-
15120 bool isUserDataString,
-
-
-
-
15124 VkDeviceMemory hMemory = VK_NULL_HANDLE;
-
15125 VkResult res = AllocateVulkanMemory(&allocInfo, &hMemory);
-
-
-
15128 VMA_DEBUG_LOG(
" vkAllocateMemory FAILED");
-
-
-
-
15132 void* pMappedData = VMA_NULL;
-
-
-
15135 res = (*m_VulkanFunctions.vkMapMemory)(
-
-
-
-
-
-
-
-
-
15144 VMA_DEBUG_LOG(
" vkMapMemory FAILED");
-
15145 FreeVulkanMemory(memTypeIndex, size, hMemory);
-
-
-
-
-
15150 *pAllocation = m_AllocationObjectAllocator.Allocate();
-
15151 (*pAllocation)->Ctor(m_CurrentFrameIndex.load(), isUserDataString);
-
15152 (*pAllocation)->InitDedicatedAllocation(memTypeIndex, hMemory, suballocType, pMappedData, size);
-
15153 (*pAllocation)->SetUserData(
this, pUserData);
-
15154 m_Budget.AddAllocation(MemoryTypeIndexToHeapIndex(memTypeIndex), size);
-
15155 if(VMA_DEBUG_INITIALIZE_ALLOCATIONS)
-
-
15157 FillAllocation(*pAllocation, VMA_ALLOCATION_FILL_PATTERN_CREATED);
-
-
-
-
-
-
15163 void VmaAllocator_T::GetBufferMemoryRequirements(
-
-
15165 VkMemoryRequirements& memReq,
-
15166 bool& requiresDedicatedAllocation,
-
15167 bool& prefersDedicatedAllocation)
const
-
-
15169 #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
-
15170 if(m_UseKhrDedicatedAllocation || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
-
-
15172 VkBufferMemoryRequirementsInfo2KHR memReqInfo = { VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2_KHR };
-
15173 memReqInfo.buffer = hBuffer;
-
-
15175 VkMemoryDedicatedRequirementsKHR memDedicatedReq = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR };
-
-
15177 VkMemoryRequirements2KHR memReq2 = { VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR };
-
15178 memReq2.pNext = &memDedicatedReq;
-
-
15180 (*m_VulkanFunctions.vkGetBufferMemoryRequirements2KHR)(m_hDevice, &memReqInfo, &memReq2);
-
-
15182 memReq = memReq2.memoryRequirements;
-
15183 requiresDedicatedAllocation = (memDedicatedReq.requiresDedicatedAllocation != VK_FALSE);
-
15184 prefersDedicatedAllocation = (memDedicatedReq.prefersDedicatedAllocation != VK_FALSE);
-
-
-
15187 #endif // #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
-
-
15189 (*m_VulkanFunctions.vkGetBufferMemoryRequirements)(m_hDevice, hBuffer, &memReq);
-
15190 requiresDedicatedAllocation =
false;
-
15191 prefersDedicatedAllocation =
false;
-
-
-
-
15195 void VmaAllocator_T::GetImageMemoryRequirements(
-
-
15197 VkMemoryRequirements& memReq,
-
15198 bool& requiresDedicatedAllocation,
-
15199 bool& prefersDedicatedAllocation)
const
-
-
15201 #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
-
15202 if(m_UseKhrDedicatedAllocation || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
-
-
15204 VkImageMemoryRequirementsInfo2KHR memReqInfo = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2_KHR };
-
15205 memReqInfo.image = hImage;
-
-
15207 VkMemoryDedicatedRequirementsKHR memDedicatedReq = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR };
-
-
15209 VkMemoryRequirements2KHR memReq2 = { VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR };
-
15210 memReq2.pNext = &memDedicatedReq;
-
-
15212 (*m_VulkanFunctions.vkGetImageMemoryRequirements2KHR)(m_hDevice, &memReqInfo, &memReq2);
-
-
15214 memReq = memReq2.memoryRequirements;
-
15215 requiresDedicatedAllocation = (memDedicatedReq.requiresDedicatedAllocation != VK_FALSE);
-
15216 prefersDedicatedAllocation = (memDedicatedReq.prefersDedicatedAllocation != VK_FALSE);
-
-
-
15219 #endif // #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
-
-
15221 (*m_VulkanFunctions.vkGetImageMemoryRequirements)(m_hDevice, hImage, &memReq);
-
15222 requiresDedicatedAllocation =
false;
-
15223 prefersDedicatedAllocation =
false;
-
-
-
-
15227 VkResult VmaAllocator_T::AllocateMemory(
-
15228 const VkMemoryRequirements& vkMemReq,
-
15229 bool requiresDedicatedAllocation,
-
15230 bool prefersDedicatedAllocation,
-
15231 VkBuffer dedicatedBuffer,
-
15232 VkImage dedicatedImage,
-
-
15234 VmaSuballocationType suballocType,
-
15235 size_t allocationCount,
-
-
-
15238 memset(pAllocations, 0,
sizeof(
VmaAllocation) * allocationCount);
-
-
15240 VMA_ASSERT(VmaIsPow2(vkMemReq.alignment));
-
-
15242 if(vkMemReq.size == 0)
-
-
15244 return VK_ERROR_VALIDATION_FAILED_EXT;
-
-
-
-
-
15249 VMA_ASSERT(0 &&
"Specifying VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT together with VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT makes no sense.");
-
15250 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
15114 memset(pAllocations, 0,
sizeof(
VmaAllocation) * allocationCount);
+
+
+
+
+
+
15120 VkResult VmaAllocator_T::AllocateDedicatedMemoryPage(
+
+
15122 VmaSuballocationType suballocType,
+
15123 uint32_t memTypeIndex,
+
15124 const VkMemoryAllocateInfo& allocInfo,
+
+
15126 bool isUserDataString,
+
+
+
+
15130 VkDeviceMemory hMemory = VK_NULL_HANDLE;
+
15131 VkResult res = AllocateVulkanMemory(&allocInfo, &hMemory);
+
+
+
15134 VMA_DEBUG_LOG(
" vkAllocateMemory FAILED");
+
+
+
+
15138 void* pMappedData = VMA_NULL;
+
+
+
15141 res = (*m_VulkanFunctions.vkMapMemory)(
+
+
+
+
+
+
+
+
+
15150 VMA_DEBUG_LOG(
" vkMapMemory FAILED");
+
15151 FreeVulkanMemory(memTypeIndex, size, hMemory);
+
+
+
+
+
15156 *pAllocation = m_AllocationObjectAllocator.Allocate();
+
15157 (*pAllocation)->Ctor(m_CurrentFrameIndex.load(), isUserDataString);
+
15158 (*pAllocation)->InitDedicatedAllocation(memTypeIndex, hMemory, suballocType, pMappedData, size);
+
15159 (*pAllocation)->SetUserData(
this, pUserData);
+
15160 m_Budget.AddAllocation(MemoryTypeIndexToHeapIndex(memTypeIndex), size);
+
15161 if(VMA_DEBUG_INITIALIZE_ALLOCATIONS)
+
+
15163 FillAllocation(*pAllocation, VMA_ALLOCATION_FILL_PATTERN_CREATED);
+
+
+
+
+
+
15169 void VmaAllocator_T::GetBufferMemoryRequirements(
+
+
15171 VkMemoryRequirements& memReq,
+
15172 bool& requiresDedicatedAllocation,
+
15173 bool& prefersDedicatedAllocation)
const
+
+
15175 #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
+
15176 if(m_UseKhrDedicatedAllocation || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
+
+
15178 VkBufferMemoryRequirementsInfo2KHR memReqInfo = { VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2_KHR };
+
15179 memReqInfo.buffer = hBuffer;
+
+
15181 VkMemoryDedicatedRequirementsKHR memDedicatedReq = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR };
+
+
15183 VkMemoryRequirements2KHR memReq2 = { VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR };
+
15184 memReq2.pNext = &memDedicatedReq;
+
+
15186 (*m_VulkanFunctions.vkGetBufferMemoryRequirements2KHR)(m_hDevice, &memReqInfo, &memReq2);
+
+
15188 memReq = memReq2.memoryRequirements;
+
15189 requiresDedicatedAllocation = (memDedicatedReq.requiresDedicatedAllocation != VK_FALSE);
+
15190 prefersDedicatedAllocation = (memDedicatedReq.prefersDedicatedAllocation != VK_FALSE);
+
+
+
15193 #endif // #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
+
+
15195 (*m_VulkanFunctions.vkGetBufferMemoryRequirements)(m_hDevice, hBuffer, &memReq);
+
15196 requiresDedicatedAllocation =
false;
+
15197 prefersDedicatedAllocation =
false;
+
+
+
+
15201 void VmaAllocator_T::GetImageMemoryRequirements(
+
+
15203 VkMemoryRequirements& memReq,
+
15204 bool& requiresDedicatedAllocation,
+
15205 bool& prefersDedicatedAllocation)
const
+
+
15207 #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
+
15208 if(m_UseKhrDedicatedAllocation || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
+
+
15210 VkImageMemoryRequirementsInfo2KHR memReqInfo = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2_KHR };
+
15211 memReqInfo.image = hImage;
+
+
15213 VkMemoryDedicatedRequirementsKHR memDedicatedReq = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR };
+
+
15215 VkMemoryRequirements2KHR memReq2 = { VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR };
+
15216 memReq2.pNext = &memDedicatedReq;
+
+
15218 (*m_VulkanFunctions.vkGetImageMemoryRequirements2KHR)(m_hDevice, &memReqInfo, &memReq2);
+
+
15220 memReq = memReq2.memoryRequirements;
+
15221 requiresDedicatedAllocation = (memDedicatedReq.requiresDedicatedAllocation != VK_FALSE);
+
15222 prefersDedicatedAllocation = (memDedicatedReq.prefersDedicatedAllocation != VK_FALSE);
+
+
+
15225 #endif // #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
+
+
15227 (*m_VulkanFunctions.vkGetImageMemoryRequirements)(m_hDevice, hImage, &memReq);
+
15228 requiresDedicatedAllocation =
false;
+
15229 prefersDedicatedAllocation =
false;
+
+
+
+
15233 VkResult VmaAllocator_T::AllocateMemory(
+
15234 const VkMemoryRequirements& vkMemReq,
+
15235 bool requiresDedicatedAllocation,
+
15236 bool prefersDedicatedAllocation,
+
15237 VkBuffer dedicatedBuffer,
+
15238 VkImage dedicatedImage,
+
+
15240 VmaSuballocationType suballocType,
+
15241 size_t allocationCount,
+
+
+
15244 memset(pAllocations, 0,
sizeof(
VmaAllocation) * allocationCount);
+
+
15246 VMA_ASSERT(VmaIsPow2(vkMemReq.alignment));
+
+
15248 if(vkMemReq.size == 0)
+
+
15250 return VK_ERROR_VALIDATION_FAILED_EXT;
-
-
+
+
-
15255 VMA_ASSERT(0 &&
"Specifying VMA_ALLOCATION_CREATE_MAPPED_BIT together with VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT is invalid.");
+
15255 VMA_ASSERT(0 &&
"Specifying VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT together with VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT makes no sense.");
15256 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
-
15258 if(requiresDedicatedAllocation)
-
-
-
-
15262 VMA_ASSERT(0 &&
"VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT specified while dedicated allocation is required.");
-
15263 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
-
-
15265 if(createInfo.
pool != VK_NULL_HANDLE)
-
-
15267 VMA_ASSERT(0 &&
"Pool specified while dedicated allocation is required.");
-
15268 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
-
-
-
15271 if((createInfo.
pool != VK_NULL_HANDLE) &&
-
-
-
15274 VMA_ASSERT(0 &&
"Specifying VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT when pool != null is invalid.");
-
15275 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
+
+
+
15261 VMA_ASSERT(0 &&
"Specifying VMA_ALLOCATION_CREATE_MAPPED_BIT together with VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT is invalid.");
+
15262 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
+
15264 if(requiresDedicatedAllocation)
+
+
+
+
15268 VMA_ASSERT(0 &&
"VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT specified while dedicated allocation is required.");
+
15269 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
+
15271 if(createInfo.
pool != VK_NULL_HANDLE)
+
+
15273 VMA_ASSERT(0 &&
"Pool specified while dedicated allocation is required.");
+
15274 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
-
-
15278 if(createInfo.
pool != VK_NULL_HANDLE)
+
15277 if((createInfo.
pool != VK_NULL_HANDLE) &&
+
-
15280 const VkDeviceSize alignmentForPool = VMA_MAX(
-
15281 vkMemReq.alignment,
-
15282 GetMemoryTypeMinAlignment(createInfo.
pool->m_BlockVector.GetMemoryTypeIndex()));
+
15280 VMA_ASSERT(0 &&
"Specifying VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT when pool != null is invalid.");
+
15281 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
-
-
-
-
15287 (m_MemProps.memoryTypes[createInfo.
pool->m_BlockVector.GetMemoryTypeIndex()].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
-
-
-
-
-
15292 return createInfo.
pool->m_BlockVector.Allocate(
-
15293 m_CurrentFrameIndex.load(),
-
-
-
-
-
-
-
-
-
-
-
15304 uint32_t memoryTypeBits = vkMemReq.memoryTypeBits;
-
15305 uint32_t memTypeIndex = UINT32_MAX;
-
-
15307 if(res == VK_SUCCESS)
-
-
15309 VkDeviceSize alignmentForMemType = VMA_MAX(
-
15310 vkMemReq.alignment,
-
15311 GetMemoryTypeMinAlignment(memTypeIndex));
-
-
15313 res = AllocateMemoryOfType(
-
-
15315 alignmentForMemType,
-
15316 requiresDedicatedAllocation || prefersDedicatedAllocation,
-
-
-
-
-
-
-
-
-
15325 if(res == VK_SUCCESS)
-
-
-
-
-
-
-
-
-
-
15335 memoryTypeBits &= ~(1u << memTypeIndex);
-
-
-
15338 if(res == VK_SUCCESS)
-
-
15340 alignmentForMemType = VMA_MAX(
-
15341 vkMemReq.alignment,
-
15342 GetMemoryTypeMinAlignment(memTypeIndex));
-
-
15344 res = AllocateMemoryOfType(
-
-
15346 alignmentForMemType,
-
15347 requiresDedicatedAllocation || prefersDedicatedAllocation,
-
-
-
-
-
-
-
-
-
15356 if(res == VK_SUCCESS)
-
-
-
-
-
-
-
-
-
-
15366 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
15284 if(createInfo.
pool != VK_NULL_HANDLE)
+
+
15286 const VkDeviceSize alignmentForPool = VMA_MAX(
+
15287 vkMemReq.alignment,
+
15288 GetMemoryTypeMinAlignment(createInfo.
pool->m_BlockVector.GetMemoryTypeIndex()));
+
+
+
+
+
15293 (m_MemProps.memoryTypes[createInfo.
pool->m_BlockVector.GetMemoryTypeIndex()].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
+
+
+
+
+
15298 return createInfo.
pool->m_BlockVector.Allocate(
+
15299 m_CurrentFrameIndex.load(),
+
+
+
+
+
+
+
+
+
+
+
15310 uint32_t memoryTypeBits = vkMemReq.memoryTypeBits;
+
15311 uint32_t memTypeIndex = UINT32_MAX;
+
+
15313 if(res == VK_SUCCESS)
+
+
15315 VkDeviceSize alignmentForMemType = VMA_MAX(
+
15316 vkMemReq.alignment,
+
15317 GetMemoryTypeMinAlignment(memTypeIndex));
+
+
15319 res = AllocateMemoryOfType(
+
+
15321 alignmentForMemType,
+
15322 requiresDedicatedAllocation || prefersDedicatedAllocation,
+
+
+
+
+
+
+
+
+
15331 if(res == VK_SUCCESS)
+
+
+
+
+
+
+
+
+
+
15341 memoryTypeBits &= ~(1u << memTypeIndex);
+
+
+
15344 if(res == VK_SUCCESS)
+
+
15346 alignmentForMemType = VMA_MAX(
+
15347 vkMemReq.alignment,
+
15348 GetMemoryTypeMinAlignment(memTypeIndex));
+
+
15350 res = AllocateMemoryOfType(
+
+
15352 alignmentForMemType,
+
15353 requiresDedicatedAllocation || prefersDedicatedAllocation,
+
+
+
+
+
+
+
+
+
15362 if(res == VK_SUCCESS)
+
+
+
+
-
-
-
-
-
-
-
-
-
-
15377 void VmaAllocator_T::FreeMemory(
-
15378 size_t allocationCount,
-
-
-
15381 VMA_ASSERT(pAllocations);
+
+
+
+
+
15372 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
+
+
+
+
+
+
+
+
-
15383 for(
size_t allocIndex = allocationCount; allocIndex--; )
-
-
-
-
15387 if(allocation != VK_NULL_HANDLE)
-
-
15389 if(TouchAllocation(allocation))
-
-
15391 if(VMA_DEBUG_INITIALIZE_ALLOCATIONS)
-
-
15393 FillAllocation(allocation, VMA_ALLOCATION_FILL_PATTERN_DESTROYED);
-
-
-
15396 switch(allocation->GetType())
-
-
15398 case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
-
-
15400 VmaBlockVector* pBlockVector = VMA_NULL;
-
15401 VmaPool hPool = allocation->GetBlock()->GetParentPool();
-
15402 if(hPool != VK_NULL_HANDLE)
-
-
15404 pBlockVector = &hPool->m_BlockVector;
-
-
-
-
15408 const uint32_t memTypeIndex = allocation->GetMemoryTypeIndex();
-
15409 pBlockVector = m_pBlockVectors[memTypeIndex];
-
-
15411 pBlockVector->Free(allocation);
-
-
-
15414 case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
-
15415 FreeDedicatedMemory(allocation);
-
-
-
-
-
-
-
-
15423 m_Budget.RemoveAllocation(MemoryTypeIndexToHeapIndex(allocation->GetMemoryTypeIndex()), allocation->GetSize());
-
15424 allocation->SetUserData(
this, VMA_NULL);
-
15425 allocation->Dtor();
-
15426 m_AllocationObjectAllocator.Free(allocation);
-
-
-
-
-
15431 VkResult VmaAllocator_T::ResizeAllocation(
-
-
15433 VkDeviceSize newSize)
-
-
-
15436 if(newSize == 0 || alloc->GetLastUseFrameIndex() == VMA_FRAME_INDEX_LOST)
-
-
15438 return VK_ERROR_VALIDATION_FAILED_EXT;
-
-
15440 if(newSize == alloc->GetSize())
-
-
-
-
15444 return VK_ERROR_OUT_OF_POOL_MEMORY;
-
-
-
15447 void VmaAllocator_T::CalculateStats(
VmaStats* pStats)
-
-
-
15450 InitStatInfo(pStats->
total);
-
15451 for(
size_t i = 0; i < VK_MAX_MEMORY_TYPES; ++i)
-
-
15453 for(
size_t i = 0; i < VK_MAX_MEMORY_HEAPS; ++i)
-
-
-
-
15457 for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
-
-
15459 VmaBlockVector*
const pBlockVector = m_pBlockVectors[memTypeIndex];
-
15460 VMA_ASSERT(pBlockVector);
-
15461 pBlockVector->AddStats(pStats);
-
-
-
-
-
15466 VmaMutexLockRead lock(m_PoolsMutex, m_UseMutex);
-
15467 for(
size_t poolIndex = 0, poolCount = m_Pools.size(); poolIndex < poolCount; ++poolIndex)
-
-
15469 m_Pools[poolIndex]->m_BlockVector.AddStats(pStats);
-
-
-
-
-
15474 for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
-
-
15476 const uint32_t memHeapIndex = MemoryTypeIndexToHeapIndex(memTypeIndex);
-
15477 VmaMutexLockRead dedicatedAllocationsLock(m_DedicatedAllocationsMutex[memTypeIndex], m_UseMutex);
-
15478 AllocationVectorType*
const pDedicatedAllocVector = m_pDedicatedAllocations[memTypeIndex];
-
15479 VMA_ASSERT(pDedicatedAllocVector);
-
15480 for(
size_t allocIndex = 0, allocCount = pDedicatedAllocVector->size(); allocIndex < allocCount; ++allocIndex)
-
-
-
15483 (*pDedicatedAllocVector)[allocIndex]->DedicatedAllocCalcStatsInfo(allocationStatInfo);
-
15484 VmaAddStatInfo(pStats->
total, allocationStatInfo);
-
15485 VmaAddStatInfo(pStats->
memoryType[memTypeIndex], allocationStatInfo);
-
15486 VmaAddStatInfo(pStats->
memoryHeap[memHeapIndex], allocationStatInfo);
-
-
-
-
-
15491 VmaPostprocessCalcStatInfo(pStats->
total);
-
15492 for(
size_t i = 0; i < GetMemoryTypeCount(); ++i)
-
15493 VmaPostprocessCalcStatInfo(pStats->
memoryType[i]);
-
15494 for(
size_t i = 0; i < GetMemoryHeapCount(); ++i)
-
15495 VmaPostprocessCalcStatInfo(pStats->
memoryHeap[i]);
-
-
-
15498 void VmaAllocator_T::GetBudget(
VmaBudget* outBudget, uint32_t firstHeap, uint32_t heapCount)
-
-
15500 #if VMA_MEMORY_BUDGET
-
15501 if(m_UseExtMemoryBudget)
-
-
15503 if(m_Budget.m_OperationsSinceBudgetFetch < 30)
-
-
15505 VmaMutexLockRead lockRead(m_Budget.m_BudgetMutex, m_UseMutex);
-
15506 for(uint32_t i = 0; i < heapCount; ++i, ++outBudget)
-
-
15508 const uint32_t heapIndex = firstHeap + i;
-
-
15510 outBudget->
blockBytes = m_Budget.m_BlockBytes[heapIndex];
-
-
-
15513 if(m_Budget.m_VulkanUsage[heapIndex] + outBudget->
blockBytes > m_Budget.m_BlockBytesAtBudgetFetch[heapIndex])
-
-
15515 outBudget->
usage = m_Budget.m_VulkanUsage[heapIndex] +
-
15516 outBudget->
blockBytes - m_Budget.m_BlockBytesAtBudgetFetch[heapIndex];
-
-
-
-
15520 outBudget->
usage = 0;
-
-
-
-
15524 outBudget->
budget = VMA_MIN(
-
15525 m_Budget.m_VulkanBudget[heapIndex], m_MemProps.memoryHeaps[heapIndex].size);
-
-
-
-
-
15530 UpdateVulkanBudget();
-
15531 GetBudget(outBudget, firstHeap, heapCount);
-
-
-
-
-
-
15537 for(uint32_t i = 0; i < heapCount; ++i, ++outBudget)
-
-
15539 const uint32_t heapIndex = firstHeap + i;
-
-
15541 outBudget->
blockBytes = m_Budget.m_BlockBytes[heapIndex];
-
-
-
-
15545 outBudget->
budget = m_MemProps.memoryHeaps[heapIndex].size * 8 / 10;
-
-
-
+
15383 void VmaAllocator_T::FreeMemory(
+
15384 size_t allocationCount,
+
+
+
15387 VMA_ASSERT(pAllocations);
+
+
15389 for(
size_t allocIndex = allocationCount; allocIndex--; )
+
+
+
+
15393 if(allocation != VK_NULL_HANDLE)
+
+
15395 if(TouchAllocation(allocation))
+
+
15397 if(VMA_DEBUG_INITIALIZE_ALLOCATIONS)
+
+
15399 FillAllocation(allocation, VMA_ALLOCATION_FILL_PATTERN_DESTROYED);
+
+
+
15402 switch(allocation->GetType())
+
+
15404 case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
+
+
15406 VmaBlockVector* pBlockVector = VMA_NULL;
+
15407 VmaPool hPool = allocation->GetBlock()->GetParentPool();
+
15408 if(hPool != VK_NULL_HANDLE)
+
+
15410 pBlockVector = &hPool->m_BlockVector;
+
+
+
+
15414 const uint32_t memTypeIndex = allocation->GetMemoryTypeIndex();
+
15415 pBlockVector = m_pBlockVectors[memTypeIndex];
+
+
15417 pBlockVector->Free(allocation);
+
+
+
15420 case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
+
15421 FreeDedicatedMemory(allocation);
+
+
+
+
+
+
+
+
15429 m_Budget.RemoveAllocation(MemoryTypeIndexToHeapIndex(allocation->GetMemoryTypeIndex()), allocation->GetSize());
+
15430 allocation->SetUserData(
this, VMA_NULL);
+
15431 allocation->Dtor();
+
15432 m_AllocationObjectAllocator.Free(allocation);
+
+
+
+
+
15437 VkResult VmaAllocator_T::ResizeAllocation(
+
+
15439 VkDeviceSize newSize)
+
+
+
15442 if(newSize == 0 || alloc->GetLastUseFrameIndex() == VMA_FRAME_INDEX_LOST)
+
+
15444 return VK_ERROR_VALIDATION_FAILED_EXT;
+
+
15446 if(newSize == alloc->GetSize())
+
+
+
+
15450 return VK_ERROR_OUT_OF_POOL_MEMORY;
+
+
+
15453 void VmaAllocator_T::CalculateStats(
VmaStats* pStats)
+
+
+
15456 InitStatInfo(pStats->
total);
+
15457 for(
size_t i = 0; i < VK_MAX_MEMORY_TYPES; ++i)
+
+
15459 for(
size_t i = 0; i < VK_MAX_MEMORY_HEAPS; ++i)
+
+
+
+
15463 for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
+
+
15465 VmaBlockVector*
const pBlockVector = m_pBlockVectors[memTypeIndex];
+
15466 VMA_ASSERT(pBlockVector);
+
15467 pBlockVector->AddStats(pStats);
+
+
+
+
+
15472 VmaMutexLockRead lock(m_PoolsMutex, m_UseMutex);
+
15473 for(
size_t poolIndex = 0, poolCount = m_Pools.size(); poolIndex < poolCount; ++poolIndex)
+
+
15475 m_Pools[poolIndex]->m_BlockVector.AddStats(pStats);
+
+
+
+
+
15480 for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
+
+
15482 const uint32_t memHeapIndex = MemoryTypeIndexToHeapIndex(memTypeIndex);
+
15483 VmaMutexLockRead dedicatedAllocationsLock(m_DedicatedAllocationsMutex[memTypeIndex], m_UseMutex);
+
15484 AllocationVectorType*
const pDedicatedAllocVector = m_pDedicatedAllocations[memTypeIndex];
+
15485 VMA_ASSERT(pDedicatedAllocVector);
+
15486 for(
size_t allocIndex = 0, allocCount = pDedicatedAllocVector->size(); allocIndex < allocCount; ++allocIndex)
+
+
+
15489 (*pDedicatedAllocVector)[allocIndex]->DedicatedAllocCalcStatsInfo(allocationStatInfo);
+
15490 VmaAddStatInfo(pStats->
total, allocationStatInfo);
+
15491 VmaAddStatInfo(pStats->
memoryType[memTypeIndex], allocationStatInfo);
+
15492 VmaAddStatInfo(pStats->
memoryHeap[memHeapIndex], allocationStatInfo);
+
+
+
+
+
15497 VmaPostprocessCalcStatInfo(pStats->
total);
+
15498 for(
size_t i = 0; i < GetMemoryTypeCount(); ++i)
+
15499 VmaPostprocessCalcStatInfo(pStats->
memoryType[i]);
+
15500 for(
size_t i = 0; i < GetMemoryHeapCount(); ++i)
+
15501 VmaPostprocessCalcStatInfo(pStats->
memoryHeap[i]);
+
+
+
15504 void VmaAllocator_T::GetBudget(
VmaBudget* outBudget, uint32_t firstHeap, uint32_t heapCount)
+
+
15506 #if VMA_MEMORY_BUDGET
+
15507 if(m_UseExtMemoryBudget)
+
+
15509 if(m_Budget.m_OperationsSinceBudgetFetch < 30)
+
+
15511 VmaMutexLockRead lockRead(m_Budget.m_BudgetMutex, m_UseMutex);
+
15512 for(uint32_t i = 0; i < heapCount; ++i, ++outBudget)
+
+
15514 const uint32_t heapIndex = firstHeap + i;
+
+
15516 outBudget->
blockBytes = m_Budget.m_BlockBytes[heapIndex];
+
+
+
15519 if(m_Budget.m_VulkanUsage[heapIndex] + outBudget->
blockBytes > m_Budget.m_BlockBytesAtBudgetFetch[heapIndex])
+
+
15521 outBudget->
usage = m_Budget.m_VulkanUsage[heapIndex] +
+
15522 outBudget->
blockBytes - m_Budget.m_BlockBytesAtBudgetFetch[heapIndex];
+
+
+
+
15526 outBudget->
usage = 0;
+
+
+
+
15530 outBudget->
budget = VMA_MIN(
+
15531 m_Budget.m_VulkanBudget[heapIndex], m_MemProps.memoryHeaps[heapIndex].size);
+
+
+
+
+
15536 UpdateVulkanBudget();
+
15537 GetBudget(outBudget, firstHeap, heapCount);
+
+
+
+
+
+
15543 for(uint32_t i = 0; i < heapCount; ++i, ++outBudget)
+
+
15545 const uint32_t heapIndex = firstHeap + i;
+
+
15547 outBudget->
blockBytes = m_Budget.m_BlockBytes[heapIndex];
+
-
15550 static const uint32_t VMA_VENDOR_ID_AMD = 4098;
-
-
15552 VkResult VmaAllocator_T::DefragmentationBegin(
-
-
-
-
-
-
-
-
-
-
15562 *pContext = vma_new(
this, VmaDefragmentationContext_T)(
-
15563 this, m_CurrentFrameIndex.load(), info.
flags, pStats);
-
-
-
15566 (*pContext)->AddAllocations(
-
-
-
15569 VkResult res = (*pContext)->Defragment(
-
-
-
-
-
15574 if(res != VK_NOT_READY)
-
-
15576 vma_delete(
this, *pContext);
-
15577 *pContext = VMA_NULL;
-
+
+
15551 outBudget->
budget = m_MemProps.memoryHeaps[heapIndex].size * 8 / 10;
+
+
+
+
+
15556 static const uint32_t VMA_VENDOR_ID_AMD = 4098;
+
+
15558 VkResult VmaAllocator_T::DefragmentationBegin(
+
+
+
+
+
+
+
+
+
+
15568 *pContext = vma_new(
this, VmaDefragmentationContext_T)(
+
15569 this, m_CurrentFrameIndex.load(), info.
flags, pStats);
+
+
+
15572 (*pContext)->AddAllocations(
+
+
+
15575 VkResult res = (*pContext)->Defragment(
+
+
+
-
-
-
-
15583 VkResult VmaAllocator_T::DefragmentationEnd(
-
-
-
15586 vma_delete(
this, context);
-
-
-
-
+
15580 if(res != VK_NOT_READY)
+
+
15582 vma_delete(
this, *pContext);
+
15583 *pContext = VMA_NULL;
+
+
+
+
+
+
15589 VkResult VmaAllocator_T::DefragmentationEnd(
+
-
15592 if(hAllocation->CanBecomeLost())
-
-
-
-
-
-
15598 const uint32_t localCurrFrameIndex = m_CurrentFrameIndex.load();
-
15599 uint32_t localLastUseFrameIndex = hAllocation->GetLastUseFrameIndex();
-
-
-
15602 if(localLastUseFrameIndex == VMA_FRAME_INDEX_LOST)
-
-
-
-
15606 pAllocationInfo->
offset = 0;
-
15607 pAllocationInfo->
size = hAllocation->GetSize();
-
-
15609 pAllocationInfo->
pUserData = hAllocation->GetUserData();
-
-
-
15612 else if(localLastUseFrameIndex == localCurrFrameIndex)
-
-
15614 pAllocationInfo->
memoryType = hAllocation->GetMemoryTypeIndex();
-
15615 pAllocationInfo->
deviceMemory = hAllocation->GetMemory();
-
15616 pAllocationInfo->
offset = hAllocation->GetOffset();
-
15617 pAllocationInfo->
size = hAllocation->GetSize();
-
-
15619 pAllocationInfo->
pUserData = hAllocation->GetUserData();
-
-
-
-
-
15624 if(hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex))
-
-
15626 localLastUseFrameIndex = localCurrFrameIndex;
-
-
-
-
-
-
-
15633 #if VMA_STATS_STRING_ENABLED
-
15634 uint32_t localCurrFrameIndex = m_CurrentFrameIndex.load();
-
15635 uint32_t localLastUseFrameIndex = hAllocation->GetLastUseFrameIndex();
-
-
-
15638 VMA_ASSERT(localLastUseFrameIndex != VMA_FRAME_INDEX_LOST);
-
15639 if(localLastUseFrameIndex == localCurrFrameIndex)
-
-
-
-
-
-
15645 if(hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex))
-
-
15647 localLastUseFrameIndex = localCurrFrameIndex;
-
-
-
-
-
-
15653 pAllocationInfo->
memoryType = hAllocation->GetMemoryTypeIndex();
-
15654 pAllocationInfo->
deviceMemory = hAllocation->GetMemory();
-
15655 pAllocationInfo->
offset = hAllocation->GetOffset();
-
15656 pAllocationInfo->
size = hAllocation->GetSize();
-
15657 pAllocationInfo->
pMappedData = hAllocation->GetMappedData();
-
15658 pAllocationInfo->
pUserData = hAllocation->GetUserData();
-
-
-
-
15662 bool VmaAllocator_T::TouchAllocation(
VmaAllocation hAllocation)
-
-
-
15665 if(hAllocation->CanBecomeLost())
-
-
15667 uint32_t localCurrFrameIndex = m_CurrentFrameIndex.load();
-
15668 uint32_t localLastUseFrameIndex = hAllocation->GetLastUseFrameIndex();
-
-
-
15671 if(localLastUseFrameIndex == VMA_FRAME_INDEX_LOST)
-
-
-
-
15675 else if(localLastUseFrameIndex == localCurrFrameIndex)
-
-
-
-
-
-
15681 if(hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex))
-
-
15683 localLastUseFrameIndex = localCurrFrameIndex;
-
-
-
-
-
-
-
15690 #if VMA_STATS_STRING_ENABLED
-
15691 uint32_t localCurrFrameIndex = m_CurrentFrameIndex.load();
-
15692 uint32_t localLastUseFrameIndex = hAllocation->GetLastUseFrameIndex();
-
-
-
15695 VMA_ASSERT(localLastUseFrameIndex != VMA_FRAME_INDEX_LOST);
-
15696 if(localLastUseFrameIndex == localCurrFrameIndex)
-
-
-
-
-
-
15702 if(hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex))
-
-
15704 localLastUseFrameIndex = localCurrFrameIndex;
-
-
-
-
-
-
-
-
-
-
-
-
15716 VMA_DEBUG_LOG(
" CreatePool: MemoryTypeIndex=%u, flags=%u", pCreateInfo->
memoryTypeIndex, pCreateInfo->
flags);
-
-
+
15592 vma_delete(
this, context);
+
+
+
+
+
+
15598 if(hAllocation->CanBecomeLost())
+
+
+
+
+
+
15604 const uint32_t localCurrFrameIndex = m_CurrentFrameIndex.load();
+
15605 uint32_t localLastUseFrameIndex = hAllocation->GetLastUseFrameIndex();
+
+
+
15608 if(localLastUseFrameIndex == VMA_FRAME_INDEX_LOST)
+
+
+
+
15612 pAllocationInfo->
offset = 0;
+
15613 pAllocationInfo->
size = hAllocation->GetSize();
+
+
15615 pAllocationInfo->
pUserData = hAllocation->GetUserData();
+
+
+
15618 else if(localLastUseFrameIndex == localCurrFrameIndex)
+
+
15620 pAllocationInfo->
memoryType = hAllocation->GetMemoryTypeIndex();
+
15621 pAllocationInfo->
deviceMemory = hAllocation->GetMemory();
+
15622 pAllocationInfo->
offset = hAllocation->GetOffset();
+
15623 pAllocationInfo->
size = hAllocation->GetSize();
+
+
15625 pAllocationInfo->
pUserData = hAllocation->GetUserData();
+
+
+
+
+
15630 if(hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex))
+
+
15632 localLastUseFrameIndex = localCurrFrameIndex;
+
+
+
+
+
+
+
15639 #if VMA_STATS_STRING_ENABLED
+
15640 uint32_t localCurrFrameIndex = m_CurrentFrameIndex.load();
+
15641 uint32_t localLastUseFrameIndex = hAllocation->GetLastUseFrameIndex();
+
+
+
15644 VMA_ASSERT(localLastUseFrameIndex != VMA_FRAME_INDEX_LOST);
+
15645 if(localLastUseFrameIndex == localCurrFrameIndex)
+
+
+
+
+
+
15651 if(hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex))
+
+
15653 localLastUseFrameIndex = localCurrFrameIndex;
+
+
+
+
+
+
15659 pAllocationInfo->
memoryType = hAllocation->GetMemoryTypeIndex();
+
15660 pAllocationInfo->
deviceMemory = hAllocation->GetMemory();
+
15661 pAllocationInfo->
offset = hAllocation->GetOffset();
+
15662 pAllocationInfo->
size = hAllocation->GetSize();
+
15663 pAllocationInfo->
pMappedData = hAllocation->GetMappedData();
+
15664 pAllocationInfo->
pUserData = hAllocation->GetUserData();
+
+
+
+
15668 bool VmaAllocator_T::TouchAllocation(
VmaAllocation hAllocation)
+
+
+
15671 if(hAllocation->CanBecomeLost())
+
+
15673 uint32_t localCurrFrameIndex = m_CurrentFrameIndex.load();
+
15674 uint32_t localLastUseFrameIndex = hAllocation->GetLastUseFrameIndex();
+
+
+
15677 if(localLastUseFrameIndex == VMA_FRAME_INDEX_LOST)
+
+
+
+
15681 else if(localLastUseFrameIndex == localCurrFrameIndex)
+
+
+
+
+
+
15687 if(hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex))
+
+
15689 localLastUseFrameIndex = localCurrFrameIndex;
+
+
+
+
+
+
+
15696 #if VMA_STATS_STRING_ENABLED
+
15697 uint32_t localCurrFrameIndex = m_CurrentFrameIndex.load();
+
15698 uint32_t localLastUseFrameIndex = hAllocation->GetLastUseFrameIndex();
+
+
+
15701 VMA_ASSERT(localLastUseFrameIndex != VMA_FRAME_INDEX_LOST);
+
15702 if(localLastUseFrameIndex == localCurrFrameIndex)
+
+
+
+
+
+
15708 if(hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex))
+
+
15710 localLastUseFrameIndex = localCurrFrameIndex;
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
15726 return VK_ERROR_INITIALIZATION_FAILED;
-
-
-
15729 const VkDeviceSize preferredBlockSize = CalcPreferredBlockSize(newCreateInfo.
memoryTypeIndex);
-
-
15731 *pPool = vma_new(
this, VmaPool_T)(
this, newCreateInfo, preferredBlockSize);
-
-
15733 VkResult res = (*pPool)->m_BlockVector.CreateMinBlocks();
-
15734 if(res != VK_SUCCESS)
-
-
15736 vma_delete(
this, *pPool);
-
-
-
-
-
-
-
15743 VmaMutexLockWrite lock(m_PoolsMutex, m_UseMutex);
-
15744 (*pPool)->SetId(m_NextPoolId++);
-
15745 VmaVectorInsertSorted<VmaPointerLess>(m_Pools, *pPool);
-
-
-
-
-
-
15751 void VmaAllocator_T::DestroyPool(
VmaPool pool)
-
-
-
-
15755 VmaMutexLockWrite lock(m_PoolsMutex, m_UseMutex);
-
15756 bool success = VmaVectorRemoveSorted<VmaPointerLess>(m_Pools, pool);
-
15757 VMA_ASSERT(success &&
"Pool not found in Allocator.");
-
-
-
15760 vma_delete(
this, pool);
-
-
-
-
-
15765 pool->m_BlockVector.GetPoolStats(pPoolStats);
-
-
-
15768 void VmaAllocator_T::SetCurrentFrameIndex(uint32_t frameIndex)
-
-
15770 m_CurrentFrameIndex.store(frameIndex);
-
-
15772 #if VMA_MEMORY_BUDGET
-
15773 if(m_UseExtMemoryBudget)
-
-
15775 UpdateVulkanBudget();
-
-
15777 #endif // #if VMA_MEMORY_BUDGET
-
-
-
15780 void VmaAllocator_T::MakePoolAllocationsLost(
-
-
15782 size_t* pLostAllocationCount)
-
-
15784 hPool->m_BlockVector.MakePoolAllocationsLost(
-
15785 m_CurrentFrameIndex.load(),
-
15786 pLostAllocationCount);
-
-
-
15789 VkResult VmaAllocator_T::CheckPoolCorruption(
VmaPool hPool)
-
-
15791 return hPool->m_BlockVector.CheckCorruption();
-
-
-
15794 VkResult VmaAllocator_T::CheckCorruption(uint32_t memoryTypeBits)
-
-
15796 VkResult finalRes = VK_ERROR_FEATURE_NOT_PRESENT;
-
-
-
15799 for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
-
-
15801 if(((1u << memTypeIndex) & memoryTypeBits) != 0)
-
-
15803 VmaBlockVector*
const pBlockVector = m_pBlockVectors[memTypeIndex];
-
15804 VMA_ASSERT(pBlockVector);
-
15805 VkResult localRes = pBlockVector->CheckCorruption();
-
-
-
15808 case VK_ERROR_FEATURE_NOT_PRESENT:
-
-
-
15811 finalRes = VK_SUCCESS;
-
-
-
-
-
-
-
-
-
-
15821 VmaMutexLockRead lock(m_PoolsMutex, m_UseMutex);
-
15822 for(
size_t poolIndex = 0, poolCount = m_Pools.size(); poolIndex < poolCount; ++poolIndex)
-
-
15824 if(((1u << m_Pools[poolIndex]->m_BlockVector.GetMemoryTypeIndex()) & memoryTypeBits) != 0)
-
-
15826 VkResult localRes = m_Pools[poolIndex]->m_BlockVector.CheckCorruption();
-
-
-
15829 case VK_ERROR_FEATURE_NOT_PRESENT:
-
-
-
15832 finalRes = VK_SUCCESS;
-
-
-
-
-
-
-
-
-
-
-
-
15844 void VmaAllocator_T::CreateLostAllocation(
VmaAllocation* pAllocation)
-
-
15846 *pAllocation = m_AllocationObjectAllocator.Allocate();
-
15847 (*pAllocation)->Ctor(VMA_FRAME_INDEX_LOST,
false);
-
15848 (*pAllocation)->InitLost();
-
-
-
15851 VkResult VmaAllocator_T::AllocateVulkanMemory(
const VkMemoryAllocateInfo* pAllocateInfo, VkDeviceMemory* pMemory)
-
-
15853 const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(pAllocateInfo->memoryTypeIndex);
-
-
-
15856 if((m_HeapSizeLimitMask & (1u << heapIndex)) != 0)
-
-
15858 const VkDeviceSize heapSize = m_MemProps.memoryHeaps[heapIndex].size;
-
15859 VkDeviceSize blockBytes = m_Budget.m_BlockBytes[heapIndex];
-
-
-
15862 const VkDeviceSize blockBytesAfterAllocation = blockBytes + pAllocateInfo->allocationSize;
-
15863 if(blockBytesAfterAllocation > heapSize)
-
-
15865 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
-
-
15867 if(m_Budget.m_BlockBytes->compare_exchange_strong(blockBytes, blockBytesAfterAllocation))
-
-
-
-
-
-
-
-
15875 m_Budget.m_BlockBytes[heapIndex] += pAllocateInfo->allocationSize;
-
-
-
-
15879 VkResult res = (*m_VulkanFunctions.vkAllocateMemory)(m_hDevice, pAllocateInfo, GetAllocationCallbacks(), pMemory);
-
-
15881 if(res == VK_SUCCESS)
-
-
15883 #if VMA_MEMORY_BUDGET
-
15884 ++m_Budget.m_OperationsSinceBudgetFetch;
-
+
+
+
15722 VMA_DEBUG_LOG(
" CreatePool: MemoryTypeIndex=%u, flags=%u", pCreateInfo->
memoryTypeIndex, pCreateInfo->
flags);
+
+
+
+
+
+
+
+
+
+
15732 return VK_ERROR_INITIALIZATION_FAILED;
+
+
+
15735 const VkDeviceSize preferredBlockSize = CalcPreferredBlockSize(newCreateInfo.
memoryTypeIndex);
+
+
15737 *pPool = vma_new(
this, VmaPool_T)(
this, newCreateInfo, preferredBlockSize);
+
+
15739 VkResult res = (*pPool)->m_BlockVector.CreateMinBlocks();
+
15740 if(res != VK_SUCCESS)
+
+
15742 vma_delete(
this, *pPool);
+
+
+
+
+
+
+
15749 VmaMutexLockWrite lock(m_PoolsMutex, m_UseMutex);
+
15750 (*pPool)->SetId(m_NextPoolId++);
+
15751 VmaVectorInsertSorted<VmaPointerLess>(m_Pools, *pPool);
+
+
+
+
+
+
15757 void VmaAllocator_T::DestroyPool(
VmaPool pool)
+
+
+
+
15761 VmaMutexLockWrite lock(m_PoolsMutex, m_UseMutex);
+
15762 bool success = VmaVectorRemoveSorted<VmaPointerLess>(m_Pools, pool);
+
15763 VMA_ASSERT(success &&
"Pool not found in Allocator.");
+
+
+
15766 vma_delete(
this, pool);
+
+
+
+
+
15771 pool->m_BlockVector.GetPoolStats(pPoolStats);
+
+
+
15774 void VmaAllocator_T::SetCurrentFrameIndex(uint32_t frameIndex)
+
+
15776 m_CurrentFrameIndex.store(frameIndex);
+
+
15778 #if VMA_MEMORY_BUDGET
+
15779 if(m_UseExtMemoryBudget)
+
+
15781 UpdateVulkanBudget();
+
+
15783 #endif // #if VMA_MEMORY_BUDGET
+
+
+
15786 void VmaAllocator_T::MakePoolAllocationsLost(
+
+
15788 size_t* pLostAllocationCount)
+
+
15790 hPool->m_BlockVector.MakePoolAllocationsLost(
+
15791 m_CurrentFrameIndex.load(),
+
15792 pLostAllocationCount);
+
+
+
15795 VkResult VmaAllocator_T::CheckPoolCorruption(
VmaPool hPool)
+
+
15797 return hPool->m_BlockVector.CheckCorruption();
+
+
+
15800 VkResult VmaAllocator_T::CheckCorruption(uint32_t memoryTypeBits)
+
+
15802 VkResult finalRes = VK_ERROR_FEATURE_NOT_PRESENT;
+
+
+
15805 for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
+
+
15807 if(((1u << memTypeIndex) & memoryTypeBits) != 0)
+
+
15809 VmaBlockVector*
const pBlockVector = m_pBlockVectors[memTypeIndex];
+
15810 VMA_ASSERT(pBlockVector);
+
15811 VkResult localRes = pBlockVector->CheckCorruption();
+
+
+
15814 case VK_ERROR_FEATURE_NOT_PRESENT:
+
+
+
15817 finalRes = VK_SUCCESS;
+
+
+
+
+
+
+
+
+
+
15827 VmaMutexLockRead lock(m_PoolsMutex, m_UseMutex);
+
15828 for(
size_t poolIndex = 0, poolCount = m_Pools.size(); poolIndex < poolCount; ++poolIndex)
+
+
15830 if(((1u << m_Pools[poolIndex]->m_BlockVector.GetMemoryTypeIndex()) & memoryTypeBits) != 0)
+
+
15832 VkResult localRes = m_Pools[poolIndex]->m_BlockVector.CheckCorruption();
+
+
+
15835 case VK_ERROR_FEATURE_NOT_PRESENT:
+
+
+
15838 finalRes = VK_SUCCESS;
+
+
+
+
+
+
+
+
+
+
+
+
15850 void VmaAllocator_T::CreateLostAllocation(
VmaAllocation* pAllocation)
+
+
15852 *pAllocation = m_AllocationObjectAllocator.Allocate();
+
15853 (*pAllocation)->Ctor(VMA_FRAME_INDEX_LOST,
false);
+
15854 (*pAllocation)->InitLost();
+
+
+
15857 VkResult VmaAllocator_T::AllocateVulkanMemory(
const VkMemoryAllocateInfo* pAllocateInfo, VkDeviceMemory* pMemory)
+
+
15859 const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(pAllocateInfo->memoryTypeIndex);
+
+
+
15862 if((m_HeapSizeLimitMask & (1u << heapIndex)) != 0)
+
+
15864 const VkDeviceSize heapSize = m_MemProps.memoryHeaps[heapIndex].size;
+
15865 VkDeviceSize blockBytes = m_Budget.m_BlockBytes[heapIndex];
+
+
+
15868 const VkDeviceSize blockBytesAfterAllocation = blockBytes + pAllocateInfo->allocationSize;
+
15869 if(blockBytesAfterAllocation > heapSize)
+
+
15871 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
+
15873 if(m_Budget.m_BlockBytes[heapIndex].compare_exchange_strong(blockBytes, blockBytesAfterAllocation))
+
+
+
+
+
+
+
+
15881 m_Budget.m_BlockBytes[heapIndex] += pAllocateInfo->allocationSize;
+
+
+
+
15885 VkResult res = (*m_VulkanFunctions.vkAllocateMemory)(m_hDevice, pAllocateInfo, GetAllocationCallbacks(), pMemory);
-
-
15888 if(m_DeviceMemoryCallbacks.
pfnAllocate != VMA_NULL)
-
-
15890 (*m_DeviceMemoryCallbacks.
pfnAllocate)(
this, pAllocateInfo->memoryTypeIndex, *pMemory, pAllocateInfo->allocationSize);
-
-
-
-
-
15895 m_Budget.m_BlockBytes[heapIndex] -= pAllocateInfo->allocationSize;
-
-
-
-
-
-
15901 void VmaAllocator_T::FreeVulkanMemory(uint32_t memoryType, VkDeviceSize size, VkDeviceMemory hMemory)
-
-
-
15904 if(m_DeviceMemoryCallbacks.
pfnFree != VMA_NULL)
-
-
15906 (*m_DeviceMemoryCallbacks.
pfnFree)(
this, memoryType, hMemory, size);
-
-
-
-
15910 (*m_VulkanFunctions.vkFreeMemory)(m_hDevice, hMemory, GetAllocationCallbacks());
-
-
15912 m_Budget.m_BlockBytes[MemoryTypeIndexToHeapIndex(memoryType)] -= size;
-
+
15887 if(res == VK_SUCCESS)
+
+
15889 #if VMA_MEMORY_BUDGET
+
15890 ++m_Budget.m_OperationsSinceBudgetFetch;
+
+
+
+
15894 if(m_DeviceMemoryCallbacks.
pfnAllocate != VMA_NULL)
+
+
15896 (*m_DeviceMemoryCallbacks.
pfnAllocate)(
this, pAllocateInfo->memoryTypeIndex, *pMemory, pAllocateInfo->allocationSize);
+
+
+
+
+
15901 m_Budget.m_BlockBytes[heapIndex] -= pAllocateInfo->allocationSize;
+
+
+
+
+
+
15907 void VmaAllocator_T::FreeVulkanMemory(uint32_t memoryType, VkDeviceSize size, VkDeviceMemory hMemory)
+
+
+
15910 if(m_DeviceMemoryCallbacks.
pfnFree != VMA_NULL)
+
+
15912 (*m_DeviceMemoryCallbacks.
pfnFree)(
this, memoryType, hMemory, size);
+
-
15915 VkResult VmaAllocator_T::BindVulkanBuffer(
-
15916 VkDeviceMemory memory,
-
15917 VkDeviceSize memoryOffset,
-
-
-
-
15921 if(pNext != VMA_NULL)
-
-
15923 #if VMA_VULKAN_VERSION >= 1001000 || VMA_BIND_MEMORY2
-
15924 if((m_UseKhrBindMemory2 || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)) &&
-
15925 m_VulkanFunctions.vkBindBufferMemory2KHR != VMA_NULL)
-
-
15927 VkBindBufferMemoryInfoKHR bindBufferMemoryInfo = { VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR };
-
15928 bindBufferMemoryInfo.pNext = pNext;
-
15929 bindBufferMemoryInfo.buffer = buffer;
-
15930 bindBufferMemoryInfo.memory = memory;
-
15931 bindBufferMemoryInfo.memoryOffset = memoryOffset;
-
15932 return (*m_VulkanFunctions.vkBindBufferMemory2KHR)(m_hDevice, 1, &bindBufferMemoryInfo);
-
-
-
15935 #endif // #if VMA_VULKAN_VERSION >= 1001000 || VMA_BIND_MEMORY2
-
-
15937 return VK_ERROR_EXTENSION_NOT_PRESENT;
-
-
-
-
-
15942 return (*m_VulkanFunctions.vkBindBufferMemory)(m_hDevice, buffer, memory, memoryOffset);
-
-
-
-
15946 VkResult VmaAllocator_T::BindVulkanImage(
-
15947 VkDeviceMemory memory,
-
15948 VkDeviceSize memoryOffset,
-
-
-
-
15952 if(pNext != VMA_NULL)
-
-
15954 #if VMA_VULKAN_VERSION >= 1001000 || VMA_BIND_MEMORY2
-
15955 if((m_UseKhrBindMemory2 || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)) &&
-
15956 m_VulkanFunctions.vkBindImageMemory2KHR != VMA_NULL)
-
-
15958 VkBindImageMemoryInfoKHR bindBufferMemoryInfo = { VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO_KHR };
-
15959 bindBufferMemoryInfo.pNext = pNext;
-
15960 bindBufferMemoryInfo.image = image;
-
15961 bindBufferMemoryInfo.memory = memory;
-
15962 bindBufferMemoryInfo.memoryOffset = memoryOffset;
-
15963 return (*m_VulkanFunctions.vkBindImageMemory2KHR)(m_hDevice, 1, &bindBufferMemoryInfo);
-
-
-
15966 #endif // #if VMA_BIND_MEMORY2
-
-
15968 return VK_ERROR_EXTENSION_NOT_PRESENT;
-
-
-
-
-
15973 return (*m_VulkanFunctions.vkBindImageMemory)(m_hDevice, image, memory, memoryOffset);
-
-
-
-
15977 VkResult VmaAllocator_T::Map(
VmaAllocation hAllocation,
void** ppData)
-
-
15979 if(hAllocation->CanBecomeLost())
-
-
15981 return VK_ERROR_MEMORY_MAP_FAILED;
-
-
-
15984 switch(hAllocation->GetType())
-
-
15986 case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
-
-
15988 VmaDeviceMemoryBlock*
const pBlock = hAllocation->GetBlock();
-
15989 char *pBytes = VMA_NULL;
-
15990 VkResult res = pBlock->Map(
this, 1, (
void**)&pBytes);
-
15991 if(res == VK_SUCCESS)
-
-
15993 *ppData = pBytes + (ptrdiff_t)hAllocation->GetOffset();
-
15994 hAllocation->BlockAllocMap();
-
-
-
-
15998 case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
-
15999 return hAllocation->DedicatedAllocMap(
this, ppData);
-
-
-
16002 return VK_ERROR_MEMORY_MAP_FAILED;
-
-
-
-
-
-
16008 switch(hAllocation->GetType())
-
-
16010 case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
-
-
16012 VmaDeviceMemoryBlock*
const pBlock = hAllocation->GetBlock();
-
16013 hAllocation->BlockAllocUnmap();
-
16014 pBlock->Unmap(
this, 1);
-
-
-
16017 case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
-
16018 hAllocation->DedicatedAllocUnmap(
this);
-
-
-
-
-
-
-
16025 VkResult VmaAllocator_T::BindBufferMemory(
-
-
16027 VkDeviceSize allocationLocalOffset,
-
-
-
-
16031 VkResult res = VK_SUCCESS;
-
16032 switch(hAllocation->GetType())
-
-
16034 case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
-
16035 res = BindVulkanBuffer(hAllocation->GetMemory(), allocationLocalOffset, hBuffer, pNext);
-
-
16037 case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
-
-
16039 VmaDeviceMemoryBlock*
const pBlock = hAllocation->GetBlock();
-
16040 VMA_ASSERT(pBlock &&
"Binding buffer to allocation that doesn't belong to any block. Is the allocation lost?");
-
16041 res = pBlock->BindBufferMemory(
this, hAllocation, allocationLocalOffset, hBuffer, pNext);
+
+
15916 (*m_VulkanFunctions.vkFreeMemory)(m_hDevice, hMemory, GetAllocationCallbacks());
+
+
15918 m_Budget.m_BlockBytes[MemoryTypeIndexToHeapIndex(memoryType)] -= size;
+
+
+
15921 VkResult VmaAllocator_T::BindVulkanBuffer(
+
15922 VkDeviceMemory memory,
+
15923 VkDeviceSize memoryOffset,
+
+
+
+
15927 if(pNext != VMA_NULL)
+
+
15929 #if VMA_VULKAN_VERSION >= 1001000 || VMA_BIND_MEMORY2
+
15930 if((m_UseKhrBindMemory2 || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)) &&
+
15931 m_VulkanFunctions.vkBindBufferMemory2KHR != VMA_NULL)
+
+
15933 VkBindBufferMemoryInfoKHR bindBufferMemoryInfo = { VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR };
+
15934 bindBufferMemoryInfo.pNext = pNext;
+
15935 bindBufferMemoryInfo.buffer = buffer;
+
15936 bindBufferMemoryInfo.memory = memory;
+
15937 bindBufferMemoryInfo.memoryOffset = memoryOffset;
+
15938 return (*m_VulkanFunctions.vkBindBufferMemory2KHR)(m_hDevice, 1, &bindBufferMemoryInfo);
+
+
+
15941 #endif // #if VMA_VULKAN_VERSION >= 1001000 || VMA_BIND_MEMORY2
+
+
15943 return VK_ERROR_EXTENSION_NOT_PRESENT;
+
+
+
+
+
15948 return (*m_VulkanFunctions.vkBindBufferMemory)(m_hDevice, buffer, memory, memoryOffset);
+
+
+
+
15952 VkResult VmaAllocator_T::BindVulkanImage(
+
15953 VkDeviceMemory memory,
+
15954 VkDeviceSize memoryOffset,
+
+
+
+
15958 if(pNext != VMA_NULL)
+
+
15960 #if VMA_VULKAN_VERSION >= 1001000 || VMA_BIND_MEMORY2
+
15961 if((m_UseKhrBindMemory2 || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)) &&
+
15962 m_VulkanFunctions.vkBindImageMemory2KHR != VMA_NULL)
+
+
15964 VkBindImageMemoryInfoKHR bindBufferMemoryInfo = { VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO_KHR };
+
15965 bindBufferMemoryInfo.pNext = pNext;
+
15966 bindBufferMemoryInfo.image = image;
+
15967 bindBufferMemoryInfo.memory = memory;
+
15968 bindBufferMemoryInfo.memoryOffset = memoryOffset;
+
15969 return (*m_VulkanFunctions.vkBindImageMemory2KHR)(m_hDevice, 1, &bindBufferMemoryInfo);
+
+
+
15972 #endif // #if VMA_BIND_MEMORY2
+
+
15974 return VK_ERROR_EXTENSION_NOT_PRESENT;
+
+
+
+
+
15979 return (*m_VulkanFunctions.vkBindImageMemory)(m_hDevice, image, memory, memoryOffset);
+
+
+
+
15983 VkResult VmaAllocator_T::Map(
VmaAllocation hAllocation,
void** ppData)
+
+
15985 if(hAllocation->CanBecomeLost())
+
+
15987 return VK_ERROR_MEMORY_MAP_FAILED;
+
+
+
15990 switch(hAllocation->GetType())
+
+
15992 case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
+
+
15994 VmaDeviceMemoryBlock*
const pBlock = hAllocation->GetBlock();
+
15995 char *pBytes = VMA_NULL;
+
15996 VkResult res = pBlock->Map(
this, 1, (
void**)&pBytes);
+
15997 if(res == VK_SUCCESS)
+
+
15999 *ppData = pBytes + (ptrdiff_t)hAllocation->GetOffset();
+
16000 hAllocation->BlockAllocMap();
+
+
+
+
16004 case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
+
16005 return hAllocation->DedicatedAllocMap(
this, ppData);
+
+
+
16008 return VK_ERROR_MEMORY_MAP_FAILED;
+
+
+
+
+
+
16014 switch(hAllocation->GetType())
+
+
16016 case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
+
+
16018 VmaDeviceMemoryBlock*
const pBlock = hAllocation->GetBlock();
+
16019 hAllocation->BlockAllocUnmap();
+
16020 pBlock->Unmap(
this, 1);
+
+
+
16023 case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
+
16024 hAllocation->DedicatedAllocUnmap(
this);
+
+
+
+
+
+
+
16031 VkResult VmaAllocator_T::BindBufferMemory(
+
+
16033 VkDeviceSize allocationLocalOffset,
+
+
+
+
16037 VkResult res = VK_SUCCESS;
+
16038 switch(hAllocation->GetType())
+
+
16040 case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
+
16041 res = BindVulkanBuffer(hAllocation->GetMemory(), allocationLocalOffset, hBuffer, pNext);
-
-
-
-
-
-
-
-
16050 VkResult VmaAllocator_T::BindImageMemory(
-
-
16052 VkDeviceSize allocationLocalOffset,
-
-
-
-
16056 VkResult res = VK_SUCCESS;
-
16057 switch(hAllocation->GetType())
-
-
16059 case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
-
16060 res = BindVulkanImage(hAllocation->GetMemory(), allocationLocalOffset, hImage, pNext);
-
-
16062 case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
-
-
16064 VmaDeviceMemoryBlock* pBlock = hAllocation->GetBlock();
-
16065 VMA_ASSERT(pBlock &&
"Binding image to allocation that doesn't belong to any block. Is the allocation lost?");
-
16066 res = pBlock->BindImageMemory(
this, hAllocation, allocationLocalOffset, hImage, pNext);
+
16043 case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
+
+
16045 VmaDeviceMemoryBlock*
const pBlock = hAllocation->GetBlock();
+
16046 VMA_ASSERT(pBlock &&
"Binding buffer to allocation that doesn't belong to any block. Is the allocation lost?");
+
16047 res = pBlock->BindBufferMemory(
this, hAllocation, allocationLocalOffset, hBuffer, pNext);
+
+
+
+
+
+
+
+
+
16056 VkResult VmaAllocator_T::BindImageMemory(
+
+
16058 VkDeviceSize allocationLocalOffset,
+
+
+
+
16062 VkResult res = VK_SUCCESS;
+
16063 switch(hAllocation->GetType())
+
+
16065 case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
+
16066 res = BindVulkanImage(hAllocation->GetMemory(), allocationLocalOffset, hImage, pNext);
-
-
-
-
-
-
-
-
16075 void VmaAllocator_T::FlushOrInvalidateAllocation(
-
-
16077 VkDeviceSize offset, VkDeviceSize size,
-
16078 VMA_CACHE_OPERATION op)
-
-
16080 const uint32_t memTypeIndex = hAllocation->GetMemoryTypeIndex();
-
16081 if(size > 0 && IsMemoryTypeNonCoherent(memTypeIndex))
-
-
16083 const VkDeviceSize allocationSize = hAllocation->GetSize();
-
16084 VMA_ASSERT(offset <= allocationSize);
-
-
16086 const VkDeviceSize nonCoherentAtomSize = m_PhysicalDeviceProperties.limits.nonCoherentAtomSize;
-
-
16088 VkMappedMemoryRange memRange = { VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE };
-
16089 memRange.memory = hAllocation->GetMemory();
-
-
16091 switch(hAllocation->GetType())
-
-
16093 case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
-
16094 memRange.offset = VmaAlignDown(offset, nonCoherentAtomSize);
-
16095 if(size == VK_WHOLE_SIZE)
-
-
16097 memRange.size = allocationSize - memRange.offset;
-
-
-
-
16101 VMA_ASSERT(offset + size <= allocationSize);
-
16102 memRange.size = VMA_MIN(
-
16103 VmaAlignUp(size + (offset - memRange.offset), nonCoherentAtomSize),
-
16104 allocationSize - memRange.offset);
-
-
-
-
16108 case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
-
-
-
16111 memRange.offset = VmaAlignDown(offset, nonCoherentAtomSize);
-
16112 if(size == VK_WHOLE_SIZE)
-
-
16114 size = allocationSize - offset;
-
-
-
-
16118 VMA_ASSERT(offset + size <= allocationSize);
-
-
16120 memRange.size = VmaAlignUp(size + (offset - memRange.offset), nonCoherentAtomSize);
-
-
-
16123 const VkDeviceSize allocationOffset = hAllocation->GetOffset();
-
16124 VMA_ASSERT(allocationOffset % nonCoherentAtomSize == 0);
-
16125 const VkDeviceSize blockSize = hAllocation->GetBlock()->m_pMetadata->GetSize();
-
16126 memRange.offset += allocationOffset;
-
16127 memRange.size = VMA_MIN(memRange.size, blockSize - memRange.offset);
-
-
-
-
-
-
-
-
-
-
-
16138 case VMA_CACHE_FLUSH:
-
16139 (*GetVulkanFunctions().vkFlushMappedMemoryRanges)(m_hDevice, 1, &memRange);
-
-
16141 case VMA_CACHE_INVALIDATE:
-
16142 (*GetVulkanFunctions().vkInvalidateMappedMemoryRanges)(m_hDevice, 1, &memRange);
-
-
-
-
-
-
-
-
-
16151 void VmaAllocator_T::FreeDedicatedMemory(
const VmaAllocation allocation)
-
-
16153 VMA_ASSERT(allocation && allocation->GetType() == VmaAllocation_T::ALLOCATION_TYPE_DEDICATED);
-
-
16155 const uint32_t memTypeIndex = allocation->GetMemoryTypeIndex();
-
-
16157 VmaMutexLockWrite lock(m_DedicatedAllocationsMutex[memTypeIndex], m_UseMutex);
-
16158 AllocationVectorType*
const pDedicatedAllocations = m_pDedicatedAllocations[memTypeIndex];
-
16159 VMA_ASSERT(pDedicatedAllocations);
-
16160 bool success = VmaVectorRemoveSorted<VmaPointerLess>(*pDedicatedAllocations, allocation);
-
16161 VMA_ASSERT(success);
-
-
-
16164 VkDeviceMemory hMemory = allocation->GetMemory();
-
-
-
-
-
-
-
-
-
-
-
-
16176 FreeVulkanMemory(memTypeIndex, allocation->GetSize(), hMemory);
-
-
16178 VMA_DEBUG_LOG(
" Freed DedicatedMemory MemoryTypeIndex=%u", memTypeIndex);
-
-
-
16181 uint32_t VmaAllocator_T::CalculateGpuDefragmentationMemoryTypeBits()
const
-
-
16183 VkBufferCreateInfo dummyBufCreateInfo;
-
16184 VmaFillGpuDefragmentationBufferCreateInfo(dummyBufCreateInfo);
-
-
16186 uint32_t memoryTypeBits = 0;
-
-
-
16189 VkBuffer buf = VK_NULL_HANDLE;
-
16190 VkResult res = (*GetVulkanFunctions().vkCreateBuffer)(
-
16191 m_hDevice, &dummyBufCreateInfo, GetAllocationCallbacks(), &buf);
-
16192 if(res == VK_SUCCESS)
-
-
-
16195 VkMemoryRequirements memReq;
-
16196 (*GetVulkanFunctions().vkGetBufferMemoryRequirements)(m_hDevice, buf, &memReq);
-
16197 memoryTypeBits = memReq.memoryTypeBits;
-
-
-
16200 (*GetVulkanFunctions().vkDestroyBuffer)(m_hDevice, buf, GetAllocationCallbacks());
-
-
-
16203 return memoryTypeBits;
-
-
-
16206 #if VMA_MEMORY_BUDGET
-
-
16208 void VmaAllocator_T::UpdateVulkanBudget()
-
-
16210 VMA_ASSERT(m_UseExtMemoryBudget);
+
16068 case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
+
+
16070 VmaDeviceMemoryBlock* pBlock = hAllocation->GetBlock();
+
16071 VMA_ASSERT(pBlock &&
"Binding image to allocation that doesn't belong to any block. Is the allocation lost?");
+
16072 res = pBlock->BindImageMemory(
this, hAllocation, allocationLocalOffset, hImage, pNext);
+
+
+
+
+
+
+
+
+
16081 void VmaAllocator_T::FlushOrInvalidateAllocation(
+
+
16083 VkDeviceSize offset, VkDeviceSize size,
+
16084 VMA_CACHE_OPERATION op)
+
+
16086 const uint32_t memTypeIndex = hAllocation->GetMemoryTypeIndex();
+
16087 if(size > 0 && IsMemoryTypeNonCoherent(memTypeIndex))
+
+
16089 const VkDeviceSize allocationSize = hAllocation->GetSize();
+
16090 VMA_ASSERT(offset <= allocationSize);
+
+
16092 const VkDeviceSize nonCoherentAtomSize = m_PhysicalDeviceProperties.limits.nonCoherentAtomSize;
+
+
16094 VkMappedMemoryRange memRange = { VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE };
+
16095 memRange.memory = hAllocation->GetMemory();
+
+
16097 switch(hAllocation->GetType())
+
+
16099 case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
+
16100 memRange.offset = VmaAlignDown(offset, nonCoherentAtomSize);
+
16101 if(size == VK_WHOLE_SIZE)
+
+
16103 memRange.size = allocationSize - memRange.offset;
+
+
+
+
16107 VMA_ASSERT(offset + size <= allocationSize);
+
16108 memRange.size = VMA_MIN(
+
16109 VmaAlignUp(size + (offset - memRange.offset), nonCoherentAtomSize),
+
16110 allocationSize - memRange.offset);
+
+
+
+
16114 case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
+
+
+
16117 memRange.offset = VmaAlignDown(offset, nonCoherentAtomSize);
+
16118 if(size == VK_WHOLE_SIZE)
+
+
16120 size = allocationSize - offset;
+
+
+
+
16124 VMA_ASSERT(offset + size <= allocationSize);
+
+
16126 memRange.size = VmaAlignUp(size + (offset - memRange.offset), nonCoherentAtomSize);
+
+
+
16129 const VkDeviceSize allocationOffset = hAllocation->GetOffset();
+
16130 VMA_ASSERT(allocationOffset % nonCoherentAtomSize == 0);
+
16131 const VkDeviceSize blockSize = hAllocation->GetBlock()->m_pMetadata->GetSize();
+
16132 memRange.offset += allocationOffset;
+
16133 memRange.size = VMA_MIN(memRange.size, blockSize - memRange.offset);
+
+
+
+
+
+
+
+
+
+
+
16144 case VMA_CACHE_FLUSH:
+
16145 (*GetVulkanFunctions().vkFlushMappedMemoryRanges)(m_hDevice, 1, &memRange);
+
+
16147 case VMA_CACHE_INVALIDATE:
+
16148 (*GetVulkanFunctions().vkInvalidateMappedMemoryRanges)(m_hDevice, 1, &memRange);
+
+
+
+
+
+
+
+
+
16157 void VmaAllocator_T::FreeDedicatedMemory(
const VmaAllocation allocation)
+
+
16159 VMA_ASSERT(allocation && allocation->GetType() == VmaAllocation_T::ALLOCATION_TYPE_DEDICATED);
+
+
16161 const uint32_t memTypeIndex = allocation->GetMemoryTypeIndex();
+
+
16163 VmaMutexLockWrite lock(m_DedicatedAllocationsMutex[memTypeIndex], m_UseMutex);
+
16164 AllocationVectorType*
const pDedicatedAllocations = m_pDedicatedAllocations[memTypeIndex];
+
16165 VMA_ASSERT(pDedicatedAllocations);
+
16166 bool success = VmaVectorRemoveSorted<VmaPointerLess>(*pDedicatedAllocations, allocation);
+
16167 VMA_ASSERT(success);
+
+
+
16170 VkDeviceMemory hMemory = allocation->GetMemory();
+
+
+
+
+
+
+
+
+
+
+
+
16182 FreeVulkanMemory(memTypeIndex, allocation->GetSize(), hMemory);
+
+
16184 VMA_DEBUG_LOG(
" Freed DedicatedMemory MemoryTypeIndex=%u", memTypeIndex);
+
+
+
16187 uint32_t VmaAllocator_T::CalculateGpuDefragmentationMemoryTypeBits()
const
+
+
16189 VkBufferCreateInfo dummyBufCreateInfo;
+
16190 VmaFillGpuDefragmentationBufferCreateInfo(dummyBufCreateInfo);
+
+
16192 uint32_t memoryTypeBits = 0;
+
+
+
16195 VkBuffer buf = VK_NULL_HANDLE;
+
16196 VkResult res = (*GetVulkanFunctions().vkCreateBuffer)(
+
16197 m_hDevice, &dummyBufCreateInfo, GetAllocationCallbacks(), &buf);
+
16198 if(res == VK_SUCCESS)
+
+
+
16201 VkMemoryRequirements memReq;
+
16202 (*GetVulkanFunctions().vkGetBufferMemoryRequirements)(m_hDevice, buf, &memReq);
+
16203 memoryTypeBits = memReq.memoryTypeBits;
+
+
+
16206 (*GetVulkanFunctions().vkDestroyBuffer)(m_hDevice, buf, GetAllocationCallbacks());
+
+
+
16209 return memoryTypeBits;
+
-
16212 VkPhysicalDeviceMemoryProperties2KHR memProps = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2_KHR };
+
16212 #if VMA_MEMORY_BUDGET
-
16214 VkPhysicalDeviceMemoryBudgetPropertiesEXT budgetProps = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT };
-
16215 memProps.pNext = &budgetProps;
-
-
16217 GetVulkanFunctions().vkGetPhysicalDeviceMemoryProperties2KHR(m_PhysicalDevice, &memProps);
-
-
-
16220 VmaMutexLockWrite lockWrite(m_Budget.m_BudgetMutex, m_UseMutex);
-
-
16222 for(uint32_t heapIndex = 0; heapIndex < GetMemoryHeapCount(); ++heapIndex)
-
-
16224 m_Budget.m_VulkanUsage[heapIndex] = budgetProps.heapUsage[heapIndex];
-
16225 m_Budget.m_VulkanBudget[heapIndex] = budgetProps.heapBudget[heapIndex];
-
16226 m_Budget.m_BlockBytesAtBudgetFetch[heapIndex] = m_Budget.m_BlockBytes[heapIndex].load();
-
-
16228 m_Budget.m_OperationsSinceBudgetFetch = 0;
-
-
-
-
16232 #endif // #if VMA_MEMORY_BUDGET
-
-
16234 void VmaAllocator_T::FillAllocation(
const VmaAllocation hAllocation, uint8_t pattern)
-
-
16236 if(VMA_DEBUG_INITIALIZE_ALLOCATIONS &&
-
16237 !hAllocation->CanBecomeLost() &&
-
16238 (m_MemProps.memoryTypes[hAllocation->GetMemoryTypeIndex()].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0)
-
-
16240 void* pData = VMA_NULL;
-
16241 VkResult res = Map(hAllocation, &pData);
-
16242 if(res == VK_SUCCESS)
-
-
16244 memset(pData, (
int)pattern, (
size_t)hAllocation->GetSize());
-
16245 FlushOrInvalidateAllocation(hAllocation, 0, VK_WHOLE_SIZE, VMA_CACHE_FLUSH);
-
16246 Unmap(hAllocation);
-
-
+
16214 void VmaAllocator_T::UpdateVulkanBudget()
+
+
16216 VMA_ASSERT(m_UseExtMemoryBudget);
+
+
16218 VkPhysicalDeviceMemoryProperties2KHR memProps = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2_KHR };
+
+
16220 VkPhysicalDeviceMemoryBudgetPropertiesEXT budgetProps = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT };
+
16221 memProps.pNext = &budgetProps;
+
+
16223 GetVulkanFunctions().vkGetPhysicalDeviceMemoryProperties2KHR(m_PhysicalDevice, &memProps);
+
+
+
16226 VmaMutexLockWrite lockWrite(m_Budget.m_BudgetMutex, m_UseMutex);
+
+
16228 for(uint32_t heapIndex = 0; heapIndex < GetMemoryHeapCount(); ++heapIndex)
+
+
16230 m_Budget.m_VulkanUsage[heapIndex] = budgetProps.heapUsage[heapIndex];
+
16231 m_Budget.m_VulkanBudget[heapIndex] = budgetProps.heapBudget[heapIndex];
+
16232 m_Budget.m_BlockBytesAtBudgetFetch[heapIndex] = m_Budget.m_BlockBytes[heapIndex].load();
+
+
16234 m_Budget.m_OperationsSinceBudgetFetch = 0;
+
+
+
+
16238 #endif // #if VMA_MEMORY_BUDGET
+
+
16240 void VmaAllocator_T::FillAllocation(
const VmaAllocation hAllocation, uint8_t pattern)
+
+
16242 if(VMA_DEBUG_INITIALIZE_ALLOCATIONS &&
+
16243 !hAllocation->CanBecomeLost() &&
+
16244 (m_MemProps.memoryTypes[hAllocation->GetMemoryTypeIndex()].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0)
+
+
16246 void* pData = VMA_NULL;
+
16247 VkResult res = Map(hAllocation, &pData);
+
16248 if(res == VK_SUCCESS)
-
16250 VMA_ASSERT(0 &&
"VMA_DEBUG_INITIALIZE_ALLOCATIONS is enabled, but couldn't map memory to fill allocation.");
-
-
-
-
-
16255 uint32_t VmaAllocator_T::GetGpuDefragmentationMemoryTypeBits()
-
-
16257 uint32_t memoryTypeBits = m_GpuDefragmentationMemoryTypeBits.load();
-
16258 if(memoryTypeBits == UINT32_MAX)
-
-
16260 memoryTypeBits = CalculateGpuDefragmentationMemoryTypeBits();
-
16261 m_GpuDefragmentationMemoryTypeBits.store(memoryTypeBits);
-
-
16263 return memoryTypeBits;
-
-
-
16266 #if VMA_STATS_STRING_ENABLED
-
-
16268 void VmaAllocator_T::PrintDetailedMap(VmaJsonWriter& json)
-
-
16270 bool dedicatedAllocationsStarted =
false;
-
16271 for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
-
-
16273 VmaMutexLockRead dedicatedAllocationsLock(m_DedicatedAllocationsMutex[memTypeIndex], m_UseMutex);
-
16274 AllocationVectorType*
const pDedicatedAllocVector = m_pDedicatedAllocations[memTypeIndex];
-
16275 VMA_ASSERT(pDedicatedAllocVector);
-
16276 if(pDedicatedAllocVector->empty() ==
false)
-
-
16278 if(dedicatedAllocationsStarted ==
false)
-
-
16280 dedicatedAllocationsStarted =
true;
-
16281 json.WriteString(
"DedicatedAllocations");
-
16282 json.BeginObject();
-
-
-
16285 json.BeginString(
"Type ");
-
16286 json.ContinueString(memTypeIndex);
-
-
-
+
16250 memset(pData, (
int)pattern, (
size_t)hAllocation->GetSize());
+
16251 FlushOrInvalidateAllocation(hAllocation, 0, VK_WHOLE_SIZE, VMA_CACHE_FLUSH);
+
16252 Unmap(hAllocation);
+
+
+
+
16256 VMA_ASSERT(0 &&
"VMA_DEBUG_INITIALIZE_ALLOCATIONS is enabled, but couldn't map memory to fill allocation.");
+
+
+
+
+
16261 uint32_t VmaAllocator_T::GetGpuDefragmentationMemoryTypeBits()
+
+
16263 uint32_t memoryTypeBits = m_GpuDefragmentationMemoryTypeBits.load();
+
16264 if(memoryTypeBits == UINT32_MAX)
+
+
16266 memoryTypeBits = CalculateGpuDefragmentationMemoryTypeBits();
+
16267 m_GpuDefragmentationMemoryTypeBits.store(memoryTypeBits);
+
+
16269 return memoryTypeBits;
+
+
+
16272 #if VMA_STATS_STRING_ENABLED
+
+
16274 void VmaAllocator_T::PrintDetailedMap(VmaJsonWriter& json)
+
+
16276 bool dedicatedAllocationsStarted =
false;
+
16277 for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
+
+
16279 VmaMutexLockRead dedicatedAllocationsLock(m_DedicatedAllocationsMutex[memTypeIndex], m_UseMutex);
+
16280 AllocationVectorType*
const pDedicatedAllocVector = m_pDedicatedAllocations[memTypeIndex];
+
16281 VMA_ASSERT(pDedicatedAllocVector);
+
16282 if(pDedicatedAllocVector->empty() ==
false)
+
+
16284 if(dedicatedAllocationsStarted ==
false)
+
+
16286 dedicatedAllocationsStarted =
true;
+
16287 json.WriteString(
"DedicatedAllocations");
+
16288 json.BeginObject();
+
-
16291 for(
size_t i = 0; i < pDedicatedAllocVector->size(); ++i)
-
-
16293 json.BeginObject(
true);
-
-
16295 hAlloc->PrintParameters(json);
-
-
-
-
-
-
-
16302 if(dedicatedAllocationsStarted)
-
-
-
-
-
-
16308 bool allocationsStarted =
false;
-
16309 for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
-
-
16311 if(m_pBlockVectors[memTypeIndex]->IsEmpty() ==
false)
-
-
16313 if(allocationsStarted ==
false)
-
-
16315 allocationsStarted =
true;
-
16316 json.WriteString(
"DefaultPools");
-
16317 json.BeginObject();
-
-
-
16320 json.BeginString(
"Type ");
-
16321 json.ContinueString(memTypeIndex);
-
-
-
16324 m_pBlockVectors[memTypeIndex]->PrintDetailedMap(json);
-
-
-
16327 if(allocationsStarted)
-
-
-
-
-
-
-
-
16335 VmaMutexLockRead lock(m_PoolsMutex, m_UseMutex);
-
16336 const size_t poolCount = m_Pools.size();
-
-
-
16339 json.WriteString(
"Pools");
-
16340 json.BeginObject();
-
16341 for(
size_t poolIndex = 0; poolIndex < poolCount; ++poolIndex)
-
-
16343 json.BeginString();
-
16344 json.ContinueString(m_Pools[poolIndex]->GetId());
-
-
-
16347 m_Pools[poolIndex]->m_BlockVector.PrintDetailedMap(json);
-
-
-
-
-
-
-
16354 #endif // #if VMA_STATS_STRING_ENABLED
-
-
-
-
-
-
-
-
16363 VMA_ASSERT(pCreateInfo && pAllocator);
-
-
-
16366 VMA_DEBUG_LOG(
"vmaCreateAllocator");
-
-
16368 return (*pAllocator)->Init(pCreateInfo);
-
-
-
-
-
-
16374 if(allocator != VK_NULL_HANDLE)
-
-
16376 VMA_DEBUG_LOG(
"vmaDestroyAllocator");
-
16377 VkAllocationCallbacks allocationCallbacks = allocator->m_AllocationCallbacks;
-
16378 vma_delete(&allocationCallbacks, allocator);
-
-
-
-
-
-
16384 const VkPhysicalDeviceProperties **ppPhysicalDeviceProperties)
-
-
16386 VMA_ASSERT(allocator && ppPhysicalDeviceProperties);
-
16387 *ppPhysicalDeviceProperties = &allocator->m_PhysicalDeviceProperties;
-
-
-
-
-
16392 const VkPhysicalDeviceMemoryProperties** ppPhysicalDeviceMemoryProperties)
-
-
16394 VMA_ASSERT(allocator && ppPhysicalDeviceMemoryProperties);
-
16395 *ppPhysicalDeviceMemoryProperties = &allocator->m_MemProps;
-
-
-
-
-
16400 uint32_t memoryTypeIndex,
-
16401 VkMemoryPropertyFlags* pFlags)
-
-
16403 VMA_ASSERT(allocator && pFlags);
-
16404 VMA_ASSERT(memoryTypeIndex < allocator->GetMemoryTypeCount());
-
16405 *pFlags = allocator->m_MemProps.memoryTypes[memoryTypeIndex].propertyFlags;
-
-
-
-
-
16410 uint32_t frameIndex)
-
-
16412 VMA_ASSERT(allocator);
-
16413 VMA_ASSERT(frameIndex != VMA_FRAME_INDEX_LOST);
-
-
16415 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
16417 allocator->SetCurrentFrameIndex(frameIndex);
-
-
-
-
-
-
-
16424 VMA_ASSERT(allocator && pStats);
-
16425 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
16426 allocator->CalculateStats(pStats);
-
-
-
-
-
-
-
16433 VMA_ASSERT(allocator && pBudget);
-
16434 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
16435 allocator->GetBudget(pBudget, 0, allocator->GetMemoryHeapCount());
-
-
-
16438 #if VMA_STATS_STRING_ENABLED
-
-
-
-
16442 char** ppStatsString,
-
16443 VkBool32 detailedMap)
-
-
16445 VMA_ASSERT(allocator && ppStatsString);
-
16446 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
16448 VmaStringBuilder sb(allocator);
-
-
16450 VmaJsonWriter json(allocator->GetAllocationCallbacks(), sb);
-
16451 json.BeginObject();
-
-
-
16454 allocator->GetBudget(budget, 0, allocator->GetMemoryHeapCount());
-
-
-
16457 allocator->CalculateStats(&stats);
+
16291 json.BeginString(
"Type ");
+
16292 json.ContinueString(memTypeIndex);
+
+
+
+
+
16297 for(
size_t i = 0; i < pDedicatedAllocVector->size(); ++i)
+
+
16299 json.BeginObject(
true);
+
+
16301 hAlloc->PrintParameters(json);
+
+
+
+
+
+
+
16308 if(dedicatedAllocationsStarted)
+
+
+
+
+
+
16314 bool allocationsStarted =
false;
+
16315 for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
+
+
16317 if(m_pBlockVectors[memTypeIndex]->IsEmpty() ==
false)
+
+
16319 if(allocationsStarted ==
false)
+
+
16321 allocationsStarted =
true;
+
16322 json.WriteString(
"DefaultPools");
+
16323 json.BeginObject();
+
+
+
16326 json.BeginString(
"Type ");
+
16327 json.ContinueString(memTypeIndex);
+
+
+
16330 m_pBlockVectors[memTypeIndex]->PrintDetailedMap(json);
+
+
+
16333 if(allocationsStarted)
+
+
+
+
+
+
+
+
16341 VmaMutexLockRead lock(m_PoolsMutex, m_UseMutex);
+
16342 const size_t poolCount = m_Pools.size();
+
+
+
16345 json.WriteString(
"Pools");
+
16346 json.BeginObject();
+
16347 for(
size_t poolIndex = 0; poolIndex < poolCount; ++poolIndex)
+
+
16349 json.BeginString();
+
16350 json.ContinueString(m_Pools[poolIndex]->GetId());
+
+
+
16353 m_Pools[poolIndex]->m_BlockVector.PrintDetailedMap(json);
+
+
+
+
+
+
+
16360 #endif // #if VMA_STATS_STRING_ENABLED
+
+
+
+
+
+
+
+
16369 VMA_ASSERT(pCreateInfo && pAllocator);
+
+
+
16372 VMA_DEBUG_LOG(
"vmaCreateAllocator");
+
+
16374 return (*pAllocator)->Init(pCreateInfo);
+
+
+
+
+
+
16380 if(allocator != VK_NULL_HANDLE)
+
+
16382 VMA_DEBUG_LOG(
"vmaDestroyAllocator");
+
16383 VkAllocationCallbacks allocationCallbacks = allocator->m_AllocationCallbacks;
+
16384 vma_delete(&allocationCallbacks, allocator);
+
+
+
+
+
+
16390 const VkPhysicalDeviceProperties **ppPhysicalDeviceProperties)
+
+
16392 VMA_ASSERT(allocator && ppPhysicalDeviceProperties);
+
16393 *ppPhysicalDeviceProperties = &allocator->m_PhysicalDeviceProperties;
+
+
+
+
+
16398 const VkPhysicalDeviceMemoryProperties** ppPhysicalDeviceMemoryProperties)
+
+
16400 VMA_ASSERT(allocator && ppPhysicalDeviceMemoryProperties);
+
16401 *ppPhysicalDeviceMemoryProperties = &allocator->m_MemProps;
+
+
+
+
+
16406 uint32_t memoryTypeIndex,
+
16407 VkMemoryPropertyFlags* pFlags)
+
+
16409 VMA_ASSERT(allocator && pFlags);
+
16410 VMA_ASSERT(memoryTypeIndex < allocator->GetMemoryTypeCount());
+
16411 *pFlags = allocator->m_MemProps.memoryTypes[memoryTypeIndex].propertyFlags;
+
+
+
+
+
16416 uint32_t frameIndex)
+
+
16418 VMA_ASSERT(allocator);
+
16419 VMA_ASSERT(frameIndex != VMA_FRAME_INDEX_LOST);
+
+
16421 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
16423 allocator->SetCurrentFrameIndex(frameIndex);
+
+
+
+
+
+
+
16430 VMA_ASSERT(allocator && pStats);
+
16431 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
16432 allocator->CalculateStats(pStats);
+
+
+
+
+
+
+
16439 VMA_ASSERT(allocator && pBudget);
+
16440 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
16441 allocator->GetBudget(pBudget, 0, allocator->GetMemoryHeapCount());
+
+
+
16444 #if VMA_STATS_STRING_ENABLED
+
+
+
+
16448 char** ppStatsString,
+
16449 VkBool32 detailedMap)
+
+
16451 VMA_ASSERT(allocator && ppStatsString);
+
16452 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
16454 VmaStringBuilder sb(allocator);
+
+
16456 VmaJsonWriter json(allocator->GetAllocationCallbacks(), sb);
+
16457 json.BeginObject();
-
16459 json.WriteString(
"Total");
-
16460 VmaPrintStatInfo(json, stats.
total);
-
-
16462 for(uint32_t heapIndex = 0; heapIndex < allocator->GetMemoryHeapCount(); ++heapIndex)
-
-
16464 json.BeginString(
"Heap ");
-
16465 json.ContinueString(heapIndex);
-
-
16467 json.BeginObject();
-
-
16469 json.WriteString(
"Size");
-
16470 json.WriteNumber(allocator->m_MemProps.memoryHeaps[heapIndex].size);
-
-
16472 json.WriteString(
"Flags");
-
16473 json.BeginArray(
true);
-
16474 if((allocator->m_MemProps.memoryHeaps[heapIndex].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0)
-
-
16476 json.WriteString(
"DEVICE_LOCAL");
-
-
-
-
16480 json.WriteString(
"Budget");
-
16481 json.BeginObject();
-
-
16483 json.WriteString(
"BlockBytes");
-
16484 json.WriteNumber(budget[heapIndex].blockBytes);
-
16485 json.WriteString(
"AllocationBytes");
-
16486 json.WriteNumber(budget[heapIndex].allocationBytes);
-
16487 json.WriteString(
"Usage");
-
16488 json.WriteNumber(budget[heapIndex].usage);
-
16489 json.WriteString(
"Budget");
-
16490 json.WriteNumber(budget[heapIndex].budget);
-
-
-
-
-
-
16496 json.WriteString(
"Stats");
-
16497 VmaPrintStatInfo(json, stats.
memoryHeap[heapIndex]);
-
+
+
16460 allocator->GetBudget(budget, 0, allocator->GetMemoryHeapCount());
+
+
+
16463 allocator->CalculateStats(&stats);
+
+
16465 json.WriteString(
"Total");
+
16466 VmaPrintStatInfo(json, stats.
total);
+
+
16468 for(uint32_t heapIndex = 0; heapIndex < allocator->GetMemoryHeapCount(); ++heapIndex)
+
+
16470 json.BeginString(
"Heap ");
+
16471 json.ContinueString(heapIndex);
+
+
16473 json.BeginObject();
+
+
16475 json.WriteString(
"Size");
+
16476 json.WriteNumber(allocator->m_MemProps.memoryHeaps[heapIndex].size);
+
+
16478 json.WriteString(
"Flags");
+
16479 json.BeginArray(
true);
+
16480 if((allocator->m_MemProps.memoryHeaps[heapIndex].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0)
+
+
16482 json.WriteString(
"DEVICE_LOCAL");
+
+
+
+
16486 json.WriteString(
"Budget");
+
16487 json.BeginObject();
+
+
16489 json.WriteString(
"BlockBytes");
+
16490 json.WriteNumber(budget[heapIndex].blockBytes);
+
16491 json.WriteString(
"AllocationBytes");
+
16492 json.WriteNumber(budget[heapIndex].allocationBytes);
+
16493 json.WriteString(
"Usage");
+
16494 json.WriteNumber(budget[heapIndex].usage);
+
16495 json.WriteString(
"Budget");
+
16496 json.WriteNumber(budget[heapIndex].budget);
+
+
-
16500 for(uint32_t typeIndex = 0; typeIndex < allocator->GetMemoryTypeCount(); ++typeIndex)
+
-
16502 if(allocator->MemoryTypeIndexToHeapIndex(typeIndex) == heapIndex)
-
-
16504 json.BeginString(
"Type ");
-
16505 json.ContinueString(typeIndex);
-
-
-
16508 json.BeginObject();
-
-
16510 json.WriteString(
"Flags");
-
16511 json.BeginArray(
true);
-
16512 VkMemoryPropertyFlags flags = allocator->m_MemProps.memoryTypes[typeIndex].propertyFlags;
-
16513 if((flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != 0)
-
-
16515 json.WriteString(
"DEVICE_LOCAL");
-
-
16517 if((flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0)
-
-
16519 json.WriteString(
"HOST_VISIBLE");
-
-
16521 if((flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) != 0)
-
-
16523 json.WriteString(
"HOST_COHERENT");
-
-
16525 if((flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) != 0)
-
-
16527 json.WriteString(
"HOST_CACHED");
-
-
16529 if((flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) != 0)
-
-
16531 json.WriteString(
"LAZILY_ALLOCATED");
-
-
-
-
+
16502 json.WriteString(
"Stats");
+
16503 VmaPrintStatInfo(json, stats.
memoryHeap[heapIndex]);
+
+
+
16506 for(uint32_t typeIndex = 0; typeIndex < allocator->GetMemoryTypeCount(); ++typeIndex)
+
+
16508 if(allocator->MemoryTypeIndexToHeapIndex(typeIndex) == heapIndex)
+
+
16510 json.BeginString(
"Type ");
+
16511 json.ContinueString(typeIndex);
+
+
+
16514 json.BeginObject();
+
+
16516 json.WriteString(
"Flags");
+
16517 json.BeginArray(
true);
+
16518 VkMemoryPropertyFlags flags = allocator->m_MemProps.memoryTypes[typeIndex].propertyFlags;
+
16519 if((flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != 0)
+
+
16521 json.WriteString(
"DEVICE_LOCAL");
+
+
16523 if((flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0)
+
+
16525 json.WriteString(
"HOST_VISIBLE");
+
+
16527 if((flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) != 0)
+
+
16529 json.WriteString(
"HOST_COHERENT");
+
+
16531 if((flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) != 0)
+
+
16533 json.WriteString(
"HOST_CACHED");
+
+
16535 if((flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) != 0)
-
16537 json.WriteString(
"Stats");
-
16538 VmaPrintStatInfo(json, stats.
memoryType[typeIndex]);
-
+
16537 json.WriteString(
"LAZILY_ALLOCATED");
+
+
-
-
-
-
-
-
-
16547 if(detailedMap == VK_TRUE)
-
-
16549 allocator->PrintDetailedMap(json);
-
-
-
-
-
-
16555 const size_t len = sb.GetLength();
-
16556 char*
const pChars = vma_new_array(allocator,
char, len + 1);
-
-
-
16559 memcpy(pChars, sb.GetData(), len);
-
-
16561 pChars[len] =
'\0';
-
16562 *ppStatsString = pChars;
-
-
-
-
-
16567 char* pStatsString)
-
-
16569 if(pStatsString != VMA_NULL)
-
-
16571 VMA_ASSERT(allocator);
-
16572 size_t len = strlen(pStatsString);
-
16573 vma_delete_array(allocator, pStatsString, len + 1);
-
-
-
-
16577 #endif // #if VMA_STATS_STRING_ENABLED
-
-
-
-
-
-
-
16584 uint32_t memoryTypeBits,
-
-
16586 uint32_t* pMemoryTypeIndex)
-
-
16588 VMA_ASSERT(allocator != VK_NULL_HANDLE);
-
16589 VMA_ASSERT(pAllocationCreateInfo != VMA_NULL);
-
16590 VMA_ASSERT(pMemoryTypeIndex != VMA_NULL);
-
-
-
-
-
-
-
16597 uint32_t requiredFlags = pAllocationCreateInfo->
requiredFlags;
-
16598 uint32_t preferredFlags = pAllocationCreateInfo->
preferredFlags;
-
16599 uint32_t notPreferredFlags = 0;
-
-
-
16602 switch(pAllocationCreateInfo->
usage)
-
-
-
-
-
16607 if(!allocator->IsIntegratedGpu() || (preferredFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
-
-
16609 preferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
-
+
+
+
16543 json.WriteString(
"Stats");
+
16544 VmaPrintStatInfo(json, stats.
memoryType[typeIndex]);
+
+
+
+
+
+
+
+
+
16553 if(detailedMap == VK_TRUE)
+
+
16555 allocator->PrintDetailedMap(json);
+
+
+
+
+
+
16561 const size_t len = sb.GetLength();
+
16562 char*
const pChars = vma_new_array(allocator,
char, len + 1);
+
+
+
16565 memcpy(pChars, sb.GetData(), len);
+
+
16567 pChars[len] =
'\0';
+
16568 *ppStatsString = pChars;
+
+
+
+
+
16573 char* pStatsString)
+
+
16575 if(pStatsString != VMA_NULL)
+
+
16577 VMA_ASSERT(allocator);
+
16578 size_t len = strlen(pStatsString);
+
16579 vma_delete_array(allocator, pStatsString, len + 1);
+
+
+
+
16583 #endif // #if VMA_STATS_STRING_ENABLED
+
+
+
+
+
+
+
16590 uint32_t memoryTypeBits,
+
+
16592 uint32_t* pMemoryTypeIndex)
+
+
16594 VMA_ASSERT(allocator != VK_NULL_HANDLE);
+
16595 VMA_ASSERT(pAllocationCreateInfo != VMA_NULL);
+
16596 VMA_ASSERT(pMemoryTypeIndex != VMA_NULL);
+
+
+
+
+
+
+
16603 uint32_t requiredFlags = pAllocationCreateInfo->
requiredFlags;
+
16604 uint32_t preferredFlags = pAllocationCreateInfo->
preferredFlags;
+
16605 uint32_t notPreferredFlags = 0;
+
+
+
16608 switch(pAllocationCreateInfo->
usage)
+
+
-
-
16613 requiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
-
-
-
16616 requiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
-
16617 if(!allocator->IsIntegratedGpu() || (preferredFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
-
-
16619 preferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
-
-
-
-
16623 requiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
-
16624 preferredFlags |= VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
-
-
-
16627 notPreferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
-
-
-
16630 requiredFlags |= VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT;
+
+
16613 if(!allocator->IsIntegratedGpu() || (preferredFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
+
+
16615 preferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
+
+
+
+
16619 requiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
+
+
+
16622 requiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
+
16623 if(!allocator->IsIntegratedGpu() || (preferredFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
+
+
16625 preferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
+
+
+
+
16629 requiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
+
16630 preferredFlags |= VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
-
-
+
+
16633 notPreferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
-
-
-
16637 *pMemoryTypeIndex = UINT32_MAX;
-
16638 uint32_t minCost = UINT32_MAX;
-
16639 for(uint32_t memTypeIndex = 0, memTypeBit = 1;
-
16640 memTypeIndex < allocator->GetMemoryTypeCount();
-
16641 ++memTypeIndex, memTypeBit <<= 1)
-
-
-
16644 if((memTypeBit & memoryTypeBits) != 0)
-
-
16646 const VkMemoryPropertyFlags currFlags =
-
16647 allocator->m_MemProps.memoryTypes[memTypeIndex].propertyFlags;
-
-
16649 if((requiredFlags & ~currFlags) == 0)
-
-
-
16652 uint32_t currCost = VmaCountBitsSet(preferredFlags & ~currFlags) +
-
16653 VmaCountBitsSet(currFlags & notPreferredFlags);
-
-
16655 if(currCost < minCost)
-
-
16657 *pMemoryTypeIndex = memTypeIndex;
-
-
-
-
-
16662 minCost = currCost;
-
-
-
-
-
16667 return (*pMemoryTypeIndex != UINT32_MAX) ? VK_SUCCESS : VK_ERROR_FEATURE_NOT_PRESENT;
-
-
-
-
-
16672 const VkBufferCreateInfo* pBufferCreateInfo,
-
-
16674 uint32_t* pMemoryTypeIndex)
-
-
16676 VMA_ASSERT(allocator != VK_NULL_HANDLE);
-
16677 VMA_ASSERT(pBufferCreateInfo != VMA_NULL);
-
16678 VMA_ASSERT(pAllocationCreateInfo != VMA_NULL);
-
16679 VMA_ASSERT(pMemoryTypeIndex != VMA_NULL);
-
-
16681 const VkDevice hDev = allocator->m_hDevice;
-
16682 VkBuffer hBuffer = VK_NULL_HANDLE;
-
16683 VkResult res = allocator->GetVulkanFunctions().vkCreateBuffer(
-
16684 hDev, pBufferCreateInfo, allocator->GetAllocationCallbacks(), &hBuffer);
-
16685 if(res == VK_SUCCESS)
-
-
16687 VkMemoryRequirements memReq = {};
-
16688 allocator->GetVulkanFunctions().vkGetBufferMemoryRequirements(
-
16689 hDev, hBuffer, &memReq);
-
-
-
-
16693 memReq.memoryTypeBits,
-
16694 pAllocationCreateInfo,
-
+
+
16636 requiredFlags |= VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT;
+
+
+
+
+
+
+
16643 *pMemoryTypeIndex = UINT32_MAX;
+
16644 uint32_t minCost = UINT32_MAX;
+
16645 for(uint32_t memTypeIndex = 0, memTypeBit = 1;
+
16646 memTypeIndex < allocator->GetMemoryTypeCount();
+
16647 ++memTypeIndex, memTypeBit <<= 1)
+
+
+
16650 if((memTypeBit & memoryTypeBits) != 0)
+
+
16652 const VkMemoryPropertyFlags currFlags =
+
16653 allocator->m_MemProps.memoryTypes[memTypeIndex].propertyFlags;
+
+
16655 if((requiredFlags & ~currFlags) == 0)
+
+
+
16658 uint32_t currCost = VmaCountBitsSet(preferredFlags & ~currFlags) +
+
16659 VmaCountBitsSet(currFlags & notPreferredFlags);
+
+
16661 if(currCost < minCost)
+
+
16663 *pMemoryTypeIndex = memTypeIndex;
+
+
+
+
+
16668 minCost = currCost;
+
+
+
+
+
16673 return (*pMemoryTypeIndex != UINT32_MAX) ? VK_SUCCESS : VK_ERROR_FEATURE_NOT_PRESENT;
+
+
+
+
+
16678 const VkBufferCreateInfo* pBufferCreateInfo,
+
+
16680 uint32_t* pMemoryTypeIndex)
+
+
16682 VMA_ASSERT(allocator != VK_NULL_HANDLE);
+
16683 VMA_ASSERT(pBufferCreateInfo != VMA_NULL);
+
16684 VMA_ASSERT(pAllocationCreateInfo != VMA_NULL);
+
16685 VMA_ASSERT(pMemoryTypeIndex != VMA_NULL);
+
+
16687 const VkDevice hDev = allocator->m_hDevice;
+
16688 VkBuffer hBuffer = VK_NULL_HANDLE;
+
16689 VkResult res = allocator->GetVulkanFunctions().vkCreateBuffer(
+
16690 hDev, pBufferCreateInfo, allocator->GetAllocationCallbacks(), &hBuffer);
+
16691 if(res == VK_SUCCESS)
+
+
16693 VkMemoryRequirements memReq = {};
+
16694 allocator->GetVulkanFunctions().vkGetBufferMemoryRequirements(
+
16695 hDev, hBuffer, &memReq);
-
16697 allocator->GetVulkanFunctions().vkDestroyBuffer(
-
16698 hDev, hBuffer, allocator->GetAllocationCallbacks());
-
-
-
+
+
+
16699 memReq.memoryTypeBits,
+
16700 pAllocationCreateInfo,
+
-
-
-
16705 const VkImageCreateInfo* pImageCreateInfo,
-
-
16707 uint32_t* pMemoryTypeIndex)
-
-
16709 VMA_ASSERT(allocator != VK_NULL_HANDLE);
-
16710 VMA_ASSERT(pImageCreateInfo != VMA_NULL);
-
16711 VMA_ASSERT(pAllocationCreateInfo != VMA_NULL);
-
16712 VMA_ASSERT(pMemoryTypeIndex != VMA_NULL);
-
-
16714 const VkDevice hDev = allocator->m_hDevice;
-
16715 VkImage hImage = VK_NULL_HANDLE;
-
16716 VkResult res = allocator->GetVulkanFunctions().vkCreateImage(
-
16717 hDev, pImageCreateInfo, allocator->GetAllocationCallbacks(), &hImage);
-
16718 if(res == VK_SUCCESS)
-
-
16720 VkMemoryRequirements memReq = {};
-
16721 allocator->GetVulkanFunctions().vkGetImageMemoryRequirements(
-
16722 hDev, hImage, &memReq);
-
-
-
-
16726 memReq.memoryTypeBits,
-
16727 pAllocationCreateInfo,
-
+
16703 allocator->GetVulkanFunctions().vkDestroyBuffer(
+
16704 hDev, hBuffer, allocator->GetAllocationCallbacks());
+
+
+
+
+
+
+
16711 const VkImageCreateInfo* pImageCreateInfo,
+
+
16713 uint32_t* pMemoryTypeIndex)
+
+
16715 VMA_ASSERT(allocator != VK_NULL_HANDLE);
+
16716 VMA_ASSERT(pImageCreateInfo != VMA_NULL);
+
16717 VMA_ASSERT(pAllocationCreateInfo != VMA_NULL);
+
16718 VMA_ASSERT(pMemoryTypeIndex != VMA_NULL);
+
+
16720 const VkDevice hDev = allocator->m_hDevice;
+
16721 VkImage hImage = VK_NULL_HANDLE;
+
16722 VkResult res = allocator->GetVulkanFunctions().vkCreateImage(
+
16723 hDev, pImageCreateInfo, allocator->GetAllocationCallbacks(), &hImage);
+
16724 if(res == VK_SUCCESS)
+
+
16726 VkMemoryRequirements memReq = {};
+
16727 allocator->GetVulkanFunctions().vkGetImageMemoryRequirements(
+
16728 hDev, hImage, &memReq);
-
16730 allocator->GetVulkanFunctions().vkDestroyImage(
-
16731 hDev, hImage, allocator->GetAllocationCallbacks());
-
-
-
+
+
+
16732 memReq.memoryTypeBits,
+
16733 pAllocationCreateInfo,
+
-
-
-
-
-
-
16741 VMA_ASSERT(allocator && pCreateInfo && pPool);
-
-
16743 VMA_DEBUG_LOG(
"vmaCreatePool");
-
-
16745 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
16747 VkResult res = allocator->CreatePool(pCreateInfo, pPool);
+
16736 allocator->GetVulkanFunctions().vkDestroyImage(
+
16737 hDev, hImage, allocator->GetAllocationCallbacks());
+
+
+
+
+
+
+
+
+
+
16747 VMA_ASSERT(allocator && pCreateInfo && pPool);
-
16749 #if VMA_RECORDING_ENABLED
-
16750 if(allocator->GetRecorder() != VMA_NULL)
-
-
16752 allocator->GetRecorder()->RecordCreatePool(allocator->GetCurrentFrameIndex(), *pCreateInfo, *pPool);
-
-
-
-
-
-
-
-
-
-
-
16763 VMA_ASSERT(allocator);
-
-
16765 if(pool == VK_NULL_HANDLE)
-
-
-
-
-
16770 VMA_DEBUG_LOG(
"vmaDestroyPool");
-
-
16772 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
16774 #if VMA_RECORDING_ENABLED
-
16775 if(allocator->GetRecorder() != VMA_NULL)
-
-
16777 allocator->GetRecorder()->RecordDestroyPool(allocator->GetCurrentFrameIndex(), pool);
-
-
-
-
16781 allocator->DestroyPool(pool);
-
-
-
-
-
-
-
-
16789 VMA_ASSERT(allocator && pool && pPoolStats);
-
-
16791 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
16793 allocator->GetPoolStats(pool, pPoolStats);
-
-
-
-
-
-
16799 size_t* pLostAllocationCount)
-
-
16801 VMA_ASSERT(allocator && pool);
-
-
16803 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
16805 #if VMA_RECORDING_ENABLED
-
16806 if(allocator->GetRecorder() != VMA_NULL)
-
-
16808 allocator->GetRecorder()->RecordMakePoolAllocationsLost(allocator->GetCurrentFrameIndex(), pool);
-
-
-
-
16812 allocator->MakePoolAllocationsLost(pool, pLostAllocationCount);
-
-
-
-
-
16817 VMA_ASSERT(allocator && pool);
-
-
16819 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
16749 VMA_DEBUG_LOG(
"vmaCreatePool");
+
+
16751 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
16753 VkResult res = allocator->CreatePool(pCreateInfo, pPool);
+
+
16755 #if VMA_RECORDING_ENABLED
+
16756 if(allocator->GetRecorder() != VMA_NULL)
+
+
16758 allocator->GetRecorder()->RecordCreatePool(allocator->GetCurrentFrameIndex(), *pCreateInfo, *pPool);
+
+
+
+
+
+
+
+
+
+
+
16769 VMA_ASSERT(allocator);
+
+
16771 if(pool == VK_NULL_HANDLE)
+
+
+
+
+
16776 VMA_DEBUG_LOG(
"vmaDestroyPool");
+
+
16778 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
16780 #if VMA_RECORDING_ENABLED
+
16781 if(allocator->GetRecorder() != VMA_NULL)
+
+
16783 allocator->GetRecorder()->RecordDestroyPool(allocator->GetCurrentFrameIndex(), pool);
+
+
+
+
16787 allocator->DestroyPool(pool);
+
+
+
+
+
+
+
+
16795 VMA_ASSERT(allocator && pool && pPoolStats);
+
+
16797 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
16799 allocator->GetPoolStats(pool, pPoolStats);
+
+
+
+
+
+
16805 size_t* pLostAllocationCount)
+
+
16807 VMA_ASSERT(allocator && pool);
+
+
16809 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
16811 #if VMA_RECORDING_ENABLED
+
16812 if(allocator->GetRecorder() != VMA_NULL)
+
+
16814 allocator->GetRecorder()->RecordMakePoolAllocationsLost(allocator->GetCurrentFrameIndex(), pool);
+
+
+
+
16818 allocator->MakePoolAllocationsLost(pool, pLostAllocationCount);
+
-
16821 VMA_DEBUG_LOG(
"vmaCheckPoolCorruption");
-
-
16823 return allocator->CheckPoolCorruption(pool);
-
-
-
-
-
-
16829 const char** ppName)
-
-
16831 VMA_ASSERT(allocator && pool);
-
-
16833 VMA_DEBUG_LOG(
"vmaGetPoolName");
-
-
16835 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
16837 *ppName = pool->GetName();
-
-
-
-
-
-
-
-
16845 VMA_ASSERT(allocator && pool);
-
-
16847 VMA_DEBUG_LOG(
"vmaSetPoolName");
-
-
16849 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
16851 pool->SetName(pName);
+
+
+
16823 VMA_ASSERT(allocator && pool);
+
+
16825 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
16827 VMA_DEBUG_LOG(
"vmaCheckPoolCorruption");
+
+
16829 return allocator->CheckPoolCorruption(pool);
+
+
+
+
+
+
16835 const char** ppName)
+
+
16837 VMA_ASSERT(allocator && pool);
+
+
16839 VMA_DEBUG_LOG(
"vmaGetPoolName");
+
+
16841 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
16843 *ppName = pool->GetName();
+
+
+
+
+
+
+
+
16851 VMA_ASSERT(allocator && pool);
-
16853 #if VMA_RECORDING_ENABLED
-
16854 if(allocator->GetRecorder() != VMA_NULL)
-
-
16856 allocator->GetRecorder()->RecordSetPoolName(allocator->GetCurrentFrameIndex(), pool, pName);
-
-
-
-
-
-
-
16863 const VkMemoryRequirements* pVkMemoryRequirements,
-
-
-
-
-
16868 VMA_ASSERT(allocator && pVkMemoryRequirements && pCreateInfo && pAllocation);
-
-
16870 VMA_DEBUG_LOG(
"vmaAllocateMemory");
-
-
16872 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
16874 VkResult result = allocator->AllocateMemory(
-
16875 *pVkMemoryRequirements,
-
-
-
-
-
-
16881 VMA_SUBALLOCATION_TYPE_UNKNOWN,
-
-
-
-
16885 #if VMA_RECORDING_ENABLED
-
16886 if(allocator->GetRecorder() != VMA_NULL)
-
-
16888 allocator->GetRecorder()->RecordAllocateMemory(
-
16889 allocator->GetCurrentFrameIndex(),
-
16890 *pVkMemoryRequirements,
-
-
-
-
-
-
16896 if(pAllocationInfo != VMA_NULL && result == VK_SUCCESS)
-
-
16898 allocator->GetAllocationInfo(*pAllocation, pAllocationInfo);
+
16853 VMA_DEBUG_LOG(
"vmaSetPoolName");
+
+
16855 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
16857 pool->SetName(pName);
+
+
16859 #if VMA_RECORDING_ENABLED
+
16860 if(allocator->GetRecorder() != VMA_NULL)
+
+
16862 allocator->GetRecorder()->RecordSetPoolName(allocator->GetCurrentFrameIndex(), pool, pName);
+
+
+
+
+
+
+
16869 const VkMemoryRequirements* pVkMemoryRequirements,
+
+
+
+
+
16874 VMA_ASSERT(allocator && pVkMemoryRequirements && pCreateInfo && pAllocation);
+
+
16876 VMA_DEBUG_LOG(
"vmaAllocateMemory");
+
+
16878 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
16880 VkResult result = allocator->AllocateMemory(
+
16881 *pVkMemoryRequirements,
+
+
+
+
+
+
16887 VMA_SUBALLOCATION_TYPE_UNKNOWN,
+
+
+
+
16891 #if VMA_RECORDING_ENABLED
+
16892 if(allocator->GetRecorder() != VMA_NULL)
+
+
16894 allocator->GetRecorder()->RecordAllocateMemory(
+
16895 allocator->GetCurrentFrameIndex(),
+
16896 *pVkMemoryRequirements,
+
+
-
-
-
-
-
-
-
16906 const VkMemoryRequirements* pVkMemoryRequirements,
-
-
16908 size_t allocationCount,
-
-
-
-
16912 if(allocationCount == 0)
-
-
-
-
-
16917 VMA_ASSERT(allocator && pVkMemoryRequirements && pCreateInfo && pAllocations);
-
-
16919 VMA_DEBUG_LOG(
"vmaAllocateMemoryPages");
-
-
16921 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
+
16902 if(pAllocationInfo != VMA_NULL && result == VK_SUCCESS)
+
+
16904 allocator->GetAllocationInfo(*pAllocation, pAllocationInfo);
+
+
+
+
+
+
+
+
16912 const VkMemoryRequirements* pVkMemoryRequirements,
+
+
16914 size_t allocationCount,
+
+
+
+
16918 if(allocationCount == 0)
+
+
+
-
16923 VkResult result = allocator->AllocateMemory(
-
16924 *pVkMemoryRequirements,
-
-
-
-
-
-
16930 VMA_SUBALLOCATION_TYPE_UNKNOWN,
-
-
-
-
16934 #if VMA_RECORDING_ENABLED
-
16935 if(allocator->GetRecorder() != VMA_NULL)
-
-
16937 allocator->GetRecorder()->RecordAllocateMemoryPages(
-
16938 allocator->GetCurrentFrameIndex(),
-
16939 *pVkMemoryRequirements,
-
-
16941 (uint64_t)allocationCount,
-
-
-
-
-
16946 if(pAllocationInfo != VMA_NULL && result == VK_SUCCESS)
-
-
16948 for(
size_t i = 0; i < allocationCount; ++i)
-
-
16950 allocator->GetAllocationInfo(pAllocations[i], pAllocationInfo + i);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
16964 VMA_ASSERT(allocator && buffer != VK_NULL_HANDLE && pCreateInfo && pAllocation);
-
-
16966 VMA_DEBUG_LOG(
"vmaAllocateMemoryForBuffer");
-
-
16968 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
16970 VkMemoryRequirements vkMemReq = {};
-
16971 bool requiresDedicatedAllocation =
false;
-
16972 bool prefersDedicatedAllocation =
false;
-
16973 allocator->GetBufferMemoryRequirements(buffer, vkMemReq,
-
16974 requiresDedicatedAllocation,
-
16975 prefersDedicatedAllocation);
-
-
16977 VkResult result = allocator->AllocateMemory(
-
-
16979 requiresDedicatedAllocation,
-
16980 prefersDedicatedAllocation,
-
-
-
-
16984 VMA_SUBALLOCATION_TYPE_BUFFER,
-
-
-
-
16988 #if VMA_RECORDING_ENABLED
-
16989 if(allocator->GetRecorder() != VMA_NULL)
-
-
16991 allocator->GetRecorder()->RecordAllocateMemoryForBuffer(
-
16992 allocator->GetCurrentFrameIndex(),
-
-
16994 requiresDedicatedAllocation,
-
16995 prefersDedicatedAllocation,
-
-
-
-
-
-
17001 if(pAllocationInfo && result == VK_SUCCESS)
-
-
17003 allocator->GetAllocationInfo(*pAllocation, pAllocationInfo);
+
16923 VMA_ASSERT(allocator && pVkMemoryRequirements && pCreateInfo && pAllocations);
+
+
16925 VMA_DEBUG_LOG(
"vmaAllocateMemoryPages");
+
+
16927 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
16929 VkResult result = allocator->AllocateMemory(
+
16930 *pVkMemoryRequirements,
+
+
+
+
+
+
16936 VMA_SUBALLOCATION_TYPE_UNKNOWN,
+
+
+
+
16940 #if VMA_RECORDING_ENABLED
+
16941 if(allocator->GetRecorder() != VMA_NULL)
+
+
16943 allocator->GetRecorder()->RecordAllocateMemoryPages(
+
16944 allocator->GetCurrentFrameIndex(),
+
16945 *pVkMemoryRequirements,
+
+
16947 (uint64_t)allocationCount,
+
+
+
+
+
16952 if(pAllocationInfo != VMA_NULL && result == VK_SUCCESS)
+
+
16954 for(
size_t i = 0; i < allocationCount; ++i)
+
+
16956 allocator->GetAllocationInfo(pAllocations[i], pAllocationInfo + i);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
16970 VMA_ASSERT(allocator && buffer != VK_NULL_HANDLE && pCreateInfo && pAllocation);
+
+
16972 VMA_DEBUG_LOG(
"vmaAllocateMemoryForBuffer");
+
+
16974 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
16976 VkMemoryRequirements vkMemReq = {};
+
16977 bool requiresDedicatedAllocation =
false;
+
16978 bool prefersDedicatedAllocation =
false;
+
16979 allocator->GetBufferMemoryRequirements(buffer, vkMemReq,
+
16980 requiresDedicatedAllocation,
+
16981 prefersDedicatedAllocation);
+
+
16983 VkResult result = allocator->AllocateMemory(
+
+
16985 requiresDedicatedAllocation,
+
16986 prefersDedicatedAllocation,
+
+
+
+
16990 VMA_SUBALLOCATION_TYPE_BUFFER,
+
+
+
+
16994 #if VMA_RECORDING_ENABLED
+
16995 if(allocator->GetRecorder() != VMA_NULL)
+
+
16997 allocator->GetRecorder()->RecordAllocateMemoryForBuffer(
+
16998 allocator->GetCurrentFrameIndex(),
+
+
17000 requiresDedicatedAllocation,
+
17001 prefersDedicatedAllocation,
+
+
-
-
-
-
-
-
-
-
-
-
-
-
17016 VMA_ASSERT(allocator && image != VK_NULL_HANDLE && pCreateInfo && pAllocation);
-
-
17018 VMA_DEBUG_LOG(
"vmaAllocateMemoryForImage");
-
-
17020 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17022 VkMemoryRequirements vkMemReq = {};
-
17023 bool requiresDedicatedAllocation =
false;
-
17024 bool prefersDedicatedAllocation =
false;
-
17025 allocator->GetImageMemoryRequirements(image, vkMemReq,
-
17026 requiresDedicatedAllocation, prefersDedicatedAllocation);
+
+
+
17007 if(pAllocationInfo && result == VK_SUCCESS)
+
+
17009 allocator->GetAllocationInfo(*pAllocation, pAllocationInfo);
+
+
+
+
+
+
+
+
+
+
+
+
+
17022 VMA_ASSERT(allocator && image != VK_NULL_HANDLE && pCreateInfo && pAllocation);
+
+
17024 VMA_DEBUG_LOG(
"vmaAllocateMemoryForImage");
+
+
17026 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
17028 VkResult result = allocator->AllocateMemory(
-
-
17030 requiresDedicatedAllocation,
-
17031 prefersDedicatedAllocation,
-
-
-
-
17035 VMA_SUBALLOCATION_TYPE_IMAGE_UNKNOWN,
-
-
-
-
17039 #if VMA_RECORDING_ENABLED
-
17040 if(allocator->GetRecorder() != VMA_NULL)
-
-
17042 allocator->GetRecorder()->RecordAllocateMemoryForImage(
-
17043 allocator->GetCurrentFrameIndex(),
-
-
17045 requiresDedicatedAllocation,
-
17046 prefersDedicatedAllocation,
-
-
-
-
-
-
17052 if(pAllocationInfo && result == VK_SUCCESS)
-
-
17054 allocator->GetAllocationInfo(*pAllocation, pAllocationInfo);
+
17028 VkMemoryRequirements vkMemReq = {};
+
17029 bool requiresDedicatedAllocation =
false;
+
17030 bool prefersDedicatedAllocation =
false;
+
17031 allocator->GetImageMemoryRequirements(image, vkMemReq,
+
17032 requiresDedicatedAllocation, prefersDedicatedAllocation);
+
+
17034 VkResult result = allocator->AllocateMemory(
+
+
17036 requiresDedicatedAllocation,
+
17037 prefersDedicatedAllocation,
+
+
+
+
17041 VMA_SUBALLOCATION_TYPE_IMAGE_UNKNOWN,
+
+
+
+
17045 #if VMA_RECORDING_ENABLED
+
17046 if(allocator->GetRecorder() != VMA_NULL)
+
+
17048 allocator->GetRecorder()->RecordAllocateMemoryForImage(
+
17049 allocator->GetCurrentFrameIndex(),
+
+
17051 requiresDedicatedAllocation,
+
17052 prefersDedicatedAllocation,
+
+
-
-
-
-
-
-
-
-
-
17064 VMA_ASSERT(allocator);
-
-
17066 if(allocation == VK_NULL_HANDLE)
-
-
-
-
-
17071 VMA_DEBUG_LOG(
"vmaFreeMemory");
-
-
17073 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17075 #if VMA_RECORDING_ENABLED
-
17076 if(allocator->GetRecorder() != VMA_NULL)
-
-
17078 allocator->GetRecorder()->RecordFreeMemory(
-
17079 allocator->GetCurrentFrameIndex(),
-
-
-
-
-
17084 allocator->FreeMemory(
-
-
-
-
-
-
-
17091 size_t allocationCount,
-
-
-
17094 if(allocationCount == 0)
-
-
-
-
-
17099 VMA_ASSERT(allocator);
-
-
17101 VMA_DEBUG_LOG(
"vmaFreeMemoryPages");
-
-
17103 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
+
17058 if(pAllocationInfo && result == VK_SUCCESS)
+
+
17060 allocator->GetAllocationInfo(*pAllocation, pAllocationInfo);
+
+
+
+
+
+
+
+
+
+
17070 VMA_ASSERT(allocator);
+
+
17072 if(allocation == VK_NULL_HANDLE)
+
+
+
+
+
17077 VMA_DEBUG_LOG(
"vmaFreeMemory");
+
+
17079 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17081 #if VMA_RECORDING_ENABLED
+
17082 if(allocator->GetRecorder() != VMA_NULL)
+
+
17084 allocator->GetRecorder()->RecordFreeMemory(
+
17085 allocator->GetCurrentFrameIndex(),
+
+
+
+
+
17090 allocator->FreeMemory(
+
+
+
+
+
+
+
17097 size_t allocationCount,
+
+
+
17100 if(allocationCount == 0)
+
+
+
-
17105 #if VMA_RECORDING_ENABLED
-
17106 if(allocator->GetRecorder() != VMA_NULL)
-
-
17108 allocator->GetRecorder()->RecordFreeMemoryPages(
-
17109 allocator->GetCurrentFrameIndex(),
-
17110 (uint64_t)allocationCount,
-
-
-
-
-
17115 allocator->FreeMemory(allocationCount, pAllocations);
-
-
-
-
-
-
17121 VkDeviceSize newSize)
-
-
17123 VMA_ASSERT(allocator && allocation);
-
-
17125 VMA_DEBUG_LOG(
"vmaResizeAllocation");
-
-
17127 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17129 return allocator->ResizeAllocation(allocation, newSize);
-
-
-
-
-
-
-
-
17137 VMA_ASSERT(allocator && allocation && pAllocationInfo);
-
-
17139 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17141 #if VMA_RECORDING_ENABLED
-
17142 if(allocator->GetRecorder() != VMA_NULL)
-
-
17144 allocator->GetRecorder()->RecordGetAllocationInfo(
-
17145 allocator->GetCurrentFrameIndex(),
-
-
-
-
-
17150 allocator->GetAllocationInfo(allocation, pAllocationInfo);
-
-
-
-
-
-
-
17157 VMA_ASSERT(allocator && allocation);
+
17105 VMA_ASSERT(allocator);
+
+
17107 VMA_DEBUG_LOG(
"vmaFreeMemoryPages");
+
+
17109 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17111 #if VMA_RECORDING_ENABLED
+
17112 if(allocator->GetRecorder() != VMA_NULL)
+
+
17114 allocator->GetRecorder()->RecordFreeMemoryPages(
+
17115 allocator->GetCurrentFrameIndex(),
+
17116 (uint64_t)allocationCount,
+
+
+
+
+
17121 allocator->FreeMemory(allocationCount, pAllocations);
+
+
+
+
+
+
17127 VkDeviceSize newSize)
+
+
17129 VMA_ASSERT(allocator && allocation);
+
+
17131 VMA_DEBUG_LOG(
"vmaResizeAllocation");
+
+
17133 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17135 return allocator->ResizeAllocation(allocation, newSize);
+
+
+
+
+
+
+
+
17143 VMA_ASSERT(allocator && allocation && pAllocationInfo);
+
+
17145 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17147 #if VMA_RECORDING_ENABLED
+
17148 if(allocator->GetRecorder() != VMA_NULL)
+
+
17150 allocator->GetRecorder()->RecordGetAllocationInfo(
+
17151 allocator->GetCurrentFrameIndex(),
+
+
+
+
+
17156 allocator->GetAllocationInfo(allocation, pAllocationInfo);
+
-
17159 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17161 #if VMA_RECORDING_ENABLED
-
17162 if(allocator->GetRecorder() != VMA_NULL)
-
-
17164 allocator->GetRecorder()->RecordTouchAllocation(
-
17165 allocator->GetCurrentFrameIndex(),
-
-
-
-
-
17170 return allocator->TouchAllocation(allocation);
-
-
-
-
-
-
-
-
17178 VMA_ASSERT(allocator && allocation);
-
-
17180 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17182 allocation->SetUserData(allocator, pUserData);
-
-
17184 #if VMA_RECORDING_ENABLED
-
17185 if(allocator->GetRecorder() != VMA_NULL)
-
-
17187 allocator->GetRecorder()->RecordSetAllocationUserData(
-
17188 allocator->GetCurrentFrameIndex(),
-
-
-
-
-
-
-
-
-
-
-
17199 VMA_ASSERT(allocator && pAllocation);
+
+
+
+
+
17163 VMA_ASSERT(allocator && allocation);
+
+
17165 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17167 #if VMA_RECORDING_ENABLED
+
17168 if(allocator->GetRecorder() != VMA_NULL)
+
+
17170 allocator->GetRecorder()->RecordTouchAllocation(
+
17171 allocator->GetCurrentFrameIndex(),
+
+
+
+
+
17176 return allocator->TouchAllocation(allocation);
+
+
+
+
+
+
+
+
17184 VMA_ASSERT(allocator && allocation);
+
+
17186 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17188 allocation->SetUserData(allocator, pUserData);
+
+
17190 #if VMA_RECORDING_ENABLED
+
17191 if(allocator->GetRecorder() != VMA_NULL)
+
+
17193 allocator->GetRecorder()->RecordSetAllocationUserData(
+
17194 allocator->GetCurrentFrameIndex(),
+
+
+
+
+
-
17201 VMA_DEBUG_GLOBAL_MUTEX_LOCK;
-
-
17203 allocator->CreateLostAllocation(pAllocation);
-
-
17205 #if VMA_RECORDING_ENABLED
-
17206 if(allocator->GetRecorder() != VMA_NULL)
-
-
17208 allocator->GetRecorder()->RecordCreateLostAllocation(
-
17209 allocator->GetCurrentFrameIndex(),
-
-
-
-
-
-
-
-
-
-
-
17220 VMA_ASSERT(allocator && allocation && ppData);
-
-
17222 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17224 VkResult res = allocator->Map(allocation, ppData);
-
-
17226 #if VMA_RECORDING_ENABLED
-
17227 if(allocator->GetRecorder() != VMA_NULL)
-
-
17229 allocator->GetRecorder()->RecordMapMemory(
-
17230 allocator->GetCurrentFrameIndex(),
-
-
-
-
-
-
-
-
-
-
-
-
17242 VMA_ASSERT(allocator && allocation);
+
+
+
+
+
17205 VMA_ASSERT(allocator && pAllocation);
+
+
17207 VMA_DEBUG_GLOBAL_MUTEX_LOCK;
+
+
17209 allocator->CreateLostAllocation(pAllocation);
+
+
17211 #if VMA_RECORDING_ENABLED
+
17212 if(allocator->GetRecorder() != VMA_NULL)
+
+
17214 allocator->GetRecorder()->RecordCreateLostAllocation(
+
17215 allocator->GetCurrentFrameIndex(),
+
+
+
+
+
+
+
+
+
+
+
17226 VMA_ASSERT(allocator && allocation && ppData);
+
+
17228 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17230 VkResult res = allocator->Map(allocation, ppData);
+
+
17232 #if VMA_RECORDING_ENABLED
+
17233 if(allocator->GetRecorder() != VMA_NULL)
+
+
17235 allocator->GetRecorder()->RecordMapMemory(
+
17236 allocator->GetCurrentFrameIndex(),
+
+
+
+
+
+
-
17244 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17246 #if VMA_RECORDING_ENABLED
-
17247 if(allocator->GetRecorder() != VMA_NULL)
-
-
17249 allocator->GetRecorder()->RecordUnmapMemory(
-
17250 allocator->GetCurrentFrameIndex(),
-
-
-
-
-
17255 allocator->Unmap(allocation);
-
-
-
-
-
17260 VMA_ASSERT(allocator && allocation);
-
-
17262 VMA_DEBUG_LOG(
"vmaFlushAllocation");
+
+
+
+
+
17248 VMA_ASSERT(allocator && allocation);
+
+
17250 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17252 #if VMA_RECORDING_ENABLED
+
17253 if(allocator->GetRecorder() != VMA_NULL)
+
+
17255 allocator->GetRecorder()->RecordUnmapMemory(
+
17256 allocator->GetCurrentFrameIndex(),
+
+
+
+
+
17261 allocator->Unmap(allocation);
+
-
17264 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17266 allocator->FlushOrInvalidateAllocation(allocation, offset, size, VMA_CACHE_FLUSH);
+
+
+
17266 VMA_ASSERT(allocator && allocation);
-
17268 #if VMA_RECORDING_ENABLED
-
17269 if(allocator->GetRecorder() != VMA_NULL)
-
-
17271 allocator->GetRecorder()->RecordFlushAllocation(
-
17272 allocator->GetCurrentFrameIndex(),
-
17273 allocation, offset, size);
-
-
-
-
-
-
-
17280 VMA_ASSERT(allocator && allocation);
-
-
17282 VMA_DEBUG_LOG(
"vmaInvalidateAllocation");
+
17268 VMA_DEBUG_LOG(
"vmaFlushAllocation");
+
+
17270 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17272 allocator->FlushOrInvalidateAllocation(allocation, offset, size, VMA_CACHE_FLUSH);
+
+
17274 #if VMA_RECORDING_ENABLED
+
17275 if(allocator->GetRecorder() != VMA_NULL)
+
+
17277 allocator->GetRecorder()->RecordFlushAllocation(
+
17278 allocator->GetCurrentFrameIndex(),
+
17279 allocation, offset, size);
+
+
+
-
17284 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17286 allocator->FlushOrInvalidateAllocation(allocation, offset, size, VMA_CACHE_INVALIDATE);
+
+
+
17286 VMA_ASSERT(allocator && allocation);
-
17288 #if VMA_RECORDING_ENABLED
-
17289 if(allocator->GetRecorder() != VMA_NULL)
-
-
17291 allocator->GetRecorder()->RecordInvalidateAllocation(
-
17292 allocator->GetCurrentFrameIndex(),
-
17293 allocation, offset, size);
-
-
-
-
-
-
-
17300 VMA_ASSERT(allocator);
-
-
17302 VMA_DEBUG_LOG(
"vmaCheckCorruption");
+
17288 VMA_DEBUG_LOG(
"vmaInvalidateAllocation");
+
+
17290 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17292 allocator->FlushOrInvalidateAllocation(allocation, offset, size, VMA_CACHE_INVALIDATE);
+
+
17294 #if VMA_RECORDING_ENABLED
+
17295 if(allocator->GetRecorder() != VMA_NULL)
+
+
17297 allocator->GetRecorder()->RecordInvalidateAllocation(
+
17298 allocator->GetCurrentFrameIndex(),
+
17299 allocation, offset, size);
+
+
+
-
17304 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17306 return allocator->CheckCorruption(memoryTypeBits);
-
-
-
-
-
-
17312 size_t allocationCount,
-
17313 VkBool32* pAllocationsChanged,
-
-
-
-
-
-
-
-
-
-
17323 if(pDefragmentationInfo != VMA_NULL)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
17337 if(res == VK_NOT_READY)
-
-
-
-
-
-
-
-
-
-
-
-
-
17350 VMA_ASSERT(allocator && pInfo && pContext);
-
-
-
-
-
-
+
+
+
17306 VMA_ASSERT(allocator);
+
+
17308 VMA_DEBUG_LOG(
"vmaCheckCorruption");
+
+
17310 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17312 return allocator->CheckCorruption(memoryTypeBits);
+
+
+
+
+
+
17318 size_t allocationCount,
+
17319 VkBool32* pAllocationsChanged,
+
+
+
+
+
+
+
+
+
+
17329 if(pDefragmentationInfo != VMA_NULL)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
17343 if(res == VK_NOT_READY)
+
+
+
+
+
+
+
+
+
+
+
+
+
17356 VMA_ASSERT(allocator && pInfo && pContext);
-
-
-
-
17361 VMA_HEAVY_ASSERT(VmaValidatePointerArray(pInfo->
poolCount, pInfo->
pPools));
-
-
17363 VMA_DEBUG_LOG(
"vmaDefragmentationBegin");
-
-
17365 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17367 VkResult res = allocator->DefragmentationBegin(*pInfo, pStats, pContext);
+
+
+
+
+
+
+
+
+
+
17367 VMA_HEAVY_ASSERT(VmaValidatePointerArray(pInfo->
poolCount, pInfo->
pPools));
-
17369 #if VMA_RECORDING_ENABLED
-
17370 if(allocator->GetRecorder() != VMA_NULL)
-
-
17372 allocator->GetRecorder()->RecordDefragmentationBegin(
-
17373 allocator->GetCurrentFrameIndex(), *pInfo, *pContext);
-
-
-
-
-
-
-
-
-
-
-
17384 VMA_ASSERT(allocator);
+
17369 VMA_DEBUG_LOG(
"vmaDefragmentationBegin");
+
+
17371 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17373 VkResult res = allocator->DefragmentationBegin(*pInfo, pStats, pContext);
+
+
17375 #if VMA_RECORDING_ENABLED
+
17376 if(allocator->GetRecorder() != VMA_NULL)
+
+
17378 allocator->GetRecorder()->RecordDefragmentationBegin(
+
17379 allocator->GetCurrentFrameIndex(), *pInfo, *pContext);
+
+
+
+
+
-
17386 VMA_DEBUG_LOG(
"vmaDefragmentationEnd");
-
-
17388 if(context != VK_NULL_HANDLE)
-
-
17390 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
+
+
+
17390 VMA_ASSERT(allocator);
-
17392 #if VMA_RECORDING_ENABLED
-
17393 if(allocator->GetRecorder() != VMA_NULL)
-
-
17395 allocator->GetRecorder()->RecordDefragmentationEnd(
-
17396 allocator->GetCurrentFrameIndex(), context);
-
-
-
-
17400 return allocator->DefragmentationEnd(context);
-
-
-
-
-
-
-
-
-
-
-
-
-
17413 VMA_ASSERT(allocator && allocation && buffer);
-
-
17415 VMA_DEBUG_LOG(
"vmaBindBufferMemory");
-
-
17417 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17419 return allocator->BindBufferMemory(allocation, 0, buffer, VMA_NULL);
-
-
-
-
-
-
17425 VkDeviceSize allocationLocalOffset,
-
-
-
-
17429 VMA_ASSERT(allocator && allocation && buffer);
-
-
17431 VMA_DEBUG_LOG(
"vmaBindBufferMemory2");
-
-
17433 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17435 return allocator->BindBufferMemory(allocation, allocationLocalOffset, buffer, pNext);
-
-
-
-
-
-
-
-
17443 VMA_ASSERT(allocator && allocation && image);
-
-
17445 VMA_DEBUG_LOG(
"vmaBindImageMemory");
-
-
17447 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17449 return allocator->BindImageMemory(allocation, 0, image, VMA_NULL);
-
-
-
-
-
-
17455 VkDeviceSize allocationLocalOffset,
-
-
-
-
17459 VMA_ASSERT(allocator && allocation && image);
-
-
17461 VMA_DEBUG_LOG(
"vmaBindImageMemory2");
-
-
17463 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17465 return allocator->BindImageMemory(allocation, allocationLocalOffset, image, pNext);
-
-
-
-
-
17470 const VkBufferCreateInfo* pBufferCreateInfo,
-
-
-
-
-
-
17476 VMA_ASSERT(allocator && pBufferCreateInfo && pAllocationCreateInfo && pBuffer && pAllocation);
-
-
17478 if(pBufferCreateInfo->size == 0)
-
-
17480 return VK_ERROR_VALIDATION_FAILED_EXT;
-
-
-
17483 VMA_DEBUG_LOG(
"vmaCreateBuffer");
-
-
17485 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17487 *pBuffer = VK_NULL_HANDLE;
-
17488 *pAllocation = VK_NULL_HANDLE;
-
-
-
17491 VkResult res = (*allocator->GetVulkanFunctions().vkCreateBuffer)(
-
17492 allocator->m_hDevice,
-
-
17494 allocator->GetAllocationCallbacks(),
-
-
-
-
-
17499 VkMemoryRequirements vkMemReq = {};
-
17500 bool requiresDedicatedAllocation =
false;
-
17501 bool prefersDedicatedAllocation =
false;
-
17502 allocator->GetBufferMemoryRequirements(*pBuffer, vkMemReq,
-
17503 requiresDedicatedAllocation, prefersDedicatedAllocation);
-
-
-
-
17507 if((pBufferCreateInfo->usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT) != 0)
-
-
17509 VMA_ASSERT(vkMemReq.alignment %
-
17510 allocator->m_PhysicalDeviceProperties.limits.minTexelBufferOffsetAlignment == 0);
-
-
17512 if((pBufferCreateInfo->usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) != 0)
-
-
17514 VMA_ASSERT(vkMemReq.alignment %
-
17515 allocator->m_PhysicalDeviceProperties.limits.minUniformBufferOffsetAlignment == 0);
-
-
17517 if((pBufferCreateInfo->usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT) != 0)
-
-
17519 VMA_ASSERT(vkMemReq.alignment %
-
17520 allocator->m_PhysicalDeviceProperties.limits.minStorageBufferOffsetAlignment == 0);
-
-
-
-
17524 res = allocator->AllocateMemory(
-
-
17526 requiresDedicatedAllocation,
-
17527 prefersDedicatedAllocation,
-
-
-
17530 *pAllocationCreateInfo,
-
17531 VMA_SUBALLOCATION_TYPE_BUFFER,
-
-
-
-
17535 #if VMA_RECORDING_ENABLED
-
17536 if(allocator->GetRecorder() != VMA_NULL)
-
-
17538 allocator->GetRecorder()->RecordCreateBuffer(
-
17539 allocator->GetCurrentFrameIndex(),
-
17540 *pBufferCreateInfo,
-
17541 *pAllocationCreateInfo,
-
-
-
-
-
-
-
-
-
-
17551 res = allocator->BindBufferMemory(*pAllocation, 0, *pBuffer, VMA_NULL);
-
-
-
-
-
17556 #if VMA_STATS_STRING_ENABLED
-
17557 (*pAllocation)->InitBufferImageUsage(pBufferCreateInfo->usage);
-
-
17559 if(pAllocationInfo != VMA_NULL)
-
-
17561 allocator->GetAllocationInfo(*pAllocation, pAllocationInfo);
-
-
-
-
-
17566 allocator->FreeMemory(
-
-
-
17569 *pAllocation = VK_NULL_HANDLE;
-
17570 (*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, *pBuffer, allocator->GetAllocationCallbacks());
-
17571 *pBuffer = VK_NULL_HANDLE;
-
-
-
17574 (*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, *pBuffer, allocator->GetAllocationCallbacks());
-
17575 *pBuffer = VK_NULL_HANDLE;
-
-
-
-
-
-
-
-
-
-
-
17586 VMA_ASSERT(allocator);
-
-
17588 if(buffer == VK_NULL_HANDLE && allocation == VK_NULL_HANDLE)
-
-
-
-
-
17593 VMA_DEBUG_LOG(
"vmaDestroyBuffer");
-
-
17595 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17597 #if VMA_RECORDING_ENABLED
-
17598 if(allocator->GetRecorder() != VMA_NULL)
-
-
17600 allocator->GetRecorder()->RecordDestroyBuffer(
-
17601 allocator->GetCurrentFrameIndex(),
-
-
-
-
-
17606 if(buffer != VK_NULL_HANDLE)
-
-
17608 (*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, buffer, allocator->GetAllocationCallbacks());
+
17392 VMA_DEBUG_LOG(
"vmaDefragmentationEnd");
+
+
17394 if(context != VK_NULL_HANDLE)
+
+
17396 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17398 #if VMA_RECORDING_ENABLED
+
17399 if(allocator->GetRecorder() != VMA_NULL)
+
+
17401 allocator->GetRecorder()->RecordDefragmentationEnd(
+
17402 allocator->GetCurrentFrameIndex(), context);
+
+
+
+
17406 return allocator->DefragmentationEnd(context);
+
+
+
+
+
+
+
+
+
+
+
+
+
17419 VMA_ASSERT(allocator && allocation && buffer);
+
+
17421 VMA_DEBUG_LOG(
"vmaBindBufferMemory");
+
+
17423 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17425 return allocator->BindBufferMemory(allocation, 0, buffer, VMA_NULL);
+
+
+
+
+
+
17431 VkDeviceSize allocationLocalOffset,
+
+
+
+
17435 VMA_ASSERT(allocator && allocation && buffer);
+
+
17437 VMA_DEBUG_LOG(
"vmaBindBufferMemory2");
+
+
17439 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17441 return allocator->BindBufferMemory(allocation, allocationLocalOffset, buffer, pNext);
+
+
+
+
+
+
+
+
17449 VMA_ASSERT(allocator && allocation && image);
+
+
17451 VMA_DEBUG_LOG(
"vmaBindImageMemory");
+
+
17453 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17455 return allocator->BindImageMemory(allocation, 0, image, VMA_NULL);
+
+
+
+
+
+
17461 VkDeviceSize allocationLocalOffset,
+
+
+
+
17465 VMA_ASSERT(allocator && allocation && image);
+
+
17467 VMA_DEBUG_LOG(
"vmaBindImageMemory2");
+
+
17469 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17471 return allocator->BindImageMemory(allocation, allocationLocalOffset, image, pNext);
+
+
+
+
+
17476 const VkBufferCreateInfo* pBufferCreateInfo,
+
+
+
+
+
+
17482 VMA_ASSERT(allocator && pBufferCreateInfo && pAllocationCreateInfo && pBuffer && pAllocation);
+
+
17484 if(pBufferCreateInfo->size == 0)
+
+
17486 return VK_ERROR_VALIDATION_FAILED_EXT;
+
+
+
17489 VMA_DEBUG_LOG(
"vmaCreateBuffer");
+
+
17491 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17493 *pBuffer = VK_NULL_HANDLE;
+
17494 *pAllocation = VK_NULL_HANDLE;
+
+
+
17497 VkResult res = (*allocator->GetVulkanFunctions().vkCreateBuffer)(
+
17498 allocator->m_hDevice,
+
+
17500 allocator->GetAllocationCallbacks(),
+
+
+
+
+
17505 VkMemoryRequirements vkMemReq = {};
+
17506 bool requiresDedicatedAllocation =
false;
+
17507 bool prefersDedicatedAllocation =
false;
+
17508 allocator->GetBufferMemoryRequirements(*pBuffer, vkMemReq,
+
17509 requiresDedicatedAllocation, prefersDedicatedAllocation);
+
+
+
+
17513 if((pBufferCreateInfo->usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT) != 0)
+
+
17515 VMA_ASSERT(vkMemReq.alignment %
+
17516 allocator->m_PhysicalDeviceProperties.limits.minTexelBufferOffsetAlignment == 0);
+
+
17518 if((pBufferCreateInfo->usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) != 0)
+
+
17520 VMA_ASSERT(vkMemReq.alignment %
+
17521 allocator->m_PhysicalDeviceProperties.limits.minUniformBufferOffsetAlignment == 0);
+
+
17523 if((pBufferCreateInfo->usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT) != 0)
+
+
17525 VMA_ASSERT(vkMemReq.alignment %
+
17526 allocator->m_PhysicalDeviceProperties.limits.minStorageBufferOffsetAlignment == 0);
+
+
+
+
17530 res = allocator->AllocateMemory(
+
+
17532 requiresDedicatedAllocation,
+
17533 prefersDedicatedAllocation,
+
+
+
17536 *pAllocationCreateInfo,
+
17537 VMA_SUBALLOCATION_TYPE_BUFFER,
+
+
+
+
17541 #if VMA_RECORDING_ENABLED
+
17542 if(allocator->GetRecorder() != VMA_NULL)
+
+
17544 allocator->GetRecorder()->RecordCreateBuffer(
+
17545 allocator->GetCurrentFrameIndex(),
+
17546 *pBufferCreateInfo,
+
17547 *pAllocationCreateInfo,
+
+
+
+
+
+
+
+
+
+
17557 res = allocator->BindBufferMemory(*pAllocation, 0, *pBuffer, VMA_NULL);
+
+
+
+
+
17562 #if VMA_STATS_STRING_ENABLED
+
17563 (*pAllocation)->InitBufferImageUsage(pBufferCreateInfo->usage);
+
+
17565 if(pAllocationInfo != VMA_NULL)
+
+
17567 allocator->GetAllocationInfo(*pAllocation, pAllocationInfo);
+
+
+
+
+
17572 allocator->FreeMemory(
+
+
+
17575 *pAllocation = VK_NULL_HANDLE;
+
17576 (*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, *pBuffer, allocator->GetAllocationCallbacks());
+
17577 *pBuffer = VK_NULL_HANDLE;
+
+
+
17580 (*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, *pBuffer, allocator->GetAllocationCallbacks());
+
17581 *pBuffer = VK_NULL_HANDLE;
+
+
+
+
+
+
+
+
+
+
+
17592 VMA_ASSERT(allocator);
+
+
17594 if(buffer == VK_NULL_HANDLE && allocation == VK_NULL_HANDLE)
+
+
+
+
+
17599 VMA_DEBUG_LOG(
"vmaDestroyBuffer");
+
+
17601 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17603 #if VMA_RECORDING_ENABLED
+
17604 if(allocator->GetRecorder() != VMA_NULL)
+
+
17606 allocator->GetRecorder()->RecordDestroyBuffer(
+
17607 allocator->GetCurrentFrameIndex(),
+
-
-
17611 if(allocation != VK_NULL_HANDLE)
-
-
17613 allocator->FreeMemory(
-
-
-
-
-
-
-
-
17621 const VkImageCreateInfo* pImageCreateInfo,
-
-
-
-
-
-
17627 VMA_ASSERT(allocator && pImageCreateInfo && pAllocationCreateInfo && pImage && pAllocation);
-
-
17629 if(pImageCreateInfo->extent.width == 0 ||
-
17630 pImageCreateInfo->extent.height == 0 ||
-
17631 pImageCreateInfo->extent.depth == 0 ||
-
17632 pImageCreateInfo->mipLevels == 0 ||
-
17633 pImageCreateInfo->arrayLayers == 0)
-
-
17635 return VK_ERROR_VALIDATION_FAILED_EXT;
-
-
-
17638 VMA_DEBUG_LOG(
"vmaCreateImage");
-
-
17640 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17642 *pImage = VK_NULL_HANDLE;
-
17643 *pAllocation = VK_NULL_HANDLE;
-
-
-
17646 VkResult res = (*allocator->GetVulkanFunctions().vkCreateImage)(
-
17647 allocator->m_hDevice,
-
-
17649 allocator->GetAllocationCallbacks(),
-
-
-
-
17653 VmaSuballocationType suballocType = pImageCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL ?
-
17654 VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL :
-
17655 VMA_SUBALLOCATION_TYPE_IMAGE_LINEAR;
-
-
-
17658 VkMemoryRequirements vkMemReq = {};
-
17659 bool requiresDedicatedAllocation =
false;
-
17660 bool prefersDedicatedAllocation =
false;
-
17661 allocator->GetImageMemoryRequirements(*pImage, vkMemReq,
-
17662 requiresDedicatedAllocation, prefersDedicatedAllocation);
-
-
17664 res = allocator->AllocateMemory(
-
-
17666 requiresDedicatedAllocation,
-
17667 prefersDedicatedAllocation,
-
-
-
17670 *pAllocationCreateInfo,
-
-
-
-
-
17675 #if VMA_RECORDING_ENABLED
-
17676 if(allocator->GetRecorder() != VMA_NULL)
-
-
17678 allocator->GetRecorder()->RecordCreateImage(
-
17679 allocator->GetCurrentFrameIndex(),
-
-
17681 *pAllocationCreateInfo,
-
-
-
-
-
-
-
-
-
-
17691 res = allocator->BindImageMemory(*pAllocation, 0, *pImage, VMA_NULL);
-
-
-
-
-
17696 #if VMA_STATS_STRING_ENABLED
-
17697 (*pAllocation)->InitBufferImageUsage(pImageCreateInfo->usage);
-
-
17699 if(pAllocationInfo != VMA_NULL)
-
-
17701 allocator->GetAllocationInfo(*pAllocation, pAllocationInfo);
-
-
-
-
-
17706 allocator->FreeMemory(
-
-
-
17709 *pAllocation = VK_NULL_HANDLE;
-
17710 (*allocator->GetVulkanFunctions().vkDestroyImage)(allocator->m_hDevice, *pImage, allocator->GetAllocationCallbacks());
-
17711 *pImage = VK_NULL_HANDLE;
-
-
-
17714 (*allocator->GetVulkanFunctions().vkDestroyImage)(allocator->m_hDevice, *pImage, allocator->GetAllocationCallbacks());
-
17715 *pImage = VK_NULL_HANDLE;
-
-
-
-
-
-
-
-
-
-
-
17726 VMA_ASSERT(allocator);
-
-
17728 if(image == VK_NULL_HANDLE && allocation == VK_NULL_HANDLE)
-
-
-
-
-
17733 VMA_DEBUG_LOG(
"vmaDestroyImage");
-
-
17735 VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
-
17737 #if VMA_RECORDING_ENABLED
-
17738 if(allocator->GetRecorder() != VMA_NULL)
-
-
17740 allocator->GetRecorder()->RecordDestroyImage(
-
17741 allocator->GetCurrentFrameIndex(),
-
-
-
-
-
17746 if(image != VK_NULL_HANDLE)
-
-
17748 (*allocator->GetVulkanFunctions().vkDestroyImage)(allocator->m_hDevice, image, allocator->GetAllocationCallbacks());
+
+
+
17612 if(buffer != VK_NULL_HANDLE)
+
+
17614 (*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, buffer, allocator->GetAllocationCallbacks());
+
+
+
17617 if(allocation != VK_NULL_HANDLE)
+
+
17619 allocator->FreeMemory(
+
+
+
+
+
+
+
+
17627 const VkImageCreateInfo* pImageCreateInfo,
+
+
+
+
+
+
17633 VMA_ASSERT(allocator && pImageCreateInfo && pAllocationCreateInfo && pImage && pAllocation);
+
+
17635 if(pImageCreateInfo->extent.width == 0 ||
+
17636 pImageCreateInfo->extent.height == 0 ||
+
17637 pImageCreateInfo->extent.depth == 0 ||
+
17638 pImageCreateInfo->mipLevels == 0 ||
+
17639 pImageCreateInfo->arrayLayers == 0)
+
+
17641 return VK_ERROR_VALIDATION_FAILED_EXT;
+
+
+
17644 VMA_DEBUG_LOG(
"vmaCreateImage");
+
+
17646 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17648 *pImage = VK_NULL_HANDLE;
+
17649 *pAllocation = VK_NULL_HANDLE;
+
+
+
17652 VkResult res = (*allocator->GetVulkanFunctions().vkCreateImage)(
+
17653 allocator->m_hDevice,
+
+
17655 allocator->GetAllocationCallbacks(),
+
+
+
+
17659 VmaSuballocationType suballocType = pImageCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL ?
+
17660 VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL :
+
17661 VMA_SUBALLOCATION_TYPE_IMAGE_LINEAR;
+
+
+
17664 VkMemoryRequirements vkMemReq = {};
+
17665 bool requiresDedicatedAllocation =
false;
+
17666 bool prefersDedicatedAllocation =
false;
+
17667 allocator->GetImageMemoryRequirements(*pImage, vkMemReq,
+
17668 requiresDedicatedAllocation, prefersDedicatedAllocation);
+
+
17670 res = allocator->AllocateMemory(
+
+
17672 requiresDedicatedAllocation,
+
17673 prefersDedicatedAllocation,
+
+
+
17676 *pAllocationCreateInfo,
+
+
+
+
+
17681 #if VMA_RECORDING_ENABLED
+
17682 if(allocator->GetRecorder() != VMA_NULL)
+
+
17684 allocator->GetRecorder()->RecordCreateImage(
+
17685 allocator->GetCurrentFrameIndex(),
+
+
17687 *pAllocationCreateInfo,
+
+
+
+
+
+
+
+
+
+
17697 res = allocator->BindImageMemory(*pAllocation, 0, *pImage, VMA_NULL);
+
+
+
+
+
17702 #if VMA_STATS_STRING_ENABLED
+
17703 (*pAllocation)->InitBufferImageUsage(pImageCreateInfo->usage);
+
+
17705 if(pAllocationInfo != VMA_NULL)
+
+
17707 allocator->GetAllocationInfo(*pAllocation, pAllocationInfo);
+
+
+
+
+
17712 allocator->FreeMemory(
+
+
+
17715 *pAllocation = VK_NULL_HANDLE;
+
17716 (*allocator->GetVulkanFunctions().vkDestroyImage)(allocator->m_hDevice, *pImage, allocator->GetAllocationCallbacks());
+
17717 *pImage = VK_NULL_HANDLE;
+
+
+
17720 (*allocator->GetVulkanFunctions().vkDestroyImage)(allocator->m_hDevice, *pImage, allocator->GetAllocationCallbacks());
+
17721 *pImage = VK_NULL_HANDLE;
+
+
+
+
+
+
+
+
+
+
+
17732 VMA_ASSERT(allocator);
+
+
17734 if(image == VK_NULL_HANDLE && allocation == VK_NULL_HANDLE)
+
+
+
+
+
17739 VMA_DEBUG_LOG(
"vmaDestroyImage");
+
+
17741 VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+
17743 #if VMA_RECORDING_ENABLED
+
17744 if(allocator->GetRecorder() != VMA_NULL)
+
+
17746 allocator->GetRecorder()->RecordDestroyImage(
+
17747 allocator->GetCurrentFrameIndex(),
+
-
17750 if(allocation != VK_NULL_HANDLE)
-
-
17752 allocator->FreeMemory(
-
-
+
+
+
17752 if(image != VK_NULL_HANDLE)
+
+
17754 (*allocator->GetVulkanFunctions().vkDestroyImage)(allocator->m_hDevice, image, allocator->GetAllocationCallbacks());
-
-
-
17758 #endif // #ifdef VMA_IMPLEMENTATION
+
17756 if(allocation != VK_NULL_HANDLE)
+
+
17758 allocator->FreeMemory(
+
+
+
+
+
+
17764 #endif // #ifdef VMA_IMPLEMENTATION