turnip: build drm_msm_gem_submit_bo array directly
authorChia-I Wu <olvaffe@gmail.com>
Thu, 17 Jan 2019 18:23:19 +0000 (10:23 -0800)
committerChia-I Wu <olvaffe@gmail.com>
Mon, 11 Mar 2019 17:01:41 +0000 (10:01 -0700)
Build drm_msm_gem_submit_bo array directly in tu_bo_list.  We might
change this again, but this is good enough for now.

There are other issues as well, such as not using
VkAllocationCallbacks and sloppy error checking.  We should revisit
this in the near future.  Same to tu_cs.

src/freedreno/vulkan/tu_cmd_buffer.c
src/freedreno/vulkan/tu_device.c
src/freedreno/vulkan/tu_private.h

index 4600f1ffa2f73d11e20b6cf8ff52f9deb934568e..d58e8e1bd0fe0a83320f7beb9bf530cc09cb31ef 100644 (file)
@@ -35,13 +35,13 @@ void
 tu_bo_list_init(struct tu_bo_list *list)
 {
    list->count = list->capacity = 0;
-   list->handles = NULL;
+   list->bo_infos = NULL;
 }
 
 void
 tu_bo_list_destroy(struct tu_bo_list *list)
 {
-   free(list->handles);
+   free(list->bo_infos);
 }
 
 void
@@ -50,27 +50,39 @@ tu_bo_list_reset(struct tu_bo_list *list)
    list->count = 0;
 }
 
+/**
+ * \a flags consists of MSM_SUBMIT_BO_FLAGS.
+ */
 uint32_t
 tu_bo_list_add(struct tu_bo_list *list,
-               const struct tu_bo *bo)
+               const struct tu_bo *bo,
+               uint32_t flags)
 {
    uint32_t handle = bo->gem_handle;
    for (uint32_t i = 0; i < list->count; ++i) {
-      if (list->handles[i] == handle)
+      if (list->bo_infos[i].handle == handle) {
+         list->bo_infos[i].flags |= flags;
          return i;
+      }
    }
 
+   /* grow list->bo_infos if needed */
    if (list->count == list->capacity) {
       uint32_t new_capacity = MAX2(2 * list->count, 16);
-      uint32_t *new_handles = realloc(list->handles, new_capacity * sizeof(uint32_t));
-      if (!new_handles)
+      struct drm_msm_gem_submit_bo *new_bo_infos = realloc(
+         list->bo_infos, new_capacity * sizeof(struct drm_msm_gem_submit_bo));
+      if (!new_bo_infos)
          return ~0;
-      list->handles = new_handles;
+      list->bo_infos = new_bo_infos;
       list->capacity = new_capacity;
    }
 
    uint32_t ret = list->count;
-   list->handles[list->count] = handle;
+   list->bo_infos[list->count] = (struct drm_msm_gem_submit_bo) {
+      .flags = flags,
+      .handle = bo->gem_handle,
+      .presumed = bo->iova,
+   };
    ++list->count;
 
    return ret;
index d5533028a6216095c4414b40a7ac276647404eee..f0c70f4f8113127c92163dc0444ca8f720962304 100644 (file)
@@ -1178,8 +1178,8 @@ tu_QueueSubmit(VkQueue _queue,
          struct tu_cs *cs = &cmdbuf->cs;
          for (unsigned i = 0; i < cs->entry_count; ++i, ++entry_idx) {
             cmds[entry_idx].type = MSM_SUBMIT_CMD_BUF;
-            cmds[entry_idx].submit_idx =
-               tu_bo_list_add(&bo_list, cs->entries[i].bo);
+            cmds[entry_idx].submit_idx = tu_bo_list_add(
+               &bo_list, cs->entries[i].bo, MSM_SUBMIT_BO_READ);
             cmds[entry_idx].submit_offset = cs->entries[i].offset;
             cmds[entry_idx].size = cs->entries[i].size;
             cmds[entry_idx].pad = 0;
@@ -1188,13 +1188,6 @@ tu_QueueSubmit(VkQueue _queue,
          }
       }
 
-      struct drm_msm_gem_submit_bo bos[bo_list.count];
-      for (unsigned i = 0; i < bo_list.count; ++i) {
-         bos[i].flags = MSM_SUBMIT_BO_READ | MSM_SUBMIT_BO_WRITE;
-         bos[i].handle = bo_list.handles[i];
-         bos[i].presumed = 0;
-      }
-
       uint32_t flags = MSM_PIPE_3D0;
       if (last_submit) {
          flags |= MSM_SUBMIT_FENCE_FD_OUT;
@@ -1203,7 +1196,7 @@ tu_QueueSubmit(VkQueue _queue,
       struct drm_msm_gem_submit req = {
          .flags = flags,
          .queueid = queue->msm_queue_id,
-         .bos = (uint64_t)(uintptr_t)bos,
+         .bos = (uint64_t)(uintptr_t) bo_list.bo_infos,
          .nr_bos = bo_list.count,
          .cmds = (uint64_t)(uintptr_t)cmds,
          .nr_cmds = entry_count,
index 31f9d23fa4c0d6f46c6f43f02533659b748151ca..c2552330cb8d832a359a09f7451690737f24fbe5 100644 (file)
@@ -51,6 +51,7 @@
 #include "vk_alloc.h"
 #include "vk_debug_report.h"
 
+#include "drm/msm_drm.h"
 #include "tu_descriptor_set.h"
 #include "tu_extensions.h"
 
@@ -708,14 +709,19 @@ struct tu_bo_list
 {
    uint32_t count;
    uint32_t capacity;
-   uint32_t *handles;
+   struct drm_msm_gem_submit_bo *bo_infos;
 };
 
-void tu_bo_list_init(struct tu_bo_list *list);
-void tu_bo_list_destroy(struct tu_bo_list *list);
-void tu_bo_list_reset(struct tu_bo_list *list);
-uint32_t tu_bo_list_add(struct tu_bo_list *list,
-                        const struct tu_bo *bo);
+void
+tu_bo_list_init(struct tu_bo_list *list);
+void
+tu_bo_list_destroy(struct tu_bo_list *list);
+void
+tu_bo_list_reset(struct tu_bo_list *list);
+uint32_t
+tu_bo_list_add(struct tu_bo_list *list,
+               const struct tu_bo *bo,
+               uint32_t flags);
 
 struct tu_cs_entry
 {