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/+/2377119
Reviewed-by: Courtney Goeltzenleuchter <courtneygo@google.com>
Reviewed-by: Cody Northrop <cnorthrop@google.com>
Commit-Queue: Tobin Ehlis <tobine@google.com>
This commit is contained in:
Tobin Ehlis 2020-08-26 11:27:13 -06:00 коммит произвёл Commit Bot
Родитель 7bb75ff628
Коммит d72765868d
7 изменённых файлов: 23 добавлений и 14 удалений

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

@ -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);
}

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

@ -205,7 +205,7 @@ IterableBitSet<N>::Iterator::Iterator(const std::bitset<N> &bitset)
}
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)
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.

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

@ -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);

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

@ -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<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
// 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)

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

@ -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<UINT>(sizeof(CopyShaderParams), 32u);
constantBufferDesc.ByteWidth = roundUpPow2<UINT>(sizeof(CopyShaderParams), 32u);
constantBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
constantBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
constantBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;

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

@ -739,7 +739,7 @@ class SecondaryCommandBuffer final : angle::NonCopyable
else
{
// 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);
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<size_t>(stringSize, 4);
const size_t alignedStringSize = roundUpPow2<size_t>(stringSize, 4);
DebugUtilsLabelParams *paramStruct =
initCommand<DebugUtilsLabelParams>(cmd, alignedStringSize, &writePtr);
paramStruct->color[0] = label.color[0];