aboutsummaryrefslogtreecommitdiffstats
path: root/src/freedreno/vulkan/tu_cs.c
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2019-01-28 15:55:40 -0800
committerChia-I Wu <[email protected]>2019-03-11 10:02:13 -0700
commit29f111000399821452e8538ca74ce2de7210ee47 (patch)
tree8a9ed9b5cbce3c3bf5adba64409c2f2bc2dca64d /src/freedreno/vulkan/tu_cs.c
parent0d81be3959234c3d877efd6ddee5280b01815433 (diff)
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.
Diffstat (limited to 'src/freedreno/vulkan/tu_cs.c')
-rw-r--r--src/freedreno/vulkan/tu_cs.c65
1 files changed, 36 insertions, 29 deletions
diff --git a/src/freedreno/vulkan/tu_cs.c b/src/freedreno/vulkan/tu_cs.c
index 81bf36e9a87..0e3d4e99b42 100644
--- a/src/freedreno/vulkan/tu_cs.c
+++ b/src/freedreno/vulkan/tu_cs.c
@@ -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 and add an IB entry.
+ */
+void
+tu_cs_end(struct tu_cs *cs)
+{
+ if (!tu_cs_is_empty(cs))
+ tu_cs_add_entry(cs);
}
/**
- * End command packet emission by adding an IB entry for the command packets
- * emitted since the last call to tu_cs_begin.
+ * Reserve space from a command stream for \a reserved_size uint32_t values.
*/
VkResult
-tu_cs_end(struct tu_cs *cs)
+tu_cs_reserve_space(struct tu_device *dev,
+ struct tu_cs *cs,
+ uint32_t reserved_size)
{
- /* no command packet at all */
- if (tu_cs_is_empty(cs))
- return VK_SUCCESS;
+ 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);
- VkResult result = tu_cs_reserve_entry(cs);
- if (result != VK_SUCCESS)
- return result;
+ /* 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;
+ }
- tu_cs_add_entry(cs);
+ assert(tu_cs_get_space(cs) >= reserved_size);
+ cs->reserved_end = cs->cur + reserved_size;
- return VK_SUCCESS;
+ /* reserve an entry for the next call to this function or tu_cs_end */
+ return tu_cs_reserve_entry(dev, cs);
}
/**