@@ -455,6 +455,7 @@ void vmaDestroyImage(
455455
456456#ifdef VMA_IMPLEMENTATION
457457
458+ #include < cstdint>
458459#include < cstdlib>
459460
460461/* ******************************************************************************
@@ -497,6 +498,11 @@ remove them if not needed.
497498#include < algorithm> // for min, max
498499#include < mutex> // for std::mutex
499500
501+ #if !defined(_WIN32)
502+ #include < malloc.h> // for aligned_alloc()
503+ #endif
504+
505+
500506#ifdef _DEBUG
501507 // Normal assert to check for programmer's errors, especially in Debug configuration.
502508 #define VMA_ASSERT (expr ) assert (expr)
@@ -512,8 +518,14 @@ remove them if not needed.
512518#define VMA_NULL nullptr
513519
514520#define VMA_ALIGN_OF (type ) (__alignof(type))
515- #define VMA_SYSTEM_ALIGNED_MALLOC (size, alignment ) (_aligned_malloc((size), (alignment)))
516- #define VMA_SYSTEM_FREE (ptr ) _aligned_free(ptr)
521+
522+ #if defined(_WIN32)
523+ #define VMA_SYSTEM_ALIGNED_MALLOC (size, alignment ) (_aligned_malloc((size), (alignment)))
524+ #define VMA_SYSTEM_FREE (ptr ) _aligned_free(ptr)
525+ #else
526+ #define VMA_SYSTEM_ALIGNED_MALLOC (size, alignment ) (aligned_alloc((alignment), (size) ))
527+ #define VMA_SYSTEM_FREE (ptr ) free(ptr)
528+ #endif
517529
518530#define VMA_MIN (v1, v2 ) (std::min((v1), (v2)))
519531#define VMA_MAX (v1, v2 ) (std::max((v1), (v2)))
@@ -841,6 +853,8 @@ class VmaStlAllocator
841853 {
842854 return m_pCallbacks != rhs.m_pCallbacks ;
843855 }
856+
857+ VmaStlAllocator& operator =(const VmaStlAllocator& x) = delete ;
844858};
845859
846860#if VMA_USE_STL_VECTOR
@@ -868,6 +882,14 @@ template<typename T, typename AllocatorT>
868882class VmaVector
869883{
870884public:
885+ VmaVector (const AllocatorT& allocator) :
886+ m_Allocator (allocator),
887+ m_pArray (VMA_NULL),
888+ m_Count (0 ),
889+ m_Capacity (0 )
890+ {
891+ }
892+
871893 VmaVector (AllocatorT& allocator) :
872894 m_Allocator (allocator),
873895 m_pArray (VMA_NULL),
@@ -886,7 +908,7 @@ class VmaVector
886908
887909 VmaVector (const VmaVector<T, AllocatorT>& src) :
888910 m_Allocator (src.m_Allocator),
889- m_pArray (src.m_Count ? (T*)VmaAllocateArray<T>(allocator ->m_pCallbacks, src.m_Count) : VMA_NULL),
911+ m_pArray (src.m_Count ? (T*)VmaAllocateArray<T>(src ->m_pCallbacks, src.m_Count) : VMA_NULL),
890912 m_Count (src.m_Count),
891913 m_Capacity (src.m_Count)
892914 {
@@ -956,7 +978,7 @@ class VmaVector
956978
957979 if (newCapacity != m_Capacity)
958980 {
959- T* const newArray = newCapacity ? VmaAllocateArray<T>(m_hAllocator , newCapacity) : VMA_NULL;
981+ T* const newArray = newCapacity ? VmaAllocateArray<T>(m_Allocator , newCapacity) : VMA_NULL;
960982 if (m_Count != 0 )
961983 memcpy (newArray, m_pArray, m_Count * sizeof (T));
962984 VmaFree (m_Allocator.m_pCallbacks , m_pArray);
@@ -1129,7 +1151,7 @@ T* VmaPoolAllocator<T>::Alloc()
11291151 {
11301152 ItemBlock& block = m_ItemBlocks[i];
11311153 // This block has some free items: Use first one.
1132- if (block.FirstFreeIndex != UINT_MAX )
1154+ if (block.FirstFreeIndex != UINT32_MAX )
11331155 {
11341156 Item* const pItem = &block.pItems [block.FirstFreeIndex ];
11351157 block.FirstFreeIndex = pItem->NextFreeIndex ;
@@ -1179,7 +1201,7 @@ typename VmaPoolAllocator<T>::ItemBlock& VmaPoolAllocator<T>::CreateNewBlock()
11791201 // Setup singly-linked list of all free items in this block.
11801202 for (uint32_t i = 0 ; i < m_ItemsPerBlock - 1 ; ++i)
11811203 newBlock.pItems [i].NextFreeIndex = i + 1 ;
1182- newBlock.pItems [m_ItemsPerBlock - 1 ].NextFreeIndex = UINT_MAX ;
1204+ newBlock.pItems [m_ItemsPerBlock - 1 ].NextFreeIndex = UINT32_MAX ;
11831205 return m_ItemBlocks.back ();
11841206}
11851207
@@ -1340,7 +1362,7 @@ VmaListItem<T>* VmaRawList<T>::PushFront(const T& value)
13401362{
13411363 ItemType* const pNewItem = PushFront ();
13421364 pNewItem->Value = value;
1343- return newItem ;
1365+ return pNewItem ;
13441366}
13451367
13461368template <typename T>
@@ -1621,6 +1643,7 @@ class VmaList
16211643 };
16221644
16231645 VmaList (AllocatorT& allocator) : m_RawList(allocator.m_pCallbacks) { }
1646+ VmaList (const AllocatorT& allocator) : m_RawList(allocator.m_pCallbacks) { }
16241647
16251648 bool empty () const { return m_RawList.IsEmpty (); }
16261649 size_t size () const { return m_RawList.GetCount (); }
@@ -1675,6 +1698,7 @@ class VmaMap
16751698 typedef PairType* iterator;
16761699
16771700 VmaMap (VmaStlAllocator<PairType>& allocator) : m_Vector(allocator) { }
1701+ VmaMap (const VmaStlAllocator<PairType>& allocator) : m_Vector(allocator) { }
16781702
16791703 iterator begin () { return m_Vector.begin (); }
16801704 iterator end () { return m_Vector.end (); }
@@ -2279,7 +2303,7 @@ bool VmaAllocation::Validate() const
22792303How many suitable free suballocations to analyze before choosing best one.
22802304- Set to 1 to use First-Fit algorithm - first suitable free suballocation will
22812305 be chosen.
2282- - Set to UINT_MAX to use Best-Fit/Worst-Fit algorithm - all suitable free
2306+ - Set to UINT32_MAX to use Best-Fit/Worst-Fit algorithm - all suitable free
22832307 suballocations will be analized and best one will be chosen.
22842308- Any other value is also acceptable.
22852309*/
@@ -2301,8 +2325,6 @@ bool VmaAllocation::CreateAllocationRequest(
23012325 if (m_SumFreeSize < allocSize)
23022326 return false ;
23032327
2304- bool found = false ;
2305-
23062328 // Old brute-force algorithm, linearly searching suballocations.
23072329 /*
23082330 uint32_t suitableSuballocationsFound = 0;
@@ -3128,7 +3150,7 @@ VkResult VmaAllocator_T::AllocateMemory(
31283150
31293151 // Bit mask of memory Vulkan types acceptable for this allocation.
31303152 uint32_t memoryTypeBits = vkMemReq.memoryTypeBits ;
3131- uint32_t memTypeIndex = UINT_MAX ;
3153+ uint32_t memTypeIndex = UINT32_MAX ;
31323154 VkResult res = vmaFindMemoryTypeIndex (this , memoryTypeBits, &vmaMemReq, &memTypeIndex);
31333155 if (res == VK_SUCCESS)
31343156 {
@@ -3579,8 +3601,8 @@ VkResult vmaFindMemoryTypeIndex(
35793601 break ;
35803602 }
35813603
3582- *pMemoryTypeIndex = UINT_MAX ;
3583- uint32_t minCost = UINT_MAX ;
3604+ *pMemoryTypeIndex = UINT32_MAX ;
3605+ uint32_t minCost = UINT32_MAX ;
35843606 for (uint32_t memTypeIndex = 0 , memTypeBit = 1 ;
35853607 memTypeIndex < allocator->GetMemoryTypeCount ();
35863608 ++memTypeIndex, memTypeBit <<= 1 )
@@ -3606,7 +3628,7 @@ VkResult vmaFindMemoryTypeIndex(
36063628 }
36073629 }
36083630 }
3609- return (*pMemoryTypeIndex != UINT_MAX ) ? VK_SUCCESS : VK_ERROR_FEATURE_NOT_PRESENT;
3631+ return (*pMemoryTypeIndex != UINT32_MAX ) ? VK_SUCCESS : VK_ERROR_FEATURE_NOT_PRESENT;
36103632}
36113633
36123634VkResult vmaAllocateMemory (
0 commit comments