cell: keep track of num_vertex_attribs/buffers for shorter loops
authorBrian <brian.paul@tungstengraphics.com>
Wed, 9 Apr 2008 03:18:21 +0000 (21:18 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Wed, 9 Apr 2008 03:20:10 +0000 (21:20 -0600)
src/gallium/drivers/cell/ppu/cell_context.h
src/gallium/drivers/cell/ppu/cell_draw_arrays.c
src/gallium/drivers/cell/ppu/cell_state_vertex.c

index 7f656a974478e06c4e00c2bd9826a6ccadbec3be..8df41c1d4caba57c100c83bcfad3ebc80b9cb092 100644 (file)
@@ -104,7 +104,9 @@ struct cell_context
    uint num_textures;
    struct pipe_viewport_state viewport;
    struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
+   uint num_vertex_buffers;
    struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS];
+   uint num_vertex_elements;
 
    ubyte *cbuf_map[PIPE_MAX_COLOR_BUFS];
    ubyte *zsbuf_map;
index b896252f817a7657f7aef515e99b1fe809bad408..36af5be5f028be55391fb596bb96612e52505827 100644 (file)
@@ -123,14 +123,12 @@ cell_draw_elements(struct pipe_context *pipe,
    /*
     * Map vertex buffers
     */
-   for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
-      if (sp->vertex_buffer[i].buffer) {
-         void *buf = pipe->winsys->buffer_map(pipe->winsys,
-                                              sp->vertex_buffer[i].buffer,
-                                              PIPE_BUFFER_USAGE_CPU_READ);
-        cell_flush_buffer_range(sp, buf, sp->vertex_buffer[i].buffer->size);
-         draw_set_mapped_vertex_buffer(draw, i, buf);
-      }
+   for (i = 0; i < sp->num_vertex_buffers; i++) {
+      void *buf = pipe->winsys->buffer_map(pipe->winsys,
+                                           sp->vertex_buffer[i].buffer,
+                                           PIPE_BUFFER_USAGE_CPU_READ);
+      cell_flush_buffer_range(sp, buf, sp->vertex_buffer[i].buffer->size);
+      draw_set_mapped_vertex_buffer(draw, i, buf);
    }
    /* Map index buffer, if present */
    if (indexBuffer) {
@@ -151,11 +149,9 @@ cell_draw_elements(struct pipe_context *pipe,
    /*
     * unmap vertex/index buffers - will cause draw module to flush
     */
-   for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
-      if (sp->vertex_buffer[i].buffer) {
-         draw_set_mapped_vertex_buffer(draw, i, NULL);
-         pipe->winsys->buffer_unmap(pipe->winsys, sp->vertex_buffer[i].buffer);
-      }
+   for (i = 0; i < sp->num_vertex_buffers; i++) {
+      draw_set_mapped_vertex_buffer(draw, i, NULL);
+      pipe->winsys->buffer_unmap(pipe->winsys, sp->vertex_buffer[i].buffer);
    }
    if (indexBuffer) {
       draw_set_mapped_element_buffer(draw, 0, NULL);
index 6c83b8dc72253cad0856375563f724488973bcf8..114684c2a330cdff605414396a62abc7f1993f3e 100644 (file)
@@ -45,6 +45,7 @@ cell_set_vertex_elements(struct pipe_context *pipe,
    assert(count <= PIPE_MAX_ATTRIBS);
 
    memcpy(cell->vertex_element, elements, count * sizeof(elements[0]));
+   cell->num_vertex_elements = count;
 
    cell->dirty |= CELL_NEW_VERTEX;
 
@@ -62,6 +63,7 @@ cell_set_vertex_buffers(struct pipe_context *pipe,
    assert(count <= PIPE_MAX_ATTRIBS);
 
    memcpy(cell->vertex_buffer, buffers, count * sizeof(buffers[0]));
+   cell->num_vertex_buffers = count;
 
    cell->dirty |= CELL_NEW_VERTEX;