From 1cf39ec2c0e72238b25f68d77871bdb43f9719c0 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Tue, 13 Apr 2021 12:30:52 -0500 Subject: [PATCH] c/main: Add comp_target::has_images, and implement in comp_target_swapchain. --- src/xrt/compositor/main/comp_target.h | 24 +++++++++++++++++++ .../compositor/main/comp_target_swapchain.c | 15 ++++++++++-- .../compositor/main/comp_target_swapchain.h | 1 + 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/xrt/compositor/main/comp_target.h b/src/xrt/compositor/main/comp_target.h index 96eefa5e7..376cacf9d 100644 --- a/src/xrt/compositor/main/comp_target.h +++ b/src/xrt/compositor/main/comp_target.h @@ -125,8 +125,18 @@ struct comp_target VkColorSpaceKHR preferred_color_space, VkPresentModeKHR present_mode); + /*! + * Has this target successfully had images created? + * + * Call before calling @ref acquire - if false but @ref check_ready is true, you'll need to call @ref + * create_images + */ + bool (*has_images)(struct comp_target *ct); + /*! * Acquire the next image for rendering. + * + * @pre @ref has_images returns true */ VkResult (*acquire)(struct comp_target *ct, VkSemaphore semaphore, uint32_t *out_index); @@ -266,6 +276,20 @@ comp_target_create_images(struct comp_target *ct, present_mode); // } +/*! + * @copydoc comp_target::has_images + * + * @public @memberof comp_target + * @ingroup comp_main + */ +static inline bool +comp_target_has_images(struct comp_target *ct) +{ + COMP_TRACE_MARKER(); + + return ct->has_images(ct); +} + /*! * @copydoc comp_target::acquire * diff --git a/src/xrt/compositor/main/comp_target_swapchain.c b/src/xrt/compositor/main/comp_target_swapchain.c index 9e1dca5c0..957d64bb5 100644 --- a/src/xrt/compositor/main/comp_target_swapchain.c +++ b/src/xrt/compositor/main/comp_target_swapchain.c @@ -251,10 +251,13 @@ comp_target_swapchain_acquire_next_image(struct comp_target *ct, VkSemaphore sem struct comp_target_swapchain *cts = (struct comp_target_swapchain *)ct; struct vk_bundle *vk = get_vk(cts); - + if (!comp_target_swapchain_has_images(ct)) { + //! @todo what error to return here? + return VK_ERROR_INITIALIZATION_FAILED; + } return vk->vkAcquireNextImageKHR( // vk->device, // device - cts->swapchain.handle, // timeout + cts->swapchain.handle, // swapchain UINT64_MAX, // timeout semaphore, // semaphore VK_NULL_HANDLE, // fence @@ -306,6 +309,13 @@ comp_target_swapchain_check_ready(struct comp_target *ct) return cts->surface.handle != VK_NULL_HANDLE; } +static bool +comp_target_swapchain_has_images(struct comp_target *ct) +{ + struct comp_target_swapchain *cts = (struct comp_target_swapchain *)ct; + return cts->surface.handle != VK_NULL_HANDLE && cts->swapchain.handle != VK_NULL_HANDLE; +} + static bool _find_surface_format(struct comp_target_swapchain *cts, VkSurfaceKHR surface, VkSurfaceFormatKHR *format) { @@ -655,6 +665,7 @@ comp_target_swapchain_init_and_set_fnptrs(struct comp_target_swapchain *cts, cts->timing_usage = timing_usage; cts->base.check_ready = comp_target_swapchain_check_ready; cts->base.create_images = comp_target_swapchain_create_images; + cts->base.has_images = comp_target_swapchain_has_images; cts->base.acquire = comp_target_swapchain_acquire_next_image; cts->base.present = comp_target_swapchain_present; cts->base.calc_frame_timings = comp_target_swapchain_calc_frame_timings; diff --git a/src/xrt/compositor/main/comp_target_swapchain.h b/src/xrt/compositor/main/comp_target_swapchain.h index a30cf24e4..c1e146ab1 100644 --- a/src/xrt/compositor/main/comp_target_swapchain.h +++ b/src/xrt/compositor/main/comp_target_swapchain.h @@ -85,6 +85,7 @@ struct comp_target_swapchain * * - comp_target::check_ready * - comp_target::create_images + * - comp_target::has_images * - comp_target::acquire * - comp_target::present * - comp_target::calc_frame_timings