Monado OpenXR Runtime
Loading...
Searching...
No Matches
comp_swapchain.c File Reference

Independent swapchain implementation. More...

#include "xrt/xrt_compiler.h"
#include "xrt/xrt_handles.h"
#include "xrt/xrt_config_os.h"
#include "xrt/xrt_results.h"
#include "xrt/xrt_allocation_collection_vk.h"
#include "util/u_misc.h"
#include "util/u_handles.h"
#include "util/u_logging.h"
#include "util/u_trace_marker.h"
#include "util/u_limited_unique_id.h"
#include "vk/vk_cmd_pool.h"
#include "vk/vk_compositor_flags.h"
#include "vk/vk_format.h"
#include "vk/vk_helpers.h"
#include "vk/vk_mini_helpers.h"
#include "allocation/a_allocator.h"
#include "util/comp_swapchain.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
Include dependency graph for comp_swapchain.c:

Macros

#define XVK_CHK_AND_RET(...)   U_LOG_CHK_AND_RET(vk->log_level, __VA_ARGS__)
 
#define XVK_CHK_WITH_GOTO(...)   U_LOG_CHK_WITH_GOTO(vk->log_level, __VA_ARGS__)
 
#define XVK_CHK_WITH_RET(...)   U_LOG_CHK_WITH_RET(vk->log_level, __VA_ARGS__)
 
#define XVK_CHK_ONLY_PRINT(...)   U_LOG_CHK_ONLY_PRINT(vk->log_level, __VA_ARGS__)
 
#define XVK_CHK_ALWAYS_RET(...)   U_LOG_CHK_ALWAYS_RET(vk->log_level, __VA_ARGS__)
 

Functions

static void swapchain_destroy (struct xrt_swapchain *xsc)
 
static xrt_result_t swapchain_acquire_image (struct xrt_swapchain *xsc, uint32_t *out_index)
 
static xrt_result_t swapchain_inc_image_use (struct xrt_swapchain *xsc, uint32_t index)
 
static xrt_result_t swapchain_dec_image_use (struct xrt_swapchain *xsc, uint32_t index)
 
static xrt_result_t swapchain_wait_image (struct xrt_swapchain *xsc, int64_t timeout_ns, uint32_t index)
 
static xrt_result_t swapchain_release_image (struct xrt_swapchain *xsc, uint32_t index)
 
static struct comp_swapchain * set_common_fields (struct comp_swapchain *sc, comp_swapchain_destroy_func_t destroy_func, struct vk_bundle *vk, struct comp_swapchain_shared *cscs, uint32_t image_count)
 
static void image_view_array_cleanup (struct vk_bundle *vk, size_t array_size, VkImageView **views_ptr)
 
static void image_cleanup (struct vk_bundle *vk, struct comp_swapchain_image *image)
 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 cleanup_post_create_vulkan_setup (struct vk_bundle *vk, struct comp_swapchain *sc)
 Clean up all resources held by a comp_swapchain, but does not free the struct itself.
 
static XRT_CHECK_RESULT xrt_result_t get_and_store_vk_images (struct vk_bundle *vk, struct comp_swapchain *sc)
 Get VkImages from the image collection and store them in the swapchain.
 
static XRT_CHECK_RESULT xrt_result_t do_post_create_vulkan_setup (struct vk_bundle *vk, const struct xrt_swapchain_create_info *info, struct comp_swapchain *sc)
 
static void really_destroy (struct comp_swapchain *sc)
 Swapchain destruct is delayed until it is safe to destroy them, this function does the actual destruction and is called from comp_swapchain_shared_garbage_collect.
 
xrt_result_t comp_swapchain_create_init (struct comp_swapchain *sc, comp_swapchain_destroy_func_t destroy_func, struct vk_bundle *vk, struct comp_swapchain_shared *cscs, const struct xrt_swapchain_create_info *info, const struct xrt_swapchain_create_properties *xsccp)
 Helper to init a comp_swachain struct as if it was a create operation, useful for wrapping comp_swapchain within another struct.
 
xrt_result_t comp_swapchain_import_init (struct comp_swapchain *sc, comp_swapchain_destroy_func_t destroy_func, struct vk_bundle *vk, struct comp_swapchain_shared *cscs, const struct xrt_swapchain_create_info *info, struct xrt_image_native *native_images, uint32_t native_image_count)
 Helper to init a comp_swachain struct as if it was a import operation, useful for wrapping comp_swapchain within another struct.
 
void comp_swapchain_teardown (struct comp_swapchain *sc)
 De-inits a comp_swapchain, usable for classes sub-classing comp_swapchain.
 
XRT_CHECK_RESULT xrt_result_t comp_swapchain_shared_init (struct comp_swapchain_shared *cscs, struct vk_bundle *vk)
 Create the shared struct.
 
void comp_swapchain_shared_destroy (struct comp_swapchain_shared *cscs, struct vk_bundle *vk)
 Destroy the shared struct.
 
void comp_swapchain_shared_garbage_collect (struct comp_swapchain_shared *cscs)
 Do garbage collection, destroying any resources that has been scheduled for destruction from other threads.
 
xrt_result_t comp_swapchain_get_create_properties (const struct xrt_swapchain_create_info *info, struct xrt_swapchain_create_properties *xsccp)
 A compositor function that is implemented in the swapchain code.
 
xrt_result_t comp_swapchain_create (struct vk_bundle *vk, struct comp_swapchain_shared *cscs, const struct xrt_swapchain_create_info *info, const struct xrt_swapchain_create_properties *xsccp, struct xrt_swapchain **out_xsc)
 A compositor function that is implemented in the swapchain code.
 
xrt_result_t comp_swapchain_import (struct vk_bundle *vk, struct comp_swapchain_shared *cscs, const struct xrt_swapchain_create_info *info, struct xrt_image_native *native_images, uint32_t native_image_count, struct xrt_swapchain **out_xsc)
 A compositor function that is implemented in the swapchain code.
 

Detailed Description

Independent swapchain implementation.

Author
Jakob Bornecrantz jakob.nosp@m.@col.nosp@m.labor.nosp@m.a.co.nosp@m.m

Function Documentation

◆ cleanup_post_create_vulkan_setup()

static void cleanup_post_create_vulkan_setup ( struct vk_bundle *  vk,
struct comp_swapchain *  sc 
)
static

Clean up all resources held by a comp_swapchain, but does not free the struct itself.

Safe to call at any point during initialization - only cleans up what was allocated. Does NOT clean up threading objects (mutex/cond) as they are only initialized at the very end of successful creation and require the use_count check in comp_swapchain_teardown.

Parameters
vkVulkan bundle.
scThe swapchain to clean up.

References xrt_swapchain_native::base, image_cleanup(), xrt_swapchain::image_count, and xrt_swapchain_native::xac.

Referenced by comp_swapchain_teardown(), and do_post_create_vulkan_setup().

◆ do_post_create_vulkan_setup()

◆ get_and_store_vk_images()

static XRT_CHECK_RESULT xrt_result_t get_and_store_vk_images ( struct vk_bundle *  vk,
struct comp_swapchain *  sc 
)
static

Get VkImages from the image collection and store them in the swapchain.

On error, releases the image collection and returns the error.

Parameters
vkVulkan bundle the images were created with.
scThe swapchain to populate.
Returns
XRT_SUCCESS on success.

References xrt_swapchain_native::base, comp_swapchain_image::image, xrt_swapchain::image_count, xrt_swapchain_native::xac, XRT_MAX_SWAPCHAIN_IMAGES, and XRT_SUCCESS.

Referenced by comp_swapchain_create_init(), and comp_swapchain_import_init().

◆ image_cleanup()

static void image_cleanup ( struct vk_bundle *  vk,
struct comp_swapchain_image *  image 
)
static

Free and destroy any initialized fields on the given image, safe to pass in images that has one or all fields set to NULL.

References comp_swapchain_image::array_size, vk_bundle::main_queue, and comp_swapchain_image::views.

Referenced by cleanup_post_create_vulkan_setup().