nouveau: fix handling draw info
authorMarek Olšák <marek.olsak@amd.com>
Sun, 22 Nov 2020 07:22:45 +0000 (02:22 -0500)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 5 Jan 2021 00:22:33 +0000 (19:22 -0500)
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>

src/gallium/drivers/nouveau/nv30/nv30_vbo.c
src/gallium/drivers/nouveau/nv50/nv50_push.c
src/gallium/drivers/nouveau/nv50/nv50_vbo.c
src/gallium/drivers/nouveau/nvc0/nvc0_vbo.c

index a041bf0..2812a70 100644 (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) {
index a7ec021..4af068e 100644 (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);
    }
index 1aaff44..26539b3 100644 (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) {
index 5cf0238..9b8c054 100644 (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;