vbuf updates/fixes (KeithW)
authorBrian <brian.paul@tungstengraphics.com>
Wed, 16 Jan 2008 17:57:53 +0000 (10:57 -0700)
committerBrian <brian.paul@tungstengraphics.com>
Wed, 16 Jan 2008 17:57:53 +0000 (10:57 -0700)
Plus, update i915 and Cell drivers for latest vbuf->draw() params.

src/mesa/pipe/cell/ppu/cell_vbuf.c
src/mesa/pipe/draw/draw_vbuf.c
src/mesa/pipe/draw/draw_vbuf.h
src/mesa/pipe/i915simple/i915_prim_vbuf.c

index d27d718daec31119d2592a052649357a2db1ba17..a420de041afa05cf9f459f963413996731441895 100644 (file)
@@ -46,6 +46,8 @@ struct cell_vbuf_render
    struct vbuf_render base;
    struct cell_context *cell;
    uint prim;
+   uint vertex_size;
+   void *vertex_buffer;
 };
 
 
@@ -70,8 +72,12 @@ static void *
 cell_vbuf_allocate_vertices(struct vbuf_render *vbr,
                             ushort vertex_size, ushort nr_vertices)
 {
+   struct cell_vbuf_render *cvbr = cell_vbuf_render(vbr);
    /*printf("Alloc verts %u * %u\n", vertex_size, nr_vertices);*/
-   return align_malloc(vertex_size * nr_vertices, 16);
+   assert(!cvbr->vertex_buffer);
+   cvbr->vertex_buffer = align_malloc(vertex_size * nr_vertices, 16);
+   cvbr->vertex_size = vertex_size;
+   return cvbr->vertex_buffer;
 }
 
 
@@ -86,17 +92,22 @@ cell_vbuf_set_primitive(struct vbuf_render *vbr, unsigned prim)
 
 static void
 cell_vbuf_draw(struct vbuf_render *vbr,
-               uint prim,
               const ushort *indices,
-               uint nr_indices,
-               const void *vertices,
-               uint nr_vertices,
-               uint vertex_size)
+               uint nr_indices)
 {
    struct cell_vbuf_render *cvbr = cell_vbuf_render(vbr);
    struct cell_context *cell = cvbr->cell;
    float xmin, ymin, xmax, ymax;
    uint i;
+   uint nr_vertices = 0;
+   const void *vertices = cvbr->vertex_buffer;
+   const uint vertex_size = cvbr->vertex_size;
+
+   for (i = 0; i < nr_indices; i++) {
+      if (indices[i] > nr_vertices)
+         nr_vertices = indices[i];
+   }
+   nr_vertices++;
 
 #if 0
    printf("cell_vbuf_draw() nr_indices = %u nr_verts = %u\n",
@@ -127,14 +138,14 @@ cell_vbuf_draw(struct vbuf_render *vbr,
          ymax = v[1];
    }
 
-   if (prim != PIPE_PRIM_TRIANGLES)
+   if (cvbr->prim != PIPE_PRIM_TRIANGLES)
       return; /* only render tris for now */
 
 #if 0
    for (i = 0; i < cell->num_spus; i++) {
       struct cell_command_render *render = &cell_global.command[i].render;
       render->opcode = CELL_CMD_RENDER;
-      render->prim_type = prim;
+      render->prim_type = cvbr->prim;
       render->num_verts = nr_vertices;
       render->num_attribs = CELL_MAX_ATTRIBS; /* XXX fix */
       render->vertex_data = vertices;
@@ -155,7 +166,7 @@ cell_vbuf_draw(struct vbuf_render *vbr,
          = (struct cell_command_render *)
          cell_batch_alloc(cell, sizeof(*render));
       render->opcode = CELL_CMD_RENDER;
-      render->prim_type = prim;
+      render->prim_type = cvbr->prim;
       render->num_verts = nr_vertices;
       render->num_attribs = CELL_MAX_ATTRIBS; /* XXX fix */
       render->vertex_data = vertices;
@@ -182,8 +193,13 @@ static void
 cell_vbuf_release_vertices(struct vbuf_render *vbr, void *vertices, 
                            unsigned vertex_size, unsigned vertices_used)
 {
+   struct cell_vbuf_render *cvbr = cell_vbuf_render(vbr);
+
    /*printf("Free verts %u * %u\n", vertex_size, vertices_used);*/
    align_free(vertices);
+
+   assert(vertices == cvbr->vertex_buffer);
+   cvbr->vertex_buffer = NULL;
 }
 
 
index 4f59b1b25da8366d971fa5999efd69af93c39ef5..6cda122c3afadf0064b38fb632b9cec0d79b1df5 100644 (file)
@@ -83,7 +83,8 @@ vbuf_stage( struct draw_stage *stage )
 
 
 static void vbuf_flush_indices( struct draw_stage *stage );
-static void vbuf_flush_vertices( struct draw_stage *stage,
+static void vbuf_flush_vertices( struct draw_stage *stage );
+static void vbuf_alloc_vertices( struct draw_stage *stage,
                                  unsigned new_vertex_size );
 
 
@@ -98,8 +99,10 @@ overflow( void *map, void *ptr, unsigned bytes, unsigned bufsz )
 static INLINE void 
 check_space( struct vbuf_stage *vbuf, unsigned nr )
 {
-   if (vbuf->nr_vertices + nr > vbuf->max_vertices ) 
-      vbuf_flush_vertices(&vbuf->stage, vbuf->vertex_size );
+   if (vbuf->nr_vertices + nr > vbuf->max_vertices ) {
+      vbuf_flush_vertices(&vbuf->stage);
+      vbuf_alloc_vertices(&vbuf->stage, vbuf->vertex_size);
+   }
 
    if (vbuf->nr_indices + nr > vbuf->max_indices )
       vbuf_flush_indices(&vbuf->stage);
@@ -232,10 +235,12 @@ vbuf_first_tri( struct draw_stage *stage,
    struct vbuf_stage *vbuf = vbuf_stage( stage );
 
    vbuf_flush_indices( stage );   
+
    stage->tri = vbuf_tri;
-   stage->tri( stage, prim );
    vbuf->prim = PIPE_PRIM_TRIANGLES;
    vbuf->render->set_primitive(vbuf->render, PIPE_PRIM_TRIANGLES);
+
+   stage->tri( stage, prim );
 }
 
 
@@ -247,9 +252,10 @@ vbuf_first_line( struct draw_stage *stage,
 
    vbuf_flush_indices( stage );
    stage->line = vbuf_line;
-   stage->line( stage, prim );
    vbuf->prim = PIPE_PRIM_LINES;
    vbuf->render->set_primitive(vbuf->render, PIPE_PRIM_LINES);
+
+   stage->line( stage, prim );
 }
 
 
@@ -260,10 +266,12 @@ vbuf_first_point( struct draw_stage *stage,
    struct vbuf_stage *vbuf = vbuf_stage( stage );
 
    vbuf_flush_indices( stage );
+
    stage->point = vbuf_point;
-   stage->point( stage, prim );
    vbuf->prim = PIPE_PRIM_POINTS;
    vbuf->render->set_primitive(vbuf->render, PIPE_PRIM_POINTS);
+
+   stage->point( stage, prim );
 }
 
 
@@ -291,15 +299,13 @@ vbuf_flush_indices( struct draw_stage *stage )
       assert(0);
    }
    
-   vbuf->render->draw( vbuf->render,
-                       vbuf->prim,
-                       vbuf->indices,
-                       vbuf->nr_indices,
-                       vbuf->vertices,
-                       vbuf->nr_vertices,
-                       vbuf->vertex_size );
-
+   vbuf->render->draw(vbuf->render, vbuf->indices, vbuf->nr_indices);
+   
    vbuf->nr_indices = 0;
+
+   stage->point = vbuf_first_point;
+   stage->line = vbuf_first_line;
+   stage->tri = vbuf_first_tri;
 }
 
 
@@ -311,8 +317,7 @@ vbuf_flush_indices( struct draw_stage *stage )
  * we flush.
  */
 static void 
-vbuf_flush_vertices( struct draw_stage *stage,
-                     unsigned new_vertex_size )
+vbuf_flush_vertices( struct draw_stage *stage )
 {
    struct vbuf_stage *vbuf = vbuf_stage( stage );
 
@@ -332,15 +337,24 @@ vbuf_flush_vertices( struct draw_stage *stage,
       vbuf->vertex_ptr = vbuf->vertices = NULL;
       
    }
+}
    
+
+static void 
+vbuf_alloc_vertices( struct draw_stage *stage,
+                    unsigned new_vertex_size )
+{
+   struct vbuf_stage *vbuf = vbuf_stage( stage );
+
    assert(!vbuf->nr_indices);
+   assert(!vbuf->vertices);
    
    /* Allocate a new vertex buffer */
    vbuf->vertex_size = new_vertex_size;
    vbuf->max_vertices = vbuf->render->max_vertex_buffer_bytes / vbuf->vertex_size;
    vbuf->vertices = vbuf->render->allocate_vertices(vbuf->render,
-                                                      vbuf->vertex_size,
-                                                      vbuf->max_vertices) ;
+                                                    (ushort) vbuf->vertex_size,
+                                                    (ushort) vbuf->max_vertices);
    vbuf->vertex_ptr = vbuf->vertices;
 }
 
@@ -352,22 +366,17 @@ vbuf_begin( struct draw_stage *stage )
    const struct vertex_info *vinfo = vbuf->render->get_vertex_info(vbuf->render);
    unsigned vertex_size = vinfo->size * sizeof(float);
 
-   if(vbuf->vertex_size != vertex_size)
-      vbuf_flush_vertices(&vbuf->stage, vertex_size);
+   /* XXX: Overkill */
+   vbuf_alloc_vertices(&vbuf->stage, vertex_size);
 }
 
 
 static void 
 vbuf_end( struct draw_stage *stage )
 {
-#if 0
+//   vbuf_flush_indices( stage );
    /* XXX: Overkill */
-   vbuf_flush_indices( stage );
-#else
-   /* By flushing vertices we avoid having the vertex buffer grow and grow */
-   struct vbuf_stage *vbuf = vbuf_stage(stage);
-   vbuf_flush_vertices( stage, vbuf->vertex_size );
-#endif
+   vbuf_flush_vertices( stage );
    
    stage->point = vbuf_first_point;
    stage->line = vbuf_first_line;
index be4c4ab77bcaaac8932801d8e0b8df9618f8b9a2..cfd2b9820c10f283bd4b31f815f04e92f1292f48 100644 (file)
@@ -82,12 +82,8 @@ struct vbuf_render {
     * DrawElements, note indices are ushort:
     */
    void (*draw)( struct vbuf_render *,
-                 uint prim,
                 const ushort *indices,
-                uint nr_indices,
-                 const void *vertices,
-                 uint nr_vertices,
-                 uint vertex_bytes);
+                uint nr_indices );
 
    /**
     * Called when vbuf is done with this set of vertices:
index bdcc027ed7b2d66f56ecdf99007624e8f637eac6..d85a6d3c0fcc6cac05065f91414c7ad14c829007 100644 (file)
@@ -136,12 +136,8 @@ i915_vbuf_render_set_primitive( struct vbuf_render *render,
 
 static void 
 i915_vbuf_render_draw( struct vbuf_render *render,
-                       uint prim,
                        const ushort *indices,
-                       uint nr_indices,
-                       const void *vertices,
-                       uint nr_vertices,
-                       uint vertex_bytes)
+                       uint nr_indices)
 {
    struct i915_vbuf_render *i915_render = i915_vbuf_render(render);
    struct i915_context *i915 = i915_render->i915;