Cell: compute min index referenced in draw command, use it to reduce size of vertex data payload

This commit is contained in:
Brian 2008-01-28 18:03:45 -07:00
parent 25105276b3
commit e2406b4788
3 changed files with 29 additions and 6 deletions

View file

@ -124,6 +124,8 @@ struct cell_command_render
uint num_indexes;
uint vertex_buf; /**< which cell->buffer[] contains the vertex data */
float xmin, dummy2, ymin, xmax, ymax; /* XXX another dummy field */
uint dummy3;
uint min_index;
boolean inline_verts;
} ALIGN16_ATTRIB;

View file

@ -138,16 +138,23 @@ cell_vbuf_draw(struct vbuf_render *vbr,
struct cell_context *cell = cvbr->cell;
float xmin, ymin, xmax, ymax;
uint i;
uint nr_vertices = 0;
uint nr_vertices = 0, min_index = ~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];
if (indices[i] < min_index)
min_index = indices[i];
}
nr_vertices++;
#if 0
/*if (min_index > 0)*/
printf("%s min_index = %u\n", __FUNCTION__, min_index);
#endif
#if 0
printf("cell_vbuf_draw() nr_indices = %u nr_verts = %u\n",
nr_indices, nr_vertices);
@ -169,7 +176,7 @@ cell_vbuf_draw(struct vbuf_render *vbr,
/* compute x/y bounding box */
xmin = ymin = 1e50;
xmax = ymax = -1e50;
for (i = 0; i < nr_vertices; i++) {
for (i = min_index; i < nr_vertices; i++) {
const float *v = (float *) ((ubyte *) vertices + i * vertex_size);
if (v[0] < xmin)
xmin = v[0];
@ -204,6 +211,7 @@ cell_vbuf_draw(struct vbuf_render *vbr,
render->prim_type = cvbr->prim;
render->num_indexes = nr_indices;
render->min_index = min_index;
/* append indices after render command */
memcpy(render + 1, indices, nr_indices * 2);
@ -214,6 +222,7 @@ cell_vbuf_draw(struct vbuf_render *vbr,
render->vertex_size = 4 * cell->vertex_info.size;
render->num_verts = nr_vertices;
if (ALLOW_INLINE_VERTS &&
min_index == 0 &&
vertex_bytes <= cell_batch_free_space(cell)) {
/* vertex data inlined, after indices */
void *dst = cell_batch_alloc(cell, vertex_bytes);

View file

@ -253,7 +253,7 @@ cmd_render(const struct cell_command_render *render, uint *pos_incr)
/* we'll DMA into these buffers */
ubyte vertex_data[CELL_BUFFER_SIZE] ALIGN16_ATTRIB;
const uint vertex_size = render->vertex_size; /* in bytes */
const uint total_vertex_bytes = render->num_verts * vertex_size;
/*const*/ uint total_vertex_bytes = render->num_verts * vertex_size;
const ubyte *vertices;
const ushort *indexes;
uint i, j;
@ -289,9 +289,21 @@ cmd_render(const struct cell_command_render *render, uint *pos_incr)
}
else {
/* Begin DMA fetch of vertex buffer */
void *src = spu.init.buffers[render->vertex_buf];
mfc_get(vertex_data, /* dest */
(unsigned int) src,
ubyte *src = spu.init.buffers[render->vertex_buf];
ubyte *dest = vertex_data;
/* skip vertex data we won't use */
#if 01
src += render->min_index * vertex_size;
dest += render->min_index * vertex_size;
total_vertex_bytes -= render->min_index * vertex_size;
#endif
ASSERT(total_vertex_bytes % 16 == 0);
ASSERT_ALIGN16(dest);
ASSERT_ALIGN16(src);
mfc_get(dest, /* in vertex_data[] array */
(unsigned int) src, /* src in main memory */
total_vertex_bytes, /* size */
TAG_VERTEX_BUFFER,
0, /* tid */