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

index fee33d82de45ba60444116f34e9b00edf0940174..58a5854f0d9c8d6121b012dc544020afde1e9336 100644 (file)
@@ -65,14 +65,12 @@ i915_draw_elements( struct pipe_context *pipe,
    /*
     * Map vertex buffers
     */
-   for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
-      if (i915->vertex_buffer[i].buffer) {
-         void *buf
-            = pipe->winsys->buffer_map(pipe->winsys,
-                                       i915->vertex_buffer[i].buffer,
-                                       PIPE_BUFFER_USAGE_CPU_READ);
-         draw_set_mapped_vertex_buffer(draw, i, buf);
-      }
+   for (i = 0; i < i915->num_vertex_buffers; i++) {
+      void *buf
+         = pipe->winsys->buffer_map(pipe->winsys,
+                                    i915->vertex_buffer[i].buffer,
+                                    PIPE_BUFFER_USAGE_CPU_READ);
+      draw_set_mapped_vertex_buffer(draw, i, buf);
    }
    /* Map index buffer, if present */
    if (indexBuffer) {
@@ -96,11 +94,9 @@ i915_draw_elements( struct pipe_context *pipe,
    /*
     * unmap vertex/index buffers
     */
-   for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
-      if (i915->vertex_buffer[i].buffer) {
-         pipe->winsys->buffer_unmap(pipe->winsys, i915->vertex_buffer[i].buffer);
-         draw_set_mapped_vertex_buffer(draw, i, NULL);
-      }
+   for (i = 0; i < i915->num_vertex_buffers; i++) {
+      pipe->winsys->buffer_unmap(pipe->winsys, i915->vertex_buffer[i].buffer);
+      draw_set_mapped_vertex_buffer(draw, i, NULL);
    }
    if (indexBuffer) {
       pipe->winsys->buffer_unmap(pipe->winsys, indexBuffer);
index 8e707ea574ae9e1d49ff30c96b5a62293dc2325e..38e6a348845a13c0c63d248c6e33f692477ac6ff 100644 (file)
@@ -238,6 +238,8 @@ struct i915_context
 \r
    unsigned num_samplers;\r
    unsigned num_textures;\r
+   unsigned num_vertex_elements;\r
+   unsigned num_vertex_buffers;\r
 \r
    unsigned *batch_start;\r
 \r
index 4404bc459011cdc680623151aa31b0d889f896a0..24d31ad740e658b0f900bdfa891b9358e6d90ee8 100644 (file)
@@ -694,6 +694,8 @@ static void i915_set_vertex_buffers(struct pipe_context *pipe,
    struct i915_context *i915 = i915_context(pipe);
 
    memcpy(i915->vertex_buffer, buffers, count * sizeof(buffers[0]));
+   i915->num_vertex_buffers = count;
+
    /* pass-through to draw module */
    draw_set_vertex_buffers(i915->draw, count, buffers);
 }
@@ -703,6 +705,7 @@ static void i915_set_vertex_elements(struct pipe_context *pipe,
                                      const struct pipe_vertex_element *elements)
 {
    struct i915_context *i915 = i915_context(pipe);
+   i915->num_vertex_elements = count;
    /* pass-through to draw module */
    draw_set_vertex_elements(i915->draw, count, elements);
 }