diff --git a/README.md b/README.md index f87a36d..550686e 100644 --- a/README.md +++ b/README.md @@ -54,10 +54,40 @@ Additional features: - Platform-independent, but developed and tested on Windows using Visual Studio. - Error handling implemented by returning `VkResult` error codes - same way as in Vulkan. +# Example + +Basic usage of this library is very simple. Advanced features are optional. After you created global `VmaAllocator` object, a complete code needed to create a buffer may look like this: + +```cpp +VkBufferCreateInfo bufferInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO }; +bufferInfo.size = 65536; +bufferInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; + +VmaAllocationCreateInfo allocInfo = {}; +allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY; + +VkBuffer buffer; +VmaAllocation allocation; +vmaCreateBuffer(allocator, &bufferInfo, &allocInfo, &buffer, &allocation, nullptr); +``` + +With this one function call: + +1. `VkBuffer` is created. +2. `VkDeviceMemory` block is allocated if needed. +3. An unused region of the memory block is bound to this buffer. + +`VmaAllocation` is an object that represents memory assigned to this buffer. It can be queried for parameters useful e.g. if you want to map the memory on host. + # Read more See **[Documentation](https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/)**. +# Software using this library + +- **[Anvil](https://github.com/GPUOpen-LibrariesAndSDKs/Anvil)** - cross-platform framework for Vulkan +- **[vkDOOM3](https://github.com/DustinHLand/vkDOOM3)** - Vulkan port of GPL DOOM 3 BFG Edition + # See also - **[Awesome Vulkan](https://github.com/vinjn/awesome-vulkan)** - a curated list of awesome Vulkan libraries, debuggers and resources. diff --git a/docs/html/index.html b/docs/html/index.html index 09b11cb..e73c089 100644 --- a/docs/html/index.html +++ b/docs/html/index.html @@ -113,15 +113,15 @@ vmaCreateAllocator(&allocatorInfo, &allocator);
  • Call vmaCreateBuffer() / vmaCreateImage() to get VkBuffer/VkImage with memory already allocated and bound to it.
  • VkBufferCreateInfo bufferInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
    -bufferInfo.size = myBufferSize;
    +bufferInfo.size = 65536;
     bufferInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
     
    -VmaAllocationCreateInfo memReq = {};
    -memReq.usage = VMA_MEMORY_USAGE_GPU_ONLY;
    +VmaAllocationCreateInfo allocInfo = {};
    +allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY;
     
     VkBuffer buffer;
     VmaAllocation allocation;
    -vmaCreateBuffer(allocator, &bufferInfo, &memReq, &buffer, &allocation, nullptr);
    +vmaCreateBuffer(allocator, &bufferInfo, &allocInfo, &buffer, &allocation, nullptr);
     

    Don't forget to destroy your objects when no longer needed:

    vmaDestroyBuffer(allocator, buffer, allocation);
     vmaDestroyAllocator(allocator);
    diff --git a/src/vk_mem_alloc.h b/src/vk_mem_alloc.h
    index 40e0cbf..3ce8d66 100644
    --- a/src/vk_mem_alloc.h
    +++ b/src/vk_mem_alloc.h
    @@ -76,15 +76,15 @@ When you want to create a buffer or image:
     
     
         VkBufferCreateInfo bufferInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
    -    bufferInfo.size = myBufferSize;
    +    bufferInfo.size = 65536;
         bufferInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
     
    -    VmaAllocationCreateInfo memReq = {};
    -    memReq.usage = VMA_MEMORY_USAGE_GPU_ONLY;
    +    VmaAllocationCreateInfo allocInfo = {};
    +    allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY;
     
         VkBuffer buffer;
         VmaAllocation allocation;
    -    vmaCreateBuffer(allocator, &bufferInfo, &memReq, &buffer, &allocation, nullptr);
    +    vmaCreateBuffer(allocator, &bufferInfo, &allocInfo, &buffer, &allocation, nullptr);
     
     Don't forget to destroy your objects when no longer needed: