From 651e8e9a73b4f0c3424a78b978f710d098f47ae2 Mon Sep 17 00:00:00 2001 From: Brian Date: Sat, 26 Jan 2008 16:46:52 -0700 Subject: gallium: disable unnecessary point/line/tri re-validation in vbuf_flush_indices() --- src/mesa/pipe/draw/draw_vbuf.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/mesa/pipe/draw/draw_vbuf.c b/src/mesa/pipe/draw/draw_vbuf.c index cd0b4fbbb9..aea5b4aeee 100644 --- a/src/mesa/pipe/draw/draw_vbuf.c +++ b/src/mesa/pipe/draw/draw_vbuf.c @@ -331,9 +331,12 @@ vbuf_flush_indices( struct draw_stage *stage ) vbuf->nr_indices = 0; + /* don't need to reset point/line/tri functions */ +#if 0 stage->point = vbuf_first_point; stage->line = vbuf_first_line; stage->tri = vbuf_first_tri; +#endif } -- cgit v1.2.3 From 8dc597290813f58e2f2b7ddcb4ad762ea379c1f7 Mon Sep 17 00:00:00 2001 From: Brian Date: Sat, 26 Jan 2008 18:27:37 -0700 Subject: Cell: added cell_batch_free_space() --- src/mesa/pipe/cell/ppu/cell_batch.c | 11 +++++++++++ src/mesa/pipe/cell/ppu/cell_batch.h | 3 +++ 2 files changed, 14 insertions(+) (limited to 'src') diff --git a/src/mesa/pipe/cell/ppu/cell_batch.c b/src/mesa/pipe/cell/ppu/cell_batch.c index 5a25f1b266..c894ef8608 100644 --- a/src/mesa/pipe/cell/ppu/cell_batch.c +++ b/src/mesa/pipe/cell/ppu/cell_batch.c @@ -96,6 +96,15 @@ cell_batch_flush(struct cell_context *cell) } +uint +cell_batch_free_space(const struct cell_context *cell) +{ + uint free = CELL_BATCH_BUFFER_SIZE + - cell->batch_buffer_size[cell->cur_batch]; + return free; +} + + /** * \param cmd command to append * \param length command size in bytes @@ -129,6 +138,8 @@ cell_batch_alloc(struct cell_context *cell, uint bytes) void *pos; uint size; + ASSERT(bytes % 4 == 0); + assert(cell->cur_batch >= 0); size = cell->batch_buffer_size[cell->cur_batch]; diff --git a/src/mesa/pipe/cell/ppu/cell_batch.h b/src/mesa/pipe/cell/ppu/cell_batch.h index 47e3287626..c4ba7feb3d 100644 --- a/src/mesa/pipe/cell/ppu/cell_batch.h +++ b/src/mesa/pipe/cell/ppu/cell_batch.h @@ -38,6 +38,9 @@ struct cell_context; extern void cell_batch_flush(struct cell_context *cell); +extern uint +cell_batch_free_space(const struct cell_context *cell); + extern void cell_batch_append(struct cell_context *cell, const void *cmd, uint length); -- cgit v1.2.3 From 1bab5bd24e09b6e11cd99f989bb00c587119aed2 Mon Sep 17 00:00:00 2001 From: Brian Date: Sat, 26 Jan 2008 18:30:44 -0700 Subject: Cell: added support for inlined indexes If there's room in the batch buffer after the rendering command to accomodate the indexes, put them there rather than in a separate buffer. --- src/mesa/pipe/cell/common.h | 1 + src/mesa/pipe/cell/ppu/cell_vbuf.c | 31 +++++++-- src/mesa/pipe/cell/spu/spu_main.c | 125 +++++++++++++++++++++++++------------ 3 files changed, 114 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/mesa/pipe/cell/common.h b/src/mesa/pipe/cell/common.h index e925299119..e955bb9ec5 100644 --- a/src/mesa/pipe/cell/common.h +++ b/src/mesa/pipe/cell/common.h @@ -124,6 +124,7 @@ struct cell_command_render const void *vertex_data; const ushort *index_data; float xmin, ymin, xmax, ymax; + boolean inline_indexes; } ALIGN16_ATTRIB; diff --git a/src/mesa/pipe/cell/ppu/cell_vbuf.c b/src/mesa/pipe/cell/ppu/cell_vbuf.c index 00ff990eab..59a4a2b6e9 100644 --- a/src/mesa/pipe/cell/ppu/cell_vbuf.c +++ b/src/mesa/pipe/cell/ppu/cell_vbuf.c @@ -39,6 +39,10 @@ #include "pipe/draw/draw_vbuf.h" +/** Allow render indexes to be inlined after RENDER command */ +#define ALLOW_INLINING 1 + + /** * Subclass of vbuf_render because we need a cell_context pointer in * a few places. @@ -123,6 +127,8 @@ cell_vbuf_draw(struct vbuf_render *vbr, printf("cell_vbuf_draw() nr_indices = %u nr_verts = %u indexes = [%u %u %u ...]\n", nr_indices, nr_vertices, indices[0], indices[1], indices[2]); + printf("ind space = %u, space = %u\n", + nr_indices * 2, cell_batch_free_space(cell)); #endif /* compute x/y bounding box */ @@ -145,23 +151,40 @@ cell_vbuf_draw(struct vbuf_render *vbr, /* build/insert batch RENDER command */ { + const uint index_bytes = (nr_indices * 2 + 3) & ~0x3; + struct cell_command_render *render = (struct cell_command_render *) cell_batch_alloc(cell, sizeof(*render)); render->opcode = CELL_CMD_RENDER; render->prim_type = cvbr->prim; + render->num_verts = nr_vertices; render->vertex_size = 4 * cell->vertex_info.size; render->vertex_data = vertices; - render->index_data = indices; + ASSERT_ALIGN16(render->vertex_data); + render->num_indexes = nr_indices; + + if (ALLOW_INLINING && + index_bytes <= cell_batch_free_space(cell)) { + /* indices inlined, right after render cmd */ + void *dst = cell_batch_alloc(cell, index_bytes); + memcpy(dst, indices, nr_indices * 2); + render->inline_indexes = TRUE; + render->index_data = NULL; + } + else { + /* indices in separate buffer */ + render->inline_indexes = FALSE; + render->index_data = indices; + ASSERT_ALIGN16(render->index_data); + } + render->xmin = xmin; render->ymin = ymin; render->xmax = xmax; render->ymax = ymax; - - ASSERT_ALIGN16(render->vertex_data); - ASSERT_ALIGN16(render->index_data); } #if 01 diff --git a/src/mesa/pipe/cell/spu/spu_main.c b/src/mesa/pipe/cell/spu/spu_main.c index ef605a5197..92be0b4a4a 100644 --- a/src/mesa/pipe/cell/spu/spu_main.c +++ b/src/mesa/pipe/cell/spu/spu_main.c @@ -204,66 +204,104 @@ tile_bounding_box(const struct cell_command_render *render, } +/** + * Render primitives + * \param pos_incr returns value indicating how may words to skip after + * this command in the batch buffer + */ static void -cmd_render(const struct cell_command_render *render) +cmd_render(const struct cell_command_render *render, uint *pos_incr) { /* we'll DMA into these buffers */ ubyte vertex_data[CELL_MAX_VBUF_SIZE] ALIGN16_ATTRIB; - ushort indexes[CELL_MAX_VBUF_INDEXES] ALIGN16_ATTRIB; - uint i, j, total_vertex_bytes, total_index_bytes; + ushort index_data[CELL_MAX_VBUF_INDEXES] ALIGN16_ATTRIB; const uint vertex_size = render->vertex_size; /* in bytes */ + const ushort *indexes; + uint i, j; + if (Debug) { - printf("SPU %u: RENDER prim %u, indices: %u, nr_vert: %u\n", + printf("SPU %u: RENDER prim %u, num_vert=%u num_ind=%u inlined=%u\n", spu.init.id, render->prim_type, render->num_verts, - render->num_indexes); + render->num_indexes, + render->inline_indexes); + /* printf(" bound: %g, %g .. %g, %g\n", render->xmin, render->ymin, render->xmax, render->ymax); */ + printf("SPU %u: indices at %p vertices at %p\n", + spu.init.id, + render->index_data, render->vertex_data); } ASSERT_ALIGN16(render->vertex_data); ASSERT_ALIGN16(render->index_data); - /* how much vertex data */ - total_vertex_bytes = render->num_verts * vertex_size; - total_index_bytes = render->num_indexes * sizeof(ushort); - if (total_index_bytes < 16) - total_index_bytes = 16; - else - total_index_bytes = ROUNDUP16(total_index_bytes); - /* - printf("VBUF: indices at %p, vertices at %p total_vertex_bytes %u ind_bytes %u\n", - render->index_data, render->vertex_data, total_vertex_bytes, total_index_bytes); - */ + /** + ** Get vertices + **/ + { + const uint total_vertex_bytes = render->num_verts * vertex_size; - ASSERT(total_vertex_bytes % 16 == 0); - /* get vertex data from main memory */ - mfc_get(vertex_data, /* dest */ - (unsigned int) render->vertex_data, /* src */ - total_vertex_bytes, /* size */ - TAG_VERTEX_BUFFER, - 0, /* tid */ - 0 /* rid */); + ASSERT(total_vertex_bytes % 16 == 0); + + /* get vertex data from main memory */ + mfc_get(vertex_data, /* dest */ + (unsigned int) render->vertex_data, /* src */ + total_vertex_bytes, /* size */ + TAG_VERTEX_BUFFER, + 0, /* tid */ + 0 /* rid */); + } - ASSERT(total_index_bytes % 16 == 0); - /* get index data from main memory */ - mfc_get(indexes, /* dest */ - (unsigned int) render->index_data, /* src */ - total_index_bytes, - TAG_INDEX_BUFFER, - 0, /* tid */ - 0 /* rid */); + /** + ** Get indexes + **/ + if (render->inline_indexes) { + /* indexes are right after the render command in the batch buffer */ + ASSERT(sizeof(*render) % 4 == 0); + indexes = (ushort *) (render + 1); - wait_on_mask_all((1 << TAG_VERTEX_BUFFER) | - (1 << TAG_INDEX_BUFFER)); + *pos_incr = (render->num_indexes * 2 + 3) / 4; - /* find tiles which intersect the prim bounding box */ + /* wait for vertex data */ + wait_on_mask_all(1 << TAG_VERTEX_BUFFER); + } + else { + /* indexes are in separate buffer */ + uint total_index_bytes; + + *pos_incr = 0; + + total_index_bytes = render->num_indexes * sizeof(ushort); + if (total_index_bytes < 16) + total_index_bytes = 16; + else + total_index_bytes = ROUNDUP16(total_index_bytes); + + indexes = index_data; + + /* get index data from main memory */ + mfc_get(index_data, /* dest */ + (unsigned int) render->index_data, /* src */ + total_index_bytes, + TAG_INDEX_BUFFER, + 0, /* tid */ + 0 /* rid */); + + wait_on_mask_all((1 << TAG_VERTEX_BUFFER) | + (1 << TAG_INDEX_BUFFER)); + } + + + /** + ** find tiles which intersect the prim bounding box + **/ uint txmin, tymin, box_width_tiles, box_num_tiles; #if 0 tile_bounding_box(render, &txmin, &tymin, @@ -278,7 +316,10 @@ cmd_render(const struct cell_command_render *render) /* make sure any pending clears have completed */ wait_on_mask(1 << TAG_SURFACE_CLEAR); - /* loop over tiles */ + + /** + ** loop over tiles, rendering tris + **/ for (i = spu.init.id; i < box_num_tiles; i += spu.init.num_spus) { const uint tx = txmin + i % box_width_tiles; const uint ty = tymin + i / box_width_tiles; @@ -300,6 +341,7 @@ cmd_render(const struct cell_command_render *render) } ASSERT(render->prim_type == PIPE_PRIM_TRIANGLES); + ASSERT(render->num_indexes % 3 == 0); /* loop over tris */ for (j = 0; j < render->num_indexes; j += 3) { @@ -508,8 +550,9 @@ cmd_batch(uint opcode) { struct cell_command_render *render = (struct cell_command_render *) &buffer[pos]; - cmd_render(render); - pos += sizeof(*render) / 4; + uint pos_incr; + cmd_render(render, &pos_incr); + pos += sizeof(*render) / 4 + pos_incr; } break; case CELL_CMD_FINISH: @@ -591,7 +634,11 @@ main_loop(void) cmd_clear_surface(&cmd.clear); break; case CELL_CMD_RENDER: - cmd_render(&cmd.render); + { + uint pos_incr; + cmd_render(&cmd.render, &pos_incr); + assert(pos_incr == 0); + } break; case CELL_CMD_BATCH: cmd_batch(opcode); -- cgit v1.2.3 From 419a5cca34d931e61587eaeb8d32a44b415c43ad Mon Sep 17 00:00:00 2001 From: Brian Date: Sat, 26 Jan 2008 19:31:20 -0700 Subject: Cell: added ROUNUP4 --- src/mesa/pipe/cell/common.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/mesa/pipe/cell/common.h b/src/mesa/pipe/cell/common.h index e955bb9ec5..bdde166630 100644 --- a/src/mesa/pipe/cell/common.h +++ b/src/mesa/pipe/cell/common.h @@ -54,6 +54,9 @@ assert((((unsigned long) (ptr)) & 0xf) == 0); +/** round up value to next multiple of 4 */ +#define ROUNDUP4(k) (((k) + 0x3) & ~0x3) + /** round up value to next multiple of 16 */ #define ROUNDUP16(k) (((k) + 0xf) & ~0xf) -- cgit v1.2.3 From 87a8a339d7c8973168ffb5e5506f7ec4b3a524ba Mon Sep 17 00:00:00 2001 From: Brian Date: Sat, 26 Jan 2008 19:38:16 -0700 Subject: Cell: added support for inlined vertex buffers. Small prims are now self-contained in batch buffers when space allows. --- src/mesa/pipe/cell/common.h | 1 + src/mesa/pipe/cell/ppu/cell_vbuf.c | 40 ++++++++++++++++------- src/mesa/pipe/cell/spu/spu_main.c | 66 ++++++++++++++++++++++---------------- 3 files changed, 68 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/mesa/pipe/cell/common.h b/src/mesa/pipe/cell/common.h index bdde166630..0b63ed39be 100644 --- a/src/mesa/pipe/cell/common.h +++ b/src/mesa/pipe/cell/common.h @@ -128,6 +128,7 @@ struct cell_command_render const ushort *index_data; float xmin, ymin, xmax, ymax; boolean inline_indexes; + boolean inline_verts; } ALIGN16_ATTRIB; diff --git a/src/mesa/pipe/cell/ppu/cell_vbuf.c b/src/mesa/pipe/cell/ppu/cell_vbuf.c index 59a4a2b6e9..ee572b3a51 100644 --- a/src/mesa/pipe/cell/ppu/cell_vbuf.c +++ b/src/mesa/pipe/cell/ppu/cell_vbuf.c @@ -39,8 +39,9 @@ #include "pipe/draw/draw_vbuf.h" -/** Allow render indexes to be inlined after RENDER command */ -#define ALLOW_INLINING 1 +/** Allow prim indexes, verts to be inlined after RENDER command */ +#define ALLOW_INLINE_INDEXES 1 +#define ALLOW_INLINE_VERTS 1 /** @@ -127,8 +128,10 @@ cell_vbuf_draw(struct vbuf_render *vbr, printf("cell_vbuf_draw() nr_indices = %u nr_verts = %u indexes = [%u %u %u ...]\n", nr_indices, nr_vertices, indices[0], indices[1], indices[2]); - printf("ind space = %u, space = %u\n", - nr_indices * 2, cell_batch_free_space(cell)); + printf("ind space = %u, vert space = %u, space = %u\n", + nr_indices * 2, + nr_vertices * 4 * cell->vertex_info.size, + cell_batch_free_space(cell)); #endif /* compute x/y bounding box */ @@ -151,7 +154,8 @@ cell_vbuf_draw(struct vbuf_render *vbr, /* build/insert batch RENDER command */ { - const uint index_bytes = (nr_indices * 2 + 3) & ~0x3; + const uint index_bytes = ROUNDUP4(nr_indices * 2); + const uint vertex_bytes = nr_vertices * 4 * cell->vertex_info.size; struct cell_command_render *render = (struct cell_command_render *) @@ -159,14 +163,8 @@ cell_vbuf_draw(struct vbuf_render *vbr, render->opcode = CELL_CMD_RENDER; render->prim_type = cvbr->prim; - render->num_verts = nr_vertices; - render->vertex_size = 4 * cell->vertex_info.size; - render->vertex_data = vertices; - ASSERT_ALIGN16(render->vertex_data); - render->num_indexes = nr_indices; - - if (ALLOW_INLINING && + if (ALLOW_INLINE_INDEXES && index_bytes <= cell_batch_free_space(cell)) { /* indices inlined, right after render cmd */ void *dst = cell_batch_alloc(cell, index_bytes); @@ -181,6 +179,24 @@ cell_vbuf_draw(struct vbuf_render *vbr, ASSERT_ALIGN16(render->index_data); } + render->vertex_size = 4 * cell->vertex_info.size; + render->num_verts = nr_vertices; + if (ALLOW_INLINE_VERTS && + render->inline_indexes && + vertex_bytes <= cell_batch_free_space(cell)) { + /* vertex data inlined, after indices */ + void *dst = cell_batch_alloc(cell, vertex_bytes); + memcpy(dst, vertices, vertex_bytes); + render->inline_verts = TRUE; + render->vertex_data = NULL; + } + else { + render->inline_verts = FALSE; + render->vertex_data = vertices; + ASSERT_ALIGN16(render->vertex_data); + } + + render->xmin = xmin; render->ymin = ymin; render->xmax = xmax; diff --git a/src/mesa/pipe/cell/spu/spu_main.c b/src/mesa/pipe/cell/spu/spu_main.c index 92be0b4a4a..0c83900a18 100644 --- a/src/mesa/pipe/cell/spu/spu_main.c +++ b/src/mesa/pipe/cell/spu/spu_main.c @@ -216,16 +216,21 @@ cmd_render(const struct cell_command_render *render, uint *pos_incr) ubyte vertex_data[CELL_MAX_VBUF_SIZE] ALIGN16_ATTRIB; ushort index_data[CELL_MAX_VBUF_INDEXES] ALIGN16_ATTRIB; const uint vertex_size = render->vertex_size; /* in bytes */ + const uint total_vertex_bytes = render->num_verts * vertex_size; + const ubyte *vertices; const ushort *indexes; + uint mask; uint i, j; if (Debug) { - printf("SPU %u: RENDER prim %u, num_vert=%u num_ind=%u inlined=%u\n", + printf("SPU %u: RENDER prim %u, num_vert=%u num_ind=%u " + "inline_vert=%u inline_ind=%u\n", spu.init.id, render->prim_type, render->num_verts, render->num_indexes, + render->inline_verts, render->inline_indexes); /* @@ -237,43 +242,28 @@ cmd_render(const struct cell_command_render *render, uint *pos_incr) render->index_data, render->vertex_data); } + ASSERT(sizeof(*render) % 4 == 0); ASSERT_ALIGN16(render->vertex_data); ASSERT_ALIGN16(render->index_data); /** - ** Get vertices + ** Get vertex, index buffers if not inlined **/ - { - const uint total_vertex_bytes = render->num_verts * vertex_size; - + if (!render->inline_verts) { ASSERT(total_vertex_bytes % 16 == 0); - /* get vertex data from main memory */ mfc_get(vertex_data, /* dest */ (unsigned int) render->vertex_data, /* src */ total_vertex_bytes, /* size */ TAG_VERTEX_BUFFER, 0, /* tid */ 0 /* rid */); - } - - /** - ** Get indexes - **/ - if (render->inline_indexes) { - /* indexes are right after the render command in the batch buffer */ - ASSERT(sizeof(*render) % 4 == 0); - indexes = (ushort *) (render + 1); - - *pos_incr = (render->num_indexes * 2 + 3) / 4; - - /* wait for vertex data */ - wait_on_mask_all(1 << TAG_VERTEX_BUFFER); + vertices = vertex_data; } - else { - /* indexes are in separate buffer */ + + if (!render->inline_indexes) { uint total_index_bytes; *pos_incr = 0; @@ -293,12 +283,34 @@ cmd_render(const struct cell_command_render *render, uint *pos_incr) TAG_INDEX_BUFFER, 0, /* tid */ 0 /* rid */); + } + + + /** + ** Get pointers to inlined indexes, verts, if present + **/ + if (render->inline_indexes) { + /* indexes are right after the render command in the batch buffer */ + indexes = (ushort *) (render + 1); + *pos_incr = (render->num_indexes * 2 + 3) / 4; - wait_on_mask_all((1 << TAG_VERTEX_BUFFER) | - (1 << TAG_INDEX_BUFFER)); + if (render->inline_verts) { + /* vertices are after indexes, if inlined */ + vertices = (const ubyte *) (render + 1) + *pos_incr * 4; + *pos_incr = *pos_incr + total_vertex_bytes / 4; + } } + /* wait for vertex and/or index buffers if not inlined */ + mask = 0x0; + if (!render->inline_verts) + mask |= (1 << TAG_VERTEX_BUFFER); + if (!render->inline_indexes) + mask |= (1 << TAG_INDEX_BUFFER); + wait_on_mask_all(mask); + + /** ** find tiles which intersect the prim bounding box **/ @@ -347,9 +359,9 @@ cmd_render(const struct cell_command_render *render, uint *pos_incr) for (j = 0; j < render->num_indexes; j += 3) { const float *v0, *v1, *v2; - v0 = (const float *) (vertex_data + indexes[j+0] * vertex_size); - v1 = (const float *) (vertex_data + indexes[j+1] * vertex_size); - v2 = (const float *) (vertex_data + indexes[j+2] * vertex_size); + v0 = (const float *) (vertices + indexes[j+0] * vertex_size); + v1 = (const float *) (vertices + indexes[j+1] * vertex_size); + v2 = (const float *) (vertices + indexes[j+2] * vertex_size); tri_draw(v0, v1, v2, tx, ty); } -- cgit v1.2.3 From e6c8278c04518b8b8b0960a9e21b48b6816fcc20 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Sun, 27 Jan 2008 19:20:48 +0900 Subject: Fullfill pipe_winsys->user_buffer_create. Aggregate winsys functions. --- src/mesa/pipe/pipebuffer/Makefile | 5 +- src/mesa/pipe/pipebuffer/pb_buffer.c | 77 ------------- src/mesa/pipe/pipebuffer/pb_buffer.h | 62 +++++----- src/mesa/pipe/pipebuffer/pb_buffer_client.c | 115 ------------------- src/mesa/pipe/pipebuffer/pb_winsys.c | 170 ++++++++++++++++++++++++++++ 5 files changed, 207 insertions(+), 222 deletions(-) delete mode 100644 src/mesa/pipe/pipebuffer/pb_buffer.c delete mode 100644 src/mesa/pipe/pipebuffer/pb_buffer_client.c create mode 100644 src/mesa/pipe/pipebuffer/pb_winsys.c (limited to 'src') diff --git a/src/mesa/pipe/pipebuffer/Makefile b/src/mesa/pipe/pipebuffer/Makefile index ea8c3440c3..75764a9a18 100644 --- a/src/mesa/pipe/pipebuffer/Makefile +++ b/src/mesa/pipe/pipebuffer/Makefile @@ -5,13 +5,12 @@ include $(TOP)/configs/current LIBNAME = pipebuffer DRIVER_SOURCES = \ - pb_buffer.c \ - pb_buffer_client.c \ pb_buffer_fenced.c \ pb_buffer_malloc.c \ pb_bufmgr_fenced.c \ pb_bufmgr_mm.c \ - pb_bufmgr_pool.c + pb_bufmgr_pool.c \ + pb_winsys.c C_SOURCES = \ $(DRIVER_SOURCES) diff --git a/src/mesa/pipe/pipebuffer/pb_buffer.c b/src/mesa/pipe/pipebuffer/pb_buffer.c deleted file mode 100644 index 90ab9044ff..0000000000 --- a/src/mesa/pipe/pipebuffer/pb_buffer.c +++ /dev/null @@ -1,77 +0,0 @@ -/************************************************************************** - * - * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -/** - * \file - * Buffer implementation. - * - * \author José Fonseca - */ - - -#include "pb_buffer.h" -#include "pipe/p_winsys.h" - - - -static void * -pb_winsys_map(struct pipe_winsys *winsys, - struct pipe_buffer *ws_buf, - unsigned flags) -{ - struct pb_buffer *buf = pb_buffer(ws_buf); - - return buf->vtbl->map(buf, flags); -} - -static void -pb_winsys_unmap(struct pipe_winsys *winsys, - struct pipe_buffer *ws_buf) -{ - struct pb_buffer *buf = pb_buffer(ws_buf); - - buf->vtbl->unmap(buf); -} - -static void -pb_winsys_destroy(struct pipe_winsys *winsys, - struct pipe_buffer *ws_buf) -{ - struct pb_buffer *buf = pb_buffer(ws_buf); - - buf->vtbl->destroy(buf); -} - - - -void -pb_init_winsys(struct pipe_winsys *winsys) -{ - winsys->buffer_map = pb_winsys_map; - winsys->buffer_unmap = pb_winsys_unmap; - winsys->buffer_destroy = pb_winsys_destroy; -} diff --git a/src/mesa/pipe/pipebuffer/pb_buffer.h b/src/mesa/pipe/pipebuffer/pb_buffer.h index 2f570ef9de..17551b3b50 100644 --- a/src/mesa/pipe/pipebuffer/pb_buffer.h +++ b/src/mesa/pipe/pipebuffer/pb_buffer.h @@ -48,8 +48,9 @@ #include #include "pipe/p_compiler.h" - #include "pipe/p_state.h" +#include "pipe/p_inlines.h" + struct pb_vtbl; @@ -81,6 +82,7 @@ struct pb_buffer const struct pb_vtbl *vtbl; }; + /** * Virtual function table for the buffer storage operations. * @@ -116,6 +118,24 @@ struct pb_vtbl }; +static INLINE struct pipe_buffer * +pb_pipe_buffer( struct pb_buffer *pbuf ) +{ + assert(pbuf); + return &pbuf->base; +} + + +static INLINE struct pb_buffer * +pb_buffer( struct pipe_buffer *buf ) +{ + assert(buf); + /* Could add a magic cookie check on debug builds. + */ + return (struct pb_buffer *)buf; +} + + /* Accessor functions for pb->vtbl: */ static INLINE void * @@ -143,6 +163,7 @@ pb_get_base_buffer( struct pb_buffer *buf, buf->vtbl->get_base_buffer(buf, base_buf, offset); } + static INLINE void pb_destroy(struct pb_buffer *buf) { @@ -151,19 +172,20 @@ pb_destroy(struct pb_buffer *buf) } +/* XXX: thread safety issues! + */ +static INLINE void +pb_reference(struct pb_buffer **dst, + struct pb_buffer *src) +{ + if (src) + src->base.refcount++; + if (*dst && --(*dst)->base.refcount == 0) + pb_destroy( *dst ); -/** - * User buffers are special buffers that initially reference memory - * held by the user but which may if necessary copy that memory into - * device memory behind the scenes, for submission to hardware. - * - * These are particularly useful when the referenced data is never - * submitted to hardware at all, in the particular case of software - * vertex processing. - */ -struct pb_buffer * -pb_user_buffer_create(void *data, unsigned bytes); + *dst = src; +} /** @@ -175,22 +197,8 @@ pb_malloc_buffer_create(size_t size, const struct pb_desc *desc); -static INLINE struct pipe_buffer * -pb_pipe_buffer( struct pb_buffer *pbuf ) -{ - return &pbuf->base; -} - -static INLINE struct pb_buffer * -pb_buffer( struct pipe_buffer *buf ) -{ - /* Could add a magic cookie check on debug builds. - */ - return (struct pb_buffer *)buf; -} - - void pb_init_winsys(struct pipe_winsys *winsys); + #endif /*PB_BUFFER_H_*/ diff --git a/src/mesa/pipe/pipebuffer/pb_buffer_client.c b/src/mesa/pipe/pipebuffer/pb_buffer_client.c deleted file mode 100644 index c316aabd32..0000000000 --- a/src/mesa/pipe/pipebuffer/pb_buffer_client.c +++ /dev/null @@ -1,115 +0,0 @@ -/************************************************************************** - * - * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -/** - * \file - * Implementation of client buffer (also designated as "user buffers"), which - * are just state-tracker owned data masqueraded as buffers. - * - * \author José Fonseca - */ - - -#include "pipe/p_util.h" -#include "pb_buffer.h" - - -struct pb_user_buffer -{ - struct pb_buffer base; - void *data; -}; - - -extern const struct pb_vtbl pb_user_buffer_vtbl; - - -static INLINE struct pb_user_buffer * -pb_user_buffer(struct pb_buffer *buf) -{ - assert(buf); - assert(buf->vtbl == &pb_user_buffer_vtbl); - return (struct pb_user_buffer *)buf; -} - - -static void -pb_user_buffer_destroy(struct pb_buffer *buf) -{ - assert(buf); - FREE(buf); -} - - -static void * -pb_user_buffer_map(struct pb_buffer *buf, - unsigned flags) -{ - return pb_user_buffer(buf)->data; -} - - -static void -pb_user_buffer_unmap(struct pb_buffer *buf) -{ - /* No-op */ -} - - -static void -pb_user_buffer_get_base_buffer(struct pb_buffer *buf, - struct pb_buffer **base_buf, - unsigned *offset) -{ - *base_buf = buf; - *offset = 0; -} - - -const struct pb_vtbl -pb_user_buffer_vtbl = { - pb_user_buffer_destroy, - pb_user_buffer_map, - pb_user_buffer_unmap, - pb_user_buffer_get_base_buffer -}; - - -struct pb_buffer * -pb_user_buffer_create(void *data, unsigned bytes) -{ - struct pb_user_buffer *buf = CALLOC_STRUCT(pb_user_buffer); - - if(!buf) - return NULL; - - buf->base.vtbl = &pb_user_buffer_vtbl; - buf->base.base.size = bytes; - buf->data = data; - - return &buf->base; -} diff --git a/src/mesa/pipe/pipebuffer/pb_winsys.c b/src/mesa/pipe/pipebuffer/pb_winsys.c new file mode 100644 index 0000000000..978944091f --- /dev/null +++ b/src/mesa/pipe/pipebuffer/pb_winsys.c @@ -0,0 +1,170 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \file + * Implementation of client buffer (also designated as "user buffers"), which + * are just state-tracker owned data masqueraded as buffers. + * + * \author José Fonseca + */ + + +#include "pipe/p_winsys.h" +#include "pipe/p_util.h" + +#include "pb_buffer.h" + + +/** + * User buffers are special buffers that initially reference memory + * held by the user but which may if necessary copy that memory into + * device memory behind the scenes, for submission to hardware. + * + * These are particularly useful when the referenced data is never + * submitted to hardware at all, in the particular case of software + * vertex processing. + */ +struct pb_user_buffer +{ + struct pb_buffer base; + void *data; +}; + + +extern const struct pb_vtbl pb_user_buffer_vtbl; + + +static INLINE struct pb_user_buffer * +pb_user_buffer(struct pb_buffer *buf) +{ + assert(buf); + assert(buf->vtbl == &pb_user_buffer_vtbl); + return (struct pb_user_buffer *)buf; +} + + +static void +pb_user_buffer_destroy(struct pb_buffer *buf) +{ + assert(buf); + FREE(buf); +} + + +static void * +pb_user_buffer_map(struct pb_buffer *buf, + unsigned flags) +{ + return pb_user_buffer(buf)->data; +} + + +static void +pb_user_buffer_unmap(struct pb_buffer *buf) +{ + /* No-op */ +} + + +static void +pb_user_buffer_get_base_buffer(struct pb_buffer *buf, + struct pb_buffer **base_buf, + unsigned *offset) +{ + *base_buf = buf; + *offset = 0; +} + + +const struct pb_vtbl +pb_user_buffer_vtbl = { + pb_user_buffer_destroy, + pb_user_buffer_map, + pb_user_buffer_unmap, + pb_user_buffer_get_base_buffer +}; + + +static struct pipe_buffer * +pb_winsys_user_buffer_create(struct pipe_winsys *winsys, + void *data, + unsigned bytes) +{ + struct pb_user_buffer *buf = CALLOC_STRUCT(pb_user_buffer); + + if(!buf) + return NULL; + + buf->base.base.refcount = 1; + buf->base.base.size = bytes; + buf->base.base.alignment = 0; + buf->base.base.usage = 0; + + buf->base.vtbl = &pb_user_buffer_vtbl; + buf->data = data; + + return &buf->base.base; +} + + +static void * +pb_winsys_buffer_map(struct pipe_winsys *winsys, + struct pipe_buffer *buf, + unsigned flags) +{ + (void)winsys; + return pb_map(pb_buffer(buf), flags); +} + + +static void +pb_winsys_buffer_unmap(struct pipe_winsys *winsys, + struct pipe_buffer *buf) +{ + (void)winsys; + pb_unmap(pb_buffer(buf)); +} + + +static void +pb_winsys_buffer_destroy(struct pipe_winsys *winsys, + struct pipe_buffer *buf) +{ + (void)winsys; + pb_destroy(pb_buffer(buf)); +} + + +void +pb_init_winsys(struct pipe_winsys *winsys) +{ + winsys->user_buffer_create = pb_winsys_user_buffer_create; + winsys->buffer_map = pb_winsys_buffer_map; + winsys->buffer_unmap = pb_winsys_buffer_unmap; + winsys->buffer_destroy = pb_winsys_buffer_destroy; +} -- cgit v1.2.3 From dac124081d4bbc9d7527661e4a96aa78077b9f52 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Sun, 27 Jan 2008 19:22:25 +0900 Subject: Do refcounting trhoughout all buffer objects, since it is now a base requirement. --- src/mesa/pipe/pipebuffer/pb_buffer_fenced.c | 11 +++++++---- src/mesa/pipe/pipebuffer/pb_buffer_malloc.c | 3 ++- src/mesa/pipe/pipebuffer/pb_bufmgr_fenced.c | 1 + src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c | 9 +++++++-- src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c | 16 ++++++++++++++-- 5 files changed, 31 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/mesa/pipe/pipebuffer/pb_buffer_fenced.c b/src/mesa/pipe/pipebuffer/pb_buffer_fenced.c index b2edc321ef..349647fe6e 100644 --- a/src/mesa/pipe/pipebuffer/pb_buffer_fenced.c +++ b/src/mesa/pipe/pipebuffer/pb_buffer_fenced.c @@ -80,7 +80,6 @@ struct fenced_buffer struct pb_buffer *buffer; - unsigned refcount; struct pipe_fence_handle *fence; struct list_head head; @@ -145,7 +144,7 @@ _fenced_buffer_list_check_free(struct fenced_buffer_list *fenced_list, /* Do the delayed destroy: */ - pb_destroy(fenced_buf->buffer); + pb_reference(&fenced_buf->buffer, NULL); free(fenced_buf); } } @@ -162,7 +161,7 @@ fenced_buffer_destroy(struct pb_buffer *buf) fenced_list->numDelayed++; } else { - pb_destroy(fenced_buf->buffer); + pb_reference(&fenced_buf->buffer, NULL); free(fenced_buf); } @@ -220,9 +219,13 @@ fenced_buffer_create(struct fenced_buffer_list *fenced_list, if(!buf) return NULL; + buf->base.base.refcount = 1; + buf->base.base.alignment = buffer->base.alignment; + buf->base.base.usage = buffer->base.usage; + buf->base.base.size = buffer->base.size; + buf->base.vtbl = &fenced_buffer_vtbl; buf->buffer = buffer; - buf->refcount = 1; buf->list = fenced_list; return &buf->base; diff --git a/src/mesa/pipe/pipebuffer/pb_buffer_malloc.c b/src/mesa/pipe/pipebuffer/pb_buffer_malloc.c index f0ff1d347e..fc83a00f36 100644 --- a/src/mesa/pipe/pipebuffer/pb_buffer_malloc.c +++ b/src/mesa/pipe/pipebuffer/pb_buffer_malloc.c @@ -114,10 +114,11 @@ pb_malloc_buffer_create(size_t size, if(!buf) return NULL; - buf->base.vtbl = &malloc_buffer_vtbl; + buf->base.base.refcount = 1; buf->base.base.alignment = desc->alignment; buf->base.base.usage = desc->usage; buf->base.base.size = size; + buf->base.vtbl = &malloc_buffer_vtbl; buf->data = align_malloc(size, desc->alignment < sizeof(void*) ? sizeof(void*) : desc->alignment); if(!buf->data) { diff --git a/src/mesa/pipe/pipebuffer/pb_bufmgr_fenced.c b/src/mesa/pipe/pipebuffer/pb_bufmgr_fenced.c index 6a81cbdae0..3b341c64c2 100644 --- a/src/mesa/pipe/pipebuffer/pb_bufmgr_fenced.c +++ b/src/mesa/pipe/pipebuffer/pb_bufmgr_fenced.c @@ -88,6 +88,7 @@ fenced_bufmgr_create_buffer(struct pb_manager *mgr, fenced_buf = fenced_buffer_create(fenced_mgr->fenced_list, buf); if(!fenced_buf) { + assert(buf->base.refcount == 1); pb_destroy(buf); } diff --git a/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c b/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c index 2a62702c36..2694f57bca 100644 --- a/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c +++ b/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c @@ -466,6 +466,11 @@ mm_bufmgr_create_buffer(struct pb_manager *mgr, return NULL; } + mm_buf->base.base.refcount = 1; + mm_buf->base.base.alignment = desc->alignment; + mm_buf->base.base.usage = desc->usage; + mm_buf->base.base.size = size; + mm_buf->base.vtbl = &mm_buffer_vtbl; mm_buf->mgr = mm; @@ -505,7 +510,7 @@ mm_bufmgr_destroy(struct pb_manager *mgr) mmDestroy(mm->heap); pb_unmap(mm->buffer); - pb_destroy(mm->buffer); + pb_reference(&mm->buffer, NULL); _glthread_UNLOCK_MUTEX(mm->mutex); @@ -579,7 +584,7 @@ mm_bufmgr_create(struct pb_manager *provider, mgr = mm_bufmgr_create_from_buffer(buffer, size, align2); if (!mgr) { - pb_destroy(buffer); + pb_reference(&buffer, NULL); return NULL; } diff --git a/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c b/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c index 61c06ec824..7c29954112 100644 --- a/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c +++ b/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c @@ -111,6 +111,8 @@ pool_buffer_destroy(struct pb_buffer *buf) struct pool_buffer *pool_buf = pool_buffer(buf); struct pool_pb_manager *pool = pool_buf->mgr; + assert(pool_buf->base.base.refcount == 0); + _glthread_LOCK_MUTEX(pool->mutex); LIST_ADD(&pool_buf->head, &pool->free); pool->numFree++; @@ -192,7 +194,13 @@ pool_bufmgr_create_buffer(struct pb_manager *mgr, --pool->numFree; _glthread_UNLOCK_MUTEX(pool->mutex); + pool_buf = LIST_ENTRY(struct pool_buffer, item, head); + assert(pool_buf->base.base.refcount == 0); + pool_buf->base.base.refcount = 1; + pool_buf->base.base.alignment = desc->alignment; + pool_buf->base.base.usage = desc->usage; + return SUPER(pool_buf); } @@ -206,7 +214,7 @@ pool_bufmgr_destroy(struct pb_manager *mgr) FREE(pool->bufs); pb_unmap(pool->buffer); - pb_destroy(pool->buffer); + pb_reference(&pool->buffer, NULL); _glthread_UNLOCK_MUTEX(pool->mutex); @@ -256,6 +264,10 @@ pool_bufmgr_create(struct pb_manager *provider, pool_buf = pool->bufs; for (i = 0; i < numBufs; ++i) { + pool_buf->base.base.refcount = 0; + pool_buf->base.base.alignment = 0; + pool_buf->base.base.usage = 0; + pool_buf->base.base.size = bufSize; pool_buf->base.vtbl = &pool_buffer_vtbl; pool_buf->mgr = pool; pool_buf->start = i * bufSize; @@ -271,7 +283,7 @@ failure: if(pool->map) pb_unmap(pool->buffer); if(pool->buffer) - pb_destroy(pool->buffer); + pb_reference(&pool->buffer, NULL); if(pool) FREE(pool); return NULL; -- cgit v1.2.3 From 3b93c74a8d6e36039b79ddf38c11e27aa0bd3b9b Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 28 Jan 2008 14:51:14 +0900 Subject: Cache the vinfo in vbuf_stage. --- src/mesa/pipe/draw/draw_vbuf.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/mesa/pipe/draw/draw_vbuf.c b/src/mesa/pipe/draw/draw_vbuf.c index aea5b4aeee..60ad93133c 100644 --- a/src/mesa/pipe/draw/draw_vbuf.c +++ b/src/mesa/pipe/draw/draw_vbuf.c @@ -50,6 +50,8 @@ struct vbuf_stage { struct vbuf_render *render; + const struct vertex_info *vinfo; + /** Vertex size in bytes */ unsigned vertex_size; @@ -84,8 +86,7 @@ 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_alloc_vertices( struct draw_stage *stage, - unsigned new_vertex_size ); +static void vbuf_alloc_vertices( struct draw_stage *stage ); static INLINE boolean @@ -101,7 +102,7 @@ check_space( struct vbuf_stage *vbuf, unsigned nr ) { if (vbuf->nr_vertices + nr > vbuf->max_vertices ) { vbuf_flush_vertices(&vbuf->stage); - vbuf_alloc_vertices(&vbuf->stage, vbuf->vertex_size); + vbuf_alloc_vertices(&vbuf->stage); } if (vbuf->nr_indices + nr > vbuf->max_indices ) @@ -120,10 +121,12 @@ static INLINE void emit_vertex( struct vbuf_stage *vbuf, struct vertex_header *vertex ) { - const struct vertex_info *vinfo = vbuf->render->get_vertex_info(vbuf->render); + const struct vertex_info *vinfo = vbuf->vinfo; uint i; uint count = 0; /* for debug/sanity */ + + assert(vinfo == vbuf->render->get_vertex_info(vbuf->render)); // fprintf(stderr, "emit vertex %d to %p\n", // vbuf->nr_vertices, vbuf->vertex_ptr); @@ -265,8 +268,11 @@ vbuf_set_prim( struct draw_stage *stage, uint newprim ) if (vertex_size != vbuf->vertex_size) vbuf_flush_vertices(stage); + vbuf->vinfo = vinfo; + vbuf->vertex_size = vertex_size; + if (!vbuf->vertices) - vbuf_alloc_vertices(stage, vertex_size); + vbuf_alloc_vertices(stage); } @@ -364,7 +370,7 @@ vbuf_flush_vertices( struct draw_stage *stage ) vbuf->vertices, vbuf->vertex_size, vbuf->nr_vertices); - vbuf->nr_vertices = 0; + vbuf->max_vertices = vbuf->nr_vertices = 0; vbuf->vertex_ptr = vbuf->vertices = NULL; } @@ -372,8 +378,7 @@ vbuf_flush_vertices( struct draw_stage *stage ) static void -vbuf_alloc_vertices( struct draw_stage *stage, - unsigned new_vertex_size ) +vbuf_alloc_vertices( struct draw_stage *stage ) { struct vbuf_stage *vbuf = vbuf_stage( stage ); @@ -381,7 +386,6 @@ vbuf_alloc_vertices( struct draw_stage *stage, 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 = (uint *) vbuf->render->allocate_vertices(vbuf->render, (ushort) vbuf->vertex_size, -- cgit v1.2.3 From c3f10aef386e0af90f8735d8b9598959c17a590f Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 28 Jan 2008 15:00:08 +0900 Subject: Simplify prototypes of draw_vbuf's internal functions. --- src/mesa/pipe/draw/draw_vbuf.c | 57 +++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/mesa/pipe/draw/draw_vbuf.c b/src/mesa/pipe/draw/draw_vbuf.c index 60ad93133c..1e260c6156 100644 --- a/src/mesa/pipe/draw/draw_vbuf.c +++ b/src/mesa/pipe/draw/draw_vbuf.c @@ -84,9 +84,9 @@ 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_alloc_vertices( struct draw_stage *stage ); +static void vbuf_flush_indices( struct vbuf_stage *vbuf ); +static void vbuf_flush_vertices( struct vbuf_stage *vbuf ); +static void vbuf_alloc_vertices( struct vbuf_stage *vbuf ); static INLINE boolean @@ -101,12 +101,12 @@ 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_alloc_vertices(&vbuf->stage); + vbuf_flush_vertices(vbuf); + vbuf_alloc_vertices(vbuf); } if (vbuf->nr_indices + nr > vbuf->max_indices ) - vbuf_flush_indices(&vbuf->stage); + vbuf_flush_indices(vbuf); } @@ -249,9 +249,8 @@ vbuf_point( struct draw_stage *stage, * will be flushed if needed and a new one allocated. */ static void -vbuf_set_prim( struct draw_stage *stage, uint newprim ) +vbuf_set_prim( struct vbuf_stage *vbuf, uint newprim ) { - struct vbuf_stage *vbuf = vbuf_stage(stage); const struct vertex_info *vinfo; unsigned vertex_size; @@ -266,13 +265,13 @@ vbuf_set_prim( struct draw_stage *stage, uint newprim ) vertex_size = vinfo->size * sizeof(float); if (vertex_size != vbuf->vertex_size) - vbuf_flush_vertices(stage); + vbuf_flush_vertices(vbuf); vbuf->vinfo = vinfo; vbuf->vertex_size = vertex_size; if (!vbuf->vertices) - vbuf_alloc_vertices(stage); + vbuf_alloc_vertices(vbuf); } @@ -280,9 +279,11 @@ static void vbuf_first_tri( struct draw_stage *stage, struct prim_header *prim ) { - vbuf_flush_indices( stage ); + struct vbuf_stage *vbuf = vbuf_stage( stage ); + + vbuf_flush_indices( vbuf ); stage->tri = vbuf_tri; - vbuf_set_prim(stage, PIPE_PRIM_TRIANGLES); + vbuf_set_prim(vbuf, PIPE_PRIM_TRIANGLES); stage->tri( stage, prim ); } @@ -291,9 +292,11 @@ static void vbuf_first_line( struct draw_stage *stage, struct prim_header *prim ) { - vbuf_flush_indices( stage ); + struct vbuf_stage *vbuf = vbuf_stage( stage ); + + vbuf_flush_indices( vbuf ); stage->line = vbuf_line; - vbuf_set_prim(stage, PIPE_PRIM_LINES); + vbuf_set_prim(vbuf, PIPE_PRIM_LINES); stage->line( stage, prim ); } @@ -302,18 +305,18 @@ static void vbuf_first_point( struct draw_stage *stage, struct prim_header *prim ) { - vbuf_flush_indices( stage ); + struct vbuf_stage *vbuf = vbuf_stage( stage ); + + vbuf_flush_indices( vbuf ); stage->point = vbuf_point; - vbuf_set_prim(stage, PIPE_PRIM_POINTS); + vbuf_set_prim(vbuf, PIPE_PRIM_POINTS); stage->point( stage, prim ); } static void -vbuf_flush_indices( struct draw_stage *stage ) +vbuf_flush_indices( struct vbuf_stage *vbuf ) { - struct vbuf_stage *vbuf = vbuf_stage( stage ); - if(!vbuf->nr_indices) return; @@ -354,12 +357,10 @@ vbuf_flush_indices( struct draw_stage *stage ) * we flush. */ static void -vbuf_flush_vertices( struct draw_stage *stage ) +vbuf_flush_vertices( struct vbuf_stage *vbuf ) { - struct vbuf_stage *vbuf = vbuf_stage( stage ); - if(vbuf->vertices) { - vbuf_flush_indices(stage); + vbuf_flush_indices(vbuf); /* Reset temporary vertices ids */ if(vbuf->nr_vertices) @@ -378,10 +379,8 @@ vbuf_flush_vertices( struct draw_stage *stage ) static void -vbuf_alloc_vertices( struct draw_stage *stage ) +vbuf_alloc_vertices( struct vbuf_stage *vbuf ) { - struct vbuf_stage *vbuf = vbuf_stage( stage ); - assert(!vbuf->nr_indices); assert(!vbuf->vertices); @@ -398,14 +397,16 @@ vbuf_alloc_vertices( struct draw_stage *stage ) static void vbuf_flush( struct draw_stage *stage, unsigned flags ) { - vbuf_flush_indices( stage ); + struct vbuf_stage *vbuf = vbuf_stage( stage ); + + vbuf_flush_indices( vbuf ); stage->point = vbuf_first_point; stage->line = vbuf_first_line; stage->tri = vbuf_first_tri; if (flags & DRAW_FLUSH_BACKEND) - vbuf_flush_vertices( stage ); + vbuf_flush_vertices( vbuf ); } -- cgit v1.2.3