@@ -455,6 +455,7 @@ void vmaDestroyImage(
455
455
456
456
#ifdef VMA_IMPLEMENTATION
457
457
458
+ #include < cstdint>
458
459
#include < cstdlib>
459
460
460
461
/* ******************************************************************************
@@ -497,6 +498,11 @@ remove them if not needed.
497
498
#include < algorithm> // for min, max
498
499
#include < mutex> // for std::mutex
499
500
501
+ #if !defined(_WIN32)
502
+ #include < malloc.h> // for aligned_alloc()
503
+ #endif
504
+
505
+
500
506
#ifdef _DEBUG
501
507
// Normal assert to check for programmer's errors, especially in Debug configuration.
502
508
#define VMA_ASSERT (expr ) assert(expr)
@@ -512,8 +518,14 @@ remove them if not needed.
512
518
#define VMA_NULL nullptr
513
519
514
520
#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
517
529
518
530
#define VMA_MIN (v1, v2 ) (std::min((v1), (v2)))
519
531
#define VMA_MAX (v1, v2 ) (std::max((v1), (v2)))
@@ -841,6 +853,8 @@ class VmaStlAllocator
841
853
{
842
854
return m_pCallbacks != rhs.m_pCallbacks ;
843
855
}
856
+
857
+ VmaStlAllocator& operator =(const VmaStlAllocator& x) = delete ;
844
858
};
845
859
846
860
#if VMA_USE_STL_VECTOR
@@ -868,6 +882,14 @@ template<typename T, typename AllocatorT>
868
882
class VmaVector
869
883
{
870
884
public:
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
+
871
893
VmaVector (AllocatorT& allocator) :
872
894
m_Allocator (allocator),
873
895
m_pArray (VMA_NULL),
@@ -886,7 +908,7 @@ class VmaVector
886
908
887
909
VmaVector (const VmaVector<T, AllocatorT>& src) :
888
910
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),
890
912
m_Count (src.m_Count),
891
913
m_Capacity (src.m_Count)
892
914
{
@@ -956,7 +978,7 @@ class VmaVector
956
978
957
979
if (newCapacity != m_Capacity)
958
980
{
959
- T* const newArray = newCapacity ? VmaAllocateArray<T>(m_hAllocator , newCapacity) : VMA_NULL;
981
+ T* const newArray = newCapacity ? VmaAllocateArray<T>(m_Allocator , newCapacity) : VMA_NULL;
960
982
if (m_Count != 0 )
961
983
memcpy (newArray, m_pArray, m_Count * sizeof (T));
962
984
VmaFree (m_Allocator.m_pCallbacks , m_pArray);
@@ -1129,7 +1151,7 @@ T* VmaPoolAllocator<T>::Alloc()
1129
1151
{
1130
1152
ItemBlock& block = m_ItemBlocks[i];
1131
1153
// This block has some free items: Use first one.
1132
- if (block.FirstFreeIndex != UINT_MAX )
1154
+ if (block.FirstFreeIndex != UINT32_MAX )
1133
1155
{
1134
1156
Item* const pItem = &block.pItems [block.FirstFreeIndex ];
1135
1157
block.FirstFreeIndex = pItem->NextFreeIndex ;
@@ -1179,7 +1201,7 @@ typename VmaPoolAllocator<T>::ItemBlock& VmaPoolAllocator<T>::CreateNewBlock()
1179
1201
// Setup singly-linked list of all free items in this block.
1180
1202
for (uint32_t i = 0 ; i < m_ItemsPerBlock - 1 ; ++i)
1181
1203
newBlock.pItems [i].NextFreeIndex = i + 1 ;
1182
- newBlock.pItems [m_ItemsPerBlock - 1 ].NextFreeIndex = UINT_MAX ;
1204
+ newBlock.pItems [m_ItemsPerBlock - 1 ].NextFreeIndex = UINT32_MAX ;
1183
1205
return m_ItemBlocks.back ();
1184
1206
}
1185
1207
@@ -1340,7 +1362,7 @@ VmaListItem<T>* VmaRawList<T>::PushFront(const T& value)
1340
1362
{
1341
1363
ItemType* const pNewItem = PushFront ();
1342
1364
pNewItem->Value = value;
1343
- return newItem ;
1365
+ return pNewItem ;
1344
1366
}
1345
1367
1346
1368
template <typename T>
@@ -1621,6 +1643,7 @@ class VmaList
1621
1643
};
1622
1644
1623
1645
VmaList (AllocatorT& allocator) : m_RawList(allocator.m_pCallbacks) { }
1646
+ VmaList (const AllocatorT& allocator) : m_RawList(allocator.m_pCallbacks) { }
1624
1647
1625
1648
bool empty () const { return m_RawList.IsEmpty (); }
1626
1649
size_t size () const { return m_RawList.GetCount (); }
@@ -1675,6 +1698,7 @@ class VmaMap
1675
1698
typedef PairType* iterator;
1676
1699
1677
1700
VmaMap (VmaStlAllocator<PairType>& allocator) : m_Vector(allocator) { }
1701
+ VmaMap (const VmaStlAllocator<PairType>& allocator) : m_Vector(allocator) { }
1678
1702
1679
1703
iterator begin () { return m_Vector.begin (); }
1680
1704
iterator end () { return m_Vector.end (); }
@@ -2279,7 +2303,7 @@ bool VmaAllocation::Validate() const
2279
2303
How many suitable free suballocations to analyze before choosing best one.
2280
2304
- Set to 1 to use First-Fit algorithm - first suitable free suballocation will
2281
2305
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
2283
2307
suballocations will be analized and best one will be chosen.
2284
2308
- Any other value is also acceptable.
2285
2309
*/
@@ -2301,8 +2325,6 @@ bool VmaAllocation::CreateAllocationRequest(
2301
2325
if (m_SumFreeSize < allocSize)
2302
2326
return false ;
2303
2327
2304
- bool found = false ;
2305
-
2306
2328
// Old brute-force algorithm, linearly searching suballocations.
2307
2329
/*
2308
2330
uint32_t suitableSuballocationsFound = 0;
@@ -3128,7 +3150,7 @@ VkResult VmaAllocator_T::AllocateMemory(
3128
3150
3129
3151
// Bit mask of memory Vulkan types acceptable for this allocation.
3130
3152
uint32_t memoryTypeBits = vkMemReq.memoryTypeBits ;
3131
- uint32_t memTypeIndex = UINT_MAX ;
3153
+ uint32_t memTypeIndex = UINT32_MAX ;
3132
3154
VkResult res = vmaFindMemoryTypeIndex (this , memoryTypeBits, &vmaMemReq, &memTypeIndex);
3133
3155
if (res == VK_SUCCESS)
3134
3156
{
@@ -3579,8 +3601,8 @@ VkResult vmaFindMemoryTypeIndex(
3579
3601
break ;
3580
3602
}
3581
3603
3582
- *pMemoryTypeIndex = UINT_MAX ;
3583
- uint32_t minCost = UINT_MAX ;
3604
+ *pMemoryTypeIndex = UINT32_MAX ;
3605
+ uint32_t minCost = UINT32_MAX ;
3584
3606
for (uint32_t memTypeIndex = 0 , memTypeBit = 1 ;
3585
3607
memTypeIndex < allocator->GetMemoryTypeCount ();
3586
3608
++memTypeIndex, memTypeBit <<= 1 )
@@ -3606,7 +3628,7 @@ VkResult vmaFindMemoryTypeIndex(
3606
3628
}
3607
3629
}
3608
3630
}
3609
- return (*pMemoryTypeIndex != UINT_MAX ) ? VK_SUCCESS : VK_ERROR_FEATURE_NOT_PRESENT;
3631
+ return (*pMemoryTypeIndex != UINT32_MAX ) ? VK_SUCCESS : VK_ERROR_FEATURE_NOT_PRESENT;
3610
3632
}
3611
3633
3612
3634
VkResult vmaAllocateMemory (
0 commit comments