[Mesa-dev] [PATCH 4/8] mesa: Track position/generic0 aliasing in the VAO.

Brian Paul brianp at vmware.com
Wed Jan 31 16:55:25 UTC 2018


On 01/31/2018 12:55 AM, Mathias.Froehlich at gmx.net wrote:
> From: Mathias Fröhlich <mathias.froehlich at web.de>
> 
> Since the first material attribute no longer aliases with
> the generic0 attribute, only aliasing between generic0 and
> position is left and entirely dependent on the enabled
> state of the VAO. So introduce a gl_attribute_map_mode
> in the VAO that is used to track how the position
> and the generic 0 attribute alias.
> Provide a static const array that can be used to
> map from vertex program input indices to VERT_ATTRIB_*
> indices. The outer dimension of the array is meant to
> be indexed directly by the new VAO member variable.
> Also provide methods on the VAO to convert bitmasks of
> VERT_BIT's from the VAO numbering to the vertex processing
> inputs numbering.
> 
> Signed-off-by: Mathias Fröhlich <Mathias.Froehlich at web.de>
> ---
>   src/mesa/main/arrayobj.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++
>   src/mesa/main/arrayobj.h |  64 +++++++++++++++++++++++
>   src/mesa/main/enable.c   |   5 ++
>   src/mesa/main/mtypes.h   |  18 +++++++
>   src/mesa/main/varray.c   |  18 +++++--
>   5 files changed, 232 insertions(+), 4 deletions(-)
> 
> diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c
> index 7208f4c534..ae414072ab 100644
> --- a/src/mesa/main/arrayobj.c
> +++ b/src/mesa/main/arrayobj.c
> @@ -54,6 +54,135 @@
>   #include "util/bitscan.h"
>   
>   
> +const unsigned char

How about GLubyte instead?


> +_mesa_vao_attribute_map[_ATTRIBUTE_MAP_MODE_MAX][VERT_ATTRIB_MAX] =
> +{
> +   /* ATTRIBUTE_MAP_MODE_IDENTITY
> +    *
> +    * Grab vertex processing attribute VERT_ATTRIB_POS from
> +    * the VAO attribute VERT_ATTRIB_POS, and grab vertex processing
> +    * attribute VERT_ATTRIB_GENERIC0 from the VAO attribute
> +    * VERT_ATTRIB_GENERIC0.
> +    */
> +   {
> +      VERT_ATTRIB_POS,                 /* VERT_ATTRIB_POS */
> +      VERT_ATTRIB_NORMAL,              /* VERT_ATTRIB_NORMAL */
> +      VERT_ATTRIB_COLOR0,              /* VERT_ATTRIB_COLOR0 */
> +      VERT_ATTRIB_COLOR1,              /* VERT_ATTRIB_COLOR1 */
> +      VERT_ATTRIB_FOG,                 /* VERT_ATTRIB_FOG */
> +      VERT_ATTRIB_COLOR_INDEX,         /* VERT_ATTRIB_COLOR_INDEX */
> +      VERT_ATTRIB_EDGEFLAG,            /* VERT_ATTRIB_EDGEFLAG */
> +      VERT_ATTRIB_TEX0,                /* VERT_ATTRIB_TEX0 */
> +      VERT_ATTRIB_TEX1,                /* VERT_ATTRIB_TEX1 */
> +      VERT_ATTRIB_TEX2,                /* VERT_ATTRIB_TEX2 */
> +      VERT_ATTRIB_TEX3,                /* VERT_ATTRIB_TEX3 */
> +      VERT_ATTRIB_TEX4,                /* VERT_ATTRIB_TEX4 */
> +      VERT_ATTRIB_TEX5,                /* VERT_ATTRIB_TEX5 */
> +      VERT_ATTRIB_TEX6,                /* VERT_ATTRIB_TEX6 */
> +      VERT_ATTRIB_TEX7,                /* VERT_ATTRIB_TEX7 */
> +      VERT_ATTRIB_POINT_SIZE,          /* VERT_ATTRIB_POINT_SIZE */
> +      VERT_ATTRIB_GENERIC0,            /* VERT_ATTRIB_GENERIC0 */
> +      VERT_ATTRIB_GENERIC1,            /* VERT_ATTRIB_GENERIC1 */
> +      VERT_ATTRIB_GENERIC2,            /* VERT_ATTRIB_GENERIC2 */
> +      VERT_ATTRIB_GENERIC3,            /* VERT_ATTRIB_GENERIC3 */
> +      VERT_ATTRIB_GENERIC4,            /* VERT_ATTRIB_GENERIC4 */
> +      VERT_ATTRIB_GENERIC5,            /* VERT_ATTRIB_GENERIC5 */
> +      VERT_ATTRIB_GENERIC6,            /* VERT_ATTRIB_GENERIC6 */
> +      VERT_ATTRIB_GENERIC7,            /* VERT_ATTRIB_GENERIC7 */
> +      VERT_ATTRIB_GENERIC8,            /* VERT_ATTRIB_GENERIC8 */
> +      VERT_ATTRIB_GENERIC9,            /* VERT_ATTRIB_GENERIC9 */
> +      VERT_ATTRIB_GENERIC10,           /* VERT_ATTRIB_GENERIC10 */
> +      VERT_ATTRIB_GENERIC11,           /* VERT_ATTRIB_GENERIC11 */
> +      VERT_ATTRIB_GENERIC12,           /* VERT_ATTRIB_GENERIC12 */
> +      VERT_ATTRIB_GENERIC13,           /* VERT_ATTRIB_GENERIC13 */
> +      VERT_ATTRIB_GENERIC14,           /* VERT_ATTRIB_GENERIC14 */
> +      VERT_ATTRIB_GENERIC15            /* VERT_ATTRIB_GENERIC15 */
> +   },
> +
> +   /* ATTRIBUTE_MAP_MODE_POSITION
> +    *
> +    * Grab vertex processing attribute VERT_ATTRIB_POS as well as
> +    * vertex processing attribute VERT_ATTRIB_GENERIC0 from the
> +    * VAO attribute VERT_ATTRIB_POS.
> +    */
> +   {
> +      VERT_ATTRIB_POS,                 /* VERT_ATTRIB_POS */
> +      VERT_ATTRIB_NORMAL,              /* VERT_ATTRIB_NORMAL */
> +      VERT_ATTRIB_COLOR0,              /* VERT_ATTRIB_COLOR0 */
> +      VERT_ATTRIB_COLOR1,              /* VERT_ATTRIB_COLOR1 */
> +      VERT_ATTRIB_FOG,                 /* VERT_ATTRIB_FOG */
> +      VERT_ATTRIB_COLOR_INDEX,         /* VERT_ATTRIB_COLOR_INDEX */
> +      VERT_ATTRIB_EDGEFLAG,            /* VERT_ATTRIB_EDGEFLAG */
> +      VERT_ATTRIB_TEX0,                /* VERT_ATTRIB_TEX0 */
> +      VERT_ATTRIB_TEX1,                /* VERT_ATTRIB_TEX1 */
> +      VERT_ATTRIB_TEX2,                /* VERT_ATTRIB_TEX2 */
> +      VERT_ATTRIB_TEX3,                /* VERT_ATTRIB_TEX3 */
> +      VERT_ATTRIB_TEX4,                /* VERT_ATTRIB_TEX4 */
> +      VERT_ATTRIB_TEX5,                /* VERT_ATTRIB_TEX5 */
> +      VERT_ATTRIB_TEX6,                /* VERT_ATTRIB_TEX6 */
> +      VERT_ATTRIB_TEX7,                /* VERT_ATTRIB_TEX7 */
> +      VERT_ATTRIB_POINT_SIZE,          /* VERT_ATTRIB_POINT_SIZE */
> +      VERT_ATTRIB_POS,                 /* VERT_ATTRIB_GENERIC0 */
> +      VERT_ATTRIB_GENERIC1,            /* VERT_ATTRIB_GENERIC1 */
> +      VERT_ATTRIB_GENERIC2,            /* VERT_ATTRIB_GENERIC2 */
> +      VERT_ATTRIB_GENERIC3,            /* VERT_ATTRIB_GENERIC3 */
> +      VERT_ATTRIB_GENERIC4,            /* VERT_ATTRIB_GENERIC4 */
> +      VERT_ATTRIB_GENERIC5,            /* VERT_ATTRIB_GENERIC5 */
> +      VERT_ATTRIB_GENERIC6,            /* VERT_ATTRIB_GENERIC6 */
> +      VERT_ATTRIB_GENERIC7,            /* VERT_ATTRIB_GENERIC7 */
> +      VERT_ATTRIB_GENERIC8,            /* VERT_ATTRIB_GENERIC8 */
> +      VERT_ATTRIB_GENERIC9,            /* VERT_ATTRIB_GENERIC9 */
> +      VERT_ATTRIB_GENERIC10,           /* VERT_ATTRIB_GENERIC10 */
> +      VERT_ATTRIB_GENERIC11,           /* VERT_ATTRIB_GENERIC11 */
> +      VERT_ATTRIB_GENERIC12,           /* VERT_ATTRIB_GENERIC12 */
> +      VERT_ATTRIB_GENERIC13,           /* VERT_ATTRIB_GENERIC13 */
> +      VERT_ATTRIB_GENERIC14,           /* VERT_ATTRIB_GENERIC14 */
> +      VERT_ATTRIB_GENERIC15            /* VERT_ATTRIB_GENERIC15 */
> +   },
> +
> +   /* ATTRIBUTE_MAP_MODE_GENERIC0
> +    *
> +    * Grab vertex processing attribute VERT_ATTRIB_POS as well as
> +    * vertex processing attribute VERT_ATTRIB_GENERIC0 from the
> +    * VAO attribute VERT_ATTRIB_GENERIC0.
> +    */
> +   {
> +      VERT_ATTRIB_GENERIC0,            /* VERT_ATTRIB_POS */
> +      VERT_ATTRIB_NORMAL,              /* VERT_ATTRIB_NORMAL */
> +      VERT_ATTRIB_COLOR0,              /* VERT_ATTRIB_COLOR0 */
> +      VERT_ATTRIB_COLOR1,              /* VERT_ATTRIB_COLOR1 */
> +      VERT_ATTRIB_FOG,                 /* VERT_ATTRIB_FOG */
> +      VERT_ATTRIB_COLOR_INDEX,         /* VERT_ATTRIB_COLOR_INDEX */
> +      VERT_ATTRIB_EDGEFLAG,            /* VERT_ATTRIB_EDGEFLAG */
> +      VERT_ATTRIB_TEX0,                /* VERT_ATTRIB_TEX0 */
> +      VERT_ATTRIB_TEX1,                /* VERT_ATTRIB_TEX1 */
> +      VERT_ATTRIB_TEX2,                /* VERT_ATTRIB_TEX2 */
> +      VERT_ATTRIB_TEX3,                /* VERT_ATTRIB_TEX3 */
> +      VERT_ATTRIB_TEX4,                /* VERT_ATTRIB_TEX4 */
> +      VERT_ATTRIB_TEX5,                /* VERT_ATTRIB_TEX5 */
> +      VERT_ATTRIB_TEX6,                /* VERT_ATTRIB_TEX6 */
> +      VERT_ATTRIB_TEX7,                /* VERT_ATTRIB_TEX7 */
> +      VERT_ATTRIB_POINT_SIZE,          /* VERT_ATTRIB_POINT_SIZE */
> +      VERT_ATTRIB_GENERIC0,            /* VERT_ATTRIB_GENERIC0 */
> +      VERT_ATTRIB_GENERIC1,            /* VERT_ATTRIB_GENERIC1 */
> +      VERT_ATTRIB_GENERIC2,            /* VERT_ATTRIB_GENERIC2 */
> +      VERT_ATTRIB_GENERIC3,            /* VERT_ATTRIB_GENERIC3 */
> +      VERT_ATTRIB_GENERIC4,            /* VERT_ATTRIB_GENERIC4 */
> +      VERT_ATTRIB_GENERIC5,            /* VERT_ATTRIB_GENERIC5 */
> +      VERT_ATTRIB_GENERIC6,            /* VERT_ATTRIB_GENERIC6 */
> +      VERT_ATTRIB_GENERIC7,            /* VERT_ATTRIB_GENERIC7 */
> +      VERT_ATTRIB_GENERIC8,            /* VERT_ATTRIB_GENERIC8 */
> +      VERT_ATTRIB_GENERIC9,            /* VERT_ATTRIB_GENERIC9 */
> +      VERT_ATTRIB_GENERIC10,           /* VERT_ATTRIB_GENERIC10 */
> +      VERT_ATTRIB_GENERIC11,           /* VERT_ATTRIB_GENERIC11 */
> +      VERT_ATTRIB_GENERIC12,           /* VERT_ATTRIB_GENERIC12 */
> +      VERT_ATTRIB_GENERIC13,           /* VERT_ATTRIB_GENERIC13 */
> +      VERT_ATTRIB_GENERIC14,           /* VERT_ATTRIB_GENERIC14 */
> +      VERT_ATTRIB_GENERIC15            /* VERT_ATTRIB_GENERIC15 */
> +   }
> +};
> +
> +
>   /**
>    * Look up the array object for the given ID.
>    *
> @@ -305,6 +434,8 @@ _mesa_initialize_vao(struct gl_context *ctx,
>         }
>      }
>   
> +   vao->_AttributeMapMode = ATTRIBUTE_MAP_MODE_IDENTITY;
> +
>      _mesa_reference_buffer_object(ctx, &vao->IndexBufferObj,
>                                    ctx->Shared->NullBufferObj);
>   }
> diff --git a/src/mesa/main/arrayobj.h b/src/mesa/main/arrayobj.h
> index ff26157c79..d538ddf534 100644
> --- a/src/mesa/main/arrayobj.h
> +++ b/src/mesa/main/arrayobj.h
> @@ -89,6 +89,70 @@ _mesa_all_varyings_in_vbos(const struct gl_vertex_array_object *vao);
>   extern bool
>   _mesa_all_buffers_are_unmapped(const struct gl_vertex_array_object *vao);
>   
> +
> +/* Array to apply the position/generic0 aliasing map to
> + * an attribute value used in vertex processing inputs to an attribute
> + * as they appear in the vao.
> + */
> +extern const unsigned char
> +_mesa_vao_attribute_map[_ATTRIBUTE_MAP_MODE_MAX][VERT_ATTRIB_MAX];
> +
> +/* Depending on the position and generic0 attributes enable flags select
> + * the one that is used for both attributes.
> + * The generic0 attribute takes precedence.
> + */
> +static inline void
> +_mesa_update_attribute_map_mode(const struct gl_context *ctx,
> +                                struct gl_vertex_array_object *vao)
> +{
> +   /* There is no need to change the mapping away from the
> +    * identity mapping if we are not in compat mode.
> +    */
> +   if (ctx->API != API_OPENGL_COMPAT)
> +      return;
> +   /* The generic0 attribute superseeds the position attribute */
> +   const GLbitfield enabled = vao->_Enabled;
> +   if (enabled & VERT_BIT_GENERIC0)
> +      vao->_AttributeMapMode = ATTRIBUTE_MAP_MODE_GENERIC0;
> +   else if (enabled & VERT_BIT_POS)
> +      vao->_AttributeMapMode = ATTRIBUTE_MAP_MODE_POSITION;
> +   else
> +      vao->_AttributeMapMode = ATTRIBUTE_MAP_MODE_IDENTITY;
> +}
> +
> +/* Apply the position/generic0 aliasing map to a bitfield from the vao.
> + * Use for example to convert Applicable gl_vertex_array_object::_Enabled
> + * or gl_vertex_buffer_binding::_VertexBinding from the vao numbering to
> + * the numbering used with vertex processing inputs.
> + */
> +static inline GLbitfield
> +_mesa_vao_enable_to_vp_inputs(gl_attribute_map_mode mode, GLbitfield enabled)
> +{
> +   switch (mode) {
> +   case ATTRIBUTE_MAP_MODE_IDENTITY:
> +      return enabled;
> +   case ATTRIBUTE_MAP_MODE_POSITION:

Add some comments?

          /* copy VERT_ATTRIB_POS enable bit into GENERIC0 position */

> +      return (enabled & ~VERT_BIT_GENERIC0)
> +         | ((enabled & VERT_BIT_POS) << VERT_ATTRIB_GENERIC0);
> +   case ATTRIBUTE_MAP_MODE_GENERIC0:
          /* copy VERT_ATTRIB_GENERIC0 enable bit into the POS position */

> +      return (enabled & ~VERT_BIT_POS)
> +         | ((enabled & VERT_BIT_GENERIC0) >> VERT_ATTRIB_GENERIC0);
> +   default:
> +      return 0;
> +   }
> +}
> +
> +/* Return the vp_inputs enabled bitmask after application of
> + * the position/generic0 aliasing map.
> + */
> +static inline GLbitfield
> +_mesa_get_vao_vp_inputs(const struct gl_vertex_array_object *vao)
> +{
> +   const gl_attribute_map_mode mode = vao->_AttributeMapMode;
> +   return _mesa_vao_enable_to_vp_inputs(mode, vao->_Enabled);
> +}

Could you put two blank lines between functions and use this style for 
the function comments?

/**
  * comment
  */


> +
> +
>   /*
>    * API functions
>    */
> diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c
> index 0b3de5220d..451a9c918f 100644
> --- a/src/mesa/main/enable.c
> +++ b/src/mesa/main/enable.c
> @@ -29,6 +29,7 @@
>   
>   
>   #include "glheader.h"
> +#include "arrayobj.h"
>   #include "blend.h"
>   #include "clip.h"
>   #include "context.h"
> @@ -138,6 +139,10 @@ client_state(struct gl_context *ctx, GLenum cap, GLboolean state)
>   
>      vao->NewArrays |= vert_attrib_bit;
>   
> +   /* Something got en/disabled, so update the map mode */
> +   if (vert_attrib_bit & (VERT_BIT_POS|VERT_BIT_GENERIC0))
> +      _mesa_update_attribute_map_mode(ctx, vao);
> +
>      if (ctx->Driver.Enable) {
>         ctx->Driver.Enable( ctx, cap, state );
>      }
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> index a1285fe4d1..675da05f2f 100644
> --- a/src/mesa/main/mtypes.h
> +++ b/src/mesa/main/mtypes.h
> @@ -1512,6 +1512,21 @@ struct gl_vertex_array
>   };
>   
>   
> +/**
> + * Enum for defining the mapping for the position/generic0 attribute.
> + *
> + * Do not change the order of the values as these are used as
> + * array indices.
> + */
> +typedef enum
> +{
> +   ATTRIBUTE_MAP_MODE_IDENTITY, /**< 1:1 mapping */
> +   ATTRIBUTE_MAP_MODE_POSITION, /**< get position and generic0 from position */
> +   ATTRIBUTE_MAP_MODE_GENERIC0, /**< get position and generic0 from generic0 */
> +   _ATTRIBUTE_MAP_MODE_MAX      /**< for sizing arrays */

I don't think the _ prefix on the last value is needed.


> +} gl_attribute_map_mode;
> +
> +
>   /**
>    * Attributes to describe a vertex array.
>    *
> @@ -1598,6 +1613,9 @@ struct gl_vertex_array_object
>      /** Mask of VERT_BIT_* values indicating which arrays are enabled */
>      GLbitfield _Enabled;
>   
> +   /** Denotes the way the position/generic0 attribute is mapped */
> +   gl_attribute_map_mode _AttributeMapMode;
> +
>      /** Mask of VERT_BIT_* values indicating changed/dirty arrays */
>      GLbitfield NewArrays;
>   
> diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c
> index bc0afa6bcf..81b8fbe8ca 100644
> --- a/src/mesa/main/varray.c
> +++ b/src/mesa/main/varray.c
> @@ -1071,8 +1071,13 @@ _mesa_enable_vertex_array_attrib(struct gl_context *ctx,
>         /* was disabled, now being enabled */
>         FLUSH_VERTICES(ctx, _NEW_ARRAY);
>         vao->VertexAttrib[attrib].Enabled = GL_TRUE;
> -      vao->_Enabled |= VERT_BIT(attrib);
> -      vao->NewArrays |= VERT_BIT(attrib);
> +      const GLbitfield array_bit = VERT_BIT(attrib);
> +      vao->_Enabled |= array_bit;
> +      vao->NewArrays |= array_bit;
> +
> +      /* Update the map mode if needed */
> +      if (array_bit & (VERT_BIT_POS|VERT_BIT_GENERIC0))
> +         _mesa_update_attribute_map_mode(ctx, vao);
>      }
>   }
>   
> @@ -1150,8 +1155,13 @@ disable_vertex_array_attrib(struct gl_context *ctx,
>         /* was enabled, now being disabled */
>         FLUSH_VERTICES(ctx, _NEW_ARRAY);
>         vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_FALSE;
> -      vao->_Enabled &= ~VERT_BIT_GENERIC(index);
> -      vao->NewArrays |= VERT_BIT_GENERIC(index);
> +      const GLbitfield array_bit = VERT_BIT_GENERIC(index);
> +      vao->_Enabled &= ~array_bit;
> +      vao->NewArrays |= array_bit;
> +
> +      /* Update the map mode if needed */
> +      if (array_bit & (VERT_BIT_POS|VERT_BIT_GENERIC0))
> +         _mesa_update_attribute_map_mode(ctx, vao);
>      }
>   }
>   
> 



More information about the mesa-dev mailing list