Commit 6ba9754f by Geoff Lang Committed by Commit Bot

Refactor index range calculation in DrawCallParams.

BUG=864528 Change-Id: Iac418054ae56a2d9dd277d0474019997aeaa834b Reviewed-on: https://chromium-review.googlesource.com/1163633Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent a6d34af6
...@@ -162,8 +162,36 @@ Error DrawCallParams::ensureIndexRangeResolved(const Context *context) const ...@@ -162,8 +162,36 @@ Error DrawCallParams::ensureIndexRangeResolved(const Context *context) const
} }
const IndexRange &indexRange = mIndexRange.value(); const IndexRange &indexRange = mIndexRange.value();
mFirstVertex = mBaseVertex + static_cast<GLint>(indexRange.start);
mVertexCount = indexRange.vertexCount(); // The entire index range should be within the limits of a 32-bit uint because the largest GL
// index type is GL_UNSIGNED_INT.
ASSERT(indexRange.start <= std::numeric_limits<uint32_t>::max() &&
indexRange.end <= std::numeric_limits<uint32_t>::max());
// Given the assertion above and the type of mBaseVertex (GLint), adding them both as 64-bit
// ints is safe.
int64_t startVertexInt64 =
static_cast<int64_t>(mBaseVertex) + static_cast<int64_t>(indexRange.start);
// OpenGL ES 3.2 spec section 10.5: "Behavior of DrawElementsOneInstance is undefined if the
// vertex ID is negative for any element"
if (startVertexInt64 < 0)
{
return gl::InternalError() << "Negative index value.";
}
// OpenGL ES 3.2 spec section 10.5: "If the vertex ID is larger than the maximum value
// representable by type, it should behave as if the calculation were upconverted to 32-bit
// unsigned integers(with wrapping on overflow conditions)." ANGLE does not fully handle these
// rules, an overflow error is returned if the start vertex cannot be stored in a 32-bit signed
// integer.
if (startVertexInt64 > std::numeric_limits<GLint>::max())
{
return gl::InternalError() << "Negative value overflow.";
}
mFirstVertex = static_cast<GLint>(startVertexInt64);
mVertexCount = indexRange.vertexCount();
return NoError(); return NoError();
} }
......
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