Commit d7276586 by Tobin Ehlis Committed by Commit Bot

Vulkan:Use roundUpPow2 where possible

Utility function roundUpPow2 is more optimal than roundUp so use it. Bug: b/166462979 Change-Id: I616fa9f487b818137b1b496d93e292c3bd1f428c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2377119Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com> Commit-Queue: Tobin Ehlis <tobine@google.com>
parent 7bb75ff6
...@@ -580,7 +580,7 @@ class FastIntegerSet final ...@@ -580,7 +580,7 @@ class FastIntegerSet final
ANGLE_INLINE void reserve(size_t newSize) 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; size_t count = alignedSize >> kShiftForDivision;
mKeyData.resize(count, KeyBitSet::Zero()); mKeyData.resize(count, KeyBitSet::Zero());
...@@ -656,7 +656,7 @@ class FastIntegerMap final ...@@ -656,7 +656,7 @@ class FastIntegerMap final
ANGLE_INLINE void reserve(size_t newSize) 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); mValueData.resize(alignedSize);
} }
......
...@@ -205,7 +205,7 @@ IterableBitSet<N>::Iterator::Iterator(const std::bitset<N> &bitset) ...@@ -205,7 +205,7 @@ IterableBitSet<N>::Iterator::Iterator(const std::bitset<N> &bitset)
} }
else else
{ {
mOffset = static_cast<unsigned long>(rx::roundUp(N, BitsPerWord)); mOffset = static_cast<unsigned long>(rx::roundUpPow2(N, BitsPerWord));
} }
} }
......
...@@ -211,12 +211,21 @@ TEST(MathUtilTest, CountLeadingZeros) ...@@ -211,12 +211,21 @@ TEST(MathUtilTest, CountLeadingZeros)
EXPECT_EQ(32u, CountLeadingZeros(0)); 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) TEST(MathUtilTest, BasicRoundUp)
{ {
EXPECT_EQ(0u, rx::roundUp(0u, 4u)); EXPECT_EQ(0u, rx::roundUp(0u, 5u));
EXPECT_EQ(4u, rx::roundUp(1u, 4u)); EXPECT_EQ(5u, rx::roundUp(1u, 5u));
EXPECT_EQ(4u, rx::roundUp(4u, 4u)); EXPECT_EQ(5u, rx::roundUp(4u, 5u));
EXPECT_EQ(5u, rx::roundUp(5u, 5u));
} }
// Test that rounding up zero produces zero for checked ints. // Test that rounding up zero produces zero for checked ints.
......
...@@ -475,7 +475,7 @@ void WriteBinaryParamReplay(DataTracker *dataTracker, ...@@ -475,7 +475,7 @@ void WriteBinaryParamReplay(DataTracker *dataTracker,
{ {
// Store in binary file if data are not of type string or enum // Store in binary file if data are not of type string or enum
// Round up to 16-byte boundary for cross ABI safety // 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()); binaryData->resize(offset + data.size());
memcpy(binaryData->data() + offset, data.data(), data.size()); memcpy(binaryData->data() + offset, data.data(), data.size());
out << "reinterpret_cast<" << ParamTypeToString(overrideType) << ">(&gBinaryData[" << offset out << "reinterpret_cast<" << ParamTypeToString(overrideType) << ">(&gBinaryData[" << offset
...@@ -1015,7 +1015,7 @@ void WriteCppReplay(bool compression, ...@@ -1015,7 +1015,7 @@ void WriteCppReplay(bool compression,
Result::Continue) Result::Continue)
{ {
size_t serializedContextLength = serializedContextData.length(); 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); binaryData->resize(serializedContextOffset + serializedContextLength);
memcpy(binaryData->data() + serializedContextOffset, serializedContextData.data(), memcpy(binaryData->data() + serializedContextOffset, serializedContextData.data(),
serializedContextLength); serializedContextLength);
......
...@@ -54,7 +54,7 @@ void CalculateConstantBufferParams(GLintptr offset, ...@@ -54,7 +54,7 @@ void CalculateConstantBufferParams(GLintptr offset,
// The GL size is not required to be aligned to a 256 bytes boundary. // 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. // Round the size up to a 256 bytes boundary then express the results in constants of 16-bytes.
*outNumConstants = static_cast<UINT>(rx::roundUp(size, static_cast<GLsizeiptr>(256)) / 16); *outNumConstants = static_cast<UINT>(rx::roundUpPow2(size, static_cast<GLsizeiptr>(256)) / 16);
// Since the size is rounded up, firstConstant + numConstants may be bigger than the actual size // 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 // 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, ...@@ -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 // 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 // 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. // 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) // (Windows 10 seems to allow larger constant buffers, but not Windows 7)
......
...@@ -89,7 +89,7 @@ angle::Result PixelTransfer11::loadResources(const gl::Context *context) ...@@ -89,7 +89,7 @@ angle::Result PixelTransfer11::loadResources(const gl::Context *context)
ANGLE_TRY(mRenderer->allocateResource(context11, depthStencilDesc, &mCopyDepthStencilState)); ANGLE_TRY(mRenderer->allocateResource(context11, depthStencilDesc, &mCopyDepthStencilState));
D3D11_BUFFER_DESC constantBufferDesc = {}; D3D11_BUFFER_DESC constantBufferDesc = {};
constantBufferDesc.ByteWidth = roundUp<UINT>(sizeof(CopyShaderParams), 32u); constantBufferDesc.ByteWidth = roundUpPow2<UINT>(sizeof(CopyShaderParams), 32u);
constantBufferDesc.Usage = D3D11_USAGE_DYNAMIC; constantBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
constantBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; constantBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
constantBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; constantBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
......
...@@ -739,7 +739,7 @@ class SecondaryCommandBuffer final : angle::NonCopyable ...@@ -739,7 +739,7 @@ class SecondaryCommandBuffer final : angle::NonCopyable
else else
{ {
// Make sure allocation is 4-byte aligned // Make sure allocation is 4-byte aligned
const size_t alignedSize = roundUp<size_t>(requiredSize, 4); const size_t alignedSize = roundUpPow2<size_t>(requiredSize, 4);
ASSERT((alignedSize % 4) == 0); ASSERT((alignedSize % 4) == 0);
allocateNewBlock(alignedSize); allocateNewBlock(alignedSize);
} }
...@@ -804,7 +804,7 @@ ANGLE_INLINE void SecondaryCommandBuffer::commonDebugUtilsLabel(CommandID cmd, ...@@ -804,7 +804,7 @@ ANGLE_INLINE void SecondaryCommandBuffer::commonDebugUtilsLabel(CommandID cmd,
{ {
uint8_t *writePtr; uint8_t *writePtr;
const size_t stringSize = strlen(label.pLabelName) + 1; const size_t stringSize = strlen(label.pLabelName) + 1;
const size_t alignedStringSize = roundUp<size_t>(stringSize, 4); const size_t alignedStringSize = roundUpPow2<size_t>(stringSize, 4);
DebugUtilsLabelParams *paramStruct = DebugUtilsLabelParams *paramStruct =
initCommand<DebugUtilsLabelParams>(cmd, alignedStringSize, &writePtr); initCommand<DebugUtilsLabelParams>(cmd, alignedStringSize, &writePtr);
paramStruct->color[0] = label.color[0]; paramStruct->color[0] = label.color[0];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment