The open source OpenXR runtime
1// Copyright 2019-2023, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Independent semaphore implementation.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @ingroup comp_util
8 */
9
10#pragma once
11
12#include "xrt/xrt_compositor.h"
13#include "vk/vk_helpers.h"
14
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20
21/*!
22 * A simple implementation of the xrt_compositor_semaphore interface.
23 *
24 * @ingroup comp_util
25 * @implements xrt_compositor_swapchain
26 * @see comp_compositor
27 */
28struct comp_semaphore
29{
30 struct xrt_compositor_semaphore base;
31
32 struct vk_bundle *vk;
33
34 VkSemaphore semaphore;
35
36 /*!
37 * Shared handle, the layer above compositor, such as IPC & st/oxr,
38 * doesn't consume this handle, instead it has dup semantics. So we
39 * need to keep track of the handle and free it once done. This is
40 * because the platform may be required by the platform.
41 */
42 xrt_graphics_sync_handle_t handle;
43};
44
45
46/*
47 *
48 * Helper functions.
49 *
50 */
51
52/*!
53 * Convenience function to convert an xrt_compositor_semaphore to a comp_semaphore.
54 *
55 * @ingroup comp_util
56 * @private @memberof comp_semaphore
57 */
58static inline struct comp_semaphore *
59comp_semaphore(struct xrt_compositor_semaphore *xcsem)
60{
61 return (struct comp_semaphore *)xcsem;
62}
63
64
65/*
66 *
67 * 'Exported' functions.
68 *
69 */
70
71/*!
72 * Creates a @ref comp_semaphore, used to implement compositor functionality.
73 *
74 * @ingroup comp_util
75 */
76xrt_result_t
77comp_semaphore_create(struct vk_bundle *vk,
78 xrt_graphics_sync_handle_t *out_handle,
79 struct xrt_compositor_semaphore **out_xcsem);
80
81
82#ifdef __cplusplus
83}
84#endif