aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/zink/zink_state.c
diff options
context:
space:
mode:
authorDuncan Hopkins <[email protected]>2019-07-10 14:50:16 +0100
committerErik Faye-Lund <[email protected]>2019-10-28 08:51:48 +0000
commit108ba81c959021ba894553b2c409593c7c51b7bd (patch)
tree5b4f78b1b55fbd3b8bf5d5f6b87fc3c1693df045 /src/gallium/drivers/zink/zink_state.c
parentdf11f3f2ab270c3801762b28cf6854a82639a934 (diff)
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 <[email protected]>
Diffstat (limited to 'src/gallium/drivers/zink/zink_state.c')
-rw-r--r--src/gallium/drivers/zink/zink_state.c19
1 files changed, 16 insertions, 3 deletions
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;
}