<divclass="textblock"><p>A memory pool contains a number of <code>VkDeviceMemory</code> blocks. The library automatically creates and manages default pool for each memory type available on the device. Default memory pool automatically grows in size. Size of allocated blocks is also variable and managed automatically.</p>
<p>You can create custom pool and allocate memory out of it. It can be useful if you want to:</p>
<li>Fill <aclass="el"href="struct_vma_pool_create_info.html"title="Describes parameter of created VmaPool. ">VmaPoolCreateInfo</a> structure.</li>
<li>Call <aclass="el"href="vk__mem__alloc_8h.html#a5c8770ded7c59c8caac6de0c2cb00b50"title="Allocates Vulkan device memory and creates VmaPool object. ">vmaCreatePool()</a> to obtain <code>VmaPool</code> handle.</li>
<li>When making an allocation, set <aclass="el"href="struct_vma_allocation_create_info.html#a6272c0555cfd1fe28bff1afeb6190150"title="Pool that this allocation should be created in. ">VmaAllocationCreateInfo::pool</a> to this handle. You don't need to specify any other parameters of this structure, like usage.</li>
<divclass="fragment"><divclass="line"><spanclass="comment">// Create a pool that can have at most 2 blocks, 128 MiB each.</span></div><divclass="line"><aclass="code"href="struct_vma_pool_create_info.html">VmaPoolCreateInfo</a> poolCreateInfo = {};</div><divclass="line">poolCreateInfo.<aclass="code"href="struct_vma_pool_create_info.html#a596fa76b685d3f1f688f84a709a5b319">memoryTypeIndex</a> = ...</div><divclass="line">poolCreateInfo.blockSize = 128ull * 1024 * 1024;</div><divclass="line">poolCreateInfo.<aclass="code"href="struct_vma_pool_create_info.html#ae41142f2834fcdc82baa4883c187b75c">maxBlockCount</a> = 2;</div><divclass="line"></div><divclass="line">VmaPool pool;</div><divclass="line"><aclass="code"href="vk__mem__alloc_8h.html#a5c8770ded7c59c8caac6de0c2cb00b50">vmaCreatePool</a>(allocator, &poolCreateInfo, &pool);</div><divclass="line"></div><divclass="line"><spanclass="comment">// Allocate a buffer out of it.</span></div><divclass="line">VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };</div><divclass="line">bufCreateInfo.size = 1024;</div><divclass="line">bufCreateInfo.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;</div><divclass="line"></div><divclass="line"><aclass="code"href="struct_vma_allocation_create_info.html">VmaAllocationCreateInfo</a> allocCreateInfo = {};</div><divclass="line">allocCreateInfo.<aclass="code"href="struct_vma_allocation_create_info.html#a6272c0555cfd1fe28bff1afeb6190150">pool</a> = pool;</div><divclass="line"></div><divclass="line">VkBuffer buf;</div><divclass="line">VmaAllocation alloc;</div><divclass="line"><aclass="code"href="struct_vma_allocation_info.html">VmaAllocationInfo</a> allocInfo;</div><divclass="line"><aclass="code"href="vk__mem__alloc_8h.html#ac72ee55598617e8eecca384e746bab51">vmaCreateBuffer</a>(allocator, &bufCreateInfo, &allocCreateInfo, &buf, &alloc, &allocInfo);</div></div><!-- fragment --><p>You have to free all allocations made from this pool before destroying it.</p>
<p>When creating a pool, you must explicitly specify memory type index. To find the one suitable for your buffers or images, you can use helper functions <aclass="el"href="vk__mem__alloc_8h.html#ae790ab9ffaf7667fb8f62523e6897888"title="Helps to find memoryTypeIndex, given VkBufferCreateInfo and VmaAllocationCreateInfo. ">vmaFindMemoryTypeIndexForBufferInfo()</a>, <aclass="el"href="vk__mem__alloc_8h.html#a088da83d8eaf3ce9056d9ea0b981d472"title="Helps to find memoryTypeIndex, given VkImageCreateInfo and VmaAllocationCreateInfo. ">vmaFindMemoryTypeIndexForImageInfo()</a>. You need to provide structures with example parameters of buffers or images that you are going to create in that pool.</p>
<divclass="fragment"><divclass="line">VkBufferCreateInfo exampleBufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };</div><divclass="line">exampleBufCreateInfo.size = 1024; <spanclass="comment">// Whatever.</span></div><divclass="line">exampleBufCreateInfo.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; <spanclass="comment">// Change if needed.</span></div><divclass="line"></div><divclass="line"><aclass="code"href="struct_vma_allocation_create_info.html">VmaAllocationCreateInfo</a> allocCreateInfo = {};</div><divclass="line">allocCreateInfo.<aclass="code"href="struct_vma_allocation_create_info.html#accb8b06b1f677d858cb9af20705fa910">usage</a> = <aclass="code"href="vk__mem__alloc_8h.html#aa5846affa1e9da3800e3e78fae2305ccac6b5dc1432d88647aa4cd456246eadf7">VMA_MEMORY_USAGE_GPU_ONLY</a>; <spanclass="comment">// Change if needed.</span></div><divclass="line"></div><divclass="line">uint32_t memTypeIndex;</div><divclass="line"><aclass="code"href="vk__mem__alloc_8h.html#ae790ab9ffaf7667fb8f62523e6897888">vmaFindMemoryTypeIndexForBufferInfo</a>(allocator, &exampleBufCreateInfo, &allocCreateInfo, &memTypeIndex);</div><divclass="line"></div><divclass="line"><aclass="code"href="struct_vma_pool_create_info.html">VmaPoolCreateInfo</a> poolCreateInfo = {};</div><divclass="line">poolCreateInfo.<aclass="code"href="struct_vma_pool_create_info.html#a596fa76b685d3f1f688f84a709a5b319">memoryTypeIndex</a> = memTypeIndex;</div><divclass="line"><spanclass="comment">// ...</span></div></div><!-- fragment --><p>Dummy buffer is needed to query driver for <code>memReq.memoryTypeBits</code>. Memory is never allocated for this buffer. You should fill structures <code>dummyBufCreateInfo</code> and <code>allocCreateInfo</code> with the same parameters as you are going to use for buffers created in your pool.</p>
<p>When creating buffers/images allocated in that pool, provide following parameters:</p>
<ul>
<li><code>VkBufferCreateInfo</code>: Prefer to pass same parameters as above. Otherwise you risk creating resources in a memory type that is not suitable for them, which may result in undefined behavior. Using different <code>VK_BUFFER_USAGE_</code> flags may work, but you shouldn't create images in a pool intended for buffers or the other way around.</li>
<li><aclass="el"href="struct_vma_allocation_create_info.html">VmaAllocationCreateInfo</a>: You don't need to pass same parameters. Fill only <code>pool</code> member. Other members are ignored anyway. </li>