diff --git a/.gitignore b/.gitignore index f56901a..35324aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,3 @@ /bin/* - /build/* -!/build/src/ -/build/src/* -!/build/src/Release/ -/build/src/Release/* -!/build/src/Release/VmaSample.exe -!/build/src/VmaReplay/ -/build/src/VmaReplay/* -!/build/src/VmaReplay/Release/ -/build/src/VmaReplay/Release/* -!/build/src/VmaReplay/Release/VmaReplay.exe +!/bin/VmaSample_Release_vs2019.exe diff --git a/CHANGELOG.md b/CHANGELOG.md index 218a98b..5d5498d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,53 @@ +# 3.0.0 (2022-03-25) + +It has been a long time since the previous official release, so hopefully everyone has been using the latest code from "master" branch, which is always maintained in a good state, not the old version. For completeness, here is the list of changes since v2.3.0. The major version number has changed, so there are some compatibility-breaking changes, but the basic API stays the same and is mostly backward-compatible. + +Major features added (some compatibility-breaking): + +- Added new API for selecting preferred memory type: flags `VMA_MEMORY_USAGE_AUTO`, `VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE`, `VMA_MEMORY_USAGE_AUTO_PREFER_HOST`, `VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT`, `VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT`, `VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT`. Old values like `VMA_MEMORY_USAGE_GPU_ONLY` still work as before, for backward compatibility, but are not recommended. +- Added new defragmentation API and algorithm, replacing the old one. See structure `VmaDefragmentationInfo`, `VmaDefragmentationMove`, `VmaDefragmentationPassMoveInfo`, `VmaDefragmentationStats`, function `vmaBeginDefragmentation`, `vmaEndDefragmentation`, `vmaBeginDefragmentationPass`, `vmaEndDefragmentationPass`. +- Redesigned API for statistics, replacing the old one. See structures: `VmaStatistics`, `VmaDetailedStatistics`, `VmaTotalStatistics`. `VmaBudget`, functions: `vmaGetHeapBudgets`, `vmaCalculateStatistics`, `vmaGetPoolStatistics`, `vmaCalculatePoolStatistics`, `vmaGetVirtualBlockStatistics`, `vmaCalculateVirtualBlockStatistics`. +- Added "Virtual allocator" feature - possibility to use core allocation algorithms for allocation of custom memory, not necessarily Vulkan device memory. See functions like `vmaCreateVirtualBlock`, `vmaDestroyVirtualBlock` and many more. +- `VmaAllocation` now keeps both `void* pUserData` and `char* pName`. Added function `vmaSetAllocationName`, member `VmaAllocationInfo::pName`. Flag `VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT` is now deprecated. +- Clarified and cleaned up various ways of importing Vulkan functions. See macros `VMA_STATIC_VULKAN_FUNCTIONS`, `VMA_DYNAMIC_VULKAN_FUNCTIONS`, structure `VmaVulkanFunctions`. Added members `VmaVulkanFunctions::vkGetInstanceProcAddr`, `vkGetDeviceProcAddr`, which are now required when using `VMA_DYNAMIC_VULKAN_FUNCTIONS`. + +Removed (compatibility-breaking): + +- Removed whole "lost allocations" feature. Removed from the interface: `VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT`, `VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT`, `vmaCreateLostAllocation`, `vmaMakePoolAllocationsLost`, `vmaTouchAllocation`, `VmaAllocatorCreateInfo::frameInUseCount`, `VmaPoolCreateInfo::frameInUseCount`. +- Removed whole "record & replay" feature. Removed from the API: `VmaAllocatorCreateInfo::pRecordSettings`, `VmaRecordSettings`, `VmaRecordFlagBits`, `VmaRecordFlags`. Removed VmaReplay application. +- Removed "buddy" algorithm - removed flag `VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT`. + +Minor but compatibility-breaking changes: + +- Changes in `ALLOCATION_CREATE_STRATEGY` flags. Removed flags: `VMA_ALLOCATION_CREATE_STRATEGY_MIN_FRAGMENTATION_BIT`, `VMA_ALLOCATION_CREATE_STRATEGY_WORST_FIT_BIT`, `VMA_VIRTUAL_ALLOCATION_CREATE_STRATEGY_MIN_FRAGMENTATION_BIT`, which were aliases to other existing flags. +- Added a member `void* pUserData` to `VmaDeviceMemoryCallbacks`. Updated `PFN_vmaAllocateDeviceMemoryFunction`, `PFN_vmaFreeDeviceMemoryFunction` to use the new `pUserData` member. +- Removed function `vmaResizeAllocation` that was already deprecated. + +Other major changes: + +- Added new features to custom pools: support for dedicated allocations, new member `VmaPoolCreateInfo::pMemoryAllocateNext`, `minAllocationAlignment`. +- Added support for Vulkan 1.2, 1.3. +- Added support for VK_KHR_buffer_device_address extension - flag `VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT`. +- Added support for VK_EXT_memory_priority extension - flag `VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT`, members `VmaAllocationCreateInfo::priority`, `VmaPoolCreateInfo::priority`. +- Added support for VK_AMD_device_coherent_memory extension - flag `VMA_ALLOCATOR_CREATE_AMD_DEVICE_COHERENT_MEMORY_BIT`. +- Added member `VmaAllocatorCreateInfo::pTypeExternalMemoryHandleTypes`. +- Added function `vmaGetAllocatorInfo`, structure `VmaAllocatorInfo`. +- Added functions `vmaFlushAllocations`, `vmaInvalidateAllocations` for multiple allocations at once. +- Added flag `VMA_ALLOCATION_CREATE_CAN_ALIAS_BIT`. +- Added function `vmaCreateBufferWithAlignment`. +- Added convenience function `vmaGetAllocationMemoryProperties`. +- Added convenience functions: `vmaCreateAliasingBuffer`, `vmaCreateAliasingImage`. + +Other minor changes: + +- Implemented Two-Level Segregated Fit (TLSF) allocation algorithm, replacing previous default one. It is much faster, especially when freeing many allocations at once or when `bufferImageGranularity` is large. +- Renamed debug macro `VMA_DEBUG_ALIGNMENT` to `VMA_MIN_ALIGNMENT`. +- Added CMake support - CMakeLists.txt files. Removed Premake support. +- Changed `vmaInvalidateAllocation` and `vmaFlushAllocation` to return `VkResult`. +- Added nullability annotations for Clang: `VMA_NULLABLE`, `VMA_NOT_NULL`, `VMA_NULLABLE_NON_DISPATCHABLE`, `VMA_NOT_NULL_NON_DISPATCHABLE`, `VMA_LEN_IF_NOT_NULL`. +- JSON dump format has changed. +- Countless fixes and improvements, including performance optimizations, compatibility with various platforms and compilers, documentation. + # 2.3.0 (2019-12-04) Major release after a year of development in "master" branch and feature branches. Notable new features: supporting Vulkan 1.1, supporting query for memory budget. diff --git a/bin/VmaSample_Release_vs2019.exe b/bin/VmaSample_Release_vs2019.exe new file mode 100644 index 0000000..c9a36e0 Binary files /dev/null and b/bin/VmaSample_Release_vs2019.exe differ diff --git a/build/src/Release/VmaSample.exe b/build/src/Release/VmaSample.exe deleted file mode 100644 index 8ec81f5..0000000 Binary files a/build/src/Release/VmaSample.exe and /dev/null differ diff --git a/docs/html/index.html b/docs/html/index.html index c5ce1d2..8d81d72 100644 --- a/docs/html/index.html +++ b/docs/html/index.html @@ -65,7 +65,7 @@ $(function() {
Version 3.0.0-development
+Version 3.0.0 (2022-03-25)
Copyright (c) 2017-2022 Advanced Micro Devices, Inc. All rights reserved.
License: MIT
API documentation divided into groups: Modules
diff --git a/docs/html/lost_allocations.html b/docs/html/lost_allocations.html deleted file mode 100644 index 38c75e9..0000000 --- a/docs/html/lost_allocations.html +++ /dev/null @@ -1,142 +0,0 @@ - - - - - - - -
- Vulkan Memory Allocator
-
- |
-
If your game oversubscribes video memory, if may work OK in previous-generation graphics APIs (DirectX 9, 10, 11, OpenGL) because resources are automatically paged to system RAM. In Vulkan you can't do it because when you run out of memory, an allocation just fails. If you have more data (e.g. textures) that can fit into VRAM and you don't need it all at once, you may want to upload them to GPU on demand and "push out" ones that are not used for a long time to make room for the new ones, effectively using VRAM (or a cartain memory pool) as a form of cache. Vulkan Memory Allocator can help you with that by supporting a concept of "lost allocations".
-To create an allocation that can become lost, include VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT flag in VmaAllocationCreateInfo::flags. Before using a buffer or image bound to such allocation in every new frame, you need to query it if it is not lost. To check it, call vmaTouchAllocation(). If the allocation is lost, you should not use it or buffer/image bound to it. You mustn't forget to destroy this allocation and this buffer/image. vmaGetAllocationInfo() can also be used for checking status of the allocation. Allocation is lost when returned VmaAllocationInfo::deviceMemory == VK_NULL_HANDLE
.
To create an allocation that can make some other allocations lost to make room for it, use VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT flag. You will usually use both flags VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT and VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT at the same time.
-Warning! Current implementation uses quite naive, brute force algorithm, which can make allocation calls that use VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT flag quite slow. A new, more optimal algorithm and data structure to speed this up is planned for the future.
-Q: When interleaving creation of new allocations with usage of existing ones, how do you make sure that an allocation won't become lost while it is used in the current frame?
-It is ensured because vmaTouchAllocation() / vmaGetAllocationInfo() not only returns allocation status/parameters and checks whether it is not lost, but when it is not, it also atomically marks it as used in the current frame, which makes it impossible to become lost in that frame. It uses lockless algorithm, so it works fast and doesn't involve locking any internal mutex.
-Q: What if my allocation may still be in use by the GPU when it is rendering a previous frame while I already submit new frame on the CPU?
-You can make sure that allocations "touched" by vmaTouchAllocation() / vmaGetAllocationInfo() will not become lost for a number of additional frames back from the current one by specifying this number as VmaAllocatorCreateInfo::frameInUseCount (for default memory pool) and VmaPoolCreateInfo::frameInUseCount (for custom pool).
-Q: How do you inform the library when new frame starts?
-You need to call function vmaSetCurrentFrameIndex().
-Example code:
-When using lost allocations, you may see some Vulkan validation layer warnings about overlapping regions of memory bound to different kinds of buffers and images. This is still valid as long as you implement proper handling of lost allocations (like in the example above) and don't use them.
-You can create an allocation that is already in lost state from the beginning using function vmaCreateLostAllocation(). It may be useful if you need a "dummy" allocation that is not null.
-You can call function vmaMakePoolAllocationsLost() to set all eligible allocations in a specified custom pool to lost state. Allocations that have been "touched" in current frame or VmaPoolCreateInfo::frameInUseCount frames back cannot become lost.
-Q: Can I touch allocation that cannot become lost?
-Yes, although it has no visible effect. Calls to vmaGetAllocationInfo() and vmaTouchAllocation() update last use frame index also for allocations that cannot become lost, but the only way to observe it is to dump internal allocator state using vmaBuildStatsString(). You can use this feature for debugging purposes to explicitly mark allocations that you use in current frame and then analyze JSON dump to see for how long each allocation stays unused.
-
- Vulkan Memory Allocator
-
- |
-
While using the library, sequence of calls to its functions together with their parameters can be recorded to a file and later replayed using standalone player application. It can be useful to:
-Recording functionality is disabled by default. To enable it, define following macro before every include of this library:
-To record sequence of calls to a file: Fill in VmaAllocatorCreateInfo::pRecordSettings member while creating VmaAllocator object. File is opened and written during whole lifetime of the allocator.
-To replay file: Use VmaReplay - standalone command-line program. Precompiled binary can be found in "bin" directory. Its source can be found in "src/VmaReplay" directory. Its project is generated by Premake. Command line syntax is printed when the program is launched without parameters. Basic usage:
VmaReplay.exe MyRecording.csv -
Documentation of file format can be found in file: "docs/Recording file format.md". It is a human-readable, text file in CSV format (Comma Separated Values).
-bufferImageGranularity
, nonCoherentAtomSize
, and especially different set of memory heaps and types) may give different performance and memory usage results, as well as issue some warnings and errors.VMA_RECORDING_ENABLED
macro. Support for other platforms should be easy to add. Contributions are welcomed.
- Vulkan Memory Allocator
-
- |
-
This is the complete list of members for VmaDefragmentationInfo2, including all inherited members.
-
- Vulkan Memory Allocator
-
- |
-
Parameters for defragmentation. - More...
--Public Attributes | |
VmaDefragmentationFlags | flags |
Reserved for future use. Should be 0. More... | |
uint32_t | allocationCount |
Number of allocations in pAllocations array. More... | |
const VmaAllocation * | pAllocations |
Pointer to array of allocations that can be defragmented. More... | |
VkBool32 * | pAllocationsChanged |
Optional, output. Pointer to array that will be filled with information whether the allocation at certain index has been changed during defragmentation. More... | |
uint32_t | poolCount |
Numer of pools in pPools array. More... | |
const VmaPool * | pPools |
Either null or pointer to array of pools to be defragmented. More... | |
VkDeviceSize | maxCpuBytesToMove |
Maximum total numbers of bytes that can be copied while moving allocations to different places using transfers on CPU side, like memcpy() , memmove() . More... | |
uint32_t | maxCpuAllocationsToMove |
Maximum number of allocations that can be moved to a different place using transfers on CPU side, like memcpy() , memmove() . More... | |
VkDeviceSize | maxGpuBytesToMove |
Maximum total numbers of bytes that can be copied while moving allocations to different places using transfers on GPU side, posted to commandBuffer . More... | |
uint32_t | maxGpuAllocationsToMove |
Maximum number of allocations that can be moved to a different place using transfers on GPU side, posted to commandBuffer . More... | |
VkCommandBuffer | commandBuffer |
Optional. Command buffer where GPU copy commands will be posted. More... | |
Parameters for defragmentation.
-To be used with function vmaDefragmentationBegin().
-uint32_t VmaDefragmentationInfo2::allocationCount | -
Number of allocations in pAllocations
array.
VkCommandBuffer VmaDefragmentationInfo2::commandBuffer | -
Optional. Command buffer where GPU copy commands will be posted.
-If not null, it must be a valid command buffer handle that supports Transfer queue type. It must be in the recording state and outside of a render pass instance. You need to submit it and make sure it finished execution before calling vmaDefragmentationEnd().
-Passing null means that only CPU defragmentation will be performed.
- -VmaDefragmentationFlags VmaDefragmentationInfo2::flags | -
Reserved for future use. Should be 0.
- -uint32_t VmaDefragmentationInfo2::maxCpuAllocationsToMove | -
Maximum number of allocations that can be moved to a different place using transfers on CPU side, like memcpy()
, memmove()
.
UINT32_MAX
means no limit.
VkDeviceSize VmaDefragmentationInfo2::maxCpuBytesToMove | -
Maximum total numbers of bytes that can be copied while moving allocations to different places using transfers on CPU side, like memcpy()
, memmove()
.
VK_WHOLE_SIZE
means no limit.
uint32_t VmaDefragmentationInfo2::maxGpuAllocationsToMove | -
Maximum number of allocations that can be moved to a different place using transfers on GPU side, posted to commandBuffer
.
UINT32_MAX
means no limit.
VkDeviceSize VmaDefragmentationInfo2::maxGpuBytesToMove | -
Maximum total numbers of bytes that can be copied while moving allocations to different places using transfers on GPU side, posted to commandBuffer
.
VK_WHOLE_SIZE
means no limit.
const VmaAllocation* VmaDefragmentationInfo2::pAllocations | -
Pointer to array of allocations that can be defragmented.
-The array should have allocationCount
elements. The array should not contain nulls. Elements in the array should be unique - same allocation cannot occur twice. All allocations not present in this array are considered non-moveable during this defragmentation.
VkBool32* VmaDefragmentationInfo2::pAllocationsChanged | -
Optional, output. Pointer to array that will be filled with information whether the allocation at certain index has been changed during defragmentation.
-The array should have allocationCount
elements. You can pass null if you are not interested in this information.
uint32_t VmaDefragmentationInfo2::poolCount | -
Numer of pools in pPools
array.
const VmaPool* VmaDefragmentationInfo2::pPools | -
Either null or pointer to array of pools to be defragmented.
-All the allocations in the specified pools can be moved during defragmentation and there is no way to check if they were really moved as in pAllocationsChanged
, so you must query all the allocations in all these pools for new VkDeviceMemory
and offset using vmaGetAllocationInfo() if you might need to recreate buffers and images bound to them.
The array should have poolCount
elements. The array should not contain nulls. Elements in the array should be unique - same pool cannot occur twice.
Using this array is equivalent to specifying all allocations from the pools in pAllocations
. It might be more efficient.
- Vulkan Memory Allocator
-
- |
-
This is the complete list of members for VmaDefragmentationPassInfo, including all inherited members.
-moveCount | VmaDefragmentationPassInfo | |
pMoves | VmaDefragmentationPassInfo |
- Vulkan Memory Allocator
-
- |
-
Parameters for incremental defragmentation steps. - More...
--Public Attributes | |
uint32_t | moveCount |
VmaDefragmentationPassMoveInfo * | pMoves |
Parameters for incremental defragmentation steps.
-To be used with function vmaBeginDefragmentationPass().
-uint32_t VmaDefragmentationPassInfo::moveCount | -
VmaDefragmentationPassMoveInfo* VmaDefragmentationPassInfo::pMoves | -
- Vulkan Memory Allocator
-
- |
-
This is the complete list of members for VmaPoolStats, including all inherited members.
-allocationCount | VmaPoolStats | |
blockCount | VmaPoolStats | |
size | VmaPoolStats | |
unusedRangeCount | VmaPoolStats | |
unusedSize | VmaPoolStats |
- Vulkan Memory Allocator
-
- |
-
Describes parameter of existing VmaPool. - More...
--Public Attributes | |
VkDeviceSize | size |
Total amount of VkDeviceMemory allocated from Vulkan for this pool, in bytes. More... | |
VkDeviceSize | unusedSize |
Total number of bytes in the pool not used by any VmaAllocation. More... | |
size_t | allocationCount |
Number of VmaAllocation objects created from this pool that were not destroyed. More... | |
size_t | unusedRangeCount |
Number of continuous memory ranges in the pool not used by any VmaAllocation. More... | |
size_t | blockCount |
Number of VkDeviceMemory blocks allocated for this pool. More... | |
Describes parameter of existing VmaPool.
-size_t VmaPoolStats::allocationCount | -
Number of VmaAllocation objects created from this pool that were not destroyed.
- -size_t VmaPoolStats::blockCount | -
Number of VkDeviceMemory
blocks allocated for this pool.
VkDeviceSize VmaPoolStats::size | -
Total amount of VkDeviceMemory
allocated from Vulkan for this pool, in bytes.
size_t VmaPoolStats::unusedRangeCount | -
Number of continuous memory ranges in the pool not used by any VmaAllocation.
- -VkDeviceSize VmaPoolStats::unusedSize | -
Total number of bytes in the pool not used by any VmaAllocation.
- -
- Vulkan Memory Allocator
-
- |
-
This is the complete list of members for VmaRecordSettings, including all inherited members.
-flags | VmaRecordSettings | |
pFilePath | VmaRecordSettings |
- Vulkan Memory Allocator
-
- |
-
Parameters for recording calls to VMA functions. To be used in VmaAllocatorCreateInfo::pRecordSettings. - More...
- -#include <vk_mem_alloc.h>
-Public Attributes | |
VmaRecordFlags | flags |
Flags for recording. Use VmaRecordFlagBits enum. More... | |
const char * | pFilePath |
Path to the file that should be written by the recording. More... | |
Parameters for recording calls to VMA functions. To be used in VmaAllocatorCreateInfo::pRecordSettings.
-VmaRecordFlags VmaRecordSettings::flags | -
Flags for recording. Use VmaRecordFlagBits enum.
- -const char* VmaRecordSettings::pFilePath | -
Path to the file that should be written by the recording.
-Suggested extension: "csv". If the file already exists, it will be overwritten. It will be opened for the whole time VmaAllocator object is alive. If opening this file fails, creation of the whole allocator object fails.
- -
- Vulkan Memory Allocator
-
- |
-
This is the complete list of members for VmaStatInfo, including all inherited members.
-
- Vulkan Memory Allocator
-
- |
-
Calculated statistics of memory usage in entire allocator. - More...
--Public Attributes | |
uint32_t | blockCount |
Number of VkDeviceMemory Vulkan memory blocks allocated. More... | |
uint32_t | allocationCount |
Number of VmaAllocation allocation objects allocated. More... | |
uint32_t | unusedRangeCount |
Number of free ranges of memory between allocations. More... | |
VkDeviceSize | usedBytes |
Total number of bytes occupied by all allocations. More... | |
VkDeviceSize | unusedBytes |
Total number of bytes occupied by unused ranges. More... | |
VkDeviceSize | allocationSizeMin |
VkDeviceSize | allocationSizeAvg |
VkDeviceSize | allocationSizeMax |
VkDeviceSize | unusedRangeSizeMin |
VkDeviceSize | unusedRangeSizeAvg |
VkDeviceSize | unusedRangeSizeMax |
Calculated statistics of memory usage in entire allocator.
-uint32_t VmaStatInfo::allocationCount | -
Number of VmaAllocation allocation objects allocated.
- -VkDeviceSize VmaStatInfo::allocationSizeAvg | -
VkDeviceSize VmaStatInfo::allocationSizeMax | -
VkDeviceSize VmaStatInfo::allocationSizeMin | -
uint32_t VmaStatInfo::blockCount | -
Number of VkDeviceMemory
Vulkan memory blocks allocated.
VkDeviceSize VmaStatInfo::unusedBytes | -
Total number of bytes occupied by unused ranges.
- -uint32_t VmaStatInfo::unusedRangeCount | -
Number of free ranges of memory between allocations.
- -VkDeviceSize VmaStatInfo::unusedRangeSizeAvg | -
VkDeviceSize VmaStatInfo::unusedRangeSizeMax | -
VkDeviceSize VmaStatInfo::unusedRangeSizeMin | -
VkDeviceSize VmaStatInfo::usedBytes | -
Total number of bytes occupied by all allocations.
- -
- Vulkan Memory Allocator
-
- |
-
This is the complete list of members for VmaStats, including all inherited members.
-memoryHeap | VmaStats | |
memoryType | VmaStats | |
total | VmaStats |
- Vulkan Memory Allocator
-
- |
-
General statistics from current state of Allocator. - More...
--Public Attributes | |
VmaStatInfo | memoryType [VK_MAX_MEMORY_TYPES] |
VmaStatInfo | memoryHeap [VK_MAX_MEMORY_HEAPS] |
VmaStatInfo | total |
General statistics from current state of Allocator.
-VmaStatInfo VmaStats::memoryHeap[VK_MAX_MEMORY_HEAPS] | -
VmaStatInfo VmaStats::memoryType[VK_MAX_MEMORY_TYPES] | -
VmaStatInfo VmaStats::total | -