Mesa (gallium-index-bias): draw: Implement index bias.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Mon Apr 19 16:22:35 UTC 2010


Module: Mesa
Branch: gallium-index-bias
Commit: 2197fac47cb1f87387820678357cc67c9a2536b9
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=2197fac47cb1f87387820678357cc67c9a2536b9

Author: José Fonseca <jfonseca at vmware.com>
Date:   Mon Apr 19 18:14:04 2010 +0200

draw: Implement index bias.

---

 src/gallium/auxiliary/draw/draw_context.c          |    4 +
 src/gallium/auxiliary/draw/draw_context.h          |    2 +
 src/gallium/auxiliary/draw/draw_private.h          |    1 +
 src/gallium/auxiliary/draw/draw_pt.c               |    6 ++-
 src/gallium/auxiliary/draw/draw_pt.h               |    1 +
 .../auxiliary/draw/draw_pt_varray_tmp_linear.h     |    3 +
 src/gallium/auxiliary/draw/draw_pt_vcache.c        |   17 +++--
 src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h    |   77 ++++++++++----------
 8 files changed, 65 insertions(+), 46 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_context.c b/src/gallium/auxiliary/draw/draw_context.c
index 99f4e6d..b6c558b 100644
--- a/src/gallium/auxiliary/draw/draw_context.c
+++ b/src/gallium/auxiliary/draw/draw_context.c
@@ -427,12 +427,14 @@ void draw_set_render( struct draw_context *draw,
 void
 draw_set_mapped_element_buffer_range( struct draw_context *draw,
                                       unsigned eltSize,
+                                      int eltBias,
                                       unsigned min_index,
                                       unsigned max_index,
                                       const void *elements )
 {
    draw->pt.user.elts = elements;
    draw->pt.user.eltSize = eltSize;
+   draw->pt.user.eltBias = eltBias;
    draw->pt.user.min_index = min_index;
    draw->pt.user.max_index = max_index;
 }
@@ -441,10 +443,12 @@ draw_set_mapped_element_buffer_range( struct draw_context *draw,
 void
 draw_set_mapped_element_buffer( struct draw_context *draw,
                                 unsigned eltSize,
+                                int eltBias,
                                 const void *elements )
 {
    draw->pt.user.elts = elements;
    draw->pt.user.eltSize = eltSize;
+   draw->pt.user.eltBias = eltBias;
    draw->pt.user.min_index = 0;
    draw->pt.user.max_index = 0xffffffff;
 }
diff --git a/src/gallium/auxiliary/draw/draw_context.h b/src/gallium/auxiliary/draw/draw_context.h
index 1af4961..cfa0ad8 100644
--- a/src/gallium/auxiliary/draw/draw_context.h
+++ b/src/gallium/auxiliary/draw/draw_context.h
@@ -139,12 +139,14 @@ void draw_set_vertex_elements(struct draw_context *draw,
 void
 draw_set_mapped_element_buffer_range( struct draw_context *draw,
                                       unsigned eltSize,
+                                      int eltBias,
                                       unsigned min_index,
                                       unsigned max_index,
                                       const void *elements );
 
 void draw_set_mapped_element_buffer( struct draw_context *draw,
                                      unsigned eltSize, 
+                                     int eltBias,
                                      const void *elements );
 
 void draw_set_mapped_vertex_buffer(struct draw_context *draw,
diff --git a/src/gallium/auxiliary/draw/draw_private.h b/src/gallium/auxiliary/draw/draw_private.h
index da64102..33b0c19 100644
--- a/src/gallium/auxiliary/draw/draw_private.h
+++ b/src/gallium/auxiliary/draw/draw_private.h
@@ -148,6 +148,7 @@ struct draw_context
          const void *elts;
          /** bytes per index (0, 1, 2 or 4) */
          unsigned eltSize;
+         int eltBias;
          unsigned min_index;
          unsigned max_index;
          
diff --git a/src/gallium/auxiliary/draw/draw_pt.c b/src/gallium/auxiliary/draw/draw_pt.c
index 43f6c56..aa1f706 100644
--- a/src/gallium/auxiliary/draw/draw_pt.c
+++ b/src/gallium/auxiliary/draw/draw_pt.c
@@ -111,6 +111,7 @@ draw_pt_arrays(struct draw_context *draw,
    frontend->run(frontend, 
                  draw_pt_elt_func(draw),
                  draw_pt_elt_ptr(draw, start),
+                 draw->pt.user.eltBias,
                  count);
 
    frontend->finish( frontend );
@@ -222,8 +223,11 @@ draw_print_arrays(struct draw_context *draw, uint prim, int start, uint count)
             break;
          default:
             assert(0);
+            return;
          }
-         debug_printf("Element[%u + %u] -> Vertex %u:\n", start, i, ii);
+         ii += draw->pt.user.eltBias;
+         debug_printf("Element[%u + %u] + %i -> Vertex %u:\n", start, i,
+                      draw->pt.user.eltBias, ii);
       }
       else {
          /* non-indexed arrays */
diff --git a/src/gallium/auxiliary/draw/draw_pt.h b/src/gallium/auxiliary/draw/draw_pt.h
index c2797a7..3e3ea32 100644
--- a/src/gallium/auxiliary/draw/draw_pt.h
+++ b/src/gallium/auxiliary/draw/draw_pt.h
@@ -67,6 +67,7 @@ struct draw_pt_front_end {
    void (*run)( struct draw_pt_front_end *,
                 pt_elt_func elt_func,
                 const void *elt_ptr,
+                int elt_bias,
                 unsigned count );
 
    void (*finish)( struct draw_pt_front_end * );
diff --git a/src/gallium/auxiliary/draw/draw_pt_varray_tmp_linear.h b/src/gallium/auxiliary/draw/draw_pt_varray_tmp_linear.h
index f0aec5f..a292346 100644
--- a/src/gallium/auxiliary/draw/draw_pt_varray_tmp_linear.h
+++ b/src/gallium/auxiliary/draw/draw_pt_varray_tmp_linear.h
@@ -6,6 +6,7 @@ static unsigned trim( unsigned count, unsigned first, unsigned incr )
 static void FUNC(struct draw_pt_front_end *frontend,
                  pt_elt_func get_elt,
                  const void *elts,
+                 int elt_bias,
                  unsigned count)
 {
    struct varray_frontend *varray = (struct varray_frontend *)frontend;
@@ -14,6 +15,8 @@ static void FUNC(struct draw_pt_front_end *frontend,
    unsigned j;
    unsigned first, incr;
 
+   assert(elt_bias == 0);
+
    draw_pt_split_prim(varray->input_prim, &first, &incr);
    
    /* Sanitize primitive length:
diff --git a/src/gallium/auxiliary/draw/draw_pt_vcache.c b/src/gallium/auxiliary/draw/draw_pt_vcache.c
index 757c487..a513188 100644
--- a/src/gallium/auxiliary/draw/draw_pt_vcache.c
+++ b/src/gallium/auxiliary/draw/draw_pt_vcache.c
@@ -329,6 +329,7 @@ static INLINE void
 vcache_check_run( struct draw_pt_front_end *frontend, 
                   pt_elt_func get_elt,
                   const void *elts,
+                  int elt_bias,
                   unsigned draw_count )
 {
    struct vcache_frontend *vcache = (struct vcache_frontend *)frontend; 
@@ -362,8 +363,9 @@ vcache_check_run( struct draw_pt_front_end *frontend,
    }
 
 
-   if (min_index == 0 &&
-       index_size == 2) 
+   if (elt_bias <= 0 &&
+       min_index == (unsigned)-elt_bias &&
+       index_size == 2)
    {
       transformed_elts = (const ushort *)elts;
    }
@@ -373,7 +375,8 @@ vcache_check_run( struct draw_pt_front_end *frontend,
       if (!storage)
          goto fail;
       
-      if (min_index == 0) {
+      if (elt_bias <= 0 &&
+          min_index == (unsigned)-elt_bias) {
          switch(index_size) {
          case 1:
             translate_ubyte_elts( (const ubyte *)elts,
@@ -404,21 +407,21 @@ vcache_check_run( struct draw_pt_front_end *frontend,
          case 1:
             rebase_ubyte_elts( (const ubyte *)elts,
                                   draw_count,
-                                  0 - (int)min_index,
+                                  elt_bias - (int)min_index,
                                   storage );
             break;
 
          case 2:
             rebase_ushort_elts( (const ushort *)elts,
                                    draw_count,
-                                   0 - (int)min_index,
+                                   elt_bias - (int)min_index,
                                    storage );
             break;
 
          case 4:
             rebase_uint_elts( (const uint *)elts,
                                  draw_count,
-                                 0 - (int)min_index,
+                                 elt_bias - (int)min_index,
                                  storage );
             break;
 
@@ -447,7 +450,7 @@ vcache_check_run( struct draw_pt_front_end *frontend,
                 fetch_count, draw_count);
 
  fail:
-   vcache_run( frontend, get_elt, elts, draw_count );
+   vcache_run( frontend, get_elt, elts, elt_bias, draw_count );
 }
 
 
diff --git a/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h b/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h
index 7cba854..eedd31b 100644
--- a/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h
+++ b/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h
@@ -3,6 +3,7 @@
 static void FUNC( struct draw_pt_front_end *frontend, 
                   pt_elt_func get_elt,
                   const void *elts,
+                  int elt_bias,
                   unsigned count )
 {
    struct vcache_frontend *vcache = (struct vcache_frontend *)frontend;
@@ -20,7 +21,7 @@ static void FUNC( struct draw_pt_front_end *frontend,
    case PIPE_PRIM_POINTS:
       for (i = 0; i < count; i ++) {
 	 POINT( vcache,
-                get_elt(elts, i + 0) );
+                get_elt(elts, i + 0) + elt_bias );
       }
       break;
 
@@ -28,8 +29,8 @@ static void FUNC( struct draw_pt_front_end *frontend,
       for (i = 0; i+1 < count; i += 2) {
          LINE( vcache, 
                DRAW_PIPE_RESET_STIPPLE,
-               get_elt(elts, i + 0),
-               get_elt(elts, i + 1));
+               get_elt(elts, i + 0) + elt_bias,
+               get_elt(elts, i + 1) + elt_bias);
       }
       break;
 
@@ -40,14 +41,14 @@ static void FUNC( struct draw_pt_front_end *frontend,
          for (i = 1; i < count; i++, flags = 0) {
             LINE( vcache, 
                   flags,
-                  get_elt(elts, i - 1),
-                  get_elt(elts, i ));
+                  get_elt(elts, i - 1) + elt_bias,
+                  get_elt(elts, i ) + elt_bias);
          }
 
 	 LINE( vcache, 
                flags,
-               get_elt(elts, i - 1),
-               get_elt(elts, 0 ));
+               get_elt(elts, i - 1) + elt_bias,
+               get_elt(elts, 0 ) + elt_bias);
       }
       break;
 
@@ -56,8 +57,8 @@ static void FUNC( struct draw_pt_front_end *frontend,
       for (i = 1; i < count; i++, flags = 0) {
          LINE( vcache, 
                flags,
-               get_elt(elts, i - 1),
-               get_elt(elts, i ));
+               get_elt(elts, i - 1) + elt_bias,
+               get_elt(elts, i ) + elt_bias);
       }
       break;
 
@@ -65,9 +66,9 @@ static void FUNC( struct draw_pt_front_end *frontend,
       for (i = 0; i+2 < count; i += 3) {
          TRIANGLE( vcache,
                    DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL, 
-                   get_elt(elts, i + 0),
-                   get_elt(elts, i + 1),
-                   get_elt(elts, i + 2 ));
+                   get_elt(elts, i + 0) + elt_bias,
+                   get_elt(elts, i + 1) + elt_bias,
+                   get_elt(elts, i + 2 ) + elt_bias);
       }
       break;
 
@@ -76,18 +77,18 @@ static void FUNC( struct draw_pt_front_end *frontend,
          for (i = 0; i+2 < count; i++) {
             TRIANGLE( vcache,
                       DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL, 
-                      get_elt(elts, i + 0),
-                      get_elt(elts, i + 1 + (i&1)),
-                      get_elt(elts, i + 2 - (i&1)));
+                      get_elt(elts, i + 0) + elt_bias,
+                      get_elt(elts, i + 1 + (i&1) + elt_bias),
+                      get_elt(elts, i + 2 - (i&1) + elt_bias));
          }
       }
       else {
          for (i = 0; i+2 < count; i++) {
             TRIANGLE( vcache,
                       DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL, 
-                      get_elt(elts, i + 0 + (i&1)),
-                      get_elt(elts, i + 1 - (i&1)),
-                      get_elt(elts, i + 2 ));
+                      get_elt(elts, i + 0 + (i&1) + elt_bias),
+                      get_elt(elts, i + 1 - (i&1) + elt_bias),
+                      get_elt(elts, i + 2 ) + elt_bias);
          }
       }
       break;
@@ -98,18 +99,18 @@ static void FUNC( struct draw_pt_front_end *frontend,
             for (i = 0; i+2 < count; i++) {
                TRIANGLE( vcache,
                          DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL, 
-                         get_elt(elts, i + 1),
-                         get_elt(elts, i + 2),
-                         get_elt(elts, 0 ));
+                         get_elt(elts, i + 1) + elt_bias,
+                         get_elt(elts, i + 2) + elt_bias,
+                         get_elt(elts, 0 ) + elt_bias);
             }
          }
          else {
             for (i = 0; i+2 < count; i++) {
                TRIANGLE( vcache,
                          DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL, 
-                         get_elt(elts, 0),
-                         get_elt(elts, i + 1),
-                         get_elt(elts, i + 2 ));
+                         get_elt(elts, 0) + elt_bias,
+                         get_elt(elts, i + 1) + elt_bias,
+                         get_elt(elts, i + 2 ) + elt_bias);
             }
          }
       }
@@ -119,20 +120,20 @@ static void FUNC( struct draw_pt_front_end *frontend,
    case PIPE_PRIM_QUADS:
       for (i = 0; i+3 < count; i += 4) {
          QUAD( vcache,
-               get_elt(elts, i + 0),
-               get_elt(elts, i + 1),
-               get_elt(elts, i + 2),
-               get_elt(elts, i + 3) );
+               get_elt(elts, i + 0) + elt_bias,
+               get_elt(elts, i + 1) + elt_bias,
+               get_elt(elts, i + 2) + elt_bias,
+               get_elt(elts, i + 3) + elt_bias );
       }
       break;
 
    case PIPE_PRIM_QUAD_STRIP:
       for (i = 0; i+3 < count; i += 2) {
          QUAD( vcache,
-               get_elt(elts, i + 2),
-               get_elt(elts, i + 0),
-               get_elt(elts, i + 1),
-               get_elt(elts, i + 3) );
+               get_elt(elts, i + 2) + elt_bias,
+               get_elt(elts, i + 0) + elt_bias,
+               get_elt(elts, i + 1) + elt_bias,
+               get_elt(elts, i + 3) + elt_bias );
       }
       break;
 
@@ -165,16 +166,16 @@ static void FUNC( struct draw_pt_front_end *frontend,
             if (flatfirst) {
                TRIANGLE( vcache,
                          flags,
-                         get_elt(elts, 0),
-                         get_elt(elts, i + 1),
-                         get_elt(elts, i + 2) );
+                         get_elt(elts, 0) + elt_bias,
+                         get_elt(elts, i + 1) + elt_bias,
+                         get_elt(elts, i + 2) + elt_bias );
             }
             else {
                TRIANGLE( vcache,
                          flags,
-                         get_elt(elts, i + 1),
-                         get_elt(elts, i + 2),
-                         get_elt(elts, 0));
+                         get_elt(elts, i + 1) + elt_bias,
+                         get_elt(elts, i + 2) + elt_bias,
+                         get_elt(elts, 0) + elt_bias);
             }
 	 }
       }




More information about the mesa-commit mailing list