Monado OpenXR Runtime
render_interface.h
Go to the documentation of this file.
1// Copyright 2019-2023, Collabora, Ltd.
2// Copyright 2025, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief The NEW compositor rendering code header.
7 * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
8 * @author Jakob Bornecrantz <jakob@collabora.com>
9 * @ingroup comp_render
10 */
11
12#pragma once
13
14#include "xrt/xrt_compiler.h"
15#include "xrt/xrt_defines.h"
16
17#include "vk/vk_helpers.h"
18#include "vk/vk_cmd_pool.h"
19
21
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27
28/*!
29 * @defgroup comp_render Compositor render code
30 * @ingroup comp
31 *
32 * @brief Rendering helper that is used by the compositor to render.
33 */
34
35/*!
36 * @addtogroup comp_render
37 * @{
38 */
39
40/*
41 *
42 * Defines
43 *
44 */
45
46/*!
47 * The value `minUniformBufferOffsetAlignment` is defined by the Vulkan spec as
48 * having a max value of 256. Use this value to safely figure out sizes and
49 * alignment of UBO sub-allocation. It is also the max for 'nonCoherentAtomSize`
50 * which if we need to do flushing is what we need to align UBOs to.
51 *
52 * https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkPhysicalDeviceLimits.html
53 * https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#limits-minmax
54 */
55#define RENDER_ALWAYS_SAFE_UBO_ALIGNMENT (256)
56
57/*!
58 * Max number of layers for layer squasher, can be different from
59 * @ref XRT_MAX_LAYERS as the render module is separate from the compositor.
60 */
61#define RENDER_MAX_LAYERS (XRT_MAX_LAYERS)
62
63/*!
64 * The maximum number samplers per view that can be used by the compute shader
65 * for layer composition (layer.comp)
66 */
67#define RENDER_CS_MAX_SAMPLERS_PER_VIEW 2
68
69/*!
70 * Max number of images that can be given at a single time to the layer
71 * squasher in a single dispatch.
72 */
73#define RENDER_MAX_IMAGES_SIZE (RENDER_MAX_LAYERS * RENDER_CS_MAX_SAMPLERS_PER_VIEW)
74
75/*!
76 * Maximum number of times that the layer squasher shader can run per
77 * @ref render_compute. Since you run the layer squasher shader once per view
78 * this is essentially the same as number of views. But if you were to do
79 * two or more different compositions it is not the maximum number of views per
80 * composition (which is this number divided by number of composition).
81 */
82#define RENDER_MAX_LAYER_RUNS_SIZE (XRT_MAX_VIEWS)
83#define RENDER_MAX_LAYER_RUNS_COUNT(RENDER_RESOURCES) (RENDER_RESOURCES->view_count)
84
85//! Distortion image dimension in pixels
86#define RENDER_DISTORTION_IMAGE_DIMENSIONS (128)
87
88//! How many distortion images we have, one for each channel (3 rgb) and per view.
89#define RENDER_DISTORTION_IMAGES_SIZE (3 * XRT_MAX_VIEWS)
90#define RENDER_DISTORTION_IMAGES_COUNT(RENDER_RESOURCES) (3 * RENDER_RESOURCES->view_count)
91
92//! The binding that the layer projection and quad shader have their UBO on.
93#define RENDER_BINDING_LAYER_SHARED_UBO 0
94
95//! The binding that the shared layer fragment shader has its source on.
96#define RENDER_BINDING_LAYER_SHARED_SRC 1
97
98/*!
99 * The maximum number samplers per view that can be used by the compute shader
100 * for layer composition (layer.comp)
101 */
102#define RENDER_CS_MAX_SAMPLERS_PER_VIEW 2
103
104/*
105 *
106 * Util functions.
107 *
108 */
109
110/*!
111 * Determines the maximum number of compositor layers supported based on Vulkan
112 * device limits and the composition path being used.
113 *
114 * @param vk Vulkan bundle containing device properties
115 * @param use_compute True if using compute pipeline path, false for graphics
116 * @param desired_max_layers Maximum layers requested by the compositor
117 * @return Actual maximum layers supported, clamped by device limits (minimum 16)
118 *
119 */
120uint32_t
121render_max_layers_capable(const struct vk_bundle *vk, bool use_compute, uint32_t desired_max_layers);
122
123/*!
124 * Create a simplified projection matrix for timewarp.
125 */
126void
127render_calc_time_warp_projection(const struct xrt_fov *fov, struct xrt_matrix_4x4 *result);
128
129/*!
130 * Calculates a timewarp matrix which takes in NDC coords and gives out results
131 * in [-1, 1] space that needs a perspective divide.
132 */
133void
134render_calc_time_warp_matrix(const struct xrt_pose *src_pose,
135 const struct xrt_fov *src_fov,
136 const struct xrt_pose *new_pose,
137 struct xrt_matrix_4x4 *matrix);
138
139/*!
140 * This function constructs a transformation in the form of a normalized rect
141 * that lets you go from a UV coordinate on a projection plane to the a point on
142 * the tangent plane. An example is that the UV coordinate `(0, 0)` would be
143 * transformed to `(tan(angle_left), tan(fov.angle_up))`. The tangent plane (aka
144 * tangent space) is really the tangent of the angle, aka length at unit distance.
145 *
146 * For the trivial case of an fov with 45 degrees angles, that is where the
147 * tangent length are `1` (aka `tan(45)`), the transformation would go from
148 * `[0 .. 1]` to `[-1 .. 1]` the expected returns are `x = -1`, `y = -1`,
149 * `w = 2` and `h = 2`.
150 *
151 * param fov The fov of the projection image.
152 * param[out] out_rect Transformation from UV to tangent lengths.
153 */
154void
155render_calc_uv_to_tangent_lengths_rect(const struct xrt_fov *fov, struct xrt_normalized_rect *out_rect);
156
157
158/*
159 *
160 * Buffer
161 *
162 */
163
164/*!
165 * Helper struct holding a buffer and its memory.
166 */
168{
169 //! Backing memory.
170 VkDeviceMemory memory;
171
172 //! Buffer.
173 VkBuffer buffer;
174
175 //! Size requested for the buffer.
176 VkDeviceSize size;
177
178 //! Size of the memory allocation.
179 VkDeviceSize allocation_size;
180
181 //! Alignment of the buffer.
182 VkDeviceSize alignment;
183
184 void *mapped;
185};
186
187/*!
188 * Initialize a buffer.
189 */
190VkResult
192 struct render_buffer *buffer,
193 VkBufferUsageFlags usage_flags,
194 VkMemoryPropertyFlags memory_property_flags,
195 VkDeviceSize size);
196
197/*!
198 * Initialize a buffer, making it exportable.
199 */
200VkResult
202 struct render_buffer *buffer,
203 VkBufferUsageFlags usage_flags,
204 VkMemoryPropertyFlags memory_property_flags,
205 VkDeviceSize size);
206
207/*!
208 * Frees all resources that this buffer has, but does not free the buffer itself.
209 */
210void
211render_buffer_fini(struct vk_bundle *vk, struct render_buffer *buffer);
212
213/*!
214 * Maps the memory, sets render_buffer::mapped to the memory.
215 */
216VkResult
217render_buffer_map(struct vk_bundle *vk, struct render_buffer *buffer);
218
219/*!
220 * Unmaps the memory.
221 */
222void
223render_buffer_unmap(struct vk_bundle *vk, struct render_buffer *buffer);
224
225/*!
226 * Maps the buffer, and copies the given data to the buffer.
227 */
228VkResult
229render_buffer_map_and_write(struct vk_bundle *vk, struct render_buffer *buffer, void *data, VkDeviceSize size);
230
231/*!
232 * Writes the given data to the buffer, will map it temporarily if not mapped.
233 */
234VkResult
235render_buffer_write(struct vk_bundle *vk, struct render_buffer *buffer, void *data, VkDeviceSize size);
236
237
238/*
239 *
240 * Sub-alloc.
241 *
242 */
243
244/*!
245 * Per frame sub-allocation into a buffer, used to reduce the number of UBO
246 * objects we need to create. There is no way to free a sub-allocation, this is
247 * done implicitly at the end of the frame when @ref render_sub_alloc_tracker is
248 * zeroed out.
249 *
250 * @see render_sub_alloc_tracker
251 */
253{
254 /*!
255 * The buffer this is allocated from, it is the caller's responsibility
256 * to keep it alive for as long as the sub-allocation is used.
257 */
258 VkBuffer buffer;
259
260 //! Size of sub-allocation.
261 VkDeviceSize size;
262
263 //! Offset into buffer.
264 VkDeviceSize offset;
265};
266
267/*!
268 * A per-frame tracker of sub-allocation out of a buffer, used to reduce the
269 * number of UBO objects we need to create. This code is designed with one
270 * constraint in mind, that the lifetime of a sub-allocation is only for one
271 * frame and is discarded at the end of it, but also alive for the entire frame.
272 * This removes the need to free individual sub-allocation, or even track them
273 * beyond filling the UBO data and descriptor sets.
274 *
275 * @see render_sub_alloc
276 */
278{
279 /*!
280 * The buffer to allocate from, it is the caller's responsibility to keep
281 * it alive for as long as the sub-allocations are in used.
282 */
283 VkBuffer buffer;
284
285 //! Start of memory, if buffer was mapped with initialised.
286 void *mapped;
287
288 //! Total size of buffer.
289 VkDeviceSize total_size;
290
291 //! Currently used memory.
292 VkDeviceSize used;
293};
294
295/*!
296 * Init a @ref render_sub_alloc_tracker struct from a @ref render_buffer, the
297 * caller is responsible for keeping @p buffer alive while the sub allocator
298 * is being used.
299 */
300void
302
303/*!
304 * Allocate enough memory (with constraints of UBOs) of @p size, return the
305 * pointer to the mapped memory or null if the buffer wasn't allocated.
306 */
307XRT_CHECK_RESULT VkResult
309 struct render_sub_alloc_tracker *rsat,
310 VkDeviceSize size,
311 void **out_ptr,
312 struct render_sub_alloc *out_rsa);
313
314/*!
315 * Allocate enough memory (with constraints of UBOs) to hold the memory in @p ptr
316 * and copy that memory to the buffer using the CPU.
317 */
318XRT_CHECK_RESULT VkResult
320 struct render_sub_alloc_tracker *rsat,
321 const void *ptr,
322 VkDeviceSize size,
323 struct render_sub_alloc *out_rsa);
324
325
326/*
327 *
328 * Resources
329 *
330 */
331
332/*!
333 * Holds all pools and static resources for rendering.
334 */
336{
337 //! The count of views that we are rendering to.
338 uint32_t view_count;
339
340 //! Vulkan resources.
341 struct vk_bundle *vk;
342
343 /*
344 * Loaded resources.
345 */
346
347 //! All shaders loaded.
349
350
351 /*
352 * Shared pools and caches.
353 */
354
355 //! Pool used for distortion image uploads.
357
358 //! Shared for all rendering.
359 VkPipelineCache pipeline_cache;
360
361 VkCommandPool cmd_pool;
362
363 VkQueryPool query_pool;
364
365
366 /*
367 * Static
368 */
369
370 //! Command buffer for recording everything.
371 VkCommandBuffer cmd;
372
373 struct
374 {
375 //! Sampler for mock/null images.
376 VkSampler mock;
377
378 //! Sampler that repeats the texture in all directions.
379 VkSampler repeat;
380
381 //! Sampler that clamps the coordinates to the edge in all directions.
382 VkSampler clamp_to_edge;
383
384 //! Sampler that clamps color samples to black in all directions.
386 } samplers;
387
388 struct
389 {
390 //! Pool for shaders that uses one ubo and sampler.
392
393 /*!
394 * Shared UBO buffer that we sub-allocate out of, this is to
395 * have fewer buffers that the kernel needs to validate on
396 * command submission time.
397 *
398 * https://registry.khronos.org/vulkan/site/guide/latest/memory_allocation.html
399 */
401
402 struct
403 {
404 struct
405 {
406 //! For projection and quad layer.
407 VkDescriptorSetLayout descriptor_set_layout;
408
409 //! For projection and quad layer.
410 VkPipelineLayout pipeline_layout;
411 } shared;
412 } layer;
413 } gfx;
414
415 struct
416 {
417 //! The binding index for the source texture.
418 uint32_t src_binding;
419
420 //! The binding index for the UBO.
421 uint32_t ubo_binding;
422
423 //! Descriptor set layout for mesh distortion.
424 VkDescriptorSetLayout descriptor_set_layout;
425
426 //! Pipeline layout used for mesh.
427 VkPipelineLayout pipeline_layout;
428
429 struct render_buffer vbo;
430 struct render_buffer ibo;
431
432 uint32_t vertex_count;
433 uint32_t index_counts[XRT_MAX_VIEWS];
434 uint32_t stride;
435 uint32_t index_offsets[XRT_MAX_VIEWS];
436 uint32_t index_count_total;
437
438 //! Info UBOs.
439 struct render_buffer ubos[XRT_MAX_VIEWS];
440 } mesh;
441
442 /*!
443 * Used as a default image empty image when none is given or to pad
444 * out fixed sized descriptor sets.
445 */
446 struct
447 {
448 struct
449 {
450 VkImage image;
451 VkImageView image_view;
452 VkDeviceMemory memory;
453 } color;
455
456 struct
457 {
458 //! Descriptor pool for compute work.
459 VkDescriptorPool descriptor_pool;
460
461 //! The source projection view binding point.
462 uint32_t src_binding;
463
464 //! Image storing the distortion.
466
467 //! Writing the image out too.
469
470 //! Uniform data binding.
471 uint32_t ubo_binding;
472
473 struct
474 {
475 //! Descriptor set layout for compute.
476 VkDescriptorSetLayout descriptor_set_layout;
477
478 //! Pipeline layout used for compute distortion.
479 VkPipelineLayout pipeline_layout;
480
481 //! Doesn't depend on target so is static.
483
484 //! Doesn't depend on target so is static.
486
487 //! Size of combined image sampler array
489
490 //! Target info.
492 } layer;
493
494 struct
495 {
496 //! Descriptor set layout for compute distortion.
497 VkDescriptorSetLayout descriptor_set_layout;
498
499 //! Pipeline layout used for compute distortion, shared with clear.
500 VkPipelineLayout pipeline_layout;
501
502 //! Doesn't depend on target so is static.
503 VkPipeline pipeline;
504
505 //! Doesn't depend on target so is static.
506 VkPipeline timewarp_pipeline;
507
508 //! Target info.
510 } distortion;
511
512 struct
513 {
514 //! Doesn't depend on target so is static.
515 VkPipeline pipeline;
516
517 //! Target info.
518 struct render_buffer ubo;
519
520 //! @todo other resources
521 } clear;
522 } compute;
523
524 struct
525 {
526 //! Transform to go from UV to tangle angles.
527 struct xrt_normalized_rect uv_to_tanangle[XRT_MAX_VIEWS];
528
529 //! Backing memory to distortion images.
531
532 //! Distortion images.
534
535 //! The views into the distortion images.
537
538 //! Whether distortion images have been pre-rotated 90 degrees.
540 } distortion;
541};
542
543/*!
544 * Allocate pools and static resources.
545 *
546 * @ingroup comp_main
547 *
548 * @public @memberof render_resources
549 */
550bool
552 struct render_shaders *shaders,
553 struct vk_bundle *vk,
554 struct xrt_device *xdev);
555
556/*!
557 * Free all pools and static resources, does not free the struct itself.
558 *
559 * @public @memberof render_resources
560 */
561void
563
564/*!
565 * Creates or recreates the compute distortion textures if necessary.
566 *
567 * @see render_distortion_images_fini
568 * @public @memberof render_resources
569 */
570bool
572 struct vk_bundle *vk,
573 struct xrt_device *xdev,
574 bool pre_rotate);
575
576/*!
577 * Free distortion images.
578 *
579 * @see render_distortion_images_ensure
580 * @public @memberof render_resources
581 */
582void
584
585/*!
586 * Returns the timestamps for when the latest GPU work started and stopped that
587 * was submitted using @ref render_gfx or @ref render_compute cmd buf builders.
588 *
589 * Returned in the same time domain as returned by @ref os_monotonic_get_ns .
590 * Behaviour for this function is undefined if the GPU has not completed before
591 * calling this function, so make sure to call vkQueueWaitIdle or wait on the
592 * fence that the work was submitted with have fully completed. See other
593 * limitation mentioned for @ref vk_convert_timestamps_to_host_ns .
594 *
595 * @see vk_convert_timestamps_to_host_ns
596 *
597 * @public @memberof render_resources
598 */
599bool
600render_resources_get_timestamps(struct render_resources *r, uint64_t *out_gpu_start_ns, uint64_t *out_gpu_end_ns);
601
602/*!
603 * Returns the duration for the latest GPU work that was submitted using
604 * @ref render_gfx or @ref render_compute cmd buf builders.
605 *
606 * Behaviour for this function is undefined if the GPU has not completed before
607 * calling this function, so make sure to call vkQueueWaitIdle or wait on the
608 * fence that the work was submitted with have fully completed.
609 *
610 * @public @memberof render_resources
611 */
612bool
613render_resources_get_duration(struct render_resources *r, uint64_t *out_gpu_duration_ns);
614
615
616/*
617 *
618 * Scratch images.
619 *
620 */
621
622/*!
623 * Small helper struct to hold a scratch image, intended to be used with the
624 * compute pipeline where both srgb and unorm views are needed.
625 */
627{
628 VkDeviceMemory device_memory;
629 VkImage image;
630 VkImageView srgb_view;
631 VkImageView unorm_view;
632};
633
634/*!
635 * Helper struct to hold scratch images.
636 */
638{
639 VkExtent2D extent;
640
641 struct render_scratch_color_image color[XRT_MAX_VIEWS];
642};
643
644/*!
645 * Ensure that the scratch images are created and have the given extent.
646 *
647 * @public @memberof render_scratch_images
648 */
649bool
650render_scratch_images_ensure(struct render_resources *r, struct render_scratch_images *rsi, VkExtent2D extent);
651
652/*!
653 * Close all resources on the given @ref render_scratch_images.
654 *
655 * @public @memberof render_scratch_images
656 */
657void
659
660
661/*
662 *
663 * Shared between both gfx and compute.
664 *
665 */
666
667/*!
668 * The pure data information about a view that the renderer is rendering to.
669 */
671{
672 uint32_t x, y;
673 uint32_t w, h;
674};
675
676
677/*
678 *
679 * Render pass
680 *
681 */
682
683/*!
684 * A render pass, while not depending on a @p VkFramebuffer, does depend on the
685 * format of the target image(s), and other options for the render pass. These
686 * are used to create a @p VkRenderPass, all @p VkFramebuffer(s) and
687 * @p VkPipeline depends on the @p VkRenderPass so hang off this struct.
688 */
690{
691 struct render_resources *r;
692
693 //! The format of the image(s) we are rendering to.
694 VkFormat format;
695
696 //! Sample count for this render pass.
697 VkSampleCountFlagBits sample_count;
698
699 //! Load op used on the attachment(s).
700 VkAttachmentLoadOp load_op;
701
702 //! Final layout of the target image(s).
703 VkImageLayout final_layout;
704
705 //! Render pass used for rendering.
706 VkRenderPass render_pass;
707
708 struct
709 {
710 //! Pipeline layout used for mesh, without timewarp.
711 VkPipeline pipeline;
712
713 //! Pipeline layout used for mesh, with timewarp.
715 } mesh;
716
717 struct
718 {
719 VkPipeline cylinder_premultiplied_alpha;
720 VkPipeline cylinder_unpremultiplied_alpha;
721
722 VkPipeline equirect2_premultiplied_alpha;
723 VkPipeline equirect2_unpremultiplied_alpha;
724
725 VkPipeline proj_premultiplied_alpha;
726 VkPipeline proj_unpremultiplied_alpha;
727
728 VkPipeline quad_premultiplied_alpha;
729 VkPipeline quad_unpremultiplied_alpha;
730 } layer;
731};
732
733/*!
734 * Creates all resources held by the render pass.
735 *
736 * @public @memberof render_gfx_render_pass
737 */
738bool
740 struct render_resources *r,
741 VkFormat format,
742 VkAttachmentLoadOp load_op,
743 VkImageLayout final_layout);
744
745/*!
746 * Frees all resources held by the render pass, does not free the struct itself.
747 *
748 * @public @memberof render_gfx_render_pass
749 */
750void
752
753
754/*
755 *
756 * Rendering target
757 *
758 */
759
760/*!
761 * Each rendering (@ref render_gfx) render to one or more targets
762 * (@ref render_gfx_target_resources), the target points to one render pass and
763 * its pipelines (@ref render_gfx_render_pass). It is up to the code using
764 * these to do reuse of render passes and ensure they match.
765 *
766 * @see comp_render_gfx
767 */
769{
770 //! Collections of static resources.
772
773 //! Render pass.
775
776 // The extent of the framebuffer.
777 VkExtent2D extent;
778
779 //! Framebuffer for this target, depends on given VkImageView.
780 VkFramebuffer framebuffer;
781};
782
783/*!
784 * Init a target resource struct, caller has to keep target alive until closed.
785 *
786 * @public @memberof render_gfx_target_resources
787 */
788bool
790 struct render_resources *r,
791 struct render_gfx_render_pass *rgrp,
792 VkImageView target,
793 VkExtent2D extent);
794
795/*!
796 * Frees all resources held by the target, does not free the struct itself.
797 *
798 * @public @memberof render_gfx_target_resources
799 */
800void
802
803
804/*
805 *
806 * Rendering
807 *
808 */
809
810/*!
811 * The low-level resources and operations to perform layer squashing and/or
812 * mesh distortion for a single frame using graphics shaders.
813 *
814 * It uses a two-stage process to render a frame. This means
815 * consumers iterate layers (or other operations) **twice**, within each target and view.
816 * There is a preparation stage, where the uniform buffer is sub-allocated and written.
817 * This must be completed for all layers before the actual draw stage begins.
818 * The second stage is recording the draw commands into a command buffer.
819 *
820 * You must make equivalent calls in the same order between the two stages. The second stage
821 * additionally has @ref render_gfx_begin_target, @ref render_gfx_end_target,
822 * @ref render_gfx_begin_view, and @ref render_gfx_end_view lacked by the first stage,
823 * but if you exclude those functions, the others must line up.
824 *
825 * Furthermore, the struct needs to be kept alive until the work has been waited on,
826 * or you get validation warnings. Either wait on the `VkFence` for the submit, or call
827 * `vkDeviceWaitIdle`/`vkQueueWaitIdle` on the device/queue.
828 *
829 * @see comp_render_gfx
830 */
832{
833 //! Resources that we are based on.
835
836 //! Shared buffer that we sub-allocate UBOs from.
838
839 //! The current target we are rendering to, can change during command building.
841};
842
843/*!
844 * Init struct and create resources needed for rendering.
845 *
846 * @public @memberof render_gfx
847 */
848bool
849render_gfx_init(struct render_gfx *render, struct render_resources *r);
850
851/*!
852 * Begins the rendering, takes the vk_bundle's pool lock and leaves it locked.
853 *
854 * @public @memberof render_gfx
855 */
856bool
857render_gfx_begin(struct render_gfx *render);
858
859/*!
860 * Frees any unneeded resources and ends the command buffer so it can be used,
861 * also unlocks the vk_bundle's pool lock that was taken by begin.
862 *
863 * @public @memberof render_gfx
864 */
865bool
866render_gfx_end(struct render_gfx *render);
867
868/*!
869 * Frees all resources held by the rendering, does not free the struct itself.
870 *
871 * @public @memberof render_gfx
872 */
873void
874render_gfx_fini(struct render_gfx *render);
875
876
877/*
878 *
879 * Drawing
880 *
881 */
882
883/*!
884 * UBO data that is sent to the mesh shaders.
885 *
886 * @relates render_gfx
887 */
889{
890 struct xrt_matrix_2x2 vertex_rot;
891 struct xrt_normalized_rect post_transform;
892
893 // Only used for timewarp.
894 struct xrt_normalized_rect pre_transform;
895 struct xrt_matrix_4x4 transform;
896};
897
898/*!
899 * UBO data that is sent to the layer cylinder shader.
900 *
901 * @relates render_gfx
902 */
904{
905 struct xrt_normalized_rect post_transform;
906 struct xrt_matrix_4x4 mvp;
907 float radius;
908 float central_angle;
909 float aspect_ratio;
910 float _pad;
911 struct xrt_colour_rgba_f32 color_scale;
912 struct xrt_colour_rgba_f32 color_bias;
913};
914
915/*!
916 * UBO data that is sent to the layer equirect2 shader.
917 *
918 * @relates render_gfx
919 */
921{
922 struct xrt_normalized_rect post_transform;
923 struct xrt_matrix_4x4 mv_inverse;
924
925 //! See @ref render_calc_uv_to_tangent_lengths_rect.
927
928 float radius;
929 float central_horizontal_angle;
930 float upper_vertical_angle;
931 float lower_vertical_angle;
932 struct xrt_colour_rgba_f32 color_scale;
933 struct xrt_colour_rgba_f32 color_bias;
934};
935
936/*!
937 * UBO data that is sent to the layer projection shader.
938 *
939 * @relates render_gfx
940 */
942{
943 struct xrt_normalized_rect post_transform;
944 struct xrt_normalized_rect to_tanget;
945 struct xrt_matrix_4x4 mvp;
946 struct xrt_colour_rgba_f32 color_scale;
947 struct xrt_colour_rgba_f32 color_bias;
948};
949
950/*!
951 * UBO data that is sent to the layer quad shader.
952 *
953 * @relates render_gfx
954 */
956{
957 struct xrt_normalized_rect post_transform;
958 struct xrt_matrix_4x4 mvp;
959 struct xrt_colour_rgba_f32 color_scale;
960 struct xrt_colour_rgba_f32 color_bias;
961};
962
963/*!
964 * @name Preparation functions - first stage
965 * @{
966 */
967
968/*!
969 * Allocate needed resources for one mesh shader dispatch, will also update the
970 * descriptor set, UBO will be filled out with the given @p data argument.
971 *
972 * Uses the @ref render_sub_alloc_tracker of the @ref render_gfx and the
973 * descriptor pool of @ref render_resources, both of which will be reset once
974 * closed, so don't save any reference to these objects beyond the frame.
975 *
976 * @public @memberof render_gfx
977 */
978XRT_CHECK_RESULT VkResult
980 const struct render_gfx_mesh_ubo_data *data,
981 VkSampler src_sampler,
982 VkImageView src_image_view,
983 VkDescriptorSet *out_descriptor_set);
984
985/*!
986 * Allocate and write a UBO and descriptor_set to be used for cylinder layer
987 * rendering, the content of @p data need to be valid at the time of the call.
988 *
989 * @public @memberof render_gfx
990 */
991XRT_CHECK_RESULT VkResult
993 const struct render_gfx_layer_cylinder_data *data,
994 VkSampler src_sampler,
995 VkImageView src_image_view,
996 VkDescriptorSet *out_descriptor_set);
997
998/*!
999 * Allocate and write a UBO and descriptor_set to be used for equirect2 layer
1000 * rendering, the content of @p data need to be valid at the time of the call.
1001 *
1002 * @public @memberof render_gfx
1003 */
1004XRT_CHECK_RESULT VkResult
1006 const struct render_gfx_layer_equirect2_data *data,
1007 VkSampler src_sampler,
1008 VkImageView src_image_view,
1009 VkDescriptorSet *out_descriptor_set);
1010
1011/*!
1012 * Allocate and write a UBO and descriptor_set to be used for projection layer
1013 * rendering, the content of @p data need to be valid at the time of the call.
1014 *
1015 * @public @memberof render_gfx
1016 */
1017XRT_CHECK_RESULT VkResult
1019 const struct render_gfx_layer_projection_data *data,
1020 VkSampler src_sampler,
1021 VkImageView src_image_view,
1022 VkDescriptorSet *out_descriptor_set);
1023
1024/*!
1025 * Allocate and write a UBO and descriptor_set to be used for quad layer
1026 * rendering, the content of @p data need to be valid at the time of the call.
1027 *
1028 * @public @memberof render_gfx
1029 */
1030XRT_CHECK_RESULT VkResult
1032 const struct render_gfx_layer_quad_data *data,
1033 VkSampler src_sampler,
1034 VkImageView src_image_view,
1035 VkDescriptorSet *out_descriptor_set);
1036
1037
1038/*!
1039 * @}
1040 */
1041
1042/*!
1043 * @name Drawing functions - second stage
1044 * @{
1045 */
1046
1047/*!
1048 * This function allocates everything to start a single rendering. This is the
1049 * first function you call when you start the drawiing stage, you follow up with a call
1050 * to @ref render_gfx_begin_view.
1051 *
1052 * @public @memberof render_gfx
1053 */
1054bool
1055render_gfx_begin_target(struct render_gfx *render,
1056 struct render_gfx_target_resources *rtr,
1057 const VkClearColorValue *color);
1058
1059/*!
1060 * @pre successful @ref render_gfx_begin_target call,
1061 * no @ref render_gfx_begin_view without matching @ref render_gfx_end_view
1062 * @public @memberof render_gfx
1063 */
1064void
1065render_gfx_end_target(struct render_gfx *render);
1066
1067/*!
1068 * @pre successful @ref render_gfx_begin_target call
1069 * @public @memberof render_gfx
1070 */
1071void
1072render_gfx_begin_view(struct render_gfx *render, uint32_t view, const struct render_viewport_data *viewport_data);
1073
1074/*!
1075 * @pre successful @ref render_gfx_begin_view call without a matching call to this function
1076 * @public @memberof render_gfx
1077 */
1078void
1079render_gfx_end_view(struct render_gfx *render);
1080
1081/*!
1082 * Dispatch one mesh shader instance, using the give @p mesh_index as source for
1083 * mesh geometry, timewarp selectable via @p do_timewarp.
1084 *
1085 * Must have successfully called @ref render_gfx_mesh_alloc_and_write
1086 * before @ref render_gfx_begin_target to allocate @p descriptor_set and UBO.
1087 *
1088 * @pre successful @ref render_gfx_mesh_alloc_and_write call, successful @ref render_gfx_begin_view call
1089 * @public @memberof render_gfx
1090 */
1091void
1092render_gfx_mesh_draw(struct render_gfx *render, uint32_t mesh_index, VkDescriptorSet descriptor_set, bool do_timewarp);
1093
1094/*!
1095 * Dispatch a cylinder layer shader into the current target and view.
1096 *
1097 * Must have successfully called @ref render_gfx_layer_cylinder_alloc_and_write
1098 * before @ref render_gfx_begin_target to allocate @p descriptor_set and UBO.
1099 *
1100 * @public @memberof render_gfx
1101 */
1102void
1103render_gfx_layer_cylinder(struct render_gfx *render, bool premultiplied_alpha, VkDescriptorSet descriptor_set);
1104
1105/*!
1106 * Dispatch a equirect2 layer shader into the current target and view.
1107 *
1108 * Must have successfully called @ref render_gfx_layer_equirect2_alloc_and_write
1109 * before @ref render_gfx_begin_target to allocate @p descriptor_set and UBO.
1110 *
1111 * @public @memberof render_gfx
1112 */
1113void
1114render_gfx_layer_equirect2(struct render_gfx *render, bool premultiplied_alpha, VkDescriptorSet descriptor_set);
1115
1116/*!
1117 * Dispatch a projection layer shader into the current target and view.
1118 *
1119 * Must have successfully called @ref render_gfx_layer_projection_alloc_and_write
1120 * before @ref render_gfx_begin_target to allocate @p descriptor_set and UBO.
1121 *
1122 * @public @memberof render_gfx
1123 */
1124void
1125render_gfx_layer_projection(struct render_gfx *render, bool premultiplied_alpha, VkDescriptorSet descriptor_set);
1126
1127/*!
1128 * Dispatch a quad layer shader into the current target and view.
1129 *
1130 * Must have successfully called @ref render_gfx_layer_quad_alloc_and_write
1131 * before @ref render_gfx_begin_target to allocate @p descriptor_set and UBO.
1132 *
1133 * @public @memberof render_gfx
1134 */
1135void
1136render_gfx_layer_quad(struct render_gfx *render, bool premultiplied_alpha, VkDescriptorSet descriptor_set);
1137
1138/*!
1139 * @}
1140 */
1141
1142
1143/*
1144 *
1145 * Compute distortion.
1146 *
1147 */
1148
1149/*!
1150 * The semi-low level resources and operations required to squash layers and/or
1151 * apply distortion for a single frame using compute shaders.
1152 *
1153 * Unlike @ref render_gfx, this is a single stage process, and you pass all layers at a single time.
1154 *
1155 * @see comp_render_cs
1156 */
1158{
1159 //! Shared resources.
1161
1162 //! Layer descriptor set.
1164
1165 /*!
1166 * Shared descriptor set, used for the clear and distortion shaders. It
1167 * is used in the functions @ref render_compute_projection_timewarp,
1168 * @ref render_compute_projection, and @ref render_compute_clear.
1169 */
1170 VkDescriptorSet shared_descriptor_set;
1171};
1172
1173/*!
1174 * Push data that is sent to the blit shader.
1175 *
1176 * @relates render_compute
1177 */
1179{
1180 struct xrt_normalized_rect source_rect;
1181 struct xrt_rect target_rect;
1182};
1183
1184/*!
1185 * UBO data that is sent to the compute layer shaders.
1186 *
1187 * @relates render_compute
1188 */
1190{
1191 struct render_viewport_data view;
1192
1193 struct
1194 {
1195 uint32_t value;
1196 uint32_t padding[3]; // Padding up to a vec4.
1197 } layer_count;
1198
1199 struct xrt_normalized_rect pre_transform;
1200 struct xrt_normalized_rect post_transforms[RENDER_MAX_LAYERS];
1201
1202 /*!
1203 * Corresponds to enum xrt_layer_type and unpremultiplied alpha.
1204 *
1205 * std140 uvec2, because it is an array it gets padded to vec4.
1206 */
1207 struct
1208 {
1209 uint32_t layer_type;
1210 uint32_t unpremultiplied_alpha;
1211 uint32_t _padding0;
1212 uint32_t _padding1;
1214
1215 /*!
1216 * Which image/sampler(s) correspond to each layer.
1217 *
1218 * std140 uvec2, because it is an array it gets padded to vec4.
1219 */
1220 struct
1221 {
1222 uint32_t color_image_index;
1223 uint32_t depth_image_index;
1224
1225 //! @todo Implement separated samplers and images (and change to samplers[2])
1226 uint32_t _padding0;
1227 uint32_t _padding1;
1229
1230 //! Shared between cylinder and equirect2.
1232
1233
1234 /*!
1235 * For cylinder layer
1236 */
1237 struct
1238 {
1239 float radius;
1240 float central_angle;
1241 float aspect_ratio;
1242 float padding;
1244
1245
1246 /*!
1247 * For equirect2 layers
1248 */
1249 struct
1250 {
1251 float radius;
1252 float central_horizontal_angle;
1253 float upper_vertical_angle;
1254 float lower_vertical_angle;
1256
1257
1258 /*!
1259 * For projection layers
1260 */
1261
1262 //! Timewarp matrices
1264
1265 /*!
1266 * For quad layers
1267 */
1268
1269 //! All quad transforms and coordinates are in view space
1270 struct
1271 {
1272 struct xrt_vec3 val;
1273 float padding;
1275 struct
1276 {
1277 struct xrt_vec3 val;
1278 float padding;
1279 } quad_normal[RENDER_MAX_LAYERS];
1280 struct xrt_matrix_4x4 inverse_quad_transform[RENDER_MAX_LAYERS];
1281
1282 //! Quad extent in world scale
1283 struct
1284 {
1285 struct xrt_vec2 val;
1286 float padding[XRT_MAX_VIEWS];
1288
1289 /*!
1290 * Color scale and bias for all layers
1291 */
1293 struct xrt_colour_rgba_f32 color_bias[RENDER_MAX_LAYERS];
1294};
1295
1296/*!
1297 * UBO data that is sent to the compute distortion shaders.
1298 *
1299 * @relates render_compute
1300 */
1302{
1303 struct render_viewport_data views[XRT_MAX_VIEWS];
1304 struct xrt_normalized_rect pre_transforms[XRT_MAX_VIEWS];
1305 struct xrt_normalized_rect post_transforms[XRT_MAX_VIEWS];
1306 struct xrt_matrix_4x4 transform_timewarp_scanout_begin[XRT_MAX_VIEWS];
1307 struct xrt_matrix_4x4 transform_timewarp_scanout_end[XRT_MAX_VIEWS];
1308};
1309
1310/*!
1311 * Init struct and create resources needed for compute rendering.
1312 *
1313 * @public @memberof render_compute
1314 */
1315bool
1316render_compute_init(struct render_compute *render, struct render_resources *r);
1317
1318/*!
1319 * Frees all resources held by the compute rendering, does not free the struct itself.
1320 *
1321 * @public @memberof render_compute
1322 */
1323void
1324render_compute_fini(struct render_compute *render);
1325
1326/*!
1327 * Begin the compute command buffer building, takes the vk_bundle's pool lock
1328 * and leaves it locked.
1329 *
1330 * @public @memberof render_compute
1331 */
1332bool
1333render_compute_begin(struct render_compute *render);
1334
1335/*!
1336 * Frees any unneeded resources and ends the command buffer so it can be used,
1337 * also unlocks the vk_bundle's pool lock that was taken by begin.
1338 *
1339 * @public @memberof render_compute
1340 */
1341bool
1342render_compute_end(struct render_compute *render);
1343
1344/*!
1345 * Updates the given @p descriptor_set and dispatches the layer shader. Unlike
1346 * other dispatch functions below this function doesn't do any layer barriers
1347 * before or after dispatching, this is to allow the callee to batch any such
1348 * image transitions.
1349 *
1350 * Expected layouts:
1351 * * Source images: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
1352 * * Target image: VK_IMAGE_LAYOUT_GENERAL
1353 *
1354 * @public @memberof render_compute
1355 */
1356void
1358 VkDescriptorSet descriptor_set,
1359 VkBuffer ubo,
1360 VkSampler src_samplers[RENDER_MAX_IMAGES_SIZE],
1361 VkImageView src_image_views[RENDER_MAX_IMAGES_SIZE],
1362 uint32_t num_srcs,
1363 VkImageView target_image_view,
1364 const struct render_viewport_data *view,
1365 bool timewarp);
1366
1367/*!
1368 * @public @memberof render_compute
1369 */
1370void
1371render_compute_projection_timewarp(struct render_compute *render,
1372 VkSampler src_samplers[XRT_MAX_VIEWS],
1373 VkImageView src_image_views[XRT_MAX_VIEWS],
1374 const struct xrt_normalized_rect src_rects[XRT_MAX_VIEWS],
1375 const struct xrt_pose src_poses[XRT_MAX_VIEWS],
1376 const struct xrt_fov src_fovs[XRT_MAX_VIEWS],
1377 const struct xrt_pose new_poses_scanout_begin[XRT_MAX_VIEWS],
1378 const struct xrt_pose new_poses_scanout_end[XRT_MAX_VIEWS],
1379 VkImage target_image,
1380 VkImageView target_image_view,
1381 const struct render_viewport_data views[XRT_MAX_VIEWS]);
1382
1383/*!
1384 * @public @memberof render_compute
1385 */
1386void
1387render_compute_projection_scanout_compensation(struct render_compute *render,
1388 VkSampler src_samplers[XRT_MAX_VIEWS],
1389 VkImageView src_image_views[XRT_MAX_VIEWS],
1390 const struct xrt_normalized_rect src_rects[XRT_MAX_VIEWS],
1391 const struct xrt_fov src_fovs[XRT_MAX_VIEWS],
1392 const struct xrt_pose new_poses_scanout_begin[XRT_MAX_VIEWS],
1393 const struct xrt_pose new_poses_scanout_end[XRT_MAX_VIEWS],
1394 VkImage target_image,
1395 VkImageView target_image_view,
1396 const struct render_viewport_data views[XRT_MAX_VIEWS]);
1397
1398/*!
1399 * @public @memberof render_compute
1400 */
1401void
1402render_compute_projection_no_timewarp(struct render_compute *render,
1403 VkSampler src_samplers[XRT_MAX_VIEWS],
1404 VkImageView src_image_views[XRT_MAX_VIEWS],
1405 const struct xrt_normalized_rect src_rects[XRT_MAX_VIEWS],
1406 VkImage target_image,
1407 VkImageView target_image_view,
1408 const struct render_viewport_data views[XRT_MAX_VIEWS]);
1409
1410/*!
1411 * @public @memberof render_compute
1412 */
1413void
1414render_compute_clear(struct render_compute *render,
1415 VkImage target_image,
1416 VkImageView target_image_view,
1417 const struct render_viewport_data views[XRT_MAX_VIEWS]);
1418
1419
1420
1421/*!
1422 * @}
1423 */
1424
1425
1426#ifdef __cplusplus
1427}
1428#endif
bool render_resources_init(struct render_resources *r, struct render_shaders *shaders, struct vk_bundle *vk, struct xrt_device *xdev)
Allocate pools and static resources.
Definition: render_resources.c:509
VkResult render_buffer_map_and_write(struct vk_bundle *vk, struct render_buffer *buffer, void *data, VkDeviceSize size)
Maps the buffer, and copies the given data to the buffer.
Definition: render_buffer.c:209
#define RENDER_MAX_LAYER_RUNS_SIZE
Maximum number of times that the layer squasher shader can run per render_compute.
Definition: render_interface.h:82
VkResult render_buffer_write(struct vk_bundle *vk, struct render_buffer *buffer, void *data, VkDeviceSize size)
Writes the given data to the buffer, will map it temporarily if not mapped.
Definition: render_buffer.c:231
void render_gfx_end_view(struct render_gfx *render)
Definition: render_gfx.c:1137
void render_gfx_mesh_draw(struct render_gfx *render, uint32_t mesh_index, VkDescriptorSet descriptor_set, bool do_timewarp)
Dispatch one mesh shader instance, using the give mesh_index as source for mesh geometry,...
Definition: render_gfx.c:1166
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
XRT_CHECK_RESULT VkResult render_gfx_layer_equirect2_alloc_and_write(struct render_gfx *render, const struct render_gfx_layer_equirect2_data *data, VkSampler src_sampler, VkImageView src_image_view, VkDescriptorSet *out_descriptor_set)
Allocate and write a UBO and descriptor_set to be used for equirect2 layer rendering,...
Definition: render_gfx.c:1271
void render_gfx_begin_view(struct render_gfx *render, uint32_t view, const struct render_viewport_data *viewport_data)
Definition: render_gfx.c:1086
void render_gfx_layer_equirect2(struct render_gfx *render, bool premultiplied_alpha, VkDescriptorSet descriptor_set)
Dispatch a equirect2 layer shader into the current target and view.
Definition: render_gfx.c:1361
XRT_CHECK_RESULT VkResult render_gfx_layer_cylinder_alloc_and_write(struct render_gfx *render, const struct render_gfx_layer_cylinder_data *data, VkSampler src_sampler, VkImageView src_image_view, VkDescriptorSet *out_descriptor_set)
Allocate and write a UBO and descriptor_set to be used for cylinder layer rendering,...
Definition: render_gfx.c:1249
bool render_resources_get_timestamps(struct render_resources *r, uint64_t *out_gpu_start_ns, uint64_t *out_gpu_end_ns)
Returns the timestamps for when the latest GPU work started and stopped that was submitted using rend...
Definition: render_resources.c:1147
void render_gfx_fini(struct render_gfx *render)
Frees all resources held by the rendering, does not free the struct itself.
Definition: render_gfx.c:1025
void render_distortion_images_fini(struct render_resources *r)
Free distortion images.
Definition: render_distortion.c:396
void render_calc_time_warp_matrix(const struct xrt_pose *src_pose, const struct xrt_fov *src_fov, const struct xrt_pose *new_pose, struct xrt_matrix_4x4 *matrix)
Calculates a timewarp matrix which takes in NDC coords and gives out results in [-1,...
Definition: render_util.c:140
void render_compute_layers(struct render_compute *render, VkDescriptorSet descriptor_set, VkBuffer ubo, VkSampler src_samplers[((XRT_MAX_LAYERS) *2)], VkImageView src_image_views[((XRT_MAX_LAYERS) *2)], uint32_t num_srcs, VkImageView target_image_view, const struct render_viewport_data *view, bool timewarp)
Updates the given descriptor_set and dispatches the layer shader.
bool render_gfx_target_resources_init(struct render_gfx_target_resources *rtr, struct render_resources *r, struct render_gfx_render_pass *rgrp, VkImageView target, VkExtent2D extent)
Init a target resource struct, caller has to keep target alive until closed.
Definition: render_gfx.c:915
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
void render_calc_time_warp_projection(const struct xrt_fov *fov, struct xrt_matrix_4x4 *result)
Create a simplified projection matrix for timewarp.
Definition: render_util.c:176
#define RENDER_MAX_LAYERS
Max number of layers for layer squasher, can be different from XRT_MAX_LAYERS as the render module is...
Definition: render_interface.h:61
#define RENDER_DISTORTION_IMAGES_SIZE
How many distortion images we have, one for each channel (3 rgb) and per view.
Definition: render_interface.h:89
void render_calc_uv_to_tangent_lengths_rect(const struct xrt_fov *fov, struct xrt_normalized_rect *out_rect)
This function constructs a transformation in the form of a normalized rect that lets you go from a UV...
Definition: render_util.c:187
void render_gfx_target_resources_fini(struct render_gfx_target_resources *rtr)
Frees all resources held by the target, does not free the struct itself.
Definition: render_gfx.c:943
bool render_gfx_begin_target(struct render_gfx *render, struct render_gfx_target_resources *rtr, const VkClearColorValue *color)
This function allocates everything to start a single rendering.
Definition: render_gfx.c:1048
#define RENDER_MAX_IMAGES_SIZE
Max number of images that can be given at a single time to the layer squasher in a single dispatch.
Definition: render_interface.h:73
VkResult render_buffer_init(struct vk_bundle *vk, struct render_buffer *buffer, VkBufferUsageFlags usage_flags, VkMemoryPropertyFlags memory_property_flags, VkDeviceSize size)
Initialize a buffer.
Definition: render_buffer.c:118
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_gfx_render_pass_init(struct render_gfx_render_pass *rgrp, struct render_resources *r, VkFormat format, VkAttachmentLoadOp load_op, VkImageLayout final_layout)
Creates all resources held by the render pass.
Definition: render_gfx.c:710
XRT_CHECK_RESULT VkResult render_gfx_layer_projection_alloc_and_write(struct render_gfx *render, const struct render_gfx_layer_projection_data *data, VkSampler src_sampler, VkImageView src_image_view, VkDescriptorSet *out_descriptor_set)
Allocate and write a UBO and descriptor_set to be used for projection layer rendering,...
Definition: render_gfx.c:1293
XRT_CHECK_RESULT VkResult render_gfx_layer_quad_alloc_and_write(struct render_gfx *render, const struct render_gfx_layer_quad_data *data, VkSampler src_sampler, VkImageView src_image_view, VkDescriptorSet *out_descriptor_set)
Allocate and write a UBO and descriptor_set to be used for quad layer rendering, the content of data ...
Definition: render_gfx.c:1315
void render_gfx_layer_projection(struct render_gfx *render, bool premultiplied_alpha, VkDescriptorSet descriptor_set)
Dispatch a projection layer shader into the current target and view.
Definition: render_gfx.c:1377
void render_resources_fini(struct render_resources *r)
Free all pools and static resources, does not free the struct itself.
Definition: render_resources.c:1084
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
bool render_compute_init(struct render_compute *render, struct render_resources *r)
Init struct and create resources needed for compute rendering.
Definition: render_compute.c:412
uint32_t render_max_layers_capable(const struct vk_bundle *vk, bool use_compute, uint32_t desired_max_layers)
Determines the maximum number of compositor layers supported based on Vulkan device limits and the co...
Definition: render_util.c:91
void render_scratch_images_fini(struct render_resources *r, struct render_scratch_images *rsi)
Close all resources on the given render_scratch_images.
Definition: render_resources.c:1279
void render_gfx_end_target(struct render_gfx *render)
Definition: render_gfx.c:1074
void render_buffer_unmap(struct vk_bundle *vk, struct render_buffer *buffer)
Unmaps the memory.
Definition: render_buffer.c:200
bool render_resources_get_duration(struct render_resources *r, uint64_t *out_gpu_duration_ns)
Returns the duration for the latest GPU work that was submitted using render_gfx or render_compute cm...
Definition: render_resources.c:1200
void render_compute_fini(struct render_compute *render)
Frees all resources held by the compute rendering, does not free the struct itself.
Definition: render_compute.c:497
bool render_gfx_init(struct render_gfx *render, struct render_resources *r)
Init struct and create resources needed for rendering.
Definition: render_gfx.c:960
void render_gfx_render_pass_fini(struct render_gfx_render_pass *rgrp)
Frees all resources held by the render pass, does not free the struct itself.
Definition: render_gfx.c:887
void render_sub_alloc_tracker_init(struct render_sub_alloc_tracker *rsat, struct render_buffer *buffer)
Init a render_sub_alloc_tracker struct from a render_buffer, the caller is responsible for keeping bu...
Definition: render_sub_alloc.c:29
VkResult render_buffer_init_exportable(struct vk_bundle *vk, struct render_buffer *buffer, VkBufferUsageFlags usage_flags, VkMemoryPropertyFlags memory_property_flags, VkDeviceSize size)
Initialize a buffer, making it exportable.
Definition: render_buffer.c:144
XRT_CHECK_RESULT VkResult render_gfx_mesh_alloc_and_write(struct render_gfx *render, const struct render_gfx_mesh_ubo_data *data, VkSampler src_sampler, VkImageView src_image_view, VkDescriptorSet *out_descriptor_set)
Allocate needed resources for one mesh shader dispatch, will also update the descriptor set,...
Definition: render_gfx.c:1144
void render_gfx_layer_cylinder(struct render_gfx *render, bool premultiplied_alpha, VkDescriptorSet descriptor_set)
Dispatch a cylinder layer shader into the current target and view.
Definition: render_gfx.c:1337
bool render_distortion_images_ensure(struct render_resources *r, struct vk_bundle *vk, struct xrt_device *xdev, bool pre_rotate)
Creates or recreates the compute distortion textures if necessary.
Definition: render_distortion.c:408
VkResult render_buffer_map(struct vk_bundle *vk, struct render_buffer *buffer)
Maps the memory, sets render_buffer::mapped to the memory.
Definition: render_buffer.c:189
void render_gfx_layer_quad(struct render_gfx *render, bool premultiplied_alpha, VkDescriptorSet descriptor_set)
Dispatch a quad layer shader into the current target and view.
Definition: render_gfx.c:1393
XRT_CHECK_RESULT VkResult render_sub_alloc_ubo_alloc_and_get_ptr(struct vk_bundle *vk, struct render_sub_alloc_tracker *rsat, VkDeviceSize size, void **out_ptr, struct render_sub_alloc *out_rsa)
Allocate enough memory (with constraints of UBOs) of size, return the pointer to the mapped memory or...
Definition: render_sub_alloc.c:38
XRT_CHECK_RESULT VkResult render_sub_alloc_ubo_alloc_and_write(struct vk_bundle *vk, struct render_sub_alloc_tracker *rsat, const void *ptr, VkDeviceSize size, struct render_sub_alloc *out_rsa)
Allocate enough memory (with constraints of UBOs) to hold the memory in ptr and copy that memory to t...
Definition: render_sub_alloc.c:84
bool render_scratch_images_ensure(struct render_resources *r, struct render_scratch_images *rsi, VkExtent2D extent)
Ensure that the scratch images are created and have the given extent.
Definition: render_resources.c:1245
void render_buffer_fini(struct vk_bundle *vk, struct render_buffer *buffer)
Frees all resources that this buffer has, but does not free the buffer itself.
Definition: render_buffer.c:181
Shader loading interface.
Helper struct holding a buffer and its memory.
Definition: render_interface.h:168
VkDeviceSize alignment
Alignment of the buffer.
Definition: render_interface.h:182
VkDeviceSize allocation_size
Size of the memory allocation.
Definition: render_interface.h:179
VkDeviceMemory memory
Backing memory.
Definition: render_interface.h:170
VkBuffer buffer
Buffer.
Definition: render_interface.h:173
VkDeviceSize size
Size requested for the buffer.
Definition: render_interface.h:176
Push data that is sent to the blit shader.
Definition: render_interface.h:1179
UBO data that is sent to the compute distortion shaders.
Definition: render_interface.h:1302
UBO data that is sent to the compute layer shaders.
Definition: render_interface.h:1190
struct xrt_matrix_4x4 transforms_timewarp[(XRT_MAX_LAYERS)]
For projection layers.
Definition: render_interface.h:1263
struct render_compute_layer_ubo_data::@101 layer_data[(XRT_MAX_LAYERS)]
Corresponds to enum xrt_layer_type and unpremultiplied alpha.
struct render_compute_layer_ubo_data::@104 eq2_data[(XRT_MAX_LAYERS)]
For equirect2 layers.
struct xrt_colour_rgba_f32 color_scale[(XRT_MAX_LAYERS)]
Color scale and bias for all layers.
Definition: render_interface.h:1292
struct render_compute_layer_ubo_data::@105 quad_position[(XRT_MAX_LAYERS)]
For quad layers.
struct xrt_matrix_4x4 mv_inverse[(XRT_MAX_LAYERS)]
Shared between cylinder and equirect2.
Definition: render_interface.h:1231
struct render_compute_layer_ubo_data::@102 image_info[(XRT_MAX_LAYERS)]
Which image/sampler(s) correspond to each layer.
struct render_compute_layer_ubo_data::@107 quad_extent[(XRT_MAX_LAYERS)]
Quad extent in world scale.
uint32_t _padding0
Definition: render_interface.h:1211
struct render_compute_layer_ubo_data::@103 cylinder_data[(XRT_MAX_LAYERS)]
For cylinder layer.
The semi-low level resources and operations required to squash layers and/or apply distortion for a s...
Definition: render_interface.h:1158
struct render_resources * r
Shared resources.
Definition: render_interface.h:1160
VkDescriptorSet shared_descriptor_set
Shared descriptor set, used for the clear and distortion shaders.
Definition: render_interface.h:1170
VkDescriptorSet layer_descriptor_sets[(XRT_MAX_VIEWS)]
Layer descriptor set.
Definition: render_interface.h:1163
UBO data that is sent to the layer cylinder shader.
Definition: render_interface.h:904
UBO data that is sent to the layer equirect2 shader.
Definition: render_interface.h:921
struct xrt_normalized_rect to_tangent
See render_calc_uv_to_tangent_lengths_rect.
Definition: render_interface.h:926
UBO data that is sent to the layer projection shader.
Definition: render_interface.h:942
UBO data that is sent to the layer quad shader.
Definition: render_interface.h:956
UBO data that is sent to the mesh shaders.
Definition: render_interface.h:889
A render pass, while not depending on a VkFramebuffer, does depend on the format of the target image(...
Definition: render_interface.h:690
VkPipeline pipeline
Pipeline layout used for mesh, without timewarp.
Definition: render_interface.h:711
VkFormat format
The format of the image(s) we are rendering to.
Definition: render_interface.h:694
VkSampleCountFlagBits sample_count
Sample count for this render pass.
Definition: render_interface.h:697
VkAttachmentLoadOp load_op
Load op used on the attachment(s).
Definition: render_interface.h:700
VkImageLayout final_layout
Final layout of the target image(s).
Definition: render_interface.h:703
VkRenderPass render_pass
Render pass used for rendering.
Definition: render_interface.h:706
VkPipeline pipeline_timewarp
Pipeline layout used for mesh, with timewarp.
Definition: render_interface.h:714
Each rendering (render_gfx) render to one or more targets (render_gfx_target_resources),...
Definition: render_interface.h:769
struct render_resources * r
Collections of static resources.
Definition: render_interface.h:771
struct render_gfx_render_pass * rgrp
Render pass.
Definition: render_interface.h:774
VkFramebuffer framebuffer
Framebuffer for this target, depends on given VkImageView.
Definition: render_interface.h:780
The low-level resources and operations to perform layer squashing and/or mesh distortion for a single...
Definition: render_interface.h:832
struct render_resources * r
Resources that we are based on.
Definition: render_interface.h:834
struct render_gfx_target_resources * rtr
The current target we are rendering to, can change during command building.
Definition: render_interface.h:840
struct render_sub_alloc_tracker ubo_tracker
Shared buffer that we sub-allocate UBOs from.
Definition: render_interface.h:837
Holds all pools and static resources for rendering.
Definition: render_interface.h:336
uint32_t target_binding
Writing the image out too.
Definition: render_interface.h:468
uint32_t ubo_binding
The binding index for the UBO.
Definition: render_interface.h:421
VkCommandBuffer cmd
Command buffer for recording everything.
Definition: render_interface.h:371
uint32_t image_array_size
Size of combined image sampler array.
Definition: render_interface.h:488
uint32_t view_count
The count of views that we are rendering to.
Definition: render_interface.h:338
struct render_buffer ubos[XRT_MAX_VIEWS]
Info UBOs.
Definition: render_interface.h:439
struct vk_bundle * vk
Vulkan resources.
Definition: render_interface.h:341
VkSampler clamp_to_border_black
Sampler that clamps color samples to black in all directions.
Definition: render_interface.h:385
bool pre_rotated
Whether distortion images have been pre-rotated 90 degrees.
Definition: render_interface.h:539
VkPipeline non_timewarp_pipeline
Doesn't depend on target so is static.
Definition: render_interface.h:482
struct render_shaders * shaders
All shaders loaded.
Definition: render_interface.h:348
struct render_buffer shared_ubo
Shared UBO buffer that we sub-allocate out of, this is to have fewer buffers that the kernel needs to...
Definition: render_interface.h:400
VkDescriptorSetLayout descriptor_set_layout
For projection and quad layer.
Definition: render_interface.h:407
struct xrt_normalized_rect uv_to_tanangle[XRT_MAX_VIEWS]
Transform to go from UV to tangle angles.
Definition: render_interface.h:527
VkPipeline timewarp_pipeline
Doesn't depend on target so is static.
Definition: render_interface.h:485
VkPipeline pipeline
Doesn't depend on target so is static.
Definition: render_interface.h:503
VkImage images[(3 *XRT_MAX_VIEWS)]
Distortion images.
Definition: render_interface.h:533
VkDescriptorPool ubo_and_src_descriptor_pool
Pool for shaders that uses one ubo and sampler.
Definition: render_interface.h:391
struct vk_cmd_pool distortion_pool
Pool used for distortion image uploads.
Definition: render_interface.h:356
VkSampler repeat
Sampler that repeats the texture in all directions.
Definition: render_interface.h:379
uint32_t src_binding
The binding index for the source texture.
Definition: render_interface.h:418
VkDeviceMemory device_memories[(3 *XRT_MAX_VIEWS)]
Backing memory to distortion images.
Definition: render_interface.h:530
VkSampler mock
Sampler for mock/null images.
Definition: render_interface.h:376
VkSampler clamp_to_edge
Sampler that clamps the coordinates to the edge in all directions.
Definition: render_interface.h:382
struct render_buffer ubo
Target info.
Definition: render_interface.h:509
uint32_t distortion_binding
Image storing the distortion.
Definition: render_interface.h:465
VkPipelineLayout pipeline_layout
For projection and quad layer.
Definition: render_interface.h:410
VkDescriptorPool descriptor_pool
Descriptor pool for compute work.
Definition: render_interface.h:459
VkPipelineCache pipeline_cache
Shared for all rendering.
Definition: render_interface.h:359
VkImageView image_views[(3 *XRT_MAX_VIEWS)]
The views into the distortion images.
Definition: render_interface.h:536
Small helper struct to hold a scratch image, intended to be used with the compute pipeline where both...
Definition: render_interface.h:627
Helper struct to hold scratch images.
Definition: render_interface.h:638
Holds all shaders.
Definition: render_shaders_interface.h:26
A per-frame tracker of sub-allocation out of a buffer, used to reduce the number of UBO objects we ne...
Definition: render_interface.h:278
void * mapped
Start of memory, if buffer was mapped with initialised.
Definition: render_interface.h:286
VkBuffer buffer
The buffer to allocate from, it is the caller's responsibility to keep it alive for as long as the su...
Definition: render_interface.h:283
VkDeviceSize used
Currently used memory.
Definition: render_interface.h:292
VkDeviceSize total_size
Total size of buffer.
Definition: render_interface.h:289
Per frame sub-allocation into a buffer, used to reduce the number of UBO objects we need to create.
Definition: render_interface.h:253
VkDeviceSize size
Size of sub-allocation.
Definition: render_interface.h:261
VkBuffer buffer
The buffer this is allocated from, it is the caller's responsibility to keep it alive for as long as ...
Definition: render_interface.h:258
VkDeviceSize offset
Offset into buffer.
Definition: render_interface.h:264
The pure data information about a view that the renderer is rendering to.
Definition: render_interface.h:671
A bundle of Vulkan functions and objects, used by both Compositor and Compositor client code.
Definition: vk_helpers.h:75
Small helper to manage lock around a command pool.
Definition: vk_cmd_pool.h:33
A 4 element colour with floating point channels.
Definition: xrt_defines.h:410
A single HMD or input device.
Definition: xrt_device.h:310
Describes a projection matrix fov.
Definition: xrt_defines.h:499
A tightly packed 2x2 matrix of floats.
Definition: xrt_defines.h:526
A tightly packed 4x4 matrix of floats.
Definition: xrt_defines.h:573
Normalized image rectangle, coordinates and size in 0 .
Definition: xrt_defines.h:467
A pose composed of a position and orientation.
Definition: xrt_defines.h:479
Image rectangle.
Definition: xrt_defines.h:444
A 2 element vector with single floats.
Definition: xrt_defines.h:268
A 3 element vector with single floats.
Definition: xrt_defines.h:289
Command pool helpers.
Common Vulkan code header.
Header holding common defines.
Common defines and enums for XRT.