From 108ba81c959021ba894553b2c409593c7c51b7bd Mon Sep 17 00:00:00 2001 From: Duncan Hopkins Date: Wed, 10 Jul 2019 14:50:16 +0100 Subject: zink: fix line-width calculation There's two things that goes wrong in this code on some drivers: 1. Rounding off the line-width to granularity can push it outside the legal range. 2. A granularity of 0.0 results in NaN, because we divide by zero. So let's make this code a bit more robust. Acked-by: Jordan Justen --- src/gallium/drivers/zink/zink_state.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/gallium/drivers/zink/zink_state.c') diff --git a/src/gallium/drivers/zink/zink_state.c b/src/gallium/drivers/zink/zink_state.c index 709627079d8..07da1be2bf8 100644 --- a/src/gallium/drivers/zink/zink_state.c +++ b/src/gallium/drivers/zink/zink_state.c @@ -359,7 +359,19 @@ zink_delete_depth_stencil_alpha_state(struct pipe_context *pctx, static float round_to_granularity(float value, float granularity) { - return (float)(round(value / granularity) * granularity); + return roundf(value / granularity) * granularity; +} + +static float +line_width(float width, float granularity, const float range[2]) +{ + assert(granularity >= 0); + assert(range[0] <= range[1]); + + if (granularity > 0) + width = round_to_granularity(width, granularity); + + return CLAMP(width, range[0], range[1]); } static void * @@ -395,8 +407,9 @@ zink_create_rasterizer_state(struct pipe_context *pctx, state->offset_clamp = rs_state->offset_clamp; state->offset_scale = rs_state->offset_scale; - state->line_width = round_to_granularity(rs_state->line_width, - screen->props.limits.lineWidthGranularity); + state->line_width = line_width(rs_state->line_width, + screen->props.limits.lineWidthGranularity, + screen->props.limits.lineWidthRange); return state; } -- cgit v1.2.3