r300g: simplify the code for buffer uploads
authorMarek Olšák <maraeo@gmail.com>
Sat, 25 Dec 2010 13:46:45 +0000 (14:46 +0100)
committerMarek Olšák <maraeo@gmail.com>
Sat, 25 Dec 2010 15:07:13 +0000 (16:07 +0100)
src/gallium/drivers/r300/r300_render.c
src/gallium/drivers/r300/r300_screen_buffer.c
src/gallium/drivers/r300/r300_screen_buffer.h

index 142538b36575580595c08bf735557b8f6a0775ea..92d12743a45b6b3be91daa341213e33508fecc4a 100644 (file)
@@ -592,15 +592,16 @@ static void r300_draw_range_elements(struct pipe_context* pipe,
              * The start index will be aligned simply from the fact that
              * every sub-buffer in u_upload_mgr is aligned. */
             userbuf = pipe->screen->user_buffer_create(pipe->screen,
-                                                       ptr + start, count * 2,
+                                                       ptr, count * 2,
                                                        PIPE_BIND_INDEX_BUFFER);
             indexBuffer = userbuf;
-            r300_upload_index_buffer(r300, &indexBuffer, indexSize, 0, count, &start);
+            r300_upload_index_buffer(r300, &indexBuffer, indexSize, &start, count);
             pipe_resource_reference(&userbuf, NULL);
         }
         pipe_buffer_unmap(pipe, transfer);
     } else {
-        r300_upload_index_buffer(r300, &indexBuffer, indexSize, start, count, &start);
+        if (r300_buffer_is_user_buffer(indexBuffer))
+            r300_upload_index_buffer(r300, &indexBuffer, indexSize, &start, count);
     }
 
     /* 19 dwords for emit_draw_elements. Give up if the function fails. */
index 44364435221c9dc83ec0d55a01fe114b905c20b4..1bf922ef351449871a995c447a14ea4e1328b4e7 100644 (file)
@@ -56,72 +56,42 @@ static unsigned r300_buffer_is_referenced_by_cs(struct pipe_context *context,
     return r300_buffer_is_referenced(context, buf, R300_REF_CS);
 }
 
-/* External helper, not required to implent u_resource_vtbl:
- */
-int r300_upload_index_buffer(struct r300_context *r300,
-                            struct pipe_resource **index_buffer,
-                            unsigned index_size,
-                            unsigned start,
-                            unsigned count,
-                            unsigned *out_offset)
+void r300_upload_index_buffer(struct r300_context *r300,
+                             struct pipe_resource **index_buffer,
+                             unsigned index_size, unsigned *start,
+                             unsigned count)
 {
-   struct pipe_resource *upload_buffer = NULL;
-   unsigned index_offset = start * index_size;
-   int ret = 0;
-
-    if (r300_buffer_is_user_buffer(*index_buffer)) {
-       ret = u_upload_buffer(r300->upload_ib,
-                             index_offset,
-                             count * index_size,
-                             *index_buffer,
-                             &index_offset,
-                             &upload_buffer);
-       if (ret) {
-           goto done;
-       }
-       *index_buffer = upload_buffer;
-       *out_offset = index_offset / index_size;
-    } else
-        *out_offset = start;
-
- done:
-    //    if (upload_buffer)
-    // pipe_resource_reference(&upload_buffer, NULL);
-    return ret;
+    unsigned index_offset;
+    uint8_t *ptr = r300_buffer(*index_buffer)->user_buffer;
+
+    *index_buffer = NULL;
+
+    u_upload_data(r300->upload_ib,
+                  count * index_size,
+                  ptr + (*start * index_size),
+                  &index_offset,
+                  index_buffer);
+
+    *start = index_offset / index_size;
 }
 
-/* External helper, not required to implement u_resource_vtbl:
- */
-int r300_upload_user_buffers(struct r300_context *r300)
+void r300_upload_user_buffers(struct r300_context *r300)
 {
-    enum pipe_error ret = PIPE_OK;
-    int i, nr;
-
-    nr = r300->velems->count;
+    int i, nr = r300->velems->count;
 
     for (i = 0; i < nr; i++) {
         struct pipe_vertex_buffer *vb =
             &r300->vertex_buffer[r300->velems->velem[i].vertex_buffer_index];
 
         if (r300_buffer_is_user_buffer(vb->buffer)) {
-            struct pipe_resource *upload_buffer = NULL;
-            unsigned offset = 0; /*vb->buffer_offset * 4;*/
-            unsigned size = vb->buffer->width0;
-            unsigned upload_offset;
-            ret = u_upload_buffer(r300->upload_vb,
-                                  offset, size,
-                                  vb->buffer,
-                                  &upload_offset, &upload_buffer);
-            if (ret)
-                return ret;
-
-            pipe_resource_reference(&vb->buffer, NULL);
-            vb->buffer = upload_buffer;
-            vb->buffer_offset = upload_offset;
+            u_upload_data(r300->upload_vb,
+                          vb->buffer->width0,
+                          r300_buffer(vb->buffer)->user_buffer,
+                          &vb->buffer_offset, &vb->buffer);
+
             r300->validate_buffers = TRUE;
         }
     }
-    return ret;
 }
 
 static void r300_buffer_destroy(struct pipe_screen *screen,
index 0b3555dd813583d62cb0ebcf0a83d66389f5770c..fb0033c0f59e1e8355b389acc014f9ee933e6f9c 100644 (file)
@@ -63,13 +63,12 @@ struct r300_buffer
 
 /* Functions. */
 
-int r300_upload_user_buffers(struct r300_context *r300);
+void r300_upload_user_buffers(struct r300_context *r300);
 
-int r300_upload_index_buffer(struct r300_context *r300,
-                            struct pipe_resource **index_buffer,
-                            unsigned index_size,
-                            unsigned start,
-                            unsigned count, unsigned *out_offset);
+void r300_upload_index_buffer(struct r300_context *r300,
+                             struct pipe_resource **index_buffer,
+                             unsigned index_size, unsigned *start,
+                             unsigned count);
 
 struct pipe_resource *r300_buffer_create(struct pipe_screen *screen,
                                         const struct pipe_resource *templ);