mirror of
https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git
synced 2024-11-27 00:44:35 +00:00
Optimized VmaBlockVector::Allocate for certain cases.
This commit is contained in:
parent
0dec444a58
commit
1f6c388348
@ -9169,9 +9169,16 @@ VkResult VmaBlockVector::Allocate(
|
|||||||
VmaSuballocationType suballocType,
|
VmaSuballocationType suballocType,
|
||||||
VmaAllocation* pAllocation)
|
VmaAllocation* pAllocation)
|
||||||
{
|
{
|
||||||
|
const bool isUpperAddress = (createInfo.flags & VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT) != 0;
|
||||||
|
const bool canMakeOtherLost = (createInfo.flags & VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT) != 0;
|
||||||
|
const bool mapped = (createInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0;
|
||||||
|
const bool isUserDataString = (createInfo.flags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0;
|
||||||
|
const bool canCreateNewBlock =
|
||||||
|
((createInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) == 0) &&
|
||||||
|
(m_Blocks.size() < m_MaxBlockCount);
|
||||||
|
|
||||||
// Upper address can only be used with linear allocator.
|
// Upper address can only be used with linear allocator.
|
||||||
if((createInfo.flags & VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT) != 0 &&
|
if(isUpperAddress && !m_LinearAlgorithm)
|
||||||
!m_LinearAlgorithm)
|
|
||||||
{
|
{
|
||||||
return VK_ERROR_FEATURE_NOT_PRESENT;
|
return VK_ERROR_FEATURE_NOT_PRESENT;
|
||||||
}
|
}
|
||||||
@ -9182,12 +9189,15 @@ VkResult VmaBlockVector::Allocate(
|
|||||||
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
|
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool mapped = (createInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0;
|
|
||||||
const bool isUserDataString = (createInfo.flags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0;
|
|
||||||
const bool upperAddress = (createInfo.flags & VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT) != 0;
|
|
||||||
|
|
||||||
VmaMutexLock lock(m_Mutex, m_hAllocator->m_UseMutex);
|
VmaMutexLock lock(m_Mutex, m_hAllocator->m_UseMutex);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Under certain condition, this whole section can be skipped for optimization, so
|
||||||
|
we move on directly to trying to allocate with canMakeOtherLost. That's the case
|
||||||
|
e.g. for custom pools with linear algorithm.
|
||||||
|
*/
|
||||||
|
if(!canMakeOtherLost || canCreateNewBlock)
|
||||||
|
{
|
||||||
// 1. Search existing allocations. Try to allocate without making other allocations lost.
|
// 1. Search existing allocations. Try to allocate without making other allocations lost.
|
||||||
// Forward order in m_Blocks - prefer blocks with smallest amount of free space.
|
// Forward order in m_Blocks - prefer blocks with smallest amount of free space.
|
||||||
for(size_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex )
|
for(size_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex )
|
||||||
@ -9201,7 +9211,7 @@ VkResult VmaBlockVector::Allocate(
|
|||||||
m_BufferImageGranularity,
|
m_BufferImageGranularity,
|
||||||
size,
|
size,
|
||||||
alignment,
|
alignment,
|
||||||
upperAddress,
|
isUpperAddress,
|
||||||
suballocType,
|
suballocType,
|
||||||
false, // canMakeOtherLost
|
false, // canMakeOtherLost
|
||||||
&currRequest))
|
&currRequest))
|
||||||
@ -9225,7 +9235,7 @@ VkResult VmaBlockVector::Allocate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
*pAllocation = vma_new(m_hAllocator, VmaAllocation_T)(currentFrameIndex, isUserDataString);
|
*pAllocation = vma_new(m_hAllocator, VmaAllocation_T)(currentFrameIndex, isUserDataString);
|
||||||
pCurrBlock->m_pMetadata->Alloc(currRequest, suballocType, size, upperAddress, *pAllocation);
|
pCurrBlock->m_pMetadata->Alloc(currRequest, suballocType, size, isUpperAddress, *pAllocation);
|
||||||
(*pAllocation)->InitBlockAllocation(
|
(*pAllocation)->InitBlockAllocation(
|
||||||
hCurrentPool,
|
hCurrentPool,
|
||||||
pCurrBlock,
|
pCurrBlock,
|
||||||
@ -9251,10 +9261,6 @@ VkResult VmaBlockVector::Allocate(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool canCreateNewBlock =
|
|
||||||
((createInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) == 0) &&
|
|
||||||
(m_Blocks.size() < m_MaxBlockCount);
|
|
||||||
|
|
||||||
// 2. Try to create new block.
|
// 2. Try to create new block.
|
||||||
if(canCreateNewBlock)
|
if(canCreateNewBlock)
|
||||||
{
|
{
|
||||||
@ -9327,13 +9333,13 @@ VkResult VmaBlockVector::Allocate(
|
|||||||
m_BufferImageGranularity,
|
m_BufferImageGranularity,
|
||||||
size,
|
size,
|
||||||
alignment,
|
alignment,
|
||||||
upperAddress,
|
isUpperAddress,
|
||||||
suballocType,
|
suballocType,
|
||||||
false, // canMakeOtherLost
|
false, // canMakeOtherLost
|
||||||
&allocRequest))
|
&allocRequest))
|
||||||
{
|
{
|
||||||
*pAllocation = vma_new(m_hAllocator, VmaAllocation_T)(currentFrameIndex, isUserDataString);
|
*pAllocation = vma_new(m_hAllocator, VmaAllocation_T)(currentFrameIndex, isUserDataString);
|
||||||
pBlock->m_pMetadata->Alloc(allocRequest, suballocType, size, upperAddress, *pAllocation);
|
pBlock->m_pMetadata->Alloc(allocRequest, suballocType, size, isUpperAddress, *pAllocation);
|
||||||
(*pAllocation)->InitBlockAllocation(
|
(*pAllocation)->InitBlockAllocation(
|
||||||
hCurrentPool,
|
hCurrentPool,
|
||||||
pBlock,
|
pBlock,
|
||||||
@ -9364,8 +9370,7 @@ VkResult VmaBlockVector::Allocate(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
const bool canMakeOtherLost = (createInfo.flags & VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT) != 0;
|
|
||||||
|
|
||||||
// 3. Try to allocate from existing blocks with making other allocations lost.
|
// 3. Try to allocate from existing blocks with making other allocations lost.
|
||||||
if(canMakeOtherLost)
|
if(canMakeOtherLost)
|
||||||
@ -9434,7 +9439,7 @@ VkResult VmaBlockVector::Allocate(
|
|||||||
}
|
}
|
||||||
// Allocate from this pBlock.
|
// Allocate from this pBlock.
|
||||||
*pAllocation = vma_new(m_hAllocator, VmaAllocation_T)(currentFrameIndex, isUserDataString);
|
*pAllocation = vma_new(m_hAllocator, VmaAllocation_T)(currentFrameIndex, isUserDataString);
|
||||||
pBestRequestBlock->m_pMetadata->Alloc(bestRequest, suballocType, size, upperAddress, *pAllocation);
|
pBestRequestBlock->m_pMetadata->Alloc(bestRequest, suballocType, size, isUpperAddress, *pAllocation);
|
||||||
(*pAllocation)->InitBlockAllocation(
|
(*pAllocation)->InitBlockAllocation(
|
||||||
hCurrentPool,
|
hCurrentPool,
|
||||||
pBestRequestBlock,
|
pBestRequestBlock,
|
||||||
|
Loading…
Reference in New Issue
Block a user