Removed VMA_USE_STL_CONTAINERS

This commit is contained in:
Adam Sawicki 2021-12-22 14:57:18 +01:00
parent cbad11e039
commit 7c48285034
5 changed files with 45 additions and 102 deletions

View File

@ -15,7 +15,6 @@ message(STATUS "VMA_BUILD_SAMPLE_SHADERS = ${VMA_BUILD_SAMPLE_SHADERS}")
message(STATUS "VMA_BUILD_REPLAY = ${VMA_BUILD_REPLAY}") message(STATUS "VMA_BUILD_REPLAY = ${VMA_BUILD_REPLAY}")
option(VMA_RECORDING_ENABLED "Enable VMA memory recording for debugging" OFF) option(VMA_RECORDING_ENABLED "Enable VMA memory recording for debugging" OFF)
option(VMA_USE_STL_CONTAINERS "Use C++ STL containers instead of VMA's containers" OFF)
option(VMA_STATIC_VULKAN_FUNCTIONS "Link statically with Vulkan API" ON) option(VMA_STATIC_VULKAN_FUNCTIONS "Link statically with Vulkan API" ON)
option(VMA_DYNAMIC_VULKAN_FUNCTIONS "Fetch pointers to Vulkan functions internally (no static linking)" OFF) option(VMA_DYNAMIC_VULKAN_FUNCTIONS "Fetch pointers to Vulkan functions internally (no static linking)" OFF)
option(VMA_DEBUG_ALWAYS_DEDICATED_MEMORY "Every allocation will have its own memory block" OFF) option(VMA_DEBUG_ALWAYS_DEDICATED_MEMORY "Every allocation will have its own memory block" OFF)
@ -24,7 +23,6 @@ option(VMA_DEBUG_GLOBAL_MUTEX "Enable single mutex protecting all entry calls to
option(VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT "Never exceed VkPhysicalDeviceLimits::maxMemoryAllocationCount and return error" OFF) option(VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT "Never exceed VkPhysicalDeviceLimits::maxMemoryAllocationCount and return error" OFF)
message(STATUS "VMA_RECORDING_ENABLED = ${VMA_RECORDING_ENABLED}") message(STATUS "VMA_RECORDING_ENABLED = ${VMA_RECORDING_ENABLED}")
message(STATUS "VMA_USE_STL_CONTAINERS = ${VMA_USE_STL_CONTAINERS}")
message(STATUS "VMA_STATIC_VULKAN_FUNCTIONS = ${VMA_STATIC_VULKAN_FUNCTIONS}") message(STATUS "VMA_STATIC_VULKAN_FUNCTIONS = ${VMA_STATIC_VULKAN_FUNCTIONS}")
message(STATUS "VMA_DYNAMIC_VULKAN_FUNCTIONS = ${VMA_DYNAMIC_VULKAN_FUNCTIONS}") message(STATUS "VMA_DYNAMIC_VULKAN_FUNCTIONS = ${VMA_DYNAMIC_VULKAN_FUNCTIONS}")
message(STATUS "VMA_DEBUG_ALWAYS_DEDICATED_MEMORY = ${VMA_DEBUG_ALWAYS_DEDICATED_MEMORY}") message(STATUS "VMA_DEBUG_ALWAYS_DEDICATED_MEMORY = ${VMA_DEBUG_ALWAYS_DEDICATED_MEMORY}")

View File

@ -65,7 +65,7 @@ Additional features:
# Prequisites # Prequisites
- Self-contained C++ library in single header file. No external dependencies other than standard C and C++ library and of course Vulkan. Some features of C++14 used. STL containers are not used by default. - Self-contained C++ library in single header file. No external dependencies other than standard C and C++ library and of course Vulkan. Some features of C++14 used. STL containers are not used.
- Public interface in C, in same convention as Vulkan API. Implementation in C++. - Public interface in C, in same convention as Vulkan API. Implementation in C++.
- Error handling implemented by returning `VkResult` error codes - same way as in Vulkan. - Error handling implemented by returning `VkResult` error codes - same way as in Vulkan.
- Interface documented using Doxygen-style comments. - Interface documented using Doxygen-style comments.

View File

@ -2508,21 +2508,6 @@ VmaAllocatorCreateInfo::pVulkanFunctions. Other members can be null.
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1 #define VMA_DYNAMIC_VULKAN_FUNCTIONS 1
#endif #endif
// Define this macro to 1 to make the library use STL containers instead of its own implementation.
//#define VMA_USE_STL_CONTAINERS 1
/* Set this macro to 1 to make the library including and using STL containers:
std::pair, std::vector, std::list, std::unordered_map.
Set it to 0 or undefined to make the library using its own implementation of
the containers.
*/
#if VMA_USE_STL_CONTAINERS
#define VMA_USE_STL_VECTOR 1
#define VMA_USE_STL_UNORDERED_MAP 1
#define VMA_USE_STL_LIST 1
#endif
#ifndef VMA_USE_STL_SHARED_MUTEX #ifndef VMA_USE_STL_SHARED_MUTEX
// Compiler conforms to C++17. // Compiler conforms to C++17.
#if __cplusplus >= 201703L #if __cplusplus >= 201703L
@ -2536,22 +2521,6 @@ the containers.
#endif #endif
#endif #endif
/*
THESE INCLUDES ARE NOT ENABLED BY DEFAULT.
Library has its own container implementation.
*/
#if VMA_USE_STL_VECTOR
#include <vector>
#endif
#if VMA_USE_STL_UNORDERED_MAP
#include <unordered_map>
#endif
#if VMA_USE_STL_LIST
#include <list>
#endif
/* /*
Following headers are used in this CONFIGURATION section only, so feel free to Following headers are used in this CONFIGURATION section only, so feel free to
remove them if not needed. remove them if not needed.
@ -2971,12 +2940,8 @@ struct AtomicTransactionalIncrement;
template<typename T> template<typename T>
struct VmaStlAllocator; struct VmaStlAllocator;
#if VMA_USE_STL_VECTOR
#define VmaVector std::vector
#else
template<typename T, typename AllocatorT> template<typename T, typename AllocatorT>
class VmaVector; class VmaVector;
#endif // VMA_USE_STL_VECTOR
template<typename T, typename AllocatorT, size_t N> template<typename T, typename AllocatorT, size_t N>
class VmaSmallVector; class VmaSmallVector;
@ -2984,9 +2949,6 @@ class VmaSmallVector;
template<typename T> template<typename T>
class VmaPoolAllocator; class VmaPoolAllocator;
#if VMA_USE_STL_LIST
#define VmaList std::list
#else
template<typename T> template<typename T>
struct VmaListItem; struct VmaListItem;
@ -2995,11 +2957,21 @@ class VmaRawList;
template<typename T, typename AllocatorT> template<typename T, typename AllocatorT>
class VmaList; class VmaList;
#endif // VMA_USE_STL_LIST
template<typename ItemTypeTraits> template<typename ItemTypeTraits>
class VmaIntrusiveLinkedList; class VmaIntrusiveLinkedList;
// Unused in this version
#if 0
template<typename T1, typename T2>
struct VmaPair;
template<typename FirstT, typename SecondT>
struct VmaPairFirstLess;
template<typename KeyT, typename ValueT>
class VmaMap;
#endif
#if VMA_STATS_STRING_ENABLED #if VMA_STATS_STRING_ENABLED
class VmaStringBuilder; class VmaStringBuilder;
class VmaJsonWriter; class VmaJsonWriter;
@ -3693,21 +3665,7 @@ struct VmaStlAllocator
}; };
#endif // _VMA_STL_ALLOCATOR #endif // _VMA_STL_ALLOCATOR
#if VMA_USE_STL_VECTOR #ifndef _VMA_VECTOR
template<typename T, typename allocatorT>
static void VmaVectorInsert(std::vector<T, allocatorT>& vec, size_t index, const T& item)
{
vec.insert(vec.begin() + index, item);
}
template<typename T, typename allocatorT>
static void VmaVectorRemove(std::vector<T, allocatorT>& vec, size_t index)
{
vec.erase(vec.begin() + index);
}
#else
/* Class with interface compatible with subset of std::vector. /* Class with interface compatible with subset of std::vector.
T must be POD because constructors and destructors are not called and memcpy is T must be POD because constructors and destructors are not called and memcpy is
used for these objects. */ used for these objects. */
@ -3918,8 +3876,7 @@ static void VmaVectorRemove(VmaVector<T, allocatorT>& vec, size_t index)
{ {
vec.remove(index); vec.remove(index);
} }
#endif // _VMA_VECTOR
#endif // VMA_USE_STL_VECTOR
#ifndef _VMA_SMALL_VECTOR #ifndef _VMA_SMALL_VECTOR
/* /*
@ -4205,7 +4162,6 @@ typename VmaPoolAllocator<T>::ItemBlock& VmaPoolAllocator<T>::CreateNewBlock()
#endif // _VMA_POOL_ALLOCATOR_FUNCTIONS #endif // _VMA_POOL_ALLOCATOR_FUNCTIONS
#endif // _VMA_POOL_ALLOCATOR #endif // _VMA_POOL_ALLOCATOR
#ifndef VMA_USE_STL_LIST
#ifndef _VMA_RAW_LIST #ifndef _VMA_RAW_LIST
template<typename T> template<typename T>
struct VmaListItem struct VmaListItem
@ -4686,7 +4642,6 @@ typename VmaList<T, AllocatorT>::const_reverse_iterator& VmaList<T, AllocatorT>:
} }
#endif // _VMA_LIST_FUNCTIONS #endif // _VMA_LIST_FUNCTIONS
#endif // _VMA_LIST #endif // _VMA_LIST
#endif // VMA_USE_STL_LIST
#ifndef _VMA_INTRUSIVE_LINKED_LIST #ifndef _VMA_INTRUSIVE_LINKED_LIST
/* /*
@ -4939,15 +4894,7 @@ void VmaIntrusiveLinkedList<ItemTypeTraits>::RemoveAll()
// Unused in this version. // Unused in this version.
#if 0 #if 0
#if VMA_USE_STL_UNORDERED_MAP #ifndef _VMA_PAIR
#define VmaPair std::pair
#define VMA_MAP_TYPE(KeyT, ValueT) \
std::unordered_map< KeyT, ValueT, std::hash<KeyT>, std::equal_to<KeyT>, VmaStlAllocator< std::pair<KeyT, ValueT> > >
#else // #if VMA_USE_STL_UNORDERED_MAP
template<typename T1, typename T2> template<typename T1, typename T2>
struct VmaPair struct VmaPair
{ {
@ -4958,6 +4905,21 @@ struct VmaPair
VmaPair(const T1& firstSrc, const T2& secondSrc) : first(firstSrc), second(secondSrc) {} VmaPair(const T1& firstSrc, const T2& secondSrc) : first(firstSrc), second(secondSrc) {}
}; };
template<typename FirstT, typename SecondT>
struct VmaPairFirstLess
{
bool operator()(const VmaPair<FirstT, SecondT>& lhs, const VmaPair<FirstT, SecondT>& rhs) const
{
return lhs.first < rhs.first;
}
bool operator()(const VmaPair<FirstT, SecondT>& lhs, const FirstT& rhsFirst) const
{
return lhs.first < rhsFirst;
}
};
#endif // _VMA_PAIR
#ifndef _VMA_MAP
/* Class compatible with subset of interface of std::unordered_map. /* Class compatible with subset of interface of std::unordered_map.
KeyT, ValueT must be POD because they will be stored in VmaVector. KeyT, ValueT must be POD because they will be stored in VmaVector.
*/ */
@ -4981,21 +4943,7 @@ private:
VmaVector< PairType, VmaStlAllocator<PairType> > m_Vector; VmaVector< PairType, VmaStlAllocator<PairType> > m_Vector;
}; };
#define VMA_MAP_TYPE(KeyT, ValueT) VmaMap<KeyT, ValueT> #ifndef _VMA_MAP_FUNCTIONS
template<typename FirstT, typename SecondT>
struct VmaPairFirstLess
{
bool operator()(const VmaPair<FirstT, SecondT>& lhs, const VmaPair<FirstT, SecondT>& rhs) const
{
return lhs.first < rhs.first;
}
bool operator()(const VmaPair<FirstT, SecondT>& lhs, const FirstT& rhsFirst) const
{
return lhs.first < rhsFirst;
}
};
template<typename KeyT, typename ValueT> template<typename KeyT, typename ValueT>
void VmaMap<KeyT, ValueT>::insert(const PairType& pair) void VmaMap<KeyT, ValueT>::insert(const PairType& pair)
{ {
@ -5030,8 +4978,8 @@ void VmaMap<KeyT, ValueT>::erase(iterator it)
{ {
VmaVectorRemove(m_Vector, it - m_Vector.begin()); VmaVectorRemove(m_Vector, it - m_Vector.begin());
} }
#endif // _VMA_MAP_FUNCTIONS
#endif // #if VMA_USE_STL_UNORDERED_MAP #endif // _VMA_MAP
#endif // #if 0 #endif // #if 0

View File

@ -47,7 +47,6 @@ target_compile_definitions(
VulkanMemoryAllocator VulkanMemoryAllocator
PUBLIC PUBLIC
VMA_USE_STL_CONTAINERS=$<BOOL:${VMA_USE_STL_CONTAINERS}>
VMA_STATIC_VULKAN_FUNCTIONS=$<BOOL:${VULKAN_USE_STATIC}> VMA_STATIC_VULKAN_FUNCTIONS=$<BOOL:${VULKAN_USE_STATIC}>
VMA_DYNAMIC_VULKAN_FUNCTIONS=$<BOOL:${VULKAN_USE_DYNAMIC}> VMA_DYNAMIC_VULKAN_FUNCTIONS=$<BOOL:${VULKAN_USE_DYNAMIC}>
VMA_DEBUG_ALWAYS_DEDICATED_MEMORY=$<BOOL:${VMA_DEBUG_ALWAYS_DEDICATED_MEMORY}> VMA_DEBUG_ALWAYS_DEDICATED_MEMORY=$<BOOL:${VMA_DEBUG_ALWAYS_DEDICATED_MEMORY}>

View File

@ -31,8 +31,6 @@
#endif // #if !defined(VK_USE_PLATFORM_WIN32_KHR) #endif // #if !defined(VK_USE_PLATFORM_WIN32_KHR)
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
//#define VMA_USE_STL_CONTAINERS 1
//#define VMA_HEAVY_ASSERT(expr) assert(expr) //#define VMA_HEAVY_ASSERT(expr) assert(expr)
//#define VMA_DEDICATED_ALLOCATION 0 //#define VMA_DEDICATED_ALLOCATION 0