Code improvements based on static analysis

See #488
This commit is contained in:
Adam Sawicki 2025-05-09 12:55:22 +02:00
parent 089e0eb4c4
commit fbd9e6eae6

View file

@ -3982,7 +3982,7 @@ VmaBufferImageUsage::VmaBufferImageUsage(const VkBufferCreateInfo &createInfo,
// of the VK_KHR_maintenance5 extension. // of the VK_KHR_maintenance5 extension.
const VkBufferUsageFlags2CreateInfoKHR* const usageFlags2 = const VkBufferUsageFlags2CreateInfoKHR* const usageFlags2 =
VmaPnextChainFind<VkBufferUsageFlags2CreateInfoKHR>(&createInfo, VK_STRUCTURE_TYPE_BUFFER_USAGE_FLAGS_2_CREATE_INFO_KHR); VmaPnextChainFind<VkBufferUsageFlags2CreateInfoKHR>(&createInfo, VK_STRUCTURE_TYPE_BUFFER_USAGE_FLAGS_2_CREATE_INFO_KHR);
if(usageFlags2 != 0) if(usageFlags2 != VMA_NULL)
{ {
this->Value = usageFlags2->usage; this->Value = usageFlags2->usage;
return; return;
@ -10153,7 +10153,6 @@ public:
explicit VmaVirtualBlock_T(const VmaVirtualBlockCreateInfo& createInfo); explicit VmaVirtualBlock_T(const VmaVirtualBlockCreateInfo& createInfo);
~VmaVirtualBlock_T(); ~VmaVirtualBlock_T();
VkResult Init() { return VK_SUCCESS; }
bool IsEmpty() const { return m_Metadata->IsEmpty(); } bool IsEmpty() const { return m_Metadata->IsEmpty(); }
void Free(VmaVirtualAllocation allocation) { m_Metadata->Free((VmaAllocHandle)allocation); } void Free(VmaVirtualAllocation allocation) { m_Metadata->Free((VmaAllocHandle)allocation); }
void SetAllocationUserData(VmaVirtualAllocation allocation, void* userData) { m_Metadata->SetAllocationUserData((VmaAllocHandle)allocation, userData); } void SetAllocationUserData(VmaVirtualAllocation allocation, void* userData) { m_Metadata->SetAllocationUserData((VmaAllocHandle)allocation, userData); }
@ -11412,7 +11411,7 @@ VkResult VmaBlockVector::AllocatePage(
{ {
const bool isUpperAddress = (createInfo.flags & VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT) != 0; const bool isUpperAddress = (createInfo.flags & VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT) != 0;
VkDeviceSize freeMemory; VkDeviceSize freeMemory = 0;
{ {
const uint32_t heapIndex = m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex); const uint32_t heapIndex = m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex);
VmaBudget heapBudget = {}; VmaBudget heapBudget = {};
@ -11993,6 +11992,8 @@ VmaDefragmentationContext_T::VmaDefragmentationContext_T(
m_AlgorithmState = vma_new_array(hAllocator, StateExtensive, m_BlockVectorCount); m_AlgorithmState = vma_new_array(hAllocator, StateExtensive, m_BlockVectorCount);
} }
break; break;
default:
; // Do nothing.
} }
} }
@ -12089,11 +12090,10 @@ VkResult VmaDefragmentationContext_T::DefragmentPassEnd(VmaDefragmentationPassMo
size_t currentCount = 0; size_t currentCount = 0;
VkDeviceSize freedBlockSize = 0; VkDeviceSize freedBlockSize = 0;
uint32_t vectorIndex; uint32_t vectorIndex = 0;
VmaBlockVector* vector; VmaBlockVector* vector = VMA_NULL;
if (m_PoolBlockVector != VMA_NULL) if (m_PoolBlockVector != VMA_NULL)
{ {
vectorIndex = 0;
vector = m_PoolBlockVector; vector = m_PoolBlockVector;
} }
else else
@ -12178,7 +12178,7 @@ VkResult VmaDefragmentationContext_T::DefragmentPassEnd(VmaDefragmentationPassMo
} }
freedBlockSize *= prevCount - currentCount; freedBlockSize *= prevCount - currentCount;
VkDeviceSize dstBlockSize; VkDeviceSize dstBlockSize = SIZE_MAX;
{ {
VmaMutexLockRead lock(vector->GetMutex(), vector->GetAllocator()->m_UseMutex); VmaMutexLockRead lock(vector->GetMutex(), vector->GetAllocator()->m_UseMutex);
dstBlockSize = move.dstTmpAllocation->GetBlock()->m_pMetadata->GetSize(); dstBlockSize = move.dstTmpAllocation->GetBlock()->m_pMetadata->GetSize();
@ -12354,8 +12354,7 @@ VmaDefragmentationContext_T::CounterStatus VmaDefragmentationContext_T::CheckCou
{ {
if (++m_IgnoredAllocs < MAX_ALLOCS_TO_IGNORE) if (++m_IgnoredAllocs < MAX_ALLOCS_TO_IGNORE)
return CounterStatus::Ignore; return CounterStatus::Ignore;
else return CounterStatus::End;
return CounterStatus::End;
} }
m_IgnoredAllocs = 0; m_IgnoredAllocs = 0;
@ -14574,11 +14573,9 @@ VkResult VmaAllocator_T::BindVulkanBuffer(
bindBufferMemoryInfo.memoryOffset = memoryOffset; bindBufferMemoryInfo.memoryOffset = memoryOffset;
return (*m_VulkanFunctions.vkBindBufferMemory2KHR)(m_hDevice, 1, &bindBufferMemoryInfo); return (*m_VulkanFunctions.vkBindBufferMemory2KHR)(m_hDevice, 1, &bindBufferMemoryInfo);
} }
else
#endif // #if VMA_VULKAN_VERSION >= 1001000 || VMA_BIND_MEMORY2 #endif // #if VMA_VULKAN_VERSION >= 1001000 || VMA_BIND_MEMORY2
{
return VK_ERROR_EXTENSION_NOT_PRESENT; return VK_ERROR_EXTENSION_NOT_PRESENT;
}
} }
else else
{ {
@ -15543,7 +15540,7 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndexForBufferInfo(
const VkDevice hDev = allocator->m_hDevice; const VkDevice hDev = allocator->m_hDevice;
const VmaVulkanFunctions* funcs = &allocator->GetVulkanFunctions(); const VmaVulkanFunctions* funcs = &allocator->GetVulkanFunctions();
VkResult res; VkResult res = VK_SUCCESS;
#if VMA_KHR_MAINTENANCE4 || VMA_VULKAN_VERSION >= 1003000 #if VMA_KHR_MAINTENANCE4 || VMA_VULKAN_VERSION >= 1003000
if(funcs->vkGetDeviceBufferMemoryRequirements) if(funcs->vkGetDeviceBufferMemoryRequirements)
@ -15595,7 +15592,7 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndexForImageInfo(
const VkDevice hDev = allocator->m_hDevice; const VkDevice hDev = allocator->m_hDevice;
const VmaVulkanFunctions* funcs = &allocator->GetVulkanFunctions(); const VmaVulkanFunctions* funcs = &allocator->GetVulkanFunctions();
VkResult res; VkResult res = VK_SUCCESS;
#if VMA_KHR_MAINTENANCE4 || VMA_VULKAN_VERSION >= 1003000 #if VMA_KHR_MAINTENANCE4 || VMA_VULKAN_VERSION >= 1003000
if(funcs->vkGetDeviceImageMemoryRequirements) if(funcs->vkGetDeviceImageMemoryRequirements)
@ -16712,6 +16709,11 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateVirtualBlock(
VMA_DEBUG_LOG("vmaCreateVirtualBlock"); VMA_DEBUG_LOG("vmaCreateVirtualBlock");
VMA_DEBUG_GLOBAL_MUTEX_LOCK; VMA_DEBUG_GLOBAL_MUTEX_LOCK;
*pVirtualBlock = vma_new(pCreateInfo->pAllocationCallbacks, VmaVirtualBlock_T)(*pCreateInfo); *pVirtualBlock = vma_new(pCreateInfo->pAllocationCallbacks, VmaVirtualBlock_T)(*pCreateInfo);
return VK_SUCCESS;
/*
Code for the future if we ever need a separate Init() method that could fail:
VkResult res = (*pVirtualBlock)->Init(); VkResult res = (*pVirtualBlock)->Init();
if(res < 0) if(res < 0)
{ {
@ -16719,6 +16721,7 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateVirtualBlock(
*pVirtualBlock = VK_NULL_HANDLE; *pVirtualBlock = VK_NULL_HANDLE;
} }
return res; return res;
*/
} }
VMA_CALL_PRE void VMA_CALL_POST vmaDestroyVirtualBlock(VmaVirtualBlock VMA_NULLABLE virtualBlock) VMA_CALL_PRE void VMA_CALL_POST vmaDestroyVirtualBlock(VmaVirtualBlock VMA_NULLABLE virtualBlock)