diff --git a/src/gallium/drivers/llvmpipe/lp_state_setup.c b/src/gallium/drivers/llvmpipe/lp_state_setup.c index d34c3f21692..1de79960c9a 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_setup.c +++ b/src/gallium/drivers/llvmpipe/lp_state_setup.c @@ -797,11 +797,17 @@ lp_make_setup_variant_key(const struct llvmpipe_context *lp, */ key->floating_point_depth = lp->floating_point_depth && !lp->rasterizer->offset_units_unscaled; - if (lp->floating_point_depth || lp->rasterizer->offset_units_unscaled) { - key->pgon_offset_units = (float) lp->rasterizer->offset_units; - } else { + key->pgon_offset_units = (float) lp->rasterizer->offset_units; + if (lp->rasterizer->offset_units != 0 && !lp->floating_point_depth && + !lp->rasterizer->offset_units_unscaled) { + /* Ensure correct rounding if a unorm format is used. */ + float adjustment = + lp->floating_point_depth + ? 0 + : (lp->rasterizer->offset_units > 0 ? 0.5 : -0.5); + key->pgon_offset_units = - (float) (lp->rasterizer->offset_units * lp->mrd * 2); + (float) ((lp->rasterizer->offset_units + adjustment) * lp->mrd); } key->pgon_offset_scale = lp->rasterizer->offset_scale;