draw: simplify index buffer specification
authorBrian Paul <brianp@vmware.com>
Fri, 25 May 2012 15:44:53 +0000 (09:44 -0600)
committerBrian Paul <brianp@vmware.com>
Thu, 31 May 2012 15:40:35 +0000 (09:40 -0600)
Replace draw_set_index_buffer() and draw_set_mapped_index_buffer() with
draw_set_indexes() which simply takes a pointer and an index size.

15 files changed:
src/gallium/auxiliary/draw/draw_context.c
src/gallium/auxiliary/draw/draw_context.h
src/gallium/auxiliary/draw/draw_private.h
src/gallium/auxiliary/draw/draw_pt.c
src/gallium/auxiliary/draw/draw_pt_vsplit_tmp.h
src/gallium/drivers/i915/i915_context.c
src/gallium/drivers/i915/i915_state.c
src/gallium/drivers/llvmpipe/lp_draw_arrays.c
src/gallium/drivers/llvmpipe/lp_state_vertex.c
src/gallium/drivers/nv30/nv30_draw.c
src/gallium/drivers/r300/r300_state.c
src/gallium/drivers/softpipe/sp_draw_arrays.c
src/gallium/drivers/softpipe/sp_state_vertex.c
src/gallium/drivers/svga/svga_swtnl_draw.c
src/mesa/state_tracker/st_draw_feedback.c

index ad49ce733acf259fac4578e8f47b22a2d13486c3..2eae204ff2c28cf00a16daced3f96b9b6134b888 100644 (file)
@@ -627,25 +627,23 @@ void draw_set_render( struct draw_context *draw,
 }
 
 
-void
-draw_set_index_buffer(struct draw_context *draw,
-                      const struct pipe_index_buffer *ib)
-{
-   if (ib)
-      memcpy(&draw->pt.index_buffer, ib, sizeof(draw->pt.index_buffer));
-   else
-      memset(&draw->pt.index_buffer, 0, sizeof(draw->pt.index_buffer));
-}
-
-
 /**
- * Tell drawing context where to find mapped index/element buffer.
+ * Tell the draw module where vertex indexes/elements are located, and
+ * their size (in bytes).
+ *
+ * Note: the caller must apply the pipe_index_buffer::offset value to
+ * the address.  The draw module doesn't do that.
  */
 void
-draw_set_mapped_index_buffer(struct draw_context *draw,
-                             const void *elements)
-{
-    draw->pt.user.elts = elements;
+draw_set_indexes(struct draw_context *draw,
+                 const void *elements, unsigned elem_size)
+{
+   assert(elem_size == 0 ||
+          elem_size == 1 ||
+          elem_size == 2 ||
+          elem_size == 4);
+   draw->pt.user.elts = elements;
+   draw->pt.user.eltSize = elem_size;
 }
 
 
index f3a3f23232280d162ca0cbf502466dd61a4fd1e6..4cd0caf3296feac8969fa465611cf0b47e9c9e09 100644 (file)
@@ -208,11 +208,8 @@ void draw_set_vertex_elements(struct draw_context *draw,
                              unsigned count,
                               const struct pipe_vertex_element *elements);
 
-void draw_set_index_buffer(struct draw_context *draw,
-                           const struct pipe_index_buffer *ib);
-
-void draw_set_mapped_index_buffer(struct draw_context *draw,
-                                  const void *elements);
+void draw_set_indexes(struct draw_context *draw,
+                      const void *elements, unsigned elem_size);
 
 void draw_set_mapped_vertex_buffer(struct draw_context *draw,
                                    unsigned attr, const void *buffer);
index 9e6380341dadbaad77a461c1ffd62cb818d2481c..d85deeea7f552c7479c3541dcadb3912f331ad27 100644 (file)
@@ -169,8 +169,6 @@ struct draw_context
       struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS];
       unsigned nr_vertex_elements;
 
-      struct pipe_index_buffer index_buffer;
-
       /* user-space vertex data, buffers */
       struct {
          /** vertex element/index buffer (ex: glDrawElements) */
index 2c4edc0f9464cc671d4128e6f74cfdb51d7f5474..5b6eaa739d04ac5ad04ab7bbb1d28e581ad414de 100644 (file)
@@ -232,28 +232,24 @@ draw_print_arrays(struct draw_context *draw, uint prim, int start, uint count)
       uint j;
 
       if (draw->pt.user.eltSize) {
-         const char *elts;
-
          /* indexed arrays */
-         elts = (const char *) draw->pt.user.elts;
-         elts += draw->pt.index_buffer.offset;
 
          switch (draw->pt.user.eltSize) {
          case 1:
             {
-               const ubyte *elem = (const ubyte *) elts;
+               const ubyte *elem = (const ubyte *) draw->pt.user.elts;
                ii = elem[start + i];
             }
             break;
          case 2:
             {
-               const ushort *elem = (const ushort *) elts;
+               const ushort *elem = (const ushort *) draw->pt.user.elts;
                ii = elem[start + i];
             }
             break;
          case 4:
             {
-               const uint *elem = (const uint *) elts;
+               const uint *elem = (const uint *) draw->pt.user.elts;
                ii = elem[start + i];
             }
             break;
@@ -368,28 +364,25 @@ draw_pt_arrays_restart(struct draw_context *draw,
 
    if (draw->pt.user.elts) {
       /* indexed prims (draw_elements) */
-      const char *elts =
-         (const char *) draw->pt.user.elts + draw->pt.index_buffer.offset;
-
       cur_start = start;
       cur_count = 0;
 
       switch (draw->pt.user.eltSize) {
       case 1:
          {
-            const ubyte *elt_ub = (const ubyte *) elts;
+            const ubyte *elt_ub = (const ubyte *) draw->pt.user.elts;
             PRIM_RESTART_LOOP(elt_ub);
          }
          break;
       case 2:
          {
-            const ushort *elt_us = (const ushort *) elts;
+            const ushort *elt_us = (const ushort *) draw->pt.user.elts;
             PRIM_RESTART_LOOP(elt_us);
          }
          break;
       case 4:
          {
-            const uint *elt_ui = (const uint *) elts;
+            const uint *elt_ui = (const uint *) draw->pt.user.elts;
             PRIM_RESTART_LOOP(elt_ui);
          }
          break;
@@ -469,9 +462,6 @@ draw_vbo(struct draw_context *draw,
    if (info->indexed)
       assert(draw->pt.user.elts);
 
-   draw->pt.user.eltSize =
-      (info->indexed) ? draw->pt.index_buffer.index_size : 0;
-
    draw->pt.user.eltBias = info->index_bias;
    draw->pt.user.min_index = info->min_index;
    draw->pt.user.max_index = info->max_index;
index bb3cbf80ad76980be4614f74713e1b842035da17..98a4668efb79313e1139d5f9a19c39ad4ce0a374 100644 (file)
@@ -38,8 +38,7 @@ CONCAT(vsplit_primitive_, ELT_TYPE)(struct vsplit_frontend *vsplit,
                                     unsigned istart, unsigned icount)
 {
    struct draw_context *draw = vsplit->draw;
-   const ELT_TYPE *ib = (const ELT_TYPE *)
-      ((const char *) draw->pt.user.elts + draw->pt.index_buffer.offset);
+   const ELT_TYPE *ib = (const ELT_TYPE *) draw->pt.user.elts;
    const unsigned min_index = draw->pt.user.min_index;
    const unsigned max_index = draw->pt.user.max_index;
    const int elt_bias = draw->pt.user.eltBias;
@@ -128,8 +127,7 @@ CONCAT(vsplit_segment_cache_, ELT_TYPE)(struct vsplit_frontend *vsplit,
                                         boolean close, unsigned iclose)
 {
    struct draw_context *draw = vsplit->draw;
-   const ELT_TYPE *ib = (const ELT_TYPE *)
-      ((const char *) draw->pt.user.elts + draw->pt.index_buffer.offset);
+   const ELT_TYPE *ib = (const ELT_TYPE *) draw->pt.user.elts;
    const int ibias = draw->pt.user.eltBias;
    unsigned i;
 
index f3c7b30527c23da61c64498468da84c5152d9b14..988d659151981396624093ac88cee0bb6303d9c0 100644 (file)
@@ -71,8 +71,10 @@ i915_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
       mapped_indices = i915->index_buffer.user_buffer;
       if (!mapped_indices)
          mapped_indices = i915_buffer(i915->index_buffer.buffer)->data;
+      draw_set_indexes(draw,
+                       (ubyte *) mapped_indices + i915->index_buffer.offset,
+                       i915->index_buffer.index_size);
    }
-   draw_set_mapped_index_buffer(draw, mapped_indices);
 
    if (i915->constants[PIPE_SHADER_VERTEX])
       draw_set_mapped_constant_buffer(draw, PIPE_SHADER_VERTEX, 0,
@@ -91,7 +93,7 @@ i915_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
    draw_vbo(i915->draw, info);
 
    if (mapped_indices)
-      draw_set_mapped_index_buffer(draw, NULL);
+      draw_set_indexes(draw, NULL, 0);
 
    if (i915->num_vertex_sampler_views > 0)
       i915_cleanup_vertex_sampling(i915);
index 1ff53884ada3bdb1eaf6dc0b2e44d405cc5a5762..f4b5d6f37b759e40b8c61180c452a5b4f7535dd7 100644 (file)
@@ -1048,9 +1048,6 @@ static void i915_set_index_buffer(struct pipe_context *pipe,
       memcpy(&i915->index_buffer, ib, sizeof(i915->index_buffer));
    else
       memset(&i915->index_buffer, 0, sizeof(i915->index_buffer));
-
-   /* pass-through to draw module */
-   draw_set_index_buffer(i915->draw, ib);
 }
 
 static void
index 225b80e3dfbac8c56f5f579ec669291345a150f4..96259d7144f4be13899b4ccca6f35d1a75ba6a46 100644 (file)
@@ -78,9 +78,11 @@ llvmpipe_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
       mapped_indices = lp->index_buffer.user_buffer;
       if (!mapped_indices)
          mapped_indices = llvmpipe_resource_data(lp->index_buffer.buffer);
-   }
 
-   draw_set_mapped_index_buffer(draw, mapped_indices);
+      draw_set_indexes(draw,
+                       (ubyte *) mapped_indices + lp->index_buffer.offset,
+                       lp->index_buffer.index_size);
+   }
 
    llvmpipe_prepare_vertex_sampling(lp,
                                     lp->num_vertex_sampler_views,
@@ -96,7 +98,7 @@ llvmpipe_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
       draw_set_mapped_vertex_buffer(draw, i, NULL);
    }
    if (mapped_indices) {
-      draw_set_mapped_index_buffer(draw, NULL);
+      draw_set_indexes(draw, NULL, 0);
    }
    llvmpipe_cleanup_vertex_sampling(lp);
 
index a62cfd553343d6d0da583729ab4df80b2af71ea0..4a74cd7c9d41c3cf0bf9d377483d77c3826f1ae6 100644 (file)
@@ -102,8 +102,6 @@ llvmpipe_set_index_buffer(struct pipe_context *pipe,
       memcpy(&llvmpipe->index_buffer, ib, sizeof(llvmpipe->index_buffer));
    else
       memset(&llvmpipe->index_buffer, 0, sizeof(llvmpipe->index_buffer));
-
-   draw_set_index_buffer(llvmpipe->draw, ib);
 }
 
 void
index 29e63953838960f2a3b5292d2e2413fe2f014acc..46e8536281595413995266e288b5e04ad798f289 100644 (file)
@@ -417,10 +417,11 @@ nv30_render_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
          pipe_buffer_map(pipe, nv30->idxbuf.buffer,
                                   PIPE_TRANSFER_UNSYNCHRONIZED |
                                   PIPE_TRANSFER_READ, &transferi);
-      draw_set_index_buffer(draw, &nv30->idxbuf);
-      draw_set_mapped_index_buffer(draw, map);
+      draw_set_indexes(draw,
+                       (ubyte *) map + nv30->idxbuf.offset,
+                       nv30->idxbuf.index_size);
    } else {
-      draw_set_mapped_index_buffer(draw, NULL);
+      draw_set_indexes(draw, NULL, 0);
    }
 
    draw_vbo(draw, info);
index e025c2fcd1e2d7eb1c84b423ac49ab6098844297..6f9feb105640934a88e1c9a0063f0b01693f54b2 100644 (file)
@@ -1649,16 +1649,16 @@ static void r300_set_index_buffer_swtcl(struct pipe_context* pipe,
 {
     struct r300_context* r300 = r300_context(pipe);
 
-    draw_set_index_buffer(r300->draw, ib);
-
     if (ib) {
+        const void *buf = NULL;
         if (ib->user_buffer) {
-            draw_set_mapped_index_buffer(r300->draw,
-                                         ib->user_buffer);
+            buf = ib->user_buffer;
         } else if (ib->buffer) {
-            draw_set_mapped_index_buffer(r300->draw,
-                r300_resource(ib->buffer)->malloced_buffer);
+            buf = r300_resource(ib->buffer)->malloced_buffer;
         }
+        draw_set_indexes(r300->draw,
+                         (const ubyte *) buf + ib->offset,
+                         ib->index_size);
     }
 }
 
index 7a2274565d5121e822157cf91a37530d2ddaa31f..f9fc923a184a8330df667d6e01e47c05041e4507 100644 (file)
@@ -88,9 +88,12 @@ softpipe_draw_vbo(struct pipe_context *pipe,
       mapped_indices = sp->index_buffer.user_buffer;
       if (!mapped_indices)
          mapped_indices = softpipe_resource(sp->index_buffer.buffer)->data;
+
+      draw_set_indexes(draw,
+                       (ubyte *) mapped_indices + sp->index_buffer.offset,
+                       sp->index_buffer.index_size);
    }
 
-   draw_set_mapped_index_buffer(draw, mapped_indices);
 
    for (i = 0; i < sp->num_so_targets; i++) {
       void *buf = softpipe_resource(sp->so_targets[i]->target.buffer)->data;
@@ -108,7 +111,7 @@ softpipe_draw_vbo(struct pipe_context *pipe,
       draw_set_mapped_vertex_buffer(draw, i, NULL);
    }
    if (mapped_indices) {
-      draw_set_mapped_index_buffer(draw, NULL);
+      draw_set_indexes(draw, NULL, 0);
    }
 
    draw_set_mapped_so_targets(draw, 0, NULL);
index 1dbd79807d0e7f466a535094ade59f9d489039aa..95acecd3be4d31ae7e876191b63ba69bd2c39f90 100644 (file)
@@ -106,8 +106,6 @@ softpipe_set_index_buffer(struct pipe_context *pipe,
       memcpy(&softpipe->index_buffer, ib, sizeof(softpipe->index_buffer));
    else
       memset(&softpipe->index_buffer, 0, sizeof(softpipe->index_buffer));
-
-   draw_set_index_buffer(softpipe->draw, ib);
 }
 
 
index bb6870f6572e9aeb8b5001b49f51d673e4805f32..212f11a8230805ed88b7a94e80324e2923d83f53 100644 (file)
@@ -76,17 +76,16 @@ svga_swtnl_draw_vbo(struct svga_context *svga,
       }
    }
 
-   /* TODO move this to update_swtnl_draw */
-   draw_set_index_buffer(draw, &svga->curr.ib);
-
    /* Map index buffer, if present */
    map = NULL;
    if (info->indexed && svga->curr.ib.buffer) {
       map = pipe_buffer_map(&svga->pipe, svga->curr.ib.buffer,
                             PIPE_TRANSFER_READ,
                             &ib_transfer);
+      draw_set_indexes(draw,
+                       (const ubyte *) map + svga->curr.ib.offset,
+                       svga->curr.ib.index_size);
    }
-   draw_set_mapped_index_buffer(draw, map);
 
    if (svga->curr.cb[PIPE_SHADER_VERTEX]) {
       map = pipe_buffer_map(&svga->pipe,
@@ -119,7 +118,7 @@ svga_swtnl_draw_vbo(struct svga_context *svga,
 
    if (ib_transfer) {
       pipe_buffer_unmap(&svga->pipe, ib_transfer);
-      draw_set_mapped_index_buffer(draw, NULL);
+      draw_set_indexes(draw, NULL, 0);
    }
 
    if (svga->curr.cb[PIPE_SHADER_VERTEX]) {
index 4209fb214f8c659a4f2943d188f541f1ee207e05..820918e51e30462e0165ad14feade3b13cfa605d 100644 (file)
@@ -232,8 +232,9 @@ st_feedback_draw_vbo(struct gl_context *ctx,
          mapped_indices = ib->ptr;
       }
 
-      draw_set_index_buffer(draw, &ibuffer);
-      draw_set_mapped_index_buffer(draw, mapped_indices);
+      draw_set_indexes(draw,
+                       (ubyte *) mapped_indices + ibuffer.offset,
+                       ibuffer.index_size);
    }
 
    /* set the constant buffer */
@@ -252,9 +253,7 @@ st_feedback_draw_vbo(struct gl_context *ctx,
     * unmap vertex/index buffers
     */
    if (ib) {
-      draw_set_mapped_index_buffer(draw, NULL);
-      draw_set_index_buffer(draw, NULL);
-
+      draw_set_indexes(draw, NULL, 0);
       if (ib_transfer)
          pipe_buffer_unmap(pipe, ib_transfer);
       pipe_resource_reference(&ibuffer.buffer, NULL);