Commit de8d4cb0 by Jamie Madill Committed by Commit Bot

Optimize BindingsBenchmark::drawBenchmark.

Fix contributed by matavenrath@nvidia.com. This fixes BindingsBenchmark::drawBenchmark to take only 3% instead of 15% of the time spent in BindingsBenchmark.Run/gl_100_objects_allocated_at_initialization. Bug: angleproject:2777 Change-Id: I5b5b6f167289b947767b40e7761d90cf06c49816 Reviewed-on: https://chromium-review.googlesource.com/1181868Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent d710fee3
......@@ -152,10 +152,23 @@ void BindingsBenchmark::drawBenchmark()
glGenBuffers(static_cast<GLsizei>(mBuffers.size()), mBuffers.data());
}
for (size_t bufferIdx = 0; bufferIdx < mBuffers.size(); bufferIdx++)
// Fetch a few variables from the underlying data structure to keep them in registers.
// Otherwise each loop iteration they'll be fetched again because the compiler cannot
// guarantee that those are unchanged when calling glBindBuffer.
unsigned int *buffers = mBuffers.data();
unsigned int *bindingPoints = mBindingPoints.data();
size_t bindingPointsSize = mBindingPoints.size();
size_t buffersSize = mBuffers.size();
size_t bindingIndex = it % bindingPointsSize;
for (size_t bufferIdx = 0; bufferIdx < buffersSize; bufferIdx++)
{
GLenum binding = mBindingPoints[(bufferIdx + it) % mBindingPoints.size()];
glBindBuffer(binding, mBuffers[bufferIdx]);
GLenum binding = bindingPoints[bindingIndex];
glBindBuffer(binding, buffers[bufferIdx]);
// Instead of doing a costly division to get an index in the range [0,bindingPointsSize)
// do a bounds-check and reset the index.
++bindingIndex;
bindingIndex = (bindingIndex >= bindingPointsSize) ? 0 : bindingIndex;
}
// Delete all the buffers
......
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