The open source OpenXR runtime
0
fork

Configure Feed

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

comp: Guard acquire/release with a fence

Fixes validation warning when acquiring images before the command buffer
of the previous acquire or release on the same queue has finished.

VUID-vkQueueSubmit-pCommandBuffers-00071(ERROR / SPEC): msgNum: 774851941 - Validation Error: [ VUID-vkQueueSubmit-pCommandBuffers-00071 ] Object 0: handle = 0x558634c5c750, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x2e2f4d65 | vkQueueSubmit(): pSubmits[0].pCommandBuffers[0] VkCommandBuffer 0x558634b85a10[] is already in use and is not marked for simultaneous use. The Vulkan spec states: If any element of the pCommandBuffers member of any element of pSubmits was not recorded with the VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, it must not be in the pending state (https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VUID-vkQueueSubmit-pCommandBuffers-00071)
Objects: 1
[0] 0x558634c5c750, type: 3, name: NULL

+27 -2
+26 -2
src/xrt/compositor/client/comp_vk_client.c
··· 16 16 #include <stdlib.h> 17 17 #include <assert.h> 18 18 19 + #define MS_TO_NS(ms) (ms * 1000L * 1000L) 20 + 19 21 /*! 20 22 * Down-cast helper. 21 23 * ··· 81 83 return xret; 82 84 } 83 85 86 + VkResult ret; 87 + 88 + ret = vk->vkWaitForFences(vk->device, 1, &sc->acquire_release_fence[*out_index], true, MS_TO_NS(500)); 89 + vk_check_error("vkWaitForFences", ret, XRT_ERROR_VULKAN); 90 + 91 + ret = vk->vkResetFences(vk->device, 1, &sc->acquire_release_fence[*out_index]); 92 + vk_check_error("vkResetFences", ret, XRT_ERROR_VULKAN); 93 + 84 94 // Acquire ownership and complete layout transition 85 95 VkSubmitInfo submitInfo = { 86 96 .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, ··· 88 98 .pCommandBuffers = &sc->acquire[*out_index], 89 99 }; 90 100 91 - VkResult ret = vk_locked_submit(vk, vk->queue, 1, &submitInfo, VK_NULL_HANDLE); 101 + ret = vk_locked_submit(vk, vk->queue, 1, &submitInfo, sc->acquire_release_fence[*out_index]); 92 102 if (ret != VK_SUCCESS) { 93 103 VK_ERROR(vk, "Could not submit to queue: %d", ret); 94 104 return XRT_ERROR_FAILED_TO_SUBMIT_VULKAN_COMMANDS; ··· 112 122 struct client_vk_swapchain *sc = client_vk_swapchain(xsc); 113 123 struct vk_bundle *vk = &sc->c->vk; 114 124 125 + VkResult ret; 126 + 127 + ret = vk->vkWaitForFences(vk->device, 1, &sc->acquire_release_fence[index], true, MS_TO_NS(500)); 128 + vk_check_error("vkWaitForFences", ret, XRT_ERROR_VULKAN); 129 + 130 + vk->vkResetFences(vk->device, 1, &sc->acquire_release_fence[index]); 131 + vk_check_error("vkResetFences", ret, XRT_ERROR_VULKAN); 132 + 115 133 // Release ownership and begin layout transition 116 134 VkSubmitInfo submitInfo = { 117 135 .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, ··· 119 137 .pCommandBuffers = &sc->release[index], 120 138 }; 121 139 122 - VkResult ret = vk_locked_submit(vk, vk->queue, 1, &submitInfo, VK_NULL_HANDLE); 140 + ret = vk_locked_submit(vk, vk->queue, 1, &submitInfo, sc->acquire_release_fence[index]); 123 141 if (ret != VK_SUCCESS) { 124 142 VK_ERROR(vk, "Could not submit to queue: %d", ret); 125 143 return XRT_ERROR_FAILED_TO_SUBMIT_VULKAN_COMMANDS; ··· 499 517 VK_ERROR(vk, "vkEndCommandBuffer: %s", vk_result_string(ret)); 500 518 return XRT_ERROR_VULKAN; 501 519 } 520 + 521 + VkFenceCreateInfo fence_create_info = { 522 + .sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, 523 + .flags = VK_FENCE_CREATE_SIGNALED_BIT, 524 + }; 525 + vk->vkCreateFence(vk->device, &fence_create_info, NULL, &sc->acquire_release_fence[i]); 502 526 } 503 527 504 528 *out_xsc = &sc->base.base;
+1
src/xrt/compositor/client/comp_vk_client.h
··· 50 50 // Prerecorded swapchain image ownership/layout transition barriers 51 51 VkCommandBuffer acquire[XRT_MAX_SWAPCHAIN_IMAGES]; 52 52 VkCommandBuffer release[XRT_MAX_SWAPCHAIN_IMAGES]; 53 + VkFence acquire_release_fence[XRT_MAX_SWAPCHAIN_IMAGES]; 53 54 }; 54 55 55 56 /*!