mirror of
https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator
synced 2024-11-05 12:20:07 +00:00
Fixed for Linux GCC compilation.
This commit is contained in:
parent
2f16fa52d8
commit
b2c2d3bd0b
@ -455,6 +455,7 @@ void vmaDestroyImage(
|
|||||||
|
|
||||||
#ifdef VMA_IMPLEMENTATION
|
#ifdef VMA_IMPLEMENTATION
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -497,6 +498,11 @@ remove them if not needed.
|
|||||||
#include <algorithm> // for min, max
|
#include <algorithm> // for min, max
|
||||||
#include <mutex> // for std::mutex
|
#include <mutex> // for std::mutex
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
|
#include <malloc.h> // for aligned_alloc()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
// Normal assert to check for programmer's errors, especially in Debug configuration.
|
// Normal assert to check for programmer's errors, especially in Debug configuration.
|
||||||
#define VMA_ASSERT(expr) assert(expr)
|
#define VMA_ASSERT(expr) assert(expr)
|
||||||
@ -512,8 +518,14 @@ remove them if not needed.
|
|||||||
#define VMA_NULL nullptr
|
#define VMA_NULL nullptr
|
||||||
|
|
||||||
#define VMA_ALIGN_OF(type) (__alignof(type))
|
#define VMA_ALIGN_OF(type) (__alignof(type))
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
#define VMA_SYSTEM_ALIGNED_MALLOC(size, alignment) (_aligned_malloc((size), (alignment)))
|
#define VMA_SYSTEM_ALIGNED_MALLOC(size, alignment) (_aligned_malloc((size), (alignment)))
|
||||||
#define VMA_SYSTEM_FREE(ptr) _aligned_free(ptr)
|
#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_MIN(v1, v2) (std::min((v1), (v2)))
|
||||||
#define VMA_MAX(v1, v2) (std::max((v1), (v2)))
|
#define VMA_MAX(v1, v2) (std::max((v1), (v2)))
|
||||||
@ -841,6 +853,8 @@ public:
|
|||||||
{
|
{
|
||||||
return m_pCallbacks != rhs.m_pCallbacks;
|
return m_pCallbacks != rhs.m_pCallbacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VmaStlAllocator& operator=(const VmaStlAllocator& x) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if VMA_USE_STL_VECTOR
|
#if VMA_USE_STL_VECTOR
|
||||||
@ -868,6 +882,14 @@ template<typename T, typename AllocatorT>
|
|||||||
class VmaVector
|
class VmaVector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
VmaVector(const AllocatorT& allocator) :
|
||||||
|
m_Allocator(allocator),
|
||||||
|
m_pArray(VMA_NULL),
|
||||||
|
m_Count(0),
|
||||||
|
m_Capacity(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
VmaVector(AllocatorT& allocator) :
|
VmaVector(AllocatorT& allocator) :
|
||||||
m_Allocator(allocator),
|
m_Allocator(allocator),
|
||||||
m_pArray(VMA_NULL),
|
m_pArray(VMA_NULL),
|
||||||
@ -886,7 +908,7 @@ public:
|
|||||||
|
|
||||||
VmaVector(const VmaVector<T, AllocatorT>& src) :
|
VmaVector(const VmaVector<T, AllocatorT>& src) :
|
||||||
m_Allocator(src.m_Allocator),
|
m_Allocator(src.m_Allocator),
|
||||||
m_pArray(src.m_Count ? (T*)VmaAllocateArray<T>(allocator->m_pCallbacks, src.m_Count) : VMA_NULL),
|
m_pArray(src.m_Count ? (T*)VmaAllocateArray<T>(src->m_pCallbacks, src.m_Count) : VMA_NULL),
|
||||||
m_Count(src.m_Count),
|
m_Count(src.m_Count),
|
||||||
m_Capacity(src.m_Count)
|
m_Capacity(src.m_Count)
|
||||||
{
|
{
|
||||||
@ -956,7 +978,7 @@ public:
|
|||||||
|
|
||||||
if(newCapacity != m_Capacity)
|
if(newCapacity != m_Capacity)
|
||||||
{
|
{
|
||||||
T* const newArray = newCapacity ? VmaAllocateArray<T>(m_hAllocator, newCapacity) : VMA_NULL;
|
T* const newArray = newCapacity ? VmaAllocateArray<T>(m_Allocator, newCapacity) : VMA_NULL;
|
||||||
if(m_Count != 0)
|
if(m_Count != 0)
|
||||||
memcpy(newArray, m_pArray, m_Count * sizeof(T));
|
memcpy(newArray, m_pArray, m_Count * sizeof(T));
|
||||||
VmaFree(m_Allocator.m_pCallbacks, m_pArray);
|
VmaFree(m_Allocator.m_pCallbacks, m_pArray);
|
||||||
@ -1129,7 +1151,7 @@ T* VmaPoolAllocator<T>::Alloc()
|
|||||||
{
|
{
|
||||||
ItemBlock& block = m_ItemBlocks[i];
|
ItemBlock& block = m_ItemBlocks[i];
|
||||||
// This block has some free items: Use first one.
|
// 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];
|
Item* const pItem = &block.pItems[block.FirstFreeIndex];
|
||||||
block.FirstFreeIndex = pItem->NextFreeIndex;
|
block.FirstFreeIndex = pItem->NextFreeIndex;
|
||||||
@ -1179,7 +1201,7 @@ typename VmaPoolAllocator<T>::ItemBlock& VmaPoolAllocator<T>::CreateNewBlock()
|
|||||||
// Setup singly-linked list of all free items in this block.
|
// Setup singly-linked list of all free items in this block.
|
||||||
for(uint32_t i = 0; i < m_ItemsPerBlock - 1; ++i)
|
for(uint32_t i = 0; i < m_ItemsPerBlock - 1; ++i)
|
||||||
newBlock.pItems[i].NextFreeIndex = i + 1;
|
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();
|
return m_ItemBlocks.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1340,7 +1362,7 @@ VmaListItem<T>* VmaRawList<T>::PushFront(const T& value)
|
|||||||
{
|
{
|
||||||
ItemType* const pNewItem = PushFront();
|
ItemType* const pNewItem = PushFront();
|
||||||
pNewItem->Value = value;
|
pNewItem->Value = value;
|
||||||
return newItem;
|
return pNewItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -1621,6 +1643,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
VmaList(AllocatorT& allocator) : m_RawList(allocator.m_pCallbacks) { }
|
VmaList(AllocatorT& allocator) : m_RawList(allocator.m_pCallbacks) { }
|
||||||
|
VmaList(const AllocatorT& allocator) : m_RawList(allocator.m_pCallbacks) { }
|
||||||
|
|
||||||
bool empty() const { return m_RawList.IsEmpty(); }
|
bool empty() const { return m_RawList.IsEmpty(); }
|
||||||
size_t size() const { return m_RawList.GetCount(); }
|
size_t size() const { return m_RawList.GetCount(); }
|
||||||
@ -1675,6 +1698,7 @@ public:
|
|||||||
typedef PairType* iterator;
|
typedef PairType* iterator;
|
||||||
|
|
||||||
VmaMap(VmaStlAllocator<PairType>& allocator) : m_Vector(allocator) { }
|
VmaMap(VmaStlAllocator<PairType>& allocator) : m_Vector(allocator) { }
|
||||||
|
VmaMap(const VmaStlAllocator<PairType>& allocator) : m_Vector(allocator) { }
|
||||||
|
|
||||||
iterator begin() { return m_Vector.begin(); }
|
iterator begin() { return m_Vector.begin(); }
|
||||||
iterator end() { return m_Vector.end(); }
|
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.
|
How many suitable free suballocations to analyze before choosing best one.
|
||||||
- Set to 1 to use First-Fit algorithm - first suitable free suballocation will
|
- Set to 1 to use First-Fit algorithm - first suitable free suballocation will
|
||||||
be chosen.
|
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.
|
suballocations will be analized and best one will be chosen.
|
||||||
- Any other value is also acceptable.
|
- Any other value is also acceptable.
|
||||||
*/
|
*/
|
||||||
@ -2301,8 +2325,6 @@ bool VmaAllocation::CreateAllocationRequest(
|
|||||||
if(m_SumFreeSize < allocSize)
|
if(m_SumFreeSize < allocSize)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool found = false;
|
|
||||||
|
|
||||||
// Old brute-force algorithm, linearly searching suballocations.
|
// Old brute-force algorithm, linearly searching suballocations.
|
||||||
/*
|
/*
|
||||||
uint32_t suitableSuballocationsFound = 0;
|
uint32_t suitableSuballocationsFound = 0;
|
||||||
@ -3128,7 +3150,7 @@ VkResult VmaAllocator_T::AllocateMemory(
|
|||||||
|
|
||||||
// Bit mask of memory Vulkan types acceptable for this allocation.
|
// Bit mask of memory Vulkan types acceptable for this allocation.
|
||||||
uint32_t memoryTypeBits = vkMemReq.memoryTypeBits;
|
uint32_t memoryTypeBits = vkMemReq.memoryTypeBits;
|
||||||
uint32_t memTypeIndex = UINT_MAX;
|
uint32_t memTypeIndex = UINT32_MAX;
|
||||||
VkResult res = vmaFindMemoryTypeIndex(this, memoryTypeBits, &vmaMemReq, &memTypeIndex);
|
VkResult res = vmaFindMemoryTypeIndex(this, memoryTypeBits, &vmaMemReq, &memTypeIndex);
|
||||||
if(res == VK_SUCCESS)
|
if(res == VK_SUCCESS)
|
||||||
{
|
{
|
||||||
@ -3579,8 +3601,8 @@ VkResult vmaFindMemoryTypeIndex(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*pMemoryTypeIndex = UINT_MAX;
|
*pMemoryTypeIndex = UINT32_MAX;
|
||||||
uint32_t minCost = UINT_MAX;
|
uint32_t minCost = UINT32_MAX;
|
||||||
for(uint32_t memTypeIndex = 0, memTypeBit = 1;
|
for(uint32_t memTypeIndex = 0, memTypeBit = 1;
|
||||||
memTypeIndex < allocator->GetMemoryTypeCount();
|
memTypeIndex < allocator->GetMemoryTypeCount();
|
||||||
++memTypeIndex, memTypeBit <<= 1)
|
++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(
|
VkResult vmaAllocateMemory(
|
||||||
|
Loading…
Reference in New Issue
Block a user