Micro-optimization in HandleVertexAttribPointer
vertexAttribPointer is a fairly common GL call, so substituting integer
division with bitwise and which has far less latency on common CPU
architectures is a worthwhile optimization.
IsPOT function is added for asserts that make sure this does not break.
Redundant comparison against zero is dropped from IsNPOT. In C++,
unsigned integers are specified to work with mod 2^n arithmetic.
TEST=gpu_unittests
BUG=400135
Review URL: https://codereview.chromium.org/439253002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287512 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc
index 8d33587..7e5f942 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -7205,13 +7205,15 @@
}
GLsizei component_size =
GLES2Util::GetGLTypeSizeForTexturesAndBuffers(type);
- if (offset % component_size > 0) {
+ // component_size must be a power of two to use & as optimized modulo.
+ DCHECK(GLES2Util::IsPOT(component_size));
+ if (offset & (component_size - 1)) {
LOCAL_SET_GL_ERROR(
GL_INVALID_OPERATION,
"glVertexAttribPointer", "offset not valid for type");
return error::kNoError;
}
- if (stride % component_size > 0) {
+ if (stride & (component_size - 1)) {
LOCAL_SET_GL_ERROR(
GL_INVALID_OPERATION,
"glVertexAttribPointer", "stride not valid for type");
@@ -7984,8 +7986,7 @@
}
bool IsValidPVRTCSize(GLint level, GLsizei size) {
- // Ensure that the size is a power of two
- return (size & (size - 1)) == 0;
+ return GLES2Util::IsPOT(size);
}
} // anonymous namespace.