asahi: Track batch masks on ZS/blend CSO
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Thu, 24 Nov 2022 15:55:52 +0000 (10:55 -0500)
committerAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sun, 11 Dec 2022 02:50:45 +0000 (21:50 -0500)
Adapted from panfrost, with the work happening at CSO create time instead of
draw time allowing us to do more sophisticated analysis. We'll use these for
accurate masks in a moment.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20123>

src/gallium/drivers/asahi/agx_pipe.c
src/gallium/drivers/asahi/agx_state.c
src/gallium/drivers/asahi/agx_state.h

index 1334e50..5758f06 100644 (file)
@@ -954,6 +954,7 @@ agx_clear(struct pipe_context *pctx, unsigned buffers, const struct pipe_scissor
    }
 
    batch->clear |= fastclear;
+   batch->resolve |= buffers;
    assert((batch->draw & slowclear) == slowclear);
 }
 
index c793373..33cc501 100644 (file)
@@ -163,6 +163,9 @@ agx_create_blend_state(struct pipe_context *ctx,
       }
 
       so->rt[i].colormask = rt.colormask;
+
+      if (rt.colormask)
+         so->store |= (PIPE_CLEAR_COLOR0 << i);
    }
 
    return so;
@@ -249,6 +252,22 @@ agx_create_zsa_state(struct pipe_context *ctx,
       so->back_stencil = so->front_stencil;
    }
 
+   if (state->depth_enabled) {
+      if (state->depth_func != PIPE_FUNC_NEVER &&
+          state->depth_func != PIPE_FUNC_ALWAYS) {
+
+         so->load |= PIPE_CLEAR_DEPTH;
+      }
+
+      if (state->depth_writemask)
+         so->store |= PIPE_CLEAR_DEPTH;
+   }
+
+   if (state->stencil[0].enabled) {
+      so->load |= PIPE_CLEAR_STENCIL; /* TODO: Optimize */
+      so->store |= PIPE_CLEAR_STENCIL;
+   }
+
    return so;
 }
 
@@ -1974,9 +1993,18 @@ agx_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info,
    if (reduced_prim != batch->reduced_prim) ctx->dirty |= AGX_DIRTY_PRIM;
    batch->reduced_prim = reduced_prim;
 
-   /* TODO: masks */
-   batch->draw |= ~0;
-   batch->load |= ~0;
+   /* Update batch masks based on current state */
+   if (ctx->dirty & AGX_DIRTY_BLEND) {
+      /* TODO: Any point to tracking load? */
+      batch->draw |= ctx->blend->store;
+      batch->resolve |= ctx->blend->store;
+   }
+
+   if (ctx->dirty & AGX_DIRTY_ZS) {
+      batch->load |= ctx->zs->load;
+      batch->draw |= ctx->zs->store;
+      batch->resolve |= ctx->zs->store;
+   }
 
    /* TODO: These are expensive calls, consider finer dirty tracking */
    if (agx_update_vs(ctx))
index 888ab3f..48da69d 100644 (file)
@@ -97,7 +97,7 @@ struct agx_batch {
    struct agx_tilebuffer_layout tilebuffer_layout;
 
    /* PIPE_CLEAR_* bitmask */
-   uint32_t clear, draw, load;
+   uint32_t clear, draw, load, resolve;
 
    /* Base of uploaded texture descriptors */
    uint64_t textures;
@@ -133,12 +133,18 @@ struct agx_zsa {
    struct pipe_depth_stencil_alpha_state base;
    struct agx_fragment_face_packed depth;
    struct agx_fragment_stencil_packed front_stencil, back_stencil;
+
+   /* PIPE_CLEAR_* bitmask corresponding to this depth/stencil state */
+   uint32_t load, store;
 };
 
 struct agx_blend {
    bool logicop_enable, blend_enable;
    nir_lower_blend_rt rt[8];
    unsigned logicop_func;
+
+   /* PIPE_CLEAR_* bitmask corresponding to this blend state */
+   uint32_t store;
 };
 
 struct asahi_shader_key {