aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Fröhlich <[email protected]>2018-01-27 16:07:22 +0100
committerMathias Fröhlich <[email protected]>2018-02-01 22:39:06 +0100
commitb4fd63015ac7fd73e0147ff078caec47be729e87 (patch)
treedf1ee50284dc622f78a5626f391b53585eb4faab
parent186f03cfb021223f0a6f238da036517fbf240d26 (diff)
mesa: Track position/generic0 aliasing in the VAO.
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. v2: s,unsigned char,GLubyte,g s,_ATTRIBUTE_MAP_MODE_MAX,ATTRIBUTE_MAP_MODE_MAX,g Change comment style, add comments. Signed-off-by: Mathias Fröhlich <[email protected]> Reviewed-by: Brian Paul <[email protected]>
-rw-r--r--src/mesa/main/arrayobj.c131
-rw-r--r--src/mesa/main/arrayobj.h74
-rw-r--r--src/mesa/main/enable.c5
-rw-r--r--src/mesa/main/mtypes.h18
-rw-r--r--src/mesa/main/varray.c18
5 files changed, 242 insertions, 4 deletions
diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c
index 7208f4c534f..360d097ec1d 100644
--- a/src/mesa/main/arrayobj.c
+++ b/src/mesa/main/arrayobj.c
@@ -54,6 +54,135 @@
#include "util/bitscan.h"
+const GLubyte
+_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 ff26157c79e..411ed65c50b 100644
--- a/src/mesa/main/arrayobj.h
+++ b/src/mesa/main/arrayobj.h
@@ -89,6 +89,80 @@ _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 GLubyte
+_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 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:
+ /* 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 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);
+}
+
+
/*
* API functions
*/
diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c
index 0b3de5220df..451a9c918f4 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 f6fa6f45618..b00f059e39a 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1513,6 +1513,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 */
+} gl_attribute_map_mode;
+
+
+/**
* Attributes to describe a vertex array.
*
* Contains the size, type, format and normalization flag,
@@ -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 bc0afa6bcf5..81b8fbe8ca7 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);
}
}