Fixes for some compiler warnings

Found by Visual Studio 2019
This commit is contained in:
Adam Sawicki 2023-02-24 14:04:59 +01:00
parent 5e921fcff1
commit 729b7c1408
2 changed files with 49 additions and 33 deletions

View File

@ -2860,6 +2860,21 @@ static void vma_aligned_free(void* VMA_NULLABLE ptr)
#define VMA_DEBUG_LOG(str) VMA_DEBUG_LOG_FORMAT("%s", (str)) #define VMA_DEBUG_LOG(str) VMA_DEBUG_LOG_FORMAT("%s", (str))
#endif #endif
#ifndef VMA_CLASS_NO_COPY
#define VMA_CLASS_NO_COPY(className) \
private: \
className(const className&) = delete; \
className& operator=(const className&) = delete;
#endif
#ifndef VMA_CLASS_NO_COPY_NO_MOVE
#define VMA_CLASS_NO_COPY_NO_MOVE(className) \
private: \
className(const className&) = delete; \
className(className&&) = delete; \
className& operator=(const className&) = delete; \
className& operator=(className&&) = delete;
#endif
// Define this macro to 1 to enable functions: vmaBuildStatsString, vmaFreeStatsString. // Define this macro to 1 to enable functions: vmaBuildStatsString, vmaFreeStatsString.
#if VMA_STATS_STRING_ENABLED #if VMA_STATS_STRING_ENABLED
static inline void VmaUint32ToStr(char* VMA_NOT_NULL outStr, size_t strLen, uint32_t num) static inline void VmaUint32ToStr(char* VMA_NOT_NULL outStr, size_t strLen, uint32_t num)
@ -2879,7 +2894,9 @@ static void vma_aligned_free(void* VMA_NULLABLE ptr)
#ifndef VMA_MUTEX #ifndef VMA_MUTEX
class VmaMutex class VmaMutex
{ {
VMA_CLASS_NO_COPY_NO_MOVE(VmaMutex)
public: public:
VmaMutex() { }
void Lock() { m_Mutex.lock(); } void Lock() { m_Mutex.lock(); }
void Unlock() { m_Mutex.unlock(); } void Unlock() { m_Mutex.unlock(); }
bool TryLock() { return m_Mutex.try_lock(); } bool TryLock() { return m_Mutex.try_lock(); }
@ -3045,13 +3062,6 @@ tools like RenderDoc.
#define VMA_MAPPING_HYSTERESIS_ENABLED 1 #define VMA_MAPPING_HYSTERESIS_ENABLED 1
#endif #endif
#ifndef VMA_CLASS_NO_COPY
#define VMA_CLASS_NO_COPY(className) \
private: \
className(const className&) = delete; \
className& operator=(const className&) = delete;
#endif
#define VMA_VALIDATE(cond) do { if(!(cond)) { \ #define VMA_VALIDATE(cond) do { if(!(cond)) { \
VMA_ASSERT(0 && "Validation failed: " #cond); \ VMA_ASSERT(0 && "Validation failed: " #cond); \
return false; \ return false; \
@ -3544,7 +3554,7 @@ new element with value (key) should be inserted.
template <typename CmpLess, typename IterT, typename KeyT> template <typename CmpLess, typename IterT, typename KeyT>
static IterT VmaBinaryFindFirstNotLess(IterT beg, IterT end, const KeyT& key, const CmpLess& cmp) static IterT VmaBinaryFindFirstNotLess(IterT beg, IterT end, const KeyT& key, const CmpLess& cmp)
{ {
size_t down = 0, up = (end - beg); size_t down = 0, up = size_t(end - beg);
while (down < up) while (down < up)
{ {
const size_t mid = down + (up - down) / 2; // Overflow-safe midpoint calculation const size_t mid = down + (up - down) / 2; // Overflow-safe midpoint calculation
@ -3951,7 +3961,7 @@ static void VmaAddDetailedStatistics(VmaDetailedStatistics& inoutStats, const Vm
// Helper RAII class to lock a mutex in constructor and unlock it in destructor (at the end of scope). // Helper RAII class to lock a mutex in constructor and unlock it in destructor (at the end of scope).
struct VmaMutexLock struct VmaMutexLock
{ {
VMA_CLASS_NO_COPY(VmaMutexLock) VMA_CLASS_NO_COPY_NO_MOVE(VmaMutexLock)
public: public:
VmaMutexLock(VMA_MUTEX& mutex, bool useMutex = true) : VmaMutexLock(VMA_MUTEX& mutex, bool useMutex = true) :
m_pMutex(useMutex ? &mutex : VMA_NULL) m_pMutex(useMutex ? &mutex : VMA_NULL)
@ -3967,7 +3977,7 @@ private:
// Helper RAII class to lock a RW mutex in constructor and unlock it in destructor (at the end of scope), for reading. // Helper RAII class to lock a RW mutex in constructor and unlock it in destructor (at the end of scope), for reading.
struct VmaMutexLockRead struct VmaMutexLockRead
{ {
VMA_CLASS_NO_COPY(VmaMutexLockRead) VMA_CLASS_NO_COPY_NO_MOVE(VmaMutexLockRead)
public: public:
VmaMutexLockRead(VMA_RW_MUTEX& mutex, bool useMutex) : VmaMutexLockRead(VMA_RW_MUTEX& mutex, bool useMutex) :
m_pMutex(useMutex ? &mutex : VMA_NULL) m_pMutex(useMutex ? &mutex : VMA_NULL)
@ -3983,7 +3993,7 @@ private:
// Helper RAII class to lock a RW mutex in constructor and unlock it in destructor (at the end of scope), for writing. // Helper RAII class to lock a RW mutex in constructor and unlock it in destructor (at the end of scope), for writing.
struct VmaMutexLockWrite struct VmaMutexLockWrite
{ {
VMA_CLASS_NO_COPY(VmaMutexLockWrite) VMA_CLASS_NO_COPY_NO_MOVE(VmaMutexLockWrite)
public: public:
VmaMutexLockWrite(VMA_RW_MUTEX& mutex, bool useMutex) VmaMutexLockWrite(VMA_RW_MUTEX& mutex, bool useMutex)
: m_pMutex(useMutex ? &mutex : VMA_NULL) : m_pMutex(useMutex ? &mutex : VMA_NULL)
@ -4438,7 +4448,7 @@ allocator can create multiple blocks.
template<typename T> template<typename T>
class VmaPoolAllocator class VmaPoolAllocator
{ {
VMA_CLASS_NO_COPY(VmaPoolAllocator) VMA_CLASS_NO_COPY_NO_MOVE(VmaPoolAllocator)
public: public:
VmaPoolAllocator(const VkAllocationCallbacks* pAllocationCallbacks, uint32_t firstBlockCapacity); VmaPoolAllocator(const VkAllocationCallbacks* pAllocationCallbacks, uint32_t firstBlockCapacity);
~VmaPoolAllocator(); ~VmaPoolAllocator();
@ -4571,7 +4581,7 @@ struct VmaListItem
template<typename T> template<typename T>
class VmaRawList class VmaRawList
{ {
VMA_CLASS_NO_COPY(VmaRawList) VMA_CLASS_NO_COPY_NO_MOVE(VmaRawList)
public: public:
typedef VmaListItem<T> ItemType; typedef VmaListItem<T> ItemType;
@ -4834,7 +4844,7 @@ VmaListItem<T>* VmaRawList<T>::InsertAfter(ItemType* pItem, const T& value)
template<typename T, typename AllocatorT> template<typename T, typename AllocatorT>
class VmaList class VmaList
{ {
VMA_CLASS_NO_COPY(VmaList) VMA_CLASS_NO_COPY_NO_MOVE(VmaList)
public: public:
class reverse_iterator; class reverse_iterator;
class const_iterator; class const_iterator;
@ -5426,7 +5436,7 @@ void VmaStringBuilder::AddNumber(uint32_t num)
char* p = &buf[10]; char* p = &buf[10];
do do
{ {
*--p = '0' + (num % 10); *--p = '0' + (char)(num % 10);
num /= 10; num /= 10;
} while (num); } while (num);
Add(p); Add(p);
@ -5439,7 +5449,7 @@ void VmaStringBuilder::AddNumber(uint64_t num)
char* p = &buf[20]; char* p = &buf[20];
do do
{ {
*--p = '0' + (num % 10); *--p = '0' + (char)(num % 10);
num /= 10; num /= 10;
} while (num); } while (num);
Add(p); Add(p);
@ -5461,7 +5471,7 @@ VmaStringBuilder passed to the constructor.
*/ */
class VmaJsonWriter class VmaJsonWriter
{ {
VMA_CLASS_NO_COPY(VmaJsonWriter) VMA_CLASS_NO_COPY_NO_MOVE(VmaJsonWriter)
public: public:
// sb - string builder to write the document to. Must remain alive for the whole lifetime of this object. // sb - string builder to write the document to. Must remain alive for the whole lifetime of this object.
VmaJsonWriter(const VkAllocationCallbacks* pAllocationCallbacks, VmaStringBuilder& sb); VmaJsonWriter(const VkAllocationCallbacks* pAllocationCallbacks, VmaStringBuilder& sb);
@ -5800,7 +5810,7 @@ static void VmaPrintDetailedStatistics(VmaJsonWriter& json, const VmaDetailedSta
class VmaMappingHysteresis class VmaMappingHysteresis
{ {
VMA_CLASS_NO_COPY(VmaMappingHysteresis) VMA_CLASS_NO_COPY_NO_MOVE(VmaMappingHysteresis)
public: public:
VmaMappingHysteresis() = default; VmaMappingHysteresis() = default;
@ -5907,7 +5917,7 @@ Thread-safety:
*/ */
class VmaDeviceMemoryBlock class VmaDeviceMemoryBlock
{ {
VMA_CLASS_NO_COPY(VmaDeviceMemoryBlock) VMA_CLASS_NO_COPY_NO_MOVE(VmaDeviceMemoryBlock)
public: public:
VmaBlockMetadata* m_pMetadata; VmaBlockMetadata* m_pMetadata;
@ -6130,6 +6140,7 @@ Thread-safe, synchronized internally.
*/ */
class VmaDedicatedAllocationList class VmaDedicatedAllocationList
{ {
VMA_CLASS_NO_COPY_NO_MOVE(VmaDedicatedAllocationList)
public: public:
VmaDedicatedAllocationList() {} VmaDedicatedAllocationList() {}
~VmaDedicatedAllocationList(); ~VmaDedicatedAllocationList();
@ -6315,6 +6326,7 @@ in a single VkDeviceMemory block.
*/ */
class VmaBlockMetadata class VmaBlockMetadata
{ {
VMA_CLASS_NO_COPY_NO_MOVE(VmaBlockMetadata)
public: public:
// pAllocationCallbacks, if not null, must be owned externally - alive and unchanged for the whole lifetime of this object. // pAllocationCallbacks, if not null, must be owned externally - alive and unchanged for the whole lifetime of this object.
VmaBlockMetadata(const VkAllocationCallbacks* pAllocationCallbacks, VmaBlockMetadata(const VkAllocationCallbacks* pAllocationCallbacks,
@ -6381,7 +6393,7 @@ public:
protected: protected:
const VkAllocationCallbacks* GetAllocationCallbacks() const { return m_pAllocationCallbacks; } const VkAllocationCallbacks* GetAllocationCallbacks() const { return m_pAllocationCallbacks; }
VkDeviceSize GetBufferImageGranularity() const { return m_BufferImageGranularity; } VkDeviceSize GetBufferImageGranularity() const { return m_BufferImageGranularity; }
VkDeviceSize GetDebugMargin() const { return IsVirtual() ? 0 : VMA_DEBUG_MARGIN; } VkDeviceSize GetDebugMargin() const { return VkDeviceSize(IsVirtual() ? 0 : VMA_DEBUG_MARGIN); }
void DebugLogAllocation(VkDeviceSize offset, VkDeviceSize size, void* userData) const; void DebugLogAllocation(VkDeviceSize offset, VkDeviceSize size, void* userData) const;
#if VMA_STATS_STRING_ENABLED #if VMA_STATS_STRING_ENABLED
@ -6755,7 +6767,7 @@ class VmaBlockMetadata_Generic : public VmaBlockMetadata
{ {
friend class VmaDefragmentationAlgorithm_Generic; friend class VmaDefragmentationAlgorithm_Generic;
friend class VmaDefragmentationAlgorithm_Fast; friend class VmaDefragmentationAlgorithm_Fast;
VMA_CLASS_NO_COPY(VmaBlockMetadata_Generic) VMA_CLASS_NO_COPY_NO_MOVE(VmaBlockMetadata_Generic)
public: public:
VmaBlockMetadata_Generic(const VkAllocationCallbacks* pAllocationCallbacks, VmaBlockMetadata_Generic(const VkAllocationCallbacks* pAllocationCallbacks,
VkDeviceSize bufferImageGranularity, bool isVirtual); VkDeviceSize bufferImageGranularity, bool isVirtual);
@ -7594,7 +7606,7 @@ GetSize() +-------+
*/ */
class VmaBlockMetadata_Linear : public VmaBlockMetadata class VmaBlockMetadata_Linear : public VmaBlockMetadata
{ {
VMA_CLASS_NO_COPY(VmaBlockMetadata_Linear) VMA_CLASS_NO_COPY_NO_MOVE(VmaBlockMetadata_Linear)
public: public:
VmaBlockMetadata_Linear(const VkAllocationCallbacks* pAllocationCallbacks, VmaBlockMetadata_Linear(const VkAllocationCallbacks* pAllocationCallbacks,
VkDeviceSize bufferImageGranularity, bool isVirtual); VkDeviceSize bufferImageGranularity, bool isVirtual);
@ -9213,7 +9225,7 @@ m_LevelCount is the maximum number of levels to use in the current object.
*/ */
class VmaBlockMetadata_Buddy : public VmaBlockMetadata class VmaBlockMetadata_Buddy : public VmaBlockMetadata
{ {
VMA_CLASS_NO_COPY(VmaBlockMetadata_Buddy) VMA_CLASS_NO_COPY_NO_MOVE(VmaBlockMetadata_Buddy)
public: public:
VmaBlockMetadata_Buddy(const VkAllocationCallbacks* pAllocationCallbacks, VmaBlockMetadata_Buddy(const VkAllocationCallbacks* pAllocationCallbacks,
VkDeviceSize bufferImageGranularity, bool isVirtual); VkDeviceSize bufferImageGranularity, bool isVirtual);
@ -9912,7 +9924,7 @@ void VmaBlockMetadata_Buddy::PrintDetailedMapNode(class VmaJsonWriter& json, con
// VMA_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT for fastest alloc time possible. // VMA_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT for fastest alloc time possible.
class VmaBlockMetadata_TLSF : public VmaBlockMetadata class VmaBlockMetadata_TLSF : public VmaBlockMetadata
{ {
VMA_CLASS_NO_COPY(VmaBlockMetadata_TLSF) VMA_CLASS_NO_COPY_NO_MOVE(VmaBlockMetadata_TLSF)
public: public:
VmaBlockMetadata_TLSF(const VkAllocationCallbacks* pAllocationCallbacks, VmaBlockMetadata_TLSF(const VkAllocationCallbacks* pAllocationCallbacks,
VkDeviceSize bufferImageGranularity, bool isVirtual); VkDeviceSize bufferImageGranularity, bool isVirtual);
@ -10074,7 +10086,7 @@ void VmaBlockMetadata_TLSF::Init(VkDeviceSize size)
else else
m_ListsCount += 4; m_ListsCount += 4;
m_MemoryClasses = memoryClass + 2; m_MemoryClasses = memoryClass + uint8_t(2);
memset(m_InnerIsFreeBitmap, 0, MAX_MEMORY_CLASSES * sizeof(uint32_t)); memset(m_InnerIsFreeBitmap, 0, MAX_MEMORY_CLASSES * sizeof(uint32_t));
m_FreeList = vma_new_array(GetAllocationCallbacks(), Block*, m_ListsCount); m_FreeList = vma_new_array(GetAllocationCallbacks(), Block*, m_ListsCount);
@ -10267,7 +10279,7 @@ bool VmaBlockMetadata_TLSF::CreateAllocationRequest(
// Round up to the next block // Round up to the next block
VkDeviceSize sizeForNextList = allocSize; VkDeviceSize sizeForNextList = allocSize;
VkDeviceSize smallSizeStep = SMALL_BUFFER_SIZE / (IsVirtual() ? 1 << SECOND_LEVEL_INDEX : 4); VkDeviceSize smallSizeStep = VkDeviceSize(SMALL_BUFFER_SIZE / (IsVirtual() ? 1 << SECOND_LEVEL_INDEX : 4));
if (allocSize > SMALL_BUFFER_SIZE) if (allocSize > SMALL_BUFFER_SIZE)
{ {
sizeForNextList += (1ULL << (VMA_BITSCAN_MSB(allocSize) - SECOND_LEVEL_INDEX)); sizeForNextList += (1ULL << (VMA_BITSCAN_MSB(allocSize) - SECOND_LEVEL_INDEX));
@ -10676,7 +10688,7 @@ void VmaBlockMetadata_TLSF::DebugLogAllAllocations() const
uint8_t VmaBlockMetadata_TLSF::SizeToMemoryClass(VkDeviceSize size) const uint8_t VmaBlockMetadata_TLSF::SizeToMemoryClass(VkDeviceSize size) const
{ {
if (size > SMALL_BUFFER_SIZE) if (size > SMALL_BUFFER_SIZE)
return VMA_BITSCAN_MSB(size) - MEMORY_CLASS_SHIFT; return uint8_t(VMA_BITSCAN_MSB(size) - MEMORY_CLASS_SHIFT);
return 0; return 0;
} }
@ -10851,7 +10863,7 @@ Synchronized internally with a mutex.
class VmaBlockVector class VmaBlockVector
{ {
friend struct VmaDefragmentationContext_T; friend struct VmaDefragmentationContext_T;
VMA_CLASS_NO_COPY(VmaBlockVector) VMA_CLASS_NO_COPY_NO_MOVE(VmaBlockVector)
public: public:
VmaBlockVector( VmaBlockVector(
VmaAllocator hAllocator, VmaAllocator hAllocator,
@ -10970,7 +10982,7 @@ private:
#ifndef _VMA_DEFRAGMENTATION_CONTEXT #ifndef _VMA_DEFRAGMENTATION_CONTEXT
struct VmaDefragmentationContext_T struct VmaDefragmentationContext_T
{ {
VMA_CLASS_NO_COPY(VmaDefragmentationContext_T) VMA_CLASS_NO_COPY_NO_MOVE(VmaDefragmentationContext_T)
public: public:
VmaDefragmentationContext_T( VmaDefragmentationContext_T(
VmaAllocator hAllocator, VmaAllocator hAllocator,
@ -11057,7 +11069,7 @@ private:
struct VmaPool_T struct VmaPool_T
{ {
friend struct VmaPoolListItemTraits; friend struct VmaPoolListItemTraits;
VMA_CLASS_NO_COPY(VmaPool_T) VMA_CLASS_NO_COPY_NO_MOVE(VmaPool_T)
public: public:
VmaBlockVector m_BlockVector; VmaBlockVector m_BlockVector;
VmaDedicatedAllocationList m_DedicatedAllocations; VmaDedicatedAllocationList m_DedicatedAllocations;
@ -11099,6 +11111,9 @@ struct VmaPoolListItemTraits
#ifndef _VMA_CURRENT_BUDGET_DATA #ifndef _VMA_CURRENT_BUDGET_DATA
struct VmaCurrentBudgetData struct VmaCurrentBudgetData
{ {
VMA_CLASS_NO_COPY_NO_MOVE(VmaCurrentBudgetData)
public:
VMA_ATOMIC_UINT32 m_BlockCount[VK_MAX_MEMORY_HEAPS]; VMA_ATOMIC_UINT32 m_BlockCount[VK_MAX_MEMORY_HEAPS];
VMA_ATOMIC_UINT32 m_AllocationCount[VK_MAX_MEMORY_HEAPS]; VMA_ATOMIC_UINT32 m_AllocationCount[VK_MAX_MEMORY_HEAPS];
VMA_ATOMIC_UINT64 m_BlockBytes[VK_MAX_MEMORY_HEAPS]; VMA_ATOMIC_UINT64 m_BlockBytes[VK_MAX_MEMORY_HEAPS];
@ -11167,7 +11182,7 @@ Thread-safe wrapper over VmaPoolAllocator free list, for allocation of VmaAlloca
*/ */
class VmaAllocationObjectAllocator class VmaAllocationObjectAllocator
{ {
VMA_CLASS_NO_COPY(VmaAllocationObjectAllocator) VMA_CLASS_NO_COPY_NO_MOVE(VmaAllocationObjectAllocator)
public: public:
VmaAllocationObjectAllocator(const VkAllocationCallbacks* pAllocationCallbacks) VmaAllocationObjectAllocator(const VkAllocationCallbacks* pAllocationCallbacks)
: m_Allocator(pAllocationCallbacks, 1024) {} : m_Allocator(pAllocationCallbacks, 1024) {}
@ -11197,7 +11212,7 @@ void VmaAllocationObjectAllocator::Free(VmaAllocation hAlloc)
#ifndef _VMA_VIRTUAL_BLOCK_T #ifndef _VMA_VIRTUAL_BLOCK_T
struct VmaVirtualBlock_T struct VmaVirtualBlock_T
{ {
VMA_CLASS_NO_COPY(VmaVirtualBlock_T) VMA_CLASS_NO_COPY_NO_MOVE(VmaVirtualBlock_T)
public: public:
const bool m_AllocationCallbacksSpecified; const bool m_AllocationCallbacksSpecified;
const VkAllocationCallbacks m_AllocationCallbacks; const VkAllocationCallbacks m_AllocationCallbacks;
@ -11337,7 +11352,7 @@ void VmaVirtualBlock_T::BuildStatsString(bool detailedMap, VmaStringBuilder& sb)
// Main allocator object. // Main allocator object.
struct VmaAllocator_T struct VmaAllocator_T
{ {
VMA_CLASS_NO_COPY(VmaAllocator_T) VMA_CLASS_NO_COPY_NO_MOVE(VmaAllocator_T)
public: public:
bool m_UseMutex; bool m_UseMutex;
uint32_t m_VulkanApiVersion; uint32_t m_VulkanApiVersion;

View File

@ -82,6 +82,7 @@ include all public interface declarations. Example:
#pragma warning(disable: 4100) // unreferenced formal parameter #pragma warning(disable: 4100) // unreferenced formal parameter
#pragma warning(disable: 4189) // local variable is initialized but not referenced #pragma warning(disable: 4189) // local variable is initialized but not referenced
#pragma warning(disable: 4324) // structure was padded due to alignment specifier #pragma warning(disable: 4324) // structure was padded due to alignment specifier
#pragma warning(disable: 4820) // 'X': 'N' bytes padding added after data member 'X'
#endif // #ifdef _MSVC_LANG #endif // #ifdef _MSVC_LANG