summaryrefslogtreecommitdiff
path: root/src/gallium
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2013-11-13 11:26:15 -0700
committerIan Romanick <ian.d.romanick@intel.com>2013-11-15 13:39:41 -0800
commitdfff838429060986a0813d74a87ca81b0406df95 (patch)
tree83eff22a938a465627540c70fc3a0302c1e1991f /src/gallium
parent11982ca08dd8ef5111bf2155e52c3de8d2840431 (diff)
svga: do primitive trimming in translate_indices()
The index translation code expects the number of indexes to be consistent with the primitive type (ex: a multiple of 3 for PIPE_PRIM_TRIANGLES). If it's not, we can write out of bounds in the destination buffer. Fixes failed assertions in the pipebuffer debug code found with Piglit primitive-restart-draw-mode test. Cc: "10.0" <mesa-stable@lists.freedesktop.org> Reviewed-by: José Fonseca <jfonseca@vmware.com> (cherry picked from commit 79984b9928d4444665ce617a1e4551e53d415bd4)
Diffstat (limited to 'src/gallium')
-rw-r--r--src/gallium/drivers/svga/svga_draw_elements.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/gallium/drivers/svga/svga_draw_elements.c b/src/gallium/drivers/svga/svga_draw_elements.c
index fb5f1c91b29..f6603be920a 100644
--- a/src/gallium/drivers/svga/svga_draw_elements.c
+++ b/src/gallium/drivers/svga/svga_draw_elements.c
@@ -24,6 +24,7 @@
**********************************************************/
#include "util/u_inlines.h"
+#include "util/u_prim.h"
#include "indices/u_indices.h"
#include "svga_cmd.h"
@@ -37,17 +38,25 @@
static enum pipe_error
translate_indices(struct svga_hwtnl *hwtnl, struct pipe_resource *src,
- unsigned offset, unsigned nr, unsigned index_size,
+ unsigned offset, unsigned prim, unsigned nr,
+ unsigned index_size,
u_translate_func translate, struct pipe_resource **out_buf)
{
struct pipe_context *pipe = &hwtnl->svga->pipe;
struct pipe_transfer *src_transfer = NULL;
struct pipe_transfer *dst_transfer = NULL;
- unsigned size = index_size * nr;
+ unsigned size;
const void *src_map = NULL;
struct pipe_resource *dst = NULL;
void *dst_map = NULL;
+ /* Need to trim vertex count to make sure we don't write too much data
+ * to the dst buffer in the translate() call.
+ */
+ u_trim_pipe_prim(prim, &nr);
+
+ size = index_size * nr;
+
dst = pipe_buffer_create(pipe->screen,
PIPE_BIND_INDEX_BUFFER, PIPE_USAGE_STATIC, size);
if (dst == NULL)
@@ -180,7 +189,7 @@ svga_hwtnl_draw_range_elements(struct svga_hwtnl *hwtnl,
ret = translate_indices(hwtnl,
index_buffer,
start * index_size,
- gen_nr, gen_size, gen_func, &gen_buf);
+ gen_prim, gen_nr, gen_size, gen_func, &gen_buf);
if (ret != PIPE_OK)
goto done;