@@ -1951,9 +1951,13 @@ typedef struct VmaPoolCreateInfo {
1951
1951
/* * \brief Use combination of #VmaPoolCreateFlagBits.
1952
1952
*/
1953
1953
VmaPoolCreateFlags flags;
1954
- /* * \brief Size of a single `VkDeviceMemory` block to be allocated as part of this pool, in bytes.
1954
+ /* * \brief Size of a single `VkDeviceMemory` block to be allocated as part of this pool, in bytes. Optional.
1955
1955
1956
- Optional. Leave 0 to use default.
1956
+ Specify nonzero to set explicit, constant size of memory blocks used by this
1957
+ pool.
1958
+
1959
+ Leave 0 to use default and let the library manage block sizes automatically.
1960
+ Sizes of particular blocks may vary.
1957
1961
*/
1958
1962
VkDeviceSize blockSize;
1959
1963
/* * \brief Minimum number of blocks to be always allocated in this pool, even if they stay empty.
@@ -4926,6 +4930,7 @@ struct VmaBlockVector
4926
4930
VkDeviceSize bufferImageGranularity,
4927
4931
uint32_t frameInUseCount,
4928
4932
bool isCustomPool,
4933
+ bool explicitBlockSize,
4929
4934
bool linearAlgorithm);
4930
4935
~VmaBlockVector ();
4931
4936
@@ -4988,6 +4993,7 @@ struct VmaBlockVector
4988
4993
const VkDeviceSize m_BufferImageGranularity;
4989
4994
const uint32_t m_FrameInUseCount;
4990
4995
const bool m_IsCustomPool;
4996
+ const bool m_ExplicitBlockSize;
4991
4997
const bool m_LinearAlgorithm;
4992
4998
bool m_HasEmptyBlock;
4993
4999
VMA_MUTEX m_Mutex;
@@ -5019,7 +5025,8 @@ struct VmaPool_T
5019
5025
5020
5026
VmaPool_T (
5021
5027
VmaAllocator hAllocator,
5022
- const VmaPoolCreateInfo& createInfo);
5028
+ const VmaPoolCreateInfo& createInfo,
5029
+ VkDeviceSize preferredBlockSize);
5023
5030
~VmaPool_T ();
5024
5031
5025
5032
uint32_t GetId () const { return m_Id; }
@@ -9288,16 +9295,18 @@ static void VmaPostprocessCalcStatInfo(VmaStatInfo& inoutInfo)
9288
9295
9289
9296
VmaPool_T::VmaPool_T (
9290
9297
VmaAllocator hAllocator,
9291
- const VmaPoolCreateInfo& createInfo) :
9298
+ const VmaPoolCreateInfo& createInfo,
9299
+ VkDeviceSize preferredBlockSize) :
9292
9300
m_BlockVector(
9293
9301
hAllocator,
9294
9302
createInfo.memoryTypeIndex,
9295
- createInfo.blockSize,
9303
+ createInfo.blockSize != 0 ? createInfo.blockSize : preferredBlockSize ,
9296
9304
createInfo.minBlockCount,
9297
9305
createInfo.maxBlockCount,
9298
9306
(createInfo.flags & VMA_POOL_CREATE_IGNORE_BUFFER_IMAGE_GRANULARITY_BIT) != 0 ? 1 : hAllocator->GetBufferImageGranularity(),
9299
9307
createInfo.frameInUseCount,
9300
9308
true, // isCustomPool
9309
+ createInfo.blockSize != 0, // explicitBlockSize
9301
9310
(createInfo.flags & VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT) != 0), // linearAlgorithm
9302
9311
m_Id(0 )
9303
9312
{
@@ -9320,6 +9329,7 @@ VmaBlockVector::VmaBlockVector(
9320
9329
VkDeviceSize bufferImageGranularity,
9321
9330
uint32_t frameInUseCount,
9322
9331
bool isCustomPool,
9332
+ bool explicitBlockSize,
9323
9333
bool linearAlgorithm) :
9324
9334
m_hAllocator(hAllocator),
9325
9335
m_MemoryTypeIndex(memoryTypeIndex),
@@ -9329,6 +9339,7 @@ VmaBlockVector::VmaBlockVector(
9329
9339
m_BufferImageGranularity(bufferImageGranularity),
9330
9340
m_FrameInUseCount(frameInUseCount),
9331
9341
m_IsCustomPool(isCustomPool),
9342
+ m_ExplicitBlockSize(explicitBlockSize),
9332
9343
m_LinearAlgorithm(linearAlgorithm),
9333
9344
m_Blocks(VmaStlAllocator<VmaDeviceMemoryBlock*>(hAllocator->GetAllocationCallbacks ())),
9334
9345
m_HasEmptyBlock(false ),
@@ -9499,9 +9510,7 @@ VkResult VmaBlockVector::Allocate(
9499
9510
uint32_t newBlockSizeShift = 0 ;
9500
9511
const uint32_t NEW_BLOCK_SIZE_SHIFT_MAX = 3 ;
9501
9512
9502
- // Allocating blocks of other sizes is allowed only in default pools.
9503
- // In custom pools block size is fixed.
9504
- if (m_IsCustomPool == false )
9513
+ if (!m_ExplicitBlockSize)
9505
9514
{
9506
9515
// Allocate 1/8, 1/4, 1/2 as first blocks.
9507
9516
const VkDeviceSize maxExistingBlockSize = CalcMaxBlockSize ();
@@ -9523,7 +9532,7 @@ VkResult VmaBlockVector::Allocate(
9523
9532
size_t newBlockIndex = 0 ;
9524
9533
VkResult res = CreateBlock (newBlockSize, &newBlockIndex);
9525
9534
// Allocation of this size failed? Try 1/2, 1/4, 1/8 of m_PreferredBlockSize.
9526
- if (m_IsCustomPool == false )
9535
+ if (!m_ExplicitBlockSize )
9527
9536
{
9528
9537
while (res < 0 && newBlockSizeShift < NEW_BLOCK_SIZE_SHIFT_MAX)
9529
9538
{
@@ -10918,6 +10927,7 @@ VmaAllocator_T::VmaAllocator_T(const VmaAllocatorCreateInfo* pCreateInfo) :
10918
10927
GetBufferImageGranularity (),
10919
10928
pCreateInfo->frameInUseCount ,
10920
10929
false , // isCustomPool
10930
+ false , // explicitBlockSize
10921
10931
false ); // linearAlgorithm
10922
10932
// No need to call m_pBlockVectors[memTypeIndex][blockVectorTypeIndex]->CreateMinBlocks here,
10923
10933
// becase minBlockCount is 0.
@@ -11809,12 +11819,10 @@ VkResult VmaAllocator_T::CreatePool(const VmaPoolCreateInfo* pCreateInfo, VmaPoo
11809
11819
{
11810
11820
return VK_ERROR_INITIALIZATION_FAILED;
11811
11821
}
11812
- if (newCreateInfo.blockSize == 0 )
11813
- {
11814
- newCreateInfo.blockSize = CalcPreferredBlockSize (newCreateInfo.memoryTypeIndex );
11815
- }
11816
11822
11817
- *pPool = vma_new (this , VmaPool_T)(this , newCreateInfo);
11823
+ const VkDeviceSize preferredBlockSize = CalcPreferredBlockSize (newCreateInfo.memoryTypeIndex );
11824
+
11825
+ *pPool = vma_new (this , VmaPool_T)(this , newCreateInfo, preferredBlockSize);
11818
11826
11819
11827
VkResult res = (*pPool)->m_BlockVector .CreateMinBlocks ();
11820
11828
if (res != VK_SUCCESS)
0 commit comments