Merge branch 'feature-virtual-allocator'
diff --git a/src/D3D12MemAlloc.cpp b/src/D3D12MemAlloc.cpp
index d0d9c83..808efcc 100644
--- a/src/D3D12MemAlloc.cpp
+++ b/src/D3D12MemAlloc.cpp
@@ -243,19 +243,32 @@
     #define D3D12MA_ATOMIC_UINT64 std::atomic<UINT64>

 #endif

 

+/*

+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 IsPow2(T x)

+{

+    return (x & (x-1)) == 0;

+}

+

 // Aligns given value up to nearest multiply of align value. For example: AlignUp(11, 8) = 16.

 // Use types like UINT, uint64_t as T.

 template <typename T>

-static inline T AlignUp(T val, T align)

+static inline T AlignUp(T val, T alignment)

 {

-	return (val + align - 1) / align * align;

+    D3D12MA_HEAVY_ASSERT(IsPow2(alignment));

+	return (val + alignment - 1) & ~(alignment - 1);

 }

 // Aligns given value down to nearest multiply of align value. For example: AlignUp(11, 8) = 8.

 // Use types like UINT, uint64_t as T.

 template <typename T>

-static inline T AlignDown(T val, T align)

+static inline T AlignDown(T val, T alignment)

 {

-    return val / align * align;

+    D3D12MA_HEAVY_ASSERT(IsPow2(alignment));

+    return val & ~(alignment - 1);

 }

 

 // Division with mathematical rounding to nearest number.

@@ -270,17 +283,6 @@
     return (x + y - 1) / 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 IsPow2(T x)

-{

-    return (x & (x-1)) == 0;

-}

-

 // Returns smallest power of 2 greater or equal to v.

 static inline UINT NextPow2(UINT v)

 {