c/main: Add comp_target::has_images, and implement in comp_target_swapchain.

This commit is contained in:
Ryan Pavlik 2021-04-13 12:30:52 -05:00 committed by Jakob Bornecrantz
parent 90192118d0
commit 1cf39ec2c0
3 changed files with 38 additions and 2 deletions

View file

@ -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
*

View file

@ -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;

View file

@ -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