Support primitive restart in RendererGL.

Store index ranges in a new struct that tracks how many real indices were
seen.  Update index caching to key on primitive restart being enabled and
update index counting functions to skip primitive restart indicies when
needed.

Passes dEQP-GLES3.functional.primitive_restart.*

Change-Id: Id1e25a5adcdcd4e998836e8ff6679c64be4c3066
Reviewed-on: https://chromium-review.googlesource.com/297770
Tryjob-Request: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libANGLE/validationES.cpp b/src/libANGLE/validationES.cpp
index db00caf..d304c19 100644
--- a/src/libANGLE/validationES.cpp
+++ b/src/libANGLE/validationES.cpp
@@ -1642,8 +1642,13 @@
     return ValidateDrawArraysInstanced(context, mode, first, count, primcount);
 }
 
-bool ValidateDrawElements(Context *context, GLenum mode, GLsizei count, GLenum type,
-                          const GLvoid *indices, GLsizei primcount, RangeUI *indexRangeOut)
+bool ValidateDrawElements(Context *context,
+                          GLenum mode,
+                          GLsizei count,
+                          GLenum type,
+                          const GLvoid *indices,
+                          GLsizei primcount,
+                          IndexRange *indexRangeOut)
 {
     switch (type)
     {
@@ -1728,7 +1733,9 @@
     if (elementArrayBuffer)
     {
         uintptr_t offset = reinterpret_cast<uintptr_t>(indices);
-        Error error = elementArrayBuffer->getIndexRange(type, static_cast<size_t>(offset), count, indexRangeOut);
+        Error error =
+            elementArrayBuffer->getIndexRange(type, static_cast<size_t>(offset), count,
+                                              state.isPrimitiveRestartEnabled(), indexRangeOut);
         if (error.isError())
         {
             context->recordError(error);
@@ -1737,7 +1744,7 @@
     }
     else
     {
-        *indexRangeOut = ComputeIndexRange(type, indices, count);
+        *indexRangeOut = ComputeIndexRange(type, indices, count, state.isPrimitiveRestartEnabled());
     }
 
     if (!ValidateDrawAttribs(context, primcount, static_cast<GLsizei>(indexRangeOut->end)))
@@ -1745,13 +1752,17 @@
         return false;
     }
 
-    return true;
+    // No op if there are no real indices in the index data (all are primitive restart).
+    return (indexRangeOut->vertexIndexCount > 0);
 }
 
 bool ValidateDrawElementsInstanced(Context *context,
-                                   GLenum mode, GLsizei count, GLenum type,
-                                   const GLvoid *indices, GLsizei primcount,
-                                   RangeUI *indexRangeOut)
+                                   GLenum mode,
+                                   GLsizei count,
+                                   GLenum type,
+                                   const GLvoid *indices,
+                                   GLsizei primcount,
+                                   IndexRange *indexRangeOut)
 {
     if (primcount < 0)
     {
@@ -1768,8 +1779,13 @@
     return (primcount > 0);
 }
 
-bool ValidateDrawElementsInstancedANGLE(Context *context, GLenum mode, GLsizei count, GLenum type,
-                                        const GLvoid *indices, GLsizei primcount, RangeUI *indexRangeOut)
+bool ValidateDrawElementsInstancedANGLE(Context *context,
+                                        GLenum mode,
+                                        GLsizei count,
+                                        GLenum type,
+                                        const GLvoid *indices,
+                                        GLsizei primcount,
+                                        IndexRange *indexRangeOut)
 {
     if (!ValidateDrawInstancedANGLE(context))
     {