Module: Mesa
Branch: master
Commit: b071d98c0432eebf3318e8d7a1eb904e3c735d14
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=b071d98c0432eebf3318e8d7a1eb904e3c735d14

Author: Erico Nunes <nunes.er...@gmail.com>
Date:   Sun Mar 28 23:42:43 2021 +0200

lima: increase epsilon for depthrange near == far

When the application sets depthrange near == far, lima inserts an
'epsilon' difference of decreasing 'near' by 1 unit, to prevent
application bugs.
For some specific values of depthrange this does not seem to be
sufficient, presumably due to precision limitations.
Increase the difference by also incrementing the 'far' distance in
this case, to further avoid bugs.

Signed-off-by: Erico Nunes <nunes.er...@gmail.com>
Reviewed-by: Vasily Khoruzhick <anars...@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9933>

---

 src/gallium/drivers/lima/lima_draw.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/lima/lima_draw.c 
b/src/gallium/drivers/lima/lima_draw.c
index b7799950d92..c66eae1ae10 100644
--- a/src/gallium/drivers/lima/lima_draw.c
+++ b/src/gallium/drivers/lima/lima_draw.c
@@ -648,9 +648,14 @@ lima_pack_render_state(struct lima_context *ctx, const 
struct pipe_draw_info *in
    near = float_to_ushort(ctx->viewport.near);
    far = float_to_ushort(ctx->viewport.far);
 
-   /* Subtract epsilon from 'near' if far == near. Make sure we don't get 
overflow */
-   if ((far == near) && (near != 0))
+   /* Insert a small 'epsilon' difference between 'near' and 'far' when
+    * they are equal, to avoid application bugs. */
+   if (far == near) {
+      if (near > 0)
          near--;
+      if (far < USHRT_MAX)
+         far++;
+   }
 
    /* overlap with plbu? any place can remove one? */
    render->depth_range = near | (far << 16);

_______________________________________________
mesa-commit mailing list
mesa-commit@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to