From 887b69a2336df21d2c61ad65352a0cc7f23fec41 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Thu, 24 Apr 2014 16:13:54 +0200 Subject: [PATCH] radeonsi: don't add info->start to the index buffer offset MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit info->start will be invalid once info->indirect isn't NULL, so it shouldn't be added to ib.offset. Reviewed-by: Michel Dänzer --- src/gallium/drivers/radeonsi/si_state_draw.c | 36 ++++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/gallium/drivers/radeonsi/si_state_draw.c b/src/gallium/drivers/radeonsi/si_state_draw.c index 0007a70fe69..e2b29c349be 100644 --- a/src/gallium/drivers/radeonsi/si_state_draw.c +++ b/src/gallium/drivers/radeonsi/si_state_draw.c @@ -803,6 +803,7 @@ static void si_state_draw(struct si_context *sctx, si_pm4_add_bo(pm4, (struct r600_resource *)ib->buffer, RADEON_USAGE_READ, RADEON_PRIO_MIN); + va += info->start * ib->index_size; si_cmd_draw_index_2(pm4, max_size, va, info->count, V_0287F0_DI_SRC_SEL_DMA, sctx->b.predicate_drawing); @@ -917,30 +918,43 @@ void si_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info) pipe_resource_reference(&ib.buffer, sctx->index_buffer.buffer); ib.user_buffer = sctx->index_buffer.user_buffer; ib.index_size = sctx->index_buffer.index_size; - ib.offset = sctx->index_buffer.offset + info->start * ib.index_size; + ib.offset = sctx->index_buffer.offset; /* Translate or upload, if needed. */ if (ib.index_size == 1) { struct pipe_resource *out_buffer = NULL; - unsigned out_offset; + unsigned out_offset, start, count, start_offset; void *ptr; - u_upload_alloc(sctx->b.uploader, 0, info->count * 2, + start = info->start; + count = info->count; + start_offset = start * ib.index_size; + + u_upload_alloc(sctx->b.uploader, start_offset, count * 2, &out_offset, &out_buffer, &ptr); - util_shorten_ubyte_elts_to_userptr( - &sctx->b.b, &ib, 0, ib.offset, info->count, ptr); + util_shorten_ubyte_elts_to_userptr(&sctx->b.b, &ib, 0, + ib.offset + start_offset, + count, ptr); pipe_resource_reference(&ib.buffer, NULL); ib.user_buffer = NULL; ib.buffer = out_buffer; - ib.offset = out_offset; + /* info->start will be added by the drawing code */ + ib.offset = out_offset - start_offset; ib.index_size = 2; - } - - if (ib.user_buffer && !ib.buffer) { - u_upload_data(sctx->b.uploader, 0, info->count * ib.index_size, - ib.user_buffer, &ib.offset, &ib.buffer); + } else if (ib.user_buffer && !ib.buffer) { + unsigned start, count, start_offset; + + start = info->start; + count = info->count; + start_offset = start * ib.index_size; + + u_upload_data(sctx->b.uploader, start_offset, count * ib.index_size, + (char*)ib.user_buffer + start_offset, + &ib.offset, &ib.buffer); + /* info->start will be added by the drawing code */ + ib.offset -= start_offset; } } -- 2.30.2