From: Zack Rusin Date: Sat, 25 May 2013 05:04:17 +0000 (-0400) Subject: llvmpipe: clamp scissors to be between 0 and max X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c88ce3480c715ab40f4d488c86c90213b1472613;p=mesa.git llvmpipe: clamp scissors to be between 0 and max We need to clamp to make sure invalid shader doesn't crash our driver. The spec says to return 0-th index for everything that's out of bounds. Signed-off-by: Zack Rusin Reviewed-by: José Fonseca Reviewed-by: Brian Paul --- diff --git a/src/gallium/drivers/llvmpipe/lp_setup.h b/src/gallium/drivers/llvmpipe/lp_setup.h index 1f55aa41c7f..712ed145d8e 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup.h +++ b/src/gallium/drivers/llvmpipe/lp_setup.h @@ -154,4 +154,10 @@ void lp_setup_end_query(struct lp_setup_context *setup, struct llvmpipe_query *pq); +static INLINE unsigned +lp_clamp_scissor_idx(int idx) +{ + return (PIPE_MAX_VIEWPORTS > idx && idx >= 0) ? idx : 0; +} + #endif diff --git a/src/gallium/drivers/llvmpipe/lp_setup_line.c b/src/gallium/drivers/llvmpipe/lp_setup_line.c index c2a069fe066..57a96d57ce7 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup_line.c +++ b/src/gallium/drivers/llvmpipe/lp_setup_line.c @@ -318,7 +318,7 @@ try_setup_line( struct lp_setup_context *setup, nr_planes = 8; if (setup->viewport_index_slot > 0) { unsigned *udata = (unsigned*)v1[setup->viewport_index_slot]; - scissor_index = *udata; + scissor_index = lp_clamp_scissor_idx(*udata); } } else { diff --git a/src/gallium/drivers/llvmpipe/lp_setup_point.c b/src/gallium/drivers/llvmpipe/lp_setup_point.c index 30ce7490de9..b8040ae56f6 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup_point.c +++ b/src/gallium/drivers/llvmpipe/lp_setup_point.c @@ -328,7 +328,7 @@ try_setup_point( struct lp_setup_context *setup, if (setup->viewport_index_slot > 0) { unsigned *udata = (unsigned*)v0[setup->viewport_index_slot]; - scissor_index = *udata; + scissor_index = lp_clamp_scissor_idx(*udata); } /* Bounding rectangle (in pixels) */ { diff --git a/src/gallium/drivers/llvmpipe/lp_setup_tri.c b/src/gallium/drivers/llvmpipe/lp_setup_tri.c index c1ba52e8ca6..e0aaa196c9a 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup_tri.c +++ b/src/gallium/drivers/llvmpipe/lp_setup_tri.c @@ -258,7 +258,7 @@ do_triangle_ccw(struct lp_setup_context *setup, nr_planes = 7; if (setup->viewport_index_slot > 0) { unsigned *udata = (unsigned*)v0[setup->viewport_index_slot]; - scissor_index = *udata; + scissor_index = lp_clamp_scissor_idx(*udata); } } else { diff --git a/src/gallium/drivers/llvmpipe/lp_state_clip.c b/src/gallium/drivers/llvmpipe/lp_state_clip.c index 0e027fa9128..2d4f27c78ab 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_clip.c +++ b/src/gallium/drivers/llvmpipe/lp_state_clip.c @@ -71,8 +71,12 @@ llvmpipe_set_scissor_states(struct pipe_context *pipe, draw_flush(llvmpipe->draw); + debug_assert(start_slot < PIPE_MAX_VIEWPORTS); + debug_assert((start_slot + num_scissors) <= PIPE_MAX_VIEWPORTS); + memcpy(llvmpipe->scissors + start_slot, scissors, sizeof(struct pipe_scissor_state) * num_scissors); + llvmpipe->dirty |= LP_NEW_SCISSOR; }