From 7c482850344d0345a85f7c5c1c09e3d203893004 Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Wed, 22 Dec 2021 14:57:18 +0100 Subject: [PATCH] Removed VMA_USE_STL_CONTAINERS --- CMakeLists.txt | 2 - README.md | 2 +- include/vk_mem_alloc.h | 140 ++++++++++++--------------------------- src/CMakeLists.txt | 1 - src/VmaReplay/VmaUsage.h | 2 - 5 files changed, 45 insertions(+), 102 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bacd8b6..d46b019 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,6 @@ message(STATUS "VMA_BUILD_SAMPLE_SHADERS = ${VMA_BUILD_SAMPLE_SHADERS}") message(STATUS "VMA_BUILD_REPLAY = ${VMA_BUILD_REPLAY}") 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_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) @@ -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) 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_DYNAMIC_VULKAN_FUNCTIONS = ${VMA_DYNAMIC_VULKAN_FUNCTIONS}") message(STATUS "VMA_DEBUG_ALWAYS_DEDICATED_MEMORY = ${VMA_DEBUG_ALWAYS_DEDICATED_MEMORY}") diff --git a/README.md b/README.md index 5c1e81a..0f2f2a5 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ Additional features: # 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++. - Error handling implemented by returning `VkResult` error codes - same way as in Vulkan. - Interface documented using Doxygen-style comments. diff --git a/include/vk_mem_alloc.h b/include/vk_mem_alloc.h index aa5dfb4..ec9b977 100644 --- a/include/vk_mem_alloc.h +++ b/include/vk_mem_alloc.h @@ -2508,21 +2508,6 @@ VmaAllocatorCreateInfo::pVulkanFunctions. Other members can be null. #define VMA_DYNAMIC_VULKAN_FUNCTIONS 1 #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 // Compiler conforms to C++17. #if __cplusplus >= 201703L @@ -2536,22 +2521,6 @@ the containers. #endif #endif -/* -THESE INCLUDES ARE NOT ENABLED BY DEFAULT. -Library has its own container implementation. -*/ -#if VMA_USE_STL_VECTOR - #include -#endif - -#if VMA_USE_STL_UNORDERED_MAP - #include -#endif - -#if VMA_USE_STL_LIST - #include -#endif - /* Following headers are used in this CONFIGURATION section only, so feel free to remove them if not needed. @@ -2971,12 +2940,8 @@ struct AtomicTransactionalIncrement; template struct VmaStlAllocator; -#if VMA_USE_STL_VECTOR -#define VmaVector std::vector -#else template class VmaVector; -#endif // VMA_USE_STL_VECTOR template class VmaSmallVector; @@ -2984,9 +2949,6 @@ class VmaSmallVector; template class VmaPoolAllocator; -#if VMA_USE_STL_LIST -#define VmaList std::list -#else template struct VmaListItem; @@ -2995,11 +2957,21 @@ class VmaRawList; template class VmaList; -#endif // VMA_USE_STL_LIST template class VmaIntrusiveLinkedList; +// Unused in this version +#if 0 +template +struct VmaPair; +template +struct VmaPairFirstLess; + +template +class VmaMap; +#endif + #if VMA_STATS_STRING_ENABLED class VmaStringBuilder; class VmaJsonWriter; @@ -3693,21 +3665,7 @@ struct VmaStlAllocator }; #endif // _VMA_STL_ALLOCATOR -#if VMA_USE_STL_VECTOR - -template -static void VmaVectorInsert(std::vector& vec, size_t index, const T& item) -{ - vec.insert(vec.begin() + index, item); -} - -template -static void VmaVectorRemove(std::vector& vec, size_t index) -{ - vec.erase(vec.begin() + index); -} - -#else +#ifndef _VMA_VECTOR /* Class with interface compatible with subset of std::vector. T must be POD because constructors and destructors are not called and memcpy is used for these objects. */ @@ -3918,8 +3876,7 @@ static void VmaVectorRemove(VmaVector& vec, size_t index) { vec.remove(index); } - -#endif // VMA_USE_STL_VECTOR +#endif // _VMA_VECTOR #ifndef _VMA_SMALL_VECTOR /* @@ -4205,7 +4162,6 @@ typename VmaPoolAllocator::ItemBlock& VmaPoolAllocator::CreateNewBlock() #endif // _VMA_POOL_ALLOCATOR_FUNCTIONS #endif // _VMA_POOL_ALLOCATOR -#ifndef VMA_USE_STL_LIST #ifndef _VMA_RAW_LIST template struct VmaListItem @@ -4686,7 +4642,6 @@ typename VmaList::const_reverse_iterator& VmaList: } #endif // _VMA_LIST_FUNCTIONS #endif // _VMA_LIST -#endif // VMA_USE_STL_LIST #ifndef _VMA_INTRUSIVE_LINKED_LIST /* @@ -4939,50 +4894,17 @@ void VmaIntrusiveLinkedList::RemoveAll() // Unused in this version. #if 0 -#if VMA_USE_STL_UNORDERED_MAP - -#define VmaPair std::pair - -#define VMA_MAP_TYPE(KeyT, ValueT) \ - std::unordered_map< KeyT, ValueT, std::hash, std::equal_to, VmaStlAllocator< std::pair > > - -#else // #if VMA_USE_STL_UNORDERED_MAP - +#ifndef _VMA_PAIR template struct VmaPair { T1 first; T2 second; - VmaPair() : first(), second() { } - VmaPair(const T1& firstSrc, const T2& secondSrc) : first(firstSrc), second(secondSrc) { } + VmaPair() : first(), second() {} + VmaPair(const T1& firstSrc, const T2& secondSrc) : first(firstSrc), second(secondSrc) {} }; -/* Class compatible with subset of interface of std::unordered_map. -KeyT, ValueT must be POD because they will be stored in VmaVector. -*/ -template -class VmaMap -{ -public: - typedef VmaPair PairType; - typedef PairType* iterator; - - VmaMap(const VmaStlAllocator& allocator) : m_Vector(allocator) { } - - iterator begin() { return m_Vector.begin(); } - iterator end() { return m_Vector.end(); } - - void insert(const PairType& pair); - iterator find(const KeyT& key); - void erase(iterator it); - -private: - VmaVector< PairType, VmaStlAllocator > m_Vector; -}; - -#define VMA_MAP_TYPE(KeyT, ValueT) VmaMap - template struct VmaPairFirstLess { @@ -4995,7 +4917,33 @@ struct VmaPairFirstLess return lhs.first < rhsFirst; } }; +#endif // _VMA_PAIR +#ifndef _VMA_MAP +/* Class compatible with subset of interface of std::unordered_map. +KeyT, ValueT must be POD because they will be stored in VmaVector. +*/ +template +class VmaMap +{ +public: + typedef VmaPair PairType; + typedef PairType* iterator; + + VmaMap(const VmaStlAllocator& allocator) : m_Vector(allocator) {} + + iterator begin() { return m_Vector.begin(); } + iterator end() { return m_Vector.end(); } + + void insert(const PairType& pair); + iterator find(const KeyT& key); + void erase(iterator it); + +private: + VmaVector< PairType, VmaStlAllocator > m_Vector; +}; + +#ifndef _VMA_MAP_FUNCTIONS template void VmaMap::insert(const PairType& pair) { @@ -5030,8 +4978,8 @@ void VmaMap::erase(iterator it) { VmaVectorRemove(m_Vector, it - m_Vector.begin()); } - -#endif // #if VMA_USE_STL_UNORDERED_MAP +#endif // _VMA_MAP_FUNCTIONS +#endif // _VMA_MAP #endif // #if 0 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6e77d2c..f899312 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,7 +47,6 @@ target_compile_definitions( VulkanMemoryAllocator PUBLIC - VMA_USE_STL_CONTAINERS=$ VMA_STATIC_VULKAN_FUNCTIONS=$ VMA_DYNAMIC_VULKAN_FUNCTIONS=$ VMA_DEBUG_ALWAYS_DEDICATED_MEMORY=$ diff --git a/src/VmaReplay/VmaUsage.h b/src/VmaReplay/VmaUsage.h index 36c9a1f..68d30c1 100644 --- a/src/VmaReplay/VmaUsage.h +++ b/src/VmaReplay/VmaUsage.h @@ -31,8 +31,6 @@ #endif // #if !defined(VK_USE_PLATFORM_WIN32_KHR) #include -//#define VMA_USE_STL_CONTAINERS 1 - //#define VMA_HEAVY_ASSERT(expr) assert(expr) //#define VMA_DEDICATED_ALLOCATION 0