From cbdc00ac3a6170e61d36233560e5b3ce83098906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sun, 22 Nov 2020 02:22:45 -0500 Subject: [PATCH] nouveau: fix handling draw info index_bias is undefined if index_size == 0. index bounds are undefined if index_bounds_valid == false. Part-of: --- src/gallium/drivers/nouveau/nv30/nv30_vbo.c | 12 +++++++++--- src/gallium/drivers/nouveau/nv50/nv50_push.c | 4 ++-- src/gallium/drivers/nouveau/nv50/nv50_vbo.c | 11 ++++++++--- src/gallium/drivers/nouveau/nvc0/nvc0_vbo.c | 13 +++++++++---- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/gallium/drivers/nouveau/nv30/nv30_vbo.c b/src/gallium/drivers/nouveau/nv30/nv30_vbo.c index a041bf022e9..2812a7021ba 100644 --- a/src/gallium/drivers/nouveau/nv30/nv30_vbo.c +++ b/src/gallium/drivers/nouveau/nv30/nv30_vbo.c @@ -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) { diff --git a/src/gallium/drivers/nouveau/nv50/nv50_push.c b/src/gallium/drivers/nouveau/nv50/nv50_push.c index a7ec021e882..4af068efba4 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_push.c +++ b/src/gallium/drivers/nouveau/nv50/nv50_push.c @@ -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); } diff --git a/src/gallium/drivers/nouveau/nv50/nv50_vbo.c b/src/gallium/drivers/nouveau/nv50/nv50_vbo.c index 1aaff44dbaf..26539b38fe6 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_vbo.c +++ b/src/gallium/drivers/nouveau/nv50/nv50_vbo.c @@ -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) { diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_vbo.c b/src/gallium/drivers/nouveau/nvc0/nvc0_vbo.c index 5cf02387da3..9b8c05450af 100644 --- a/src/gallium/drivers/nouveau/nvc0/nvc0_vbo.c +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_vbo.c @@ -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;