Added internal function VmaIsPow2 and asserts checking if various alignment parameters are power of 2.
diff --git a/src/Tests.cpp b/src/Tests.cpp
index 21b82f2..bc2b964 100644
--- a/src/Tests.cpp
+++ b/src/Tests.cpp
@@ -4149,7 +4149,7 @@
{
wprintf(L"TESTING:\n");
- if(true)
+ if(false)
{
// # Temporarily insert custom tests here
// ########################################
@@ -4176,6 +4176,8 @@
ManuallyTestLinearAllocator();
TestLinearAllocatorMultiBlock();
+ BasicTestBuddyAllocator();
+
{
FILE* file;
fopen_s(&file, "LinearAllocator.csv", "w");
diff --git a/src/VmaReplay/VmaUsage.h b/src/VmaReplay/VmaUsage.h
index cf93a33..182132b 100644
--- a/src/VmaReplay/VmaUsage.h
+++ b/src/VmaReplay/VmaUsage.h
@@ -9,7 +9,7 @@
//#define VMA_USE_STL_CONTAINERS 1
-#define VMA_HEAVY_ASSERT(expr) assert(expr)
+//#define VMA_HEAVY_ASSERT(expr) assert(expr)
//#define VMA_DEDICATED_ALLOCATION 0
diff --git a/src/vk_mem_alloc.h b/src/vk_mem_alloc.h
index 9d21090..956e58d 100644
--- a/src/vk_mem_alloc.h
+++ b/src/vk_mem_alloc.h
@@ -2961,6 +2961,17 @@
return (x + (y / (T)2)) / y;
}
+/*
+Returns true if given number is a power of two.
+T must be unsigned integer number or signed integer but always nonnegative.
+For 0 returns true.
+*/
+template <typename T>
+inline bool VmaIsPow2(T x)
+{
+ return (x & (x-1)) == 0;
+}
+
// Returns smallest power of 2 greater or equal to v.
static inline uint32_t VmaNextPow2(uint32_t v)
{
@@ -11749,6 +11760,11 @@
(*m_VulkanFunctions.vkGetPhysicalDeviceProperties)(m_PhysicalDevice, &m_PhysicalDeviceProperties);
(*m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties)(m_PhysicalDevice, &m_MemProps);
+ VMA_ASSERT(VmaIsPow2(VMA_DEBUG_ALIGNMENT));
+ VMA_ASSERT(VmaIsPow2(VMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY));
+ VMA_ASSERT(VmaIsPow2(m_PhysicalDeviceProperties.limits.bufferImageGranularity));
+ VMA_ASSERT(VmaIsPow2(m_PhysicalDeviceProperties.limits.nonCoherentAtomSize));
+
m_PreferredLargeHeapBlockSize = (pCreateInfo->preferredLargeHeapBlockSize != 0) ?
pCreateInfo->preferredLargeHeapBlockSize : static_cast<VkDeviceSize>(VMA_DEFAULT_LARGE_HEAP_BLOCK_SIZE);
@@ -12196,6 +12212,8 @@
VmaSuballocationType suballocType,
VmaAllocation* pAllocation)
{
+ VMA_ASSERT(VmaIsPow2(vkMemReq.alignment));
+
if((createInfo.flags & VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT) != 0 &&
(createInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) != 0)
{