gallium: keep track of num_vertex_attribs/buffers for shorter loops
authorBrian <brian.paul@tungstengraphics.com>
Wed, 9 Apr 2008 03:07:14 +0000 (21:07 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Wed, 9 Apr 2008 03:20:10 +0000 (21:20 -0600)
src/gallium/drivers/softpipe/sp_context.h
src/gallium/drivers/softpipe/sp_draw_arrays.c
src/gallium/drivers/softpipe/sp_state_vertex.c

index 6f0b234d8936d58e2aa972c2219969f63cc77bec..2442bd1eb008c40e4c82890ac498775525e23646 100644 (file)
@@ -83,6 +83,8 @@ struct softpipe_context {
 
    unsigned num_samplers;
    unsigned num_textures;
+   unsigned num_vertex_elements;
+   unsigned num_vertex_buffers;
 
    /* Counter for occlusion queries.  Note this supports overlapping
     * queries.
index ab54050d3fe1eb77c4a5b772290f8c09362cb836..61bcf51899356b5397526cb7f0e01ae74b2bc8fc 100644 (file)
@@ -125,14 +125,12 @@ softpipe_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);
-         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);
+      draw_set_mapped_vertex_buffer(draw, i, buf);
    }
    /* Map index buffer, if present */
    if (indexBuffer) {
@@ -153,11 +151,9 @@ softpipe_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 e0230e16a4e2cf5e9f1f165b615b2eca2bb5accd..46b6991195d80d64a9e6640557e62c407598935e 100644 (file)
@@ -47,6 +47,7 @@ softpipe_set_vertex_elements(struct pipe_context *pipe,
 
    memcpy(softpipe->vertex_element, attribs,
           count * sizeof(struct pipe_vertex_element));
+   softpipe->num_vertex_elements = count;
 
    softpipe->dirty |= SP_NEW_VERTEX;
 
@@ -64,6 +65,7 @@ softpipe_set_vertex_buffers(struct pipe_context *pipe,
    assert(count <= PIPE_MAX_ATTRIBS);
 
    memcpy(softpipe->vertex_buffer, buffers, count * sizeof(buffers[0]));
+   softpipe->num_vertex_buffers = count;
 
    softpipe->dirty |= SP_NEW_VERTEX;