diff options
author | Zack Rusin <[email protected]> | 2013-05-13 23:07:14 -0400 |
---|---|---|
committer | Zack Rusin <[email protected]> | 2013-05-14 03:10:56 -0400 |
commit | 5104ed3dbf18d47736fc67a8e3e317ea18360fa8 (patch) | |
tree | d161f1e6f09b3ab6846b064105b8cfc014b203cc /src/gallium/drivers | |
parent | d5250da8189d0fb9741049cdbfc50e84aab44ecb (diff) |
draw: try to prevent overflows on index buffers
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 <[email protected]>
Reviewed-by: José Fonseca <[email protected]>
Reviewed-by: Roland Scheidegger <[email protected]>
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r-- | src/gallium/drivers/i915/i915_context.c | 4 | ||||
-rw-r--r-- | src/gallium/drivers/llvmpipe/lp_draw_arrays.c | 14 | ||||
-rw-r--r-- | src/gallium/drivers/nv30/nv30_draw.c | 4 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_state.c | 2 | ||||
-rw-r--r-- | src/gallium/drivers/softpipe/sp_draw_arrays.c | 13 | ||||
-rw-r--r-- | src/gallium/drivers/svga/svga_swtnl_draw.c | 4 |
6 files changed, 27 insertions, 14 deletions
diff --git a/src/gallium/drivers/i915/i915_context.c b/src/gallium/drivers/i915/i915_context.c index 90427dca963..93599def2a5 100644 --- a/src/gallium/drivers/i915/i915_context.c +++ b/src/gallium/drivers/i915/i915_context.c @@ -83,7 +83,7 @@ i915_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info) mapped_indices = i915_buffer(i915->index_buffer.buffer)->data; draw_set_indexes(draw, (ubyte *) mapped_indices + i915->index_buffer.offset, - i915->index_buffer.index_size); + i915->index_buffer.index_size, ~0); } if (i915->constants[PIPE_SHADER_VERTEX]) @@ -109,7 +109,7 @@ i915_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info) draw_set_mapped_vertex_buffer(i915->draw, i, NULL, 0); } if (mapped_indices) - draw_set_indexes(draw, NULL, 0); + draw_set_indexes(draw, NULL, 0, 0); if (i915->num_vertex_sampler_views > 0) i915_cleanup_vertex_sampling(i915); diff --git a/src/gallium/drivers/llvmpipe/lp_draw_arrays.c b/src/gallium/drivers/llvmpipe/lp_draw_arrays.c index 63c22c31304..4e239043ec4 100644 --- a/src/gallium/drivers/llvmpipe/lp_draw_arrays.c +++ b/src/gallium/drivers/llvmpipe/lp_draw_arrays.c @@ -81,13 +81,19 @@ llvmpipe_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info) /* Map index buffer, if present */ if (info->indexed) { + unsigned available_space = ~0; mapped_indices = lp->index_buffer.user_buffer; - if (!mapped_indices) + if (!mapped_indices) { mapped_indices = llvmpipe_resource_data(lp->index_buffer.buffer); - + if (lp->index_buffer.buffer->width0 > lp->index_buffer.offset) + available_space = + (lp->index_buffer.buffer->width0 - lp->index_buffer.offset); + else + available_space = 0; + } draw_set_indexes(draw, (ubyte *) mapped_indices + lp->index_buffer.offset, - lp->index_buffer.index_size); + lp->index_buffer.index_size, available_space); } for (i = 0; i < lp->num_so_targets; i++) { @@ -126,7 +132,7 @@ llvmpipe_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info) 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); diff --git a/src/gallium/drivers/nv30/nv30_draw.c b/src/gallium/drivers/nv30/nv30_draw.c index 92185c922c2..e0a1628eb91 100644 --- a/src/gallium/drivers/nv30/nv30_draw.c +++ b/src/gallium/drivers/nv30/nv30_draw.c @@ -423,9 +423,9 @@ nv30_render_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info) PIPE_TRANSFER_READ, &transferi); draw_set_indexes(draw, (ubyte *) map + nv30->idxbuf.offset, - nv30->idxbuf.index_size); + nv30->idxbuf.index_size, ~0); } else { - draw_set_indexes(draw, NULL, 0); + draw_set_indexes(draw, NULL, 0, 0); } draw_vbo(draw, info); diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index b3e25e1ad0f..36d510dc45e 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -1856,7 +1856,7 @@ static void r300_set_index_buffer_swtcl(struct pipe_context* pipe, } draw_set_indexes(r300->draw, (const ubyte *) buf + ib->offset, - ib->index_size); + ib->index_size, ~0); } } 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); diff --git a/src/gallium/drivers/svga/svga_swtnl_draw.c b/src/gallium/drivers/svga/svga_swtnl_draw.c index 850575c14b9..0a049569ff7 100644 --- a/src/gallium/drivers/svga/svga_swtnl_draw.c +++ b/src/gallium/drivers/svga/svga_swtnl_draw.c @@ -84,7 +84,7 @@ svga_swtnl_draw_vbo(struct svga_context *svga, &ib_transfer); draw_set_indexes(draw, (const ubyte *) map + svga->curr.ib.offset, - svga->curr.ib.index_size); + svga->curr.ib.index_size, ~0); } if (svga->curr.cb[PIPE_SHADER_VERTEX]) { @@ -118,7 +118,7 @@ svga_swtnl_draw_vbo(struct svga_context *svga, if (ib_transfer) { pipe_buffer_unmap(&svga->pipe, ib_transfer); - draw_set_indexes(draw, NULL, 0); + draw_set_indexes(draw, NULL, 0, 0); } if (svga->curr.cb[PIPE_SHADER_VERTEX]) { |