freedreno/ir3: small cleanup
[mesa.git] / src / freedreno / vulkan / tu_cs.h
index 05e077185042dbdd7d4dd3e6a44d594bb3d69d9c..f3e0ade2a367b985316cd49fe60f78406166edef 100644 (file)
@@ -59,6 +59,17 @@ tu_cs_reserve_space(struct tu_device *dev,
 void
 tu_cs_reset(struct tu_device *dev, struct tu_cs *cs);
 
+/**
+ * Discard all entries.  This allows \a cs to be reused while keeping the
+ * existing BOs and command packets intact.
+ */
+static inline void
+tu_cs_discard_entries(struct tu_cs *cs)
+{
+   assert(cs->mode == TU_CS_MODE_GROW);
+   cs->entry_count = 0;
+}
+
 /**
  * Get the size needed for tu_cs_emit_call.
  */
@@ -87,11 +98,22 @@ tu_cs_sanity_check(const struct tu_cs *cs)
 static inline void
 tu_cs_emit(struct tu_cs *cs, uint32_t value)
 {
-   assert(cs->cur < cs->end);
+   assert(cs->cur < cs->reserved_end);
    *cs->cur = value;
    ++cs->cur;
 }
 
+/**
+ * Emit an array of uint32_t into a command stream, without boundary checking.
+ */
+static inline void
+tu_cs_emit_array(struct tu_cs *cs, const uint32_t *values, uint32_t length)
+{
+   assert(cs->cur + length <= cs->reserved_end);
+   memcpy(cs->cur, values, sizeof(uint32_t) * length);
+   cs->cur += length;
+}
+
 static inline unsigned
 tu_odd_parity_bit(unsigned val)
 {
@@ -153,8 +175,10 @@ tu_cs_emit_write_reg(struct tu_cs *cs, uint16_t reg, uint32_t value)
 static inline void
 tu_cs_emit_ib(struct tu_cs *cs, const struct tu_cs_entry *entry)
 {
-   assert(entry->offset % sizeof(uint32_t) == 0);
+   assert(entry->bo);
+   assert(entry->size && entry->offset + entry->size <= entry->bo->size);
    assert(entry->size % sizeof(uint32_t) == 0);
+   assert(entry->offset % sizeof(uint32_t) == 0);
 
    tu_cs_emit_pkt7(cs, CP_INDIRECT_BUFFER, 3);
    tu_cs_emit_qw(cs, entry->bo->iova + entry->offset);