mesa: shrink size of gl_array_attributes (v2)
authorBrian Paul <brianp@vmware.com>
Mon, 29 Jan 2018 21:09:54 +0000 (14:09 -0700)
committerBrian Paul <brianp@vmware.com>
Tue, 30 Jan 2018 04:16:50 +0000 (21:16 -0700)
Inspired by Marek's earlier patch, but even smaller.  Sort fields from
largest to smallest.  Use bitfields for more fields (sometimes with an
extra bit for MSVC).  Reduce Stride field to GLshort.

Note that some fields cannot be bitfields because they're accessed via
pointers (such as for glEnableClientState(GL_VERTEX_ARRAY) to set the
Enabled field).

Reduces size from 48 to 24 bytes.
Also reduces size of gl_vertex_array_object from 3632 to 2864 bytes.

And add some assertions in init_array().

v2: use s/GLuint/unsigned/, improve commit comments.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/mesa/main/arrayobj.c
src/mesa/main/mtypes.h

index 2810647c7e78834d5c05b70743fee0bfb4097518..9d3ddbfcbf039a8c170027e76620a2060f13b679 100644 (file)
@@ -233,7 +233,9 @@ init_array(struct gl_context *ctx,
            struct gl_vertex_array_object *vao,
            GLuint index, GLint size, GLint type)
 {
            struct gl_vertex_array_object *vao,
            GLuint index, GLint size, GLint type)
 {
+   assert(index < ARRAY_SIZE(vao->VertexAttrib));
    struct gl_array_attributes *array = &vao->VertexAttrib[index];
    struct gl_array_attributes *array = &vao->VertexAttrib[index];
+   assert(index < ARRAY_SIZE(vao->BufferBinding));
    struct gl_vertex_buffer_binding *binding = &vao->BufferBinding[index];
 
    array->Size = size;
    struct gl_vertex_buffer_binding *binding = &vao->BufferBinding[index];
 
    array->Size = size;
@@ -247,6 +249,8 @@ init_array(struct gl_context *ctx,
    array->Integer = GL_FALSE;
    array->Doubles = GL_FALSE;
    array->_ElementSize = size * _mesa_sizeof_type(type);
    array->Integer = GL_FALSE;
    array->Doubles = GL_FALSE;
    array->_ElementSize = size * _mesa_sizeof_type(type);
+   ASSERT_BITFIELD_SIZE(struct gl_array_attributes, BufferBindingIndex,
+                        VERT_ATTRIB_MAX - 1);
    array->BufferBindingIndex = index;
 
    binding->Offset = 0;
    array->BufferBindingIndex = index;
 
    binding->Offset = 0;
index 78132de425450856b93138426e07b6ab6f78ddf6..dccc152ad878e205a38fc67c129fb17c8ff852cf 100644 (file)
@@ -1528,18 +1528,21 @@ struct gl_vertex_array
  */
 struct gl_array_attributes
 {
  */
 struct gl_array_attributes
 {
-   GLint Size;              /**< Components per element (1,2,3,4) */
+   /** Points to client array data. Not used when a VBO is bound */
+   const GLubyte *Ptr;
+   /** Offset of the first element relative to the binding offset */
+   GLuint RelativeOffset;
+   GLshort Stride;          /**< Stride as specified with gl*Pointer() */
    GLenum16 Type;           /**< Datatype: GL_FLOAT, GL_INT, etc */
    GLenum16 Format;         /**< Default: GL_RGBA, but may be GL_BGRA */
    GLenum16 Type;           /**< Datatype: GL_FLOAT, GL_INT, etc */
    GLenum16 Format;         /**< Default: GL_RGBA, but may be GL_BGRA */
-   GLsizei Stride;          /**< Stride as specified with gl*Pointer() */
-   const GLubyte *Ptr;      /**< Points to client array data. Not used when a VBO is bound */
-   GLintptr RelativeOffset; /**< Offset of the first element relative to the binding offset */
    GLboolean Enabled;       /**< Whether the array is enabled */
    GLboolean Enabled;       /**< Whether the array is enabled */
-   GLboolean Normalized;    /**< Fixed-point values are normalized when converted to floats */
-   GLboolean Integer;       /**< Fixed-point values are not converted to floats */
-   GLboolean Doubles;       /**< double precision values are not converted to floats */
-   GLuint _ElementSize;     /**< Size of each element in bytes */
-   GLuint BufferBindingIndex;    /**< Vertex buffer binding */
+   GLubyte Size;            /**< Components per element (1,2,3,4) */
+   unsigned Normalized:1;   /**< Fixed-point values are normalized when converted to floats */
+   unsigned Integer:1;      /**< Fixed-point values are not converted to floats */
+   unsigned Doubles:1;      /**< double precision values are not converted to floats */
+   unsigned _ElementSize:8; /**< Size of each element in bytes */
+   /** Index into gl_vertex_array_object::BufferBinding[] array */
+   unsigned BufferBindingIndex:6;
 };
 
 
 };