Skip to content

Commit 14dfcd8

Browse files
Added documentation chapter "When not to use custom pools"
1 parent 0479c36 commit 14dfcd8

1 file changed

Lines changed: 47 additions & 7 deletions

File tree

include/vk_mem_alloc.h

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ License: MIT
5555
- \subpage resource_aliasing
5656
- \subpage custom_memory_pools
5757
- [Choosing memory type index](@ref custom_memory_pools_MemTypeIndex)
58+
- [When not to use custom pools](@ref custom_memory_pools_when_not_use)
5859
- [Linear allocation algorithm](@ref linear_algorithm)
5960
- [Free-at-once](@ref linear_algorithm_free_at_once)
6061
- [Stack](@ref linear_algorithm_stack)
@@ -18370,6 +18371,7 @@ A memory pool contains a number of `VkDeviceMemory` blocks.
1837018371
The library automatically creates and manages default pool for each memory type available on the device.
1837118372
Default memory pool automatically grows in size.
1837218373
Size of allocated blocks is also variable and managed automatically.
18374+
You are using default pools whenever you leave VmaAllocationCreateInfo::pool = null.
1837318375

1837418376
You can create custom pool and allocate memory out of it.
1837518377
It can be useful if you want to:
@@ -18441,13 +18443,6 @@ It is supported only when VmaPoolCreateInfo::blockSize = 0.
1844118443
To use this feature, set VmaAllocationCreateInfo::pool to the pointer to your custom pool and
1844218444
VmaAllocationCreateInfo::flags to #VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT.
1844318445

18444-
\note Excessive use of custom pools is a common mistake when using this library.
18445-
Custom pools may be useful for special purposes - when you want to
18446-
keep certain type of resources separate e.g. to reserve minimum amount of memory
18447-
for them or limit maximum amount of memory they can occupy. For most
18448-
resources this is not needed and so it is not recommended to create #VmaPool
18449-
objects and allocations out of them. Allocating from the default pool is sufficient.
18450-
1845118446

1845218447
\section custom_memory_pools_MemTypeIndex Choosing memory type index
1845318448

@@ -18482,6 +18477,51 @@ When creating buffers/images allocated in that pool, provide following parameter
1848218477
- VmaAllocationCreateInfo: You don't need to pass same parameters. Fill only `pool` member.
1848318478
Other members are ignored anyway.
1848418479

18480+
18481+
\section custom_memory_pools_when_not_use When not to use custom pools
18482+
18483+
Custom pools are commonly overused by VMA users.
18484+
While it may feel natural to keep some logical groups of resources separate in memory,
18485+
in most cases it does more harm than good.
18486+
Using custom pool shouldn't be your first choice.
18487+
Instead, please make all allocations from default pools first and only use custom pools
18488+
if you can prove and measure that it is beneficial in some way,
18489+
e.g. it results in lower memory usage, better performance, etc.
18490+
18491+
Using custom pools has disadvantages:
18492+
18493+
- Each pool has its own collection of `VkDeviceMemory` blocks.
18494+
Some of them may be partially or even completely empty.
18495+
Spreading allocations across multiple pools increases the amount of wasted (allocated but unbound) memory.
18496+
- You must manually choose specific memory type to be used by a custom pool (set as VmaPoolCreateInfo::memoryTypeIndex).
18497+
When using default pools, best memory type for each of your allocations can be selected automatically
18498+
using a carefully design algorithm that works across all kinds of GPUs.
18499+
- If an allocation from a custom pool at specific memory type fails, entire allocation operation returns failure.
18500+
When using default pools, VMA tries another compatible memory type.
18501+
- If you set VmaPoolCreateInfo::blockSize != 0, each memory block has the same size,
18502+
while default pools start from small blocks and only allocate next blocks larger and larger
18503+
up to the preferred block size.
18504+
18505+
Many of the common concerns can be addressed in a different way than using custom pools:
18506+
18507+
- If you want to keep your allocations of certain size (small versus large) or certain lifetime (transient versus long lived)
18508+
separate, you likely don't need to.
18509+
VMA uses a high quality allocation algorithm that manages memory well in various cases.
18510+
Please mesure and check if using custom pools provides a benefit.
18511+
- If you want to keep your images and buffers separate, you don't need to.
18512+
VMA respects `bufferImageGranularity` limit automatically.
18513+
- If you want to keep your mapped and not mapped allocations separate, you don't need to.
18514+
VMA respects `nonCoherentAtomSize` limit automatically.
18515+
It also maps only those `VkDeviceMemory` blocks that need to map any allocation.
18516+
It even tries to keep mappable and non-mappable allocations in separate blocks to minimize the amount of mapped memory.
18517+
- If you want to choose a custom size for the default memory block, you can set it globally instead
18518+
using VmaAllocatorCreateInfo::preferredLargeHeapBlockSize.
18519+
- If you want to select specific memory type for your allocation,
18520+
you can set VmaAllocationCreateInfo::memoryTypeBits to `(1u << myMemoryTypeIndex)` instead.
18521+
- If you need to create a buffer with certain minimum alignment, you can still do it
18522+
using default pools with dedicated function vmaCreateBufferWithAlignment().
18523+
18524+
1848518525
\section linear_algorithm Linear allocation algorithm
1848618526

1848718527
Each Vulkan memory block managed by this library has accompanying metadata that

0 commit comments

Comments
 (0)