From 98b781527ffee193e128067b220686fc013d8e8b Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Fri, 14 Jul 2017 10:58:50 -0400 Subject: [PATCH] Add kTextureRowPitchAlignment and Align helper --- src/common/Constants.h | 1 + src/common/Math.cpp | 6 ++++++ src/common/Math.h | 1 + 3 files changed, 8 insertions(+) diff --git a/src/common/Constants.h b/src/common/Constants.h index 1d8f295ab8..ecd6231aa5 100644 --- a/src/common/Constants.h +++ b/src/common/Constants.h @@ -24,5 +24,6 @@ static constexpr uint32_t kMaxVertexAttributes = 16u; static constexpr uint32_t kMaxVertexInputs = 16u; static constexpr uint32_t kNumStages = 3; static constexpr uint32_t kMaxColorAttachments = 4u; +static constexpr uint32_t kTextureRowPitchAlignment = 256u; #endif // COMMON_CONSTANTS_H_ diff --git a/src/common/Math.cpp b/src/common/Math.cpp index ce4d41a190..da5455e57c 100644 --- a/src/common/Math.cpp +++ b/src/common/Math.cpp @@ -60,3 +60,9 @@ void* AlignVoidPtr(void* ptr, size_t alignment) { ASSERT(alignment != 0); return reinterpret_cast((reinterpret_cast(ptr) + (alignment - 1)) & ~(alignment - 1)); } + +uint32_t Align(uint32_t value, size_t alignment) { + ASSERT(IsPowerOfTwo(alignment)); + ASSERT(alignment != 0); + return (value + (alignment - 1)) & ~(alignment - 1); +} diff --git a/src/common/Math.h b/src/common/Math.h index e380dca5c9..486b8a4261 100644 --- a/src/common/Math.h +++ b/src/common/Math.h @@ -25,6 +25,7 @@ bool IsPowerOfTwo(size_t n); bool IsAligned(const void* ptr, size_t alignment); void* AlignVoidPtr(void* ptr, size_t alignment); +uint32_t Align(uint32_t value, size_t alignment); template T* AlignPtr(T* ptr, size_t alignment) {