r300g: use u_vbuf_mgr to set/get the index buffer
authorMarek Olšák <maraeo@gmail.com>
Sun, 20 Nov 2011 02:43:11 +0000 (03:43 +0100)
committerMarek Olšák <maraeo@gmail.com>
Sun, 20 Nov 2011 15:24:12 +0000 (16:24 +0100)
src/gallium/drivers/r300/r300_context.h
src/gallium/drivers/r300/r300_render.c
src/gallium/drivers/r300/r300_state.c

index 08353567f44505c6f389caab5078ca357bd5dcb3..4909b7e754017dc9e0d754c76b059db955551fa1 100644 (file)
@@ -546,8 +546,6 @@ struct r300_context {
     /* Vertex elements for Gallium. */
     struct r300_vertex_element_state *velems;
 
-    struct pipe_index_buffer index_buffer;
-
     /* Vertex info for Draw. */
     struct vertex_info vertex_info;
 
index 9d980813b4cd7bae5e5b9c64e203f6ea752999e6..84cabc0bac37cd9ae8fa2eab843363dd5fc1e1d7 100644 (file)
@@ -509,7 +509,7 @@ static void r300_draw_elements_immediate(struct r300_context *r300,
     uint8_t *ptr1;
     uint16_t *ptr2;
     uint32_t *ptr4;
-    unsigned index_size = r300->index_buffer.index_size;
+    unsigned index_size = r300->vbuf_mgr->index_buffer.index_size;
     unsigned i, count_dwords = index_size == 4 ? info->count :
                                                  (info->count + 1) / 2;
     CS_LOCALS(r300);
@@ -527,7 +527,7 @@ static void r300_draw_elements_immediate(struct r300_context *r300,
 
     switch (index_size) {
     case 1:
-        ptr1 = r300_resource(r300->index_buffer.buffer)->b.user_ptr;
+        ptr1 = r300_resource(r300->vbuf_mgr->index_buffer.buffer)->b.user_ptr;
         ptr1 += info->start;
 
         OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (info->count << 16) |
@@ -551,7 +551,7 @@ static void r300_draw_elements_immediate(struct r300_context *r300,
         break;
 
     case 2:
-        ptr2 = (uint16_t*)r300_resource(r300->index_buffer.buffer)->b.user_ptr;
+        ptr2 = (uint16_t*)r300_resource(r300->vbuf_mgr->index_buffer.buffer)->b.user_ptr;
         ptr2 += info->start;
 
         OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (info->count << 16) |
@@ -570,7 +570,7 @@ static void r300_draw_elements_immediate(struct r300_context *r300,
         break;
 
     case 4:
-        ptr4 = (uint32_t*)r300_resource(r300->index_buffer.buffer)->b.user_ptr;
+        ptr4 = (uint32_t*)r300_resource(r300->vbuf_mgr->index_buffer.buffer)->b.user_ptr;
         ptr4 += info->start;
 
         OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (info->count << 16) |
@@ -592,8 +592,8 @@ static void r300_draw_elements(struct r300_context *r300,
                                const struct pipe_draw_info *info,
                                int instance_id)
 {
-    struct pipe_resource *indexBuffer = r300->index_buffer.buffer;
-    unsigned indexSize = r300->index_buffer.index_size;
+    struct pipe_resource *indexBuffer = r300->vbuf_mgr->index_buffer.buffer;
+    unsigned indexSize = r300->vbuf_mgr->index_buffer.index_size;
     struct pipe_resource* orgIndexBuffer = indexBuffer;
     unsigned start = info->start;
     unsigned count = info->count;
@@ -744,7 +744,7 @@ static void r300_draw_vbo(struct pipe_context* pipe,
     struct r300_context* r300 = r300_context(pipe);
     struct pipe_draw_info info = *dinfo;
 
-    info.indexed = info.indexed && r300->index_buffer.buffer;
+    info.indexed = info.indexed && r300->vbuf_mgr->index_buffer.buffer;
 
     if (r300->skip_rendering ||
         !u_trim_pipe_prim(info.mode, &info.count)) {
@@ -760,12 +760,12 @@ static void r300_draw_vbo(struct pipe_context* pipe,
 
     /* Draw. */
     if (info.indexed) {
-        info.start += r300->index_buffer.offset;
+        info.start += r300->vbuf_mgr->index_buffer.offset / r300->vbuf_mgr->index_buffer.index_size;
         info.max_index = MIN2(r300->vbuf_mgr->max_index, info.max_index);
 
         if (info.instance_count <= 1) {
             if (info.count <= 8 &&
-                r300_resource(r300->index_buffer.buffer)->b.user_ptr) {
+                r300_resource(r300->vbuf_mgr->index_buffer.buffer)->b.user_ptr) {
                 r300_draw_elements_immediate(r300, &info);
             } else {
                 r300_draw_elements(r300, &info, -1);
@@ -802,7 +802,7 @@ static void r300_swtcl_draw_vbo(struct pipe_context* pipe,
     struct pipe_transfer *ib_transfer = NULL;
     int i;
     void *indices = NULL;
-    boolean indexed = info->indexed && r300->index_buffer.buffer;
+    boolean indexed = info->indexed && r300->vbuf_mgr->index_buffer.buffer;
 
     if (r300->skip_rendering) {
         return;
@@ -827,7 +827,7 @@ static void r300_swtcl_draw_vbo(struct pipe_context* pipe,
     }
 
     if (indexed) {
-        indices = pipe_buffer_map(pipe, r300->index_buffer.buffer,
+        indices = pipe_buffer_map(pipe, r300->vbuf_mgr->index_buffer.buffer,
                                   PIPE_TRANSFER_READ |
                                   PIPE_TRANSFER_UNSYNCHRONIZED, &ib_transfer);
     }
index 11282a45e0fa38a737911e2bd4085fa96df7c466..10d7ac285d316dcfd69767a73e012e75ff6a7a36 100644 (file)
@@ -1604,17 +1604,7 @@ static void r300_set_index_buffer(struct pipe_context* pipe,
 {
     struct r300_context* r300 = r300_context(pipe);
 
-    if (ib && ib->buffer) {
-        assert(ib->offset % ib->index_size == 0);
-
-        pipe_resource_reference(&r300->index_buffer.buffer, ib->buffer);
-        memcpy(&r300->index_buffer, ib, sizeof(r300->index_buffer));
-        r300->index_buffer.offset /= r300->index_buffer.index_size;
-    }
-    else {
-        pipe_resource_reference(&r300->index_buffer.buffer, NULL);
-        memset(&r300->index_buffer, 0, sizeof(r300->index_buffer));
-    }
+    u_vbuf_set_index_buffer(r300->vbuf_mgr, ib);
 
     if (!r300->screen->caps.has_tcl) {
         draw_set_index_buffer(r300->draw, ib);