Monado OpenXR Runtime
Loading...
Searching...
No Matches
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
81chl_frame_state_fini(struct chl_frame_state *state);
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
97chl_frame_state_gfx_set_views(struct chl_frame_state *frame_state,
98 const struct xrt_pose world_pose_scanout_begin[XRT_MAX_VIEWS],
99 const struct xrt_pose world_pose_scanout_end[XRT_MAX_VIEWS],
100 const struct xrt_pose eye_pose[XRT_MAX_VIEWS],
101 const struct xrt_fov fov[XRT_MAX_VIEWS],
102 uint32_t layer_count);
103
104/*!
105 * Adds the needed information to also perform a distortion step, reuses some
106 * information from the _set_views call and as such this needs to be called
107 * before calling this function. This is the graphics version.
108 *
109 * @memberof chl_frame_state
110 */
111void
112chl_frame_state_gfx_set_target(struct chl_frame_state *frame_state,
113 struct render_gfx_target_resources *target_rtr,
114 const struct render_viewport_data target_viewport_datas[XRT_MAX_VIEWS],
115 const render_scissor_data_t target_scissor_datas[XRT_MAX_VIEWS],
116 const struct xrt_matrix_2x2 vertex_rots[XRT_MAX_VIEWS]);
117
118/*!
119 * A single do all function, runs the default graphics pipeline.
120 *
121 * @memberof chl_frame_state
122 */
123static inline void
125 struct render_gfx *render,
126 const struct comp_layer *layers,
127 uint32_t layer_count,
128 const struct xrt_pose world_poses_scanout_begin[XRT_MAX_VIEWS],
129 const struct xrt_pose world_poses_scanout_end[XRT_MAX_VIEWS],
130 const struct xrt_pose eye_poses[XRT_MAX_VIEWS],
131 const struct xrt_fov fovs[XRT_MAX_VIEWS],
132 struct render_gfx_target_resources *target_rtr,
133 const struct render_viewport_data target_viewport_datas[XRT_MAX_VIEWS],
134 const struct xrt_matrix_2x2 vertex_rots[XRT_MAX_VIEWS])
135{
136 chl_frame_state_gfx_set_views( //
137 frame_state, //
138 world_poses_scanout_begin, //
139 world_poses_scanout_end, //
140 eye_poses, //
141 fovs, //
142 layer_count); //
143
144 chl_frame_state_gfx_set_target( //
145 frame_state, //
146 target_rtr, //
147 target_viewport_datas, //
148 target_viewport_datas, //
149 vertex_rots); //
150
151 // Start the compute pipeline.
152 render_gfx_begin(render);
153
154 // Build the command buffer.
156 render, //
157 layers, //
158 layer_count, //
159 &frame_state->data); //
160
161 // Make the command buffer submittable.
162 render_gfx_end(render);
163}
164
165
166/*
167 *
168 * Compute
169 *
170 */
171
172/*!
173 * Sets all the needed state to run the layer squasher to the scratch images,
174 * this is the compute version.
175 *
176 * @memberof chl_frame_state
177 */
178void
179chl_frame_state_cs_set_views(struct chl_frame_state *frame_state,
180 const struct xrt_pose world_pose_scanout_begin[XRT_MAX_VIEWS],
181 const struct xrt_pose world_pose_scanout_end[XRT_MAX_VIEWS],
182 const struct xrt_pose eye_pose[XRT_MAX_VIEWS],
183 const struct xrt_fov fov[XRT_MAX_VIEWS],
184 uint32_t layer_count);
185
186/*!
187 * Adds the needed information to also perform a distortion step, reuses some
188 * information from the _set_views call and as such this needs to be called
189 * before calling this function. This is the compute version.
190 *
191 * @memberof chl_frame_state
192 */
193void
194chl_frame_state_cs_set_target(struct chl_frame_state *frame_state,
195 VkImage target_image,
196 VkImageView target_storage_view,
197 const struct render_viewport_data views[XRT_MAX_VIEWS]);
198
199/*!
200 * A single do all function, runs the default compute pipeline.
201 *
202 * @memberof chl_frame_state
203 */
204static inline void
206 struct render_compute *render,
207 const struct comp_layer *layers,
208 uint32_t layer_count,
209 const struct xrt_pose world_poses_scanout_begin[XRT_MAX_VIEWS],
210 const struct xrt_pose world_poses_scanout_end[XRT_MAX_VIEWS],
211 const struct xrt_pose eye_poses[XRT_MAX_VIEWS],
212 const struct xrt_fov fovs[XRT_MAX_VIEWS],
213 VkImage target_image,
214 VkImageView target_storage_view,
215 const struct render_viewport_data target_viewport_datas[XRT_MAX_VIEWS])
216{
217 chl_frame_state_cs_set_views( //
218 frame_state, //
219 world_poses_scanout_begin, //
220 world_poses_scanout_end, //
221 eye_poses, //
222 fovs, //
223 layer_count); //
224
225 chl_frame_state_cs_set_target( //
226 frame_state, //
227 target_image, //
228 target_storage_view, //
229 target_viewport_datas); //
230
231 // Start the compute pipeline.
232 render_compute_begin(render);
233
234 // Build the command buffer.
236 render, //
237 layers, //
238 layer_count, //
239 &frame_state->data); //
240
241 // Make the command buffer submittable.
242 render_compute_end(render);
243}
244
245#ifdef __cplusplus
246}
247#endif
Higher level interface for scratch images.
Compositor render implementation.
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:479
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:445
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:810
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:901
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_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_scanout_begin[XRT_MAX_VIEWS], const struct xrt_pose world_poses_scanout_end[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:124
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_scanout_begin[XRT_MAX_VIEWS], const struct xrt_pose world_poses_scanout_end[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:205
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
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:174
The semi-low level resources and operations required to squash layers and/or apply distortion for a s...
Definition render_interface.h:1171
Each rendering (render_gfx) render to one or more targets (render_gfx_target_resources),...
Definition render_interface.h:771
The low-level resources and operations to perform layer squashing and/or mesh distortion for a single...
Definition render_interface.h:834
Holds all pools and static resources for rendering.
Definition render_interface.h:337
The pure data information about a view that the renderer is rendering to.
Definition render_interface.h:672
Describes a projection matrix fov.
Definition xrt_defines.h:512
A tightly packed 2x2 matrix of floats.
Definition xrt_defines.h:539
A pose composed of a position and orientation.
Definition xrt_defines.h:492