vk/cmd_buffer: Add a simple command pool implementation
authorJason Ekstrand <jason.ekstrand@intel.com>
Thu, 30 Jul 2015 21:55:49 +0000 (14:55 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Thu, 30 Jul 2015 21:55:49 +0000 (14:55 -0700)
src/vulkan/anv_cmd_emit.c
src/vulkan/anv_device.c
src/vulkan/anv_private.h

index 64acec82154946e7b77e287e412ac0286c78249d..3b9e67fdd0f375ca0815e1096f23d2e675148539 100644 (file)
@@ -63,6 +63,7 @@ VkResult anv_CreateCommandBuffer(
     VkCmdBuffer*                                pCmdBuffer)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
+   ANV_FROM_HANDLE(anv_cmd_pool, pool, pCreateInfo->cmdPool);
    struct anv_cmd_buffer *cmd_buffer;
    VkResult result;
 
@@ -87,6 +88,8 @@ VkResult anv_CreateCommandBuffer(
 
    anv_cmd_state_init(&cmd_buffer->state);
 
+   list_addtail(&cmd_buffer->pool_link, &pool->cmd_buffers);
+
    *pCmdBuffer = anv_cmd_buffer_to_handle(cmd_buffer);
 
    return VK_SUCCESS;
@@ -103,6 +106,8 @@ VkResult anv_DestroyCommandBuffer(
    ANV_FROM_HANDLE(anv_device, device, _device);
    ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, _cmd_buffer);
 
+   list_del(&cmd_buffer->pool_link);
+
    anv_cmd_buffer_fini_batch_bo_chain(cmd_buffer);
 
    anv_state_stream_finish(&cmd_buffer->surface_state_stream);
@@ -1369,3 +1374,52 @@ void anv_CmdExecuteCommands(
       anv_cmd_buffer_add_secondary(primary, secondary);
    }
 }
+
+VkResult anv_CreateCommandPool(
+    VkDevice                                    _device,
+    const VkCmdPoolCreateInfo*                  pCreateInfo,
+    VkCmdPool*                                  pCmdPool)
+{
+   ANV_FROM_HANDLE(anv_device, device, _device);
+   struct anv_cmd_pool *pool;
+
+   pool = anv_device_alloc(device, sizeof(*pool), 8,
+                           VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
+   if (pool == NULL)
+      return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
+
+   list_inithead(&pool->cmd_buffers);
+
+   *pCmdPool = anv_cmd_pool_to_handle(pool);
+
+   return VK_SUCCESS;
+}
+
+VkResult anv_DestroyCommandPool(
+    VkDevice                                    _device,
+    VkCmdPool                                   cmdPool)
+{
+   ANV_FROM_HANDLE(anv_device, device, _device);
+   ANV_FROM_HANDLE(anv_cmd_pool, pool, cmdPool);
+
+   anv_ResetCommandPool(_device, cmdPool, 0);
+
+   anv_device_free(device, pool);
+
+   return VK_SUCCESS;
+}
+
+VkResult anv_ResetCommandPool(
+    VkDevice                                    device,
+    VkCmdPool                                   cmdPool,
+    VkCmdPoolResetFlags                         flags)
+{
+   ANV_FROM_HANDLE(anv_cmd_pool, pool, cmdPool);
+
+   list_for_each_entry_safe(struct anv_cmd_buffer, cmd_buffer,
+                            &pool->cmd_buffers, pool_link) {
+      anv_DestroyCommandBuffer(device, anv_cmd_buffer_to_handle(cmd_buffer));
+   }
+
+   return VK_SUCCESS;
+}
index 46e2d9b6d1bce75f630208e84a477ada89717579..01eff02d25d1f153451cc457c7ac39cf6356cbae 100644 (file)
@@ -2170,33 +2170,6 @@ VkResult anv_DestroyDynamicDepthStencilState(
    return VK_SUCCESS;
 }
 
-// Command buffer functions
-
-VkResult anv_CreateCommandPool(
-    VkDevice                                    device,
-    const VkCmdPoolCreateInfo*                  pCreateInfo,
-    VkCmdPool*                                  pCmdPool)
-{
-   pCmdPool->handle = 7;
-
-   stub_return(VK_SUCCESS);
-}
-
-VkResult anv_DestroyCommandPool(
-    VkDevice                                    device,
-    VkCmdPool                                   cmdPool)
-{
-   stub_return(VK_SUCCESS);
-}
-
-VkResult anv_ResetCommandPool(
-    VkDevice                                    device,
-    VkCmdPool                                   cmdPool,
-    VkCmdPoolResetFlags                         flags)
-{
-   stub_return(VK_UNSUPPORTED);
-}
-
 VkResult anv_CreateFramebuffer(
     VkDevice                                    _device,
     const VkFramebufferCreateInfo*              pCreateInfo,
index d2b4b70e97fd128d1ca8d096f0c379e50a113bca..12f826c1ab192a63a75b804b596429cda8b88250 100644 (file)
@@ -690,6 +690,10 @@ struct anv_cmd_state {
    struct anv_descriptor_set_binding            descriptors[MAX_SETS];
 };
 
+struct anv_cmd_pool {
+   struct list_head                             cmd_buffers;
+};
+
 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
 
 enum anv_cmd_buffer_exec_mode {
@@ -702,6 +706,8 @@ enum anv_cmd_buffer_exec_mode {
 struct anv_cmd_buffer {
    struct anv_device *                          device;
 
+   struct list_head                             pool_link;
+
    struct anv_batch                             batch;
 
    /* Fields required for the actual chain of anv_batch_bo's.
@@ -1088,6 +1094,7 @@ ANV_DEFINE_HANDLE_CASTS(anv_physical_device, VkPhysicalDevice)
 ANV_DEFINE_HANDLE_CASTS(anv_queue, VkQueue)
 ANV_DEFINE_HANDLE_CASTS(anv_swap_chain, VkSwapChainWSI);
 
+ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool, VkCmdPool)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_attachment_view, VkAttachmentView)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer, VkBuffer)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view, VkBufferView);