Mesa (master): lima: fix handling of reverse depth range

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jan 16 02:13:08 UTC 2020


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

Author: Vasily Khoruzhick <anarsoul at gmail.com>
Date:   Tue Jan 14 19:53:29 2020 -0800

lima: fix handling of reverse depth range

Looks like we need to handle cases when near > far and near == far.
In first case we just need to swap near and far, and in second we
need subtract epsilon from near if it's not zero.

Fixes 10 tests in dEQP-GLES2.functional.depth_range.*

Reviewed-by: Qiang Yu <yuq825 at gmail.com>
Signed-off-by: Vasily Khoruzhick <anarsoul at gmail.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3400>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3400>

---

 src/gallium/drivers/lima/lima_draw.c  | 12 ++++++++++--
 src/gallium/drivers/lima/lima_state.c |  8 ++++++--
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/lima/lima_draw.c b/src/gallium/drivers/lima/lima_draw.c
index af50996fa33..088f33ef760 100644
--- a/src/gallium/drivers/lima/lima_draw.c
+++ b/src/gallium/drivers/lima/lima_draw.c
@@ -1090,9 +1090,17 @@ lima_pack_render_state(struct lima_context *ctx, const struct pipe_draw_info *in
    struct pipe_depth_state *depth = &ctx->zsa->base.depth;
    render->depth_test = lima_calculate_depth_test(depth, rst);
 
+   ushort far, near;
+
+   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))
+         near--;
+
    /* overlap with plbu? any place can remove one? */
-   render->depth_range = float_to_ushort(ctx->viewport.near) |
-      (float_to_ushort(ctx->viewport.far) << 16);
+   render->depth_range = near | (far << 16);
 
    struct pipe_stencil_state *stencil = ctx->zsa->base.stencil;
    struct pipe_stencil_ref *ref = &ctx->stencil_ref;
diff --git a/src/gallium/drivers/lima/lima_state.c b/src/gallium/drivers/lima/lima_state.c
index 286529e9db0..cd910fbf3de 100644
--- a/src/gallium/drivers/lima/lima_state.c
+++ b/src/gallium/drivers/lima/lima_state.c
@@ -248,8 +248,12 @@ lima_set_viewport_states(struct pipe_context *pctx,
    ctx->viewport.top = viewport->translate[1] + fabsf(viewport->scale[1]);
 
    /* reverse calculate the parameter of glDepthRange */
-   ctx->viewport.near = viewport->translate[2] - viewport->scale[2];
-   ctx->viewport.far = viewport->translate[2] + viewport->scale[2];
+   float near, far;
+   near = viewport->translate[2] - viewport->scale[2];
+   far = viewport->translate[2] + viewport->scale[2];
+
+   ctx->viewport.near = MIN2(near, far);
+   ctx->viewport.far = MAX2(near, far);
 
    ctx->viewport.transform = *viewport;
    ctx->dirty |= LIMA_CONTEXT_DIRTY_VIEWPORT;



More information about the mesa-commit mailing list