From 580ff4ceb889fac7030b5aaa9a16b2bc5d5deacd Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 16 Nov 2023 14:36:32 +0000 Subject: [PATCH] c/util: Re-order functions in comp_swapchain.c [NFC] --- src/xrt/compositor/util/comp_swapchain.c | 86 ++++++++++++------------ 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/xrt/compositor/util/comp_swapchain.c b/src/xrt/compositor/util/comp_swapchain.c index 90c82c01b..29f09a1e0 100644 --- a/src/xrt/compositor/util/comp_swapchain.c +++ b/src/xrt/compositor/util/comp_swapchain.c @@ -244,6 +244,49 @@ set_common_fields(struct comp_swapchain *sc, return sc; } +static void +image_view_array_cleanup(struct vk_bundle *vk, size_t array_size, VkImageView **views_ptr) +{ + VkImageView *views = *views_ptr; + if (views == NULL) { + return; + } + + for (uint32_t i = 0; i < array_size; ++i) { + if (views[i] == VK_NULL_HANDLE) { + continue; + } + + D(ImageView, views[i]); + } + + free(views); + array_size = 0; + + *views_ptr = NULL; +} + +/*! + * Free and destroy any initialized fields on the given image, safe to pass in + * images that has one or all fields set to NULL. + */ +static void +image_cleanup(struct vk_bundle *vk, struct comp_swapchain_image *image) +{ + /* + * This makes sure that any pending command buffer has completed and all + * resources referred by it can now be manipulated. This make sure that + * validation doesn't complain. This is done during image destruction so + * isn't time critical. + */ + os_mutex_lock(&vk->queue_mutex); + vk->vkDeviceWaitIdle(vk->device); + os_mutex_unlock(&vk->queue_mutex); + + image_view_array_cleanup(vk, image->array_size, &image->views.alpha); + image_view_array_cleanup(vk, image->array_size, &image->views.no_alpha); +} + static void do_post_create_vulkan_setup(struct vk_bundle *vk, const struct xrt_swapchain_create_info *info, @@ -384,49 +427,6 @@ do_post_create_vulkan_setup(struct vk_bundle *vk, } } -static void -clean_image_views(struct vk_bundle *vk, size_t array_size, VkImageView **views_ptr) -{ - VkImageView *views = *views_ptr; - if (views == NULL) { - return; - } - - for (uint32_t i = 0; i < array_size; ++i) { - if (views[i] == VK_NULL_HANDLE) { - continue; - } - - D(ImageView, views[i]); - } - - free(views); - array_size = 0; - - *views_ptr = NULL; -} - -/*! - * Free and destroy any initialized fields on the given image, safe to pass in - * images that has one or all fields set to NULL. - */ -static void -image_cleanup(struct vk_bundle *vk, struct comp_swapchain_image *image) -{ - /* - * This makes sure that any pending command buffer has completed and all - * resources referred by it can now be manipulated. This make sure that - * validation doesn't complain. This is done during image destruction so - * isn't time critical. - */ - os_mutex_lock(&vk->queue_mutex); - vk->vkDeviceWaitIdle(vk->device); - os_mutex_unlock(&vk->queue_mutex); - - clean_image_views(vk, image->array_size, &image->views.alpha); - clean_image_views(vk, image->array_size, &image->views.no_alpha); -} - /*! * Swapchain destruct is delayed until it is safe to destroy them, this function * does the actual destruction and is called from @ref