Monado OpenXR Runtime
comp_base.h
Go to the documentation of this file.
1// Copyright 2019-2023, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Helper implementation for native compositors.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
8 * @ingroup comp_util
9 */
10
11#pragma once
12
13#include "util/comp_sync.h"
14#include "util/comp_swapchain.h"
15
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21#define COMP_MAX_LAYERS 16
22
23/*!
24 * A single layer.
25 *
26 * @ingroup comp_util
27 * @see comp_layer_slot
28 */
30{
31 /*!
32 * Up to four compositor swapchains referenced per layer.
33 *
34 * Unused elements should be set to null.
35 */
36 struct comp_swapchain *sc_array[XRT_MAX_VIEWS * 2];
37
38 /*!
39 * All basic (trivially-serializable) data associated with a layer.
40 */
42};
43
44/*!
45 * A stack of layers.
46 *
47 * @ingroup comp_util
48 * @see comp_base
49 */
51{
52 //! The per frame data.
54
55 //! All of the layers.
56 struct comp_layer layers[COMP_MAX_LAYERS];
57
58 //! Number of submitted layers.
59 uint32_t layer_count;
60
61 //! Special case one layer projection/projection-depth fast-path.
63
64 //! fov as reported by device for the current submit.
65 struct xrt_fov fovs[XRT_MAX_VIEWS];
66 //! absolute pose as reported by device for the current submit.
67 struct xrt_pose poses[XRT_MAX_VIEWS];
68};
69
70/*!
71 * A simple compositor base that handles a lot of things for you.
72 *
73 * Things it handles for you:
74 * * App swapchains
75 * * App fences
76 * * Vulkan bundle (needed for swapchains and fences)
77 * * Layer tracking, not @ref xrt_compositor::layer_commit
78 * * Wait function, not @ref xrt_compositor::predict_frame
79 *
80 * Functions it does not handle:
81 * * @ref xrt_compositor::begin_session
82 * * @ref xrt_compositor::end_session
83 * * @ref xrt_compositor::predict_frame
84 * * @ref xrt_compositor::mark_frame
85 * * @ref xrt_compositor::begin_frame
86 * * @ref xrt_compositor::discard_frame
87 * * @ref xrt_compositor::layer_commit
88 * * @ref xrt_compositor::poll_events
89 * * @ref xrt_compositor::destroy
90 *
91 * Partially implements @ref xrt_compositor_native, meant to serve as
92 * the base of a main compositor implementation.
93 *
94 * @implements xrt_compositor_native
95 * @ingroup comp_util
96 */
98{
99 //! Base native compositor.
101
102 //! Vulkan bundle of useful things, used by swapchain and fence.
103 struct vk_bundle vk;
104
105 //! For default @ref xrt_compositor::wait_frame.
107
108 //! Swapchain garbage collector, used by swapchain, child class needs to call.
110
111 //! We only need to track a single slot.
113};
114
115
116/*
117 *
118 * Helper functions.
119 *
120 */
121
122/*!
123 * Convenience function to convert a xrt_compositor to a comp_base.
124 *
125 * @private @memberof comp_base
126 */
127static inline struct comp_base *
128comp_base(struct xrt_compositor *xc)
129{
130 return (struct comp_base *)xc;
131}
132
133
134/*
135 *
136 * 'Exported' functions.
137 *
138 */
139
140/*!
141 * Inits all of the supported functions and structs, except @ref vk_bundle.
142 *
143 * The bundle needs to be initialised before any of the implemented functions
144 * are call, but is not required to be initialised before this function is
145 * called.
146 *
147 * @protected @memberof comp_base
148 */
149void
150comp_base_init(struct comp_base *cb);
151
152/*!
153 * De-initialises all structs, except @ref vk_bundle.
154 *
155 * The bundle needs to be de-initialised by the sub-class.
156 *
157 * @private @memberof comp_base
158 */
159void
160comp_base_fini(struct comp_base *cb);
161
162
163#ifdef __cplusplus
164}
165#endif
Independent swapchain implementation.
Independent xrt_compositor_fence implementation.
A simple compositor base that handles a lot of things for you.
Definition: comp_base.h:98
struct vk_bundle vk
Vulkan bundle of useful things, used by swapchain and fence.
Definition: comp_base.h:103
struct os_precise_sleeper sleeper
For default xrt_compositor::wait_frame.
Definition: comp_base.h:106
struct xrt_compositor_native base
Base native compositor.
Definition: comp_base.h:100
struct comp_swapchain_shared cscs
Swapchain garbage collector, used by swapchain, child class needs to call.
Definition: comp_base.h:109
void comp_base_init(struct comp_base *cb)
Inits all of the supported functions and structs, except vk_bundle.
Definition: comp_base.c:250
struct comp_layer_slot slot
We only need to track a single slot.
Definition: comp_base.h:112
A stack of layers.
Definition: comp_base.h:51
bool one_projection_layer_fast_path
Special case one layer projection/projection-depth fast-path.
Definition: comp_base.h:62
struct comp_layer layers[16]
All of the layers.
Definition: comp_base.h:56
struct xrt_pose poses[XRT_MAX_VIEWS]
absolute pose as reported by device for the current submit.
Definition: comp_base.h:67
uint32_t layer_count
Number of submitted layers.
Definition: comp_base.h:59
struct xrt_layer_frame_data data
The per frame data.
Definition: comp_base.h:53
struct xrt_fov fovs[XRT_MAX_VIEWS]
fov as reported by device for the current submit.
Definition: comp_base.h:65
A single layer.
Definition: comp_base.h:30
struct comp_swapchain * sc_array[XRT_MAX_VIEWS *2]
Up to four compositor swapchains referenced per layer.
Definition: comp_base.h:36
struct xrt_layer_data data
All basic (trivially-serializable) data associated with a layer.
Definition: comp_base.h:41
Shared resource(s) and garbage collector for swapchains.
Definition: comp_swapchain.h:44
A swapchain that is almost a one to one mapping to a OpenXR swapchain.
Definition: comp_swapchain.h:92
Definition: os_time.h:208
A bundle of Vulkan functions and objects, used by both Compositor and Compositor client code.
Definition: vk_helpers.h:49
Main compositor server interface.
Definition: xrt_compositor.h:2224
Common compositor client interface/base.
Definition: xrt_compositor.h:986
Describes a projection matrix fov.
Definition: xrt_defines.h:486
All the pure data values associated with a composition layer.
Definition: xrt_compositor.h:394
Per frame data for the layer submission calls, used in xrt_compositor::layer_begin.
Definition: xrt_compositor.h:478
A pose composed of a position and orientation.
Definition: xrt_defines.h:465