nouveau: fix handling draw info

index_bias is undefined if index_size == 0.
index bounds are undefined if index_bounds_valid == false.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7679>
This commit is contained in:
Marek Olšák 2020-11-22 02:22:45 -05:00
parent f2e281c231
commit cbdc00ac3a
4 changed files with 28 additions and 12 deletions

View File

@ -573,10 +573,16 @@ nv30_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info,
*/
nv30->vbo_push_hint = /* the 64 is heuristic */
!(info->index_size &&
info->index_bounds_valid &&
((info->max_index - info->min_index + 64) < draws[0].count));
nv30->vbo_min_index = info->min_index;
nv30->vbo_max_index = info->max_index;
if (info->index_bounds_valid) {
nv30->vbo_min_index = info->min_index;
nv30->vbo_max_index = info->max_index;
} else {
nv30->vbo_min_index = 0;
nv30->vbo_max_index = ~0;
}
if (nv30->vbo_push_hint != !!nv30->vbo_fifo)
nv30->dirty |= NV30_NEW_ARRAYS;
@ -617,7 +623,7 @@ nv30_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info,
info->mode, draws[0].start, draws[0].count,
info->instance_count);
} else {
bool shorten = info->max_index <= 65535;
bool shorten = info->index_bounds_valid && info->max_index <= 65535;
if (info->primitive_restart != nv30->state.prim_restart) {
if (info->primitive_restart) {

View File

@ -253,7 +253,7 @@ nv50_push_vbo(struct nv50_context *nv50, const struct pipe_draw_info *info,
ctx.need_vertex_id = nv50->screen->base.class_3d >= NV84_3D_CLASS &&
nv50->vertprog->vp.need_vertex_id && (nv50->vertex->num_elements < 32);
ctx.index_bias = info->index_bias;
ctx.index_bias = info->index_size ? info->index_bias : 0;
ctx.instance_id = 0;
/* For indexed draws, gl_VertexID must be emitted for every vertex. */
@ -276,7 +276,7 @@ nv50_push_vbo(struct nv50_context *nv50, const struct pipe_draw_info *info,
data = vb->buffer.user;
if (apply_bias && likely(!(nv50->vertex->instance_bufs & (1 << i))))
data += (ptrdiff_t)info->index_bias * vb->stride;
data += (ptrdiff_t)(info->index_size ? info->index_bias : 0) * vb->stride;
ctx.translate->set_buffer(ctx.translate, i, data, vb->stride, ~0);
}

View File

@ -779,8 +779,13 @@ nv50_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info,
BCTX_REFN(nv50->bufctx_3d, 3D_INDEX, nv04_resource(info->index.resource), RD);
/* NOTE: caller must ensure that (min_index + index_bias) is >= 0 */
nv50->vb_elt_first = info->min_index + info->index_bias;
nv50->vb_elt_limit = info->max_index - info->min_index;
if (info->index_bounds_valid) {
nv50->vb_elt_first = info->min_index + (info->index_size ? info->index_bias : 0);
nv50->vb_elt_limit = info->max_index - info->min_index;
} else {
nv50->vb_elt_first = 0;
nv50->vb_elt_limit = ~0;
}
nv50->instance_off = info->start_instance;
nv50->instance_max = info->instance_count - 1;
@ -861,7 +866,7 @@ nv50_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info,
}
if (info->index_size) {
bool shorten = info->max_index <= 65535;
bool shorten = info->index_bounds_valid && info->max_index <= 65535;
if (info->primitive_restart != nv50->state.prim_restart) {
if (info->primitive_restart) {

View File

@ -945,8 +945,13 @@ nvc0_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info,
int s;
/* NOTE: caller must ensure that (min_index + index_bias) is >= 0 */
nvc0->vb_elt_first = info->min_index + info->index_bias;
nvc0->vb_elt_limit = info->max_index - info->min_index;
if (info->index_bounds_valid) {
nvc0->vb_elt_first = info->min_index + (info->index_size ? info->index_bias : 0);
nvc0->vb_elt_limit = info->max_index - info->min_index;
} else {
nvc0->vb_elt_first = 0;
nvc0->vb_elt_limit = ~0;
}
nvc0->instance_off = info->start_instance;
nvc0->instance_max = info->instance_count - 1;
@ -1029,7 +1034,7 @@ nvc0_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info,
PUSH_DATA (push, screen->uniform_bo->offset + NVC0_CB_AUX_INFO(0));
BEGIN_1IC0(push, NVC0_3D(CB_POS), 1 + 3);
PUSH_DATA (push, NVC0_CB_AUX_DRAW_INFO);
PUSH_DATA (push, info->index_bias);
PUSH_DATA (push, info->index_size ? info->index_bias : 0);
PUSH_DATA (push, info->start_instance);
PUSH_DATA (push, info->drawid);
}
@ -1111,7 +1116,7 @@ nvc0_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info,
nvc0_draw_stream_output(nvc0, info, indirect);
} else
if (info->index_size) {
bool shorten = info->max_index <= 65535;
bool shorten = info->index_bounds_valid && info->max_index <= 65535;
if (info->primitive_restart && info->restart_index > 65535)
shorten = false;