From: Marek Olšák Date: Thu, 23 Jan 2020 03:38:09 +0000 (-0500) Subject: st/mesa: simplify determination whether a draw needs min/max index X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fd6636ebc06d55b59851701c436b8b97f50fd7f4;p=mesa.git st/mesa: simplify determination whether a draw needs min/max index Reviewed-by: Mathias Fröhlich Part-of: --- diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c index 331dc1a3c68..6dbd09b39ec 100644 --- a/src/mesa/main/arrayobj.c +++ b/src/mesa/main/arrayobj.c @@ -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) { diff --git a/src/mesa/main/arrayobj.h b/src/mesa/main/arrayobj.h index 584e6d818cf..19ab65b3242 100644 --- a/src/mesa/main/arrayobj.h +++ b/src/mesa/main/arrayobj.h @@ -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. */ diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c index b2756354f1f..133f1a8c424 100644 --- a/src/mesa/main/attrib.c +++ b/src/mesa/main/attrib.c @@ -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; } diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 0da926e67ff..db4921d0106 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -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; diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c index 7ef0de7734a..2f6aefc9ccb 100644 --- a/src/mesa/main/varray.c +++ b/src/mesa/main/varray.c @@ -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; } } diff --git a/src/mesa/state_tracker/st_atom_array.c b/src/mesa/state_tracker/st_atom_array.c index c39c1c41f51..040c25b9651 100644 --- a/src/mesa/state_tracker/st_atom_array.c +++ b/src/mesa/state_tracker/st_atom_array.c @@ -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,