Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
fc48eb1
Added missing pool locks in the VmaDefragmenterContext constructor an…
JustSid Mar 12, 2026
cc26b9f
Updated CHANGELOG.md
reg-pl Mar 13, 2026
c3c7a2c
Added missing mutex lock in VmaDefragmentationContext_T::DefragmentPa…
reg-pl May 16, 2026
2ee9752
Use vkGetPhysicalDeviceProperties2 when possible
spencer-lunarg May 21, 2026
23a1580
Merge remote-tracking branch 'spencer-lunarg/vkGetPhysicalDevicePrope…
reg-pl May 22, 2026
ee8ccdc
Fix in MyUniformRandomNumberGenerator fixing compilation on Visual St…
reg-pl May 22, 2026
c2c925f
Fixes after merge related to VmaVulkanFunctions::vkGetPhysicalDeviceP…
reg-pl May 22, 2026
6db09d9
Fix in sample app for validation layer error about extensions VK_KHR_…
reg-pl May 22, 2026
9837451
Added file AGENTS.md for agentic AI
reg-pl May 22, 2026
5d0efb5
Fixed sample app crashing when window is minimized
reg-pl May 22, 2026
6e4dd3d
Fixed a bug in buffer-image granularity handling
reg-pl May 22, 2026
4f68795
Fixed synchronization issue of m_pMappedData
reg-pl May 22, 2026
4717263
Missing update to CHANGELOG.md
reg-pl May 22, 2026
68ad4f2
Updated Vulkan SDK version in windows.yaml to 1.4.350.0
reg-pl May 22, 2026
d48eed9
Updated windows.yaml in hope to fix the CI build on Windows (2)
reg-pl May 22, 2026
424aa00
Updates in hope to fix the CI build on Windows (3)
reg-pl May 22, 2026
07502a0
Fixed synchronization in the sample app
reg-pl May 22, 2026
280881c
Added support for macro VMA_VULKAN_HEADERS_ALREADY_INCLUDED
reg-pl May 28, 2026
9d548dd
Updated CHANGELOG.md regarding VMA_VULKAN_HEADERS_ALREADY_INCLUDED
reg-pl May 28, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions .github/workflows/windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
types: [opened, synchronize, reopened]

env:
VMA_VULKAN_VERSION: "1.3.283.0"
VMA_VULKAN_VERSION: "1.4.350.0"
VMA_VULKAN_SDK_PATH: ${{ github.workspace }}/vulkan_sdk

jobs:
Expand Down Expand Up @@ -40,26 +40,22 @@ jobs:
uses: actions/cache@v4
with:
path: ${{ env.VMA_VULKAN_SDK_PATH }}
key: vulkan-sdk-${{ env.VMA_VULKAN_VERSION }}
key: vulkan-sdk-${{ env.VMA_VULKAN_VERSION }}-installed

- name: Download Vulkan SDK
- name: Install Vulkan SDK
if: steps.cache-vulkan.outputs.cache-hit != 'true'
shell: pwsh
run: |
if (-Not (Test-Path ${{ env.VMA_VULKAN_SDK_PATH }})) {
Write-Host "Vulkan SDK not found in cache. Downloading..."
curl -LS -o vulkansdk.exe https://sdk.lunarg.com/sdk/download/${{ env.VMA_VULKAN_VERSION }}/windows/VulkanSDK-${{ env.VMA_VULKAN_VERSION }}-Installer.exe
7z x vulkansdk.exe -o"${{ env.VMA_VULKAN_SDK_PATH }}"
} else {
Write-Host "Using cached Vulkan SDK"
}
Write-Host "Vulkan SDK not found in cache. Installing..."
curl -LS -o vulkansdk.exe https://sdk.lunarg.com/sdk/download/${{ env.VMA_VULKAN_VERSION }}/windows/vulkansdk-windows-X64-${{ env.VMA_VULKAN_VERSION }}.exe
.\vulkansdk.exe --root "${{ env.VMA_VULKAN_SDK_PATH }}" --accept-licenses --default-answer --confirm-command install copy_only=1

- name: Configure CMake
shell: pwsh
run: |
$env:CC="${{ matrix.config.cc }}"
$env:CXX="${{ matrix.config.cxx }}"
$env:Path += ";${{ env.VMA_VULKAN_SDK_PATH }}\;${{ env.VMA_VULKAN_SDK_PATH }}\Bin\"
$env:Path += ";${{ env.VMA_VULKAN_SDK_PATH }}\Bin\"
$env:VULKAN_SDK="${{ env.VMA_VULKAN_SDK_PATH }}"
cmake . `
-Bbuild `
Expand Down
97 changes: 97 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
The directory where this file exists is Vulkan Memory Allocator (VMA) - a software library implemented in C++, with a C interface, intended for developers who use Vulkan API. It is distributed under the MIT license.

# Requirements

Using VMA requires a C++ compiler and a Vulkan SDK or Vulkan headers available. The public API is C-compatible. The implementation translation unit must be compiled as C++. VMA requires at least C++14 for the implementation.

It supports any platform that has a C++ compiler and Vulkan API available (including but not limited to: Windows, Linux, Android) and any Vulkan-compatible GPU (whether a discrete or integrated PC GPU or a mobile SoC).

# Scope

Using this library is not required for using Vulkan, but it is helpful and recommended, as it simplifies some aspects of the Vulkan API: allocating device memory, creating buffers and images. Specifically, what the library does is:

1. It automatically selects the correct and optimal memory type among the ones available on the current GPU, based on the intended usage flags of the buffer/image, memory requirements that Vulkan returns for it, and parameters of the allocation to be created.
2. It allocates large blocks of `VkDeviceMemory` and implements an allocation algorithm to manage parts of them, to be assigned to individual buffers/images.
3. It provides a simple API (with the most important functions being `vmaCreateBuffer`, `vmaCreateImage`) that internally does the following things (so you don't need to directly call these `vk*` functions mentioned below):
- Creates the new resource (buffer or image) using functions like `vkCreateBuffer`, `vkCreateImage`.
- Queries for its memory requirements using a function like `vkGetBufferMemoryRequirements`, `vkGetImageMemoryRequirements` or similar.
- Allocates a new `VkDeviceMemory` block using `vkAllocateMemory` function or assigns a region of an existing one, suitable for the resource, while fulfilling the requirements of alignment and size.
- Binds the resource to the memory using a function like `vkBindBufferMemory`, `vkBindImageMemory`.

# How to use

VMA is distributed in source form. All library code lives in `include/vk_mem_alloc.h`. The file is very long, so don't read it entirely! Focus on specific sections or search for specific symbols.

The library is STB-style single header. It means all its interface and implementation is contained within this one file, but it doesn't mean all C++ functions are `inline`. Instead, it means that the internal implementation needs to be extracted in exactly one .cpp file by defining macro `VMA_IMPLEMENTATION` before the include.

Other C++ source/header files you can see in this repository are sample, support, and test code, so you don't need to use them when developing software using this library.

The `include/vk_mem_alloc.h` file consists of the following sections:

1. From the beginning until the line `#ifdef VMA_IMPLEMENTATION`: Public interface (API) of the library, which has the form of a C header file with all the public enums, structures, functions.
- Accompanying comments before every symbol, in Doxygen format, are complete documentation of the API.
- You may need to analyze pieces of this section to understand how to correctly use the library.
2. From the line `#ifdef VMA_IMPLEMENTATION` to the line `#endif // VMA_IMPLEMENTATION`: Internal implementation of the library in C++.
- You typically don't need to analyze it when using the library. You can use it only when you develop the library itself or when you need to know its internal implementation beyond what the API and its documentation provides.
3. From the line `#endif // VMA_IMPLEMENTATION` until the end: A long comment in Doxygen format providing a generic documentation of the library, with high-level overview chapters, FAQ, and code examples.
- You may use this section if you need to learn more generic information about the library or find some example code with correct and recommended usage of its functions.

# Library API

The API of VMA is similar in style to Vulkan.

Errors are reported using `VkResult` error codes returned from most functions, with `VK_SUCCESS` meaning success.

Types that represent objects are opaque pointers or handles. Most important types of objects are:

- `VmaAllocator` - represents the main allocator object. Creating only one per `=` and keeping it alive for the whole time when using Vulkan is recommended.
- `VmaAllocation` - represents a specific region of allocated Vulkan memory - a dedicated `VkDeviceMemory` block or a piece of a larger block. It may or may not be bound to a specific buffer/image. That memory block is managed internally by VMA.

Example code:

```
// 1. Fill in Create structures:
VkBufferCreateInfo bufferCreateInfo = ...

VmaAllocationCreateInfo allocCreateInfo = {};
allocCreateInfo.usage = VMA_MEMORY_USAGE_AUTO;
allocCreateInfo.flags = 0;

// 2. Create two objects: buffer and its allocation:
VkBuffer buffer = VK_NULL_HANDLE;
VmaAllocation allocation = VK_NULL_HANDLE;
VkResult res = vmaCreateBuffer(allocator, &bufferCreateInfo, &allocCreateInfo, &buffer, &allocation, nullptr);
if(res != VK_SUCCESS) { ... }

// 3. Using buffer or allocation here, e.g.:
VkMemoryPropertyFlags memPropFlags = 0;
vmaGetAllocationMemoryProperties(allocator, allocation, &memPropFlags);
// Using memPropFlags...

// 4. At the end, destroy the buffer and the allocation:
vmaDestroyBuffer(allocator, buffer, allocation);
```

The pattern for creating an allocation object, as well as other library objects, looks like in Vulkan:

1. Fill `Vma*CreateInfo` structure.
- ALWAYS fully initialize such structure with zeros before filling selected members. Don't rely on the number or sizes of members - new ones may be added in future versions!
2. Call `vmaCreate*` function.
- Check the result of this function (for `VK_SUCCESS`) to make sure the creation succeeded. Handle potential failure in a way consistent with the surrounding code of the project you develop.
- If succeeded, it returns via the last parameter a newly created `Vma*` object handle. You receive ownership of it and you are responsible for destroying it when no longer needed!
3. Use the object, passing it to other functions as needed, like `vmaGetAllocationInfo`, `vmaGetAllocationMemoryProperties`.
- DO NOT EVER access members of such object directly, like `allocation->m_Size`, `allocation->m_MemoryTypeIndex`, even if it would compile and work! This would be a violation of the library interface and may not compile in future versions of VMA. Treat them as opaque handles and only pass them as arguments to the library functions to read their parameters or manipulate them.
4. When no longer needed, destroy the object using the corresponding function `vmaDestroy*`.
- Before destroying the object, make sure it is no longer used or needed, on both CPU and GPU. You need to be sure GPU finished executing Vulkan commands that may use the buffer/image/memory, e.g. by waiting on the appropriate `VkFence`.

Working with images follows the same workflow as in the example shown above for buffers, just use `vmaCreateImage`, `vmaDestroyImage`, and other image-related rather than buffer-related structures and functions.

# Allocation parameters

When filling `VmaAllocationCreateInfo` members, using `allocCreateInfo.usage = VMA_MEMORY_USAGE_AUTO` is recommended in most cases, as it makes VMA automatically choose the best memory type among those available on the current GPU and compatible with the buffer/image created.

When the memory is going to be mapped and one of the `VMA_MEMORY_USAGE_AUTO*` values is used, you need to also set `allocCreateInfo.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT` or `allocCreateInfo.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT`.

- Use `VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT` when you only write to the mapped memory (sequential number-by-number or as a destination of `memcpy`), e.g. when using a buffer intended for uploading data from CPU to GPU.
- The memory assigned to such allocation may be uncached and write-combined, which means any reads and scattered accesses may be extremely slow! DO NOT EVER read from such mapped pointer, even implicitly, e.g. when doing `pMappedPointer[i] += x`.
- Use `VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT` when you need to read from the mapped memory, e.g. when doing a readback of some data downloaded from GPU to CPU.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# 3.4.0 (2026-??-??)

- Added file `AGENTS.md` for agentic AI.
- Added member `VmaAllocationCreateInfo::minAlignment` (#523).
- Remember to always fully initialize structures with zeros and don't rely on their specific `sizeof` to ensure backward compatibility!
- Function `vmaCreateBufferWithAlignment` is now deprecated.
- Improvements for external memory export & import (#503):
- Added functions `vmaCreateDedicatedBuffer`, `vmaCreateDedicatedImage`, `vmaAllocateDedicatedMemory` offering extra parameter `void* pMemoryAllocateNext`.
- Added function `vmaGetMemoryWin32Handle2` offering extra parameter `VkExternalMemoryHandleTypeFlagBits handleType`.
- Added member `VmaVulkanFunctions::vkGetPhysicalDeviceProperties2KHR` and macro `VMA_GET_PHYSICAL_DEVICE_PROPERTIES2` to fix validation layer warnings about the usage of legacy commands on Vulkan >= 1.1 (#530, #531).
- Added `VMA_VERSION` macro with library version number (#507).
- Added support for `VMA_VULKAN_HEADERS_ALREADY_INCLUDED`. When defined, VMA does not include `<vulkan/vulkan.h>`.
- Improvements in the algorithm choosing memory type when `VMA_MEMORY_USAGE_AUTO*` is used (#520).
- Fixes for compatibility with C++20 modules on Clang 21 and GCC15 (#513, #514).
- Fixed compatibility with C++20 modules on Clang 21 and GCC15 (#513, #514).
- Fixed a bug in buffer-image granularity handling (#517).
- Fixed race conditions in defragmentation (#529, #313) and other places (#525).
- Other fixes and improvements, including compatibility with various platforms and compilers, improvements in documentation, sample application, and tests.

# 3.3.0 (2025-05-12)
Expand Down
Loading
Loading