Final cleanup to ValidateDrawAttribs.

This moves the client attribs check into a shared place. This cleans up
some of the surrounding code. Also get rid of the vertex count
parameter.

Bug: angleproject:1391
Change-Id: I9c688895c2cc5650d7b395497d69033093916f21
Reviewed-on: https://chromium-review.googlesource.com/1150517
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Frank Henigman <fjhenigman@chromium.org>
diff --git a/src/libANGLE/validationES.cpp b/src/libANGLE/validationES.cpp
index 2650fbc..ca6dedf 100644
--- a/src/libANGLE/validationES.cpp
+++ b/src/libANGLE/validationES.cpp
@@ -81,8 +81,7 @@
 
 bool ValidateDrawClientAttribs(Context *context)
 {
-    if (!context->getStateCache().hasAnyEnabledClientAttrib())
-        return true;
+    ASSERT(context->getStateCache().hasAnyEnabledClientAttrib());
 
     const gl::State &state = context->getGLState();
 
@@ -107,18 +106,10 @@
     return true;
 }
 
-bool ValidateDrawAttribs(Context *context, GLint primcount, GLint maxVertex, GLint vertexCount)
+bool ValidateDrawAttribs(Context *context, GLint primcount, GLint maxVertex)
 {
-    if (!ValidateDrawClientAttribs(context))
-    {
-        return false;
-    }
-
     // If we're drawing zero vertices, we have enough data.
-    if (vertexCount <= 0 || primcount <= 0)
-    {
-        return true;
-    }
+    ASSERT(primcount > 0);
 
     if (maxVertex <= context->getStateCache().getNonInstancedVertexElementLimit() &&
         (primcount - 1) <= context->getStateCache().getInstancedVertexElementLimit())
@@ -2690,6 +2681,14 @@
         return false;
     }
 
+    if (context->getStateCache().hasAnyEnabledClientAttrib())
+    {
+        if (!ValidateDrawClientAttribs(context))
+        {
+            return false;
+        }
+    }
+
     // If we are running GLES1, there is no current program.
     if (context->getClientVersion() >= Version(2, 0))
     {
@@ -2892,7 +2891,7 @@
     // - if count < 0, skip validating no-op draw calls.
     // From this we know maxVertex will be positive, and only need to check if it overflows GLint.
     ASSERT(first >= 0);
-    if (count > 0)
+    if (count > 0 && primcount > 0)
     {
         int64_t maxVertex = static_cast<int64_t>(first) + static_cast<int64_t>(count) - 1;
         if (maxVertex > static_cast<int64_t>(std::numeric_limits<GLint>::max()))
@@ -2901,7 +2900,7 @@
             return false;
         }
 
-        if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(maxVertex), count))
+        if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(maxVertex)))
         {
             return false;
         }
@@ -3107,15 +3106,7 @@
         }
     }
 
-    if (context->getExtensions().robustBufferAccessBehavior || count == 0)
-    {
-        // Special checks are needed for client attribs. But we don't need to validate overflows.
-        if (!ValidateDrawClientAttribs(context))
-        {
-            return false;
-        }
-    }
-    else
+    if (!context->getExtensions().robustBufferAccessBehavior && count > 0 && primcount > 0)
     {
         // Use the parameter buffer to retrieve and cache the index range.
         const DrawCallParams &params = context->getParams<DrawCallParams>();
@@ -3131,8 +3122,7 @@
             return false;
         }
 
-        if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(indexRange.end),
-                                 static_cast<GLint>(indexRange.vertexCount())))
+        if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(indexRange.end)))
         {
             return false;
         }