summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2019-01-18 14:24:45 -0800
committerChia-I Wu <[email protected]>2019-03-11 10:01:41 -0700
commit3b3af6321b9231752014ed441ba9b056219e23aa (patch)
tree08bb7f240827ebbce409ba368a4585b03675d72e
parentaaa59ef70c100fe861c099197581a1131f2bc8a4 (diff)
turnip: add tu_cs_reserve_space(_assert)
They are used like tu_cs_reserve_space(...); tu_cs_emit(...); ...; tu_cs_reserve_space_assert(); to make sure we reserved enough space at the beginning.
-rw-r--r--src/freedreno/vulkan/tu_cs.c2
-rw-r--r--src/freedreno/vulkan/tu_cs.h24
-rw-r--r--src/freedreno/vulkan/tu_private.h3
3 files changed, 26 insertions, 3 deletions
diff --git a/src/freedreno/vulkan/tu_cs.c b/src/freedreno/vulkan/tu_cs.c
index efc38b17757..ffb1dc4f10f 100644
--- a/src/freedreno/vulkan/tu_cs.c
+++ b/src/freedreno/vulkan/tu_cs.c
@@ -117,6 +117,8 @@ tu_cs_begin(struct tu_device *dev, struct tu_cs *cs, uint32_t reserve_size)
return result;
}
+ assert(cs->end - cs->cur >= reserve_size);
+
return VK_SUCCESS;
}
diff --git a/src/freedreno/vulkan/tu_cs.h b/src/freedreno/vulkan/tu_cs.h
index 94d9bf7cdde..a26b01b0ca2 100644
--- a/src/freedreno/vulkan/tu_cs.h
+++ b/src/freedreno/vulkan/tu_cs.h
@@ -42,16 +42,34 @@ 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_check_space(struct tu_device *dev, struct tu_cs *cs, size_t size)
+tu_cs_reserve_space(struct tu_device *dev, struct tu_cs *cs, size_t size)
{
- if (cs->end - cs->cur >= 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;
- return tu_cs_begin(dev, cs, size);
+ 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.
+ */
+static inline void
+tu_cs_reserve_space_assert(struct tu_cs *cs)
+{
+ assert(cs->cur <= cs->reserved_end);
}
/**
diff --git a/src/freedreno/vulkan/tu_private.h b/src/freedreno/vulkan/tu_private.h
index c52aaa34cd2..4b985d8ca69 100644
--- a/src/freedreno/vulkan/tu_private.h
+++ b/src/freedreno/vulkan/tu_private.h
@@ -747,6 +747,9 @@ struct tu_cs
uint32_t *cur;
uint32_t *end;
+ /* for tu_cs_reserve_space_assert */
+ uint32_t *reserved_end;
+
struct tu_cs_entry *entries;
uint32_t entry_count;
uint32_t entry_capacity;