lima: disable early-z if fragment shader uses discard
authorVasily Khoruzhick <anarsoul@gmail.com>
Sun, 26 Jan 2020 18:30:17 +0000 (10:30 -0800)
committerVasily Khoruzhick <anarsoul@gmail.com>
Tue, 28 Jan 2020 06:35:43 +0000 (22:35 -0800)
We have to disable early-z if fragment shader uses discard,
otherwise we'll get misrendering.

Reported-by: Icenowy Zheng <icenowy@aosc.io>
Reviewed-by: Andreas Baierl <ichgeh@imkreisrum.de>
Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3570>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3570>

src/gallium/drivers/lima/lima_context.h
src/gallium/drivers/lima/lima_draw.c
src/gallium/drivers/lima/lima_program.c

index 304576b7b6d6781a68a0dfa15ec470dfd6c3ceab..140d7f9cd95063fdec3e2f0c6dc49ef7f43fad2b 100644 (file)
@@ -55,6 +55,7 @@ struct lima_fs_shader_state {
    void *shader;
    int shader_size;
    int stack_size;
+   bool uses_discard;
    struct lima_bo *bo;
 };
 
index 446ba3b5697df1e6708aea7c712c22459bc122c1..af637f4375c9597be829cff197b8501f515abbb8 100644 (file)
@@ -1132,6 +1132,7 @@ lima_calculate_depth_test(struct pipe_depth_state *depth, struct pipe_rasterizer
 static void
 lima_pack_render_state(struct lima_context *ctx, const struct pipe_draw_info *info)
 {
+   struct lima_fs_shader_state *fs = ctx->fs;
    struct lima_render_state *render =
       lima_ctx_buff_alloc(ctx, lima_ctx_buff_pp_plb_rsw,
                           sizeof(*render));
@@ -1239,11 +1240,15 @@ lima_pack_render_state(struct lima_context *ctx, const struct pipe_draw_info *in
    render->textures_address = 0x00000000;
 
    /* more investigation */
-   render->aux0 = 0x00000300 | (ctx->vs->varying_stride >> 3);
+   render->aux0 = 0x00000100 | (ctx->vs->varying_stride >> 3);
    render->aux1 = 0x00001000;
    if (ctx->blend->base.dither)
       render->aux1 |= 0x00002000;
 
+   /* Enable Early-Z if shader doesn't have discard */
+   if (!fs->uses_discard)
+      render->aux0 |= 0x200;
+
    if (ctx->tex_stateobj.num_samplers) {
       render->textures_address =
          lima_ctx_buff_va(ctx, lima_ctx_buff_pp_tex_desc, LIMA_CTX_BUFF_SUBMIT_PP);
index 071a736624d2bd181f18a5c20858497bd6fa3f40..9b9796d588b3b0ae0a269a663dae9af2db25073b 100644 (file)
@@ -287,6 +287,8 @@ lima_create_fs_state(struct pipe_context *pctx,
       return NULL;
    }
 
+   so->uses_discard = nir->info.fs.uses_discard;
+
    return so;
 }