r300g: always emit the correct max vertex index to avoid DRM errors
authorMarek Olšák <maraeo@gmail.com>
Fri, 26 Feb 2010 23:37:01 +0000 (00:37 +0100)
committerMarek Olšák <maraeo@gmail.com>
Sat, 27 Feb 2010 17:39:35 +0000 (18:39 +0100)
Fixing bizarre reports that a vertex buffer is not large enough.

src/gallium/drivers/r300/r300_context.h
src/gallium/drivers/r300/r300_render.c
src/gallium/drivers/r300/r300_state.c

index 3d4f6524e5b625945afb91cf23e3f35875fa311a..8704f1852937b693c7b4e7f3a2aeec264100d003 100644 (file)
@@ -326,6 +326,7 @@ struct r300_context {
     /* Vertex buffers for Gallium. */
     struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
     int vertex_buffer_count;
+    int vertex_buffer_max_index;
     /* Vertex elements for Gallium. */
     struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS];
     int vertex_element_count;
index d604bfb7d75f86c4cfe6d24a938472515a1e12f8..e4f7615368db08b835e925976f77f857dd5575e6 100644 (file)
@@ -452,8 +452,11 @@ void r300_draw_elements(struct pipe_context* pipe,
                         unsigned indexSize, unsigned mode,
                         unsigned start, unsigned count)
 {
-   pipe->draw_range_elements(pipe, indexBuffer, indexSize, 0, ~0,
-                             mode, start, count);
+    struct r300_context *r300 = r300_context(pipe);
+
+    pipe->draw_range_elements(pipe, indexBuffer, indexSize, 0,
+                              r300->vertex_buffer_max_index,
+                              mode, start, count);
 }
 
 void r300_draw_arrays(struct pipe_context* pipe, unsigned mode,
index 0f14ccc53e59766857e8d57b9fe0341f4e796d83..ee4409c88998dc4bbc9c6c73ad6615d3385b38bb 100644 (file)
@@ -1026,10 +1026,17 @@ static void r300_set_vertex_buffers(struct pipe_context* pipe,
                                     const struct pipe_vertex_buffer* buffers)
 {
     struct r300_context* r300 = r300_context(pipe);
+    unsigned i, max_index = ~0;
 
     memcpy(r300->vertex_buffer, buffers,
         sizeof(struct pipe_vertex_buffer) * count);
+
+    for (i = 0; i < count; i++) {
+        max_index = MIN2(buffers[i].max_index, max_index);
+    }
+
     r300->vertex_buffer_count = count;
+    r300->vertex_buffer_max_index = max_index;
 
     if (r300->draw) {
         draw_flush(r300->draw);