The open source OpenXR runtime

a/vk: refactor vk_cmd(_pool) utils to support different queue (families)

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2572>

+54 -15
+8 -4
src/xrt/auxiliary/vk/vk_cmd.c
··· 78 78 } 79 79 80 80 XRT_CHECK_RESULT VkResult 81 - vk_cmd_submit_locked(struct vk_bundle *vk, uint32_t count, const VkSubmitInfo *infos, VkFence fence) 81 + vk_cmd_submit_locked( 82 + struct vk_bundle *vk, struct vk_bundle_queue *queue, uint32_t count, const VkSubmitInfo *infos, VkFence fence) 82 83 { 83 84 VkResult ret; 84 85 85 86 os_mutex_lock(&vk->queue_mutex); 86 - ret = vk->vkQueueSubmit(vk->main_queue.queue, count, infos, fence); 87 + ret = vk->vkQueueSubmit(queue->queue, count, infos, fence); 87 88 os_mutex_unlock(&vk->queue_mutex); 88 89 89 90 if (ret != VK_SUCCESS) { ··· 94 95 } 95 96 96 97 XRT_CHECK_RESULT VkResult 97 - vk_cmd_end_submit_wait_and_free_cmd_buffer_locked(struct vk_bundle *vk, VkCommandPool pool, VkCommandBuffer cmd_buffer) 98 + vk_cmd_end_submit_wait_and_free_cmd_buffer_locked(struct vk_bundle *vk, 99 + struct vk_bundle_queue *queue, 100 + VkCommandPool pool, 101 + VkCommandBuffer cmd_buffer) 98 102 { 99 103 VkFence fence; 100 104 VkResult ret; ··· 129 133 .pCommandBuffers = &cmd_buffer, 130 134 }; 131 135 132 - ret = vk_cmd_submit_locked(vk, 1, &submitInfo, fence); 136 + ret = vk_cmd_submit_locked(vk, queue, 1, &submitInfo, fence); 133 137 if (ret != VK_SUCCESS) { 134 138 VK_ERROR(vk, "vk_cmd_pool_submit_locked: %s", vk_result_string(ret)); 135 139 goto out_fence;
+6 -2
src/xrt/auxiliary/vk/vk_cmd.h
··· 167 167 * @ingroup aux_vk 168 168 */ 169 169 XRT_CHECK_RESULT VkResult 170 - vk_cmd_submit_locked(struct vk_bundle *vk, uint32_t count, const VkSubmitInfo *infos, VkFence fence); 170 + vk_cmd_submit_locked( 171 + struct vk_bundle *vk, struct vk_bundle_queue *queue, uint32_t count, const VkSubmitInfo *infos, VkFence fence); 171 172 172 173 /*! 173 174 * A do everything command buffer submission function, the `_locked` suffix ··· 189 190 * @ingroup aux_vk 190 191 */ 191 192 XRT_CHECK_RESULT VkResult 192 - vk_cmd_end_submit_wait_and_free_cmd_buffer_locked(struct vk_bundle *vk, VkCommandPool pool, VkCommandBuffer cmd_buffer); 193 + vk_cmd_end_submit_wait_and_free_cmd_buffer_locked(struct vk_bundle *vk, 194 + struct vk_bundle_queue *queue, 195 + VkCommandPool pool, 196 + VkCommandBuffer cmd_buffer); 193 197 194 198 195 199 /*
+9 -3
src/xrt/auxiliary/vk/vk_cmd_pool.c
··· 19 19 */ 20 20 21 21 XRT_CHECK_RESULT VkResult 22 - vk_cmd_pool_init(struct vk_bundle *vk, struct vk_cmd_pool *pool, VkCommandPoolCreateFlags flags) 22 + vk_cmd_pool_init_for_queue(struct vk_bundle *vk, 23 + struct vk_cmd_pool *pool, 24 + VkCommandPoolCreateFlags flags, 25 + struct vk_bundle_queue *queue) 23 26 { 24 27 VkResult ret; 28 + assert(queue); 25 29 26 30 XRT_MAYBE_UNUSED int iret = os_mutex_init(&pool->mutex); 27 31 assert(iret == 0); ··· 29 33 VkCommandPoolCreateInfo cmd_pool_info = { 30 34 .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, 31 35 .flags = flags, 32 - .queueFamilyIndex = vk->main_queue.family_index, 36 + .queueFamilyIndex = queue->family_index, 33 37 }; 34 38 35 39 ret = vk->vkCreateCommandPool(vk->device, &cmd_pool_info, NULL, &pool->pool); ··· 37 41 VK_ERROR(vk, "vkCreateCommandPool: %s", vk_result_string(ret)); 38 42 os_mutex_destroy(&pool->mutex); 39 43 } 44 + 45 + pool->queue = queue; 40 46 41 47 return ret; 42 48 } ··· 133 139 .pCommandBuffers = &cmd_buffer, 134 140 }; 135 141 136 - ret = vk_cmd_submit_locked(vk, 1, &submitInfo, VK_NULL_HANDLE); 142 + ret = vk_cmd_submit_locked(vk, pool->queue, 1, &submitInfo, VK_NULL_HANDLE); 137 143 138 144 if (ret != VK_SUCCESS) { 139 145 VK_ERROR(vk, "vk_cmd_submit_locked: %s", vk_result_string(ret));
+28 -3
src/xrt/auxiliary/vk/vk_cmd_pool.h
··· 31 31 */ 32 32 struct vk_cmd_pool 33 33 { 34 + //! The command pool for command buffers 34 35 VkCommandPool pool; 36 + 37 + /*! 38 + * @brief Queue (family) associated with @ref vk_cmd_pool::pool, 39 + * 40 + * weak reference to any queue in @ref vk_bundle (e.g. vk_bundle::[graphics|compute]_queue) 41 + * should not live longer than the @ref vk_bundle instance. 42 + */ 43 + struct vk_bundle_queue *queue; 44 + 45 + //! Command Pool mutex 35 46 struct os_mutex mutex; 36 47 }; 37 48 ··· 48 59 * @public @memberof vk_cmd_pool 49 60 */ 50 61 XRT_CHECK_RESULT VkResult 51 - vk_cmd_pool_init(struct vk_bundle *vk, struct vk_cmd_pool *pool, VkCommandPoolCreateFlags flags); 62 + vk_cmd_pool_init_for_queue(struct vk_bundle *vk, 63 + struct vk_cmd_pool *pool, 64 + VkCommandPoolCreateFlags flags, 65 + struct vk_bundle_queue *queue); 66 + 67 + /*! 68 + * Create a command buffer pool. 69 + * 70 + * @public @memberof vk_cmd_pool 71 + */ 72 + static inline XRT_CHECK_RESULT VkResult 73 + vk_cmd_pool_init(struct vk_bundle *vk, struct vk_cmd_pool *pool, VkCommandPoolCreateFlags flags) 74 + { 75 + return vk_cmd_pool_init_for_queue(vk, pool, flags, &vk->main_queue); 76 + } 52 77 53 78 /*! 54 79 * Destroy a command buffer pool, lock must not be held, externally ··· 113 138 struct vk_cmd_pool *pool, 114 139 VkCommandBuffer cmd_buffer) 115 140 { 116 - return vk_cmd_end_submit_wait_and_free_cmd_buffer_locked(vk, pool->pool, cmd_buffer); 141 + return vk_cmd_end_submit_wait_and_free_cmd_buffer_locked(vk, pool->queue, pool->pool, cmd_buffer); 117 142 } 118 143 119 144 /*! ··· 184 209 struct vk_bundle *vk, struct vk_cmd_pool *pool, uint32_t count, const VkSubmitInfo *infos, VkFence fence) 185 210 { 186 211 vk_cmd_pool_lock(pool); 187 - VkResult ret = vk_cmd_submit_locked(vk, count, infos, fence); 212 + VkResult ret = vk_cmd_submit_locked(vk, pool->queue, count, infos, fence); 188 213 vk_cmd_pool_unlock(pool); 189 214 return ret; 190 215 }
+1 -1
src/xrt/compositor/main/comp_renderer.c
··· 665 665 * us avoid taking a lot of locks. The queue lock will be taken by 666 666 * @ref vk_cmd_submit_locked tho. 667 667 */ 668 - ret = vk_cmd_submit_locked(vk, 1, &comp_submit_info, r->fences[r->acquired_buffer]); 668 + ret = vk_cmd_submit_locked(vk, &vk->main_queue, 1, &comp_submit_info, r->fences[r->acquired_buffer]); 669 669 670 670 // We have now completed the submit, even if we failed. 671 671 comp_target_mark_submit_end(ct, frame_id, os_monotonic_get_ns());
+1 -1
src/xrt/compositor/main/comp_window_peek.c
··· 434 434 }; 435 435 436 436 // Done writing commands, submit to queue. 437 - ret = vk_cmd_submit_locked(vk, 1, &submit, VK_NULL_HANDLE); 437 + ret = vk_cmd_submit_locked(vk, &vk->main_queue, 1, &submit, VK_NULL_HANDLE); 438 438 439 439 // Done submitting commands, unlock pool. 440 440 vk_cmd_pool_unlock(&w->pool);
+1 -1
src/xrt/compositor/render/render_resources.c
··· 657 657 r->mock.color.image); // dst 658 658 VK_CHK_WITH_RET(ret, "prepare_mock_image_locked", false); 659 659 660 - ret = vk_cmd_end_submit_wait_and_free_cmd_buffer_locked(vk, r->cmd_pool, cmd); 660 + ret = vk_cmd_end_submit_wait_and_free_cmd_buffer_locked(vk, &vk->main_queue, r->cmd_pool, cmd); 661 661 VK_CHK_WITH_RET(ret, "vk_cmd_end_submit_wait_and_free_cmd_buffer_locked", false); 662 662 663 663 // No need to wait, submit waits on the fence.