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 2ea96c686da399d379e42352fb703785a0b2c362..c3baf5b7da7be27e29bcf9b27b884c53b09c34f0 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 f8786160799101583f26746b17c194ce57ceea9a..428b1e0e6bcba5416e2efdab47da3e097a14ea1c 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 9b098bc173fa83e56f614997d5159445a79dc710..9339cf1f8831076c6c96b7b3d615dbffb42cfdec 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 16ffedf580c9b81f5d8a6e2ac3598faaec8bcfcb..5a068761df9dd1f8aeed2578d6b2abecd09b2a61 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 );
 }