r600g: Cleaned up index buffer reference handling in the draw module.
authorTilman Sauerbeck <tilman@code-monkey.de>
Sun, 26 Sep 2010 17:26:24 +0000 (19:26 +0200)
committerTilman Sauerbeck <tilman@code-monkey.de>
Tue, 28 Sep 2010 20:12:23 +0000 (22:12 +0200)
This fixes a buffer leak.

Signed-off-by: Tilman Sauerbeck <tilman@code-monkey.de>
src/gallium/drivers/r600/r600_buffer.c
src/gallium/drivers/r600/r600_draw.c
src/gallium/drivers/r600/r600_state2.c

index 1621b2ab63f3cef4ac4893d8ef2babed4ae23fb1..d734e2349fbec567c96dc701ff52c83da15572cb 100644 (file)
@@ -280,7 +280,10 @@ int r600_upload_index_buffer(struct r600_context *rctx,
                        goto done;
                }
                draw->index_buffer_offset = index_offset;
-               draw->index_buffer = upload_buffer;
+
+               /* Transfer ownership. */
+               pipe_resource_reference(&draw->index_buffer, upload_buffer);
+               pipe_resource_reference(&upload_buffer, NULL);
        }
 
 done:
index afc3b7bba16d63bf3a58f0ec201d3747665bc724..c41156f15fd3e091f06078433b9b684c55a25a9a 100644 (file)
@@ -168,7 +168,7 @@ void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
                                            info->count);
 
                draw.index_size = rctx->index_buffer.index_size;
-               draw.index_buffer = rctx->index_buffer.buffer;
+               pipe_resource_reference(&draw.index_buffer, rctx->index_buffer.buffer);
                draw.index_buffer_offset = draw.start * draw.index_size;
                draw.start = 0;
                r600_upload_index_buffer(rctx, &draw);
@@ -185,4 +185,6 @@ void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
        r = r600_draw_common(&draw);
        if (r)
          fprintf(stderr,"draw common failed %d\n", r);
+
+       pipe_resource_reference(&draw.index_buffer, NULL);
 }
index 796442f5a4baad7a8f579822db529af426c6506d..bbbf2790cccbbdd5eec24756f4fecca4007b0dd1 100644 (file)
@@ -672,7 +672,7 @@ static void r600_draw_vbo2(struct pipe_context *ctx, const struct pipe_draw_info
                                            info->count);
 
                draw.index_size = rctx->index_buffer.index_size;
-               draw.index_buffer = rctx->index_buffer.buffer;
+               pipe_resource_reference(&draw.index_buffer, rctx->index_buffer.buffer);
                draw.index_buffer_offset = draw.start * draw.index_size;
                draw.start = 0;
                r600_upload_index_buffer2(rctx, &draw);
@@ -684,6 +684,8 @@ static void r600_draw_vbo2(struct pipe_context *ctx, const struct pipe_draw_info
                draw.index_bias = info->start;
        }
        r600_draw_common(&draw);
+
+       pipe_resource_reference(&draw.index_buffer, NULL);
 }
 
 static void r600_flush2(struct pipe_context *ctx, unsigned flags,
@@ -2463,7 +2465,10 @@ int r600_upload_index_buffer2(struct r600_pipe_context *rctx, struct r600_drawl
                        goto done;
                }
                draw->index_buffer_offset = index_offset;
-               draw->index_buffer = upload_buffer;
+
+               /* Transfer ownership. */
+               pipe_resource_reference(&draw->index_buffer, upload_buffer);
+               pipe_resource_reference(&upload_buffer, NULL);
        }
 
 done: