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; + } }; }