From b2c2d3bd0b8390ca41800ad1a166e0ebe8531b0a Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Tue, 4 Jul 2017 14:43:37 +0200 Subject: [PATCH] Fixed for Linux GCC compilation. --- src/vk_mem_alloc.h | 50 +++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/src/vk_mem_alloc.h b/src/vk_mem_alloc.h index 64503c7..8d66b2d 100644 --- a/src/vk_mem_alloc.h +++ b/src/vk_mem_alloc.h @@ -455,6 +455,7 @@ void vmaDestroyImage( #ifdef VMA_IMPLEMENTATION +#include #include /******************************************************************************* @@ -497,6 +498,11 @@ remove them if not needed. #include // for min, max #include // for std::mutex +#if !defined(_WIN32) + #include // for aligned_alloc() +#endif + + #ifdef _DEBUG // Normal assert to check for programmer's errors, especially in Debug configuration. #define VMA_ASSERT(expr) assert(expr) @@ -512,8 +518,14 @@ remove them if not needed. #define VMA_NULL nullptr #define VMA_ALIGN_OF(type) (__alignof(type)) -#define VMA_SYSTEM_ALIGNED_MALLOC(size, alignment) (_aligned_malloc((size), (alignment))) -#define VMA_SYSTEM_FREE(ptr) _aligned_free(ptr) + +#if defined(_WIN32) + #define VMA_SYSTEM_ALIGNED_MALLOC(size, alignment) (_aligned_malloc((size), (alignment))) + #define VMA_SYSTEM_FREE(ptr) _aligned_free(ptr) +#else + #define VMA_SYSTEM_ALIGNED_MALLOC(size, alignment) (aligned_alloc((alignment), (size) )) + #define VMA_SYSTEM_FREE(ptr) free(ptr) +#endif #define VMA_MIN(v1, v2) (std::min((v1), (v2))) #define VMA_MAX(v1, v2) (std::max((v1), (v2))) @@ -841,6 +853,8 @@ public: { return m_pCallbacks != rhs.m_pCallbacks; } + + VmaStlAllocator& operator=(const VmaStlAllocator& x) = delete; }; #if VMA_USE_STL_VECTOR @@ -868,6 +882,14 @@ template class VmaVector { public: + VmaVector(const AllocatorT& allocator) : + m_Allocator(allocator), + m_pArray(VMA_NULL), + m_Count(0), + m_Capacity(0) + { + } + VmaVector(AllocatorT& allocator) : m_Allocator(allocator), m_pArray(VMA_NULL), @@ -886,7 +908,7 @@ public: VmaVector(const VmaVector& src) : m_Allocator(src.m_Allocator), - m_pArray(src.m_Count ? (T*)VmaAllocateArray(allocator->m_pCallbacks, src.m_Count) : VMA_NULL), + m_pArray(src.m_Count ? (T*)VmaAllocateArray(src->m_pCallbacks, src.m_Count) : VMA_NULL), m_Count(src.m_Count), m_Capacity(src.m_Count) { @@ -956,7 +978,7 @@ public: if(newCapacity != m_Capacity) { - T* const newArray = newCapacity ? VmaAllocateArray(m_hAllocator, newCapacity) : VMA_NULL; + T* const newArray = newCapacity ? VmaAllocateArray(m_Allocator, newCapacity) : VMA_NULL; if(m_Count != 0) memcpy(newArray, m_pArray, m_Count * sizeof(T)); VmaFree(m_Allocator.m_pCallbacks, m_pArray); @@ -1129,7 +1151,7 @@ T* VmaPoolAllocator::Alloc() { ItemBlock& block = m_ItemBlocks[i]; // This block has some free items: Use first one. - if(block.FirstFreeIndex != UINT_MAX) + if(block.FirstFreeIndex != UINT32_MAX) { Item* const pItem = &block.pItems[block.FirstFreeIndex]; block.FirstFreeIndex = pItem->NextFreeIndex; @@ -1179,7 +1201,7 @@ typename VmaPoolAllocator::ItemBlock& VmaPoolAllocator::CreateNewBlock() // Setup singly-linked list of all free items in this block. for(uint32_t i = 0; i < m_ItemsPerBlock - 1; ++i) newBlock.pItems[i].NextFreeIndex = i + 1; - newBlock.pItems[m_ItemsPerBlock - 1].NextFreeIndex = UINT_MAX; + newBlock.pItems[m_ItemsPerBlock - 1].NextFreeIndex = UINT32_MAX; return m_ItemBlocks.back(); } @@ -1340,7 +1362,7 @@ VmaListItem* VmaRawList::PushFront(const T& value) { ItemType* const pNewItem = PushFront(); pNewItem->Value = value; - return newItem; + return pNewItem; } template @@ -1621,6 +1643,7 @@ public: }; VmaList(AllocatorT& allocator) : m_RawList(allocator.m_pCallbacks) { } + VmaList(const AllocatorT& allocator) : m_RawList(allocator.m_pCallbacks) { } bool empty() const { return m_RawList.IsEmpty(); } size_t size() const { return m_RawList.GetCount(); } @@ -1675,6 +1698,7 @@ public: typedef PairType* iterator; VmaMap(VmaStlAllocator& allocator) : m_Vector(allocator) { } + VmaMap(const VmaStlAllocator& allocator) : m_Vector(allocator) { } iterator begin() { return m_Vector.begin(); } iterator end() { return m_Vector.end(); } @@ -2279,7 +2303,7 @@ bool VmaAllocation::Validate() const How many suitable free suballocations to analyze before choosing best one. - Set to 1 to use First-Fit algorithm - first suitable free suballocation will be chosen. -- Set to UINT_MAX to use Best-Fit/Worst-Fit algorithm - all suitable free +- Set to UINT32_MAX to use Best-Fit/Worst-Fit algorithm - all suitable free suballocations will be analized and best one will be chosen. - Any other value is also acceptable. */ @@ -2301,8 +2325,6 @@ bool VmaAllocation::CreateAllocationRequest( if(m_SumFreeSize < allocSize) return false; - bool found = false; - // Old brute-force algorithm, linearly searching suballocations. /* uint32_t suitableSuballocationsFound = 0; @@ -3128,7 +3150,7 @@ VkResult VmaAllocator_T::AllocateMemory( // Bit mask of memory Vulkan types acceptable for this allocation. uint32_t memoryTypeBits = vkMemReq.memoryTypeBits; - uint32_t memTypeIndex = UINT_MAX; + uint32_t memTypeIndex = UINT32_MAX; VkResult res = vmaFindMemoryTypeIndex(this, memoryTypeBits, &vmaMemReq, &memTypeIndex); if(res == VK_SUCCESS) { @@ -3579,8 +3601,8 @@ VkResult vmaFindMemoryTypeIndex( break; } - *pMemoryTypeIndex = UINT_MAX; - uint32_t minCost = UINT_MAX; + *pMemoryTypeIndex = UINT32_MAX; + uint32_t minCost = UINT32_MAX; for(uint32_t memTypeIndex = 0, memTypeBit = 1; memTypeIndex < allocator->GetMemoryTypeCount(); ++memTypeIndex, memTypeBit <<= 1) @@ -3606,7 +3628,7 @@ VkResult vmaFindMemoryTypeIndex( } } } - return (*pMemoryTypeIndex != UINT_MAX) ? VK_SUCCESS : VK_ERROR_FEATURE_NOT_PRESENT; + return (*pMemoryTypeIndex != UINT32_MAX) ? VK_SUCCESS : VK_ERROR_FEATURE_NOT_PRESENT; } VkResult vmaAllocateMemory(