The open source OpenXR runtime
0
fork

Configure Feed

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

comp/vk: Lock command pool calls with a mutex.

This patch resolves multithreading issues as detected by the Vulkan
validation when running the OpenXR CTS using OpenGL.

+20
+7
src/xrt/auxiliary/vk/vk_helpers.c
··· 557 557 .commandBufferCount = 1, 558 558 }; 559 559 560 + os_mutex_lock(&vk->cmd_pool_mutex); 561 + 560 562 ret = vk->vkAllocateCommandBuffers(vk->device, &cmd_buffer_info, 561 563 &cmd_buffer); 564 + 565 + os_mutex_unlock(&vk->cmd_pool_mutex); 566 + 562 567 if (ret != VK_SUCCESS) { 563 568 VK_ERROR(vk, "vkAllocateCommandBuffers: %s", 564 569 vk_result_string(ret)); ··· 665 670 out_fence: 666 671 vk->vkDestroyFence(vk->device, fence, NULL); 667 672 out: 673 + os_mutex_lock(&vk->cmd_pool_mutex); 668 674 vk->vkFreeCommandBuffers(vk->device, vk->cmd_pool, 1, &cmd_buffer); 675 + os_mutex_unlock(&vk->cmd_pool_mutex); 669 676 670 677 return ret; 671 678 }
+2
src/xrt/auxiliary/vk/vk_helpers.h
··· 56 56 57 57 VkCommandPool cmd_pool; 58 58 59 + struct os_mutex cmd_pool_mutex; 60 + 59 61 // clang-format off 60 62 // Loader functions 61 63 PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
+5
src/xrt/compositor/main/comp_compositor.c
··· 118 118 } 119 119 120 120 os_mutex_destroy(&vk->queue_mutex); 121 + os_mutex_destroy(&vk->cmd_pool_mutex); 121 122 122 123 if (vk->instance != VK_NULL_HANDLE) { 123 124 vk->vkDestroyInstance(vk->instance, NULL); ··· 936 937 ARRAY_SIZE(optional_device_extensions)); 937 938 938 939 if (os_mutex_init(&c->vk.queue_mutex) != 0) { 940 + return false; 941 + } 942 + 943 + if (os_mutex_init(&c->vk.cmd_pool_mutex) != 0) { 939 944 return false; 940 945 } 941 946
+6
src/xrt/compositor/render/comp_rendering.c
··· 216 216 }; 217 217 218 218 VkCommandBuffer cmd = VK_NULL_HANDLE; 219 + 220 + os_mutex_lock(&vk->cmd_pool_mutex); 221 + 219 222 ret = vk->vkAllocateCommandBuffers(vk->device, // 220 223 &cmd_buffer_info, // 221 224 &cmd); // 225 + 226 + os_mutex_unlock(&vk->cmd_pool_mutex); 227 + 222 228 if (ret != VK_SUCCESS) { 223 229 VK_ERROR(vk, "vkCreateFramebuffer failed: %s", 224 230 vk_result_string(ret));