turnip: Save the renderpass's clear values in the cmdbuf state.
authorEmma Anholt <emma@anholt.net>
Wed, 5 Oct 2022 21:34:29 +0000 (14:34 -0700)
committerMarge Bot <emma+marge@anholt.net>
Wed, 16 Aug 2023 16:02:51 +0000 (16:02 +0000)
For delaying clears to subpass begin time, I needed to save these until
later.  Turns out this cleans up a good bit of threading these values all
through the command buffer setup.

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

src/freedreno/vulkan/tu_clear_blit.cc
src/freedreno/vulkan/tu_clear_blit.h
src/freedreno/vulkan/tu_cmd_buffer.cc
src/freedreno/vulkan/tu_cmd_buffer.h
src/freedreno/vulkan/tu_lrz.cc
src/freedreno/vulkan/tu_lrz.h

index 3fa97de6d2b0d6baccb56cab764ef6b8a8b7c437..39814b62ae3765843b8e5b639d157521c9c85075 100644 (file)
@@ -3110,7 +3110,6 @@ clear_sysmem_attachment(struct tu_cmd_buffer *cmd,
                         struct tu_cs *cs,
                         VkFormat vk_format,
                         VkImageAspectFlags clear_mask,
-                        const VkClearValue *value,
                         uint32_t a,
                         bool separate_ds)
 {
@@ -3119,6 +3118,7 @@ clear_sysmem_attachment(struct tu_cmd_buffer *cmd,
    const struct tu_image_view *iview = cmd->state.attachments[a];
    const uint32_t clear_views = cmd->state.pass->attachments[a].clear_views;
    const struct blit_ops *ops = &r2d_ops;
+   const VkClearValue *value = &cmd->state.clear_values[a];
    if (cmd->state.pass->attachments[a].samples > 1)
       ops = &r3d_ops;
 
@@ -3152,8 +3152,7 @@ clear_sysmem_attachment(struct tu_cmd_buffer *cmd,
 void
 tu_clear_sysmem_attachment(struct tu_cmd_buffer *cmd,
                            struct tu_cs *cs,
-                           uint32_t a,
-                           const VkClearValue *value)
+                           uint32_t a)
 {
    const struct tu_render_pass_attachment *attachment =
       &cmd->state.pass->attachments[a];
@@ -3164,15 +3163,15 @@ tu_clear_sysmem_attachment(struct tu_cmd_buffer *cmd,
    if (attachment->format == VK_FORMAT_D32_SFLOAT_S8_UINT) {
       if (attachment->clear_mask & VK_IMAGE_ASPECT_DEPTH_BIT) {
          clear_sysmem_attachment(cmd, cs, VK_FORMAT_D32_SFLOAT, VK_IMAGE_ASPECT_COLOR_BIT,
-                                 value, a, true);
+                                 a, true);
       }
       if (attachment->clear_mask & VK_IMAGE_ASPECT_STENCIL_BIT) {
          clear_sysmem_attachment(cmd, cs, VK_FORMAT_S8_UINT, VK_IMAGE_ASPECT_COLOR_BIT,
-                                 value, a, true);
+                                 a, true);
       }
    } else {
       clear_sysmem_attachment(cmd, cs, attachment->format, attachment->clear_mask,
-                              value, a, false);
+                              a, false);
    }
 
    /* The spec doesn't explicitly say, but presumably the initial renderpass
@@ -3199,8 +3198,7 @@ tu_clear_sysmem_attachment(struct tu_cmd_buffer *cmd,
 void
 tu_clear_gmem_attachment(struct tu_cmd_buffer *cmd,
                          struct tu_cs *cs,
-                         uint32_t a,
-                         const VkClearValue *value)
+                         uint32_t a)
 {
    const struct tu_render_pass_attachment *attachment =
       &cmd->state.pass->attachments[a];
@@ -3210,7 +3208,8 @@ tu_clear_gmem_attachment(struct tu_cmd_buffer *cmd,
 
    tu_emit_clear_gmem_attachment(cmd, cs, a, 0, cmd->state.framebuffer->layers,
                                  attachment->clear_views,
-                                 attachment->clear_mask, value);
+                                 attachment->clear_mask,
+                                 &cmd->state.clear_values[a]);
 }
 
 static void
index bab3a15c6850e2b62385f7d63e8dfbb8cea56f23..778f5e045d59d6b0fbf0dd1528cc2ca99dc5f1a2 100644 (file)
@@ -34,14 +34,12 @@ tu_resolve_sysmem(struct tu_cmd_buffer *cmd,
 void
 tu_clear_sysmem_attachment(struct tu_cmd_buffer *cmd,
                            struct tu_cs *cs,
-                           uint32_t a,
-                           const VkClearValue *value);
+                           uint32_t a);
 
 void
 tu_clear_gmem_attachment(struct tu_cmd_buffer *cmd,
                          struct tu_cs *cs,
-                         uint32_t a,
-                         const VkClearValue *value);
+                         uint32_t a);
 
 void
 tu_load_gmem_attachment(struct tu_cmd_buffer *cmd,
index 5214951db2f4670260ca4dd3454eab3926a32997..a1e9a1abae920ea06e2adfd56bcd37cbcac9afff 100644 (file)
@@ -1462,8 +1462,7 @@ tu_set_input_attachments(struct tu_cmd_buffer *cmd, const struct tu_subpass *sub
 
 
 static void
-tu_emit_renderpass_begin(struct tu_cmd_buffer *cmd,
-                         const VkClearValue *clear_values)
+tu_emit_renderpass_begin(struct tu_cmd_buffer *cmd)
 {
    struct tu_cs *cs = &cmd->draw_cs;
 
@@ -1477,7 +1476,7 @@ tu_emit_renderpass_begin(struct tu_cmd_buffer *cmd,
    tu6_emit_blit_scissor(cmd, cs, false);
 
    for (uint32_t i = 0; i < cmd->state.pass->attachment_count; ++i)
-      tu_clear_gmem_attachment(cmd, cs, i, &clear_values[i]);
+      tu_clear_gmem_attachment(cmd, cs, i);
 
    tu_cond_exec_end(cs);
 
@@ -1487,7 +1486,7 @@ tu_emit_renderpass_begin(struct tu_cmd_buffer *cmd,
    tu_cond_exec_start(cs, CP_COND_EXEC_0_RENDER_MODE_SYSMEM);
 
    for (uint32_t i = 0; i < cmd->state.pass->attachment_count; ++i)
-      tu_clear_sysmem_attachment(cmd, cs, i, &clear_values[i]);
+      tu_clear_sysmem_attachment(cmd, cs, i);
 
    tu_cond_exec_end(cs);
 
@@ -1806,6 +1805,7 @@ static void tu_reset_render_pass(struct tu_cmd_buffer *cmd_buffer)
    cmd_buffer->state.subpass = NULL;
    cmd_buffer->state.framebuffer = NULL;
    cmd_buffer->state.attachments = NULL;
+   cmd_buffer->state.clear_values = NULL;
    cmd_buffer->state.gmem_layout = TU_GMEM_LAYOUT_COUNT; /* invalid value to prevent looking up gmem offsets */
    memset(&cmd_buffer->state.rp, 0, sizeof(cmd_buffer->state.rp));
 
@@ -3641,12 +3641,13 @@ tu_CmdBeginRenderPass2(VkCommandBuffer commandBuffer,
    cmd->state.framebuffer = fb;
    cmd->state.render_area = pRenderPassBegin->renderArea;
 
-   cmd->state.attachments = (const struct tu_image_view **)
-      vk_alloc(&cmd->vk.pool->alloc, pass->attachment_count *
-               sizeof(cmd->state.attachments[0]), 8,
-               VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
-
-   if (!cmd->state.attachments) {
+   VK_MULTIALLOC(ma);
+   vk_multialloc_add(&ma, &cmd->state.attachments,
+                     const struct tu_image_view *, pass->attachment_count);
+   vk_multialloc_add(&ma, &cmd->state.clear_values, VkClearValue,
+                     pRenderPassBegin->clearValueCount);
+   if (!vk_multialloc_alloc(&ma, &cmd->vk.pool->alloc,
+                            VK_SYSTEM_ALLOCATION_SCOPE_OBJECT)) {
       vk_command_buffer_set_error(&cmd->vk, VK_ERROR_OUT_OF_HOST_MEMORY);
       return;
    }
@@ -3660,6 +3661,9 @@ tu_CmdBeginRenderPass2(VkCommandBuffer commandBuffer,
          tu_image_view_from_handle(pAttachmentInfo->pAttachments[i]) :
          cmd->state.framebuffer->attachments[i].attachment;
    }
+   for (unsigned i = 0; i < pRenderPassBegin->clearValueCount; i++)
+         cmd->state.clear_values[i] = pRenderPassBegin->pClearValues[i];
+
    tu_choose_gmem_layout(cmd);
 
    trace_start_render_pass(&cmd->trace, &cmd->cs, cmd->state.framebuffer,
@@ -3677,11 +3681,11 @@ tu_CmdBeginRenderPass2(VkCommandBuffer commandBuffer,
    if (pass->subpasses[0].feedback_invalidate)
       cmd->state.renderpass_cache.flush_bits |= TU_CMD_FLAG_CACHE_INVALIDATE;
 
-   tu_lrz_begin_renderpass(cmd, pRenderPassBegin->pClearValues);
+   tu_lrz_begin_renderpass(cmd);
 
    cmd->trace_renderpass_start = u_trace_end_iterator(&cmd->trace);
 
-   tu_emit_renderpass_begin(cmd, pRenderPassBegin->pClearValues);
+   tu_emit_renderpass_begin(cmd);
    tu_emit_subpass_begin(cmd);
 
    if (pass->has_fdm)
@@ -3693,7 +3697,6 @@ tu_CmdBeginRendering(VkCommandBuffer commandBuffer,
                      const VkRenderingInfo *pRenderingInfo)
 {
    TU_FROM_HANDLE(tu_cmd_buffer, cmd, commandBuffer);
-   VkClearValue clear_values[2 * (MAX_RTS + 1)];
 
    tu_setup_dynamic_render_pass(cmd, pRenderingInfo);
    tu_setup_dynamic_framebuffer(cmd, pRenderingInfo);
@@ -3704,16 +3707,19 @@ tu_CmdBeginRendering(VkCommandBuffer commandBuffer,
    cmd->state.render_area = pRenderingInfo->renderArea;
 
    cmd->state.attachments = cmd->dynamic_attachments;
+   cmd->state.clear_values = cmd->dynamic_clear_values;
 
    for (unsigned i = 0; i < pRenderingInfo->colorAttachmentCount; i++) {
       uint32_t a = cmd->dynamic_subpass.color_attachments[i].attachment;
       if (!pRenderingInfo->pColorAttachments[i].imageView)
          continue;
 
+      cmd->state.clear_values[a] =
+         pRenderingInfo->pColorAttachments[i].clearValue;
+
       TU_FROM_HANDLE(tu_image_view, view,
                      pRenderingInfo->pColorAttachments[i].imageView);
       cmd->state.attachments[a] = view;
-      clear_values[a] = pRenderingInfo->pColorAttachments[i].clearValue;
 
       a = cmd->dynamic_subpass.resolve_attachments[i].attachment;
       if (a != VK_ATTACHMENT_UNUSED) {
@@ -3734,12 +3740,12 @@ tu_CmdBeginRendering(VkCommandBuffer commandBuffer,
          TU_FROM_HANDLE(tu_image_view, view, common_info->imageView);
          cmd->state.attachments[a] = view;
          if (pRenderingInfo->pDepthAttachment) {
-            clear_values[a].depthStencil.depth =
+            cmd->state.clear_values[a].depthStencil.depth =
                pRenderingInfo->pDepthAttachment->clearValue.depthStencil.depth;
          }
 
          if (pRenderingInfo->pStencilAttachment) {
-            clear_values[a].depthStencil.stencil =
+            cmd->state.clear_values[a].depthStencil.stencil =
                pRenderingInfo->pStencilAttachment->clearValue.depthStencil.stencil;
          }
 
@@ -3788,9 +3794,9 @@ tu_CmdBeginRendering(VkCommandBuffer commandBuffer,
       cmd->state.lrz.valid = false;
    } else {
       if (resuming)
-         tu_lrz_begin_resumed_renderpass(cmd, clear_values);
+         tu_lrz_begin_resumed_renderpass(cmd);
       else
-         tu_lrz_begin_renderpass(cmd, clear_values);
+         tu_lrz_begin_renderpass(cmd);
    }
 
 
@@ -3812,7 +3818,7 @@ tu_CmdBeginRendering(VkCommandBuffer commandBuffer,
    }
 
    if (!resuming) {
-      tu_emit_renderpass_begin(cmd, clear_values);
+      tu_emit_renderpass_begin(cmd);
       tu_emit_subpass_begin(cmd);
    }
 
index b9f2080af0cf8ad8a347f7ff1923a54a0c524dff..f0abeeeeb63057172e39d7c24e2146eb3a26219c 100644 (file)
@@ -448,6 +448,7 @@ struct tu_cmd_state
    VkRect2D render_area;
 
    const struct tu_image_view **attachments;
+   VkClearValue *clear_values;
 
    /* State that in the dynamic case comes from VkRenderingInfo and needs to
     * be saved/restored when suspending. This holds the state for the last
@@ -529,6 +530,7 @@ struct tu_cmd_buffer
    struct tu_subpass_attachment dynamic_color_attachments[MAX_RTS];
    struct tu_subpass_attachment dynamic_resolve_attachments[MAX_RTS + 1];
    const struct tu_image_view *dynamic_attachments[2 * (MAX_RTS + 1) + 1];
+   VkClearValue dynamic_clear_values[2 * (MAX_RTS + 1)];
 
    struct tu_render_pass dynamic_pass;
    struct tu_subpass dynamic_subpass;
index c8ce6c3eaabd0c7df30e59c0bdcf2b23077bb97e..f4dda1752ccf6677e2aea7f8df8b096c6f0c5681 100644 (file)
@@ -188,8 +188,7 @@ tu_lrz_init_secondary(struct tu_cmd_buffer *cmd,
  * lrz etc.
  */
 void
-tu_lrz_begin_resumed_renderpass(struct tu_cmd_buffer *cmd,
-                                const VkClearValue *clear_values)
+tu_lrz_begin_resumed_renderpass(struct tu_cmd_buffer *cmd)
 {
     /* Track LRZ valid state */
    memset(&cmd->state.lrz, 0, sizeof(cmd->state.lrz));
@@ -204,7 +203,7 @@ tu_lrz_begin_resumed_renderpass(struct tu_cmd_buffer *cmd,
       const struct tu_render_pass_attachment *att = &cmd->state.pass->attachments[a];
       tu_lrz_init_state(cmd, att, cmd->state.attachments[a]);
       if (att->clear_mask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT)) {
-         VkClearValue clear = clear_values[a];
+         VkClearValue clear = cmd->state.clear_values[a];
          cmd->state.lrz.depth_clear_value = clear;
          cmd->state.lrz.fast_clear = cmd->state.lrz.fast_clear &&
                                      (clear.depthStencil.depth == 0.f ||
@@ -215,8 +214,7 @@ tu_lrz_begin_resumed_renderpass(struct tu_cmd_buffer *cmd,
 }
 
 void
-tu_lrz_begin_renderpass(struct tu_cmd_buffer *cmd,
-                        const VkClearValue *clear_values)
+tu_lrz_begin_renderpass(struct tu_cmd_buffer *cmd)
 {
    const struct tu_render_pass *pass = cmd->state.pass;
 
@@ -251,7 +249,7 @@ tu_lrz_begin_renderpass(struct tu_cmd_buffer *cmd,
    }
 
     /* Track LRZ valid state */
-   tu_lrz_begin_resumed_renderpass(cmd, clear_values);
+   tu_lrz_begin_resumed_renderpass(cmd);
 
    if (!cmd->state.lrz.valid) {
       tu6_emit_lrz_buffer(&cmd->cs, NULL);
index 798cb925dad5b19b3dd625352f84dedfd852313d..01aa3a66c6fbc9d39a231cd27749ccf1977ccc21 100644 (file)
@@ -57,12 +57,10 @@ tu_lrz_clear_depth_image(struct tu_cmd_buffer *cmd,
                          const VkImageSubresourceRange *pRanges);
 
 void
-tu_lrz_begin_renderpass(struct tu_cmd_buffer *cmd,
-                        const VkClearValue *clear_values);
+tu_lrz_begin_renderpass(struct tu_cmd_buffer *cmd);
 
 void
-tu_lrz_begin_resumed_renderpass(struct tu_cmd_buffer *cmd,
-                                const VkClearValue *clear_values);
+tu_lrz_begin_resumed_renderpass(struct tu_cmd_buffer *cmd);
 
 void
 tu_lrz_begin_secondary_cmdbuf(struct tu_cmd_buffer *cmd);