turnip: minor cleanup to tu_cs_end
authorChia-I Wu <olvaffe@gmail.com>
Wed, 16 Jan 2019 22:00:43 +0000 (14:00 -0800)
committerChia-I Wu <olvaffe@gmail.com>
Mon, 11 Mar 2019 17:01:41 +0000 (10:01 -0700)
Add comments and error checking.

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

index 36bcd8af8fda8e6453c11a588992e2e5c6e9e654..4600f1ffa2f73d11e20b6cf8ff52f9deb934568e 100644 (file)
@@ -459,7 +459,10 @@ tu_EndCommandBuffer(VkCommandBuffer commandBuffer)
 {
    TU_FROM_HANDLE(tu_cmd_buffer, cmd_buffer, commandBuffer);
 
-   tu_cs_end(&cmd_buffer->cs);
+   VkResult result = tu_cs_end(&cmd_buffer->cs);
+   if (result != VK_SUCCESS)
+      cmd_buffer->record_result = result;
+
    cmd_buffer->status = TU_CMD_BUFFER_STATUS_EXECUTABLE;
 
    return cmd_buffer->record_result;
index 155a5df7512ac75f6dce11138df5b32fc5238f84..e85925f3a15738e25495d1b08b00f6d4fcff4557 100644 (file)
@@ -127,29 +127,31 @@ tu_cs_begin(struct tu_device *dev, struct tu_cs *cs, uint32_t reserve_size)
 VkResult
 tu_cs_end(struct tu_cs *cs)
 {
+   /* no command packet at all */
    if (cs->start == cs->cur)
       return VK_SUCCESS;
 
+   /* grow cs->entries if needed */
    if (cs->entry_capacity == cs->entry_count) {
       uint32_t new_capacity = MAX2(cs->entry_capacity * 2, 4);
       struct tu_cs_entry *new_entries =
          realloc(cs->entries, new_capacity * sizeof(struct tu_cs_entry));
       if (!new_entries)
-         abort(); /* TODO */
+         return VK_ERROR_OUT_OF_HOST_MEMORY;
 
       cs->entries = new_entries;
       cs->entry_capacity = new_capacity;
    }
 
    assert(cs->bo_count);
-
-   struct tu_cs_entry entry;
-   entry.bo = cs->bos[cs->bo_count - 1];
-   entry.size = (cs->cur - cs->start) * sizeof(uint32_t);
-   entry.offset = (cs->start - (uint32_t *) entry.bo->map) * sizeof(uint32_t);
-
-   cs->entries[cs->entry_count] = entry;
-   ++cs->entry_count;
+   const struct tu_bo *bo = cs->bos[cs->bo_count - 1];
+
+   /* add an entry for [cs->start, cs->cur] */
+   cs->entries[cs->entry_count++] = (struct tu_cs_entry) {
+      .bo = bo,
+      .size = (cs->cur - cs->start) * sizeof(uint32_t),
+      .offset = (cs->start - (uint32_t *) bo->map) * sizeof(uint32_t),
+   };
 
    return VK_SUCCESS;
 }
index 7a65bc385858ea42413ec5d75470def94177f425..31f9d23fa4c0d6f46c6f43f02533659b748151ca 100644 (file)
@@ -720,7 +720,7 @@ uint32_t tu_bo_list_add(struct tu_bo_list *list,
 struct tu_cs_entry
 {
    /* No ownership */
-   struct tu_bo *bo;
+   const struct tu_bo *bo;
 
    uint32_t size;
    uint64_t offset;