turnip: simplify tu_cs sub-streams usage
authorChia-I Wu <olvaffe@gmail.com>
Mon, 25 Feb 2019 22:38:34 +0000 (14:38 -0800)
committerChia-I Wu <olvaffe@gmail.com>
Mon, 11 Mar 2019 17:02:13 +0000 (10:02 -0700)
Let tu_cs_begin_sub_stream imply tu_cs_reserve_space, and
tu_cs_end_sub_stream imply tu_cs_sanity_check.  Callers are no
longer required to call them (but can still do if they choose to).

src/freedreno/vulkan/tu_cmd_buffer.c
src/freedreno/vulkan/tu_cs.c

index 29219a0b039a92451af22f9521465ce4b01ba047..ef07bd6c27bcc3c04b46d97c38b6440cc01f54a0 100644 (file)
@@ -1104,9 +1104,7 @@ tu_cmd_prepare_tile_load_ib(struct tu_cmd_buffer *cmd)
    }
 
    /* emit to tile-load sub_cs */
-   tu_cs_reserve_space(cmd->device, &sub_cs, tile_load_space);
    tu6_emit_tile_load(cmd, &sub_cs);
-   tu_cs_sanity_check(&sub_cs);
 
    cmd->state.tile_load_ib = tu_cs_end_sub_stream(&cmd->tile_cs, &sub_cs);
 
@@ -1131,9 +1129,7 @@ tu_cmd_prepare_tile_store_ib(struct tu_cmd_buffer *cmd)
    }
 
    /* emit to tile-store sub_cs */
-   tu_cs_reserve_space(cmd->device, &sub_cs, tile_store_space);
    tu6_emit_tile_store(cmd, &sub_cs);
-   tu_cs_sanity_check(&sub_cs);
 
    cmd->state.tile_store_ib = tu_cs_end_sub_stream(&cmd->tile_cs, &sub_cs);
 }
index 27fe75b8b50489273ff3110c0448cfc708d61d45..48242f813ada953826896797c6d3881b56a6a0e1 100644 (file)
@@ -221,7 +221,8 @@ tu_cs_begin(struct tu_cs *cs)
 }
 
 /**
- * End command packet emission and add an IB entry.
+ * End command packet emission.  This adds an IB entry when \a cs is in
+ * TU_CS_MODE_GROW mode.
  */
 void
 tu_cs_end(struct tu_cs *cs)
@@ -236,7 +237,9 @@ tu_cs_end(struct tu_cs *cs)
  * Begin command packet emission to a sub-stream.  \a cs must be in
  * TU_CS_MODE_SUB_STREAM mode.
  *
- * Return \a sub_cs which is in TU_CS_MODE_EXTERNAL mode.
+ * Return \a sub_cs which is in TU_CS_MODE_EXTERNAL mode.  tu_cs_begin and
+ * tu_cs_reserve_space are implied and \a sub_cs is ready for command packet
+ * emission.
  */
 VkResult
 tu_cs_begin_sub_stream(struct tu_device *dev,
@@ -252,6 +255,9 @@ tu_cs_begin_sub_stream(struct tu_device *dev,
       return result;
 
    tu_cs_init_external(sub_cs, cs->cur, cs->reserved_end);
+   tu_cs_begin(sub_cs);
+   result = tu_cs_reserve_space(dev, sub_cs, size);
+   assert(result == VK_SUCCESS);
 
    return VK_SUCCESS;
 }
@@ -268,7 +274,10 @@ tu_cs_end_sub_stream(struct tu_cs *cs, struct tu_cs *sub_cs)
 {
    assert(cs->mode == TU_CS_MODE_SUB_STREAM);
    assert(cs->bo_count);
-   assert(sub_cs->cur >= cs->start && sub_cs->cur <= cs->reserved_end);
+   assert(sub_cs->start == cs->cur && sub_cs->end == cs->reserved_end);
+   tu_cs_sanity_check(sub_cs);
+
+   tu_cs_end(sub_cs);
 
    cs->cur = sub_cs->cur;