From b76cbeb32f6b9045e7b9185b71e7e48e2bd93e4d Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Wed, 25 Nov 2020 21:21:21 +0100 Subject: [PATCH] Add utils --- openVulkanoCpp/Base/Utils.hpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/openVulkanoCpp/Base/Utils.hpp b/openVulkanoCpp/Base/Utils.hpp index 15ce087..3f71a3e 100644 --- a/openVulkanoCpp/Base/Utils.hpp +++ b/openVulkanoCpp/Base/Utils.hpp @@ -61,5 +61,35 @@ namespace openVulkanoCpp { return (size + alignment - 1) & ~(alignment - 1); } + + static inline constexpr size_t AlignPage(size_t size) + { + return Align(size, 4096); //TODO detect system page size instead of relying on hardcoded value + } + + template>> + static inline constexpr bool IsPow2(T i) + { + return ((i - 1) & i) == 0; + } + + template>> + static inline constexpr T Log2OfPow2(T n) + { + assert(n != 0); + assert(IsPow2(n)); + + T log = 0; + while(true) + { + n >>= 1; + if (n == 0) + { + break; + } + log++; + } + return log; + } }; }