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 * @ingroup comp_util
95 */
96void
98
99/*!
100 * Ensure that the scratch images are allocated and match @p extent size.
101 *
102 * @ingroup comp_util
103 */
104bool
105comp_scratch_single_images_ensure(struct comp_scratch_single_images *cssi, struct vk_bundle *vk, VkExtent2D extent);
106
107/*!
108 * Free all images allocated, @p init must be called before calling this
109 * function, is safe to call without any image allocated.
110 *
111 * @ingroup comp_util
112 */
113void
115
116/*!
117 * Get the next free image, after this function has been called you must call
118 * either @p done or @p discard before calling any other function.
119 *
120 * @ingroup comp_util
121 */
122void
123comp_scratch_single_images_get(struct comp_scratch_single_images *cssi, uint32_t *out_index);
124
125/*!
126 * After calling @p get and rendering to the image you call this function to
127 * signal that you are done with this function, the GPU work needs to be fully
128 * completed before calling done.
129 *
130 * @ingroup comp_util
131 */
132void
134
135/*!
136 * Discard a @g get call, this clears the image debug part causing no image to
137 * be shown in the debug UI.
138 *
139 * @ingroup comp_util
140 */
141void
143
144/*!
145 * Clears the debug output, this causes nothing to be shown in the debug UI.
146 *
147 * @ingroup comp_util
148 */
149void
151
152/*!
153 * Destroys scratch image struct, if any images has been allocated must call
154 * @p free before as this function only destroys the mutex, and the @p unid must
155 * no longer be tracked.
156 *
157 * @ingroup comp_util
158 */
159void
161
162
163/*
164 *
165 * Stereo.
166 *
167 */
168
169/*!
170 * Holds scartch images for a stereo views, designed to work with render code.
171 * Also manages @ref xrt_image_native and @ref u_native_images_debug to
172 * facilitate easy debugging.
173 *
174 * @ingroup comp_util
175 */
177{
179
180 struct xrt_swapchain_create_info info;
181
182 //! Keeping track of indices.
184
185 struct
186 {
187 //! Debug output for each view.
189
190 //! Count always equals to the number of rsis.
192 } views[2];
193
194 //! Process unique id, used for caching.
196};
197
198void
199comp_scratch_stereo_images_init(struct comp_scratch_stereo_images *cssi);
200
201bool
202comp_scratch_stereo_images_ensure(struct comp_scratch_stereo_images *cssi, struct vk_bundle *vk, VkExtent2D extent);
203
204void
205comp_scratch_stereo_images_free(struct comp_scratch_stereo_images *cssi, struct vk_bundle *vk);
206
207void
208comp_scratch_stereo_images_get(struct comp_scratch_stereo_images *cssi, uint32_t *out_index);
209
210void
211comp_scratch_stereo_images_done(struct comp_scratch_stereo_images *cssi);
212
213void
214comp_scratch_stereo_images_discard(struct comp_scratch_stereo_images *cssi);
215
216void
217comp_scratch_stereo_images_clear_debug(struct comp_scratch_stereo_images *cssi);
218
219void
220comp_scratch_stereo_images_destroy(struct comp_scratch_stereo_images *cssi);
221
222
223#ifdef __cplusplus
224}
225#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 @g 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:177
struct u_native_images_debug unid
Debug output for each view.
Definition: comp_scratch.h:188
struct xrt_image_native native_images[(4)]
Count always equals to the number of rsis.
Definition: comp_scratch.h:191
xrt_limited_unique_id_t limited_unique_id
Process unique id, used for caching.
Definition: comp_scratch.h:195
struct comp_scratch_indices indices
Keeping track of indices.
Definition: comp_scratch.h:183
Small helper struct to hold a scratch image, intended to be used with the compute pipeline where both...
Definition: render_interface.h:637
Helper struct to hold scratch images.
Definition: render_interface.h:648
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:49
A single image of a swapchain based on native buffer handles.
Definition: xrt_compositor.h:2156
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.