mirror of
https://github.com/lbgos/rift-s-linux.git
synced 2026-10-24 10:01:57 +02:00
comp/vk: Guard VkCommandBuffer usage with command pool mutex.
Lock all queue submits with 2 mutexes using a new vk_locked_submit function.
This commit is contained in:
1 parent
6455b1b829
commit
b005f4e2fa
5 files changed
+36
-13
No files matched your search
@@ -575,7 +575,11 @@ vk_init_cmd_buffer(struct vk_bundle *vk, VkCommandBuffer *out_cmd_buffer)
|
||||
VkCommandBufferBeginInfo begin_info = {
|
||||
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||
};
|
||||
|
||||
os_mutex_lock(&vk->cmd_pool_mutex);
|
||||
ret = vk->vkBeginCommandBuffer(cmd_buffer, &begin_info);
|
||||
os_mutex_unlock(&vk->cmd_pool_mutex);
|
||||
|
||||
if (ret != VK_SUCCESS) {
|
||||
VK_ERROR(vk, "vkBeginCommandBuffer: %s", vk_result_string(ret));
|
||||
goto err_buffer;
|
||||
@@ -636,7 +640,9 @@ vk_submit_cmd_buffer(struct vk_bundle *vk, VkCommandBuffer cmd_buffer)
|
||||
};
|
||||
|
||||
// Finish the command buffer first.
|
||||
os_mutex_lock(&vk->cmd_pool_mutex);
|
||||
ret = vk->vkEndCommandBuffer(cmd_buffer);
|
||||
os_mutex_unlock(&vk->cmd_pool_mutex);
|
||||
if (ret != VK_SUCCESS) {
|
||||
VK_ERROR(vk, "vkEndCommandBuffer: %s", vk_result_string(ret));
|
||||
goto out;
|
||||
@@ -650,9 +656,7 @@ vk_submit_cmd_buffer(struct vk_bundle *vk, VkCommandBuffer cmd_buffer)
|
||||
}
|
||||
|
||||
// Do the actual submitting.
|
||||
os_mutex_lock(&vk->queue_mutex);
|
||||
ret = vk->vkQueueSubmit(vk->queue, 1, &submitInfo, fence);
|
||||
os_mutex_unlock(&vk->queue_mutex);
|
||||
ret = vk_locked_submit(vk, vk->queue, 1, &submitInfo, fence);
|
||||
if (ret != VK_SUCCESS) {
|
||||
VK_ERROR(vk, "Error: Could not submit to queue.\n");
|
||||
goto out_fence;
|
||||
@@ -1499,3 +1503,19 @@ vk_update_buffer(struct vk_bundle *vk,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
VkResult
|
||||
vk_locked_submit(struct vk_bundle *vk,
|
||||
VkQueue queue,
|
||||
uint32_t count,
|
||||
const VkSubmitInfo *infos,
|
||||
VkFence fence)
|
||||
{
|
||||
VkResult ret;
|
||||
os_mutex_lock(&vk->queue_mutex);
|
||||
os_mutex_lock(&vk->cmd_pool_mutex);
|
||||
ret = vk->vkQueueSubmit(queue, count, infos, fence);
|
||||
os_mutex_unlock(&vk->cmd_pool_mutex);
|
||||
os_mutex_unlock(&vk->queue_mutex);
|
||||
return ret;
|
||||
}
|
||||
@@ -499,6 +499,13 @@ vk_update_buffer(struct vk_bundle *vk,
|
||||
size_t buffer_size,
|
||||
VkDeviceMemory memory);
|
||||
|
||||
VkResult
|
||||
vk_locked_submit(struct vk_bundle *vk,
|
||||
VkQueue queue,
|
||||
uint32_t count,
|
||||
const VkSubmitInfo *infos,
|
||||
VkFence fence);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -90,10 +90,8 @@ client_vk_swapchain_acquire_image(struct xrt_swapchain *xsc,
|
||||
.pCommandBuffers = &sc->acquire[*out_index],
|
||||
};
|
||||
|
||||
os_mutex_lock(&vk->queue_mutex);
|
||||
VkResult ret =
|
||||
vk->vkQueueSubmit(vk->queue, 1, &submitInfo, VK_NULL_HANDLE);
|
||||
os_mutex_unlock(&vk->queue_mutex);
|
||||
vk_locked_submit(vk, vk->queue, 1, &submitInfo, VK_NULL_HANDLE);
|
||||
if (ret != VK_SUCCESS) {
|
||||
VK_ERROR(vk, "Could not submit to queue: %d", ret);
|
||||
return XRT_ERROR_FAILED_TO_SUBMIT_VULKAN_COMMANDS;
|
||||
@@ -125,10 +123,8 @@ client_vk_swapchain_release_image(struct xrt_swapchain *xsc, uint32_t index)
|
||||
.pCommandBuffers = &sc->release[index],
|
||||
};
|
||||
|
||||
os_mutex_lock(&vk->queue_mutex);
|
||||
VkResult ret =
|
||||
vk->vkQueueSubmit(vk->queue, 1, &submitInfo, VK_NULL_HANDLE);
|
||||
os_mutex_unlock(&vk->queue_mutex);
|
||||
vk_locked_submit(vk, vk->queue, 1, &submitInfo, VK_NULL_HANDLE);
|
||||
if (ret != VK_SUCCESS) {
|
||||
VK_ERROR(vk, "Could not submit to queue: %d", ret);
|
||||
return XRT_ERROR_FAILED_TO_SUBMIT_VULKAN_COMMANDS;
|
||||
|
||||
@@ -662,7 +662,9 @@ comp_layer_renderer_draw(struct comp_layer_renderer *self)
|
||||
if (vk_init_cmd_buffer(vk, &cmd_buffer) != VK_SUCCESS)
|
||||
return;
|
||||
|
||||
os_mutex_lock(&vk->cmd_pool_mutex);
|
||||
_render_stereo(self, vk, cmd_buffer);
|
||||
os_mutex_unlock(&vk->cmd_pool_mutex);
|
||||
|
||||
VkResult res = vk_submit_cmd_buffer(vk, cmd_buffer);
|
||||
vk_check_error("vk_submit_cmd_buffer", res, );
|
||||
|
||||
@@ -173,10 +173,8 @@ renderer_submit_queue(struct comp_renderer *r)
|
||||
.pSignalSemaphores = &r->semaphores.render_complete,
|
||||
};
|
||||
|
||||
os_mutex_lock(&vk->queue_mutex);
|
||||
ret = vk->vkQueueSubmit(r->queue, 1, &comp_submit_info,
|
||||
r->fences[r->current_buffer]);
|
||||
os_mutex_unlock(&vk->queue_mutex);
|
||||
ret = vk_locked_submit(vk, r->queue, 1, &comp_submit_info,
|
||||
r->fences[r->current_buffer]);
|
||||
if (ret != VK_SUCCESS) {
|
||||
COMP_ERROR(r->c, "vkQueueSubmit: %s", vk_result_string(ret));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user