The open source OpenXR runtime

a/vk: refactors vk queues into dedicated type

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

+65 -50
+18 -15
src/xrt/auxiliary/vk/vk_bundle_init.c
··· 252 252 uint32_t count = 0; 253 253 vk->vkGetPhysicalDeviceQueueFamilyProperties(vk->physical_device, &count, NULL); 254 254 assert(count != 0); 255 - assert(count > vk->queue_family_index); 255 + assert(count > vk->main_queue.family_index); 256 256 257 257 VkQueueFamilyProperties *props = U_TYPED_ARRAY_CALLOC(VkQueueFamilyProperties, count); 258 258 vk->vkGetPhysicalDeviceQueueFamilyProperties(vk->physical_device, &count, props); 259 259 260 - vk->features.timestamp_valid_bits = props[vk->queue_family_index].timestampValidBits; 260 + vk->features.timestamp_valid_bits = props[vk->main_queue.family_index].timestampValidBits; 261 261 free(props); 262 262 } 263 263 ··· 1297 1297 } 1298 1298 1299 1299 if (only_compute) { 1300 - ret = find_queue_family(vk, VK_QUEUE_COMPUTE_BIT, &vk->queue_family_index); 1300 + ret = find_queue_family(vk, VK_QUEUE_COMPUTE_BIT, &vk->main_queue.family_index); 1301 1301 } else { 1302 - ret = find_graphics_queue_family(vk, &vk->queue_family_index); 1302 + ret = find_graphics_queue_family(vk, &vk->main_queue.family_index); 1303 1303 } 1304 1304 1305 1305 if (ret != VK_SUCCESS) { ··· 1320 1320 queue_create_info[0].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; 1321 1321 queue_create_info[0].pNext = NULL; 1322 1322 queue_create_info[0].queueCount = 1; 1323 - queue_create_info[0].queueFamilyIndex = vk->queue_family_index; 1323 + queue_create_info[0].queueFamilyIndex = vk->main_queue.family_index; 1324 1324 queue_create_info[0].pQueuePriorities = &queue_priority; 1325 1325 1326 1326 #ifdef VK_KHR_video_encode_queue 1327 1327 // Video encode queue 1328 - vk->encode_queue_family_index = VK_QUEUE_FAMILY_IGNORED; 1328 + vk->encode_queue = VK_BUNDLE_NULL_QUEUE; 1329 1329 if (u_string_list_contains(device_ext_list, VK_KHR_VIDEO_ENCODE_QUEUE_EXTENSION_NAME)) { 1330 - ret = find_queue_family(vk, VK_QUEUE_VIDEO_ENCODE_BIT_KHR, &vk->encode_queue_family_index); 1330 + ret = find_queue_family(vk, VK_QUEUE_VIDEO_ENCODE_BIT_KHR, &vk->encode_queue.family_index); 1331 1331 if (ret == VK_SUCCESS) { 1332 1332 queue_create_info[queue_create_info_count].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; 1333 1333 queue_create_info[queue_create_info_count].pNext = NULL; 1334 1334 queue_create_info[queue_create_info_count].queueCount = 1; 1335 - queue_create_info[queue_create_info_count].queueFamilyIndex = vk->encode_queue_family_index; 1335 + queue_create_info[queue_create_info_count].queueFamilyIndex = vk->encode_queue.family_index; 1336 1336 queue_create_info[queue_create_info_count].pQueuePriorities = &queue_priority; 1337 1337 queue_create_info_count++; 1338 - VK_DEBUG(vk, "Creating video encode queue, family index %d", vk->encode_queue_family_index); 1338 + VK_DEBUG(vk, "Creating video encode queue, family index %d", vk->encode_queue.family_index); 1339 1339 } 1340 1340 } 1341 1341 #endif ··· 1510 1510 if (ret != VK_SUCCESS) { 1511 1511 goto err_destroy; 1512 1512 } 1513 - vk->vkGetDeviceQueue(vk->device, vk->queue_family_index, 0, &vk->queue); 1513 + vk->vkGetDeviceQueue(vk->device, vk->main_queue.family_index, 0, &vk->main_queue.queue); 1514 1514 #if defined(VK_KHR_video_encode_queue) 1515 - if (vk->encode_queue_family_index != VK_QUEUE_FAMILY_IGNORED) { 1516 - vk->vkGetDeviceQueue(vk->device, vk->encode_queue_family_index, 0, &vk->encode_queue); 1515 + if (vk->encode_queue.family_index != VK_QUEUE_FAMILY_IGNORED) { 1516 + vk->vkGetDeviceQueue(vk->device, vk->encode_queue.family_index, 0, &vk->encode_queue.queue); 1517 1517 } 1518 1518 #endif 1519 1519 ··· 1582 1582 vk->instance = instance; 1583 1583 vk->physical_device = physical_device; 1584 1584 vk->device = device; 1585 - vk->queue_family_index = queue_family_index; 1586 - vk->queue_index = queue_index; 1585 + vk->main_queue.family_index = queue_family_index; 1586 + vk->main_queue.index = queue_index; 1587 + #ifdef VK_KHR_video_encode_queue 1588 + vk->encode_queue = VK_BUNDLE_NULL_QUEUE; 1589 + #endif 1587 1590 1588 1591 // Fill in all instance functions. 1589 1592 ret = vk_get_instance_functions(vk); ··· 1633 1636 goto err_memset; 1634 1637 } 1635 1638 1636 - vk->vkGetDeviceQueue(vk->device, vk->queue_family_index, vk->queue_index, &vk->queue); 1639 + vk->vkGetDeviceQueue(vk->device, vk->main_queue.family_index, vk->main_queue.index, &vk->main_queue.queue); 1637 1640 1638 1641 vk->has_EXT_debug_utils = false; 1639 1642 if (debug_utils_enabled) {
+1 -1
src/xrt/auxiliary/vk/vk_cmd.c
··· 83 83 VkResult ret; 84 84 85 85 os_mutex_lock(&vk->queue_mutex); 86 - ret = vk->vkQueueSubmit(vk->queue, count, infos, fence); 86 + ret = vk->vkQueueSubmit(vk->main_queue.queue, count, infos, fence); 87 87 os_mutex_unlock(&vk->queue_mutex); 88 88 89 89 if (ret != VK_SUCCESS) {
+1 -1
src/xrt/auxiliary/vk/vk_cmd_pool.c
··· 29 29 VkCommandPoolCreateInfo cmd_pool_info = { 30 30 .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, 31 31 .flags = flags, 32 - .queueFamilyIndex = vk->queue_family_index, 32 + .queueFamilyIndex = vk->main_queue.family_index, 33 33 }; 34 34 35 35 ret = vk->vkCreateCommandPool(vk->device, &cmd_pool_info, NULL, &pool->pool);
+18 -6
src/xrt/auxiliary/vk/vk_helpers.h
··· 40 40 * 41 41 */ 42 42 43 + struct vk_bundle_queue 44 + { 45 + //! The Vulkan queue handle 46 + VkQueue queue; 47 + //! The queue family index 48 + uint32_t family_index; 49 + //! The queue (instance) index 50 + uint32_t index; 51 + }; 52 + 53 + #define VK_BUNDLE_NULL_QUEUE \ 54 + XRT_C11_COMPOUND(struct vk_bundle_queue) \ 55 + { \ 56 + .queue = VK_NULL_HANDLE, .family_index = VK_QUEUE_FAMILY_IGNORED, .index = (uint32_t)-1, \ 57 + } 58 + 43 59 /*! 44 60 * A bundle of Vulkan functions and objects, used by both @ref comp and @ref 45 61 * comp_client. Note that they both have different instances of the object, and ··· 56 72 VkPhysicalDevice physical_device; 57 73 int physical_device_index; 58 74 VkDevice device; 59 - uint32_t queue_family_index; 60 - uint32_t queue_index; 61 - VkQueue queue; 75 + struct vk_bundle_queue main_queue; 62 76 #if defined(VK_KHR_video_encode_queue) 63 - uint32_t encode_queue_family_index; 64 - uint32_t encode_queue_index; 65 - VkQueue encode_queue; 77 + struct vk_bundle_queue encode_queue; 66 78 #endif 67 79 68 80 struct os_mutex queue_mutex;
+5 -5
src/xrt/auxiliary/vk/vk_sync_objects.c
··· 144 144 145 145 os_mutex_lock(&vk->queue_mutex); 146 146 147 - ret = vk->vkQueueSubmit( // 148 - vk->queue, // queue 149 - 0, // submitCount 150 - NULL, // pSubmits 151 - fence); // fence 147 + ret = vk->vkQueueSubmit( // 148 + vk->main_queue.queue, // queue 149 + 0, // submitCount 150 + NULL, // pSubmits 151 + fence); // fence 152 152 153 153 os_mutex_unlock(&vk->queue_mutex); 154 154
+9 -9
src/xrt/compositor/client/comp_vk_client.c
··· 181 181 .pSignalSemaphores = semaphores, 182 182 }; 183 183 184 - ret = vk->vkQueueSubmit( // 185 - vk->queue, // queue 186 - 1, // submitCount 187 - &submit_info, // pSubmits 188 - VK_NULL_HANDLE); // fence 184 + ret = vk->vkQueueSubmit( // 185 + vk->main_queue.queue, // queue 186 + 1, // submitCount 187 + &submit_info, // pSubmits 188 + VK_NULL_HANDLE); // fence 189 189 if (ret != VK_SUCCESS) { 190 190 VK_ERROR(vk, "vkQueueSubmit: %s", vk_result_string(ret)); 191 191 *out_xret = XRT_ERROR_VULKAN; ··· 249 249 250 250 // Last course of action fallback. 251 251 os_mutex_lock(&vk->queue_mutex); 252 - vk->vkQueueWaitIdle(vk->queue); 252 + vk->vkQueueWaitIdle(vk->main_queue.queue); 253 253 os_mutex_unlock(&vk->queue_mutex); 254 254 } 255 255 ··· 276 276 // Make sure images are not used anymore. 277 277 if (BREAK_OPENXR_SPEC_IN_DESTROY_SWAPCHAIN) { 278 278 os_mutex_lock(&vk->queue_mutex); 279 - vk->vkQueueWaitIdle(vk->queue); 279 + vk->vkQueueWaitIdle(vk->main_queue.queue); 280 280 os_mutex_unlock(&vk->queue_mutex); 281 281 } 282 282 ··· 407 407 * not in use (pending in Vulkan terms), to please the validation layer. 408 408 */ 409 409 os_mutex_lock(&vk->queue_mutex); 410 - vk->vkQueueWaitIdle(vk->queue); 410 + vk->vkQueueWaitIdle(vk->main_queue.queue); 411 411 os_mutex_unlock(&vk->queue_mutex); 412 412 413 413 // Now safe to free the pool. ··· 756 756 .dstAccessMask = 0, 757 757 .oldLayout = barrier_optimal_layout, 758 758 .newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 759 - .srcQueueFamilyIndex = vk->queue_family_index, 759 + .srcQueueFamilyIndex = vk->main_queue.family_index, 760 760 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_EXTERNAL, 761 761 .image = sc->base.images[i], 762 762 .subresourceRange = subresource_range,
+8 -8
src/xrt/compositor/main/comp_renderer.c
··· 160 160 struct vk_bundle *vk = &r->c->base.vk; 161 161 162 162 os_mutex_lock(&vk->queue_mutex); 163 - vk->vkQueueWaitIdle(vk->queue); 163 + vk->vkQueueWaitIdle(vk->main_queue.queue); 164 164 os_mutex_unlock(&vk->queue_mutex); 165 165 } 166 166 ··· 741 741 assert(!comp_frame_is_invalid_locked(&r->c->frame.rendering)); 742 742 uint64_t render_complete_signal_value = (uint64_t)r->c->frame.rendering.id; 743 743 744 - ret = comp_target_present( // 745 - r->c->target, // 746 - r->c->base.vk.queue, // 747 - r->acquired_buffer, // 748 - render_complete_signal_value, // 749 - desired_present_time_ns, // 750 - present_slop_ns); // 744 + ret = comp_target_present( // 745 + r->c->target, // 746 + r->c->base.vk.main_queue.queue, // 747 + r->acquired_buffer, // 748 + render_complete_signal_value, // 749 + desired_present_time_ns, // 750 + present_slop_ns); // 751 751 r->acquired_buffer = -1; 752 752 753 753 if (ret == VK_ERROR_OUT_OF_DATE_KHR || ret == VK_SUBOPTIMAL_KHR) {
+1 -1
src/xrt/compositor/main/comp_target_swapchain.c
··· 682 682 // Can we create swapchains from the surface on this device and queue. 683 683 ret = vk->vkGetPhysicalDeviceSurfaceSupportKHR( // 684 684 vk->physical_device, // physicalDevice 685 - vk->queue_family_index, // queueFamilyIndex 685 + vk->main_queue.family_index, // queueFamilyIndex 686 686 cts->surface.handle, // surface 687 687 &supported); // pSupported 688 688 if (ret != VK_SUCCESS) {
+1 -1
src/xrt/compositor/main/comp_window_peek.c
··· 457 457 }; 458 458 459 459 os_mutex_lock(&vk->queue_mutex); 460 - ret = vk->vkQueuePresentKHR(vk->queue, &present); 460 + ret = vk->vkQueuePresentKHR(vk->main_queue.queue, &present); 461 461 os_mutex_unlock(&vk->queue_mutex); 462 462 463 463 if (ret != VK_SUCCESS) {
+1 -1
src/xrt/compositor/render/render_resources.c
··· 595 595 VkCommandPoolCreateInfo command_pool_info = { 596 596 .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, 597 597 .flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, 598 - .queueFamilyIndex = vk->queue_family_index, 598 + .queueFamilyIndex = vk->main_queue.family_index, 599 599 }; 600 600 601 601 ret = vk->vkCreateCommandPool(vk->device, &command_pool_info, NULL, &r->cmd_pool);
+2 -2
tests/tests_comp_client_vulkan.cpp
··· 152 152 vk->has_KHR_image_format_list, // image_format_list_enabled 153 153 false, // debug_utils_enabled 154 154 false, // renderdoc_enabled 155 - vk->queue_family_index, // 156 - vk->queue_index); 155 + vk->main_queue.family_index, // 156 + vk->main_queue.index); 157 157 struct xrt_compositor *xc = &xcvk->base; 158 158 159 159 SECTION("CreateSwapchain calls native create")