draw: Set the backend prim in the pt 'prepare' operation
authorKeith Whitwell <keith@tungstengraphics.com>
Wed, 2 Apr 2008 10:55:03 +0000 (11:55 +0100)
committerKeith Whitwell <keith@tungstengraphics.com>
Wed, 2 Apr 2008 11:02:32 +0000 (12:02 +0100)
Leaving it until 'run' is bad as the primitive is pretty much state
for some drivers and so needs to get set early.  In some drivers
this is used to determine things like vertex format, etc -- by the
time we get to 'run', it's too late to change this.

src/gallium/auxiliary/draw/draw_pt.c
src/gallium/auxiliary/draw/draw_pt.h
src/gallium/auxiliary/draw/draw_pt_fetch_emit.c
src/gallium/auxiliary/draw/draw_pt_vcache.c

index 2ea96c6..c3baf5b 100644 (file)
@@ -171,10 +171,9 @@ draw_pt_arrays(struct draw_context *draw,
     */
    draw_do_flush( draw, DRAW_FLUSH_BACKEND );
 
-   frontend->prepare( frontend, middle );
+   frontend->prepare( frontend, prim, middle );
 
    frontend->run( frontend,
-                  prim,
                   draw_pt_elt_func( draw ),
                   draw_pt_elt_ptr( draw, start ),
                   count );
index f878616..428b1e0 100644 (file)
@@ -53,10 +53,10 @@ struct draw_context;
  */
 struct draw_pt_front_end {
    void (*prepare)( struct draw_pt_front_end *,
+                    unsigned prim,
                     struct draw_pt_middle_end * );
 
    void (*run)( struct draw_pt_front_end *,
-                unsigned prim,
                 pt_elt_func elt_func,
                 const void *elt_ptr,
                 unsigned count );
@@ -79,10 +79,10 @@ struct draw_pt_front_end {
  * Currenly only using the passthrough version.
  */
 struct draw_pt_middle_end {
-   void (*prepare)( struct draw_pt_middle_end * );
+   void (*prepare)( struct draw_pt_middle_end *,
+                    unsigned prim );
 
    void (*run)( struct draw_pt_middle_end *,
-                unsigned prim,
                 const unsigned *fetch_elts,
                 unsigned fetch_count,
                 const ushort *draw_elts,
index 9b098bc..9339cf1 100644 (file)
@@ -203,16 +203,29 @@ fetch_store_general( struct fetch_emit_middle_end *feme,
 
 
 
-static void fetch_emit_prepare( struct draw_pt_middle_end *middle )
+static void fetch_emit_prepare( struct draw_pt_middle_end *middle,
+                                unsigned prim )
 {
    static const float zero = 0;
    struct fetch_emit_middle_end *feme = (struct fetch_emit_middle_end *)middle;
    struct draw_context *draw = feme->draw;
-   const struct vertex_info *vinfo = draw->render->get_vertex_info(draw->render);
-   unsigned nr_attrs = vinfo->num_attribs;
+   const struct vertex_info *vinfo;
    unsigned i;
+   boolean ok;
+
+
+   ok = draw->render->set_primitive( draw->render, 
+                                     prim );
+   if (!ok) {
+      assert(0);
+      return;
+   }
+   
+   /* Must do this after set_primitive() above:
+    */
+   vinfo = draw->render->get_vertex_info(draw->render);
 
-   for (i = 0; i < nr_attrs; i++) {
+   for (i = 0; i < vinfo->num_attribs; i++) {
       unsigned src_element = vinfo->src_index[i];
       unsigned src_buffer = draw->vertex_element[src_element].vertex_buffer_index;
          
@@ -275,7 +288,7 @@ static void fetch_emit_prepare( struct draw_pt_middle_end *middle )
       }
    }
 
-   feme->nr_fetch = nr_attrs;
+   feme->nr_fetch = vinfo->num_attribs;
    feme->hw_vertex_size = vinfo->size * 4;
 }
 
@@ -284,7 +297,6 @@ static void fetch_emit_prepare( struct draw_pt_middle_end *middle )
 
 
 static void fetch_emit_run( struct draw_pt_middle_end *middle,
-                            unsigned prim,
                             const unsigned *fetch_elts,
                             unsigned fetch_count,
                             const ushort *draw_elts,
@@ -293,16 +305,7 @@ static void fetch_emit_run( struct draw_pt_middle_end *middle,
    struct fetch_emit_middle_end *feme = (struct fetch_emit_middle_end *)middle;
    struct draw_context *draw = feme->draw;
    void *hw_verts;
-   boolean ok;
-   
-   ok = draw->render->set_primitive( draw->render, 
-                                     prim );
-   if (!ok) {
-      assert(0);
-      return;
-   }
    
-
    hw_verts = draw->render->allocate_vertices( draw->render,
                                                (ushort)feme->hw_vertex_size,
                                                (ushort)fetch_count );
index 16ffedf..5a06876 100644 (file)
@@ -59,6 +59,8 @@ struct vcache_frontend {
    const void *elt_ptr;
 
    struct draw_pt_middle_end *middle;
+
+   unsigned input_prim;
    unsigned output_prim;
 };
 
@@ -77,7 +79,6 @@ static void vcache_flush( struct vcache_frontend *vcache )
 
    if (vcache->draw_count) {
       vcache->middle->run( vcache->middle,
-                           vcache->output_prim,
                            vcache->fetch_elts,
                            vcache->fetch_count,
                            vcache->draw_elts,
@@ -173,7 +174,6 @@ static unsigned reduced_prim[PIPE_PRIM_POLYGON + 1] = {
 
 
 static void vcache_run_pv2( struct draw_pt_front_end *frontend, 
-                            unsigned prim,
                             pt_elt_func get_elt,
                             const void *elts,
                             unsigned count )
@@ -185,9 +185,8 @@ static void vcache_run_pv2( struct draw_pt_front_end *frontend,
     */
    vcache->elt_func = get_elt;
    vcache->elt_ptr = elts;
-   vcache->output_prim = reduced_prim[prim];
 
-   switch (prim) {
+   switch (vcache->input_prim) {
    case PIPE_PRIM_POINTS:
       for (i = 0; i < count; i ++) {
          vcache_point( vcache,
@@ -304,7 +303,6 @@ static void vcache_run_pv2( struct draw_pt_front_end *frontend,
 
 
 static void vcache_run_pv0( struct draw_pt_front_end *frontend, 
-                            unsigned prim,
                             pt_elt_func get_elt,
                             const void *elts,
                             unsigned count )
@@ -316,9 +314,8 @@ static void vcache_run_pv0( struct draw_pt_front_end *frontend,
     */
    vcache->elt_func = get_elt;
    vcache->elt_ptr = elts;
-   vcache->output_prim = reduced_prim[prim];
 
-   switch (prim) {
+   switch (vcache->input_prim) {
    case PIPE_PRIM_POINTS:
       for (i = 0; i < count; i ++) {
          vcache_point( vcache,
@@ -389,6 +386,7 @@ static void vcache_run_pv0( struct draw_pt_front_end *frontend,
 }
 
 static void vcache_prepare( struct draw_pt_front_end *frontend,
+                            unsigned prim,
                             struct draw_pt_middle_end *middle )
 {
    struct vcache_frontend *vcache = (struct vcache_frontend *)frontend;
@@ -398,8 +396,11 @@ static void vcache_prepare( struct draw_pt_front_end *frontend,
    else
       vcache->base.run = vcache_run_pv2;
    
+   vcache->input_prim = prim;
+   vcache->output_prim = reduced_prim[prim];
+
    vcache->middle = middle;
-   middle->prepare( middle );
+   middle->prepare( middle, vcache->output_prim );
 }