vbo: minor clean-ups in vbo_exec.h
[mesa.git] / src / mesa / vbo / vbo_exec_array.c
index 30c52d5fa4fccfd4e0be4b22643a0e51d8743ca4..b11da09dd1cbcb9912383d9c761b08ad2959ec82 100644 (file)
@@ -39,7 +39,7 @@
 #include "main/macros.h"
 #include "main/transformfeedback.h"
 
-#include "vbo_context.h"
+#include "vbo_private.h"
 
 
 /**
@@ -113,6 +113,23 @@ unmap_array_buffer(struct gl_context *ctx, struct gl_vertex_array_object *vao,
 }
 
 
+static inline int
+sizeof_ib_type(GLenum type)
+{
+   switch (type) {
+   case GL_UNSIGNED_INT:
+      return sizeof(GLuint);
+   case GL_UNSIGNED_SHORT:
+      return sizeof(GLushort);
+   case GL_UNSIGNED_BYTE:
+      return sizeof(GLubyte);
+   default:
+      assert(!"unsupported index data type");
+      /* In case assert is turned off */
+      return 0;
+   }
+}
+
 /**
  * Examine the array's data for NaNs, etc.
  * For debug purposes; not normally used.
@@ -150,7 +167,7 @@ check_draw_elements_data(struct gl_context *ctx, GLsizei count,
          j = ((const GLuint *) elements)[i];
          break;
       default:
-         assert(0);
+         unreachable("Unexpected index buffer type");
       }
 
       /* check element j of each enabled array */
@@ -179,6 +196,60 @@ check_draw_arrays_data(struct gl_context *ctx, GLint start, GLsizei count)
 }
 
 
+/**
+ * Check if we should skip the draw call even after validation was successful.
+ */
+static bool
+skip_validated_draw(struct gl_context *ctx)
+{
+   switch (ctx->API) {
+   case API_OPENGLES2:
+      /* For ES2, we can draw if we have a vertex program/shader). */
+      return ctx->VertexProgram._Current == NULL;
+
+   case API_OPENGLES:
+      /* For OpenGL ES, only draw if we have vertex positions
+       */
+      if (!ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS].Enabled)
+         return true;
+      break;
+
+   case API_OPENGL_CORE:
+      /* Section 7.3 (Program Objects) of the OpenGL 4.5 Core Profile spec
+       * says:
+       *
+       *     "If there is no active program for the vertex or fragment shader
+       *     stages, the results of vertex and/or fragment processing will be
+       *     undefined. However, this is not an error."
+       *
+       * The fragment shader is not tested here because other state (e.g.,
+       * GL_RASTERIZER_DISCARD) affects whether or not we actually care.
+       */
+      return ctx->VertexProgram._Current == NULL;
+
+   case API_OPENGL_COMPAT:
+      if (ctx->VertexProgram._Current != NULL) {
+         /* Draw regardless of whether or not we have any vertex arrays.
+          * (Ex: could draw a point using a constant vertex pos)
+          */
+         return false;
+      } else {
+         /* Draw if we have vertex positions (GL_VERTEX_ARRAY or generic
+          * array [0]).
+          */
+         return (!ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS].Enabled &&
+                 !ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC0].Enabled);
+      }
+      break;
+
+   default:
+      unreachable("Invalid API value in check_valid_to_render()");
+   }
+
+   return false;
+}
+
+
 /**
  * Print info/data for glDrawArrays(), for debugging.
  */
@@ -245,11 +316,11 @@ recalculate_input_bindings(struct gl_context *ctx)
    const struct gl_array_attributes *array = ctx->Array.VAO->VertexAttrib;
    struct gl_vertex_array *vertexAttrib = ctx->Array.VAO->_VertexAttrib;
    const struct gl_vertex_array **inputs = &exec->array.inputs[0];
-   GLbitfield64 const_inputs = 0x0;
+   GLbitfield const_inputs = 0x0;
    GLuint i;
 
-   switch (get_program_mode(ctx)) {
-   case VP_NONE:
+   switch (get_vp_mode(ctx)) {
+   case VP_FF:
       /* When no vertex program is active (or the vertex program is generated
        * from fixed-function state).  We put the material values into the
        * generic slots.  This is the only situation where material values
@@ -280,7 +351,7 @@ recalculate_input_bindings(struct gl_context *ctx)
       }
       break;
 
-   case VP_ARB:
+   case VP_SHADER:
       /* There are no shaders in OpenGL ES 1.x, so this code path should be
        * impossible to reach.  The meta code is careful to not use shaders in
        * ES1.
@@ -302,7 +373,7 @@ recalculate_input_bindings(struct gl_context *ctx)
          else if (array[VERT_ATTRIB_POS].Enabled)
             inputs[0] = &vertexAttrib[VERT_ATTRIB_POS];
          else {
-            inputs[0] = &vbo->currval[VBO_ATTRIB_POS];
+            inputs[0] = &vbo->currval[VBO_ATTRIB_GENERIC0];
             const_inputs |= VERT_BIT_POS;
          }
 
@@ -367,7 +438,7 @@ recalculate_input_bindings(struct gl_context *ctx)
  * Note that this might set the _NEW_VARYING_VP_INPUTS dirty flag so state
  * validation must be done after this call.
  */
-void
+static void
 vbo_bind_arrays(struct gl_context *ctx)
 {
    struct vbo_context *vbo = vbo_context(ctx);
@@ -404,27 +475,32 @@ vbo_bind_arrays(struct gl_context *ctx)
  */
 static void
 vbo_draw_arrays(struct gl_context *ctx, GLenum mode, GLint start,
-                GLsizei count, GLuint numInstances, GLuint baseInstance)
+                GLsizei count, GLuint numInstances, GLuint baseInstance,
+                GLuint drawID)
 {
    struct vbo_context *vbo = vbo_context(ctx);
-   struct _mesa_prim prim[2];
+   struct _mesa_prim prim;
+
+   if (skip_validated_draw(ctx))
+      return;
 
    vbo_bind_arrays(ctx);
 
    /* OpenGL 4.5 says that primitive restart is ignored with non-indexed
     * draws.
     */
-   memset(prim, 0, sizeof(prim));
-   prim[0].begin = 1;
-   prim[0].end = 1;
-   prim[0].mode = mode;
-   prim[0].num_instances = numInstances;
-   prim[0].base_instance = baseInstance;
-   prim[0].is_indirect = 0;
-   prim[0].start = start;
-   prim[0].count = count;
-
-   vbo->draw_prims(ctx, prim, 1, NULL,
+   memset(&prim, 0, sizeof(prim));
+   prim.begin = 1;
+   prim.end = 1;
+   prim.mode = mode;
+   prim.num_instances = numInstances;
+   prim.base_instance = baseInstance;
+   prim.draw_id = drawID;
+   prim.is_indirect = 0;
+   prim.start = start;
+   prim.count = count;
+
+   vbo->draw_prims(ctx, &prim, 1, NULL,
                    GL_TRUE, start, start + count - 1, NULL, 0, NULL);
 
    if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH) {
@@ -566,13 +642,20 @@ vbo_exec_DrawArrays(GLenum mode, GLint start, GLsizei count)
       _mesa_debug(ctx, "glDrawArrays(%s, %d, %d)\n",
                   _mesa_enum_to_string(mode), start, count);
 
-   if (!_mesa_validate_DrawArrays(ctx, mode, count))
-      return;
+   if (_mesa_is_no_error_enabled(ctx)) {
+      FLUSH_CURRENT(ctx, 0);
+
+      if (ctx->NewState)
+         _mesa_update_state(ctx);
+   } else {
+      if (!_mesa_validate_DrawArrays(ctx, mode, count))
+         return;
+   }
 
    if (0)
       check_draw_arrays_data(ctx, start, count);
 
-   vbo_draw_arrays(ctx, mode, start, count, 1, 0);
+   vbo_draw_arrays(ctx, mode, start, count, 1, 0, 0);
 
    if (0)
       print_draw_arrays(ctx, mode, start, count);
@@ -593,14 +676,22 @@ vbo_exec_DrawArraysInstanced(GLenum mode, GLint start, GLsizei count,
       _mesa_debug(ctx, "glDrawArraysInstanced(%s, %d, %d, %d)\n",
                   _mesa_enum_to_string(mode), start, count, numInstances);
 
-   if (!_mesa_validate_DrawArraysInstanced(ctx, mode, start, count,
-                                           numInstances))
-      return;
+
+   if (_mesa_is_no_error_enabled(ctx)) {
+      FLUSH_CURRENT(ctx, 0);
+
+      if (ctx->NewState)
+         _mesa_update_state(ctx);
+   } else {
+      if (!_mesa_validate_DrawArraysInstanced(ctx, mode, start, count,
+                                              numInstances))
+         return;
+   }
 
    if (0)
       check_draw_arrays_data(ctx, start, count);
 
-   vbo_draw_arrays(ctx, mode, start, count, numInstances, 0);
+   vbo_draw_arrays(ctx, mode, start, count, numInstances, 0, 0);
 
    if (0)
       print_draw_arrays(ctx, mode, start, count);
@@ -623,20 +714,73 @@ vbo_exec_DrawArraysInstancedBaseInstance(GLenum mode, GLint first,
                   _mesa_enum_to_string(mode), first, count,
                   numInstances, baseInstance);
 
-   if (!_mesa_validate_DrawArraysInstanced(ctx, mode, first, count,
-                                           numInstances))
-      return;
+   if (_mesa_is_no_error_enabled(ctx)) {
+      FLUSH_CURRENT(ctx, 0);
+
+      if (ctx->NewState)
+         _mesa_update_state(ctx);
+   } else {
+      if (!_mesa_validate_DrawArraysInstanced(ctx, mode, first, count,
+                                              numInstances))
+         return;
+   }
 
    if (0)
       check_draw_arrays_data(ctx, first, count);
 
-   vbo_draw_arrays(ctx, mode, first, count, numInstances, baseInstance);
+   vbo_draw_arrays(ctx, mode, first, count, numInstances, baseInstance, 0);
 
    if (0)
       print_draw_arrays(ctx, mode, first, count);
 }
 
 
+/**
+ * Called from glMultiDrawArrays when in immediate mode.
+ */
+static void GLAPIENTRY
+vbo_exec_MultiDrawArrays(GLenum mode, const GLint *first,
+                         const GLsizei *count, GLsizei primcount)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   GLint i;
+
+   if (MESA_VERBOSE & VERBOSE_DRAW)
+      _mesa_debug(ctx,
+                  "glMultiDrawArrays(%s, %p, %p, %d)\n",
+                  _mesa_enum_to_string(mode), first, count, primcount);
+
+   if (_mesa_is_no_error_enabled(ctx)) {
+      FLUSH_CURRENT(ctx, 0);
+
+      if (ctx->NewState)
+         _mesa_update_state(ctx);
+   } else {
+      if (!_mesa_validate_MultiDrawArrays(ctx, mode, count, primcount))
+         return;
+   }
+
+   for (i = 0; i < primcount; i++) {
+      if (count[i] > 0) {
+         if (0)
+            check_draw_arrays_data(ctx, first[i], count[i]);
+
+         /* The GL_ARB_shader_draw_parameters spec adds the following after the
+          * pseudo-code describing glMultiDrawArrays:
+          *
+          *    "The index of the draw (<i> in the above pseudo-code) may be
+          *     read by a vertex shader as <gl_DrawIDARB>, as described in
+          *     Section 11.1.3.9."
+          */
+         vbo_draw_arrays(ctx, mode, first[i], count[i], 1, 0, i);
+
+         if (0)
+            print_draw_arrays(ctx, mode, first[i], count[i]);
+      }
+   }
+}
+
+
 
 /**
  * Map GL_ELEMENT_ARRAY_BUFFER and print contents.
@@ -698,6 +842,25 @@ dump_element_buffer(struct gl_context *ctx, GLenum type)
 #endif
 
 
+static bool
+skip_draw_elements(struct gl_context *ctx, GLsizei count,
+                   const GLvoid *indices)
+{
+   if (count == 0)
+      return true;
+
+   /* Not using a VBO for indices, so avoid NULL pointer derefs later.
+    */
+   if (!_mesa_is_bufferobj(ctx->Array.VAO->IndexBufferObj) && indices == NULL)
+      return true;
+
+   if (skip_validated_draw(ctx))
+      return true;
+
+   return false;
+}
+
+
 /**
  * Inner support for both _mesa_DrawElements and _mesa_DrawRangeElements.
  * Do the rendering for a glDrawElements or glDrawRangeElements call after
@@ -714,28 +877,36 @@ vbo_validated_drawrangeelements(struct gl_context *ctx, GLenum mode,
 {
    struct vbo_context *vbo = vbo_context(ctx);
    struct _mesa_index_buffer ib;
-   struct _mesa_prim prim[1];
+   struct _mesa_prim prim;
+
+   if (!index_bounds_valid) {
+      assert(start == 0u);
+      assert(end == ~0u);
+   }
+
+   if (skip_draw_elements(ctx, count, indices))
+      return;
 
    vbo_bind_arrays(ctx);
 
    ib.count = count;
-   ib.type = type;
+   ib.index_size = sizeof_ib_type(type);
    ib.obj = ctx->Array.VAO->IndexBufferObj;
    ib.ptr = indices;
 
-   prim[0].begin = 1;
-   prim[0].end = 1;
-   prim[0].weak = 0;
-   prim[0].pad = 0;
-   prim[0].mode = mode;
-   prim[0].start = 0;
-   prim[0].count = count;
-   prim[0].indexed = 1;
-   prim[0].is_indirect = 0;
-   prim[0].basevertex = basevertex;
-   prim[0].num_instances = numInstances;
-   prim[0].base_instance = baseInstance;
-   prim[0].draw_id = 0;
+   prim.begin = 1;
+   prim.end = 1;
+   prim.weak = 0;
+   prim.pad = 0;
+   prim.mode = mode;
+   prim.start = 0;
+   prim.count = count;
+   prim.indexed = 1;
+   prim.is_indirect = 0;
+   prim.basevertex = basevertex;
+   prim.num_instances = numInstances;
+   prim.base_instance = baseInstance;
+   prim.draw_id = 0;
 
    /* Need to give special consideration to rendering a range of
     * indices starting somewhere above zero.  Typically the
@@ -768,7 +939,7 @@ vbo_validated_drawrangeelements(struct gl_context *ctx, GLenum mode,
     * for the latter case elsewhere.
     */
 
-   vbo->draw_prims(ctx, prim, 1, &ib,
+   vbo->draw_prims(ctx, &prim, 1, &ib,
                    index_bounds_valid, start, end, NULL, 0, NULL);
 
    if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH) {
@@ -801,9 +972,16 @@ vbo_exec_DrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end,
                   _mesa_enum_to_string(mode), start, end, count,
                   _mesa_enum_to_string(type), indices, basevertex);
 
-   if (!_mesa_validate_DrawRangeElements(ctx, mode, start, end, count,
-                                         type, indices))
-      return;
+   if (_mesa_is_no_error_enabled(ctx)) {
+      FLUSH_CURRENT(ctx, 0);
+
+      if (ctx->NewState)
+         _mesa_update_state(ctx);
+   } else {
+      if (!_mesa_validate_DrawRangeElements(ctx, mode, start, end, count,
+                                            type, indices))
+         return;
+   }
 
    if ((int) end + basevertex < 0 || start + basevertex >= max_element) {
       /* The application requested we draw using a range of indices that's
@@ -857,6 +1035,11 @@ vbo_exec_DrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end,
    (void) check_draw_elements_data;
 #endif
 
+   if (!index_bounds_valid) {
+      start = 0;
+      end = ~0;
+   }
+
    vbo_validated_drawrangeelements(ctx, mode, index_bounds_valid, start, end,
                                    count, type, indices, basevertex, 1, 0);
 }
@@ -896,10 +1079,17 @@ vbo_exec_DrawElements(GLenum mode, GLsizei count, GLenum type,
                   _mesa_enum_to_string(mode), count,
                   _mesa_enum_to_string(type), indices);
 
-   if (!_mesa_validate_DrawElements(ctx, mode, count, type, indices))
-      return;
+   if (_mesa_is_no_error_enabled(ctx)) {
+      FLUSH_CURRENT(ctx, 0);
+
+      if (ctx->NewState)
+         _mesa_update_state(ctx);
+   } else {
+      if (!_mesa_validate_DrawElements(ctx, mode, count, type, indices))
+         return;
+   }
 
-   vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
+   vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, 0, ~0,
                                    count, type, indices, 0, 1, 0);
 }
 
@@ -914,14 +1104,21 @@ vbo_exec_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type,
    GET_CURRENT_CONTEXT(ctx);
 
    if (MESA_VERBOSE & VERBOSE_DRAW)
-      _mesa_debug(ctx, "glDrawElementsBaseVertex(%s, %d, %s, %p, %d)\n",
+      _mesa_debug(ctx, "glDrawElements(%s, %u, %s, %p)\n",
                   _mesa_enum_to_string(mode), count,
-                  _mesa_enum_to_string(type), indices, basevertex);
+                  _mesa_enum_to_string(type), indices);
 
-   if (!_mesa_validate_DrawElements(ctx, mode, count, type, indices))
-      return;
+   if (_mesa_is_no_error_enabled(ctx)) {
+      FLUSH_CURRENT(ctx, 0);
 
-   vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
+      if (ctx->NewState)
+         _mesa_update_state(ctx);
+   } else {
+      if (!_mesa_validate_DrawElements(ctx, mode, count, type, indices))
+         return;
+   }
+
+   vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, 0, ~0,
                                    count, type, indices, basevertex, 1, 0);
 }
 
@@ -936,15 +1133,22 @@ vbo_exec_DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type,
    GET_CURRENT_CONTEXT(ctx);
 
    if (MESA_VERBOSE & VERBOSE_DRAW)
-      _mesa_debug(ctx, "glDrawElementsInstanced(%s, %d, %s, %p, %d)\n",
+      _mesa_debug(ctx, "glDrawElements(%s, %u, %s, %p)\n",
                   _mesa_enum_to_string(mode), count,
-                  _mesa_enum_to_string(type), indices, numInstances);
+                  _mesa_enum_to_string(type), indices);
 
-   if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type, indices,
-                                             numInstances))
-      return;
+   if (_mesa_is_no_error_enabled(ctx)) {
+      FLUSH_CURRENT(ctx, 0);
 
-   vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
+      if (ctx->NewState)
+         _mesa_update_state(ctx);
+   } else {
+      if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type,
+                                                indices, numInstances))
+         return;
+   }
+
+   vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, 0, ~0,
                                    count, type, indices, 0, numInstances, 0);
 }
 
@@ -962,16 +1166,24 @@ vbo_exec_DrawElementsInstancedBaseVertex(GLenum mode, GLsizei count,
 
    if (MESA_VERBOSE & VERBOSE_DRAW)
       _mesa_debug(ctx,
-                  "glDrawElementsInstancedBaseVertex(%s, %d, %s, %p, %d; %d)\n",
+                  "glDrawElementsInstancedBaseVertex"
+                  "(%s, %d, %s, %p, %d; %d)\n",
                   _mesa_enum_to_string(mode), count,
                   _mesa_enum_to_string(type), indices,
                   numInstances, basevertex);
 
-   if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type, indices,
-                                             numInstances))
-      return;
+   if (_mesa_is_no_error_enabled(ctx)) {
+      FLUSH_CURRENT(ctx, 0);
 
-   vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
+      if (ctx->NewState)
+         _mesa_update_state(ctx);
+   } else {
+      if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type,
+                                                indices, numInstances))
+         return;
+   }
+
+   vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, 0, ~0,
                                    count, type, indices,
                                    basevertex, numInstances, 0);
 }
@@ -997,11 +1209,18 @@ vbo_exec_DrawElementsInstancedBaseInstance(GLenum mode, GLsizei count,
                   _mesa_enum_to_string(type), indices,
                   numInstances, baseInstance);
 
-   if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type, indices,
-                                             numInstances))
-      return;
+   if (_mesa_is_no_error_enabled(ctx)) {
+      FLUSH_CURRENT(ctx, 0);
 
-   vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
+      if (ctx->NewState)
+         _mesa_update_state(ctx);
+   } else {
+      if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type,
+                                                indices, numInstances))
+         return;
+   }
+
+   vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, 0, ~0,
                                    count, type, indices, 0, numInstances,
                                    baseInstance);
 }
@@ -1029,11 +1248,18 @@ vbo_exec_DrawElementsInstancedBaseVertexBaseInstance(GLenum mode,
                   _mesa_enum_to_string(type), indices,
                   numInstances, basevertex, baseInstance);
 
-   if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type, indices,
-                                             numInstances))
-      return;
+   if (_mesa_is_no_error_enabled(ctx)) {
+      FLUSH_CURRENT(ctx, 0);
+
+      if (ctx->NewState)
+         _mesa_update_state(ctx);
+   } else {
+      if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type,
+                                                indices, numInstances))
+         return;
+   }
 
-   vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
+   vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, 0, ~0,
                                    count, type, indices, basevertex,
                                    numInstances, baseInstance);
 }
@@ -1053,7 +1279,7 @@ vbo_validated_multidrawelements(struct gl_context *ctx, GLenum mode,
    struct vbo_context *vbo = vbo_context(ctx);
    struct _mesa_index_buffer ib;
    struct _mesa_prim *prim;
-   unsigned int index_type_size = vbo_sizeof_ib_type(type);
+   unsigned int index_type_size = sizeof_ib_type(type);
    uintptr_t min_index_ptr, max_index_ptr;
    GLboolean fallback = GL_FALSE;
    int i;
@@ -1112,7 +1338,7 @@ vbo_validated_multidrawelements(struct gl_context *ctx, GLenum mode,
 
    if (!fallback) {
       ib.count = (max_index_ptr - min_index_ptr) / index_type_size;
-      ib.type = type;
+      ib.index_size = sizeof_ib_type(type);
       ib.obj = ctx->Array.VAO->IndexBufferObj;
       ib.ptr = (void *) min_index_ptr;
 
@@ -1137,7 +1363,7 @@ vbo_validated_multidrawelements(struct gl_context *ctx, GLenum mode,
       }
 
       vbo->draw_prims(ctx, prim, primcount, &ib,
-                      false, ~0, ~0, NULL, 0, NULL);
+                      false, 0, ~0, NULL, 0, NULL);
    }
    else {
       /* render one prim at a time */
@@ -1145,7 +1371,7 @@ vbo_validated_multidrawelements(struct gl_context *ctx, GLenum mode,
          if (count[i] == 0)
             continue;
          ib.count = count[i];
-         ib.type = type;
+         ib.index_size = sizeof_ib_type(type);
          ib.obj = ctx->Array.VAO->IndexBufferObj;
          ib.ptr = indices[i];
 
@@ -1166,7 +1392,7 @@ vbo_validated_multidrawelements(struct gl_context *ctx, GLenum mode,
          else
             prim[0].basevertex = 0;
 
-         vbo->draw_prims(ctx, prim, 1, &ib, false, ~0, ~0, NULL, 0, NULL);
+         vbo->draw_prims(ctx, prim, 1, &ib, false, 0, ~0, NULL, 0, NULL);
       }
    }
 
@@ -1189,6 +1415,9 @@ vbo_exec_MultiDrawElements(GLenum mode,
                                          primcount))
       return;
 
+   if (skip_validated_draw(ctx))
+      return;
+
    vbo_validated_multidrawelements(ctx, mode, count, type, indices, primcount,
                                    NULL);
 }
@@ -1203,8 +1432,18 @@ vbo_exec_MultiDrawElementsBaseVertex(GLenum mode,
 {
    GET_CURRENT_CONTEXT(ctx);
 
-   if (!_mesa_validate_MultiDrawElements(ctx, mode, count, type, indices,
-                                         primcount))
+   if (_mesa_is_no_error_enabled(ctx)) {
+      FLUSH_CURRENT(ctx, 0);
+
+      if (ctx->NewState)
+         _mesa_update_state(ctx);
+   } else {
+      if (!_mesa_validate_MultiDrawElements(ctx, mode, count, type, indices,
+                                            primcount))
+         return;
+   }
+
+   if (skip_validated_draw(ctx))
       return;
 
    vbo_validated_multidrawelements(ctx, mode, count, type, indices, primcount,
@@ -1218,11 +1457,18 @@ vbo_draw_transform_feedback(struct gl_context *ctx, GLenum mode,
                             GLuint stream, GLuint numInstances)
 {
    struct vbo_context *vbo = vbo_context(ctx);
-   struct _mesa_prim prim[2];
+   struct _mesa_prim prim;
 
-   if (!_mesa_validate_DrawTransformFeedback(ctx, mode, obj, stream,
-                                             numInstances)) {
-      return;
+   if (_mesa_is_no_error_enabled(ctx)) {
+      FLUSH_CURRENT(ctx, 0);
+
+      if (ctx->NewState)
+         _mesa_update_state(ctx);
+   } else {
+      if (!_mesa_validate_DrawTransformFeedback(ctx, mode, obj, stream,
+                                                numInstances)) {
+         return;
+      }
    }
 
    if (ctx->Driver.GetTransformFeedbackVertexCount &&
@@ -1230,26 +1476,29 @@ vbo_draw_transform_feedback(struct gl_context *ctx, GLenum mode,
         !_mesa_all_varyings_in_vbos(ctx->Array.VAO))) {
       GLsizei n =
          ctx->Driver.GetTransformFeedbackVertexCount(ctx, obj, stream);
-      vbo_draw_arrays(ctx, mode, 0, n, numInstances, 0);
+      vbo_draw_arrays(ctx, mode, 0, n, numInstances, 0, 0);
       return;
    }
 
+   if (skip_validated_draw(ctx))
+      return;
+
    vbo_bind_arrays(ctx);
 
    /* init most fields to zero */
-   memset(prim, 0, sizeof(prim));
-   prim[0].begin = 1;
-   prim[0].end = 1;
-   prim[0].mode = mode;
-   prim[0].num_instances = numInstances;
-   prim[0].base_instance = 0;
-   prim[0].is_indirect = 0;
+   memset(&prim, 0, sizeof(prim));
+   prim.begin = 1;
+   prim.end = 1;
+   prim.mode = mode;
+   prim.num_instances = numInstances;
+   prim.base_instance = 0;
+   prim.is_indirect = 0;
 
    /* Maybe we should do some primitive splitting for primitive restart
     * (like in DrawArrays), but we have no way to know how many vertices
     * will be rendered. */
 
-   vbo->draw_prims(ctx, prim, 1, NULL, GL_FALSE, ~0, ~0, obj, stream, NULL);
+   vbo->draw_prims(ctx, &prim, 1, NULL, GL_FALSE, 0, ~0, obj, stream, NULL);
 
    if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH) {
       _mesa_flush(ctx);
@@ -1380,7 +1629,7 @@ vbo_validated_drawelementsindirect(struct gl_context *ctx,
    vbo_bind_arrays(ctx);
 
    ib.count = 0;                /* unknown */
-   ib.type = type;
+   ib.index_size = sizeof_ib_type(type);
    ib.obj = ctx->Array.VAO->IndexBufferObj;
    ib.ptr = NULL;
 
@@ -1412,7 +1661,7 @@ vbo_validated_multidrawelementsindirect(struct gl_context *ctx,
    /* NOTE: IndexBufferObj is guaranteed to be a VBO. */
 
    ib.count = 0;                /* unknown */
-   ib.type = type;
+   ib.index_size = sizeof_ib_type(type);
    ib.obj = ctx->Array.VAO->IndexBufferObj;
    ib.ptr = NULL;
 
@@ -1438,7 +1687,17 @@ vbo_exec_DrawArraysIndirect(GLenum mode, const GLvoid *indirect)
       _mesa_debug(ctx, "glDrawArraysIndirect(%s, %p)\n",
                   _mesa_enum_to_string(mode), indirect);
 
-   if (!_mesa_validate_DrawArraysIndirect(ctx, mode, indirect))
+   if (_mesa_is_no_error_enabled(ctx)) {
+      FLUSH_CURRENT(ctx, 0);
+
+      if (ctx->NewState)
+         _mesa_update_state(ctx);
+   } else {
+      if (!_mesa_validate_DrawArraysIndirect(ctx, mode, indirect))
+         return;
+   }
+
+   if (skip_validated_draw(ctx))
       return;
 
    vbo_validated_drawarraysindirect(ctx, mode, indirect);
@@ -1455,7 +1714,17 @@ vbo_exec_DrawElementsIndirect(GLenum mode, GLenum type, const GLvoid *indirect)
                   _mesa_enum_to_string(mode),
                   _mesa_enum_to_string(type), indirect);
 
-   if (!_mesa_validate_DrawElementsIndirect(ctx, mode, type, indirect))
+   if (_mesa_is_no_error_enabled(ctx)) {
+      FLUSH_CURRENT(ctx, 0);
+
+      if (ctx->NewState)
+         _mesa_update_state(ctx);
+   } else {
+      if (!_mesa_validate_DrawElementsIndirect(ctx, mode, type, indirect))
+         return;
+   }
+
+   if (skip_validated_draw(ctx))
       return;
 
    vbo_validated_drawelementsindirect(ctx, mode, type, indirect);
@@ -1476,8 +1745,18 @@ vbo_exec_MultiDrawArraysIndirect(GLenum mode, const GLvoid *indirect,
    if (stride == 0)
       stride = 4 * sizeof(GLuint);      /* sizeof(DrawArraysIndirectCommand) */
 
-   if (!_mesa_validate_MultiDrawArraysIndirect(ctx, mode, indirect,
-                                               primcount, stride))
+   if (_mesa_is_no_error_enabled(ctx)) {
+      FLUSH_CURRENT(ctx, 0);
+
+      if (ctx->NewState)
+         _mesa_update_state(ctx);
+   } else {
+      if (!_mesa_validate_MultiDrawArraysIndirect(ctx, mode, indirect,
+                                                  primcount, stride))
+         return;
+   }
+
+   if (skip_validated_draw(ctx))
       return;
 
    vbo_validated_multidrawarraysindirect(ctx, mode, indirect,
@@ -1501,8 +1780,18 @@ vbo_exec_MultiDrawElementsIndirect(GLenum mode, GLenum type,
    if (stride == 0)
       stride = 5 * sizeof(GLuint);      /* sizeof(DrawElementsIndirectCommand) */
 
-   if (!_mesa_validate_MultiDrawElementsIndirect(ctx, mode, type, indirect,
-                                                 primcount, stride))
+   if (_mesa_is_no_error_enabled(ctx)) {
+      FLUSH_CURRENT(ctx, 0);
+
+      if (ctx->NewState)
+         _mesa_update_state(ctx);
+   } else {
+      if (!_mesa_validate_MultiDrawElementsIndirect(ctx, mode, type, indirect,
+                                                    primcount, stride))
+         return;
+   }
+
+   if (skip_validated_draw(ctx))
       return;
 
    vbo_validated_multidrawelementsindirect(ctx, mode, type, indirect,
@@ -1556,7 +1845,7 @@ vbo_validated_multidrawelementsindirectcount(struct gl_context *ctx,
    /* NOTE: IndexBufferObj is guaranteed to be a VBO. */
 
    ib.count = 0;                /* unknown */
-   ib.type = type;
+   ib.index_size = sizeof_ib_type(type);
    ib.obj = ctx->Array.VAO->IndexBufferObj;
    ib.ptr = NULL;
 
@@ -1588,9 +1877,19 @@ vbo_exec_MultiDrawArraysIndirectCount(GLenum mode, GLintptr indirect,
    if (stride == 0)
       stride = 4 * sizeof(GLuint);      /* sizeof(DrawArraysIndirectCommand) */
 
-   if (!_mesa_validate_MultiDrawArraysIndirectCount(ctx, mode,
-                                                    indirect, drawcount,
-                                                    maxdrawcount, stride))
+   if (_mesa_is_no_error_enabled(ctx)) {
+      FLUSH_CURRENT(ctx, 0);
+
+      if (ctx->NewState)
+         _mesa_update_state(ctx);
+   } else {
+      if (!_mesa_validate_MultiDrawArraysIndirectCount(ctx, mode,
+                                                       indirect, drawcount,
+                                                       maxdrawcount, stride))
+         return;
+   }
+
+   if (skip_validated_draw(ctx))
       return;
 
    vbo_validated_multidrawarraysindirectcount(ctx, mode, indirect, drawcount,
@@ -1616,9 +1915,19 @@ vbo_exec_MultiDrawElementsIndirectCount(GLenum mode, GLenum type,
    if (stride == 0)
       stride = 5 * sizeof(GLuint);      /* sizeof(DrawElementsIndirectCommand) */
 
-   if (!_mesa_validate_MultiDrawElementsIndirectCount(ctx, mode, type,
-                                                      indirect, drawcount,
-                                                      maxdrawcount, stride))
+   if (_mesa_is_no_error_enabled(ctx)) {
+      FLUSH_CURRENT(ctx, 0);
+
+      if (ctx->NewState)
+         _mesa_update_state(ctx);
+   } else {
+      if (!_mesa_validate_MultiDrawElementsIndirectCount(ctx, mode, type,
+                                                         indirect, drawcount,
+                                                         maxdrawcount, stride))
+         return;
+   }
+
+   if (skip_validated_draw(ctx))
       return;
 
    vbo_validated_multidrawelementsindirectcount(ctx, mode, type, indirect,
@@ -1641,6 +1950,7 @@ vbo_initialize_exec_dispatch(const struct gl_context *ctx,
       SET_DrawRangeElements(exec, vbo_exec_DrawRangeElements);
    }
 
+   SET_MultiDrawArrays(exec, vbo_exec_MultiDrawArrays);
    SET_MultiDrawElementsEXT(exec, vbo_exec_MultiDrawElements);
 
    if (ctx->API == API_OPENGL_COMPAT) {