Re: [Mesa-dev] [PATCH 29/29] vbo: Use a bitmask to track the active arrays in vbo_save*.

2016-06-22 Thread Mathias Fröhlich
On Monday, June 20, 2016 11:42:19 Mark Janes wrote:
> Mathias Fröhlich  writes:
> 
> > On Monday, June 20, 2016 10:33:42 Mark Janes wrote:
> >> mathias.froehl...@gmx.net writes:
> >> 
> >> > From: Mathias Fröhlich 
> >> >
> >> > The use of a bitmask makes functions iterating only active
> >> > attributes less visible in profiles.
> >> >
> >> > Signed-off-by: Mathias Fröhlich 
> >> > ---
> >> >  src/mesa/vbo/vbo_save.h  |  2 ++
> >> >  src/mesa/vbo/vbo_save_api.c  | 70 
> >> > ++--
> >> >  src/mesa/vbo/vbo_save_draw.c | 55 ++
> >> >  3 files changed, 72 insertions(+), 55 deletions(-)
> >> >
> >> > diff --git a/src/mesa/vbo/vbo_save.h b/src/mesa/vbo/vbo_save.h
> >> > index 8032db8..e3b86bc 100644
> >> > --- a/src/mesa/vbo/vbo_save.h
> >> > +++ b/src/mesa/vbo/vbo_save.h
> >> > @@ -61,6 +61,7 @@ struct vbo_save_copied_vtx {
> >> >   * compiled using the fallback opcode mechanism provided by dlist.c.
> >> >   */
> >> >  struct vbo_save_vertex_list {
> >> > +   GLbitfield64 enabled;/**< mask of enabled vbo arrays. */
> >> > GLubyte attrsz[VBO_ATTRIB_MAX];
> >> > GLenum attrtype[VBO_ATTRIB_MAX];
> >> > GLuint vertex_size;  /**< size in GLfloats */
> >> > @@ -126,6 +127,7 @@ struct vbo_save_context {
> >> > struct gl_client_array arrays[VBO_ATTRIB_MAX];
> >> > const struct gl_client_array *inputs[VBO_ATTRIB_MAX];
> >> >  
> >> > +   GLbitfield64 enabled;/**< mask of enabled vbo arrays. */
> >> > GLubyte attrsz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
> >> > GLenum attrtype[VBO_ATTRIB_MAX];  /**< GL_FLOAT, GL_INT, etc */
> >> > GLubyte active_sz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
> >> > diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
> >> > index 97a1dfd..b178060 100644
> >> > --- a/src/mesa/vbo/vbo_save_api.c
> >> > +++ b/src/mesa/vbo/vbo_save_api.c
> >> > @@ -429,6 +429,7 @@ _save_compile_vertex_list(struct gl_context *ctx)
> >> >  
> >> > /* Duplicate our template, increment refcounts to the storage 
> >> > structs:
> >> >  */
> >> > +   node->enabled = save->enabled;
> >> > memcpy(node->attrsz, save->attrsz, sizeof(node->attrsz));
> >> > memcpy(node->attrtype, save->attrtype, sizeof(node->attrtype));
> >> > node->vertex_size = save->vertex_size;
> >> > @@ -624,14 +625,16 @@ static void
> >> >  _save_copy_to_current(struct gl_context *ctx)
> >> >  {
> >> > struct vbo_save_context *save = _context(ctx)->save;
> >> > -   GLuint i;
> >> > +   GLbitfield64 enabled = save->enabled & 
> >> > (~BITFIELD64_BIT(VBO_ATTRIB_POS));
> >> >  
> >> > -   for (i = VBO_ATTRIB_POS + 1; i < VBO_ATTRIB_MAX; i++) {
> >> > -  if (save->attrsz[i]) {
> >> > - save->currentsz[i][0] = save->attrsz[i];
> >> > - COPY_CLEAN_4V_TYPE_AS_UNION(save->current[i], save->attrsz[i],
> >> > - save->attrptr[i], 
> >> > save->attrtype[i]);
> >> > -  }
> >> > +   while (enabled) {
> >> > +  int i = ffsll(enabled) - 1;
> >> > +  enabled ^= BITFIELD64_BIT(i);
> >> > +  assert(save->attrsz[i]);
> >> > +
> >> > +  save->currentsz[i][0] = save->attrsz[i];
> >> > +  COPY_CLEAN_4V_TYPE_AS_UNION(save->current[i], save->attrsz[i],
> >> > +  save->attrptr[i], save->attrtype[i]);
> >> > }
> >> >  }
> >> >  
> >> > @@ -640,9 +643,12 @@ static void
> >> >  _save_copy_from_current(struct gl_context *ctx)
> >> >  {
> >> > struct vbo_save_context *save = _context(ctx)->save;
> >> > -   GLint i;
> >> > +   GLbitfield64 enabled = save->enabled & 
> >> > (~BITFIELD64_BIT(VBO_ATTRIB_POS));
> >> > +
> >> > +   while (enabled) {
> >> > +  int i = ffsll(enabled) - 1;
> >> > +  enabled ^= BITFIELD64_BIT(i);
> >> >  
> >> > -   for (i = VBO_ATTRIB_POS + 1; i < VBO_ATTRIB_MAX; i++) {
> >> >switch (save->attrsz[i]) {
> >> >case 4:
> >> >   save->attrptr[i][3] = save->current[i][3];
> >> > @@ -652,7 +658,9 @@ _save_copy_from_current(struct gl_context *ctx)
> >> >   save->attrptr[i][1] = save->current[i][1];
> >> >case 1:
> >> >   save->attrptr[i][0] = save->current[i][0];
> >> > + break;
> >> >case 0:
> >> > + assert(0);
> >> >   break;
> >> >}
> >> > }
> >> > @@ -691,6 +699,7 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint 
> >> > attr, GLuint newsz)
> >> >  */
> >> > oldsz = save->attrsz[attr];
> >> > save->attrsz[attr] = newsz;
> >> > +   save->enabled |= BITFIELD64_BIT(attr);
> >> >  
> >> > save->vertex_size += newsz - oldsz;
> >> > save->max_vert = ((VBO_SAVE_BUFFER_SIZE - save->vertex_store->used) /
> >> > @@ -723,7 +732,6 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint 
> >> > attr, GLuint newsz)
> >> > if (save->copied.nr) {
> >> >const fi_type *data = save->copied.buffer;
> >> 

Re: [Mesa-dev] [PATCH 29/29] vbo: Use a bitmask to track the active arrays in vbo_save*.

2016-06-20 Thread Mark Janes
Mathias Fröhlich  writes:

> On Monday, June 20, 2016 10:33:42 Mark Janes wrote:
>> mathias.froehl...@gmx.net writes:
>> 
>> > From: Mathias Fröhlich 
>> >
>> > The use of a bitmask makes functions iterating only active
>> > attributes less visible in profiles.
>> >
>> > Signed-off-by: Mathias Fröhlich 
>> > ---
>> >  src/mesa/vbo/vbo_save.h  |  2 ++
>> >  src/mesa/vbo/vbo_save_api.c  | 70 
>> > ++--
>> >  src/mesa/vbo/vbo_save_draw.c | 55 ++
>> >  3 files changed, 72 insertions(+), 55 deletions(-)
>> >
>> > diff --git a/src/mesa/vbo/vbo_save.h b/src/mesa/vbo/vbo_save.h
>> > index 8032db8..e3b86bc 100644
>> > --- a/src/mesa/vbo/vbo_save.h
>> > +++ b/src/mesa/vbo/vbo_save.h
>> > @@ -61,6 +61,7 @@ struct vbo_save_copied_vtx {
>> >   * compiled using the fallback opcode mechanism provided by dlist.c.
>> >   */
>> >  struct vbo_save_vertex_list {
>> > +   GLbitfield64 enabled;/**< mask of enabled vbo arrays. */
>> > GLubyte attrsz[VBO_ATTRIB_MAX];
>> > GLenum attrtype[VBO_ATTRIB_MAX];
>> > GLuint vertex_size;  /**< size in GLfloats */
>> > @@ -126,6 +127,7 @@ struct vbo_save_context {
>> > struct gl_client_array arrays[VBO_ATTRIB_MAX];
>> > const struct gl_client_array *inputs[VBO_ATTRIB_MAX];
>> >  
>> > +   GLbitfield64 enabled;/**< mask of enabled vbo arrays. */
>> > GLubyte attrsz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
>> > GLenum attrtype[VBO_ATTRIB_MAX];  /**< GL_FLOAT, GL_INT, etc */
>> > GLubyte active_sz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
>> > diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
>> > index 97a1dfd..b178060 100644
>> > --- a/src/mesa/vbo/vbo_save_api.c
>> > +++ b/src/mesa/vbo/vbo_save_api.c
>> > @@ -429,6 +429,7 @@ _save_compile_vertex_list(struct gl_context *ctx)
>> >  
>> > /* Duplicate our template, increment refcounts to the storage structs:
>> >  */
>> > +   node->enabled = save->enabled;
>> > memcpy(node->attrsz, save->attrsz, sizeof(node->attrsz));
>> > memcpy(node->attrtype, save->attrtype, sizeof(node->attrtype));
>> > node->vertex_size = save->vertex_size;
>> > @@ -624,14 +625,16 @@ static void
>> >  _save_copy_to_current(struct gl_context *ctx)
>> >  {
>> > struct vbo_save_context *save = _context(ctx)->save;
>> > -   GLuint i;
>> > +   GLbitfield64 enabled = save->enabled & 
>> > (~BITFIELD64_BIT(VBO_ATTRIB_POS));
>> >  
>> > -   for (i = VBO_ATTRIB_POS + 1; i < VBO_ATTRIB_MAX; i++) {
>> > -  if (save->attrsz[i]) {
>> > - save->currentsz[i][0] = save->attrsz[i];
>> > - COPY_CLEAN_4V_TYPE_AS_UNION(save->current[i], save->attrsz[i],
>> > - save->attrptr[i], save->attrtype[i]);
>> > -  }
>> > +   while (enabled) {
>> > +  int i = ffsll(enabled) - 1;
>> > +  enabled ^= BITFIELD64_BIT(i);
>> > +  assert(save->attrsz[i]);
>> > +
>> > +  save->currentsz[i][0] = save->attrsz[i];
>> > +  COPY_CLEAN_4V_TYPE_AS_UNION(save->current[i], save->attrsz[i],
>> > +  save->attrptr[i], save->attrtype[i]);
>> > }
>> >  }
>> >  
>> > @@ -640,9 +643,12 @@ static void
>> >  _save_copy_from_current(struct gl_context *ctx)
>> >  {
>> > struct vbo_save_context *save = _context(ctx)->save;
>> > -   GLint i;
>> > +   GLbitfield64 enabled = save->enabled & 
>> > (~BITFIELD64_BIT(VBO_ATTRIB_POS));
>> > +
>> > +   while (enabled) {
>> > +  int i = ffsll(enabled) - 1;
>> > +  enabled ^= BITFIELD64_BIT(i);
>> >  
>> > -   for (i = VBO_ATTRIB_POS + 1; i < VBO_ATTRIB_MAX; i++) {
>> >switch (save->attrsz[i]) {
>> >case 4:
>> >   save->attrptr[i][3] = save->current[i][3];
>> > @@ -652,7 +658,9 @@ _save_copy_from_current(struct gl_context *ctx)
>> >   save->attrptr[i][1] = save->current[i][1];
>> >case 1:
>> >   save->attrptr[i][0] = save->current[i][0];
>> > + break;
>> >case 0:
>> > + assert(0);
>> >   break;
>> >}
>> > }
>> > @@ -691,6 +699,7 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint 
>> > attr, GLuint newsz)
>> >  */
>> > oldsz = save->attrsz[attr];
>> > save->attrsz[attr] = newsz;
>> > +   save->enabled |= BITFIELD64_BIT(attr);
>> >  
>> > save->vertex_size += newsz - oldsz;
>> > save->max_vert = ((VBO_SAVE_BUFFER_SIZE - save->vertex_store->used) /
>> > @@ -723,7 +732,6 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint 
>> > attr, GLuint newsz)
>> > if (save->copied.nr) {
>> >const fi_type *data = save->copied.buffer;
>> >fi_type *dest = save->buffer;
>> > -  GLuint j;
>> >  
>> >/* Need to note this and fix up at runtime (or loopback):
>> > */
>> > @@ -733,27 +741,29 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint 
>> > attr, GLuint newsz)
>> >}
>> >  
>> >for 

Re: [Mesa-dev] [PATCH 29/29] vbo: Use a bitmask to track the active arrays in vbo_save*.

2016-06-20 Thread Mathias Fröhlich
On Monday, June 20, 2016 10:33:42 Mark Janes wrote:
> mathias.froehl...@gmx.net writes:
> 
> > From: Mathias Fröhlich 
> >
> > The use of a bitmask makes functions iterating only active
> > attributes less visible in profiles.
> >
> > Signed-off-by: Mathias Fröhlich 
> > ---
> >  src/mesa/vbo/vbo_save.h  |  2 ++
> >  src/mesa/vbo/vbo_save_api.c  | 70 
> > ++--
> >  src/mesa/vbo/vbo_save_draw.c | 55 ++
> >  3 files changed, 72 insertions(+), 55 deletions(-)
> >
> > diff --git a/src/mesa/vbo/vbo_save.h b/src/mesa/vbo/vbo_save.h
> > index 8032db8..e3b86bc 100644
> > --- a/src/mesa/vbo/vbo_save.h
> > +++ b/src/mesa/vbo/vbo_save.h
> > @@ -61,6 +61,7 @@ struct vbo_save_copied_vtx {
> >   * compiled using the fallback opcode mechanism provided by dlist.c.
> >   */
> >  struct vbo_save_vertex_list {
> > +   GLbitfield64 enabled;/**< mask of enabled vbo arrays. */
> > GLubyte attrsz[VBO_ATTRIB_MAX];
> > GLenum attrtype[VBO_ATTRIB_MAX];
> > GLuint vertex_size;  /**< size in GLfloats */
> > @@ -126,6 +127,7 @@ struct vbo_save_context {
> > struct gl_client_array arrays[VBO_ATTRIB_MAX];
> > const struct gl_client_array *inputs[VBO_ATTRIB_MAX];
> >  
> > +   GLbitfield64 enabled;/**< mask of enabled vbo arrays. */
> > GLubyte attrsz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
> > GLenum attrtype[VBO_ATTRIB_MAX];  /**< GL_FLOAT, GL_INT, etc */
> > GLubyte active_sz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
> > diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
> > index 97a1dfd..b178060 100644
> > --- a/src/mesa/vbo/vbo_save_api.c
> > +++ b/src/mesa/vbo/vbo_save_api.c
> > @@ -429,6 +429,7 @@ _save_compile_vertex_list(struct gl_context *ctx)
> >  
> > /* Duplicate our template, increment refcounts to the storage structs:
> >  */
> > +   node->enabled = save->enabled;
> > memcpy(node->attrsz, save->attrsz, sizeof(node->attrsz));
> > memcpy(node->attrtype, save->attrtype, sizeof(node->attrtype));
> > node->vertex_size = save->vertex_size;
> > @@ -624,14 +625,16 @@ static void
> >  _save_copy_to_current(struct gl_context *ctx)
> >  {
> > struct vbo_save_context *save = _context(ctx)->save;
> > -   GLuint i;
> > +   GLbitfield64 enabled = save->enabled & 
> > (~BITFIELD64_BIT(VBO_ATTRIB_POS));
> >  
> > -   for (i = VBO_ATTRIB_POS + 1; i < VBO_ATTRIB_MAX; i++) {
> > -  if (save->attrsz[i]) {
> > - save->currentsz[i][0] = save->attrsz[i];
> > - COPY_CLEAN_4V_TYPE_AS_UNION(save->current[i], save->attrsz[i],
> > - save->attrptr[i], save->attrtype[i]);
> > -  }
> > +   while (enabled) {
> > +  int i = ffsll(enabled) - 1;
> > +  enabled ^= BITFIELD64_BIT(i);
> > +  assert(save->attrsz[i]);
> > +
> > +  save->currentsz[i][0] = save->attrsz[i];
> > +  COPY_CLEAN_4V_TYPE_AS_UNION(save->current[i], save->attrsz[i],
> > +  save->attrptr[i], save->attrtype[i]);
> > }
> >  }
> >  
> > @@ -640,9 +643,12 @@ static void
> >  _save_copy_from_current(struct gl_context *ctx)
> >  {
> > struct vbo_save_context *save = _context(ctx)->save;
> > -   GLint i;
> > +   GLbitfield64 enabled = save->enabled & 
> > (~BITFIELD64_BIT(VBO_ATTRIB_POS));
> > +
> > +   while (enabled) {
> > +  int i = ffsll(enabled) - 1;
> > +  enabled ^= BITFIELD64_BIT(i);
> >  
> > -   for (i = VBO_ATTRIB_POS + 1; i < VBO_ATTRIB_MAX; i++) {
> >switch (save->attrsz[i]) {
> >case 4:
> >   save->attrptr[i][3] = save->current[i][3];
> > @@ -652,7 +658,9 @@ _save_copy_from_current(struct gl_context *ctx)
> >   save->attrptr[i][1] = save->current[i][1];
> >case 1:
> >   save->attrptr[i][0] = save->current[i][0];
> > + break;
> >case 0:
> > + assert(0);
> >   break;
> >}
> > }
> > @@ -691,6 +699,7 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint 
> > attr, GLuint newsz)
> >  */
> > oldsz = save->attrsz[attr];
> > save->attrsz[attr] = newsz;
> > +   save->enabled |= BITFIELD64_BIT(attr);
> >  
> > save->vertex_size += newsz - oldsz;
> > save->max_vert = ((VBO_SAVE_BUFFER_SIZE - save->vertex_store->used) /
> > @@ -723,7 +732,6 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint 
> > attr, GLuint newsz)
> > if (save->copied.nr) {
> >const fi_type *data = save->copied.buffer;
> >fi_type *dest = save->buffer;
> > -  GLuint j;
> >  
> >/* Need to note this and fix up at runtime (or loopback):
> > */
> > @@ -733,27 +741,29 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint 
> > attr, GLuint newsz)
> >}
> >  
> >for (i = 0; i < save->copied.nr; i++) {
> > - for (j = 0; j < VBO_ATTRIB_MAX; j++) {
> > -if (save->attrsz[j]) {
> > -   if (j == attr) {
> > -

Re: [Mesa-dev] [PATCH 29/29] vbo: Use a bitmask to track the active arrays in vbo_save*.

2016-06-20 Thread Mark Janes
mathias.froehl...@gmx.net writes:

> From: Mathias Fröhlich 
>
> The use of a bitmask makes functions iterating only active
> attributes less visible in profiles.
>
> Signed-off-by: Mathias Fröhlich 
> ---
>  src/mesa/vbo/vbo_save.h  |  2 ++
>  src/mesa/vbo/vbo_save_api.c  | 70 
> ++--
>  src/mesa/vbo/vbo_save_draw.c | 55 ++
>  3 files changed, 72 insertions(+), 55 deletions(-)
>
> diff --git a/src/mesa/vbo/vbo_save.h b/src/mesa/vbo/vbo_save.h
> index 8032db8..e3b86bc 100644
> --- a/src/mesa/vbo/vbo_save.h
> +++ b/src/mesa/vbo/vbo_save.h
> @@ -61,6 +61,7 @@ struct vbo_save_copied_vtx {
>   * compiled using the fallback opcode mechanism provided by dlist.c.
>   */
>  struct vbo_save_vertex_list {
> +   GLbitfield64 enabled;/**< mask of enabled vbo arrays. */
> GLubyte attrsz[VBO_ATTRIB_MAX];
> GLenum attrtype[VBO_ATTRIB_MAX];
> GLuint vertex_size;  /**< size in GLfloats */
> @@ -126,6 +127,7 @@ struct vbo_save_context {
> struct gl_client_array arrays[VBO_ATTRIB_MAX];
> const struct gl_client_array *inputs[VBO_ATTRIB_MAX];
>  
> +   GLbitfield64 enabled;/**< mask of enabled vbo arrays. */
> GLubyte attrsz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
> GLenum attrtype[VBO_ATTRIB_MAX];  /**< GL_FLOAT, GL_INT, etc */
> GLubyte active_sz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
> diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
> index 97a1dfd..b178060 100644
> --- a/src/mesa/vbo/vbo_save_api.c
> +++ b/src/mesa/vbo/vbo_save_api.c
> @@ -429,6 +429,7 @@ _save_compile_vertex_list(struct gl_context *ctx)
>  
> /* Duplicate our template, increment refcounts to the storage structs:
>  */
> +   node->enabled = save->enabled;
> memcpy(node->attrsz, save->attrsz, sizeof(node->attrsz));
> memcpy(node->attrtype, save->attrtype, sizeof(node->attrtype));
> node->vertex_size = save->vertex_size;
> @@ -624,14 +625,16 @@ static void
>  _save_copy_to_current(struct gl_context *ctx)
>  {
> struct vbo_save_context *save = _context(ctx)->save;
> -   GLuint i;
> +   GLbitfield64 enabled = save->enabled & (~BITFIELD64_BIT(VBO_ATTRIB_POS));
>  
> -   for (i = VBO_ATTRIB_POS + 1; i < VBO_ATTRIB_MAX; i++) {
> -  if (save->attrsz[i]) {
> - save->currentsz[i][0] = save->attrsz[i];
> - COPY_CLEAN_4V_TYPE_AS_UNION(save->current[i], save->attrsz[i],
> - save->attrptr[i], save->attrtype[i]);
> -  }
> +   while (enabled) {
> +  int i = ffsll(enabled) - 1;
> +  enabled ^= BITFIELD64_BIT(i);
> +  assert(save->attrsz[i]);
> +
> +  save->currentsz[i][0] = save->attrsz[i];
> +  COPY_CLEAN_4V_TYPE_AS_UNION(save->current[i], save->attrsz[i],
> +  save->attrptr[i], save->attrtype[i]);
> }
>  }
>  
> @@ -640,9 +643,12 @@ static void
>  _save_copy_from_current(struct gl_context *ctx)
>  {
> struct vbo_save_context *save = _context(ctx)->save;
> -   GLint i;
> +   GLbitfield64 enabled = save->enabled & (~BITFIELD64_BIT(VBO_ATTRIB_POS));
> +
> +   while (enabled) {
> +  int i = ffsll(enabled) - 1;
> +  enabled ^= BITFIELD64_BIT(i);
>  
> -   for (i = VBO_ATTRIB_POS + 1; i < VBO_ATTRIB_MAX; i++) {
>switch (save->attrsz[i]) {
>case 4:
>   save->attrptr[i][3] = save->current[i][3];
> @@ -652,7 +658,9 @@ _save_copy_from_current(struct gl_context *ctx)
>   save->attrptr[i][1] = save->current[i][1];
>case 1:
>   save->attrptr[i][0] = save->current[i][0];
> + break;
>case 0:
> + assert(0);
>   break;
>}
> }
> @@ -691,6 +699,7 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint attr, 
> GLuint newsz)
>  */
> oldsz = save->attrsz[attr];
> save->attrsz[attr] = newsz;
> +   save->enabled |= BITFIELD64_BIT(attr);
>  
> save->vertex_size += newsz - oldsz;
> save->max_vert = ((VBO_SAVE_BUFFER_SIZE - save->vertex_store->used) /
> @@ -723,7 +732,6 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint attr, 
> GLuint newsz)
> if (save->copied.nr) {
>const fi_type *data = save->copied.buffer;
>fi_type *dest = save->buffer;
> -  GLuint j;
>  
>/* Need to note this and fix up at runtime (or loopback):
> */
> @@ -733,27 +741,29 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint 
> attr, GLuint newsz)
>}
>  
>for (i = 0; i < save->copied.nr; i++) {
> - for (j = 0; j < VBO_ATTRIB_MAX; j++) {
> -if (save->attrsz[j]) {
> -   if (j == attr) {
> -  if (oldsz) {
> - COPY_CLEAN_4V_TYPE_AS_UNION(dest, oldsz, data,
> - save->attrtype[j]);
> - data += oldsz;
> - dest += newsz;
> -  }
> -  else {
> -  

[Mesa-dev] [PATCH 29/29] vbo: Use a bitmask to track the active arrays in vbo_save*.

2016-06-13 Thread Mathias . Froehlich
From: Mathias Fröhlich 

The use of a bitmask makes functions iterating only active
attributes less visible in profiles.

v2: Use _mesa_bit_scan{,64} instead of open coding.
v3: Use u_bit_scan{,64} instead of _mesa_bit_scan{,64}.

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/vbo/vbo_save.h  |  2 ++
 src/mesa/vbo/vbo_save_api.c  | 67 +---
 src/mesa/vbo/vbo_save_draw.c | 55 +++-
 3 files changed, 69 insertions(+), 55 deletions(-)

diff --git a/src/mesa/vbo/vbo_save.h b/src/mesa/vbo/vbo_save.h
index 8032db8..2843b3c 100644
--- a/src/mesa/vbo/vbo_save.h
+++ b/src/mesa/vbo/vbo_save.h
@@ -61,6 +61,7 @@ struct vbo_save_copied_vtx {
  * compiled using the fallback opcode mechanism provided by dlist.c.
  */
 struct vbo_save_vertex_list {
+   GLbitfield64 enabled; /**< mask of enabled vbo arrays. */
GLubyte attrsz[VBO_ATTRIB_MAX];
GLenum attrtype[VBO_ATTRIB_MAX];
GLuint vertex_size;  /**< size in GLfloats */
@@ -126,6 +127,7 @@ struct vbo_save_context {
struct gl_client_array arrays[VBO_ATTRIB_MAX];
const struct gl_client_array *inputs[VBO_ATTRIB_MAX];
 
+   GLbitfield64 enabled; /**< mask of enabled vbo arrays. */
GLubyte attrsz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
GLenum attrtype[VBO_ATTRIB_MAX];  /**< GL_FLOAT, GL_INT, etc */
GLubyte active_sz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
index 97a1dfd..650c9b6 100644
--- a/src/mesa/vbo/vbo_save_api.c
+++ b/src/mesa/vbo/vbo_save_api.c
@@ -78,6 +78,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "main/api_arrayelt.h"
 #include "main/vtxfmt.h"
 #include "main/dispatch.h"
+#include "util/bitscan.h"
 
 #include "vbo_context.h"
 #include "vbo_noop.h"
@@ -429,6 +430,7 @@ _save_compile_vertex_list(struct gl_context *ctx)
 
/* Duplicate our template, increment refcounts to the storage structs:
 */
+   node->enabled = save->enabled;
memcpy(node->attrsz, save->attrsz, sizeof(node->attrsz));
memcpy(node->attrtype, save->attrtype, sizeof(node->attrtype));
node->vertex_size = save->vertex_size;
@@ -624,14 +626,15 @@ static void
 _save_copy_to_current(struct gl_context *ctx)
 {
struct vbo_save_context *save = _context(ctx)->save;
-   GLuint i;
+   GLbitfield64 enabled = save->enabled & (~BITFIELD64_BIT(VBO_ATTRIB_POS));
 
-   for (i = VBO_ATTRIB_POS + 1; i < VBO_ATTRIB_MAX; i++) {
-  if (save->attrsz[i]) {
- save->currentsz[i][0] = save->attrsz[i];
- COPY_CLEAN_4V_TYPE_AS_UNION(save->current[i], save->attrsz[i],
- save->attrptr[i], save->attrtype[i]);
-  }
+   while (enabled) {
+  const int i = u_bit_scan64();
+  assert(save->attrsz[i]);
+
+  save->currentsz[i][0] = save->attrsz[i];
+  COPY_CLEAN_4V_TYPE_AS_UNION(save->current[i], save->attrsz[i],
+  save->attrptr[i], save->attrtype[i]);
}
 }
 
@@ -640,9 +643,11 @@ static void
 _save_copy_from_current(struct gl_context *ctx)
 {
struct vbo_save_context *save = _context(ctx)->save;
-   GLint i;
+   GLbitfield64 enabled = save->enabled & (~BITFIELD64_BIT(VBO_ATTRIB_POS));
+
+   while (enabled) {
+  const int i = u_bit_scan64();
 
-   for (i = VBO_ATTRIB_POS + 1; i < VBO_ATTRIB_MAX; i++) {
   switch (save->attrsz[i]) {
   case 4:
  save->attrptr[i][3] = save->current[i][3];
@@ -652,7 +657,9 @@ _save_copy_from_current(struct gl_context *ctx)
  save->attrptr[i][1] = save->current[i][1];
   case 1:
  save->attrptr[i][0] = save->current[i][0];
+ break;
   case 0:
+ assert(0);
  break;
   }
}
@@ -691,6 +698,7 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint attr, 
GLuint newsz)
 */
oldsz = save->attrsz[attr];
save->attrsz[attr] = newsz;
+   save->enabled |= BITFIELD64_BIT(attr);
 
save->vertex_size += newsz - oldsz;
save->max_vert = ((VBO_SAVE_BUFFER_SIZE - save->vertex_store->used) /
@@ -723,7 +731,6 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint attr, 
GLuint newsz)
if (save->copied.nr) {
   const fi_type *data = save->copied.buffer;
   fi_type *dest = save->buffer;
-  GLuint j;
 
   /* Need to note this and fix up at runtime (or loopback):
*/
@@ -733,27 +740,28 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint attr, 
GLuint newsz)
   }
 
   for (i = 0; i < save->copied.nr; i++) {
- for (j = 0; j < VBO_ATTRIB_MAX; j++) {
-if (save->attrsz[j]) {
-   if (j == attr) {
-  if (oldsz) {
- COPY_CLEAN_4V_TYPE_AS_UNION(dest, oldsz, data,
- save->attrtype[j]);
- data += oldsz;
- dest += newsz;
-  }
- 

[Mesa-dev] [PATCH 29/29] vbo: Use a bitmask to track the active arrays in vbo_save*.

2016-05-24 Thread Mathias . Froehlich
From: Mathias Fröhlich 

The use of a bitmask makes functions iterating only active
attributes less visible in profiles.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/vbo/vbo_save.h  |  2 ++
 src/mesa/vbo/vbo_save_api.c  | 70 ++--
 src/mesa/vbo/vbo_save_draw.c | 55 ++
 3 files changed, 72 insertions(+), 55 deletions(-)

diff --git a/src/mesa/vbo/vbo_save.h b/src/mesa/vbo/vbo_save.h
index 8032db8..e3b86bc 100644
--- a/src/mesa/vbo/vbo_save.h
+++ b/src/mesa/vbo/vbo_save.h
@@ -61,6 +61,7 @@ struct vbo_save_copied_vtx {
  * compiled using the fallback opcode mechanism provided by dlist.c.
  */
 struct vbo_save_vertex_list {
+   GLbitfield64 enabled;/**< mask of enabled vbo arrays. */
GLubyte attrsz[VBO_ATTRIB_MAX];
GLenum attrtype[VBO_ATTRIB_MAX];
GLuint vertex_size;  /**< size in GLfloats */
@@ -126,6 +127,7 @@ struct vbo_save_context {
struct gl_client_array arrays[VBO_ATTRIB_MAX];
const struct gl_client_array *inputs[VBO_ATTRIB_MAX];
 
+   GLbitfield64 enabled;/**< mask of enabled vbo arrays. */
GLubyte attrsz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
GLenum attrtype[VBO_ATTRIB_MAX];  /**< GL_FLOAT, GL_INT, etc */
GLubyte active_sz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
index 97a1dfd..b178060 100644
--- a/src/mesa/vbo/vbo_save_api.c
+++ b/src/mesa/vbo/vbo_save_api.c
@@ -429,6 +429,7 @@ _save_compile_vertex_list(struct gl_context *ctx)
 
/* Duplicate our template, increment refcounts to the storage structs:
 */
+   node->enabled = save->enabled;
memcpy(node->attrsz, save->attrsz, sizeof(node->attrsz));
memcpy(node->attrtype, save->attrtype, sizeof(node->attrtype));
node->vertex_size = save->vertex_size;
@@ -624,14 +625,16 @@ static void
 _save_copy_to_current(struct gl_context *ctx)
 {
struct vbo_save_context *save = _context(ctx)->save;
-   GLuint i;
+   GLbitfield64 enabled = save->enabled & (~BITFIELD64_BIT(VBO_ATTRIB_POS));
 
-   for (i = VBO_ATTRIB_POS + 1; i < VBO_ATTRIB_MAX; i++) {
-  if (save->attrsz[i]) {
- save->currentsz[i][0] = save->attrsz[i];
- COPY_CLEAN_4V_TYPE_AS_UNION(save->current[i], save->attrsz[i],
- save->attrptr[i], save->attrtype[i]);
-  }
+   while (enabled) {
+  int i = ffsll(enabled) - 1;
+  enabled ^= BITFIELD64_BIT(i);
+  assert(save->attrsz[i]);
+
+  save->currentsz[i][0] = save->attrsz[i];
+  COPY_CLEAN_4V_TYPE_AS_UNION(save->current[i], save->attrsz[i],
+  save->attrptr[i], save->attrtype[i]);
}
 }
 
@@ -640,9 +643,12 @@ static void
 _save_copy_from_current(struct gl_context *ctx)
 {
struct vbo_save_context *save = _context(ctx)->save;
-   GLint i;
+   GLbitfield64 enabled = save->enabled & (~BITFIELD64_BIT(VBO_ATTRIB_POS));
+
+   while (enabled) {
+  int i = ffsll(enabled) - 1;
+  enabled ^= BITFIELD64_BIT(i);
 
-   for (i = VBO_ATTRIB_POS + 1; i < VBO_ATTRIB_MAX; i++) {
   switch (save->attrsz[i]) {
   case 4:
  save->attrptr[i][3] = save->current[i][3];
@@ -652,7 +658,9 @@ _save_copy_from_current(struct gl_context *ctx)
  save->attrptr[i][1] = save->current[i][1];
   case 1:
  save->attrptr[i][0] = save->current[i][0];
+ break;
   case 0:
+ assert(0);
  break;
   }
}
@@ -691,6 +699,7 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint attr, 
GLuint newsz)
 */
oldsz = save->attrsz[attr];
save->attrsz[attr] = newsz;
+   save->enabled |= BITFIELD64_BIT(attr);
 
save->vertex_size += newsz - oldsz;
save->max_vert = ((VBO_SAVE_BUFFER_SIZE - save->vertex_store->used) /
@@ -723,7 +732,6 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint attr, 
GLuint newsz)
if (save->copied.nr) {
   const fi_type *data = save->copied.buffer;
   fi_type *dest = save->buffer;
-  GLuint j;
 
   /* Need to note this and fix up at runtime (or loopback):
*/
@@ -733,27 +741,29 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint attr, 
GLuint newsz)
   }
 
   for (i = 0; i < save->copied.nr; i++) {
- for (j = 0; j < VBO_ATTRIB_MAX; j++) {
-if (save->attrsz[j]) {
-   if (j == attr) {
-  if (oldsz) {
- COPY_CLEAN_4V_TYPE_AS_UNION(dest, oldsz, data,
- save->attrtype[j]);
- data += oldsz;
- dest += newsz;
-  }
-  else {
- COPY_SZ_4V(dest, newsz, save->current[attr]);
- dest += newsz;
-  }
+ GLbitfield64 enabled = save->enabled;
+ while (enabled) {
+int j = ffsll(enabled) - 1;
+enabled ^= BITFIELD64_BIT(j);
+