mesa: include stdio.h where needed
[mesa.git] / src / mesa / vbo / vbo_exec_array.c
index 22557e1684423c6de1b267fb5e06cd91986a1934..3ea775c0e4a5b092288863708dd1f88dd051e840 100644 (file)
@@ -26,6 +26,7 @@
  * 
  **************************************************************************/
 
+#include <stdio.h>
 #include "main/glheader.h"
 #include "main/context.h"
 #include "main/state.h"
@@ -36,6 +37,8 @@
 #include "main/enums.h"
 #include "main/macros.h"
 #include "main/transformfeedback.h"
+#include "main/sse_minmax.h"
+#include "x86/common_x86_asm.h"
 
 #include "vbo_context.h"
 
@@ -119,10 +122,16 @@ vbo_get_minmax_index(struct gl_context *ctx,
          }
       }
       else {
-         for (i = 0; i < count; i++) {
-            if (ui_indices[i] > max_ui) max_ui = ui_indices[i];
-            if (ui_indices[i] < min_ui) min_ui = ui_indices[i];
+#if defined(USE_SSE41)
+         if (cpu_has_sse4_1) {
+            _mesa_uint_array_min_max(ui_indices, &min_ui, &max_ui, count);
          }
+         else
+#endif
+            for (i = 0; i < count; i++) {
+               if (ui_indices[i] > max_ui) max_ui = ui_indices[i];
+               if (ui_indices[i] < min_ui) min_ui = ui_indices[i];
+            }
       }
       *min_index = min_ui;
       *max_index = max_ui;
@@ -173,8 +182,7 @@ vbo_get_minmax_index(struct gl_context *ctx,
       break;
    }
    default:
-      assert(0);
-      break;
+      unreachable("not reached");
    }
 
    if (_mesa_is_bufferobj(ib->obj)) {
@@ -292,7 +300,8 @@ check_draw_elements_data(struct gl_context *ctx, GLsizei count, GLenum elemType,
 {
    struct gl_vertex_array_object *vao = ctx->Array.VAO;
    const void *elemMap;
-   GLint i, k;
+   GLint i;
+   GLuint k;
 
    if (_mesa_is_bufferobj(ctx->Array.VAO->IndexBufferObj)) {
       elemMap = ctx->Driver.MapBufferRange(ctx, 0,
@@ -322,7 +331,7 @@ check_draw_elements_data(struct gl_context *ctx, GLsizei count, GLenum elemType,
       }
 
       /* check element j of each enabled array */
-      for (k = 0; k < Elements(vao->_VertexAttrib); k++) {
+      for (k = 0; k < ARRAY_SIZE(vao->_VertexAttrib); k++) {
          check_array_data(ctx, &vao->_VertexAttrib[k], k, j);
       }
    }
@@ -332,7 +341,7 @@ check_draw_elements_data(struct gl_context *ctx, GLsizei count, GLenum elemType,
                               MAP_INTERNAL);
    }
 
-   for (k = 0; k < Elements(vao->_VertexAttrib); k++) {
+   for (k = 0; k < ARRAY_SIZE(vao->_VertexAttrib); k++) {
       unmap_array_buffer(ctx, &vao->_VertexAttrib[k]);
    }
 }
@@ -562,38 +571,6 @@ vbo_bind_arrays(struct gl_context *ctx)
    }
 }
 
-
-/**
- * Handle a draw case that potentially has primitive restart enabled.
- *
- * If primitive restart is enabled, and PrimitiveRestartInSoftware is
- * set, then vbo_sw_primitive_restart is used to handle the primitive
- * restart case in software.
- */
-static void
-vbo_handle_primitive_restart(struct gl_context *ctx,
-                             const struct _mesa_prim *prim,
-                             GLuint nr_prims,
-                             const struct _mesa_index_buffer *ib,
-                             GLboolean index_bounds_valid,
-                             GLuint min_index,
-                             GLuint max_index)
-{
-   struct vbo_context *vbo = vbo_context(ctx);
-
-   if (ctx->Const.PrimitiveRestartInSoftware &&
-       ctx->Array._PrimitiveRestart &&
-       (ib != NULL)) {
-      /* Handle primitive restart in software */
-      vbo_sw_primitive_restart(ctx, prim, nr_prims, ib, NULL);
-   } else {
-      /* Call driver directly for draw_prims */
-      vbo->draw_prims(ctx, prim, nr_prims, ib,
-                      index_bounds_valid, min_index, max_index, NULL, NULL);
-   }
-}
-
-
 /**
  * Helper function called by the other DrawArrays() functions below.
  * This is where we handle primitive restart for drawing non-indexed
@@ -620,7 +597,8 @@ vbo_draw_arrays(struct gl_context *ctx, GLenum mode, GLint start,
    prim[0].is_indirect = 0;
 
    /* Implement the primitive restart index */
-   if (ctx->Array.PrimitiveRestart && ctx->Array.RestartIndex < count) {
+   if (ctx->Array.PrimitiveRestart && !ctx->Array.PrimitiveRestartFixedIndex &&
+       ctx->Array.RestartIndex < count) {
       GLuint primCount = 0;
 
       if (ctx->Array.RestartIndex == start) {
@@ -810,7 +788,7 @@ vbo_exec_DrawArrays(GLenum mode, GLint start, GLsizei count)
       _mesa_debug(ctx, "glDrawArrays(%s, %d, %d)\n",
                   _mesa_lookup_enum_by_nr(mode), start, count);
 
-   if (!_mesa_validate_DrawArrays( ctx, mode, start, count ))
+   if (!_mesa_validate_DrawArrays(ctx, mode, count))
       return;
 
    if (0)
@@ -1011,8 +989,8 @@ vbo_validated_drawrangeelements(struct gl_context *ctx, GLenum mode,
     */
 
    check_buffers_are_unmapped(exec->array.inputs);
-   vbo_handle_primitive_restart(ctx, prim, 1, &ib,
-                                index_bounds_valid, start, end);
+   vbo->draw_prims(ctx, prim, 1, &ib,
+                   index_bounds_valid, start, end, NULL, NULL);
 
    if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH) {
       _mesa_flush(ctx);
@@ -1032,7 +1010,12 @@ vbo_exec_DrawRangeElementsBaseVertex(GLenum mode,
 {
    static GLuint warnCount = 0;
    GLboolean index_bounds_valid = GL_TRUE;
-   GLuint max_element;
+
+   /* This is only useful to catch invalid values in the "end" parameter
+    * like ~0.
+    */
+   GLuint max_element = 2 * 1000 * 1000 * 1000; /* just a big number */
+
    GET_CURRENT_CONTEXT(ctx);
 
    if (MESA_VERBOSE & VERBOSE_DRAW)
@@ -1041,29 +1024,10 @@ vbo_exec_DrawRangeElementsBaseVertex(GLenum mode,
                 _mesa_lookup_enum_by_nr(mode), start, end, count,
                 _mesa_lookup_enum_by_nr(type), indices, basevertex);
 
-   if (!_mesa_validate_DrawRangeElements( ctx, mode, start, end, count,
-                                          type, indices, basevertex ))
+   if (!_mesa_validate_DrawRangeElements(ctx, mode, start, end, count,
+                                         type, indices))
       return;
 
-   if (ctx->Const.CheckArrayBounds) {
-      /* _MaxElement was computed, so we can use it.
-       * This path is used for drivers which need strict bounds checking.
-       */
-      max_element = ctx->Array.VAO->_MaxElement;
-   }
-   else {
-      /* Generally, hardware drivers don't need to know the buffer bounds
-       * if all vertex attributes are in VBOs.
-       * However, if none of vertex attributes are in VBOs, _MaxElement
-       * is always set to some random big number anyway, so bounds checking
-       * is mostly useless.
-       *
-       * This is only useful to catch invalid values in the "end" parameter
-       * like ~0.
-       */
-      max_element = 2 * 1000 * 1000 * 1000; /* just a big number */
-   }
-
    if ((int) end + basevertex < 0 ||
        start + basevertex >= max_element) {
       /* The application requested we draw using a range of indices that's
@@ -1158,7 +1122,7 @@ vbo_exec_DrawElements(GLenum mode, GLsizei count, GLenum type,
                   _mesa_lookup_enum_by_nr(mode), count,
                   _mesa_lookup_enum_by_nr(type), indices);
 
-   if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices, 0 ))
+   if (!_mesa_validate_DrawElements(ctx, mode, count, type, indices))
       return;
 
    vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
@@ -1180,8 +1144,7 @@ vbo_exec_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type,
                   _mesa_lookup_enum_by_nr(mode), count,
                   _mesa_lookup_enum_by_nr(type), indices, basevertex);
 
-   if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices,
-                                    basevertex ))
+   if (!_mesa_validate_DrawElements(ctx, mode, count, type, indices))
       return;
 
    vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
@@ -1204,7 +1167,7 @@ vbo_exec_DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type,
                   _mesa_lookup_enum_by_nr(type), indices, numInstances);
 
    if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type, indices,
-                                             numInstances, 0))
+                                             numInstances))
       return;
 
    vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
@@ -1229,7 +1192,7 @@ vbo_exec_DrawElementsInstancedBaseVertex(GLenum mode, GLsizei count, GLenum type
                   numInstances, basevertex);
 
    if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type, indices,
-                                             numInstances, basevertex))
+                                             numInstances))
       return;
 
    vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
@@ -1254,7 +1217,7 @@ vbo_exec_DrawElementsInstancedBaseInstance(GLenum mode, GLsizei count, GLenum ty
                   numInstances, baseInstance);
 
    if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type, indices,
-                                             numInstances, 0))
+                                             numInstances))
       return;
 
    vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
@@ -1280,7 +1243,7 @@ vbo_exec_DrawElementsInstancedBaseVertexBaseInstance(GLenum mode, GLsizei count,
                   numInstances, basevertex, baseInstance);
 
    if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type, indices,
-                                             numInstances, basevertex))
+                                             numInstances))
       return;
 
    vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
@@ -1386,8 +1349,8 @@ vbo_validated_multidrawelements(struct gl_context *ctx, GLenum mode,
       }
 
       check_buffers_are_unmapped(exec->array.inputs);
-      vbo_handle_primitive_restart(ctx, prim, primcount, &ib,
-                                   GL_FALSE, ~0, ~0);
+      vbo->draw_prims(ctx, prim, primcount, &ib,
+                      false, ~0, ~0, NULL, NULL);
    } else {
       /* render one prim at a time */
       for (i = 0; i < primcount; i++) {
@@ -1415,8 +1378,8 @@ vbo_validated_multidrawelements(struct gl_context *ctx, GLenum mode,
            prim[0].basevertex = 0;
 
          check_buffers_are_unmapped(exec->array.inputs);
-         vbo_handle_primitive_restart(ctx, prim, 1, &ib,
-                                      GL_FALSE, ~0, ~0);
+         vbo->draw_prims(ctx, prim, 1, &ib,
+                         false, ~0, ~0, NULL, NULL);
       }
    }
 
@@ -1437,7 +1400,7 @@ vbo_exec_MultiDrawElements(GLenum mode,
    GET_CURRENT_CONTEXT(ctx);
 
    if (!_mesa_validate_MultiDrawElements(ctx, mode, count, type, indices,
-                                         primcount, NULL))
+                                         primcount))
       return;
 
    vbo_validated_multidrawelements(ctx, mode, count, type, indices, primcount,
@@ -1455,7 +1418,7 @@ vbo_exec_MultiDrawElementsBaseVertex(GLenum mode,
    GET_CURRENT_CONTEXT(ctx);
 
    if (!_mesa_validate_MultiDrawElements(ctx, mode, count, type, indices,
-                                         primcount, basevertex))
+                                         primcount))
       return;
 
    vbo_validated_multidrawelements(ctx, mode, count, type, indices, primcount,
@@ -1478,8 +1441,6 @@ vbo_draw_transform_feedback(struct gl_context *ctx, GLenum mode,
 
    if (ctx->Driver.GetTransformFeedbackVertexCount &&
        (ctx->Const.AlwaysUseGetTransformFeedbackVertexCount ||
-        (ctx->Const.PrimitiveRestartInSoftware &&
-         ctx->Array._PrimitiveRestart) ||
         !vbo_all_varyings_in_vbos(exec->array.inputs))) {
       GLsizei n = ctx->Driver.GetTransformFeedbackVertexCount(ctx, obj, stream);
       vbo_draw_arrays(ctx, mode, 0, n, numInstances, 0);