From: Chia-I Wu Date: Fri, 18 Jan 2019 22:24:45 +0000 (-0800) Subject: turnip: add tu_cs_reserve_space(_assert) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3b3af6321b9231752014ed441ba9b056219e23aa;p=mesa.git 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. --- 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;