st/mesa: simplify determination whether a draw needs min/max index

Reviewed-by: Mathias Fröhlich <mathias.froehlich@web.de>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3829>
This commit is contained in:
Marek Olšák 2020-01-22 22:38:09 -05:00
parent 1d93372802
commit fd6636ebc0
6 changed files with 38 additions and 5 deletions

View file

@ -611,9 +611,12 @@ _mesa_update_vao_derived_arrays(struct gl_context *ctx,
const GLbitfield enabled = vao->Enabled;
/* VBO array bits. */
const GLbitfield vbos = vao->VertexAttribBufferMask;
const GLbitfield divisor_is_nonzero = vao->NonZeroDivisorMask;
/* Compute and store effectively enabled and mapped vbo arrays */
vao->_EffEnabledVBO = _mesa_vao_enable_to_vp_inputs(mode, enabled & vbos);
vao->_EffEnabledNonZeroDivisor =
_mesa_vao_enable_to_vp_inputs(mode, enabled & divisor_is_nonzero);
/* Walk those enabled arrays that have a real vbo attached */
GLbitfield mask = enabled;
while (mask) {

View file

@ -211,6 +211,20 @@ _mesa_draw_user_array_bits(const struct gl_context *ctx)
}
/**
* Return which enabled vertex attributes have a non-zero instance divisor.
*
* Needs the a fully updated VAO ready for draw.
*/
static inline GLbitfield
_mesa_draw_nonzero_divisor_bits(const struct gl_context *ctx)
{
const struct gl_vertex_array_object *const vao = ctx->Array._DrawVAO;
assert(vao->NewArrays == 0);
return ~vao->_EffEnabledNonZeroDivisor & ctx->Array._DrawVAOEnabledAttribs;
}
/**
* Return enabled current values attribute bits for draw.
*/

View file

@ -1580,8 +1580,10 @@ copy_array_object(struct gl_context *ctx,
/* Enabled must be the same than on push */
dest->Enabled = src->Enabled;
dest->_EffEnabledVBO = src->_EffEnabledVBO;
dest->_EffEnabledNonZeroDivisor = src->_EffEnabledNonZeroDivisor;
/* The bitmask of bound VBOs needs to match the VertexBinding array */
dest->VertexAttribBufferMask = src->VertexAttribBufferMask;
dest->NonZeroDivisorMask = src->NonZeroDivisorMask;
dest->_AttributeMapMode = src->_AttributeMapMode;
dest->NewArrays = src->NewArrays;
}

View file

@ -1547,6 +1547,9 @@ struct gl_vertex_array_object
/** Mask indicating which vertex arrays have vertex buffer associated. */
GLbitfield VertexAttribBufferMask;
/** Mask indicating which vertex arrays have a non-zero instance divisor. */
GLbitfield NonZeroDivisorMask;
/** Mask of VERT_BIT_* values indicating which arrays are enabled */
GLbitfield Enabled;
@ -1559,6 +1562,9 @@ struct gl_vertex_array_object
*/
GLbitfield _EffEnabledVBO;
/** Same as _EffEnabledVBO, but for instance divisors. */
GLbitfield _EffEnabledNonZeroDivisor;
/** Denotes the way the position/generic0 attribute is mapped */
gl_attribute_map_mode _AttributeMapMode;

View file

@ -174,6 +174,11 @@ _mesa_vertex_attrib_binding(struct gl_context *ctx,
else
vao->VertexAttribBufferMask &= ~array_bit;
if (vao->BufferBinding[bindingIndex].InstanceDivisor)
vao->NonZeroDivisorMask |= array_bit;
else
vao->NonZeroDivisorMask &= ~array_bit;
vao->BufferBinding[array->BufferBindingIndex]._BoundArrays &= ~array_bit;
vao->BufferBinding[bindingIndex]._BoundArrays |= array_bit;
@ -250,6 +255,12 @@ vertex_binding_divisor(struct gl_context *ctx,
if (binding->InstanceDivisor != divisor) {
binding->InstanceDivisor = divisor;
if (divisor)
vao->NonZeroDivisorMask |= binding->_BoundArrays;
else
vao->NonZeroDivisorMask &= ~binding->_BoundArrays;
vao->NewArrays |= vao->Enabled & binding->_BoundArrays;
}
}

View file

@ -143,6 +143,8 @@ st_setup_arrays(struct st_context *st,
GLbitfield userbuf_attribs = inputs_read & _mesa_draw_user_array_bits(ctx);
*has_user_vertex_buffers = userbuf_attribs != 0;
st->draw_needs_minmax_index =
(userbuf_attribs & ~_mesa_draw_nonzero_divisor_bits(ctx)) != 0;
while (mask) {
/* The attribute index to start pulling a binding */
@ -164,9 +166,6 @@ st_setup_arrays(struct st_context *st,
vbuffer[bufidx].buffer.user = ptr;
vbuffer[bufidx].is_user_buffer = true;
vbuffer[bufidx].buffer_offset = 0;
if (!binding->InstanceDivisor)
st->draw_needs_minmax_index = true;
}
vbuffer[bufidx].stride = binding->Stride; /* in bytes */
@ -296,8 +295,6 @@ st_update_array(struct st_context *st)
unsigned num_velements;
bool uses_user_vertex_buffers;
st->draw_needs_minmax_index = false;
/* ST_NEW_VERTEX_ARRAYS alias ctx->DriverFlags.NewArray */
/* Setup arrays */
st_setup_arrays(st, vp, vp_variant, velements, vbuffer, &num_vbuffers,