turnip: Implement a slow bo list
authorBas Nieuwenhuizen <basni@chromium.org>
Mon, 31 Dec 2018 10:34:32 +0000 (11:34 +0100)
committerChia-I Wu <olvaffe@gmail.com>
Mon, 11 Mar 2019 17:01:41 +0000 (10:01 -0700)
src/freedreno/vulkan/tu_cmd_buffer.c
src/freedreno/vulkan/tu_private.h

index 60002a0a708f96e79f502890025d5cd91d972f98..e8835a0aa3248a806fbff1a5816002eb1e895299 100644 (file)
 
 #include "vk_format.h"
 
+static void
+tu_bo_list_init(struct tu_bo_list *list)
+{
+   list->count = list->capacity = 0;
+   list->handles = NULL;
+}
+
+static void
+tu_bo_list_destroy(struct tu_bo_list *list)
+{
+   free(list->handles);
+}
+
+static void
+tu_bo_list_reset(struct tu_bo_list *list)
+{
+   list->count = 0;
+}
+
+static uint32_t
+tu_bo_list_add(struct tu_bo_list *list,
+               const struct tu_bo *bo)
+{
+   uint32_t handle = bo->gem_handle;
+   for (uint32_t i = 0; i < list->count; ++i) {
+      if (list->handles[i] == handle)
+         return i;
+   }
+
+   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)
+         return ~0;
+      list->handles = new_handles;
+      list->capacity = new_capacity;
+   }
+
+   uint32_t ret = list->count;
+   list->handles[list->count] = handle;
+   ++list->count;
+
+   return ret;
+}
+
 const struct tu_dynamic_state default_dynamic_state = {
    .viewport =
      {
@@ -199,6 +244,8 @@ tu_create_cmd_buffer(struct tu_device *device,
       cmd_buffer->queue_family_index = TU_QUEUE_GENERAL;
    }
 
+   tu_bo_list_init(&cmd_buffer->bo_list);
+
    *pCommandBuffer = tu_cmd_buffer_to_handle(cmd_buffer);
 
    list_inithead(&cmd_buffer->upload.list);
@@ -214,6 +261,7 @@ tu_cmd_buffer_destroy(struct tu_cmd_buffer *cmd_buffer)
    for (unsigned i = 0; i < VK_PIPELINE_BIND_POINT_RANGE_SIZE; i++)
       free(cmd_buffer->descriptors[i].push_set.set.mapped_ptr);
 
+   tu_bo_list_destroy(&cmd_buffer->bo_list);
    vk_free(&cmd_buffer->pool->alloc, cmd_buffer);
 }
 
@@ -222,6 +270,8 @@ tu_reset_cmd_buffer(struct tu_cmd_buffer *cmd_buffer)
 {
    cmd_buffer->record_result = VK_SUCCESS;
 
+   tu_bo_list_reset(&cmd_buffer->bo_list);
+
    for (unsigned i = 0; i < VK_PIPELINE_BIND_POINT_RANGE_SIZE; i++) {
       cmd_buffer->descriptors[i].dirty = 0;
       cmd_buffer->descriptors[i].valid = 0;
index 4f2a14a3dd1eae3cd05ebe113be4dfc9b154cfab..e884b2cd8dbd85ccd417a1d8e60aea0e33f4e193 100644 (file)
@@ -403,12 +403,6 @@ struct tu_queue
    VkDeviceQueueCreateFlags flags;
 };
 
-struct tu_bo_list
-{
-   unsigned capacity;
-   pthread_mutex_t mutex;
-};
-
 struct tu_device
 {
    VK_LOADER_DATA _loader_data;
@@ -431,11 +425,6 @@ struct tu_device
    mtx_t shader_slab_mutex;
 
    struct tu_device_extension_table enabled_extensions;
-
-   /* Whether the driver uses a global BO list. */
-   bool use_global_bo_list;
-
-   struct tu_bo_list bo_list;
 };
 
 struct tu_bo
@@ -715,6 +704,13 @@ enum tu_cmd_buffer_status
    TU_CMD_BUFFER_STATUS_PENDING,
 };
 
+struct tu_bo_list
+{
+   uint32_t count;
+   uint32_t capacity;
+   uint32_t *handles;
+};
+
 struct tu_cmd_buffer
 {
    VK_LOADER_DATA _loader_data;
@@ -740,19 +736,9 @@ struct tu_cmd_buffer
 
    struct tu_cmd_buffer_upload upload;
 
-   uint32_t scratch_size_needed;
-   uint32_t compute_scratch_size_needed;
-   uint32_t esgs_ring_size_needed;
-   uint32_t gsvs_ring_size_needed;
-   bool tess_rings_needed;
-   bool sample_positions_needed;
+   struct tu_bo_list bo_list;
 
    VkResult record_result;
-
-   /**
-    * Whether a query pool has been resetted and we have to flush caches.
-    */
-   bool pending_reset_query;
 };
 
 bool