zink: promote flushed clears to unordered cmdbuf when possible
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Tue, 16 May 2023 14:03:28 +0000 (10:03 -0400)
committerMarge Bot <emma+marge@anholt.net>
Tue, 23 May 2023 00:18:29 +0000 (00:18 +0000)
this reuses the unordered_blitting codepath for fb clears

for #9016

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23056>

src/gallium/drivers/zink/zink_clear.c

index 6b45ba2..a8756ae 100644 (file)
@@ -25,6 +25,7 @@
 #include "zink_clear.h"
 #include "zink_context.h"
 #include "zink_format.h"
+#include "zink_inlines.h"
 #include "zink_query.h"
 
 #include "util/u_blitter.h"
@@ -719,9 +720,38 @@ fb_clears_apply_internal(struct zink_context *ctx, struct pipe_resource *pres, i
       return;
    if (ctx->batch.in_rp)
       zink_clear_framebuffer(ctx, BITFIELD_BIT(i));
-   else
+   else {
+      struct zink_resource *res = zink_resource(pres);
+      bool queries_disabled = ctx->queries_disabled;
+      VkCommandBuffer cmdbuf = ctx->batch.state->cmdbuf;
+      /* slightly different than the u_blitter handling:
+       * this can be called recursively while unordered_blitting=true
+       */
+      bool can_reorder = zink_screen(ctx->base.screen)->info.have_KHR_dynamic_rendering &&
+                         !ctx->render_condition_active &&
+                         !ctx->unordered_blitting &&
+                         zink_get_cmdbuf(ctx, NULL, res) == ctx->batch.state->barrier_cmdbuf;
+      if (can_reorder) {
+         /* set unordered_blitting but NOT blitting:
+          * let begin_rendering handle layouts
+          */
+         ctx->unordered_blitting = true;
+         /* for unordered clears, swap the unordered cmdbuf for the main one for the whole op to avoid conditional hell */
+         ctx->batch.state->cmdbuf = ctx->batch.state->barrier_cmdbuf;
+         ctx->rp_changed = true;
+         ctx->queries_disabled = true;
+         ctx->batch.state->has_barriers = true;
+      }
       /* this will automatically trigger all the clears */
       zink_batch_rp(ctx);
+      if (can_reorder) {
+         zink_batch_no_rp(ctx);
+         ctx->unordered_blitting = false;
+         ctx->rp_changed = true;
+         ctx->queries_disabled = queries_disabled;
+         ctx->batch.state->cmdbuf = cmdbuf;
+      }
+   }
    zink_fb_clear_reset(ctx, i);
 }