mesa: optimize _mesa_attr_zero_aliases_vertex()
authorBrian Paul <brianp@vmware.com>
Fri, 18 Aug 2017 21:48:13 +0000 (15:48 -0600)
committerBrian Paul <brianp@vmware.com>
Tue, 22 Aug 2017 01:04:51 +0000 (19:04 -0600)
After the context is initialized, the API and context flags won't
change.  So, we can compute whether vertex attribute 0 aliases
vertex position just once.

This should make the glVertexAttrib*() functions a little quicker.

Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/mesa/main/context.c
src/mesa/main/mtypes.h
src/mesa/main/varray.h

index b4b7b6e..cd3ecce 100644 (file)
@@ -1607,6 +1607,23 @@ handle_first_current(struct gl_context *ctx)
       }
    }
 
+   /* Determine if generic vertex attribute 0 aliases the conventional
+    * glVertex position.
+    */
+   {
+      const bool is_forward_compatible_context =
+         ctx->Const.ContextFlags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
+
+      /* In OpenGL 3.1 attribute 0 becomes non-magic, just like in OpenGL ES
+       * 2.0.  Note that we cannot just check for API_OPENGL_COMPAT here because
+       * that will erroneously allow this usage in a 3.0 forward-compatible
+       * context too.
+       */
+      ctx->_AttribZeroAliasesVertex = (ctx->API == API_OPENGLES
+                                       || (ctx->API == API_OPENGL_COMPAT
+                                           && !is_forward_compatible_context));
+   }
+
    /* We can use this to help debug user's problems.  Tell them to set
     * the MESA_INFO env variable before running their app.  Then the
     * first time each context is made current we'll print some useful
index 49eb7d5..74392f8 100644 (file)
@@ -4972,6 +4972,9 @@ struct gl_context
    GLboolean RasterDiscard;  /**< GL_RASTERIZER_DISCARD */
    GLboolean IntelConservativeRasterization; /**< GL_INTEL_CONSERVATIVE_RASTERIZATION */
 
+   /** Does glVertexAttrib(0) alias glVertex()? */
+   bool _AttribZeroAliasesVertex;
+
    /**
     * \name Hooks for module contexts.  
     *
index 730f7cf..927a1ad 100644 (file)
@@ -73,19 +73,9 @@ _mesa_update_client_array(struct gl_context *ctx,
 }
 
 static inline bool
-_mesa_attr_zero_aliases_vertex(struct gl_context *ctx)
+_mesa_attr_zero_aliases_vertex(const struct gl_context *ctx)
 {
-   const bool is_forward_compatible_context =
-      ctx->Const.ContextFlags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
-
-   /* In OpenGL 3.1 attribute 0 becomes non-magic, just like in OpenGL ES
-    * 2.0.  Note that we cannot just check for API_OPENGL_COMPAT here because
-    * that will erroneously allow this usage in a 3.0 forward-compatible
-    * context too.
-    */
-   return (ctx->API == API_OPENGLES
-           || (ctx->API == API_OPENGL_COMPAT
-               && !is_forward_compatible_context));
+   return ctx->_AttribZeroAliasesVertex;
 }
 
 extern void