diff options
author | Zack Rusin <[email protected]> | 2013-07-02 23:56:59 -0400 |
---|---|---|
committer | Zack Rusin <[email protected]> | 2013-07-03 09:06:30 -0400 |
commit | bbd1e60198548a12be3405fc32dd39a87e8968ab (patch) | |
tree | 3d5f40a23d402c74697502ec2a16a3d8517053b5 /src/gallium/auxiliary/draw/draw_private.h | |
parent | 09820902d74eec1eed054388f6999cd66227b6b1 (diff) |
draw: fix overflows in the indexed rendering paths
The semantics for overflow detection are a bit tricky with
indexed rendering. If the base index in the elements array
overflows, then the index of the first element should be used,
if the index with bias overflows then it should be treated
like a normal overflow. Also overflows need to be checked for
in all paths that either the bias, or the starting index location.
Signed-off-by: Zack Rusin <[email protected]>
Reviewed-by: Brian Paul <[email protected]>
Reviewed-by: Roland Scheidegger <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/draw/draw_private.h')
-rw-r--r-- | src/gallium/auxiliary/draw/draw_private.h | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/gallium/auxiliary/draw/draw_private.h b/src/gallium/auxiliary/draw/draw_private.h index f42cded118a..d8cd8ebdb64 100644 --- a/src/gallium/auxiliary/draw/draw_private.h +++ b/src/gallium/auxiliary/draw/draw_private.h @@ -55,6 +55,10 @@ struct gallivm_state; /** Sum of frustum planes and user-defined planes */ #define DRAW_TOTAL_CLIP_PLANES (6 + PIPE_MAX_CLIP_PLANES) +/** + * The largest possible index of a vertex that can be fetched. + */ +#define DRAW_MAX_FETCH_IDX 0xffffffff struct pipe_context; struct draw_vertex_shader; @@ -468,14 +472,13 @@ void draw_stats_clipper_primitives(struct draw_context *draw, const struct draw_prim_info *prim_info); - /** * Return index i from the index buffer. * If the index buffer would overflow we return the - * index of the first element in the vb. + * maximum possible index. */ #define DRAW_GET_IDX(_elts, _i) \ - (((_i) >= draw->pt.user.eltMax) ? 0 : (_elts)[_i]) + (((_i) >= draw->pt.user.eltMax) ? DRAW_MAX_FETCH_IDX : (_elts)[_i]) /** * Return index of the given viewport clamping it @@ -487,5 +490,20 @@ draw_clamp_viewport_idx(int idx) return ((PIPE_MAX_VIEWPORTS > idx || idx < 0) ? idx : 0); } +/** + * Adds two unsigned integers and if the addition + * overflows then it returns the value from + * from the overflow_value variable. + */ +static INLINE unsigned +draw_overflow_uadd(unsigned a, unsigned b, + unsigned overflow_value) +{ + unsigned res = a + b; + if (res < a || res < b) { + res = overflow_value; + } + return res; +} #endif /* DRAW_PRIVATE_H */ |