Mesa (master): vbo: fix a index buffer map failure with size = 0 in get_minmax_indices_gallium

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Jan 9 07:10:54 UTC 2021


Module: Mesa
Branch: master
Commit: c69b8fd65198d8779e8af30d7f28d68cef666fb0
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c69b8fd65198d8779e8af30d7f28d68cef666fb0

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Tue Jan  5 23:14:08 2021 -0500

vbo: fix a index buffer map failure with size = 0 in get_minmax_indices_gallium

Fixes: 85b6ba136bdc2db5 "st/mesa: implement Driver.DrawGallium callbacks

Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8345>

---

 src/mesa/state_tracker/st_draw.c | 5 ++++-
 src/mesa/vbo/vbo.h               | 2 +-
 src/mesa/vbo/vbo_minmax_index.c  | 7 ++++++-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index a1a123fbae1..c11934c0a39 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -238,7 +238,10 @@ prepare_indexed_draw(/* pass both st and ctx to reduce dereferences */
       /* Get index bounds for user buffers. */
       if (!info->index_bounds_valid &&
           st->draw_needs_minmax_index) {
-         vbo_get_minmax_indices_gallium(ctx, info, draws, num_draws);
+         /* Return if this fails, which means all draws have count == 0. */
+         if (!vbo_get_minmax_indices_gallium(ctx, info, draws, num_draws))
+            return false;
+
          info->index_bounds_valid = true;
       }
 
diff --git a/src/mesa/vbo/vbo.h b/src/mesa/vbo/vbo.h
index d0b0b3e26ab..e946fd5356a 100644
--- a/src/mesa/vbo/vbo.h
+++ b/src/mesa/vbo/vbo.h
@@ -256,7 +256,7 @@ vbo_get_minmax_indices(struct gl_context *ctx, const struct _mesa_prim *prim,
                        bool primitive_restart,
                        unsigned restart_index);
 
-void
+bool
 vbo_get_minmax_indices_gallium(struct gl_context *ctx,
                                struct pipe_draw_info *info,
                                const struct pipe_draw_start_count *draws,
diff --git a/src/mesa/vbo/vbo_minmax_index.c b/src/mesa/vbo/vbo_minmax_index.c
index 97412daea42..94608a3ff86 100644
--- a/src/mesa/vbo/vbo_minmax_index.c
+++ b/src/mesa/vbo/vbo_minmax_index.c
@@ -398,7 +398,7 @@ vbo_get_minmax_indices(struct gl_context *ctx,
 /**
  * Same as vbo_get_minmax_index, but using gallium draw structures.
  */
-void
+bool
 vbo_get_minmax_indices_gallium(struct gl_context *ctx,
                                struct pipe_draw_info *info,
                                const struct pipe_draw_start_count *draws,
@@ -417,6 +417,9 @@ vbo_get_minmax_indices_gallium(struct gl_context *ctx,
          i++;
       }
 
+      if (!draw.count)
+         continue;
+
       unsigned tmp_min, tmp_max;
       vbo_get_minmax_index(ctx, info->has_user_indices ?
                               NULL : info->index.gl_bo,
@@ -428,4 +431,6 @@ vbo_get_minmax_indices_gallium(struct gl_context *ctx,
       info->min_index = MIN2(info->min_index, tmp_min);
       info->max_index = MAX2(info->max_index, tmp_max);
    }
+
+   return info->min_index <= info->max_index;
 }



More information about the mesa-commit mailing list