turnip: add function to allocate aligned memory in a substream cs
authorJonathan Marek <jonathan@marek.ca>
Fri, 15 Nov 2019 20:15:53 +0000 (15:15 -0500)
committerJonathan Marek <jonathan@marek.ca>
Fri, 6 Dec 2019 03:12:29 +0000 (22:12 -0500)
To use with texture states that need alignment (texconst, sampler, border)

Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
src/freedreno/vulkan/tu_cs.c
src/freedreno/vulkan/tu_cs.h
src/freedreno/vulkan/tu_private.h

index 48242f813ada953826896797c6d3881b56a6a0e1..22c0527db880fcca0eea906c64aa99729f2d573f 100644 (file)
@@ -262,6 +262,41 @@ tu_cs_begin_sub_stream(struct tu_device *dev,
    return VK_SUCCESS;
 }
 
+/**
+ * Allocate count*size dwords, aligned to size dwords.
+ * \a cs must be in TU_CS_MODE_SUB_STREAM mode.
+ *
+ */
+VkResult
+tu_cs_alloc(struct tu_device *dev,
+            struct tu_cs *cs,
+            uint32_t count,
+            uint32_t size,
+            struct ts_cs_memory *memory)
+{
+   assert(cs->mode == TU_CS_MODE_SUB_STREAM);
+   assert(size && size <= 1024);
+
+   if (!count)
+      return VK_SUCCESS;
+
+   /* TODO: smarter way to deal with alignment? */
+
+   VkResult result = tu_cs_reserve_space(dev, cs, count * size + (size-1));
+   if (result != VK_SUCCESS)
+      return result;
+
+   struct tu_bo *bo = cs->bos[cs->bo_count - 1];
+   size_t offset = align(tu_cs_get_offset(cs), size);
+
+   memory->map = bo->map + offset * sizeof(uint32_t);
+   memory->iova = bo->iova + offset * sizeof(uint32_t);
+
+   cs->start = cs->cur = (uint32_t*) bo->map + offset + count * size;
+
+   return VK_SUCCESS;
+}
+
 /**
  * End command packet emission to a sub-stream.  \a sub_cs becomes invalid
  * after this call.
index f3e0ade2a367b985316cd49fe60f78406166edef..19fe984b4312783e4db49edae5b6aac334a197a3 100644 (file)
@@ -48,6 +48,13 @@ tu_cs_begin_sub_stream(struct tu_device *dev,
                        uint32_t size,
                        struct tu_cs *sub_cs);
 
+VkResult
+tu_cs_alloc(struct tu_device *dev,
+            struct tu_cs *cs,
+            uint32_t count,
+            uint32_t size,
+            struct ts_cs_memory *memory);
+
 struct tu_cs_entry
 tu_cs_end_sub_stream(struct tu_cs *cs, struct tu_cs *sub_cs);
 
index 2532feed14e3d3531695aa8edb714b6829940c11..4f2b9fefad5c2c26963e31dc08e01bf1c3196331 100644 (file)
@@ -508,6 +508,11 @@ struct tu_cs_entry
    uint32_t offset;
 };
 
+struct ts_cs_memory {
+   uint32_t *map;
+   uint64_t iova;
+};
+
 enum tu_cs_mode
 {