[Mesa-dev] [PATCH 5/8] vbo: Use static const VERT_ATTRIB->VBO_ATTRIB maps.

Mathias.Froehlich at gmx.net Mathias.Froehlich at gmx.net
Wed Jan 31 07:55:59 UTC 2018


From: Mathias Fröhlich <mathias.froehlich at web.de>

Instead of each context having its own map instance for
this purpose, use a global static const map.

Signed-off-by: Mathias Fröhlich <Mathias.Froehlich at web.de>
---
 src/mesa/vbo/vbo_context.c    | 23 ++------------
 src/mesa/vbo/vbo_exec.c       | 74 +++++++++++++++++++++++++++++++++++++++++++
 src/mesa/vbo/vbo_exec_array.c |  5 ++-
 src/mesa/vbo/vbo_exec_draw.c  |  8 ++---
 src/mesa/vbo/vbo_private.h    | 15 ++++++---
 src/mesa/vbo/vbo_save_draw.c  |  8 ++---
 6 files changed, 98 insertions(+), 35 deletions(-)

diff --git a/src/mesa/vbo/vbo_context.c b/src/mesa/vbo/vbo_context.c
index 265b73d2db..fe1d0f510a 100644
--- a/src/mesa/vbo/vbo_context.c
+++ b/src/mesa/vbo/vbo_context.c
@@ -229,27 +229,8 @@ _vbo_CreateContext(struct gl_context *ctx)
    init_mat_currval(ctx);
    vbo_set_indirect_draw_func(ctx, vbo_draw_indirect_prims);
 
-   /* Build mappings from VERT_ATTRIB -> VBO_ATTRIB depending on type
-    * of vertex program active.
-    */
-   {
-      GLuint i;
-
-      /* make sure all VBO_ATTRIB_ values can fit in an unsigned byte */
-      STATIC_ASSERT(VBO_ATTRIB_MAX <= 255);
-
-      /* identity mapping */
-      for (i = 0; i < ARRAY_SIZE(vbo->map_vp_none); i++)
-         vbo->map_vp_none[i] = i;
-      /* map material attribs to generic slots */
-      for (i = 0; i < VERT_ATTRIB_MAT_MAX; i++)
-         vbo->map_vp_none[VERT_ATTRIB_MAT(i)]
-            = VBO_ATTRIB_MAT_FRONT_AMBIENT + i;
-
-      for (i = 0; i < ARRAY_SIZE(vbo->map_vp_arb); i++)
-         vbo->map_vp_arb[i] = i;
-   }
-
+   /* make sure all VBO_ATTRIB_ values can fit in an unsigned byte */
+   STATIC_ASSERT(VBO_ATTRIB_MAX <= 255);
 
    /* Hook our functions into exec and compile dispatch tables.  These
     * will pretty much be permanently installed, which means that the
diff --git a/src/mesa/vbo/vbo_exec.c b/src/mesa/vbo/vbo_exec.c
index 82f204e3dc..987fa84a9b 100644
--- a/src/mesa/vbo/vbo_exec.c
+++ b/src/mesa/vbo/vbo_exec.c
@@ -32,6 +32,80 @@
 #include "main/vtxfmt.h"
 #include "vbo_private.h"
 
+const unsigned char
+_vbo_attribute_alias_map[_VP_MODE_MAX][VERT_ATTRIB_MAX] = {
+   /* VP_FF: */
+   {
+      VBO_ATTRIB_POS,                 /* VERT_ATTRIB_POS */
+      VBO_ATTRIB_NORMAL,              /* VERT_ATTRIB_NORMAL */
+      VBO_ATTRIB_COLOR0,              /* VERT_ATTRIB_COLOR0 */
+      VBO_ATTRIB_COLOR1,              /* VERT_ATTRIB_COLOR1 */
+      VBO_ATTRIB_FOG,                 /* VERT_ATTRIB_FOG */
+      VBO_ATTRIB_COLOR_INDEX,         /* VERT_ATTRIB_COLOR_INDEX */
+      VBO_ATTRIB_EDGEFLAG,            /* VERT_ATTRIB_EDGEFLAG */
+      VBO_ATTRIB_TEX0,                /* VERT_ATTRIB_TEX0 */
+      VBO_ATTRIB_TEX1,                /* VERT_ATTRIB_TEX1 */
+      VBO_ATTRIB_TEX2,                /* VERT_ATTRIB_TEX2 */
+      VBO_ATTRIB_TEX3,                /* VERT_ATTRIB_TEX3 */
+      VBO_ATTRIB_TEX4,                /* VERT_ATTRIB_TEX4 */
+      VBO_ATTRIB_TEX5,                /* VERT_ATTRIB_TEX5 */
+      VBO_ATTRIB_TEX6,                /* VERT_ATTRIB_TEX6 */
+      VBO_ATTRIB_TEX7,                /* VERT_ATTRIB_TEX7 */
+      VBO_ATTRIB_POINT_SIZE,          /* VERT_ATTRIB_POINT_SIZE */
+      VBO_ATTRIB_GENERIC0,            /* VERT_ATTRIB_GENERIC0 */
+      VBO_ATTRIB_GENERIC1,            /* VERT_ATTRIB_GENERIC1 */
+      VBO_ATTRIB_GENERIC2,            /* VERT_ATTRIB_GENERIC2 */
+      VBO_ATTRIB_GENERIC3,            /* VERT_ATTRIB_GENERIC3 */
+      VBO_ATTRIB_MAT_FRONT_AMBIENT,   /* VERT_ATTRIB_GENERIC4 */
+      VBO_ATTRIB_MAT_BACK_AMBIENT,    /* VERT_ATTRIB_GENERIC5 */
+      VBO_ATTRIB_MAT_FRONT_DIFFUSE,   /* VERT_ATTRIB_GENERIC6 */
+      VBO_ATTRIB_MAT_BACK_DIFFUSE,    /* VERT_ATTRIB_GENERIC7 */
+      VBO_ATTRIB_MAT_FRONT_SPECULAR,  /* VERT_ATTRIB_GENERIC8 */
+      VBO_ATTRIB_MAT_BACK_SPECULAR,   /* VERT_ATTRIB_GENERIC9 */
+      VBO_ATTRIB_MAT_FRONT_EMISSION,  /* VERT_ATTRIB_GENERIC10 */
+      VBO_ATTRIB_MAT_BACK_EMISSION,   /* VERT_ATTRIB_GENERIC11 */
+      VBO_ATTRIB_MAT_FRONT_SHININESS, /* VERT_ATTRIB_GENERIC12 */
+      VBO_ATTRIB_MAT_BACK_SHININESS,  /* VERT_ATTRIB_GENERIC13 */
+      VBO_ATTRIB_MAT_FRONT_INDEXES,   /* VERT_ATTRIB_GENERIC14 */
+      VBO_ATTRIB_MAT_BACK_INDEXES     /* VERT_ATTRIB_GENERIC15 */
+   },
+
+   /* VP_SHADER: */
+   {
+      VBO_ATTRIB_POS,                 /* VERT_ATTRIB_POS */
+      VBO_ATTRIB_NORMAL,              /* VERT_ATTRIB_NORMAL */
+      VBO_ATTRIB_COLOR0,              /* VERT_ATTRIB_COLOR0 */
+      VBO_ATTRIB_COLOR1,              /* VERT_ATTRIB_COLOR1 */
+      VBO_ATTRIB_FOG,                 /* VERT_ATTRIB_FOG */
+      VBO_ATTRIB_COLOR_INDEX,         /* VERT_ATTRIB_COLOR_INDEX */
+      VBO_ATTRIB_EDGEFLAG,            /* VERT_ATTRIB_EDGEFLAG */
+      VBO_ATTRIB_TEX0,                /* VERT_ATTRIB_TEX0 */
+      VBO_ATTRIB_TEX1,                /* VERT_ATTRIB_TEX1 */
+      VBO_ATTRIB_TEX2,                /* VERT_ATTRIB_TEX2 */
+      VBO_ATTRIB_TEX3,                /* VERT_ATTRIB_TEX3 */
+      VBO_ATTRIB_TEX4,                /* VERT_ATTRIB_TEX4 */
+      VBO_ATTRIB_TEX5,                /* VERT_ATTRIB_TEX5 */
+      VBO_ATTRIB_TEX6,                /* VERT_ATTRIB_TEX6 */
+      VBO_ATTRIB_TEX7,                /* VERT_ATTRIB_TEX7 */
+      VBO_ATTRIB_POINT_SIZE,          /* VERT_ATTRIB_POINT_SIZE */
+      VBO_ATTRIB_GENERIC0,            /* VERT_ATTRIB_GENERIC0 */
+      VBO_ATTRIB_GENERIC1,            /* VERT_ATTRIB_GENERIC1 */
+      VBO_ATTRIB_GENERIC2,            /* VERT_ATTRIB_GENERIC2 */
+      VBO_ATTRIB_GENERIC3,            /* VERT_ATTRIB_GENERIC3 */
+      VBO_ATTRIB_GENERIC4,            /* VERT_ATTRIB_GENERIC4 */
+      VBO_ATTRIB_GENERIC5,            /* VERT_ATTRIB_GENERIC5 */
+      VBO_ATTRIB_GENERIC6,            /* VERT_ATTRIB_GENERIC6 */
+      VBO_ATTRIB_GENERIC7,            /* VERT_ATTRIB_GENERIC7 */
+      VBO_ATTRIB_GENERIC8,            /* VERT_ATTRIB_GENERIC8 */
+      VBO_ATTRIB_GENERIC9,            /* VERT_ATTRIB_GENERIC9 */
+      VBO_ATTRIB_GENERIC10,           /* VERT_ATTRIB_GENERIC10 */
+      VBO_ATTRIB_GENERIC11,           /* VERT_ATTRIB_GENERIC11 */
+      VBO_ATTRIB_GENERIC12,           /* VERT_ATTRIB_GENERIC12 */
+      VBO_ATTRIB_GENERIC13,           /* VERT_ATTRIB_GENERIC13 */
+      VBO_ATTRIB_GENERIC14,           /* VERT_ATTRIB_GENERIC14 */
+      VBO_ATTRIB_GENERIC15            /* VERT_ATTRIB_GENERIC15 */
+   }
+};
 
 
 void
diff --git a/src/mesa/vbo/vbo_exec_array.c b/src/mesa/vbo/vbo_exec_array.c
index 28f64e1422..50cd1deaa6 100644
--- a/src/mesa/vbo/vbo_exec_array.c
+++ b/src/mesa/vbo/vbo_exec_array.c
@@ -319,7 +319,8 @@ recalculate_input_bindings(struct gl_context *ctx)
    GLbitfield const_inputs = 0x0;
    GLuint i;
 
-   switch (get_vp_mode(ctx)) {
+   const enum vp_mode program_mode = get_vp_mode(ctx);
+   switch (program_mode) {
    case VP_FF:
       /* When no vertex program is active (or the vertex program is generated
        * from fixed-function state).  We put the material values into the
@@ -424,6 +425,8 @@ recalculate_input_bindings(struct gl_context *ctx)
       }
 
       break;
+   default:
+      assert(0);
    }
 
    _mesa_set_varying_vp_inputs(ctx, VERT_BIT_ALL & (~const_inputs));
diff --git a/src/mesa/vbo/vbo_exec_draw.c b/src/mesa/vbo/vbo_exec_draw.c
index b077fbeb6d..c4caff40bc 100644
--- a/src/mesa/vbo/vbo_exec_draw.c
+++ b/src/mesa/vbo/vbo_exec_draw.c
@@ -174,18 +174,20 @@ vbo_exec_bind_arrays(struct gl_context *ctx)
    struct vbo_context *vbo = vbo_context(ctx);
    struct vbo_exec_context *exec = &vbo->exec;
    struct gl_vertex_array *arrays = exec->vtx.arrays;
-   const GLubyte *map;
    GLuint attr;
    GLbitfield varying_inputs = 0x0;
    bool swap_pos = false;
 
+   const enum vp_mode program_mode = get_vp_mode(exec->ctx);
+   const unsigned char * const map = _vbo_attribute_alias_map[program_mode];
+
    /* Install the default (ie Current) attributes first */
    for (attr = 0; attr < VERT_ATTRIB_FF_MAX; attr++) {
       exec->vtx.inputs[attr] = &vbo->currval[VBO_ATTRIB_POS+attr];
    }
 
    /* Overlay other active attributes */
-   switch (get_vp_mode(exec->ctx)) {
+   switch (program_mode) {
    case VP_FF:
       for (attr = 0; attr < VERT_ATTRIB_MAT_OFFSET; attr++) {
          assert(VERT_ATTRIB_GENERIC(attr) < ARRAY_SIZE(exec->vtx.inputs));
@@ -197,7 +199,6 @@ vbo_exec_bind_arrays(struct gl_context *ctx)
          exec->vtx.inputs[VERT_ATTRIB_MAT(attr)] =
             &vbo->currval[VBO_ATTRIB_MAT_FRONT_AMBIENT+attr];
       }
-      map = vbo->map_vp_none;
       break;
    case VP_SHADER:
       for (attr = 0; attr < VERT_ATTRIB_GENERIC_MAX; attr++) {
@@ -205,7 +206,6 @@ vbo_exec_bind_arrays(struct gl_context *ctx)
          exec->vtx.inputs[VERT_ATTRIB_GENERIC(attr)] =
             &vbo->currval[VBO_ATTRIB_GENERIC0+attr];
       }
-      map = vbo->map_vp_arb;
 
       /* check if VERT_ATTRIB_POS is not read but VERT_BIT_GENERIC0 is read.
        * In that case we effectively need to route the data from
diff --git a/src/mesa/vbo/vbo_private.h b/src/mesa/vbo/vbo_private.h
index 7c1e3c481f..9be186a5a7 100644
--- a/src/mesa/vbo/vbo_private.h
+++ b/src/mesa/vbo/vbo_private.h
@@ -45,10 +45,6 @@ struct _mesa_prim;
 struct vbo_context {
    struct gl_vertex_array currval[VBO_ATTRIB_MAX];
 
-   /** Map VERT_ATTRIB_x to VBO_ATTRIB_y */
-   GLubyte map_vp_none[VERT_ATTRIB_MAX];
-   GLubyte map_vp_arb[VERT_ATTRIB_MAX];
-
    struct vbo_exec_context exec;
    struct vbo_save_context save;
 
@@ -79,7 +75,8 @@ vbo_context(struct gl_context *ctx)
  */
 enum vp_mode {
    VP_FF,    /**< legacy / fixed function */
-   VP_SHADER /**< ARB vertex program or GLSL vertex shader */
+   VP_SHADER, /**< ARB vertex program or GLSL vertex shader */
+   _VP_MODE_MAX /**< for sizing arrays */
 };
 
 
@@ -98,6 +95,14 @@ get_vp_mode( struct gl_context *ctx )
 }
 
 
+/* Array to apply the fixed function material aliasing map to
+ * an attribute value used in vbo processing inputs to an attribute
+ * as they appear in the vao.
+ */
+extern const unsigned char
+_vbo_attribute_alias_map[_VP_MODE_MAX][VERT_ATTRIB_MAX];
+
+
 /**
  * Return if format is integer. The immediate mode commands only emit floats
  * for non-integer types, thus everything else is integer.
diff --git a/src/mesa/vbo/vbo_save_draw.c b/src/mesa/vbo/vbo_save_draw.c
index 940739cd29..f9a0e39cea 100644
--- a/src/mesa/vbo/vbo_save_draw.c
+++ b/src/mesa/vbo/vbo_save_draw.c
@@ -138,18 +138,20 @@ bind_vertex_list(struct gl_context *ctx,
    struct vbo_context *vbo = vbo_context(ctx);
    struct vbo_save_context *save = &vbo->save;
    struct gl_vertex_array *arrays = save->arrays;
-   const GLubyte *map;
    GLuint attr;
    GLbitfield varying_inputs = 0x0;
    bool generic_from_pos = false;
 
+   const enum vp_mode program_mode = get_vp_mode(ctx);
+   const unsigned char * const map = _vbo_attribute_alias_map[program_mode];
+
    /* Install the default (ie Current) attributes first */
    for (attr = 0; attr < VERT_ATTRIB_FF_MAX; attr++) {
       save->inputs[attr] = &vbo->currval[VBO_ATTRIB_POS + attr];
    }
 
    /* Overlay other active attributes */
-   switch (get_vp_mode(ctx)) {
+   switch (program_mode) {
    case VP_FF:
       for (attr = 0; attr < VERT_ATTRIB_MAT_OFFSET; attr++) {
          save->inputs[VERT_ATTRIB_GENERIC(attr)] =
@@ -159,14 +161,12 @@ bind_vertex_list(struct gl_context *ctx,
          save->inputs[VERT_ATTRIB_MAT(attr)] =
             &vbo->currval[VBO_ATTRIB_MAT_FRONT_AMBIENT+attr];
       }
-      map = vbo->map_vp_none;
       break;
    case VP_SHADER:
       for (attr = 0; attr < VERT_ATTRIB_GENERIC_MAX; attr++) {
          save->inputs[VERT_ATTRIB_GENERIC(attr)] =
             &vbo->currval[VBO_ATTRIB_GENERIC0+attr];
       }
-      map = vbo->map_vp_arb;
 
       /* check if VERT_ATTRIB_POS is not read but VERT_BIT_GENERIC0 is read.
        * In that case we effectively need to route the data from
-- 
2.14.3



More information about the mesa-dev mailing list