draw: Implement index bias.
authorJosé Fonseca <jfonseca@vmware.com>
Mon, 19 Apr 2010 16:14:04 +0000 (18:14 +0200)
committerJosé Fonseca <jfonseca@vmware.com>
Mon, 19 Apr 2010 16:14:04 +0000 (18:14 +0200)
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.h
src/gallium/auxiliary/draw/draw_pt_varray_tmp_linear.h
src/gallium/auxiliary/draw/draw_pt_vcache.c
src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h

index 99f4e6dd2a8558c772e3c4e063f74d3302ace81d..b6c558ba9b14159bb6d57c670fd0d0d44e2db3a8 100644 (file)
@@ -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;
 }
index 1af4961716c55626ec1534c72197417e03349d2f..cfa0ad88d0a65b8a1fa506babeee9127fe34d083 100644 (file)
@@ -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,
index da64102d9d1ce7f56bff5fea8b150af2da7b2aec..33b0c196d4ebbd4aca572f741eff83e1de10ab56 100644 (file)
@@ -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;
          
index 43f6c5650a0f62969945f6fef0bba59ea16040df..aa1f7064a3a2c497b5470d4e66d7941c75623b83 100644 (file)
@@ -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 */
index c2797a759eecc87cfe67c6c9129196baa15d803f..3e3ea320cc0a0c2b5b1a03a4c41fa8778c8a1c03 100644 (file)
@@ -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 * );
index f0aec5febabdb0b518cd626c5f28661c08a713d7..a292346be957b92b55b72ea86d57a21c01bd874f 100644 (file)
@@ -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:
index 757c48745456d59db25a07084cb1a691d36f07df..a513188b918e4bc5b868570c04cddf75f7b4ca45 100644 (file)
@@ -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 );
 }
 
 
index 7cba8547f1583df966d4a6fde68d38882c8f4cbc..eedd31b7f859e59dbb7e6117637ed6f0028d87f1 100644 (file)
@@ -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);
             }
         }
       }