From f02c8a46d829ce18cce8fa2f84cf0573a7a292b9 Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Mon, 28 Feb 2022 10:57:04 +0100 Subject: [PATCH] Improvement in documentation --- docs/html/custom_memory_pools.html | 34 +++++++++++++++++++++--------- include/vk_mem_alloc.h | 22 +++++++++++++++---- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/docs/html/custom_memory_pools.html b/docs/html/custom_memory_pools.html index 10feea8..e79dd2a 100644 --- a/docs/html/custom_memory_pools.html +++ b/docs/html/custom_memory_pools.html @@ -86,14 +86,28 @@ $(function() {
  • When making an allocation, set VmaAllocationCreateInfo::pool to this handle. You don't need to specify any other parameters of this structure, like usage.
  • Example:

    -
    // Create a pool that can have at most 2 blocks, 128 MiB each.
    +
    // Find memoryTypeIndex for the pool.
    +
    VkBufferCreateInfo sampleBufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
    +
    sampleBufCreateInfo.size = 0x10000; // Doesn't matter.
    +
    sampleBufCreateInfo.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
    +
    +
    VmaAllocationCreateInfo sampleAllocCreateInfo = {};
    +
    sampleAllocCreateInfo.usage = VMA_MEMORY_USAGE_AUTO;
    +
    +
    uint32_t memTypeIndex;
    +
    VkResult res = vmaFindMemoryTypeIndexForBufferInfo(allocator,
    +
    &sampleBufCreateInfo, &sampleAllocCreateInfo, &memTypeIndex);
    +
    // Check res...
    +
    +
    // Create a pool that can have at most 2 blocks, 128 MiB each.
    VmaPoolCreateInfo poolCreateInfo = {};
    -
    poolCreateInfo.memoryTypeIndex = ...
    -
    poolCreateInfo.blockSize = 128ull * 1024 * 1024;
    +
    poolCreateInfo.memoryTypeIndex = memTypeIndex;
    +
    poolCreateInfo.blockSize = 128ull * 1024 * 1024;
    poolCreateInfo.maxBlockCount = 2;
    VmaPool pool;
    -
    vmaCreatePool(allocator, &poolCreateInfo, &pool);
    +
    res = vmaCreatePool(allocator, &poolCreateInfo, &pool);
    +
    // Check res...
    // Allocate a buffer out of it.
    VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
    @@ -105,16 +119,19 @@ $(function() {
    VkBuffer buf;
    - -
    vmaCreateBuffer(allocator, &bufCreateInfo, &allocCreateInfo, &buf, &alloc, &allocInfo);
    +
    res = vmaCreateBuffer(allocator, &bufCreateInfo, &allocCreateInfo, &buf, &alloc, nullptr);
    +
    // Check res...
    VkResult vmaCreatePool(VmaAllocator allocator, const VmaPoolCreateInfo *pCreateInfo, VmaPool *pPool)
    Allocates Vulkan device memory and creates VmaPool object.
    VkResult vmaCreateBuffer(VmaAllocator allocator, const VkBufferCreateInfo *pBufferCreateInfo, const VmaAllocationCreateInfo *pAllocationCreateInfo, VkBuffer *pBuffer, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo)
    +
    VkResult vmaFindMemoryTypeIndexForBufferInfo(VmaAllocator allocator, const VkBufferCreateInfo *pBufferCreateInfo, const VmaAllocationCreateInfo *pAllocationCreateInfo, uint32_t *pMemoryTypeIndex)
    Helps to find memoryTypeIndex, given VkBufferCreateInfo and VmaAllocationCreateInfo.
    +
    @ VMA_MEMORY_USAGE_AUTO
    Definition: vk_mem_alloc.h:489
    Definition: vk_mem_alloc.h:1212
    VmaPool pool
    Pool that this allocation should be created in.
    Definition: vk_mem_alloc.h:1244
    +
    VmaMemoryUsage usage
    Intended usage of memory.
    Definition: vk_mem_alloc.h:1220
    Represents single memory allocation.
    -
    Parameters of VmaAllocation objects, that can be retrieved using function vmaGetAllocationInfo().
    Definition: vk_mem_alloc.h:1327
    Describes parameter of created VmaPool.
    Definition: vk_mem_alloc.h:1263
    uint32_t memoryTypeIndex
    Vulkan memory type index to allocate this pool from.
    Definition: vk_mem_alloc.h:1266
    +
    VkDeviceSize blockSize
    Size of a single VkDeviceMemory block to be allocated as part of this pool, in bytes....
    Definition: vk_mem_alloc.h:1279
    size_t maxBlockCount
    Maximum number of blocks that can be allocated in this pool. Optional.
    Definition: vk_mem_alloc.h:1292
    Represents custom memory pool.

    You have to free all allocations made from this pool before destroying it.

    @@ -140,9 +157,6 @@ Choosing memory type index
    VmaPoolCreateInfo poolCreateInfo = {};
    poolCreateInfo.memoryTypeIndex = memTypeIndex;
    // ...
    -
    VkResult vmaFindMemoryTypeIndexForBufferInfo(VmaAllocator allocator, const VkBufferCreateInfo *pBufferCreateInfo, const VmaAllocationCreateInfo *pAllocationCreateInfo, uint32_t *pMemoryTypeIndex)
    Helps to find memoryTypeIndex, given VkBufferCreateInfo and VmaAllocationCreateInfo.
    -
    @ VMA_MEMORY_USAGE_AUTO
    Definition: vk_mem_alloc.h:489
    -
    VmaMemoryUsage usage
    Intended usage of memory.
    Definition: vk_mem_alloc.h:1220

    When creating buffers/images allocated in that pool, provide following parameters: