Monado OpenXR Runtime
comp_scratch.h
Go to the documentation of this file.
1// Copyright 2019-2024, 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
14
15#include "vk/vk_helpers.h"
16
18
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24
25/*
26 *
27 * Defines.
28 *
29 */
30
31//! The number of images for each view, works like a swapchain.
32#define COMP_SCRATCH_NUM_IMAGES (4)
33
34
35/*
36 *
37 * Common for handling indices.
38 *
39 */
40
41/*!
42 * Small helper struct to deal with indices.
43 *
44 * @ingroup comp_util
45 */
47{
48 uint32_t current;
49
50 uint32_t last;
51};
52
53
54/*
55 *
56 * Single view images.
57 *
58 */
59
60/*!
61 * Holds scratch images for a single view, designed to work with render code.
62 * Also manages @ref xrt_image_native and @ref u_native_images_debug to
63 * facilitate easy debugging.
64 *
65 * @ingroup comp_util
66 */
68{
69 //! Images used when rendering.
71
72 //! To connect to the debug UI.
74
75 //! Exposed via @ref unid.
77
78 //! Exposed via @ref unid.
80
81 //! Keeping track of indices.
83
84 //! Process unique id, used for caching.
86};
87
88/*!
89 * Init the struct, this function must be called before calling any other
90 * function on this struct, or variable tracking setup on @p unid. Zero init is
91 * not enough as it has a mutex in it and has native handles which on some
92 * platforms zero is a valid handle.
93 *
94 * @public @memberof comp_scratch_single_images
95 *
96 * @ingroup comp_util
97 */
98void
100
101/*!
102 * Ensure that the scratch images are allocated and match @p extent size.
103 *
104 * @public @memberof comp_scratch_single_images
105 *
106 * @ingroup comp_util
107 */
108bool
109comp_scratch_single_images_ensure(struct comp_scratch_single_images *cssi, struct vk_bundle *vk, VkExtent2D extent);
110
111/*!
112 * Free all images allocated, @p init must be called before calling this
113 * function, is safe to call without any image allocated.
114 *
115 * @public @memberof comp_scratch_single_images
116 *
117 * @ingroup comp_util
118 */
119void
121
122/*!
123 * Get the next free image, after this function has been called you must call
124 * either @p done or @p discard before calling any other function.
125 *
126 * @public @memberof comp_scratch_single_images
127 *
128 * @ingroup comp_util
129 */
130void
131comp_scratch_single_images_get(struct comp_scratch_single_images *cssi, uint32_t *out_index);
132
133/*!
134 * After calling @p get and rendering to the image you call this function to
135 * signal that you are done with this function, the GPU work needs to be fully
136 * completed before calling done.
137 *
138 * @public @memberof comp_scratch_single_images
139 *
140 * @ingroup comp_util
141 */
142void
144
145/*!
146 * Discard a @p get call, this clears the image debug part causing no image to
147 * be shown in the debug UI.
148 *
149 * @public @memberof comp_scratch_single_images
150 *
151 * @ingroup comp_util
152 */
153void
155
156/*!
157 * Clears the debug output, this causes nothing to be shown in the debug UI.
158 *
159 * @public @memberof comp_scratch_single_images
160 *
161 * @ingroup comp_util
162 */
163void
165
166/*!
167 * Destroys scratch image struct, if any images has been allocated must call
168 * @p free before as this function only destroys the mutex, and the @p unid must
169 * no longer be tracked.
170 *
171 * @public @memberof comp_scratch_single_images
172 *
173 * @ingroup comp_util
174 */
175void
177
178
179/*
180 *
181 * Stereo.
182 *
183 */
184
185/*!
186 * Holds scartch images for a stereo views, designed to work with render code.
187 * Also manages @ref xrt_image_native and @ref u_native_images_debug to
188 * facilitate easy debugging.
189 *
190 * @ingroup comp_util
191 */
193{
195
196 struct xrt_swapchain_create_info info;
197
198 //! Keeping track of indices.
200
201 struct
202 {
203 //! Debug output for each view.
205
206 //! Count always equals to the number of rsis.
208 } views[2];
209
210 //! Process unique id, used for caching.
212};
213
214void
215comp_scratch_stereo_images_init(struct comp_scratch_stereo_images *cssi);
216
217bool
218comp_scratch_stereo_images_ensure(struct comp_scratch_stereo_images *cssi, struct vk_bundle *vk, VkExtent2D extent);
219
220void
221comp_scratch_stereo_images_free(struct comp_scratch_stereo_images *cssi, struct vk_bundle *vk);
222
223void
224comp_scratch_stereo_images_get(struct comp_scratch_stereo_images *cssi, uint32_t *out_index);
225
226void
227comp_scratch_stereo_images_done(struct comp_scratch_stereo_images *cssi);
228
229void
230comp_scratch_stereo_images_discard(struct comp_scratch_stereo_images *cssi);
231
232void
233comp_scratch_stereo_images_clear_debug(struct comp_scratch_stereo_images *cssi);
234
235void
236comp_scratch_stereo_images_destroy(struct comp_scratch_stereo_images *cssi);
237
238
239#ifdef __cplusplus
240}
241#endif
#define COMP_SCRATCH_NUM_IMAGES
The number of images for each view, works like a swapchain.
Definition: comp_scratch.h:32
void comp_scratch_single_images_init(struct comp_scratch_single_images *cssi)
Init the struct, this function must be called before calling any other function on this struct,...
Definition: comp_scratch.c:263
void comp_scratch_single_images_clear_debug(struct comp_scratch_single_images *cssi)
Clears the debug output, this causes nothing to be shown in the debug UI.
Definition: comp_scratch.c:366
void comp_scratch_single_images_destroy(struct comp_scratch_single_images *cssi)
Destroys scratch image struct, if any images has been allocated must call free before as this functio...
Definition: comp_scratch.c:372
void comp_scratch_single_images_done(struct comp_scratch_single_images *cssi)
After calling get and rendering to the image you call this function to signal that you are done with ...
Definition: comp_scratch.c:340
void comp_scratch_single_images_get(struct comp_scratch_single_images *cssi, uint32_t *out_index)
Get the next free image, after this function has been called you must call either done or discard bef...
Definition: comp_scratch.c:334
bool comp_scratch_single_images_ensure(struct comp_scratch_single_images *cssi, struct vk_bundle *vk, VkExtent2D extent)
Ensure that the scratch images are allocated and match extent size.
Definition: comp_scratch.c:279
void comp_scratch_single_images_free(struct comp_scratch_single_images *cssi, struct vk_bundle *vk)
Free all images allocated, init must be called before calling this function, is safe to call without ...
Definition: comp_scratch.c:309
void comp_scratch_single_images_discard(struct comp_scratch_single_images *cssi)
Discard a get call, this clears the image debug part causing no image to be shown in the debug UI.
Definition: comp_scratch.c:358
The NEW compositor rendering code header.
Small helper struct to deal with indices.
Definition: comp_scratch.h:47
Holds scratch images for a single view, designed to work with render code.
Definition: comp_scratch.h:68
struct xrt_image_native native_images[(4)]
Exposed via unid.
Definition: comp_scratch.h:79
struct comp_scratch_indices indices
Keeping track of indices.
Definition: comp_scratch.h:82
struct xrt_swapchain_create_info info
Exposed via unid.
Definition: comp_scratch.h:76
xrt_limited_unique_id_t limited_unique_id
Process unique id, used for caching.
Definition: comp_scratch.h:85
struct u_native_images_debug unid
To connect to the debug UI.
Definition: comp_scratch.h:73
struct render_scratch_color_image images[(4)]
Images used when rendering.
Definition: comp_scratch.h:70
Holds scartch images for a stereo views, designed to work with render code.
Definition: comp_scratch.h:193
struct u_native_images_debug unid
Debug output for each view.
Definition: comp_scratch.h:204
struct xrt_image_native native_images[(4)]
Count always equals to the number of rsis.
Definition: comp_scratch.h:207
xrt_limited_unique_id_t limited_unique_id
Process unique id, used for caching.
Definition: comp_scratch.h:211
struct comp_scratch_indices indices
Keeping track of indices.
Definition: comp_scratch.h:199
Small helper struct to hold a scratch image, intended to be used with the compute pipeline where both...
Definition: render_interface.h:642
Helper struct to hold scratch images.
Definition: render_interface.h:653
A struct for debugging one or more native images.
Definition: u_native_images_debug.h:27
A bundle of Vulkan functions and objects, used by both Compositor and Compositor client code.
Definition: vk_helpers.h:50
A single image of a swapchain based on native buffer handles.
Definition: xrt_compositor.h:2150
A limited unique id, it is only unique for the process it is in, so must not be used or synchronized ...
Definition: xrt_defines.h:79
Swapchain creation info.
Definition: xrt_compositor.h:876
Special code for managing a variable tracked swapchain.
Common Vulkan code header.