Skip to content

Fixed for some compiler warnings #501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions include/vk_mem_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -4600,7 +4600,8 @@ void VmaVector<T, AllocatorT>::resize(size_t newCount)

if (newCapacity != m_Capacity)
{
T* const newArray = newCapacity ? VmaAllocateArray<T>(m_Allocator.m_pCallbacks, newCapacity) : VMA_NULL;
VMA_HEAVY_ASSERT(newCapacity > 0);
T* const newArray = VmaAllocateArray<T>(m_Allocator.m_pCallbacks, newCapacity);
const size_t elementsToCopy = VMA_MIN(m_Count, newCount);
if (elementsToCopy != 0)
{
Expand Down Expand Up @@ -11348,11 +11349,13 @@ bool VmaBlockVector::IsEmpty()

bool VmaBlockVector::IsCorruptionDetectionEnabled() const
{
const uint32_t requiredMemFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
return (VMA_DEBUG_DETECT_CORRUPTION != 0) &&
(VMA_DEBUG_MARGIN > 0) &&
(m_Algorithm == 0 || m_Algorithm == VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT) &&
#if (VMA_DEBUG_DETECT_CORRUPTION == 0) || (VMA_DEBUG_MARGIN == 0)
return false;
#else
constexpr uint32_t requiredMemFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
return (m_Algorithm == 0 || m_Algorithm == VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT) &&
(m_hAllocator->m_MemProps.memoryTypes[m_MemoryTypeIndex].propertyFlags & requiredMemFlags) == requiredMemFlags;
#endif
}

VkResult VmaBlockVector::Allocate(
Expand Down Expand Up @@ -11802,10 +11805,11 @@ VkResult VmaBlockVector::CommitAllocationRequest(
else
(*pAllocation)->SetUserData(m_hAllocator, pUserData);
m_hAllocator->m_Budget.AddAllocation(m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex), allocRequest.size);
if (VMA_DEBUG_INITIALIZE_ALLOCATIONS)
{
m_hAllocator->FillAllocation(*pAllocation, VMA_ALLOCATION_FILL_PATTERN_CREATED);
}

#if VMA_DEBUG_INITIALIZE_ALLOCATIONS
m_hAllocator->FillAllocation(*pAllocation, VMA_ALLOCATION_FILL_PATTERN_CREATED);
#endif

if (IsCorruptionDetectionEnabled())
{
VkResult res = pBlock->WriteMagicValueAfterAllocation(m_hAllocator, (*pAllocation)->GetOffset(), allocRequest.size);
Expand Down Expand Up @@ -13825,10 +13829,10 @@ VkResult VmaAllocator_T::AllocateDedicatedMemoryPage(
else
(*pAllocation)->SetUserData(this, pUserData);
m_Budget.AddAllocation(MemoryTypeIndexToHeapIndex(memTypeIndex), size);
if(VMA_DEBUG_INITIALIZE_ALLOCATIONS)
{
FillAllocation(*pAllocation, VMA_ALLOCATION_FILL_PATTERN_CREATED);
}

#if VMA_DEBUG_INITIALIZE_ALLOCATIONS
FillAllocation(*pAllocation, VMA_ALLOCATION_FILL_PATTERN_CREATED);
#endif

return VK_SUCCESS;
}
Expand Down Expand Up @@ -14027,11 +14031,12 @@ VkResult VmaAllocator_T::CalcAllocationParams(
return VK_ERROR_FEATURE_NOT_PRESENT;
}

if(VMA_DEBUG_ALWAYS_DEDICATED_MEMORY &&
(inoutCreateInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) != 0)
#if VMA_DEBUG_ALWAYS_DEDICATED_MEMORY
if((inoutCreateInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) != 0)
{
inoutCreateInfo.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
}
#endif

// Non-auto USAGE values imply HOST_ACCESS flags.
// And so does VMA_MEMORY_USAGE_UNKNOWN because it is used with custom pools.
Expand Down Expand Up @@ -14150,10 +14155,9 @@ void VmaAllocator_T::FreeMemory(

if(allocation != VK_NULL_HANDLE)
{
if(VMA_DEBUG_INITIALIZE_ALLOCATIONS)
{
FillAllocation(allocation, VMA_ALLOCATION_FILL_PATTERN_DESTROYED);
}
#if VMA_DEBUG_INITIALIZE_ALLOCATIONS
FillAllocation(allocation, VMA_ALLOCATION_FILL_PATTERN_DESTROYED);
#endif

switch(allocation->GetType())
{
Expand Down Expand Up @@ -14997,8 +15001,8 @@ void VmaAllocator_T::UpdateVulkanBudget()

void VmaAllocator_T::FillAllocation(VmaAllocation hAllocation, uint8_t pattern)
{
if(VMA_DEBUG_INITIALIZE_ALLOCATIONS &&
hAllocation->IsMappingAllowed() &&
#if VMA_DEBUG_INITIALIZE_ALLOCATIONS
if(hAllocation->IsMappingAllowed() &&
(m_MemProps.memoryTypes[hAllocation->GetMemoryTypeIndex()].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0)
{
void* pData = VMA_NULL;
Expand All @@ -15014,6 +15018,7 @@ void VmaAllocator_T::FillAllocation(VmaAllocation hAllocation, uint8_t pattern)
VMA_ASSERT(0 && "VMA_DEBUG_INITIALIZE_ALLOCATIONS is enabled, but couldn't map memory to fill allocation.");
}
}
#endif // #if VMA_DEBUG_INITIALIZE_ALLOCATIONS
}

uint32_t VmaAllocator_T::GetGpuDefragmentationMemoryTypeBits()
Expand Down