Skip to content

Fix some MSVC warnings #500

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

Closed
Closed
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
56 changes: 44 additions & 12 deletions include/vk_mem_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -3818,6 +3818,8 @@ static void VmaWriteMagicValue(void* pData, VkDeviceSize offset)
}
#else
// no-op
(void)pData;
(void)offset;
#endif
}

Expand All @@ -3833,6 +3835,9 @@ static bool VmaValidateMagicValue(const void* pData, VkDeviceSize offset)
return false;
}
}
#else
(void)pData;
(void)offset;
#endif
return true;
}
Expand Down Expand Up @@ -4600,7 +4605,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 @@ -6429,7 +6435,7 @@ struct VmaAllocation_T
bool IsPersistentMap() const { return (m_Flags & FLAG_PERSISTENT_MAP) != 0; }
bool IsMappingAllowed() const { return (m_Flags & FLAG_MAPPING_ALLOWED) != 0; }

void SetUserData(VmaAllocator hAllocator, void* pUserData) { m_pUserData = pUserData; }
void SetUserData(VmaAllocator hAllocator, void* pUserData) { (void)hAllocator; m_pUserData = pUserData; }
void SetName(VmaAllocator hAllocator, const char* pName);
void FreeName(VmaAllocator hAllocator);
uint8_t SwapBlockAllocation(VmaAllocator hAllocator, VmaAllocation allocation);
Expand Down Expand Up @@ -6827,6 +6833,10 @@ VmaBlockMetadata::VmaBlockMetadata(const VkAllocationCallbacks* pAllocationCallb

void VmaBlockMetadata::DebugLogAllocation(VkDeviceSize offset, VkDeviceSize size, void* userData) const
{
// Variables will be unreferenced and generate compiler warnings if `VMA_LEAK_LOG_FORMAT` is not defined
(void)offset;
(void)size;

if (IsVirtual())
{
VMA_LEAK_LOG_FORMAT("UNFREED VIRTUAL ALLOCATION; Offset: %" PRIu64 "; Size: %" PRIu64 "; UserData: %p", offset, size, userData);
Expand All @@ -6838,6 +6848,7 @@ void VmaBlockMetadata::DebugLogAllocation(VkDeviceSize offset, VkDeviceSize size

userData = allocation->GetUserData();
const char* name = allocation->GetName();
(void)name;

#if VMA_STATS_STRING_ENABLED
VMA_LEAK_LOG_FORMAT("UNFREED ALLOCATION; Offset: %" PRIu64 "; Size: %" PRIu64 "; UserData: %p; Name: %s; Type: %s; Usage: %" PRIu64,
Expand Down Expand Up @@ -8363,13 +8374,15 @@ VmaAllocHandle VmaBlockMetadata_Linear::GetNextAllocation(VmaAllocHandle prevAll
{
// Function only used for defragmentation, which is disabled for this algorithm
VMA_ASSERT(0);
(void)prevAlloc;
return VK_NULL_HANDLE;
}

VkDeviceSize VmaBlockMetadata_Linear::GetNextFreeRegionSize(VmaAllocHandle alloc) const
{
// Function only used for defragmentation, which is disabled for this algorithm
VMA_ASSERT(0);
(void)alloc;
return 0;
}

Expand Down Expand Up @@ -8561,6 +8574,8 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_LowerAddress(
uint32_t strategy,
VmaAllocationRequest* pAllocationRequest)
{
(void)strategy;

const VkDeviceSize blockSize = GetSize();
const VkDeviceSize debugMargin = GetDebugMargin();
const VkDeviceSize bufferImageGranularity = GetBufferImageGranularity();
Expand Down Expand Up @@ -8739,6 +8754,8 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_UpperAddress(
uint32_t strategy,
VmaAllocationRequest* pAllocationRequest)
{
(void)strategy;

const VkDeviceSize blockSize = GetSize();
const VkDeviceSize bufferImageGranularity = GetBufferImageGranularity();
SuballocationVectorType& suballocations1st = AccessSuballocations1st();
Expand Down Expand Up @@ -9370,6 +9387,8 @@ void VmaBlockMetadata_TLSF::Alloc(
VmaSuballocationType type,
void* userData)
{
(void)type;

VMA_ASSERT(request.type == VmaAllocationRequestType::TLSF);

// Get block and pop it from the free list
Expand Down Expand Up @@ -10661,7 +10680,7 @@ VmaDeviceMemoryBlock::VmaDeviceMemoryBlock(VmaAllocator hAllocator)
m_Id(0),
m_hMemory(VK_NULL_HANDLE),
m_MapCount(0),
m_pMappedData(VMA_NULL){}
m_pMappedData(VMA_NULL){ (void)hAllocator; }

VmaDeviceMemoryBlock::~VmaDeviceMemoryBlock()
{
Expand Down Expand Up @@ -11348,11 +11367,13 @@ bool VmaBlockVector::IsEmpty()

bool VmaBlockVector::IsCorruptionDetectionEnabled() const
{
#if (VMA_DEBUG_DETECT_CORRUPTION == 0) || (VMA_DEBUG_MARGIN <= 0)
return false;
#else
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) &&
(m_hAllocator->m_MemProps.memoryTypes[m_MemoryTypeIndex].propertyFlags & requiredMemFlags) == requiredMemFlags;
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 @@ -13164,6 +13185,8 @@ VmaAllocator_T::VmaAllocator_T(const VmaAllocatorCreateInfo* pCreateInfo) :

VkResult VmaAllocator_T::Init(const VmaAllocatorCreateInfo* pCreateInfo)
{
(void)pCreateInfo;

VkResult res = VK_SUCCESS;

#if VMA_MEMORY_BUDGET
Expand Down Expand Up @@ -14027,11 +14050,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 @@ -14997,9 +15021,9 @@ void VmaAllocator_T::UpdateVulkanBudget()

void VmaAllocator_T::FillAllocation(VmaAllocation hAllocation, uint8_t pattern)
{
if(VMA_DEBUG_INITIALIZE_ALLOCATIONS &&
hAllocation->IsMappingAllowed() &&
(m_MemProps.memoryTypes[hAllocation->GetMemoryTypeIndex()].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0)
#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;
VkResult res = Map(hAllocation, &pData);
Expand All @@ -15014,6 +15038,10 @@ 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.");
}
}
#else
(void)hAllocation;
(void)pattern;
#endif
}

uint32_t VmaAllocator_T::GetGpuDefragmentationMemoryTypeBits()
Expand Down Expand Up @@ -16172,6 +16200,8 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaBeginDefragmentationPass(
VmaDefragmentationContext VMA_NOT_NULL context,
VmaDefragmentationPassMoveInfo* VMA_NOT_NULL pPassInfo)
{
(void)allocator;

VMA_ASSERT(context && pPassInfo);

VMA_DEBUG_LOG("vmaBeginDefragmentationPass");
Expand All @@ -16186,6 +16216,8 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaEndDefragmentationPass(
VmaDefragmentationContext VMA_NOT_NULL context,
VmaDefragmentationPassMoveInfo* VMA_NOT_NULL pPassInfo)
{
(void)allocator;

VMA_ASSERT(context && pPassInfo);

VMA_DEBUG_LOG("vmaEndDefragmentationPass");
Expand Down