Move index range calculations into VertexArray.
This is in preparation for removing the entire DrawCallParams struct.
This struct was big enough to cause a performance hit on draw call perf
tests just by virtue of initializing the fields. Also dereferencing the
struct members is slower than reading function parameters since it adds
an indirection.
Also includes some error refactoring to enable moving code to a shared
location.
In total this patch series reduces overhead by up to 5%.
Bug: angleproject:2933
Change-Id: Ib663f2538c14ac30d4c31fd10d6350be469626e2
Reviewed-on: https://chromium-review.googlesource.com/c/1298380
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/VertexArray.cpp b/src/libANGLE/VertexArray.cpp
index a9a8be8..46aa557 100644
--- a/src/libANGLE/VertexArray.cpp
+++ b/src/libANGLE/VertexArray.cpp
@@ -7,6 +7,8 @@
//
#include "libANGLE/VertexArray.h"
+
+#include "common/utilities.h"
#include "libANGLE/Buffer.h"
#include "libANGLE/Context.h"
#include "libANGLE/renderer/BufferImpl.h"
@@ -395,6 +397,7 @@
{
if (IsElementArrayBufferSubjectIndex(index))
{
+ mIndexRangeCache.invalidate();
return contentsChanged ? DIRTY_BIT_ELEMENT_ARRAY_BUFFER_DATA
: DIRTY_BIT_ELEMENT_ARRAY_BUFFER;
}
@@ -526,4 +529,42 @@
mState.mCachedEnabledMappedArrayBuffers =
mState.mCachedMappedArrayBuffers & mState.mEnabledAttributesMask;
}
+
+angle::Result VertexArray::getIndexRangeImpl(const Context *context,
+ GLenum type,
+ GLsizei indexCount,
+ const void *indices,
+ IndexRange *indexRangeOut) const
+{
+ Buffer *elementArrayBuffer = mState.mElementArrayBuffer.get();
+ if (!elementArrayBuffer)
+ {
+ *indexRangeOut = ComputeIndexRange(type, indices, indexCount,
+ context->getGLState().isPrimitiveRestartEnabled());
+ return angle::Result::Continue();
+ }
+
+ size_t offset = reinterpret_cast<uintptr_t>(indices);
+ ANGLE_TRY(elementArrayBuffer->getIndexRange(context, type, offset, indexCount,
+ context->getGLState().isPrimitiveRestartEnabled(),
+ indexRangeOut));
+
+ mIndexRangeCache.put(type, indexCount, offset, *indexRangeOut);
+ return angle::Result::Continue();
+}
+
+VertexArray::IndexRangeCache::IndexRangeCache() = default;
+
+void VertexArray::IndexRangeCache::put(GLenum type,
+ GLsizei indexCount,
+ size_t offset,
+ const IndexRange &indexRange)
+{
+ ASSERT(type != GL_NONE);
+
+ mTypeKey = type;
+ mIndexCountKey = indexCount;
+ mOffsetKey = offset;
+ mPayload = indexRange;
+}
} // namespace gl