turnip: make cond_exec helper easier to use
authorJonathan Marek <jonathan@marek.ca>
Mon, 24 Feb 2020 14:40:56 +0000 (09:40 -0500)
committerMarge Bot <eric+marge@anholt.net>
Mon, 24 Feb 2020 21:52:46 +0000 (21:52 +0000)
Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3925>

src/freedreno/vulkan/tu_cmd_buffer.c
src/freedreno/vulkan/tu_cs.c
src/freedreno/vulkan/tu_cs.h
src/freedreno/vulkan/tu_meta_clear.c
src/freedreno/vulkan/tu_private.h

index 4f9f19bfd77b9af44b11d4ddbb5f0c955ef49dde..581edfa34a7a5e3b0cebd80dd07207ba1f39d044 100644 (file)
@@ -922,24 +922,14 @@ tu6_emit_predicated_blit(struct tu_cmd_buffer *cmd,
                          uint32_t gmem_a,
                          bool resolve)
 {
-   const uint32_t space = 14 + 6;
-   struct tu_cond_exec_state state;
-
-   VkResult result = tu_cond_exec_start(cmd->device, cs, &state,
-                                        CP_COND_REG_EXEC_0_MODE(RENDER_MODE) |
-                                        CP_COND_REG_EXEC_0_GMEM,
-                                        space);
-   if (result != VK_SUCCESS) {
-      cmd->record_result = result;
-      return;
-   }
+   tu_cond_exec_start(cs, CP_COND_EXEC_0_RENDER_MODE_GMEM);
 
    tu6_emit_blit_info(cmd, cs,
                       cmd->state.framebuffer->attachments[a].attachment,
                       cmd->state.pass->attachments[gmem_a].gmem_offset, resolve);
    tu6_emit_blit(cmd, cs);
 
-   tu_cond_exec_end(cs, &state);
+   tu_cond_exec_end(cs);
 }
 
 static void
@@ -973,21 +963,9 @@ static void tu6_emit_resolve(struct tu_cmd_buffer *cmd,
 
    tu6_emit_predicated_blit(cmd, cs, a, gmem_a, true);
 
-   const struct tu_framebuffer *fb = cmd->state.framebuffer;
-   const uint32_t space = 25 + 66 * fb->layers + 17;
-   struct tu_cond_exec_state state;
-
-   VkResult result = tu_cond_exec_start(cmd->device, cs, &state,
-                                        CP_COND_REG_EXEC_0_MODE(RENDER_MODE) |
-                                        CP_COND_REG_EXEC_0_SYSMEM,
-                                        space);
-   if (result != VK_SUCCESS) {
-      cmd->record_result = result;
-      return;
-   }
-
+   tu_cond_exec_start(cs, CP_COND_EXEC_0_RENDER_MODE_SYSMEM);
    tu6_emit_sysmem_resolve(cmd, cs, a, gmem_a);
-   tu_cond_exec_end(cs, &state);
+   tu_cond_exec_end(cs);
 }
 
 static void
index 072a52cbd3c1a75e8a86f1b263c5cdf74ad32e62..16d49838ba8f98ea0b01ecbea8752626e0c214ef 100644 (file)
@@ -364,12 +364,33 @@ tu_cs_reserve_space(struct tu_cs *cs, uint32_t reserved_size)
          tu_cs_add_entry(cs);
       }
 
+      if (cs->cond_flags) {
+         /* Subtract one here to account for the DWORD field itself. */
+         *cs->cond_dwords = cs->cur - cs->cond_dwords - 1;
+
+         /* space for CP_COND_REG_EXEC in next bo */
+         reserved_size += 3;
+      }
+
       /* switch to a new BO */
       uint32_t new_size = MAX2(cs->next_bo_size, reserved_size);
       VkResult result = tu_cs_add_bo(cs, new_size);
       if (result != VK_SUCCESS)
          return result;
 
+      /* if inside a condition, emit a new CP_COND_REG_EXEC */
+      if (cs->cond_flags) {
+         cs->reserved_end = cs->cur + reserved_size;
+
+         tu_cs_emit_pkt7(cs, CP_COND_REG_EXEC, 2);
+         tu_cs_emit(cs, cs->cond_flags);
+
+         cs->cond_dwords = cs->cur;
+
+         /* Emit dummy DWORD field here */
+         tu_cs_emit(cs, CP_COND_REG_EXEC_1_DWORDS(0));
+      }
+
       /* double the size for the next bo */
       new_size <<= 1;
       if (cs->next_bo_size < new_size)
index f5c331cdd30e9a9adc87ce70f4f697f1e96316dd..29baca74fafb79a61389c372915d9d8a040d2a76 100644 (file)
@@ -238,41 +238,34 @@ tu_cs_emit_call(struct tu_cs *cs, const struct tu_cs *target)
 /* Helpers for bracketing a large sequence of commands of unknown size inside
  * a CP_COND_REG_EXEC packet.
  */
-
-struct tu_cond_exec_state {
-   uint32_t *dword_ptr;
-   uint32_t max_dwords;
-};
-
-static inline VkResult
-tu_cond_exec_start(struct tu_device *dev, struct tu_cs *cs,
-                   struct tu_cond_exec_state *state,
-                   uint32_t condition, uint32_t max_dwords)
+static inline void
+tu_cond_exec_start(struct tu_cs *cs, uint32_t cond_flags)
 {
-   /* Reserve enough space so that both the condition packet and the actual
-    * condition will fit in the same IB.
-    */
-   VkResult result = tu_cs_reserve_space(cs, max_dwords + 3);
-   if (result != VK_SUCCESS)
-      return result;
+   assert(cs->mode == TU_CS_MODE_GROW);
+   assert(!cs->cond_flags && cond_flags);
 
-   state->max_dwords = max_dwords;
    tu_cs_emit_pkt7(cs, CP_COND_REG_EXEC, 2);
-   tu_cs_emit(cs, condition);
-   state->dword_ptr = cs->cur;
+   tu_cs_emit(cs, cond_flags);
+
+   cs->cond_flags = cond_flags;
+   cs->cond_dwords = cs->cur;
+
    /* Emit dummy DWORD field here */
    tu_cs_emit(cs, CP_COND_REG_EXEC_1_DWORDS(0));
-
-   return VK_SUCCESS;
 }
+#define CP_COND_EXEC_0_RENDER_MODE_GMEM \
+   (CP_COND_REG_EXEC_0_MODE(RENDER_MODE) | CP_COND_REG_EXEC_0_GMEM)
+#define CP_COND_EXEC_0_RENDER_MODE_SYSMEM \
+   (CP_COND_REG_EXEC_0_MODE(RENDER_MODE) | CP_COND_REG_EXEC_0_SYSMEM)
 
 static inline void
-tu_cond_exec_end(struct tu_cs *cs, struct tu_cond_exec_state *state)
+tu_cond_exec_end(struct tu_cs *cs)
 {
+   assert(cs->cond_flags);
+
+   cs->cond_flags = 0;
    /* Subtract one here to account for the DWORD field itself. */
-   uint32_t actual_dwords = cs->cur - state->dword_ptr - 1;
-   assert(actual_dwords <= state->max_dwords);
-   *state->dword_ptr = actual_dwords;
+   *cs->cond_dwords = cs->cur - cs->cond_dwords - 1;
 }
 
 #define fd_reg_pair tu_reg_value
index 7d24c737cc7b98f583cd81d1e0d9ccc9888c21e0..1454afe68f28ed2315e489413ff87324708e7566 100644 (file)
@@ -171,19 +171,7 @@ tu_CmdClearAttachments(VkCommandBuffer commandBuffer,
    const struct tu_subpass *subpass = cmd->state.subpass;
    struct tu_cs *cs = &cmd->draw_cs;
 
-   /* Note: reserving space here should never fail because we allocated
-    * enough above.
-    */
-   struct tu_cond_exec_state state;
-   VkResult result =
-      tu_cond_exec_start(cmd->device, cs, &state,
-                        CP_COND_REG_EXEC_0_MODE(RENDER_MODE) |
-                        CP_COND_REG_EXEC_0_GMEM,
-                        rectCount * (3 + attachmentCount * 15));
-   if (result != VK_SUCCESS) {
-      cmd->record_result = result;
-      return;
-   }
+   tu_cond_exec_start(cs, CP_COND_EXEC_0_RENDER_MODE_GMEM);
 
    for (unsigned i = 0; i < rectCount; i++) {
       unsigned x1 = pRects[i].rect.offset.x;
@@ -218,22 +206,9 @@ tu_CmdClearAttachments(VkCommandBuffer commandBuffer,
       }
    }
 
-   tu_cond_exec_end(cs, &state);
-
-   uint32_t clear_count = 3;
-   for (unsigned j = 0; j < rectCount; j++)
-      clear_count += 18 + 66 * pRects[j].layerCount + 17;
+   tu_cond_exec_end(cs);
 
-   result =
-      tu_cond_exec_start(cmd->device, cs, &state,
-                         CP_COND_REG_EXEC_0_MODE(RENDER_MODE) |
-                         CP_COND_REG_EXEC_0_SYSMEM,
-                         attachmentCount * clear_count);
-
-   if (result != VK_SUCCESS) {
-      cmd->record_result = result;
-      return;
-   }
+   tu_cond_exec_start(cs, CP_COND_EXEC_0_RENDER_MODE_SYSMEM);
 
    for (unsigned i = 0; i < rectCount; i++) {
       for (unsigned j = 0; j < attachmentCount; j++) {
@@ -261,5 +236,5 @@ tu_CmdClearAttachments(VkCommandBuffer commandBuffer,
       }
    }
 
-   tu_cond_exec_end(cs, &state);
+   tu_cond_exec_end(cs);
 }
index 5268586349ef57314fe380cc50a5820128c3f6f4..a7b1f76da37735be0bd7fdcb63dfeeb200b9c888 100644 (file)
@@ -580,6 +580,10 @@ struct tu_cs
    struct tu_bo **bos;
    uint32_t bo_count;
    uint32_t bo_capacity;
+
+   /* state for cond_exec_start/cond_exec_end */
+   uint32_t cond_flags;
+   uint32_t *cond_dwords;
 };
 
 struct tu_device_memory