From d11fd189ff84ec24df0fb988e5c3e1a9260e038c Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 16 Jan 2008 10:57:53 -0700 Subject: [PATCH] vbuf updates/fixes (KeithW) Plus, update i915 and Cell drivers for latest vbuf->draw() params. --- src/mesa/pipe/cell/ppu/cell_vbuf.c | 34 ++++++++---- src/mesa/pipe/draw/draw_vbuf.c | 63 +++++++++++++---------- src/mesa/pipe/draw/draw_vbuf.h | 6 +-- src/mesa/pipe/i915simple/i915_prim_vbuf.c | 6 +-- 4 files changed, 63 insertions(+), 46 deletions(-) diff --git a/src/mesa/pipe/cell/ppu/cell_vbuf.c b/src/mesa/pipe/cell/ppu/cell_vbuf.c index d27d718daec..a420de041af 100644 --- a/src/mesa/pipe/cell/ppu/cell_vbuf.c +++ b/src/mesa/pipe/cell/ppu/cell_vbuf.c @@ -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; } diff --git a/src/mesa/pipe/draw/draw_vbuf.c b/src/mesa/pipe/draw/draw_vbuf.c index 4f59b1b25da..6cda122c3af 100644 --- a/src/mesa/pipe/draw/draw_vbuf.c +++ b/src/mesa/pipe/draw/draw_vbuf.c @@ -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; diff --git a/src/mesa/pipe/draw/draw_vbuf.h b/src/mesa/pipe/draw/draw_vbuf.h index be4c4ab77bc..cfd2b9820c1 100644 --- a/src/mesa/pipe/draw/draw_vbuf.h +++ b/src/mesa/pipe/draw/draw_vbuf.h @@ -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: diff --git a/src/mesa/pipe/i915simple/i915_prim_vbuf.c b/src/mesa/pipe/i915simple/i915_prim_vbuf.c index bdcc027ed7b..d85a6d3c0fc 100644 --- a/src/mesa/pipe/i915simple/i915_prim_vbuf.c +++ b/src/mesa/pipe/i915simple/i915_prim_vbuf.c @@ -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; -- 2.30.2