Monado OpenXR Runtime
comp_high_level_render.h
Go to the documentation of this file.
1// Copyright 2019-2024, Collabora, Ltd.
2// Copyright 2024-2025, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Higher level interface for rendering a frame.
7 * @author Jakob Bornecrantz <tbornecrantz@nvidia.com>
8 * @author Christoph Haag <christoph.haag@collabora.com>
9 * @author Fernando Velazquez Innella <finnella@magicleap.com>
10 * @author Rylie Pavlik <rylie.pavlik@collabora.com>
11 * @ingroup comp_util
12 */
13
14#pragma once
15
16
18
19#include "comp_render.h"
21
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27
28/*!
29 * Encapsulates all the needed state to run the layer squasher and distortion
30 * passes, state object needs to be kept alive until the GPU work finishes.
31 * None of the functions are thread safe so make sure to synchronize access.
32 *
33 * The lifetime of this struct is one frame, but as stated above it needs to
34 * live for long enough that the GPU work has been finished.
35 *
36 * @comp_util
37 */
39{
40 struct chl_scratch *scratch;
41
42 uint32_t view_count;
43
44 struct chl_scratch_state scratch_state;
45
46 struct comp_render_dispatch_data data;
47
48 struct render_compute cs;
49};
50
51
52/*
53 *
54 * Shared functions.
55 *
56 */
57
58/*!
59 * Create the Vulkan resources using the given @p render_resources and the
60 * @p vk_bundle it refers to. Is used for both graphics and compute paths,
61 * also manages the scratch state.
62 *
63 * @memberof chl_frame_state
64 */
65void
66chl_frame_state_init(struct chl_frame_state *frame_state,
67 struct render_resources *rr,
68 uint32_t view_count,
69 bool do_timewarp,
70 bool fast_path,
71 struct chl_scratch *scratch);
72
73/*!
74 * Frees all resources that this frame state tracks and manages the scratch
75 * images state. Must be called after the GPU work has finished and has been
76 * waited on (or the validation layer gets upset).
77 *
78 * @memberof chl_frame_state
79 */
80void
82
83
84/*
85 *
86 * Graphics.
87 *
88 */
89
90/*!
91 * Sets all the needed state to run the layer squasher to the scratch images,
92 * this is the graphics version.
93 *
94 * @memberof chl_frame_state
95 */
96void
98 const struct xrt_pose world_pose[XRT_MAX_VIEWS],
99 const struct xrt_pose eye_pose[XRT_MAX_VIEWS],
100 const struct xrt_fov fov[XRT_MAX_VIEWS],
101 uint32_t layer_count);
102
103/*!
104 * Adds the needed information to also perform a distortion step, reuses some
105 * information from the _set_views call and as such this needs to be called
106 * before calling this function. This is the graphics version.
107 *
108 * @memberof chl_frame_state
109 */
110void
112 struct render_gfx_target_resources *target_rtr,
113 const struct render_viewport_data target_viewport_datas[XRT_MAX_VIEWS],
114 const struct xrt_matrix_2x2 vertex_rots[XRT_MAX_VIEWS]);
115
116/*!
117 * A single do all function, runs the default graphics pipeline.
118 *
119 * @memberof chl_frame_state
120 */
121static inline void
123 struct render_gfx *render,
124 const struct comp_layer *layers,
125 uint32_t layer_count,
126 const struct xrt_pose world_poses[XRT_MAX_VIEWS],
127 const struct xrt_pose eye_poses[XRT_MAX_VIEWS],
128 const struct xrt_fov fovs[XRT_MAX_VIEWS],
129 struct render_gfx_target_resources *target_rtr,
130 const struct render_viewport_data target_viewport_datas[XRT_MAX_VIEWS],
131 const struct xrt_matrix_2x2 vertex_rots[XRT_MAX_VIEWS])
132{
134 frame_state, //
135 world_poses, //
136 eye_poses, //
137 fovs, //
138 layer_count); //
139
141 frame_state, //
142 target_rtr, //
143 target_viewport_datas, //
144 vertex_rots); //
145
146 // Start the compute pipeline.
147 render_gfx_begin(render);
148
149 // Build the command buffer.
151 render, //
152 layers, //
153 layer_count, //
154 &frame_state->data); //
155
156 // Make the command buffer submittable.
157 render_gfx_end(render);
158}
159
160
161/*
162 *
163 * Compute
164 *
165 */
166
167/*!
168 * Sets all the needed state to run the layer squasher to the scratch images,
169 * this is the compute version.
170 *
171 * @memberof chl_frame_state
172 */
173void
175 const struct xrt_pose world_pose[XRT_MAX_VIEWS],
176 const struct xrt_pose eye_pose[XRT_MAX_VIEWS],
177 const struct xrt_fov fov[XRT_MAX_VIEWS],
178 uint32_t layer_count);
179
180/*!
181 * Adds the needed information to also perform a distortion step, reuses some
182 * information from the _set_views call and as such this needs to be called
183 * before calling this function. This is the compute version.
184 *
185 * @memberof chl_frame_state
186 */
187void
189 VkImage target_image,
190 VkImageView target_storage_view,
191 const struct render_viewport_data views[XRT_MAX_VIEWS]);
192
193/*!
194 * A single do all function, runs the default compute pipeline.
195 *
196 * @memberof chl_frame_state
197 */
198static inline void
200 struct render_compute *render,
201 const struct comp_layer *layers,
202 uint32_t layer_count,
203 const struct xrt_pose world_poses[XRT_MAX_VIEWS],
204 const struct xrt_pose eye_poses[XRT_MAX_VIEWS],
205 const struct xrt_fov fovs[XRT_MAX_VIEWS],
206 VkImage target_image,
207 VkImageView target_storage_view,
208 const struct render_viewport_data target_viewport_datas[XRT_MAX_VIEWS])
209{
211 frame_state, //
212 world_poses, //
213 eye_poses, //
214 fovs, //
215 layer_count); //
216
218 frame_state, //
219 target_image, //
220 target_storage_view, //
221 target_viewport_datas); //
222
223 // Start the compute pipeline.
224 render_compute_begin(render);
225
226 // Build the command buffer.
228 render, //
229 layers, //
230 layer_count, //
231 &frame_state->data); //
232
233 // Make the command buffer submittable.
234 render_compute_end(render);
235}
236
237#ifdef __cplusplus
238}
239#endif
Higher level interface for scratch images.
Compositor render implementation.
void comp_render_cs_dispatch(struct render_compute *render, const struct comp_layer *layers, const uint32_t layer_count, const struct comp_render_dispatch_data *d)
Write commands to render to do a full composition with distortion.
Definition: comp_render_cs.c:717
void comp_render_gfx_dispatch(struct render_gfx *render, const struct comp_layer *layers, const uint32_t layer_count, const struct comp_render_dispatch_data *d)
Writes the needed commands to the render_gfx to do a full composition with distortion.
Definition: comp_render_gfx.c:884
bool render_gfx_end(struct render_gfx *render)
Frees any unneeded resources and ends the command buffer so it can be used, also unlocks the vk_bundl...
Definition: render_gfx.c:1007
bool render_compute_end(struct render_compute *render)
Frees any unneeded resources and ends the command buffer so it can be used, also unlocks the vk_bundl...
Definition: render_compute.c:356
bool render_gfx_begin(struct render_gfx *render)
Begins the rendering, takes the vk_bundle's pool lock and leaves it locked.
Definition: render_gfx.c:972
bool render_compute_begin(struct render_compute *render)
Begin the compute command buffer building, takes the vk_bundle's pool lock and leaves it locked.
Definition: render_compute.c:322
The NEW compositor rendering code header.
Encapsulates all the needed state to run the layer squasher and distortion passes,...
Definition: comp_high_level_render.h:39
static void chl_frame_state_cs_default_pipeline(struct chl_frame_state *frame_state, struct render_compute *render, const struct comp_layer *layers, uint32_t layer_count, const struct xrt_pose world_poses[XRT_MAX_VIEWS], const struct xrt_pose eye_poses[XRT_MAX_VIEWS], const struct xrt_fov fovs[XRT_MAX_VIEWS], VkImage target_image, VkImageView target_storage_view, const struct render_viewport_data target_viewport_datas[XRT_MAX_VIEWS])
A single do all function, runs the default compute pipeline.
Definition: comp_high_level_render.h:199
void chl_frame_state_gfx_set_views(struct chl_frame_state *frame_state, const struct xrt_pose world_pose[XRT_MAX_VIEWS], const struct xrt_pose eye_pose[XRT_MAX_VIEWS], const struct xrt_fov fov[XRT_MAX_VIEWS], uint32_t layer_count)
Sets all the needed state to run the layer squasher to the scratch images, this is the graphics versi...
Definition: comp_high_level_render.c:67
void chl_frame_state_cs_set_views(struct chl_frame_state *frame_state, const struct xrt_pose world_pose[XRT_MAX_VIEWS], const struct xrt_pose eye_pose[XRT_MAX_VIEWS], const struct xrt_fov fov[XRT_MAX_VIEWS], uint32_t layer_count)
Sets all the needed state to run the layer squasher to the scratch images, this is the compute versio...
Definition: comp_high_level_render.c:149
void chl_frame_state_init(struct chl_frame_state *frame_state, struct render_resources *rr, uint32_t view_count, bool do_timewarp, bool fast_path, struct chl_scratch *scratch)
Create the Vulkan resources using the given render_resources and the vk_bundle it refers to.
Definition: comp_high_level_render.c:24
void chl_frame_state_gfx_set_target(struct chl_frame_state *frame_state, struct render_gfx_target_resources *target_rtr, const struct render_viewport_data target_viewport_datas[XRT_MAX_VIEWS], const struct xrt_matrix_2x2 vertex_rots[XRT_MAX_VIEWS])
Adds the needed information to also perform a distortion step, reuses some information from the _set_...
Definition: comp_high_level_render.c:112
void chl_frame_state_fini(struct chl_frame_state *state)
Frees all resources that this frame state tracks and manages the scratch images state.
Definition: comp_high_level_render.c:48
static void chl_frame_state_gfx_default_pipeline(struct chl_frame_state *frame_state, struct render_gfx *render, const struct comp_layer *layers, uint32_t layer_count, const struct xrt_pose world_poses[XRT_MAX_VIEWS], const struct xrt_pose eye_poses[XRT_MAX_VIEWS], const struct xrt_fov fovs[XRT_MAX_VIEWS], struct render_gfx_target_resources *target_rtr, const struct render_viewport_data target_viewport_datas[XRT_MAX_VIEWS], const struct xrt_matrix_2x2 vertex_rots[XRT_MAX_VIEWS])
A single do all function, runs the default graphics pipeline.
Definition: comp_high_level_render.h:122
void chl_frame_state_cs_set_target(struct chl_frame_state *frame_state, VkImage target_image, VkImageView target_storage_view, const struct render_viewport_data views[XRT_MAX_VIEWS])
Adds the needed information to also perform a distortion step, reuses some information from the _set_...
Definition: comp_high_level_render.c:193
Used to track the index of images gotten for the images, and if it has been used.
Definition: comp_high_level_scratch.h:155
Scratch images that can be used for staging buffers.
Definition: comp_high_level_scratch.h:29
uint32_t view_count
Number of views that has been ensured and have Vulkan resources, all comp_scratch_single_images are a...
Definition: comp_high_level_scratch.h:46
A single layer in a comp_layer_accum.
Definition: comp_layer_accum.h:36
struct xrt_layer_data data
All basic (trivially-serializable) data associated with a layer.
Definition: comp_layer_accum.h:47
The input data needed for a complete layer squashing distortion rendering to a target.
Definition: comp_render.h:164
The semi-low level resources and operations required to squash layers and/or apply distortion for a s...
Definition: render_interface.h:1166
Each rendering (render_gfx) render to one or more targets (render_gfx_target_resources),...
Definition: render_interface.h:785
The low-level resources and operations to perform layer squashing and/or mesh distortion for a single...
Definition: render_interface.h:848
Holds all pools and static resources for rendering.
Definition: render_interface.h:352
The pure data information about a view that the renderer is rendering to.
Definition: render_interface.h:687
Describes a projection matrix fov.
Definition: xrt_defines.h:483
A tightly packed 2x2 matrix of floats.
Definition: xrt_defines.h:510
A pose composed of a position and orientation.
Definition: xrt_defines.h:463