[Mesa-dev] [PATCH] mesa: make vertex array type error checking a little more efficient

Matthew McClure mcclurem at vmware.com
Tue Aug 5 07:48:18 PDT 2014


Looks good!

Reviewed-by: Matthew McClure <mcclurem at vmware.com>

________________________________________
From: mesa-dev <mesa-dev-bounces at lists.freedesktop.org> on behalf of Brian Paul <brianp at vmware.com>
Sent: Wednesday, July 30, 2014 10:08 AM
To: mesa-dev at lists.freedesktop.org
Subject: [Mesa-dev] [PATCH] mesa: make vertex array type error checking a       little more efficient

Compute the bitmask of supported array types once instead of every
time we call a GL vertex array function.
---
 src/mesa/main/mtypes.h |    3 ++
 src/mesa/main/varray.c |   86 +++++++++++++++++++++++++++++++-----------------
 2 files changed, 59 insertions(+), 30 deletions(-)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 3f60a55..f5ce360 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1693,6 +1693,9 @@ struct gl_array_attrib

    /** One of the DRAW_xxx flags, not consumed by drivers */
    gl_draw_method DrawMethod;
+
+   /** Legal array datatypes */
+   GLbitfield LegalTypesMask;
 };


diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c
index 46956ef..0356858 100644
--- a/src/mesa/main/varray.c
+++ b/src/mesa/main/varray.c
@@ -179,6 +179,53 @@ vertex_binding_divisor(struct gl_context *ctx, GLuint bindingIndex,


 /**
+ * Examine the API profile and extensions to determine which types are legal
+ * for vertex arrays.  This is called once from update_array_format().
+ */
+static GLbitfield
+get_legal_types_mask(const struct gl_context *ctx)
+{
+   GLbitfield legalTypesMask = ~0u; /* all */
+
+   if (_mesa_is_gles(ctx)) {
+      legalTypesMask &= ~(FIXED_GL_BIT |
+                          DOUBLE_BIT |
+                          UNSIGNED_INT_10F_11F_11F_REV_BIT);
+
+      /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
+       * 3.0.  The 2_10_10_10 types are added in OpenGL ES 3.0 or
+       * GL_OES_vertex_type_10_10_10_2.  GL_HALF_FLOAT data is not allowed
+       * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
+       * quite as trivial as we'd like because it uses a different enum value
+       * for GL_HALF_FLOAT_OES.
+       */
+      if (ctx->Version < 30) {
+         legalTypesMask &= ~(UNSIGNED_INT_BIT |
+                             INT_BIT |
+                             UNSIGNED_INT_2_10_10_10_REV_BIT |
+                             INT_2_10_10_10_REV_BIT |
+                             HALF_BIT);
+      }
+   }
+   else {
+      legalTypesMask &= ~FIXED_ES_BIT;
+
+      if (!ctx->Extensions.ARB_ES2_compatibility)
+         legalTypesMask &= ~FIXED_GL_BIT;
+
+      if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev)
+         legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT |
+                             INT_2_10_10_10_REV_BIT);
+
+      if (!ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev)
+         legalTypesMask &= ~UNSIGNED_INT_10F_11F_11F_REV_BIT;
+   }
+
+   return legalTypesMask;
+}
+
+
+/**
  * Does error checking and updates the format in an attrib array.
  *
  * Called by update_array() and VertexAttrib*Format().
@@ -208,40 +255,19 @@ update_array_format(struct gl_context *ctx,
    GLuint elementSize;
    GLenum format = GL_RGBA;

-   if (_mesa_is_gles(ctx)) {
-      legalTypesMask &= ~(FIXED_GL_BIT | DOUBLE_BIT | UNSIGNED_INT_10F_11F_11F_REV_BIT);
-
-      /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
-       * 3.0.  The 2_10_10_10 types are added in OpenGL ES 3.0 or
-       * GL_OES_vertex_type_10_10_10_2.  GL_HALF_FLOAT data is not allowed
-       * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
-       * quite as trivial as we'd like because it uses a different enum value
-       * for GL_HALF_FLOAT_OES.
+   if (ctx->Array.LegalTypesMask == 0) {
+      /* One-time initialization.  We can't do this in _mesa_init_varrays()
+       * below because extensions are not yet enabled at that point.
        */
-      if (ctx->Version < 30) {
-         legalTypesMask &= ~(UNSIGNED_INT_BIT
-                             | INT_BIT
-                             | UNSIGNED_INT_2_10_10_10_REV_BIT
-                             | INT_2_10_10_10_REV_BIT
-                             | HALF_BIT);
-      }
+      ctx->Array.LegalTypesMask = get_legal_types_mask(ctx);
+   }
+
+   legalTypesMask &= ctx->Array.LegalTypesMask;

+   if (_mesa_is_gles(ctx) && sizeMax == BGRA_OR_4) {
       /* BGRA ordering is not supported in ES contexts.
        */
-      if (sizeMax == BGRA_OR_4)
-         sizeMax = 4;
-   } else {
-      legalTypesMask &= ~FIXED_ES_BIT;
-
-      if (!ctx->Extensions.ARB_ES2_compatibility)
-         legalTypesMask &= ~FIXED_GL_BIT;
-
-      if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev)
-         legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT |
-                             INT_2_10_10_10_REV_BIT);
-
-      if (!ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev)
-         legalTypesMask &= ~UNSIGNED_INT_10F_11F_11F_REV_BIT;
+      sizeMax = 4;
    }

    typeBit = type_to_bit(ctx, type);
--
1.7.10.4

_______________________________________________
mesa-dev mailing list
mesa-dev at lists.freedesktop.org
https://urldefense.proofpoint.com/v1/url?u=http://lists.freedesktop.org/mailman/listinfo/mesa-dev&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=Vlukj7htlXQOYRouhHnZbWXYcQvOJnTLOoZzNyO4nxE%3D%0A&m=nHZ%2B0bDyvSgw2Vh2f1JXbmMuZ559rvSBSKOnmnHKYdo%3D%0A&s=e97e5f67e5cd6cd1728157c016062fb2c086ee42bf6c3e2a037bb3ca5a95beb5


More information about the mesa-dev mailing list