···22// SPDX-License-Identifier: BSL-1.0
33/*!
44 * @file
55- * @brief Independent semaphore implementation.
55+ * @brief Compositor render implementation.
66 * @author Jakob Bornecrantz <jakob@collabora.com>
77+ * @author Rylie Pavlik <rylie.pavlik@collabora.com>
78 * @ingroup comp_util
89 */
910···2223struct comp_layer;
232424252626+/*!
2727+ * @defgroup comp_render
2828+ * @brief Renders, aka "layer squashers" and distortion application.
2929+ *
3030+ * Two parallel implementations of the render module exist:
3131+ *
3232+ * - one uses graphics shaders (aka GFX, @ref comp_render_gfx, @ref comp_render_gfx.c)
3333+ * - the other uses compute shaders (aka CS, @ref comp_render_cs, @ref comp_render_cs.c)
3434+ *
3535+ * Their abilities are effectively equivalent, although the graphics version disregards depth
3636+ * data, while the compute shader does use it somewhat.
3737+ *
3838+ * @note In general this module requires that swapchains in your supplied @ref comp_layer layers
3939+ * implement @ref comp_swapchain in addition to just @ref xrt_swapchain.
4040+ */
4141+2542/*
2643 *
2744 * Input data struct.
···2946 */
30473148/*!
3232- * The input data needed for a single view, it shared between both GFX and CS
3333- * paths. To fully render a single view two "rendering" might be needed, the
4949+ * @name Input data structs
5050+ * @{
5151+ */
5252+5353+/*!
5454+ * The input data needed for a single view, shared between both GFX and CS
5555+ * paths.
5656+ *
5757+ * To fully render a single view two "rendering" might be needed, the
3458 * first being the layer squashing, and the second is the distortion step. The
3559 * target for the layer squashing is referred to as "layer" or "scratch" and
3660 * prefixed with `layer` if needs be. The other final step is referred to as
3761 * "distortion target" or just "target", and is prefixed with `target`.
6262+ *
6363+ * @ingroup comp_render
3864 */
3965struct comp_render_view_data
4066{
···99125/*!
100126 * The input data needed for a complete layer squashing distortion rendering
101127 * to a target. This struct is shared between GFX and CS paths.
128128+ *
129129+ * @ingroup comp_render
102130 */
103131struct comp_render_dispatch_data
104132{
···113141 //! Very often true, can be disabled for debugging.
114142 bool do_timewarp;
115143144144+ //! Members used only by GFX @ref comp_render_gfx
116145 struct
117146 {
118118- // The resources needed for the target.
147147+ //! The resources needed for the target.
119148 struct render_gfx_target_resources *rtr;
120149 } gfx;
121150151151+ //! Members used only by CS @ref comp_render_cs
122152 struct
123153 {
124124- // Target image for distortion, used for barrier.
154154+ //! Target image for distortion, used for barrier.
125155 VkImage target_image;
126156127127- // Target image view for distortion.
157157+ //! Target image view for distortion.
128158 VkImageView target_unorm_view;
129159 } cs;
130160};
131161132162163163+/*! @} */
164164+133165/*
134166 *
135167 * Gfx functions.
136168 *
137169 */
138170171171+/*!
172172+ *
173173+ * @defgroup comp_render_gfx
174174+ *
175175+ * GFX renderer control and dispatch - uses graphics shaders.
176176+ *
177177+ * Depends on the common @ref comp_render_dispatch_data, as well as the resources
178178+ * @ref render_gfx_target_resources (often called `rtr`), and @ref render_gfx.
179179+ *
180180+ * @ingroup comp_render
181181+ * @{
182182+ */
183183+184184+/*!
185185+ * Initialize structure for use of the GFX renderer.
186186+ *
187187+ * @param[out] data Common render dispatch data. Will be zeroed and initialized.
188188+ * @param rtr GFX-specific resources for the entire frameedg. Must be populated before call.
189189+ * @param fast_path Whether we will use the "fast path" avoiding layer squashing.
190190+ * @param do_timewarp Whether timewarp (reprojection) will be performed.
191191+ */
139192static inline void
140193comp_render_gfx_initial_init(struct comp_render_dispatch_data *data,
141194 struct render_gfx_target_resources *rtr,
···149202 data->gfx.rtr = rtr;
150203}
151204205205+/*!
206206+ * Add view to the common data, as required by the GFX renderer.
207207+ *
208208+ * @param[in,out] data Common render dispatch data, will be updated
209209+ * @param world_pose New world pose of this view.
210210+ * Populates @ref comp_render_view_data::world_pose
211211+ * @param eye_pose New eye pose of this view
212212+ * Populates @ref comp_render_view_data::eye_pose
213213+ * @param fov Assigned to fov in the view data, and used to
214214+ * compute @ref comp_render_view_data::target_pre_transform - also
215215+ * populates @ref comp_render_view_data::fov
216216+ * @param rtr Will be associated with this view. GFX-specific
217217+ * @param layer_viewport_data Where in the image to render the view
218218+ * Populates @ref comp_render_view_data::layer_viewport_data
219219+ * @param layer_norm_rect How to transform when sampling from the scratch image.
220220+ * Populates @ref comp_render_view_data::layer_norm_rect
221221+ * @param image Scratch image for this view
222222+ * Populates @ref comp_render_view_data::image
223223+ * @param srgb_view SRGB image view into the scratch image
224224+ * Populates @ref comp_render_view_data::srgb_view
225225+ * @param vertex_rot
226226+ * @param target_viewport_data Distortion target viewport data (aka target)
227227+ * Populates @ref comp_render_view_data::target_viewport_data
228228+ */
152229static inline void
153230comp_render_gfx_add_view(struct comp_render_dispatch_data *data,
154231 const struct xrt_pose *world_pose,
···184261}
185262186263/*!
187187- * Helper function that takes a set of layers, new device poses, a scratch
264264+ * Writes the needed commands to the @ref render_gfx to do a full composition with distortion.
265265+ *
266266+ * Takes a set of layers, new device poses, scratch
188267 * images with associated @ref render_gfx_target_resources and writes the needed
189268 * commands to the @ref render_gfx to do a full composition with distortion.
190269 * The scratch images are optionally used to squash layers should it not be
···192271 * passes of the targets which set the layout.
193272 *
194273 * The render passes of @p comp_render_dispatch_data::views::rtr must be created
195195- * with a final_layout of VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL or there will
274274+ * with a final_layout of `VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL` or there will
196275 * be validation errors.
197276 *
198277 * Expected layouts:
199199- * * Layer images: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
200200- * * Scratch images: Any (as per the @ref render_gfx_render_pass)
201201- * * Target image: Any (as per the @ref render_gfx_render_pass)
278278+ *
279279+ * - Layer images: `VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL`
280280+ * - Scratch images: Any (as per the @ref render_gfx_render_pass)
281281+ * - Target image: Any (as per the @ref render_gfx_render_pass)
202282 *
203283 * After call layouts:
204204- * * Layer images: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
205205- * * Scratch images: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
206206- * * Target image: What the render pass of @p rtr specifies.
284284+ *
285285+ * - Layer images: `VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL`
286286+ * - Scratch images: `VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL`
287287+ * - Target image: What the render pass of @p rtr specifies.
207288 *
208208- * @ingroup comp_util
289289+ * @note Swapchains in the @p layers must implement @ref comp_swapchain in
290290+ * addition to just @ref xrt_swapchain, as this function downcasts to @ref comp_swapchain !
291291+ *
292292+ * @param rr GFX render object
293293+ * @param[in] layers Layers to render, see note.
294294+ * @param[in] layer_count Number of elements in @p layers array.
295295+ * @param[in] d Common render dispatch data
209296 */
210297void
211298comp_render_gfx_dispatch(struct render_gfx *rr,
···213300 const uint32_t layer_count,
214301 const struct comp_render_dispatch_data *d);
215302303303+/* end of comp_render_gfx group */
304304+305305+/*! @} */
306306+216307217308/*
218309 *
···220311 *
221312 */
222313314314+/*!
315315+ *
316316+ * @defgroup comp_render_cs
317317+ *
318318+ * CS renderer control and dispatch - uses compute shaders
319319+ *
320320+ * Depends on @ref render_compute (often called `crc`)
321321+ *
322322+ * @ingroup comp_render
323323+ * @{
324324+ */
325325+326326+/*!
327327+ * Initialize structure for use of the CS renderer.
328328+ *
329329+ * @param data Common render dispatch data. Will be zeroed and initialized.
330330+ * @param target_image Image to render into
331331+ * @param target_unorm_view Corresponding image view
332332+ * @param fast_path Whether we will use the "fast path" avoiding layer squashing.
333333+ * @param do_timewarp Whether timewarp (reprojection) will be performed.
334334+ */
223335static inline void
224336comp_render_cs_initial_init(struct comp_render_dispatch_data *data,
225337 VkImage target_image,
···236348 data->cs.target_unorm_view = target_unorm_view;
237349}
238350351351+/*!
352352+ * Add view to the common data, as required by the CS renderer.
353353+ *
354354+ * @param[in,out] data Common render dispatch data, will be updated
355355+ * @param world_pose New world pose of this view.
356356+ * Populates @ref comp_render_view_data::world_pose
357357+ * @param eye_pose New eye pose of this view
358358+ * Populates @ref comp_render_view_data::eye_pose
359359+ * @param fov Assigned to fov in the view data, and used to compute @ref comp_render_view_data::target_pre_transform
360360+ * Populates @ref comp_render_view_data::fov
361361+ * @param layer_viewport_data Where in the image to render the view
362362+ * Populates @ref comp_render_view_data::layer_viewport_data
363363+ * @param layer_norm_rect How to transform when sampling from the scratch image.
364364+ * Populates @ref comp_render_view_data::layer_norm_rect
365365+ * @param image Scratch image for this view
366366+ * Populates @ref comp_render_view_data::image
367367+ * @param srgb_view SRGB image view into the scratch image
368368+ * Populates @ref comp_render_view_data::srgb_view
369369+ * @param unorm_view UNORM image view into the scratch image, CS specific
370370+ * @param target_viewport_data Distortion target viewport data (aka target)
371371+ * Populates @ref comp_render_view_data::target_viewport_data
372372+ */
239373static inline void
240374comp_render_cs_add_view(struct comp_render_dispatch_data *data,
241375 const struct xrt_pose *world_pose,
···269403}
270404271405/*!
272272- * Helper to dispatch the layer squasher for a single view.
406406+ * Dispatch the layer squasher for a single view.
273407 *
274408 * All source layer images and target image needs to be in the correct image
275409 * layout, no barrier is inserted at all. The @p view_index argument is needed
···277411 * select left/right data from various layers.
278412 *
279413 * Expected layouts:
280280- * * Layer images: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
281281- * * Target images: VK_IMAGE_LAYOUT_GENERAL
414414+ *
415415+ * - Layer images: `VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL`
416416+ * - Target images: `VK_IMAGE_LAYOUT_GENERAL`
417417+ *
418418+ * @note Swapchains in the @p layers must implement @ref comp_swapchain in
419419+ * addition to just @ref xrt_swapchain, as this function downcasts to @ref comp_swapchain !
420420+ *
421421+ * @param crc Compute renderer object
422422+ * @param view_index Index of the view
423423+ * @param layers Layers to render, see note.
424424+ * @param layer_count Number of elements in @p layers array.
425425+ * @param pre_transform
426426+ * @param world_pose
427427+ * @param eye_pose
428428+ * @param target_image
429429+ * @param target_image_view
430430+ * @param target_view
431431+ * @param do_timewarp
282432 */
283433void
284434comp_render_cs_layer(struct render_compute *crc,
···294444 bool do_timewarp);
295445296446/*!
297297- * Helper function to dispatch the layer squasher, works on any number of views.
447447+ * Dispatch the layer squasher, on any number of views.
298448 *
299449 * All source layer images needs to be in the correct image layout, no barrier
300300- * is inserted for them. The target images are barried from undefined to general
450450+ * is inserted for them. The target images are barriered from undefined to general
301451 * so they can be written to, then to the laying defined by @p transition_to.
302452 *
303453 * Expected layouts:
304304- * * Layer images: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
305305- * * Target images: Any
454454+ *
455455+ * - Layer images: `VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL`
456456+ * - Target images: Any
306457 *
307458 * After call layouts:
308308- * * Layer images: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
309309- * * Target images: @p transition_to
459459+ *
460460+ * - Layer images: `VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL`
461461+ * - Target images: @p transition_to
462462+ *
463463+ * @note Swapchains in the @p layers must implement @ref comp_swapchain in
464464+ * addition to just @ref xrt_swapchain, as this function downcasts to @ref comp_swapchain !
310465 *
311311- * @ingroup comp_util
466466+ * @param crc Compute renderer object
467467+ * @param[in] layers Layers to render, see note.
468468+ * @param[in] layer_count Number of elements in @p layers array.
469469+ * @param[in] d Common render dispatch data
470470+ * @param[in] transition_to Desired image layout for target images
312471 */
313472void
314473comp_render_cs_layers(struct render_compute *crc,
···318477 VkImageLayout transition_to);
319478320479/*!
480480+ * Write commands to @p crc to do a full composition with distortion.
481481+ *
321482 * Helper function that takes a set of layers, new device poses, a scratch
322483 * images and writes the needed commands to the @ref render_compute to do a full
323484 * composition with distortion. The scratch images are optionally used to squash
···326487 *
327488 *
328489 * Expected layouts:
329329- * * Layer images: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
330330- * * Scratch images: Any
331331- * * Target image: Any
490490+ *
491491+ * - Layer images: `VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL`
492492+ * - Scratch images: Any
493493+ * - Target image: Any
332494 *
333495 * After call layouts:
334334- * * Layer images: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
335335- * * Scratch images: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
336336- * * Target image: VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
496496+ *
497497+ * - Layer images: `VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL`
498498+ * - Scratch images: `VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL`
499499+ * - Target image: `VK_IMAGE_LAYOUT_PRESENT_SRC_KHR`
500500+ *
501501+ * @note Swapchains in the @p layers must implement @ref comp_swapchain in
502502+ * addition to just @ref xrt_swapchain, as this function downcasts to @ref comp_swapchain !
337503 *
338338- * @ingroup comp_util
504504+ * @param crc Compute renderer object
505505+ * @param[in] layers Layers to render, see note.
506506+ * @param[in] layer_count Number of elements in @p layers array.
507507+ * @param[in] d Common render dispatch data
508508+ *
339509 */
340510void
341511comp_render_cs_dispatch(struct render_compute *crc,
···343513 const uint32_t layer_count,
344514 const struct comp_render_dispatch_data *d);
345515516516+/* end of comp_render_cs group */
517517+/*! @} */
346518347519#ifdef __cplusplus
348520}