mirror of
https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git
synced 2024-11-26 16:34: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,
|
||||
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.
|
||||
if((createInfo.flags & VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT) != 0 &&
|
||||
!m_LinearAlgorithm)
|
||||
if(isUpperAddress && !m_LinearAlgorithm)
|
||||
{
|
||||
return VK_ERROR_FEATURE_NOT_PRESENT;
|
||||
}
|
||||
@ -9182,12 +9189,15 @@ VkResult VmaBlockVector::Allocate(
|
||||
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);
|
||||
|
||||
/*
|
||||
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.
|
||||
// Forward order in m_Blocks - prefer blocks with smallest amount of free space.
|
||||
for(size_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex )
|
||||
@ -9201,7 +9211,7 @@ VkResult VmaBlockVector::Allocate(
|
||||
m_BufferImageGranularity,
|
||||
size,
|
||||
alignment,
|
||||
upperAddress,
|
||||
isUpperAddress,
|
||||
suballocType,
|
||||
false, // canMakeOtherLost
|
||||
&currRequest))
|
||||
@ -9225,7 +9235,7 @@ VkResult VmaBlockVector::Allocate(
|
||||
}
|
||||
|
||||
*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(
|
||||
hCurrentPool,
|
||||
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.
|
||||
if(canCreateNewBlock)
|
||||
{
|
||||
@ -9327,13 +9333,13 @@ VkResult VmaBlockVector::Allocate(
|
||||
m_BufferImageGranularity,
|
||||
size,
|
||||
alignment,
|
||||
upperAddress,
|
||||
isUpperAddress,
|
||||
suballocType,
|
||||
false, // canMakeOtherLost
|
||||
&allocRequest))
|
||||
{
|
||||
*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(
|
||||
hCurrentPool,
|
||||
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.
|
||||
if(canMakeOtherLost)
|
||||
@ -9434,7 +9439,7 @@ VkResult VmaBlockVector::Allocate(
|
||||
}
|
||||
// Allocate from this pBlock.
|
||||
*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(
|
||||
hCurrentPool,
|
||||
pBestRequestBlock,
|
||||
|
Loading…
Reference in New Issue
Block a user