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;
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;