diff options
author | Mathias Fröhlich <mathias.froehlich@web.de> | 2018-01-27 16:07:22 +0100 |
---|---|---|
committer | Mathias Fröhlich <Mathias.Froehlich@gmx.net> | 2018-02-01 22:39:07 +0100 |
commit | 3d4fb879ddbce1c5da7199ae74bc2e7ae98d1b70 (patch) | |
tree | 886e65a3a68bfd422e067e92caff2b4351d20134 /src | |
parent | b4fd63015ac7fd73e0147ff078caec47be729e87 (diff) |
vbo: Use static const VERT_ATTRIB->VBO_ATTRIB maps.
Instead of each context having its own map instance for
this purpose, use a global static const map.
v2: s,unsigned char,GLubyte,g
s,_VP_MODE_MAX,VP_MODE_MAX,g
Change comment style.
Signed-off-by: Mathias Fröhlich <Mathias.Froehlich@web.de>
Reviewed-by: Brian Paul <brianp@vmware.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/vbo/vbo_context.c | 23 | ||||
-rw-r--r-- | src/mesa/vbo/vbo_exec.c | 74 | ||||
-rw-r--r-- | src/mesa/vbo/vbo_exec_array.c | 5 | ||||
-rw-r--r-- | src/mesa/vbo/vbo_exec_draw.c | 8 | ||||
-rw-r--r-- | src/mesa/vbo/vbo_private.h | 16 | ||||
-rw-r--r-- | src/mesa/vbo/vbo_save_draw.c | 8 |
6 files changed, 99 insertions, 35 deletions
diff --git a/src/mesa/vbo/vbo_context.c b/src/mesa/vbo/vbo_context.c index 4fa6f62ad0..5bc6bf0acd 100644 --- a/src/mesa/vbo/vbo_context.c +++ b/src/mesa/vbo/vbo_context.c @@ -236,27 +236,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..fc06979dcb 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 GLubyte +_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 98eb6466ba..ee4b7b56b6 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 bd82825b51..e3e050595c 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 GLubyte * 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_MAT0; 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..e44a521b11 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 */ }; @@ -99,6 +96,15 @@ 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 GLubyte +_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 a9e0890ebe..ad45f4d050 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 GLubyte * 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_MAT0; 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 |