commit | 3e3877ac83e14b899b6998c7bfc16746c48662eb | [log] [tgz] |
---|---|---|
author | Denis Orlov <denorl2009@gmail.com> | Wed Jan 04 23:50:30 2023 +0300 |
committer | Denis Orlov <denorl2009@gmail.com> | Thu Jan 05 00:05:16 2023 +0300 |
tree | 917778b867d1090618a5831f1fcb8c7d21907d81 | |
parent | 3459fd780a67b502e8016855563cc7f0aa74af81 [diff] |
Fix builds on Linux CI This fixes compilation on older Linux compilers (gcc 7.5.0, clang 7.0.0) that do not seem to implement P0558R1 defect report, thus not allowing the usage of value_type member typedef from std::atomic.
Easy to integrate Vulkan memory allocation library.
Documentation: Browse online: Vulkan Memory Allocator (generated from Doxygen-style comments in include/vk_mem_alloc.h)
License: MIT. See LICENSE.txt
Changelog: See CHANGELOG.md
Product page: Vulkan Memory Allocator on GPUOpen
Build status:
Memory allocation and resource (buffer and image) creation in Vulkan is difficult (comparing to older graphics APIs, like D3D11 or OpenGL) for several reasons:
VkDeviceMemory
is allocated separately from creating VkBuffer
/VkImage
and they must be bound together.This library can help game developers to manage memory allocations and resource creation by offering some higher-level functions:
VkDeviceMemory
+ offset + size) to the user.Additional features:
VmaAllocatorCreateInfo
structure to provide custom CPU memory allocator, pointers to Vulkan functions and other parameters.nonCoherentAtomSize
is respected automatically.VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR
is automatically added to memory allocations where needed.priority
of allocations or custom pools and it will be set automatically using this extension.void* pUserData
and debug char* pName
with each allocation.VkResult
error codes - same way as in Vulkan.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:
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_AUTO; VkBuffer buffer; VmaAllocation allocation; vmaCreateBuffer(allocator, &bufferInfo, &allocInfo, &buffer, &allocation, nullptr);
With this one function call:
VkBuffer
is created.VkDeviceMemory
block is allocated if needed.VmaAllocation
is an object that represents memory assigned to this buffer. It can be queried for parameters like VkDeviceMemory
handle and offset.
On Windows it is recommended to use CMake UI. Alternatively you can generate a Visual Studio project map using CMake in command line: cmake -B./build/ -DCMAKE_BUILD_TYPE=Debug -G "Visual Studio 16 2019" -A x64 ./
On Linux:
mkdir build cd build cmake .. make
The following targets are available
Target | Description | CMake option | Default setting |
---|---|---|---|
VmaSample | VMA sample application | VMA_BUILD_SAMPLE | OFF |
VmaBuildSampleShaders | Shaders for VmaSample | VMA_BUILD_SAMPLE_SHADERS | OFF |
Please note that while VulkanMemoryAllocator library is supported on other platforms besides Windows, VmaSample is not.
These CMake options are available
CMake option | Description | Default setting |
---|---|---|
VMA_RECORDING_ENABLED | Enable VMA memory recording for debugging | OFF |
VMA_USE_STL_CONTAINERS | Use C++ STL containers instead of VMA's containers | OFF |
VMA_STATIC_VULKAN_FUNCTIONS | Link statically with Vulkan API | OFF |
VMA_DYNAMIC_VULKAN_FUNCTIONS | Fetch pointers to Vulkan functions internally (no static linking) | ON |
VMA_DEBUG_ALWAYS_DEDICATED_MEMORY | Every allocation will have its own memory block | OFF |
VMA_DEBUG_INITIALIZE_ALLOCATIONS | Automatically fill new allocations and destroyed allocations with some bit pattern | OFF |
VMA_DEBUG_GLOBAL_MUTEX | Enable single mutex protecting all entry calls to the library | OFF |
VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT | Never exceed VkPhysicalDeviceLimits::maxMemoryAllocationCount and return error | OFF |
You can download and install VulkanMemoryAllocator using the vcpkg dependency manager:
git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install ./vcpkg install vulkan-memory-allocator
The VulkanMemoryAllocator port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.
The release comes with precompiled binary executable for “VulkanSample” application which contains test suite. It is compiled using Visual Studio 2019, so it requires appropriate libraries to work, including “MSVCP140.dll”, “VCRUNTIME140.dll”, “VCRUNTIME140_1.dll”. If the launch fails with error message telling about those files missing, please download and install Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019, “x64” version.
See Documentation.
Many other projects on GitHub and some game development studios that use Vulkan in their games.