turnip: never fail tu_cs_begin/tu_cs_end

Error checking tu_cs_begin/tu_cs_end is too tedious for the callers.
Move tu_cs_add_bo and tu_cs_reserve_entry to tu_cs_reserve_space
such that tu_cs_begin/tu_cs_end never fails.
This commit is contained in:
Chia-I Wu
2019-01-28 15:55:40 -08:00
parent 0d81be3959
commit 29f1110003
3 changed files with 51 additions and 64 deletions
+2 -6
View File
@@ -945,9 +945,7 @@ tu_BeginCommandBuffer(VkCommandBuffer commandBuffer,
memset(&cmd_buffer->state, 0, sizeof(cmd_buffer->state));
cmd_buffer->usage_flags = pBeginInfo->flags;
result = tu_cs_begin(cmd_buffer->device, &cmd_buffer->cs, 4096);
if (result != VK_SUCCESS)
return result;
tu_cs_begin(&cmd_buffer->cs);
cmd_buffer->marker_seqno = 0;
cmd_buffer->scratch_seqno = 0;
@@ -1019,9 +1017,7 @@ tu_EndCommandBuffer(VkCommandBuffer commandBuffer)
MSM_SUBMIT_BO_WRITE);
}
VkResult result = tu_cs_end(&cmd_buffer->cs);
if (result != VK_SUCCESS)
cmd_buffer->record_result = result;
tu_cs_end(&cmd_buffer->cs);
assert(!cmd_buffer->state.attachments);
+37 -30
View File
@@ -96,6 +96,9 @@ tu_cs_is_empty(const struct tu_cs *cs)
static VkResult
tu_cs_add_bo(struct tu_device *dev, struct tu_cs *cs, uint32_t size)
{
/* no dangling command packet */
assert(tu_cs_is_empty(cs));
/* grow cs->bos if needed */
if (cs->bo_count == cs->bo_capacity) {
uint32_t new_capacity = MAX2(4, 2 * cs->bo_capacity);
@@ -137,7 +140,7 @@ tu_cs_add_bo(struct tu_device *dev, struct tu_cs *cs, uint32_t size)
* Reserve an IB entry.
*/
static VkResult
tu_cs_reserve_entry(struct tu_cs *cs)
tu_cs_reserve_entry(struct tu_device *dev, struct tu_cs *cs)
{
/* grow cs->entries if needed */
if (cs->entry_count == cs->entry_capacity) {
@@ -182,47 +185,51 @@ tu_cs_add_entry(struct tu_cs *cs)
}
/**
* Begin (or continue) command packet emission. This will reserve space from
* the command stream for at least \a reserve_size uint32_t values.
* Begin (or continue) command packet emission. This does nothing but sanity
* checks currently.
*/
VkResult
tu_cs_begin(struct tu_device *dev, struct tu_cs *cs, uint32_t reserve_size)
void
tu_cs_begin(struct tu_cs *cs)
{
/* no dangling command packet */
assert(tu_cs_is_empty(cs));
if (tu_cs_get_space(cs) < reserve_size) {
uint32_t new_size = MAX2(cs->next_bo_size, reserve_size);
VkResult result = tu_cs_add_bo(dev, cs, new_size);
if (result != VK_SUCCESS)
return result;
cs->next_bo_size = new_size * 2;
}
assert(tu_cs_get_space(cs) >= reserve_size);
return VK_SUCCESS;
}
/**
* End command packet emission by adding an IB entry for the command packets
* emitted since the last call to tu_cs_begin.
* End command packet emission and add an IB entry.
*/
VkResult
void
tu_cs_end(struct tu_cs *cs)
{
/* no command packet at all */
if (tu_cs_is_empty(cs))
return VK_SUCCESS;
if (!tu_cs_is_empty(cs))
tu_cs_add_entry(cs);
}
VkResult result = tu_cs_reserve_entry(cs);
if (result != VK_SUCCESS)
return result;
/**
* Reserve space from a command stream for \a reserved_size uint32_t values.
*/
VkResult
tu_cs_reserve_space(struct tu_device *dev,
struct tu_cs *cs,
uint32_t reserved_size)
{
if (tu_cs_get_space(cs) < reserved_size) {
/* add an entry for the exiting command packets */
if (!tu_cs_is_empty(cs))
tu_cs_add_entry(cs);
tu_cs_add_entry(cs);
/* switch to a new BO */
uint32_t new_size = MAX2(cs->next_bo_size, reserved_size);
VkResult result = tu_cs_add_bo(dev, cs, new_size);
if (result != VK_SUCCESS)
return result;
cs->next_bo_size = new_size * 2;
}
return VK_SUCCESS;
assert(tu_cs_get_space(cs) >= reserved_size);
cs->reserved_end = cs->cur + reserved_size;
/* reserve an entry for the next call to this function or tu_cs_end */
return tu_cs_reserve_entry(dev, cs);
}
/**
+12 -28
View File
@@ -29,40 +29,24 @@
void
tu_cs_init(struct tu_cs *cs, uint32_t initial_size);
void
tu_cs_finish(struct tu_device *dev, struct tu_cs *cs);
VkResult
tu_cs_begin(struct tu_device *dev, struct tu_cs *cs, uint32_t reserve_size);
VkResult
void
tu_cs_begin(struct tu_cs *cs);
void
tu_cs_end(struct tu_cs *cs);
VkResult
tu_cs_reserve_space(struct tu_device *dev,
struct tu_cs *cs,
uint32_t reserved_size);
void
tu_cs_reset(struct tu_device *dev, struct tu_cs *cs);
/**
* Reserve space from a command stream for \a size uint32_t values.
*/
static inline VkResult
tu_cs_reserve_space(struct tu_device *dev, struct tu_cs *cs, size_t size)
{
if (cs->end - cs->cur >= size) {
cs->reserved_end = cs->cur + size;
return VK_SUCCESS;
}
VkResult result = tu_cs_end(cs);
if (result != VK_SUCCESS)
return result;
result = tu_cs_begin(dev, cs, size);
if (result != VK_SUCCESS)
return result;
cs->reserved_end = cs->cur + size;
assert(cs->reserved_end <= cs->end);
return VK_SUCCESS;
}
/**
* Assert that we did not exceed the reserved space.
*/