From 663b0c956763cb7390a68002bc7a1c2c6f2e30d7 Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Thu, 13 Dec 2018 12:15:01 +0100 Subject: [PATCH] Minor fixes in documentation. --- docs/html/defragmentation.html | 6 +++--- src/vk_mem_alloc.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/html/defragmentation.html b/docs/html/defragmentation.html index 0bf30ee..bdd895d 100644 --- a/docs/html/defragmentation.html +++ b/docs/html/defragmentation.html @@ -89,7 +89,7 @@ Defragmenting CPU memory
  • It temporarily maps entire memory blocks when necessary.
  • It moves data using memmove() function.
  • -
    // Given following variables already initialized:
    VkDevice device;
    VmaAllocator allocator;
    std::vector<VkBuffer> buffers;
    std::vector<VmaAllocation> allocations;
    const uint32_t allocCount = (uint32_t)allocations.size();
    std::vector<VkBool32> allocationsChanged(allocCount);
    VmaDefragmentationInfo2 defragInfo = {};
    defragInfo.allocationCount = allocCount;
    defragInfo.pAllocations = allocations.data();
    defragInfo.pAllocationsChanged = allocationsChanged.data();
    defragInfo.maxCpuBytesToMove = VK_WHOLE_SIZE; // No limit.
    defragInfo.maxCpuAllocationsToMove = UINT32_MAX; // No limit.
    vmaDefragmentationBegin(allocator, &defragInfo, nullptr, &defragCtx);
    vmaDefragmentationEnd(allocator, defragCtx);
    for(uint32_t i = 0; i < allocCount; ++i)
    {
    if(allocationsChanged[i])
    {
    // Destroy buffer that is immutably bound to memory region which is no longer valid.
    vkDestroyBuffer(device, buffers[i], nullptr);
    // Create new buffer with same parameters.
    VkBufferCreateInfo bufferInfo = ...;
    vkCreateBuffer(device, &bufferInfo, nullptr, &buffers[i]);
    // You can make dummy call to vkGetBufferMemoryRequirements here to silence validation layer warning.
    // Bind new buffer to new memory region. Data contained in it is already moved.
    VmaAllocationInfo allocInfo;
    vmaGetAllocationInfo(allocator, allocations[i], &allocInfo);
    vkBindBufferMemory(device, buffers[i], allocInfo.deviceMemory, allocInfo.offset);
    }
    }

    Filling VmaDefragmentationInfo2::pAllocationsChanged is optional. This output array tells whether particular allocation in VmaDefragmentationInfo2::pAllocations at the same index has been modified during defragmentation. You can pass null, but you then need to query every allocation passed to defragmentation for new parameters using vmaGetAllocationInfo() if you might need to recreate and rebind a buffer or image associated with it.

    +
    // Given following variables already initialized:
    VkDevice device;
    VmaAllocator allocator;
    std::vector<VkBuffer> buffers;
    std::vector<VmaAllocation> allocations;
    const uint32_t allocCount = (uint32_t)allocations.size();
    std::vector<VkBool32> allocationsChanged(allocCount);
    VmaDefragmentationInfo2 defragInfo = {};
    defragInfo.allocationCount = allocCount;
    defragInfo.pAllocations = allocations.data();
    defragInfo.pAllocationsChanged = allocationsChanged.data();
    defragInfo.maxCpuBytesToMove = VK_WHOLE_SIZE; // No limit.
    defragInfo.maxCpuAllocationsToMove = UINT32_MAX; // No limit.
    vmaDefragmentationBegin(allocator, &defragInfo, nullptr, &defragCtx);
    vmaDefragmentationEnd(allocator, defragCtx);
    for(uint32_t i = 0; i < allocCount; ++i)
    {
    if(allocationsChanged[i])
    {
    // Destroy buffer that is immutably bound to memory region which is no longer valid.
    vkDestroyBuffer(device, buffers[i], nullptr);
    // Create new buffer with same parameters.
    VkBufferCreateInfo bufferInfo = ...;
    vkCreateBuffer(device, &bufferInfo, nullptr, &buffers[i]);
    // You can make dummy call to vkGetBufferMemoryRequirements here to silence validation layer warning.
    // Bind new buffer to new memory region. Data contained in it is already moved.
    VmaAllocationInfo allocInfo;
    vmaGetAllocationInfo(allocator, allocations[i], &allocInfo);
    vkBindBufferMemory(device, buffers[i], allocInfo.deviceMemory, allocInfo.offset);
    }
    }

    Setting VmaDefragmentationInfo2::pAllocationsChanged is optional. This output array tells whether particular allocation in VmaDefragmentationInfo2::pAllocations at the same index has been modified during defragmentation. You can pass null, but you then need to query every allocation passed to defragmentation for new parameters using vmaGetAllocationInfo() if you might need to recreate and rebind a buffer or image associated with it.

    If you use Custom memory pools, you can fill VmaDefragmentationInfo2::poolCount and VmaDefragmentationInfo2::pPools instead of VmaDefragmentationInfo2::allocationCount and VmaDefragmentationInfo2::pAllocations to defragment all allocations in given pools. You cannot use VmaDefragmentationInfo2::pAllocationsChanged in that case. You can also combine both methods.

    Defragmenting GPU memory

    @@ -111,9 +111,9 @@ Additional notes Writing custom defragmentation algorithm

    If you want to implement your own, custom defragmentation algorithm, there is infrastructure prepared for that, but it is not exposed through the library API - you need to hack its source code. Here are steps needed to do this:

      -
    1. Main thing you need to do is to define your own class derived from base abstract class VmaDefragmentationAlgorithm and implement your version of its pure virtual method. See definition and comments of this class for details.
    2. +
    3. Main thing you need to do is to define your own class derived from base abstract class VmaDefragmentationAlgorithm and implement your version of its pure virtual methods. See definition and comments of this class for details.
    4. Your code needs to interact with device memory block metadata. If you need more access to its data than it's provided by its public interface, declare your new class as a friend class e.g. in class VmaBlockMetadata_Generic.
    5. -
    6. If you want to create a flag that would enable your algorithm or pass some additional flags to configure it, define some enum with such flags and use them in VmaDefragmentationInfo2::flags.
    7. +
    8. If you want to create a flag that would enable your algorithm or pass some additional flags to configure it, add them to VmaDefragmentationFlagBits and use them in VmaDefragmentationInfo2::flags.
    9. Modify function VmaBlockVectorDefragmentationContext::Begin to create object of your new class whenever needed.
    diff --git a/src/vk_mem_alloc.h b/src/vk_mem_alloc.h index c007128..7ea7c91 100644 --- a/src/vk_mem_alloc.h +++ b/src/vk_mem_alloc.h @@ -799,7 +799,7 @@ for(uint32_t i = 0; i < allocCount; ++i) } \endcode -Filling VmaDefragmentationInfo2::pAllocationsChanged is optional. +Setting VmaDefragmentationInfo2::pAllocationsChanged is optional. This output array tells whether particular allocation in VmaDefragmentationInfo2::pAllocations at the same index has been modified during defragmentation. You can pass null, but you then need to query every allocation passed to defragmentation @@ -914,13 +914,13 @@ but it is not exposed through the library API - you need to hack its source code Here are steps needed to do this: -# Main thing you need to do is to define your own class derived from base abstract - class `VmaDefragmentationAlgorithm` and implement your version of its pure virtual method. + class `VmaDefragmentationAlgorithm` and implement your version of its pure virtual methods. See definition and comments of this class for details. -# Your code needs to interact with device memory block metadata. If you need more access to its data than it's provided by its public interface, declare your new class as a friend class e.g. in class `VmaBlockMetadata_Generic`. -# If you want to create a flag that would enable your algorithm or pass some additional - flags to configure it, define some enum with such flags and use them in + flags to configure it, add them to `VmaDefragmentationFlagBits` and use them in VmaDefragmentationInfo2::flags. -# Modify function `VmaBlockVectorDefragmentationContext::Begin` to create object of your new class whenever needed.