Commit 8957b6c0 by Jamie Madill Committed by Commit Bot

Add perf test for ushort DrawElements.

The code path in the D3D11 back-end is sigificantly different for unsigned short indices vs unsigned int. Because of the workaround we have for the primitive restart index in D3D11, ushort rendering can be slower. BUG=angleproject:2229 Change-Id: I303dcc55b0314ec45508044995ba47b250cbb87d Reviewed-on: https://chromium-review.googlesource.com/767149Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 0a05df48
...@@ -833,6 +833,22 @@ const char *GetGenericErrorMessage(GLenum error) ...@@ -833,6 +833,22 @@ const char *GetGenericErrorMessage(GLenum error)
} }
} }
unsigned int ElementTypeSize(GLenum elementType)
{
switch (elementType)
{
case GL_UNSIGNED_BYTE:
return sizeof(GLubyte);
case GL_UNSIGNED_SHORT:
return sizeof(GLushort);
case GL_UNSIGNED_INT:
return sizeof(GLuint);
default:
UNREACHABLE();
return 0;
}
}
} // namespace gl } // namespace gl
namespace egl namespace egl
......
...@@ -128,6 +128,8 @@ const UniformTypeInfo &GetUniformTypeInfo(GLenum uniformType); ...@@ -128,6 +128,8 @@ const UniformTypeInfo &GetUniformTypeInfo(GLenum uniformType);
const char *GetGenericErrorMessage(GLenum error); const char *GetGenericErrorMessage(GLenum error);
unsigned int ElementTypeSize(GLenum elementType);
} // namespace gl } // namespace gl
namespace egl namespace egl
......
...@@ -241,22 +241,7 @@ gl::Error IndexDataManager::prepareIndexData(const gl::Context *context, ...@@ -241,22 +241,7 @@ gl::Error IndexDataManager::prepareIndexData(const gl::Context *context,
unsigned int offset = static_cast<unsigned int>(reinterpret_cast<uintptr_t>(indices)); unsigned int offset = static_cast<unsigned int>(reinterpret_cast<uintptr_t>(indices));
ASSERT(srcTypeInfo.bytes * static_cast<unsigned int>(count) + offset <= buffer->getSize()); ASSERT(srcTypeInfo.bytes * static_cast<unsigned int>(count) + offset <= buffer->getSize());
bool offsetAligned; bool offsetAligned = (offset % gl::ElementTypeSize(srcType) == 0);
switch (srcType)
{
case GL_UNSIGNED_BYTE:
offsetAligned = (offset % sizeof(GLubyte) == 0);
break;
case GL_UNSIGNED_SHORT:
offsetAligned = (offset % sizeof(GLushort) == 0);
break;
case GL_UNSIGNED_INT:
offsetAligned = (offset % sizeof(GLuint) == 0);
break;
default:
UNREACHABLE();
offsetAligned = false;
}
// Case 2a: the buffer can be used directly // Case 2a: the buffer can be used directly
if (offsetAligned && buffer->supportsDirectBinding() && dstType == srcType) if (offsetAligned && buffer->supportsDirectBinding() && dstType == srcType)
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "ANGLEPerfTest.h" #include "ANGLEPerfTest.h"
#include "DrawCallPerfParams.h" #include "DrawCallPerfParams.h"
#include "common/utilities.h"
#include "test_utils/draw_call_perf_utils.h" #include "test_utils/draw_call_perf_utils.h"
namespace namespace
...@@ -46,6 +47,11 @@ struct DrawElementsPerfParams final : public DrawCallPerfParams ...@@ -46,6 +47,11 @@ struct DrawElementsPerfParams final : public DrawCallPerfParams
strstr << "_index_buffer_changed"; strstr << "_index_buffer_changed";
} }
if (type == GL_UNSIGNED_SHORT)
{
strstr << "_ushort";
}
return strstr.str(); return strstr.str();
} }
...@@ -75,8 +81,10 @@ class DrawElementsPerfBenchmark : public ANGLERenderTest, ...@@ -75,8 +81,10 @@ class DrawElementsPerfBenchmark : public ANGLERenderTest,
GLuint mIndexBuffer = 0; GLuint mIndexBuffer = 0;
GLuint mFBO = 0; GLuint mFBO = 0;
GLuint mTexture = 0; GLuint mTexture = 0;
GLsizei mBufferSize = 0;
int mCount = 3 * GetParam().numTris; int mCount = 3 * GetParam().numTris;
std::vector<GLuint> mIndexData; std::vector<GLuint> mIntIndexData;
std::vector<GLushort> mShortIndexData;
}; };
DrawElementsPerfBenchmark::DrawElementsPerfBenchmark() DrawElementsPerfBenchmark::DrawElementsPerfBenchmark()
...@@ -101,11 +109,22 @@ void DrawElementsPerfBenchmark::initializeBenchmark() ...@@ -101,11 +109,22 @@ void DrawElementsPerfBenchmark::initializeBenchmark()
for (int i = 0; i < mCount; i++) for (int i = 0; i < mCount; i++)
{ {
mIndexData.push_back(rand() % mCount); mShortIndexData.push_back(rand() % mCount);
mIntIndexData.push_back(rand() % mCount);
} }
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(params.type) * mIndexData.size(),
mIndexData.data()); mBufferSize = gl::ElementTypeSize(params.type) * mCount;
if (params.type == GL_UNSIGNED_INT)
{
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, mBufferSize, mIntIndexData.data());
}
else
{
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, mBufferSize, mShortIndexData.data());
}
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
...@@ -149,8 +168,14 @@ void DrawElementsPerfBenchmark::drawBenchmark() ...@@ -149,8 +168,14 @@ void DrawElementsPerfBenchmark::drawBenchmark()
{ {
if (params.indexBufferChanged) if (params.indexBufferChanged)
{ {
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(params.type) * mIndexData.size(), if (params.type == GL_UNSIGNED_INT)
mIndexData.data()); {
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, mBufferSize, mIntIndexData.data());
}
else
{
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, mBufferSize, mShortIndexData.data());
}
} }
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(mCount), params.type, 0); glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(mCount), params.type, 0);
} }
...@@ -158,12 +183,15 @@ void DrawElementsPerfBenchmark::drawBenchmark() ...@@ -158,12 +183,15 @@ void DrawElementsPerfBenchmark::drawBenchmark()
ASSERT_GL_NO_ERROR(); ASSERT_GL_NO_ERROR();
} }
DrawElementsPerfParams DrawElementsPerfD3D11Params(bool indexBufferChanged, bool useNullDevice) DrawElementsPerfParams DrawElementsPerfD3D11Params(bool indexBufferChanged,
bool useNullDevice,
GLenum indexType)
{ {
DrawElementsPerfParams params; DrawElementsPerfParams params;
params.eglParameters = params.eglParameters =
useNullDevice ? angle::egl_platform::D3D11_NULL() : angle::egl_platform::D3D11(); useNullDevice ? angle::egl_platform::D3D11_NULL() : angle::egl_platform::D3D11();
params.indexBufferChanged = indexBufferChanged; params.indexBufferChanged = indexBufferChanged;
params.type = indexType;
return params; return params;
} }
...@@ -191,10 +219,11 @@ TEST_P(DrawElementsPerfBenchmark, Run) ...@@ -191,10 +219,11 @@ TEST_P(DrawElementsPerfBenchmark, Run)
ANGLE_INSTANTIATE_TEST(DrawElementsPerfBenchmark, ANGLE_INSTANTIATE_TEST(DrawElementsPerfBenchmark,
DrawElementsPerfD3D9Params(false), DrawElementsPerfD3D9Params(false),
DrawElementsPerfD3D9Params(true), DrawElementsPerfD3D9Params(true),
DrawElementsPerfD3D11Params(false, true), DrawElementsPerfD3D11Params(false, true, GL_UNSIGNED_INT),
DrawElementsPerfD3D11Params(true, true), DrawElementsPerfD3D11Params(true, true, GL_UNSIGNED_INT),
DrawElementsPerfD3D11Params(false, false), DrawElementsPerfD3D11Params(false, false, GL_UNSIGNED_INT),
DrawElementsPerfD3D11Params(true, false), DrawElementsPerfD3D11Params(true, false, GL_UNSIGNED_INT),
DrawElementsPerfD3D11Params(false, true, GL_UNSIGNED_SHORT),
DrawElementsPerfOpenGLOrGLESParams(false), DrawElementsPerfOpenGLOrGLESParams(false),
DrawElementsPerfOpenGLOrGLESParams(true)); DrawElementsPerfOpenGLOrGLESParams(true));
......
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