vk/cmd_buffer: Factor the guts of CmdBufferEnd into two helpers
authorJason Ekstrand <jason.ekstrand@intel.com>
Mon, 27 Jul 2015 21:52:16 +0000 (14:52 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Mon, 27 Jul 2015 21:52:16 +0000 (14:52 -0700)
src/vulkan/anv_cmd_buffer.c
src/vulkan/anv_private.h

index 085878bd69d8e90f50645fd436e7ac574f585e2b..f7d6990157b6bfaa580882bd18a163841d14cf46 100644 (file)
@@ -650,26 +650,25 @@ anv_cmd_buffer_process_relocs(struct anv_cmd_buffer *cmd_buffer,
    }
 }
 
-VkResult anv_EndCommandBuffer(
-    VkCmdBuffer                                 cmdBuffer)
+void
+anv_cmd_buffer_emit_batch_buffer_end(struct anv_cmd_buffer *cmd_buffer)
 {
-   ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
-   struct anv_device *device = cmd_buffer->device;
-   struct anv_batch *batch = &cmd_buffer->batch;
-
-   anv_batch_emit(batch, GEN8_MI_BATCH_BUFFER_END);
+   anv_batch_emit(&cmd_buffer->batch, GEN8_MI_BATCH_BUFFER_END);
 
    anv_batch_bo_finish(cmd_buffer->last_batch_bo, &cmd_buffer->batch);
    cmd_buffer->surface_batch_bo->num_relocs =
       cmd_buffer->surface_relocs.num_relocs - cmd_buffer->surface_batch_bo->first_reloc;
    cmd_buffer->surface_batch_bo->length = cmd_buffer->surface_next;
+}
+
+void
+anv_cmd_buffer_compute_validate_list(struct anv_cmd_buffer *cmd_buffer)
+{
+   struct anv_batch *batch = &cmd_buffer->batch;
 
    cmd_buffer->exec2_bo_count = 0;
    cmd_buffer->need_reloc = false;
 
-   /* Lock for access to bo->index. */
-   pthread_mutex_lock(&device->mutex);
-
    /* Add surface state bos first so we can add them with their relocs. */
    for (struct anv_batch_bo *bbo = cmd_buffer->surface_batch_bo;
         bbo != NULL; bbo = bbo->prev_batch_bo) {
@@ -716,9 +715,24 @@ VkResult anv_EndCommandBuffer(
    if (!cmd_buffer->need_reloc)
       cmd_buffer->execbuf.flags |= I915_EXEC_NO_RELOC;
    cmd_buffer->execbuf.flags |= I915_EXEC_RENDER;
-   cmd_buffer->execbuf.rsvd1 = device->context_id;
+   cmd_buffer->execbuf.rsvd1 = cmd_buffer->device->context_id;
    cmd_buffer->execbuf.rsvd2 = 0;
+}
+
+VkResult anv_EndCommandBuffer(
+    VkCmdBuffer                                 cmdBuffer)
+{
+   ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
+   struct anv_device *device = cmd_buffer->device;
 
+   anv_cmd_buffer_emit_batch_buffer_end(cmd_buffer);
+
+   /* The algorithm used to compute the validate list is not threadsafe as
+    * it uses the bo->index field.  We have to lock the device around it.
+    * Fortunately, the chances for contention here are probably very low.
+    */
+   pthread_mutex_lock(&device->mutex);
+   anv_cmd_buffer_compute_validate_list(cmd_buffer);
    pthread_mutex_unlock(&device->mutex);
 
    return VK_SUCCESS;
index 1fc84e41d360ad5a88f80d525963fbffba4ecf9f..1ddc2722ceaa4cc0fd3e1d5d419a0b53667b98e8 100644 (file)
@@ -727,6 +727,8 @@ struct anv_cmd_buffer {
 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);
 
 struct anv_state
 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer *cmd_buffer,