Mesa (main): llvmpipe: clamp z to 0..1 range when using polygon offset
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Aug 24 07:55:22 UTC 2021
Module: Mesa
Branch: main
Commit: 856533366928300bbad8949675b1c165ccb39605
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=856533366928300bbad8949675b1c165ccb39605
Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date: Wed Aug 18 11:00:33 2021 +0200
llvmpipe: clamp z to 0..1 range when using polygon offset
The OpenGL 4.6 compatibility spec, section 14.6.5 (Depth Offset) says
the following:
> For fixed-point depth buffers, fragment depth values are always
> limited to the range [0,1] by clamping after offset addition is
> performed. Fragment depth values are clamped even when the depth
> buffer uses a floating-point representation.
So we need to properly clamp the result here.
This fixes the following dEQP failures, that the CI has missed:
- dEQP-GLES3.functional.polygon_offset.default_result_depth_clamp
- dEQP-GLES3.functional.polygon_offset.default_factor_1_slope
- dEQP-GLES3.functional.polygon_offset.fixed24_result_depth_clamp
- dEQP-GLES3.functional.polygon_offset.fixed24_factor_1_slope
Reviewed-by: Roland Scheidegger <sroland at vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12442>
---
src/gallium/drivers/llvmpipe/lp_bld_interp.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/src/gallium/drivers/llvmpipe/lp_bld_interp.c b/src/gallium/drivers/llvmpipe/lp_bld_interp.c
index 96bf8d4ea59..8b02ac9622c 100644
--- a/src/gallium/drivers/llvmpipe/lp_bld_interp.c
+++ b/src/gallium/drivers/llvmpipe/lp_bld_interp.c
@@ -414,19 +414,13 @@ attribs_update_simple(struct lp_build_interp_soa_context *bld,
}
if ((attrib == 0) && (chan == 2) && !bld->depth_clamp){
- /* FIXME: Depth values can exceed 1.0, due to the fact that
- * setup interpolation coefficients refer to (0,0) which causes
- * precision loss. So we must clamp to 1.0 here to avoid artifacts.
- * Note though values outside [0,1] are perfectly valid with
- * depth clip disabled.
- * XXX: If depth clip is disabled but we force depth clamp
- * we may get values larger than 1.0 in the fs (but not in
- * depth test). Not sure if that's an issue...
- * Also, on a similar note, it is not obvious if the depth values
- * appearing in fs (with depth clip disabled) should be clamped
- * to [0,1], clamped to near/far or not be clamped at all...
+ /* OpenGL requires clamping z to 0..1 range after polgon offset
+ * is applied if depth-clamping isn't enabled.
+ *
+ * This also fixes the problem that depth values can exceed 1.0,
+ * due to imprecision in the calculations.
*/
- a = lp_build_min(coeff_bld, a, coeff_bld->one);
+ a = lp_build_clamp(coeff_bld, a, coeff_bld->zero, coeff_bld->one);
}
bld->attribs[attrib][chan] = a;
}
More information about the mesa-commit
mailing list