The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

comp/vk: Guard VkCommandBuffer usage with command pool mutex.

Lock all queue submits with 2 mutexes using a new vk_locked_submit
function.

+36 -13
+23 -3
src/xrt/auxiliary/vk/vk_helpers.c
··· 575 575 VkCommandBufferBeginInfo begin_info = { 576 576 .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, 577 577 }; 578 + 579 + os_mutex_lock(&vk->cmd_pool_mutex); 578 580 ret = vk->vkBeginCommandBuffer(cmd_buffer, &begin_info); 581 + os_mutex_unlock(&vk->cmd_pool_mutex); 582 + 579 583 if (ret != VK_SUCCESS) { 580 584 VK_ERROR(vk, "vkBeginCommandBuffer: %s", vk_result_string(ret)); 581 585 goto err_buffer; ··· 636 640 }; 637 641 638 642 // Finish the command buffer first. 643 + os_mutex_lock(&vk->cmd_pool_mutex); 639 644 ret = vk->vkEndCommandBuffer(cmd_buffer); 645 + os_mutex_unlock(&vk->cmd_pool_mutex); 640 646 if (ret != VK_SUCCESS) { 641 647 VK_ERROR(vk, "vkEndCommandBuffer: %s", vk_result_string(ret)); 642 648 goto out; ··· 650 656 } 651 657 652 658 // Do the actual submitting. 653 - os_mutex_lock(&vk->queue_mutex); 654 - ret = vk->vkQueueSubmit(vk->queue, 1, &submitInfo, fence); 655 - os_mutex_unlock(&vk->queue_mutex); 659 + ret = vk_locked_submit(vk, vk->queue, 1, &submitInfo, fence); 656 660 if (ret != VK_SUCCESS) { 657 661 VK_ERROR(vk, "Error: Could not submit to queue.\n"); 658 662 goto out_fence; ··· 1499 1503 1500 1504 return true; 1501 1505 } 1506 + 1507 + VkResult 1508 + vk_locked_submit(struct vk_bundle *vk, 1509 + VkQueue queue, 1510 + uint32_t count, 1511 + const VkSubmitInfo *infos, 1512 + VkFence fence) 1513 + { 1514 + VkResult ret; 1515 + os_mutex_lock(&vk->queue_mutex); 1516 + os_mutex_lock(&vk->cmd_pool_mutex); 1517 + ret = vk->vkQueueSubmit(queue, count, infos, fence); 1518 + os_mutex_unlock(&vk->cmd_pool_mutex); 1519 + os_mutex_unlock(&vk->queue_mutex); 1520 + return ret; 1521 + }
+7
src/xrt/auxiliary/vk/vk_helpers.h
··· 499 499 size_t buffer_size, 500 500 VkDeviceMemory memory); 501 501 502 + VkResult 503 + vk_locked_submit(struct vk_bundle *vk, 504 + VkQueue queue, 505 + uint32_t count, 506 + const VkSubmitInfo *infos, 507 + VkFence fence); 508 + 502 509 #ifdef __cplusplus 503 510 } 504 511 #endif
+2 -6
src/xrt/compositor/client/comp_vk_client.c
··· 90 90 .pCommandBuffers = &sc->acquire[*out_index], 91 91 }; 92 92 93 - os_mutex_lock(&vk->queue_mutex); 94 93 VkResult ret = 95 - vk->vkQueueSubmit(vk->queue, 1, &submitInfo, VK_NULL_HANDLE); 96 - os_mutex_unlock(&vk->queue_mutex); 94 + vk_locked_submit(vk, vk->queue, 1, &submitInfo, VK_NULL_HANDLE); 97 95 if (ret != VK_SUCCESS) { 98 96 VK_ERROR(vk, "Could not submit to queue: %d", ret); 99 97 return XRT_ERROR_FAILED_TO_SUBMIT_VULKAN_COMMANDS; ··· 125 123 .pCommandBuffers = &sc->release[index], 126 124 }; 127 125 128 - os_mutex_lock(&vk->queue_mutex); 129 126 VkResult ret = 130 - vk->vkQueueSubmit(vk->queue, 1, &submitInfo, VK_NULL_HANDLE); 131 - os_mutex_unlock(&vk->queue_mutex); 127 + vk_locked_submit(vk, vk->queue, 1, &submitInfo, VK_NULL_HANDLE); 132 128 if (ret != VK_SUCCESS) { 133 129 VK_ERROR(vk, "Could not submit to queue: %d", ret); 134 130 return XRT_ERROR_FAILED_TO_SUBMIT_VULKAN_COMMANDS;
+2
src/xrt/compositor/main/comp_layer_renderer.c
··· 662 662 if (vk_init_cmd_buffer(vk, &cmd_buffer) != VK_SUCCESS) 663 663 return; 664 664 665 + os_mutex_lock(&vk->cmd_pool_mutex); 665 666 _render_stereo(self, vk, cmd_buffer); 667 + os_mutex_unlock(&vk->cmd_pool_mutex); 666 668 667 669 VkResult res = vk_submit_cmd_buffer(vk, cmd_buffer); 668 670 vk_check_error("vk_submit_cmd_buffer", res, );
+2 -4
src/xrt/compositor/main/comp_renderer.c
··· 173 173 .pSignalSemaphores = &r->semaphores.render_complete, 174 174 }; 175 175 176 - os_mutex_lock(&vk->queue_mutex); 177 - ret = vk->vkQueueSubmit(r->queue, 1, &comp_submit_info, 178 - r->fences[r->current_buffer]); 179 - os_mutex_unlock(&vk->queue_mutex); 176 + ret = vk_locked_submit(vk, r->queue, 1, &comp_submit_info, 177 + r->fences[r->current_buffer]); 180 178 if (ret != VK_SUCCESS) { 181 179 COMP_ERROR(r->c, "vkQueueSubmit: %s", vk_result_string(ret)); 182 180 }