vk/cmd_buffer: Pull the execbuf stuff into a substruct
authorJason Ekstrand <jason.ekstrand@intel.com>
Mon, 27 Jul 2015 23:37:09 +0000 (16:37 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Mon, 27 Jul 2015 23:37:09 +0000 (16:37 -0700)
src/vulkan/anv_aub.c
src/vulkan/anv_cmd_buffer.c
src/vulkan/anv_cmd_emit.c
src/vulkan/anv_device.c
src/vulkan/anv_private.h

index 97f124a0aad8de5229fd3cc170d03f4fcfbb84f0..c371cce1bb81683fb1ac85e36456e12d2ba7ae2b 100644 (file)
@@ -248,10 +248,10 @@ anv_cmd_buffer_dump(struct anv_cmd_buffer *cmd_buffer)
    if (writer == NULL)
       return;
 
-   aub_bos = malloc(cmd_buffer->exec2_bo_count * sizeof(aub_bos[0]));
+   aub_bos = malloc(cmd_buffer->execbuf2.bo_count * sizeof(aub_bos[0]));
    offset = writer->offset;
-   for (uint32_t i = 0; i < cmd_buffer->exec2_bo_count; i++) {
-      bo = cmd_buffer->exec2_bos[i];
+   for (uint32_t i = 0; i < cmd_buffer->execbuf2.bo_count; i++) {
+      bo = cmd_buffer->execbuf2.bos[i];
       if (bo->map)
          aub_bos[i].map = bo->map;
       else
@@ -282,9 +282,9 @@ anv_cmd_buffer_dump(struct anv_cmd_buffer *cmd_buffer)
                   bbo->num_relocs, aub_bos);
    }
 
-   for (uint32_t i = 0; i < cmd_buffer->exec2_bo_count; i++) {
-      bo = cmd_buffer->exec2_bos[i];
-      if (i == cmd_buffer->exec2_bo_count - 1) {
+   for (uint32_t i = 0; i < cmd_buffer->execbuf2.bo_count; i++) {
+      bo = cmd_buffer->execbuf2.bos[i];
+      if (i == cmd_buffer->execbuf2.bo_count - 1) {
          assert(bo == &first_bbo->bo);
          aub_write_trace_block(writer, AUB_TRACE_TYPE_BATCH,
                                aub_bos[i].relocated,
index bb58338c85f0515b0265928c453d218a4311dbc1..1c891e19ac659044ea4b37e5c2c308bf8e631f93 100644 (file)
@@ -381,9 +381,9 @@ anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer)
    /* Start surface_next at 1 so surface offset 0 is invalid. */
    cmd_buffer->surface_next = 1;
 
-   cmd_buffer->exec2_objects = NULL;
-   cmd_buffer->exec2_bos = NULL;
-   cmd_buffer->exec2_array_length = 0;
+   cmd_buffer->execbuf2.objects = NULL;
+   cmd_buffer->execbuf2.bos = NULL;
+   cmd_buffer->execbuf2.array_length = 0;
 
    return VK_SUCCESS;
 
@@ -420,8 +420,8 @@ anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer)
    }
    anv_reloc_list_finish(&cmd_buffer->surface_relocs, device);
 
-   anv_device_free(device, cmd_buffer->exec2_objects);
-   anv_device_free(device, cmd_buffer->exec2_bos);
+   anv_device_free(device, cmd_buffer->execbuf2.objects);
+   anv_device_free(device, cmd_buffer->execbuf2.bos);
 }
 
 void
@@ -461,13 +461,13 @@ anv_cmd_buffer_add_bo(struct anv_cmd_buffer *cmd_buffer,
 {
    struct drm_i915_gem_exec_object2 *obj;
 
-   if (bo->index < cmd_buffer->exec2_bo_count &&
-       cmd_buffer->exec2_bos[bo->index] == bo)
+   if (bo->index < cmd_buffer->execbuf2.bo_count &&
+       cmd_buffer->execbuf2.bos[bo->index] == bo)
       return VK_SUCCESS;
 
-   if (cmd_buffer->exec2_bo_count >= cmd_buffer->exec2_array_length) {
-      uint32_t new_len = cmd_buffer->exec2_objects ?
-                         cmd_buffer->exec2_array_length * 2 : 64;
+   if (cmd_buffer->execbuf2.bo_count >= cmd_buffer->execbuf2.array_length) {
+      uint32_t new_len = cmd_buffer->execbuf2.objects ?
+                         cmd_buffer->execbuf2.array_length * 2 : 64;
 
       struct drm_i915_gem_exec_object2 *new_objects =
          anv_device_alloc(cmd_buffer->device, new_len * sizeof(*new_objects),
@@ -483,23 +483,23 @@ anv_cmd_buffer_add_bo(struct anv_cmd_buffer *cmd_buffer,
          return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
       }
 
-      if (cmd_buffer->exec2_objects) {
-         memcpy(new_objects, cmd_buffer->exec2_objects,
-                cmd_buffer->exec2_bo_count * sizeof(*new_objects));
-         memcpy(new_bos, cmd_buffer->exec2_bos,
-                cmd_buffer->exec2_bo_count * sizeof(*new_bos));
+      if (cmd_buffer->execbuf2.objects) {
+         memcpy(new_objects, cmd_buffer->execbuf2.objects,
+                cmd_buffer->execbuf2.bo_count * sizeof(*new_objects));
+         memcpy(new_bos, cmd_buffer->execbuf2.bos,
+                cmd_buffer->execbuf2.bo_count * sizeof(*new_bos));
       }
 
-      cmd_buffer->exec2_objects = new_objects;
-      cmd_buffer->exec2_bos = new_bos;
-      cmd_buffer->exec2_array_length = new_len;
+      cmd_buffer->execbuf2.objects = new_objects;
+      cmd_buffer->execbuf2.bos = new_bos;
+      cmd_buffer->execbuf2.array_length = new_len;
    }
 
-   assert(cmd_buffer->exec2_bo_count < cmd_buffer->exec2_array_length);
+   assert(cmd_buffer->execbuf2.bo_count < cmd_buffer->execbuf2.array_length);
 
-   bo->index = cmd_buffer->exec2_bo_count++;
-   obj = &cmd_buffer->exec2_objects[bo->index];
-   cmd_buffer->exec2_bos[bo->index] = bo;
+   bo->index = cmd_buffer->execbuf2.bo_count++;
+   obj = &cmd_buffer->execbuf2.objects[bo->index];
+   cmd_buffer->execbuf2.bos[bo->index] = bo;
 
    obj->handle = bo->gem_handle;
    obj->relocation_count = 0;
@@ -543,7 +543,7 @@ anv_cmd_buffer_process_relocs(struct anv_cmd_buffer *cmd_buffer,
    for (size_t i = 0; i < list->num_relocs; i++) {
       bo = list->reloc_bos[i];
       if (bo->offset != list->relocs[i].presumed_offset)
-         cmd_buffer->need_reloc = true;
+         cmd_buffer->execbuf2.need_reloc = true;
 
       list->relocs[i].target_handle = bo->index;
    }
@@ -561,12 +561,12 @@ anv_cmd_buffer_emit_batch_buffer_end(struct anv_cmd_buffer *cmd_buffer)
 }
 
 void
-anv_cmd_buffer_compute_validate_list(struct anv_cmd_buffer *cmd_buffer)
+anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer *cmd_buffer)
 {
    struct anv_batch *batch = &cmd_buffer->batch;
 
-   cmd_buffer->exec2_bo_count = 0;
-   cmd_buffer->need_reloc = false;
+   cmd_buffer->execbuf2.bo_count = 0;
+   cmd_buffer->execbuf2.need_reloc = false;
 
    /* Add surface state bos first so we can add them with their relocs. */
    for (struct anv_batch_bo *bbo = cmd_buffer->surface_batch_bo;
@@ -596,24 +596,25 @@ anv_cmd_buffer_compute_validate_list(struct anv_cmd_buffer *cmd_buffer)
    anv_cmd_buffer_add_bo(cmd_buffer, &batch_bo->bo,
                          &batch->relocs.relocs[batch_bo->first_reloc],
                          batch_bo->num_relocs);
-   assert(batch_bo->bo.index == cmd_buffer->exec2_bo_count - 1);
+   assert(batch_bo->bo.index == cmd_buffer->execbuf2.bo_count - 1);
 
    anv_cmd_buffer_process_relocs(cmd_buffer, &cmd_buffer->surface_relocs);
    anv_cmd_buffer_process_relocs(cmd_buffer, &batch->relocs);
 
-   cmd_buffer->execbuf.buffers_ptr = (uintptr_t) cmd_buffer->exec2_objects;
-   cmd_buffer->execbuf.buffer_count = cmd_buffer->exec2_bo_count;
-   cmd_buffer->execbuf.batch_start_offset = 0;
-   cmd_buffer->execbuf.batch_len = batch->next - batch->start;
-   cmd_buffer->execbuf.cliprects_ptr = 0;
-   cmd_buffer->execbuf.num_cliprects = 0;
-   cmd_buffer->execbuf.DR1 = 0;
-   cmd_buffer->execbuf.DR4 = 0;
-
-   cmd_buffer->execbuf.flags = I915_EXEC_HANDLE_LUT;
-   if (!cmd_buffer->need_reloc)
-      cmd_buffer->execbuf.flags |= I915_EXEC_NO_RELOC;
-   cmd_buffer->execbuf.flags |= I915_EXEC_RENDER;
-   cmd_buffer->execbuf.rsvd1 = cmd_buffer->device->context_id;
-   cmd_buffer->execbuf.rsvd2 = 0;
+   cmd_buffer->execbuf2.execbuf = (struct drm_i915_gem_execbuffer2) {
+      .buffers_ptr = (uintptr_t) cmd_buffer->execbuf2.objects,
+      .buffer_count = cmd_buffer->execbuf2.bo_count,
+      .batch_start_offset = 0,
+      .batch_len = batch->next - batch->start,
+      .cliprects_ptr = 0,
+      .num_cliprects = 0,
+      .DR1 = 0,
+      .DR4 = 0,
+      .flags = I915_EXEC_HANDLE_LUT | I915_EXEC_RENDER,
+      .rsvd1 = cmd_buffer->device->context_id,
+      .rsvd2 = 0,
+   };
+
+   if (!cmd_buffer->execbuf2.need_reloc)
+      cmd_buffer->execbuf2.execbuf.flags |= I915_EXEC_NO_RELOC;
 }
index c624906ae36c45bc5f40a853866bd93cf0fd1977..8178e6979641274ad697869016c6c811061642fa 100644 (file)
@@ -189,7 +189,7 @@ VkResult anv_EndCommandBuffer(
     * Fortunately, the chances for contention here are probably very low.
     */
    pthread_mutex_lock(&device->mutex);
-   anv_cmd_buffer_compute_validate_list(cmd_buffer);
+   anv_cmd_buffer_prepare_execbuf(cmd_buffer);
    pthread_mutex_unlock(&device->mutex);
 
    return VK_SUCCESS;
index 0bcf9b04b4582ae22164a182cdcb81881573b6e1..ee7682a5d9afbc96376bd0cdf10ce066d714d373 100644 (file)
@@ -742,7 +742,7 @@ VkResult anv_QueueSubmit(
          anv_cmd_buffer_dump(cmd_buffer);
 
       if (!device->no_hw) {
-         ret = anv_gem_execbuffer(device, &cmd_buffer->execbuf);
+         ret = anv_gem_execbuffer(device, &cmd_buffer->execbuf2.execbuf);
          if (ret != 0)
             return vk_error(VK_ERROR_UNKNOWN);
 
@@ -752,8 +752,8 @@ VkResult anv_QueueSubmit(
                return vk_error(VK_ERROR_UNKNOWN);
          }
 
-         for (uint32_t i = 0; i < cmd_buffer->exec2_bo_count; i++)
-            cmd_buffer->exec2_bos[i]->offset = cmd_buffer->exec2_objects[i].offset;
+         for (uint32_t i = 0; i < cmd_buffer->execbuf2.bo_count; i++)
+            cmd_buffer->execbuf2.bos[i]->offset = cmd_buffer->execbuf2.objects[i].offset;
       } else {
          *(uint32_t *)queue->completed_serial.map = cmd_buffer->serial;
       }
index f8def1108cb5224ccbff7a6cf5b162eb02664bfe..3d364ef30d4061f6f87d404241dabeb96aaab731 100644 (file)
@@ -706,12 +706,20 @@ struct anv_cmd_buffer {
    /* Information needed for execbuf that's generated when the command
     * buffer is ended.
     */
-   struct drm_i915_gem_execbuffer2              execbuf;
-   struct drm_i915_gem_exec_object2 *           exec2_objects;
-   uint32_t                                     exec2_bo_count;
-   struct anv_bo **                             exec2_bos;
-   uint32_t                                     exec2_array_length;
-   bool                                         need_reloc;
+   struct {
+      struct drm_i915_gem_execbuffer2           execbuf;
+
+      struct drm_i915_gem_exec_object2 *        objects;
+      uint32_t                                  bo_count;
+      struct anv_bo **                          bos;
+
+      /* Allocated length of the 'objects' and 'bos' arrays */
+      uint32_t                                  array_length;
+
+      bool                                      need_reloc;
+   } execbuf2;
+
+   /* Serial for tracking buffer completion */
    uint32_t                                     serial;
 
    /* Stream objects for storing temporary data */
@@ -725,7 +733,7 @@ VkResult anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
 void anv_cmd_buffer_emit_batch_buffer_end(struct anv_cmd_buffer *cmd_buffer);
-void anv_cmd_buffer_compute_validate_list(struct anv_cmd_buffer *cmd_buffer);
+void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer *cmd_buffer);
 
 struct anv_state
 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer *cmd_buffer,