Mesa (main): draw/llvmpipe: correct exponent calculation for negative z
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Aug 25 19:36:26 UTC 2021
Module: Mesa
Branch: main
Commit: e26fd607cab20715bf03d5ec221165171e0d0d1e
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=e26fd607cab20715bf03d5ec221165171e0d0d1e
Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date: Wed Aug 18 11:40:51 2021 +0200
draw/llvmpipe: correct exponent calculation for negative z
If the z components here contain negative values, we'll end up with the
wrong maximum value.
This updated equation is taken from the D3D11 functional spec (section
15.10 Depth Bias), which is a bit more clear than the OpenGL spec.
Reviewed-by: Roland Scheidegger <sroland at vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12443>
---
src/gallium/auxiliary/draw/draw_pipe_offset.c | 2 +-
src/gallium/drivers/llvmpipe/lp_state_setup.c | 13 ++++++++-----
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/gallium/auxiliary/draw/draw_pipe_offset.c b/src/gallium/auxiliary/draw/draw_pipe_offset.c
index 769e7ca372d..87db9cddac4 100644
--- a/src/gallium/auxiliary/draw/draw_pipe_offset.c
+++ b/src/gallium/auxiliary/draw/draw_pipe_offset.c
@@ -97,7 +97,7 @@ static void do_offset_tri( struct draw_stage *stage,
if (stage->draw->floating_point_depth) {
float bias;
union fi maxz;
- maxz.f = MAX3(v0[2], v1[2], v2[2]);
+ maxz.f = MAX3(fabs(v0[2]), fabs(v1[2]), fabs(v2[2]));
/* just do the math directly on shifted number */
maxz.ui &= 0xff << 23;
maxz.i -= 23 << 23;
diff --git a/src/gallium/drivers/llvmpipe/lp_state_setup.c b/src/gallium/drivers/llvmpipe/lp_state_setup.c
index 87216c04d9e..53ec2c1c38b 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_setup.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_setup.c
@@ -266,8 +266,8 @@ lp_do_offset_tri(struct gallivm_state *gallivm,
if (key->floating_point_depth) {
/*
- * bias = pgon_offset_units * 2^(exponent(max(z0, z1, z2)) - mantissa_bits) +
- * MAX2(dzdx, dzdy) * pgon_offset_scale
+ * bias = pgon_offset_units * 2^(exponent(max(abs(z0), abs(z1), abs(z2))) -
+ * mantissa_bits) + MAX2(dzdx, dzdy) * pgon_offset_scale
*
* NOTE: Assumes IEEE float32.
*/
@@ -280,11 +280,14 @@ lp_do_offset_tri(struct gallivm_state *gallivm,
exp_mask = lp_build_const_int32(gallivm, 0xff << 23);
maxz0z1_value = lp_build_max(&flt_scalar_bld,
- LLVMBuildExtractElement(b, attribv[0], twoi, ""),
- LLVMBuildExtractElement(b, attribv[1], twoi, ""));
+ lp_build_abs(&flt_scalar_bld,
+ LLVMBuildExtractElement(b, attribv[0], twoi, "")),
+ lp_build_abs(&flt_scalar_bld,
+ LLVMBuildExtractElement(b, attribv[1], twoi, "")));
maxz_value = lp_build_max(&flt_scalar_bld,
- LLVMBuildExtractElement(b, attribv[2], twoi, ""),
+ lp_build_abs(&flt_scalar_bld,
+ LLVMBuildExtractElement(b, attribv[2], twoi, "")),
maxz0z1_value);
exp = LLVMBuildBitCast(b, maxz_value, int_scalar_bld.vec_type, "");
More information about the mesa-commit
mailing list