diff --git a/src/common/FastVector.h b/src/common/FastVector.h index be684cfdd..ff7f161f2 100644 --- a/src/common/FastVector.h +++ b/src/common/FastVector.h @@ -580,7 +580,7 @@ class FastIntegerSet final ANGLE_INLINE void reserve(size_t newSize) { - size_t alignedSize = rx::roundUp(newSize, kWindowSize); + size_t alignedSize = rx::roundUpPow2(newSize, kWindowSize); size_t count = alignedSize >> kShiftForDivision; mKeyData.resize(count, KeyBitSet::Zero()); @@ -656,7 +656,7 @@ class FastIntegerMap final ANGLE_INLINE void reserve(size_t newSize) { - size_t alignedSize = rx::roundUp(newSize, FastIntegerSet::kWindowSize); + size_t alignedSize = rx::roundUpPow2(newSize, FastIntegerSet::kWindowSize); mValueData.resize(alignedSize); } diff --git a/src/common/bitset_utils.h b/src/common/bitset_utils.h index c0bc4b197..dbc7e0d38 100644 --- a/src/common/bitset_utils.h +++ b/src/common/bitset_utils.h @@ -205,7 +205,7 @@ IterableBitSet::Iterator::Iterator(const std::bitset &bitset) } else { - mOffset = static_cast(rx::roundUp(N, BitsPerWord)); + mOffset = static_cast(rx::roundUpPow2(N, BitsPerWord)); } } diff --git a/src/common/mathutil_unittest.cpp b/src/common/mathutil_unittest.cpp index 60df6d0a5..20d0bab83 100644 --- a/src/common/mathutil_unittest.cpp +++ b/src/common/mathutil_unittest.cpp @@ -211,12 +211,21 @@ TEST(MathUtilTest, CountLeadingZeros) EXPECT_EQ(32u, CountLeadingZeros(0)); } -// Some basic tests. Tests that rounding up zero produces zero. +// Some basic tests. Pow2 roundUp test and test that rounding up zero produces zero. +TEST(MathUtilTest, Pow2RoundUp) +{ + EXPECT_EQ(0u, rx::roundUpPow2(0u, 4u)); + EXPECT_EQ(4u, rx::roundUpPow2(1u, 4u)); + EXPECT_EQ(4u, rx::roundUpPow2(4u, 4u)); +} + +// Non-pow2 test. TEST(MathUtilTest, BasicRoundUp) { - EXPECT_EQ(0u, rx::roundUp(0u, 4u)); - EXPECT_EQ(4u, rx::roundUp(1u, 4u)); - EXPECT_EQ(4u, rx::roundUp(4u, 4u)); + EXPECT_EQ(0u, rx::roundUp(0u, 5u)); + EXPECT_EQ(5u, rx::roundUp(1u, 5u)); + EXPECT_EQ(5u, rx::roundUp(4u, 5u)); + EXPECT_EQ(5u, rx::roundUp(5u, 5u)); } // Test that rounding up zero produces zero for checked ints. diff --git a/src/libANGLE/FrameCapture.cpp b/src/libANGLE/FrameCapture.cpp index 62bef1e0b..4af91e244 100644 --- a/src/libANGLE/FrameCapture.cpp +++ b/src/libANGLE/FrameCapture.cpp @@ -475,7 +475,7 @@ void WriteBinaryParamReplay(DataTracker *dataTracker, { // Store in binary file if data are not of type string or enum // Round up to 16-byte boundary for cross ABI safety - size_t offset = rx::roundUp(binaryData->size(), kBinaryAlignment); + size_t offset = rx::roundUpPow2(binaryData->size(), kBinaryAlignment); binaryData->resize(offset + data.size()); memcpy(binaryData->data() + offset, data.data(), data.size()); out << "reinterpret_cast<" << ParamTypeToString(overrideType) << ">(&gBinaryData[" << offset @@ -1015,7 +1015,7 @@ void WriteCppReplay(bool compression, Result::Continue) { size_t serializedContextLength = serializedContextData.length(); - size_t serializedContextOffset = rx::roundUp(binaryData->size(), kBinaryAlignment); + size_t serializedContextOffset = rx::roundUpPow2(binaryData->size(), kBinaryAlignment); binaryData->resize(serializedContextOffset + serializedContextLength); memcpy(binaryData->data() + serializedContextOffset, serializedContextData.data(), serializedContextLength); diff --git a/src/libANGLE/renderer/d3d/d3d11/Buffer11.cpp b/src/libANGLE/renderer/d3d/d3d11/Buffer11.cpp index fe1d4028d..1e8f82bda 100644 --- a/src/libANGLE/renderer/d3d/d3d11/Buffer11.cpp +++ b/src/libANGLE/renderer/d3d/d3d11/Buffer11.cpp @@ -54,7 +54,7 @@ void CalculateConstantBufferParams(GLintptr offset, // The GL size is not required to be aligned to a 256 bytes boundary. // Round the size up to a 256 bytes boundary then express the results in constants of 16-bytes. - *outNumConstants = static_cast(rx::roundUp(size, static_cast(256)) / 16); + *outNumConstants = static_cast(rx::roundUpPow2(size, static_cast(256)) / 16); // Since the size is rounded up, firstConstant + numConstants may be bigger than the actual size // of the buffer. This behaviour is explictly allowed according to the documentation on @@ -1326,7 +1326,7 @@ void Buffer11::NativeStorage::FillBufferDesc(D3D11_BUFFER_DESC *bufferDesc, // Constant buffers must be of a limited size, and aligned to 16 byte boundaries // For our purposes we ignore any buffer data past the maximum constant buffer size - bufferDesc->ByteWidth = roundUp(bufferDesc->ByteWidth, 16u); + bufferDesc->ByteWidth = roundUpPow2(bufferDesc->ByteWidth, 16u); // Note: it seems that D3D11 allows larger buffers on some platforms, but not all. // (Windows 10 seems to allow larger constant buffers, but not Windows 7) diff --git a/src/libANGLE/renderer/d3d/d3d11/PixelTransfer11.cpp b/src/libANGLE/renderer/d3d/d3d11/PixelTransfer11.cpp index eb4d5ea37..dd71e13b5 100644 --- a/src/libANGLE/renderer/d3d/d3d11/PixelTransfer11.cpp +++ b/src/libANGLE/renderer/d3d/d3d11/PixelTransfer11.cpp @@ -89,7 +89,7 @@ angle::Result PixelTransfer11::loadResources(const gl::Context *context) ANGLE_TRY(mRenderer->allocateResource(context11, depthStencilDesc, &mCopyDepthStencilState)); D3D11_BUFFER_DESC constantBufferDesc = {}; - constantBufferDesc.ByteWidth = roundUp(sizeof(CopyShaderParams), 32u); + constantBufferDesc.ByteWidth = roundUpPow2(sizeof(CopyShaderParams), 32u); constantBufferDesc.Usage = D3D11_USAGE_DYNAMIC; constantBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; constantBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; diff --git a/src/libANGLE/renderer/vulkan/SecondaryCommandBuffer.h b/src/libANGLE/renderer/vulkan/SecondaryCommandBuffer.h index fcbde9544..198b127be 100644 --- a/src/libANGLE/renderer/vulkan/SecondaryCommandBuffer.h +++ b/src/libANGLE/renderer/vulkan/SecondaryCommandBuffer.h @@ -739,7 +739,7 @@ class SecondaryCommandBuffer final : angle::NonCopyable else { // Make sure allocation is 4-byte aligned - const size_t alignedSize = roundUp(requiredSize, 4); + const size_t alignedSize = roundUpPow2(requiredSize, 4); ASSERT((alignedSize % 4) == 0); allocateNewBlock(alignedSize); } @@ -804,7 +804,7 @@ ANGLE_INLINE void SecondaryCommandBuffer::commonDebugUtilsLabel(CommandID cmd, { uint8_t *writePtr; const size_t stringSize = strlen(label.pLabelName) + 1; - const size_t alignedStringSize = roundUp(stringSize, 4); + const size_t alignedStringSize = roundUpPow2(stringSize, 4); DebugUtilsLabelParams *paramStruct = initCommand(cmd, alignedStringSize, &writePtr); paramStruct->color[0] = label.color[0];