Commit aff8084b by Jamie Madill

Fix VertexBuffer11::getSpaceRequired for instanced attribs.

The computation could copy more data than needed. Although benign it could cause performance degredation compared to the D3D9 back end. Change-Id: I3cf1dc79085c33d44040fd55153e63a4e5e63cb1 Reviewed-on: https://chromium-review.googlesource.com/210640Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarNicolas Capens <capn@chromium.org>
parent 5d601382
...@@ -518,6 +518,12 @@ T roundUp(const T value, const T alignment) ...@@ -518,6 +518,12 @@ T roundUp(const T value, const T alignment)
return value + alignment - 1 - (value - 1) % alignment; return value + alignment - 1 - (value - 1) % alignment;
} }
inline unsigned int UnsignedCeilDivide(unsigned int value, unsigned int divisor)
{
unsigned int divided = value / divisor;
return (divided + ((value % divisor == 0) ? 0 : 1));
}
template <class T> template <class T>
inline bool IsUnsignedAdditionSafe(T lhs, T rhs) inline bool IsUnsignedAdditionSafe(T lhs, T rhs)
{ {
......
...@@ -136,15 +136,8 @@ bool VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei ...@@ -136,15 +136,8 @@ bool VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei
} }
else else
{ {
if (static_cast<unsigned int>(instances) < std::numeric_limits<unsigned int>::max() - (attrib.divisor - 1)) // Round up to divisor, if possible
{ elementCount = rx::UnsignedCeilDivide(static_cast<unsigned int>(instances), attrib.divisor);
// Round up
elementCount = rx::roundUp(static_cast<unsigned int>(instances), attrib.divisor);
}
else
{
elementCount = instances / attrib.divisor;
}
} }
gl::VertexFormat vertexFormat(attrib); gl::VertexFormat vertexFormat(attrib);
......
...@@ -214,15 +214,8 @@ bool VertexBuffer9::spaceRequired(const gl::VertexAttribute &attrib, std::size_t ...@@ -214,15 +214,8 @@ bool VertexBuffer9::spaceRequired(const gl::VertexAttribute &attrib, std::size_t
} }
else else
{ {
if (static_cast<unsigned int>(instances) < std::numeric_limits<unsigned int>::max() - (attrib.divisor - 1)) // Round up to divisor, if possible
{ elementCount = rx::UnsignedCeilDivide(static_cast<unsigned int>(instances), attrib.divisor);
// Round up
elementCount = (static_cast<unsigned int>(instances) + (attrib.divisor - 1)) / attrib.divisor;
}
else
{
elementCount = static_cast<unsigned int>(instances) / attrib.divisor;
}
} }
if (elementSize <= std::numeric_limits<unsigned int>::max() / elementCount) if (elementSize <= std::numeric_limits<unsigned int>::max() / elementCount)
......
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