DirectXHelper updated with IsPowerOf2

This commit is contained in:
Chuck Walbourn 2020-05-13 20:59:09 -07:00
Родитель 11938f59ed
Коммит 0f006913c5
1 изменённых файлов: 8 добавлений и 4 удалений

Просмотреть файл

@ -219,26 +219,30 @@ namespace DirectX
std::vector<D3D12_RESOURCE_BARRIER> mBarriers;
};
// Helper to check for power-of-2
template<typename T>
constexpr bool IsPowerOf2(T x) noexcept { return ((x != 0) && !(x & (x - 1))); }
// Helpers for aligning values by a power of 2
template<typename T>
inline T AlignDown(T size, size_t alignment) noexcept
constexpr inline T AlignDown(T size, size_t alignment) noexcept
{
if (alignment > 0)
{
assert(((alignment - 1) & alignment) == 0);
T mask = static_cast<T>(alignment - 1);
auto mask = static_cast<T>(alignment - 1);
return size & ~mask;
}
return size;
}
template<typename T>
inline T AlignUp(T size, size_t alignment) noexcept
constexpr inline T AlignUp(T size, size_t alignment) noexcept
{
if (alignment > 0)
{
assert(((alignment - 1) & alignment) == 0);
T mask = static_cast<T>(alignment - 1);
auto mask = static_cast<T>(alignment - 1);
return (size + mask) & ~mask;
}
return size;