From 5104ed3dbf18d47736fc67a8e3e317ea18360fa8 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 13 May 2013 23:07:14 -0400 Subject: draw: try to prevent overflows on index buffers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pass in the size of the index buffer, when available, and use it to handle out of bounds conditions. The behavior in the case of an overflow needs to be the same as with other overflows in the vertex processing pipeline meaning that a vertex should still be generated but all attributes in it set to zero. Signed-off-by: Zack Rusin Reviewed-by: José Fonseca Reviewed-by: Roland Scheidegger --- src/gallium/drivers/softpipe/sp_draw_arrays.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/gallium/drivers/softpipe') diff --git a/src/gallium/drivers/softpipe/sp_draw_arrays.c b/src/gallium/drivers/softpipe/sp_draw_arrays.c index 839fd220500..45b1390de4d 100644 --- a/src/gallium/drivers/softpipe/sp_draw_arrays.c +++ b/src/gallium/drivers/softpipe/sp_draw_arrays.c @@ -89,13 +89,20 @@ softpipe_draw_vbo(struct pipe_context *pipe, /* Map index buffer, if present */ if (info->indexed) { + unsigned available_space = ~0; mapped_indices = sp->index_buffer.user_buffer; - if (!mapped_indices) + if (!mapped_indices) { mapped_indices = softpipe_resource(sp->index_buffer.buffer)->data; + if (sp->index_buffer.buffer->width0 > sp->index_buffer.offset) + available_space = + (sp->index_buffer.buffer->width0 - sp->index_buffer.offset); + else + available_space = 0; + } draw_set_indexes(draw, (ubyte *) mapped_indices + sp->index_buffer.offset, - sp->index_buffer.index_size); + sp->index_buffer.index_size, available_space); } @@ -125,7 +132,7 @@ softpipe_draw_vbo(struct pipe_context *pipe, draw_set_mapped_vertex_buffer(draw, i, NULL, 0); } if (mapped_indices) { - draw_set_indexes(draw, NULL, 0); + draw_set_indexes(draw, NULL, 0, 0); } draw_set_mapped_so_targets(draw, 0, NULL); -- cgit v1.2.3