From b30bebf38ef057cf11129fdff60b6a859bed360f Mon Sep 17 00:00:00 2001 From: Konstantin Seurer Date: Sun, 19 Nov 2023 22:05:35 +0100 Subject: [PATCH] llvmpipe: Improve depth bias rounding workaround Multiplying by 2 is too conservative to pass depth bias control CTS. Reviewed-by: Mike Blumenkrantz Part-of: --- src/gallium/drivers/llvmpipe/lp_state_setup.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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;