diff options
author | Mathias Fröhlich <[email protected]> | 2018-04-01 20:18:36 +0200 |
---|---|---|
committer | Mathias Fröhlich <[email protected]> | 2018-05-10 07:06:15 +0200 |
commit | d1698d4311a63e1054e458ae1a27d7684595faee (patch) | |
tree | 6d73b27e4d4963a36db96f20472bc725c265309b /src/mesa/main/arrayobj.h | |
parent | fb4011ace9022e674639f2743272b7eba650cde3 (diff) |
mesa: Compute effective buffer bindings in the vao.
Compute VAO buffer binding information past the position/generic0 mapping.
Scan for duplicate buffer bindings and collapse them into derived
effective buffer binding index and effective attribute mask variables.
Provide a set of helper functions to access the distilled
information in the VAO. All of them prefixed with _mesa_draw_...
to indicate that they are meant to query draw information.
v2: Also group user space arrays containing interleaved arrays.
Add _Eff*Offset to be copied on attribute and binding copy.
Update comments.
Reviewed-by: Brian Paul <[email protected]>
Signed-off-by: Mathias Fröhlich <[email protected]>
Diffstat (limited to 'src/mesa/main/arrayobj.h')
-rw-r--r-- | src/mesa/main/arrayobj.h | 186 |
1 files changed, 186 insertions, 0 deletions
diff --git a/src/mesa/main/arrayobj.h b/src/mesa/main/arrayobj.h index 8da5c9ffe01..8b11c79bdb9 100644 --- a/src/mesa/main/arrayobj.h +++ b/src/mesa/main/arrayobj.h @@ -30,6 +30,7 @@ #include "glheader.h" #include "mtypes.h" #include "glformats.h" +#include "vbo/vbo.h" struct gl_context; @@ -146,6 +147,191 @@ _mesa_get_vao_vp_inputs(const struct gl_vertex_array_object *vao) } +/** + * Helper functions for consuming backends to walk the + * ctx->Array._DrawVAO for driver side array setup. + * Note that mesa provides preprocessed minimal binding information + * in the VAO. See _mesa_update_vao_derived_arrays for documentation. + */ + +/** + * Return enabled vertex attribute bits for draw. + */ +static inline GLbitfield +_mesa_draw_array_bits(const struct gl_context *ctx) +{ + return ctx->Array._DrawVAOEnabledAttribs; +} + + +/** + * Return enabled buffer object vertex attribute bits for draw. + * + * Needs the a fully updated VAO ready for draw. + */ +static inline GLbitfield +_mesa_draw_vbo_array_bits(const struct gl_context *ctx) +{ + const struct gl_vertex_array_object *const vao = ctx->Array._DrawVAO; + assert(vao->NewArrays == 0); + return vao->_EffEnabledVBO & ctx->Array._DrawVAOEnabledAttribs; +} + + +/** + * Return enabled user space vertex attribute bits for draw. + * + * Needs the a fully updated VAO ready for draw. + */ +static inline GLbitfield +_mesa_draw_user_array_bits(const struct gl_context *ctx) +{ + const struct gl_vertex_array_object *const vao = ctx->Array._DrawVAO; + assert(vao->NewArrays == 0); + return ~vao->_EffEnabledVBO & ctx->Array._DrawVAOEnabledAttribs; +} + + +/** + * Return enabled current values attribute bits for draw. + */ +static inline GLbitfield +_mesa_draw_current_bits(const struct gl_context *ctx) +{ + return ~ctx->Array._DrawVAOEnabledAttribs & VERT_BIT_ALL; +} + + +/** + * Return vertex buffer binding provided the attribute struct. + * + * Needs the a fully updated VAO ready for draw. + */ +static inline const struct gl_vertex_buffer_binding* +_mesa_draw_buffer_binding_from_attrib(const struct gl_vertex_array_object *vao, + const struct gl_array_attributes *attrib) +{ + assert(vao->NewArrays == 0); + return &vao->BufferBinding[attrib->_EffBufferBindingIndex]; +} + + +/** + * Return vertex array attribute provided the attribute number. + */ +static inline const struct gl_array_attributes* +_mesa_draw_array_attrib(const struct gl_vertex_array_object *vao, + gl_vert_attrib attr) +{ + assert(vao->NewArrays == 0); + const gl_attribute_map_mode map_mode = vao->_AttributeMapMode; + return &vao->VertexAttrib[_mesa_vao_attribute_map[map_mode][attr]]; +} + + +/** + * Return vertex buffer binding provided an attribute number. + */ +static inline const struct gl_vertex_buffer_binding* +_mesa_draw_buffer_binding(const struct gl_vertex_array_object *vao, + gl_vert_attrib attr) +{ + const struct gl_array_attributes *const attrib + = _mesa_draw_array_attrib(vao, attr); + return _mesa_draw_buffer_binding_from_attrib(vao, attrib); +} + + +/** + * Return vertex attribute bits bound at the provided binding. + * + * Needs the a fully updated VAO ready for draw. + */ +static inline GLbitfield +_mesa_draw_bound_attrib_bits(const struct gl_vertex_buffer_binding *binding) +{ + return binding->_EffBoundArrays; +} + + +/** + * Return the vertex offset bound at the provided binding. + * + * Needs the a fully updated VAO ready for draw. + */ +static inline GLintptr +_mesa_draw_binding_offset(const struct gl_vertex_buffer_binding *binding) +{ + return binding->_EffOffset; +} + + +/** + * Return the relative offset of the provided attrib. + * + * Needs the a fully updated VAO ready for draw. + */ +static inline GLushort +_mesa_draw_attributes_relative_offset(const struct gl_array_attributes *attrib) +{ + return attrib->_EffRelativeOffset; +} + + +/** + * Return a current value vertex array attribute provided the attribute number. + */ +static inline const struct gl_array_attributes* +_mesa_draw_current_attrib(const struct gl_context *ctx, gl_vert_attrib attr) +{ + return _vbo_current_attrib(ctx, attr); +} + + +/** + * Return true if we have the VERT_ATTRIB_EDGEFLAG array enabled. + */ +static inline bool +_mesa_draw_edge_flag_array_enabled(const struct gl_context *ctx) +{ + return ctx->Array._DrawVAOEnabledAttribs & VERT_BIT_EDGEFLAG; +} + + +/** + * Return the attrib for the given attribute. + */ +static inline const struct gl_array_attributes* +_mesa_draw_attrib(const struct gl_context *ctx, gl_vert_attrib attr) +{ + if (ctx->Array._DrawVAOEnabledAttribs & VERT_BIT(attr)) { + const struct gl_vertex_array_object *vao = ctx->Array._DrawVAO; + return _mesa_draw_array_attrib(vao, attr); + } else { + return _vbo_current_attrib(ctx, attr); + } +} + + +/** + * Return the attrib, binding pair for the given attribute. + */ +static inline void +_mesa_draw_attrib_and_binding(const struct gl_context *ctx, gl_vert_attrib attr, + const struct gl_array_attributes **attrib, + const struct gl_vertex_buffer_binding **binding) +{ + if (ctx->Array._DrawVAOEnabledAttribs & VERT_BIT(attr)) { + const struct gl_vertex_array_object *vao = ctx->Array._DrawVAO; + *attrib = _mesa_draw_array_attrib(vao, attr); + *binding = _mesa_draw_buffer_binding_from_attrib(vao, *attrib); + } else { + *attrib = _vbo_current_attrib(ctx, attr); + *binding = _vbo_current_binding(ctx); + } +} + + /* * API functions */ |