From 5ab8c1752ab9720b7a38a3bc72ebcf17ef3ce6f1 Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Wed, 27 Apr 2022 16:58:56 +0200 Subject: [PATCH] Fix assert when VMA_DEBUG_INITIALIZE_ALLOCATIONS is used with new memory usage flags Only mappable allocations are filled with bit pattern. See #260 --- docs/html/debugging_memory_usage.html | 4 ++-- include/vk_mem_alloc.h | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/html/debugging_memory_usage.html b/docs/html/debugging_memory_usage.html index 57672ef..72a2204 100644 --- a/docs/html/debugging_memory_usage.html +++ b/docs/html/debugging_memory_usage.html @@ -76,9 +76,9 @@ Memory initialization
#define VMA_DEBUG_INITIALIZE_ALLOCATIONS 1
#include "vk_mem_alloc.h"
-

It makes memory of all new allocations initialized to bit pattern 0xDCDCDCDC. Before an allocation is destroyed, its memory is filled with bit pattern 0xEFEFEFEF. Memory is automatically mapped and unmapped if necessary.

+

It makes memory of new allocations initialized to bit pattern 0xDCDCDCDC. Before an allocation is destroyed, its memory is filled with bit pattern 0xEFEFEFEF. Memory is automatically mapped and unmapped if necessary.

If you find these values while debugging your program, good chances are that you incorrectly read Vulkan memory that is allocated but not initialized, or already freed, respectively.

-

Memory initialization works only with memory types that are HOST_VISIBLE. It works also with dedicated allocations.

+

Memory initialization works only with memory types that are HOST_VISIBLE and with allocations that can be mapped. It works also with dedicated allocations.

Margins

By default, allocations are laid out in memory blocks next to each other if possible (considering required alignment, bufferImageGranularity, and nonCoherentAtomSize).

diff --git a/include/vk_mem_alloc.h b/include/vk_mem_alloc.h index 90410b5..5fbc4a9 100644 --- a/include/vk_mem_alloc.h +++ b/include/vk_mem_alloc.h @@ -15906,6 +15906,7 @@ void VmaAllocator_T::UpdateVulkanBudget() void VmaAllocator_T::FillAllocation(const 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) { void* pData = VMA_NULL; @@ -18823,14 +18824,14 @@ To do it, define macro `VMA_DEBUG_INITIALIZE_ALLOCATIONS` to 1. #include "vk_mem_alloc.h" \endcode -It makes memory of all new allocations initialized to bit pattern `0xDCDCDCDC`. +It makes memory of new allocations initialized to bit pattern `0xDCDCDCDC`. Before an allocation is destroyed, its memory is filled with bit pattern `0xEFEFEFEF`. Memory is automatically mapped and unmapped if necessary. If you find these values while debugging your program, good chances are that you incorrectly read Vulkan memory that is allocated but not initialized, or already freed, respectively. -Memory initialization works only with memory types that are `HOST_VISIBLE`. +Memory initialization works only with memory types that are `HOST_VISIBLE` and with allocations that can be mapped. It works also with dedicated allocations. \section debugging_memory_usage_margins Margins