[Mesa-dev] [PATCH 06/17] mesa: skip _MaxElement computation unless driver needs strict bounds checking

Marek Olšák maraeo at gmail.com
Wed May 1 20:42:57 PDT 2013


If Const.CheckArrayBounds is false, the only code using _MaxElement is
glDrawRangeElements, so I changed it and explained in the code why
_MaxElement is not very useful there.

BTW, the big magic number was copied to the letter
from _mesa_update_array_max_element.
---
 src/mesa/main/state.c         |    4 +++-
 src/mesa/vbo/vbo_exec_array.c |   26 +++++++++++++++++++++++---
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index e7e23ca..1b927ca 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -411,8 +411,10 @@ _mesa_update_state_locked( struct gl_context *ctx )
       new_prog_state |= update_program( ctx );
    }
 
-   if (new_state & (_NEW_ARRAY | _NEW_PROGRAM | _NEW_BUFFER_OBJECT))
+   if (ctx->Const.CheckArrayBounds &&
+       new_state & (_NEW_ARRAY | _NEW_PROGRAM | _NEW_BUFFER_OBJECT)) {
       _mesa_update_array_object_max_element(ctx, ctx->Array.ArrayObj);
+   }
 
  out:
    new_prog_state |= update_program_constants(ctx);
diff --git a/src/mesa/vbo/vbo_exec_array.c b/src/mesa/vbo/vbo_exec_array.c
index 1bf3af4..7a31676 100644
--- a/src/mesa/vbo/vbo_exec_array.c
+++ b/src/mesa/vbo/vbo_exec_array.c
@@ -863,6 +863,7 @@ vbo_exec_DrawRangeElementsBaseVertex(GLenum mode,
 {
    static GLuint warnCount = 0;
    GLboolean index_bounds_valid = GL_TRUE;
+   GLuint max_element;
    GET_CURRENT_CONTEXT(ctx);
 
    if (MESA_VERBOSE & VERBOSE_DRAW)
@@ -875,8 +876,27 @@ vbo_exec_DrawRangeElementsBaseVertex(GLenum mode,
                                           type, indices, basevertex ))
       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.ArrayObj->_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 >= ctx->Array.ArrayObj->_MaxElement) {
+       start + basevertex >= max_element) {
       /* The application requested we draw using a range of indices that's
        * outside the bounds of the current VBO.  This is invalid and appears
        * to give undefined results.  The safest thing to do is to simply
@@ -890,7 +910,7 @@ vbo_exec_DrawRangeElementsBaseVertex(GLenum mode,
                        "\trange is outside VBO bounds (max=%u); ignoring.\n"
                        "\tThis should be fixed in the application.",
                        start, end, basevertex, count, type, indices,
-                       ctx->Array.ArrayObj->_MaxElement - 1);
+                       max_element - 1);
       }
       index_bounds_valid = GL_FALSE;
    }
@@ -921,7 +941,7 @@ vbo_exec_DrawRangeElementsBaseVertex(GLenum mode,
    }
 
    if ((int) start + basevertex < 0 ||
-       end + basevertex >= ctx->Array.ArrayObj->_MaxElement)
+       end + basevertex >= max_element)
       index_bounds_valid = GL_FALSE;
 
 #if 0
-- 
1.7.10.4



More information about the mesa-dev mailing list