[Mesa-dev] [PATCH 3/3] draw/llvmpipe: allow indexed rendering without index buffer bound

Zack Rusin zackr at vmware.com
Tue Jul 23 09:20:51 PDT 2013


this is a wonky requirement of d3d10, which expects that if
indexed rendering call is issued without an indexed buffer
bound, the rendering should still happen but with all indices
set to 0.

Signed-off-by: Zack Rusin <zackr at vmware.com>
---
 src/gallium/auxiliary/draw/draw_private.h       |    5 +++--
 src/gallium/auxiliary/draw/draw_pt.c            |    4 +---
 src/gallium/auxiliary/draw/draw_pt_vsplit.c     |    3 ++-
 src/gallium/auxiliary/draw/draw_pt_vsplit_tmp.h |    6 +++---
 src/gallium/drivers/llvmpipe/lp_draw_arrays.c   |    2 +-
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_private.h b/src/gallium/auxiliary/draw/draw_private.h
index 868b6c7..dfb71c9 100644
--- a/src/gallium/auxiliary/draw/draw_private.h
+++ b/src/gallium/auxiliary/draw/draw_private.h
@@ -478,8 +478,9 @@ draw_stats_clipper_primitives(struct draw_context *draw,
  * If the index buffer would overflow we return the
  * maximum possible index.
  */
-#define DRAW_GET_IDX(_elts, _i)                   \
-   (((_i) >= draw->pt.user.eltMax) ? DRAW_MAX_FETCH_IDX : (_elts)[_i])
+#define DRAW_GET_IDX(_elts, _i)                 \
+   (!_elts ? (0) : \
+    (((_i) >= draw->pt.user.eltMax) ? DRAW_MAX_FETCH_IDX : (_elts)[_i]))
 
 /**
  * Return index of the given viewport clamping it
diff --git a/src/gallium/auxiliary/draw/draw_pt.c b/src/gallium/auxiliary/draw/draw_pt.c
index 5b16bc7..bf54f85 100644
--- a/src/gallium/auxiliary/draw/draw_pt.c
+++ b/src/gallium/auxiliary/draw/draw_pt.c
@@ -347,7 +347,7 @@ draw_print_arrays(struct draw_context *draw, uint prim, int start, uint count)
    do { \
       for (j = 0; j < count; j++) {               \
          i = draw_overflow_uadd(start, j, MAX_LOOP_IDX);  \
-         if (i < elt_max && elements[i] == info->restart_index) { \
+         if (i < elt_max && (elements && elements[i] == info->restart_index)) { \
             if (cur_count > 0) { \
                /* draw elts up to prev pos */ \
                draw_pt_arrays(draw, prim, cur_start, cur_count); \
@@ -471,8 +471,6 @@ draw_vbo(struct draw_context *draw,
    info = &resolved_info;
 
    assert(info->instance_count > 0);
-   if (info->indexed)
-      assert(draw->pt.user.elts);
 
    count = info->count;
 
diff --git a/src/gallium/auxiliary/draw/draw_pt_vsplit.c b/src/gallium/auxiliary/draw/draw_pt_vsplit.c
index 625505d..395a38c 100644
--- a/src/gallium/auxiliary/draw/draw_pt_vsplit.c
+++ b/src/gallium/auxiliary/draw/draw_pt_vsplit.c
@@ -116,7 +116,8 @@ vsplit_get_base_idx(struct vsplit_frontend *vsplit,
                     unsigned start, unsigned fetch, unsigned *ofbit)
 {
    struct draw_context *draw = vsplit->draw;
-   unsigned elt_idx = draw_overflow_uadd(start, fetch, MAX_ELT_IDX);
+   unsigned elt_idx = draw->pt.user.elts ? 
+      draw_overflow_uadd(start, fetch, MAX_ELT_IDX) : 0;
    if (ofbit)
       *ofbit = 0;
 
diff --git a/src/gallium/auxiliary/draw/draw_pt_vsplit_tmp.h b/src/gallium/auxiliary/draw/draw_pt_vsplit_tmp.h
index 5d72ac6..4f462c0 100644
--- a/src/gallium/auxiliary/draw/draw_pt_vsplit_tmp.h
+++ b/src/gallium/auxiliary/draw/draw_pt_vsplit_tmp.h
@@ -44,8 +44,8 @@ CONCAT(vsplit_primitive_, ELT_TYPE)(struct vsplit_frontend *vsplit,
    unsigned fetch_start, fetch_count;
    const ushort *draw_elts = NULL;
    unsigned i;
-   const unsigned start = istart;
-   const unsigned end = istart + icount;
+   const unsigned start = ib ? istart : 0;
+   const unsigned end = ib ? istart + icount : icount;
 
    /* If the index buffer overflows we'll need to run
     * through the normal paths */
@@ -55,7 +55,7 @@ CONCAT(vsplit_primitive_, ELT_TYPE)(struct vsplit_frontend *vsplit,
       return FALSE;
 
    /* use the ib directly */
-   if (min_index == 0 && sizeof(ib[0]) == sizeof(draw_elts[0])) {
+   if (ib && min_index == 0 && sizeof(ib[0]) == sizeof(draw_elts[0])) {
       if (icount > vsplit->max_vertices)
          return FALSE;
 
diff --git a/src/gallium/drivers/llvmpipe/lp_draw_arrays.c b/src/gallium/drivers/llvmpipe/lp_draw_arrays.c
index 4e23904..32d8f60 100644
--- a/src/gallium/drivers/llvmpipe/lp_draw_arrays.c
+++ b/src/gallium/drivers/llvmpipe/lp_draw_arrays.c
@@ -83,7 +83,7 @@ llvmpipe_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
    if (info->indexed) {
       unsigned available_space = ~0;
       mapped_indices = lp->index_buffer.user_buffer;
-      if (!mapped_indices) {
+      if (!mapped_indices && lp->index_buffer.buffer) {
          mapped_indices = llvmpipe_resource_data(lp->index_buffer.buffer);
          if (lp->index_buffer.buffer->width0 > lp->index_buffer.offset)
             available_space =
-- 
1.7.10.4


More information about the mesa-dev mailing list