diff --git a/src/xrt/auxiliary/vk/vk_helpers.c b/src/xrt/auxiliary/vk/vk_helpers.c index 4eda0332d..5a975a3b9 100644 --- a/src/xrt/auxiliary/vk/vk_helpers.c +++ b/src/xrt/auxiliary/vk/vk_helpers.c @@ -557,8 +557,13 @@ vk_init_cmd_buffer(struct vk_bundle *vk, VkCommandBuffer *out_cmd_buffer) .commandBufferCount = 1, }; + os_mutex_lock(&vk->cmd_pool_mutex); + ret = vk->vkAllocateCommandBuffers(vk->device, &cmd_buffer_info, &cmd_buffer); + + os_mutex_unlock(&vk->cmd_pool_mutex); + if (ret != VK_SUCCESS) { VK_ERROR(vk, "vkAllocateCommandBuffers: %s", vk_result_string(ret)); @@ -665,7 +670,9 @@ vk_submit_cmd_buffer(struct vk_bundle *vk, VkCommandBuffer cmd_buffer) out_fence: vk->vkDestroyFence(vk->device, fence, NULL); out: + os_mutex_lock(&vk->cmd_pool_mutex); vk->vkFreeCommandBuffers(vk->device, vk->cmd_pool, 1, &cmd_buffer); + os_mutex_unlock(&vk->cmd_pool_mutex); return ret; } diff --git a/src/xrt/auxiliary/vk/vk_helpers.h b/src/xrt/auxiliary/vk/vk_helpers.h index 28d65199e..dfa30f76c 100644 --- a/src/xrt/auxiliary/vk/vk_helpers.h +++ b/src/xrt/auxiliary/vk/vk_helpers.h @@ -56,6 +56,8 @@ struct vk_bundle VkCommandPool cmd_pool; + struct os_mutex cmd_pool_mutex; + // clang-format off // Loader functions PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr; diff --git a/src/xrt/compositor/main/comp_compositor.c b/src/xrt/compositor/main/comp_compositor.c index 916a03bdc..f561973e3 100644 --- a/src/xrt/compositor/main/comp_compositor.c +++ b/src/xrt/compositor/main/comp_compositor.c @@ -118,6 +118,7 @@ compositor_destroy(struct xrt_compositor *xc) } os_mutex_destroy(&vk->queue_mutex); + os_mutex_destroy(&vk->cmd_pool_mutex); if (vk->instance != VK_NULL_HANDLE) { vk->vkDestroyInstance(vk->instance, NULL); @@ -939,6 +940,10 @@ compositor_init_vulkan(struct comp_compositor *c) return false; } + if (os_mutex_init(&c->vk.cmd_pool_mutex) != 0) { + return false; + } + if (ret != VK_SUCCESS) { return false; } diff --git a/src/xrt/compositor/render/comp_rendering.c b/src/xrt/compositor/render/comp_rendering.c index 26ea7d96d..badf0a22b 100644 --- a/src/xrt/compositor/render/comp_rendering.c +++ b/src/xrt/compositor/render/comp_rendering.c @@ -216,9 +216,15 @@ create_command_buffer(struct vk_bundle *vk, VkCommandBuffer *out_cmd) }; VkCommandBuffer cmd = VK_NULL_HANDLE; + + os_mutex_lock(&vk->cmd_pool_mutex); + ret = vk->vkAllocateCommandBuffers(vk->device, // &cmd_buffer_info, // &cmd); // + + os_mutex_unlock(&vk->cmd_pool_mutex); + if (ret != VK_SUCCESS) { VK_ERROR(vk, "vkCreateFramebuffer failed: %s", vk_result_string(ret));