lima: fix viewport clipping
authorVasily Khoruzhick <anarsoul@gmail.com>
Sat, 11 Jan 2020 03:35:11 +0000 (19:35 -0800)
committerVasily Khoruzhick <anarsoul@gmail.com>
Sun, 12 Jan 2020 08:10:04 +0000 (00:10 -0800)
Apparently Mali4x0 doesn't do viewport clipping, so anything rendered beyond viewport
is still rendered. Looks like we need to use scissors to do clipping.

Fixes most of dEQP-GLES2.functional.clipping.*, 6 out of 7 remaining failures
fail on blob as well. Remaining [1] fails on many other gallium drivers.

[1] dEQP-GLES2.functional.clipping.triangle_vertex.clip_three.clip_neg_x_neg_z_and_pos_x_pos_z_and_neg_x_neg_y_pos_z

Suggested-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Qiang Yu <yuq825@gmail.com>
Tested-by: Andreas Baierl <ichgeh@imkreisrum.de>
Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
src/gallium/drivers/lima/lima_draw.c

index 0a0c60dbb948a3772f3fc60380d518e6ab11e899..d8ca64c925326ed5b2c52c35d9ce0f60d9550458 100644 (file)
@@ -827,6 +827,7 @@ lima_pack_plbu_cmd(struct lima_context *ctx, const struct pipe_draw_info *info)
 {
    struct lima_context_framebuffer *fb = &ctx->framebuffer;
    struct lima_vs_shader_state *vs = ctx->vs;
+   unsigned minx, maxx, miny, maxy;
 
    lima_pack_head_plbu_cmd(ctx);
 
@@ -876,14 +877,25 @@ lima_pack_plbu_cmd(struct lima_context *ctx, const struct pipe_draw_info *info)
     */
    if (ctx->rasterizer->base.scissor) {
       struct pipe_scissor_state *scissor = &ctx->scissor;
-      PLBU_CMD_SCISSORS(scissor->minx, scissor->maxx, scissor->miny, scissor->maxy);
-      lima_damage_rect_union(ctx, scissor->minx, scissor->maxx,
-                                  scissor->miny, scissor->maxy);
+      minx = scissor->minx;
+      maxx = scissor->maxx;
+      miny = scissor->miny;
+      maxy = scissor->maxy;
    } else {
-      PLBU_CMD_SCISSORS(0, fb->base.width, 0, fb->base.height);
-      lima_damage_rect_union(ctx, 0, fb->base.width, 0, fb->base.height);
+      minx = 0;
+      maxx = fb->base.width;
+      miny = 0;
+      maxy = fb->base.height;
    }
 
+   minx = MAX2(minx, ctx->viewport.left);
+   maxx = MIN2(maxx, ctx->viewport.right);
+   miny = MAX2(miny, ctx->viewport.bottom);
+   maxy = MIN2(maxy, ctx->viewport.top);
+
+   PLBU_CMD_SCISSORS(minx, maxx, miny, maxy);
+   lima_damage_rect_union(ctx, minx, maxx, miny, maxy);
+
    PLBU_CMD_UNKNOWN1();
 
    PLBU_CMD_DEPTH_RANGE_NEAR(fui(ctx->viewport.near));