Introduced a rule that custom pool with linear algorithm must have maxBlockCount = 1 (or 0 for default).

This commit is contained in:
Adam Sawicki 2018-08-23 10:40:30 +02:00
parent 0ebdf0c63e
commit f799c4f146
2 changed files with 22 additions and 2 deletions

View File

@ -1821,6 +1821,16 @@ static void TestLinearAllocator()
bufInfo.clear();
}
// Try to create pool with maxBlockCount higher than 1. It should fail.
{
VmaPoolCreateInfo altPoolCreateInfo = poolCreateInfo;
altPoolCreateInfo.maxBlockCount = 2;
VmaPool altPool = nullptr;
res = vmaCreatePool(g_hAllocator, &altPoolCreateInfo, &altPool);
assert(res != VK_SUCCESS);
}
vmaDestroyPool(g_hAllocator, pool);
}

View File

@ -11543,13 +11543,23 @@ bool VmaAllocator_T::TouchAllocation(VmaAllocation hAllocation)
VkResult VmaAllocator_T::CreatePool(const VmaPoolCreateInfo* pCreateInfo, VmaPool* pPool)
{
VMA_DEBUG_LOG(" CreatePool: MemoryTypeIndex=%u", pCreateInfo->memoryTypeIndex);
VMA_DEBUG_LOG(" CreatePool: MemoryTypeIndex=%u, flags=%u", pCreateInfo->memoryTypeIndex, pCreateInfo->flags);
const bool isLinearAlgorithm = (pCreateInfo->flags & VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT) != 0;
VmaPoolCreateInfo newCreateInfo = *pCreateInfo;
if(newCreateInfo.maxBlockCount == 0)
{
newCreateInfo.maxBlockCount = SIZE_MAX;
newCreateInfo.maxBlockCount = isLinearAlgorithm ? 1 : SIZE_MAX;
}
if(newCreateInfo.minBlockCount > newCreateInfo.maxBlockCount)
{
return VK_ERROR_INITIALIZATION_FAILED;
}
if(isLinearAlgorithm && newCreateInfo.maxBlockCount > 1)
{
return VK_ERROR_INITIALIZATION_FAILED;
}
if(newCreateInfo.blockSize == 0)
{