diff options
author | Chia-I Wu <[email protected]> | 2019-01-16 11:17:26 -0800 |
---|---|---|
committer | Chia-I Wu <[email protected]> | 2019-03-11 10:01:41 -0700 |
commit | af4eb208916d0fc2aecf1a0a44bc29cf49441a84 (patch) | |
tree | 5486cc070b3df6882d7b8835e4c5c324d0e23b70 /src/freedreno | |
parent | ae9a72b48b4fe77113d12a5de0cdb5a0746b8d0a (diff) |
turnip: add tu_cs_add_bo
Refactor BO allocation code out of tu_cs_begin. Add error checking.
Diffstat (limited to 'src/freedreno')
-rw-r--r-- | src/freedreno/vulkan/tu_cmd_buffer.c | 8 | ||||
-rw-r--r-- | src/freedreno/vulkan/tu_cs.c | 78 |
2 files changed, 51 insertions, 35 deletions
diff --git a/src/freedreno/vulkan/tu_cmd_buffer.c b/src/freedreno/vulkan/tu_cmd_buffer.c index d29f07b27ec..36bcd8af8fd 100644 --- a/src/freedreno/vulkan/tu_cmd_buffer.c +++ b/src/freedreno/vulkan/tu_cmd_buffer.c @@ -399,9 +399,11 @@ tu_BeginCommandBuffer(VkCommandBuffer commandBuffer, } } - cmd_buffer->status = TU_CMD_BUFFER_STATUS_RECORDING; - result = tu_cs_begin(cmd_buffer->device, &cmd_buffer->cs, 4096); + if (result != VK_SUCCESS) + return result; + + cmd_buffer->status = TU_CMD_BUFFER_STATUS_RECORDING; /* Put some stuff in so we do not have empty command buffers. */ tu_cs_emit_pkt7(&cmd_buffer->cs, CP_NOP, 4); @@ -410,7 +412,7 @@ tu_BeginCommandBuffer(VkCommandBuffer commandBuffer, tu_cs_emit(&cmd_buffer->cs, 0); tu_cs_emit(&cmd_buffer->cs, 0); - return result; + return VK_SUCCESS; } void diff --git a/src/freedreno/vulkan/tu_cs.c b/src/freedreno/vulkan/tu_cs.c index 02bb1bceac4..155a5df7512 100644 --- a/src/freedreno/vulkan/tu_cs.c +++ b/src/freedreno/vulkan/tu_cs.c @@ -53,6 +53,50 @@ tu_cs_finish(struct tu_device *dev, struct tu_cs *cs) free(cs->bos); } +/* + * Allocate and add a BO to a command stream. Following command packets will + * be emitted to the new BO. + */ +static VkResult +tu_cs_add_bo(struct tu_device *dev, struct tu_cs *cs, uint32_t byte_size) +{ + /* grow cs->bos if needed */ + if (cs->bo_count == cs->bo_capacity) { + uint32_t new_capacity = MAX2(4, 2 * cs->bo_capacity); + struct tu_bo **new_bos = + realloc(cs->bos, new_capacity * sizeof(struct tu_bo *)); + if (!new_bos) + return VK_ERROR_OUT_OF_HOST_MEMORY; + + cs->bo_capacity = new_capacity; + cs->bos = new_bos; + } + + struct tu_bo *new_bo = malloc(sizeof(struct tu_bo)); + if (!new_bo) + return VK_ERROR_OUT_OF_HOST_MEMORY; + + VkResult result = tu_bo_init_new(dev, new_bo, byte_size); + if (result != VK_SUCCESS) { + free(new_bo); + return result; + } + + result = tu_bo_map(dev, new_bo); + if (result != VK_SUCCESS) { + tu_bo_finish(dev, new_bo); + free(new_bo); + return result; + } + + cs->bos[cs->bo_count++] = new_bo; + + cs->start = cs->cur = (uint32_t *) new_bo->map; + cs->end = cs->start + new_bo->size / sizeof(uint32_t); + + return VK_SUCCESS; +} + /** * Begin (or continue) command packet emission. This will reserve space from * the command stream for at least \a reserve_size uint32_t values. @@ -63,43 +107,13 @@ tu_cs_begin(struct tu_device *dev, struct tu_cs *cs, uint32_t reserve_size) assert(reserve_size); if (cs->end - cs->cur < reserve_size) { - if (cs->bo_count == cs->bo_capacity) { - uint32_t new_capacity = MAX2(4, 2 * cs->bo_capacity); - struct tu_bo **new_bos = - realloc(cs->bos, new_capacity * sizeof(struct tu_bo *)); - if (!new_bos) - abort(); - - cs->bo_capacity = new_capacity; - cs->bos = new_bos; - } - uint32_t new_size = MAX2(16384, reserve_size * sizeof(uint32_t)); if (cs->bo_count) new_size = MAX2(new_size, cs->bos[cs->bo_count - 1]->size * 2); - struct tu_bo *new_bo = malloc(sizeof(struct tu_bo)); - if (!new_bo) - abort(); - - VkResult result = tu_bo_init_new(dev, new_bo, new_size); - if (result != VK_SUCCESS) { - free(new_bo); - return result; - } - - result = tu_bo_map(dev, new_bo); - if (result != VK_SUCCESS) { - tu_bo_finish(dev, new_bo); - free(new_bo); + VkResult result = tu_cs_add_bo(dev, cs, new_size); + if (result != VK_SUCCESS) return result; - } - - cs->bos[cs->bo_count] = new_bo; - ++cs->bo_count; - - cs->start = cs->cur = (uint32_t *) new_bo->map; - cs->end = cs->start + new_bo->size / sizeof(uint32_t); } cs->start = cs->cur; |