Defined VMA_FALLTHROUGH to fix more compiler warnings

See #321
This commit is contained in:
Adam Sawicki 2023-02-24 14:15:41 +01:00
parent 729b7c1408
commit 4c58c1fefe

View File

@ -2651,8 +2651,7 @@ VmaAllocatorCreateInfo::pVulkanFunctions. Other members can be null.
#endif #endif
#ifndef VMA_USE_STL_SHARED_MUTEX #ifndef VMA_USE_STL_SHARED_MUTEX
// Compiler conforms to C++17. #if __cplusplus >= 201703L || _MSVC_LANG >= 201703L // C++17
#if __cplusplus >= 201703L
#define VMA_USE_STL_SHARED_MUTEX 1 #define VMA_USE_STL_SHARED_MUTEX 1
// Visual studio defines __cplusplus properly only when passed additional parameter: /Zc:__cplusplus // Visual studio defines __cplusplus properly only when passed additional parameter: /Zc:__cplusplus
// Otherwise it is always 199711L, despite shared_mutex works since Visual Studio 2015 Update 2. // Otherwise it is always 199711L, despite shared_mutex works since Visual Studio 2015 Update 2.
@ -2697,6 +2696,14 @@ remove them if not needed.
#define VMA_NULL nullptr #define VMA_NULL nullptr
#endif #endif
#ifndef VMA_FALLTHROUGH
#if __cplusplus >= 201703L || _MSVC_LANG >= 201703L // C++17
#define VMA_FALLTHROUGH [[fallthrough]]
#else
#define VMA_FALLTHROUGH
#endif
#endif
// Normal assert to check for programmer's errors, especially in Debug configuration. // Normal assert to check for programmer's errors, especially in Debug configuration.
#ifndef VMA_ASSERT #ifndef VMA_ASSERT
#ifdef NDEBUG #ifdef NDEBUG
@ -2773,7 +2780,7 @@ static void* vma_aligned_alloc(size_t alignment, size_t size)
{ {
return _aligned_malloc(size, alignment); return _aligned_malloc(size, alignment);
} }
#elif __cplusplus >= 201703L // Compiler conforms to C++17. #elif __cplusplus >= 201703L || _MSVC_LANG >= 201703L // C++17
static void* vma_aligned_alloc(size_t alignment, size_t size) static void* vma_aligned_alloc(size_t alignment, size_t size)
{ {
return aligned_alloc(alignment, size); return aligned_alloc(alignment, size);
@ -5663,7 +5670,6 @@ void VmaJsonWriter::ContinueString(const char* pStr)
break; break;
default: default:
VMA_ASSERT(0 && "Character not currently supported."); VMA_ASSERT(0 && "Character not currently supported.");
break;
} }
} }
} }
@ -13216,29 +13222,24 @@ VkResult VmaDefragmentationContext_T::DefragmentPassEnd(VmaDefragmentationPassMo
m_PassStats.bytesFreed += freedBlockSize; m_PassStats.bytesFreed += freedBlockSize;
} }
switch (m_Algorithm) if(m_Algorithm == VMA_DEFRAGMENTATION_FLAG_ALGORITHM_EXTENSIVE_BIT &&
m_AlgorithmState != VMA_NULL)
{ {
case VMA_DEFRAGMENTATION_FLAG_ALGORITHM_EXTENSIVE_BIT: // Avoid unnecessary tries to allocate when new free block is available
{ StateExtensive& state = reinterpret_cast<StateExtensive*>(m_AlgorithmState)[vectorIndex];
if (m_AlgorithmState != VMA_NULL) if (state.firstFreeBlock != SIZE_MAX)
{ {
// Avoid unnecessary tries to allocate when new free block is available const size_t diff = prevCount - currentCount;
StateExtensive& state = reinterpret_cast<StateExtensive*>(m_AlgorithmState)[vectorIndex]; if (state.firstFreeBlock >= diff)
if (state.firstFreeBlock != SIZE_MAX)
{ {
const size_t diff = prevCount - currentCount; state.firstFreeBlock -= diff;
if (state.firstFreeBlock >= diff) if (state.firstFreeBlock != 0)
{ state.firstFreeBlock -= vector->GetBlock(state.firstFreeBlock - 1)->m_pMetadata->IsEmpty();
state.firstFreeBlock -= diff;
if (state.firstFreeBlock != 0)
state.firstFreeBlock -= vector->GetBlock(state.firstFreeBlock - 1)->m_pMetadata->IsEmpty();
}
else
state.firstFreeBlock = 0;
} }
else
state.firstFreeBlock = 0;
} }
} }
}
} }
moveInfo.moveCount = 0; moveInfo.moveCount = 0;
moveInfo.pMoves = VMA_NULL; moveInfo.pMoves = VMA_NULL;
@ -13796,6 +13797,8 @@ bool VmaDefragmentationContext_T::ComputeDefragmentation_Extensive(VmaBlockVecto
vectorState.operation = StateExtensive::Operation::MoveBuffers; vectorState.operation = StateExtensive::Operation::MoveBuffers;
bufferPresent = false; bufferPresent = false;
otherPresent = false; otherPresent = false;
VMA_FALLTHROUGH; // Fallthrough
} }
else else
break; break;
@ -13820,6 +13823,8 @@ bool VmaDefragmentationContext_T::ComputeDefragmentation_Extensive(VmaBlockVecto
// No more buffers to move, check all others // No more buffers to move, check all others
vectorState.operation = StateExtensive::Operation::MoveAll; vectorState.operation = StateExtensive::Operation::MoveAll;
otherPresent = false; otherPresent = false;
VMA_FALLTHROUGH; // Fallthrough
} }
else else
break; break;
@ -15570,6 +15575,7 @@ VkResult VmaAllocator_T::Map(VmaAllocation hAllocation, void** ppData)
} }
return res; return res;
} }
VMA_FALLTHROUGH; // Fallthrough
case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED: case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
return hAllocation->DedicatedAllocMap(this, ppData); return hAllocation->DedicatedAllocMap(this, ppData);
default: default: