draw: add stream output decomposition file
[mesa.git] / src / gallium / auxiliary / draw / draw_pt_vcache.c
index a513188b918e4bc5b868570c04cddf75f7b4ca45..914c87a9dc485a38c8d63c4a6a7f51d8431a8b57 100644 (file)
@@ -54,7 +54,7 @@ struct vcache_frontend {
    unsigned draw_count;
    unsigned fetch_count;
    unsigned fetch_max;
-   
+
    struct draw_pt_middle_end *middle;
 
    unsigned input_prim;
@@ -64,14 +64,15 @@ struct vcache_frontend {
    unsigned opt;
 };
 
-static INLINE void 
+static INLINE void
 vcache_flush( struct vcache_frontend *vcache )
 {
    if (vcache->middle_prim != vcache->output_prim) {
       vcache->middle_prim = vcache->output_prim;
-      vcache->middle->prepare( vcache->middle, 
-                               vcache->middle_prim, 
-                               vcache->opt, 
+      vcache->middle->prepare( vcache->middle,
+                               vcache->input_prim,
+                               vcache->middle_prim,
+                               vcache->opt,
                                &vcache->fetch_max );
    }
 
@@ -183,8 +184,16 @@ vcache_quad( struct vcache_frontend *vcache,
              unsigned i2,
              unsigned i3 )
 {
-   vcache_triangle( vcache, i0, i1, i3 );
-   vcache_triangle( vcache, i1, i2, i3 );
+   if (vcache->draw->rasterizer->flatshade_first) {
+      /* pass last quad vertex as first triangle vertex */
+      vcache_triangle( vcache, i3, i0, i1 );
+      vcache_triangle( vcache, i3, i1, i2 );
+   }
+   else {
+      /* pass last quad vertex as last triangle vertex */
+      vcache_triangle( vcache, i0, i1, i3 );
+      vcache_triangle( vcache, i1, i2, i3 );
+   }
 }
 
 static INLINE void 
@@ -195,18 +204,20 @@ vcache_ef_quad( struct vcache_frontend *vcache,
                 unsigned i3 )
 {
    if (vcache->draw->rasterizer->flatshade_first) {
+      /* pass last quad vertex as first triangle vertex */
       vcache_triangle_flags( vcache,
                              ( DRAW_PIPE_RESET_STIPPLE |
                                DRAW_PIPE_EDGE_FLAG_0 |
                                DRAW_PIPE_EDGE_FLAG_1 ),
-                             i0, i1, i2 );
+                             i3, i0, i1 );
 
       vcache_triangle_flags( vcache,
-                             ( DRAW_PIPE_EDGE_FLAG_2 |
-                               DRAW_PIPE_EDGE_FLAG_1 ),
-                             i0, i2, i3 );
+                             ( DRAW_PIPE_EDGE_FLAG_1 |
+                               DRAW_PIPE_EDGE_FLAG_2 ),
+                             i3, i1, i2 );
    }
    else {
+      /* pass last quad vertex as last triangle vertex */
       vcache_triangle_flags( vcache,
                              ( DRAW_PIPE_RESET_STIPPLE |
                                DRAW_PIPE_EDGE_FLAG_0 |
@@ -346,25 +357,28 @@ vcache_check_run( struct draw_pt_front_end *frontend,
    if (0) debug_printf("fetch_count %d fetch_max %d draw_count %d\n", fetch_count, 
                        vcache->fetch_max,
                        draw_count);
-      
-   if (max_index >= DRAW_PIPE_MAX_VERTICES ||
+
+   if (elt_bias + max_index >= DRAW_PIPE_MAX_VERTICES ||
        fetch_count >= UNDEFINED_VERTEX_ID ||
        fetch_count > draw_count) {
       if (0) debug_printf("fail\n");
       goto fail;
    }
-      
+
    if (vcache->middle_prim != vcache->input_prim) {
       vcache->middle_prim = vcache->input_prim;
-      vcache->middle->prepare( vcache->middle, 
-                               vcache->middle_prim, 
-                               vcache->opt, 
+      vcache->middle->prepare( vcache->middle,
+                               vcache->input_prim,
+                               vcache->middle_prim,
+                               vcache->opt,
                                &vcache->fetch_max );
    }
 
 
-   if (elt_bias <= 0 &&
-       min_index == (unsigned)-elt_bias &&
+   assert((elt_bias >= 0 && min_index + elt_bias >= min_index) ||
+          (elt_bias <  0 && min_index + elt_bias <  min_index));
+
+   if (min_index == 0 &&
        index_size == 2)
    {
       transformed_elts = (const ushort *)elts;
@@ -375,8 +389,7 @@ vcache_check_run( struct draw_pt_front_end *frontend,
       if (!storage)
          goto fail;
       
-      if (elt_bias <= 0 &&
-          min_index == (unsigned)-elt_bias) {
+      if (min_index == 0) {
          switch(index_size) {
          case 1:
             translate_ubyte_elts( (const ubyte *)elts,
@@ -407,21 +420,21 @@ vcache_check_run( struct draw_pt_front_end *frontend,
          case 1:
             rebase_ubyte_elts( (const ubyte *)elts,
                                   draw_count,
-                                  elt_bias - (int)min_index,
+                                  0 - (int)min_index,
                                   storage );
             break;
 
          case 2:
             rebase_ushort_elts( (const ushort *)elts,
                                    draw_count,
-                                   elt_bias - (int)min_index,
+                                   0 - (int)min_index,
                                    storage );
             break;
 
          case 4:
             rebase_uint_elts( (const uint *)elts,
                                  draw_count,
-                                 elt_bias - (int)min_index,
+                                 0 - (int)min_index,
                                  storage );
             break;
 
@@ -436,7 +449,7 @@ vcache_check_run( struct draw_pt_front_end *frontend,
 
    if (fetch_count < UNDEFINED_VERTEX_ID)
       ok = vcache->middle->run_linear_elts( vcache->middle,
-                                            min_index, /* start */
+                                            min_index + elt_bias, /* start */
                                             fetch_count,
                                             transformed_elts,
                                             draw_count );
@@ -456,9 +469,10 @@ vcache_check_run( struct draw_pt_front_end *frontend,
 
 
 
-static void 
+static void
 vcache_prepare( struct draw_pt_front_end *frontend,
-                unsigned prim,
+                unsigned in_prim,
+                unsigned out_prim,
                 struct draw_pt_middle_end *middle,
                 unsigned opt )
 {
@@ -468,13 +482,13 @@ vcache_prepare( struct draw_pt_front_end *frontend,
    {
       vcache->base.run = vcache_run_extras;
    }
-   else 
+   else
    {
       vcache->base.run = vcache_check_run;
    }
 
-   vcache->input_prim = prim;
-   vcache->output_prim = u_reduced_prim(prim);
+   vcache->input_prim = in_prim;
+   vcache->output_prim = u_reduced_prim(out_prim);
 
    vcache->middle = middle;
    vcache->opt = opt;
@@ -483,7 +497,8 @@ vcache_prepare( struct draw_pt_front_end *frontend,
     * doing so:
     */
    vcache->middle_prim = (opt & PT_PIPELINE) ? vcache->output_prim : vcache->input_prim;
-   middle->prepare( middle, vcache->middle_prim, opt, &vcache->fetch_max );
+   middle->prepare( middle, vcache->input_prim,
+                    vcache->middle_prim, opt, &vcache->fetch_max );
 }