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};
912
913/*!
914 * UBO data that is sent to the layer equirect2 shader.
915 *
916 * @relates render_gfx
917 */
919{
920 struct xrt_normalized_rect post_transform;
921 struct xrt_matrix_4x4 mv_inverse;
922
923 //! See @ref render_calc_uv_to_tangent_lengths_rect.
925
926 float radius;
927 float central_horizontal_angle;
928 float upper_vertical_angle;
929 float lower_vertical_angle;
930};
931
932/*!
933 * UBO data that is sent to the layer projection shader.
934 *
935 * @relates render_gfx
936 */
938{
939 struct xrt_normalized_rect post_transform;
940 struct xrt_normalized_rect to_tanget;
941 struct xrt_matrix_4x4 mvp;
942};
943
944/*!
945 * UBO data that is sent to the layer quad shader.
946 *
947 * @relates render_gfx
948 */
950{
951 struct xrt_normalized_rect post_transform;
952 struct xrt_matrix_4x4 mvp;
953};
954
955/*!
956 * @name Preparation functions - first stage
957 * @{
958 */
959
960/*!
961 * Allocate needed resources for one mesh shader dispatch, will also update the
962 * descriptor set, UBO will be filled out with the given @p data argument.
963 *
964 * Uses the @ref render_sub_alloc_tracker of the @ref render_gfx and the
965 * descriptor pool of @ref render_resources, both of which will be reset once
966 * closed, so don't save any reference to these objects beyond the frame.
967 *
968 * @public @memberof render_gfx
969 */
970XRT_CHECK_RESULT VkResult
972 const struct render_gfx_mesh_ubo_data *data,
973 VkSampler src_sampler,
974 VkImageView src_image_view,
975 VkDescriptorSet *out_descriptor_set);
976
977/*!
978 * Allocate and write a UBO and descriptor_set to be used for cylinder layer
979 * rendering, the content of @p data need to be valid at the time of the call.
980 *
981 * @public @memberof render_gfx
982 */
983XRT_CHECK_RESULT VkResult
985 const struct render_gfx_layer_cylinder_data *data,
986 VkSampler src_sampler,
987 VkImageView src_image_view,
988 VkDescriptorSet *out_descriptor_set);
989
990/*!
991 * Allocate and write a UBO and descriptor_set to be used for equirect2 layer
992 * rendering, the content of @p data need to be valid at the time of the call.
993 *
994 * @public @memberof render_gfx
995 */
996XRT_CHECK_RESULT VkResult
998 const struct render_gfx_layer_equirect2_data *data,
999 VkSampler src_sampler,
1000 VkImageView src_image_view,
1001 VkDescriptorSet *out_descriptor_set);
1002
1003/*!
1004 * Allocate and write a UBO and descriptor_set to be used for projection layer
1005 * rendering, the content of @p data need to be valid at the time of the call.
1006 *
1007 * @public @memberof render_gfx
1008 */
1009XRT_CHECK_RESULT VkResult
1011 const struct render_gfx_layer_projection_data *data,
1012 VkSampler src_sampler,
1013 VkImageView src_image_view,
1014 VkDescriptorSet *out_descriptor_set);
1015
1016/*!
1017 * Allocate and write a UBO and descriptor_set to be used for quad layer
1018 * rendering, the content of @p data need to be valid at the time of the call.
1019 *
1020 * @public @memberof render_gfx
1021 */
1022XRT_CHECK_RESULT VkResult
1024 const struct render_gfx_layer_quad_data *data,
1025 VkSampler src_sampler,
1026 VkImageView src_image_view,
1027 VkDescriptorSet *out_descriptor_set);
1028
1029
1030/*!
1031 * @}
1032 */
1033
1034/*!
1035 * @name Drawing functions - second stage
1036 * @{
1037 */
1038
1039/*!
1040 * This function allocates everything to start a single rendering. This is the
1041 * first function you call when you start the drawiing stage, you follow up with a call
1042 * to @ref render_gfx_begin_view.
1043 *
1044 * @public @memberof render_gfx
1045 */
1046bool
1047render_gfx_begin_target(struct render_gfx *render,
1048 struct render_gfx_target_resources *rtr,
1049 const VkClearColorValue *color);
1050
1051/*!
1052 * @pre successful @ref render_gfx_begin_target call,
1053 * no @ref render_gfx_begin_view without matching @ref render_gfx_end_view
1054 * @public @memberof render_gfx
1055 */
1056void
1057render_gfx_end_target(struct render_gfx *render);
1058
1059/*!
1060 * @pre successful @ref render_gfx_begin_target call
1061 * @public @memberof render_gfx
1062 */
1063void
1064render_gfx_begin_view(struct render_gfx *render, uint32_t view, const struct render_viewport_data *viewport_data);
1065
1066/*!
1067 * @pre successful @ref render_gfx_begin_view call without a matching call to this function
1068 * @public @memberof render_gfx
1069 */
1070void
1071render_gfx_end_view(struct render_gfx *render);
1072
1073/*!
1074 * Dispatch one mesh shader instance, using the give @p mesh_index as source for
1075 * mesh geometry, timewarp selectable via @p do_timewarp.
1076 *
1077 * Must have successfully called @ref render_gfx_mesh_alloc_and_write
1078 * before @ref render_gfx_begin_target to allocate @p descriptor_set and UBO.
1079 *
1080 * @pre successful @ref render_gfx_mesh_alloc_and_write call, successful @ref render_gfx_begin_view call
1081 * @public @memberof render_gfx
1082 */
1083void
1084render_gfx_mesh_draw(struct render_gfx *render, uint32_t mesh_index, VkDescriptorSet descriptor_set, bool do_timewarp);
1085
1086/*!
1087 * Dispatch a cylinder layer shader into the current target and view.
1088 *
1089 * Must have successfully called @ref render_gfx_layer_cylinder_alloc_and_write
1090 * before @ref render_gfx_begin_target to allocate @p descriptor_set and UBO.
1091 *
1092 * @public @memberof render_gfx
1093 */
1094void
1095render_gfx_layer_cylinder(struct render_gfx *render, bool premultiplied_alpha, VkDescriptorSet descriptor_set);
1096
1097/*!
1098 * Dispatch a equirect2 layer shader into the current target and view.
1099 *
1100 * Must have successfully called @ref render_gfx_layer_equirect2_alloc_and_write
1101 * before @ref render_gfx_begin_target to allocate @p descriptor_set and UBO.
1102 *
1103 * @public @memberof render_gfx
1104 */
1105void
1106render_gfx_layer_equirect2(struct render_gfx *render, bool premultiplied_alpha, VkDescriptorSet descriptor_set);
1107
1108/*!
1109 * Dispatch a projection layer shader into the current target and view.
1110 *
1111 * Must have successfully called @ref render_gfx_layer_projection_alloc_and_write
1112 * before @ref render_gfx_begin_target to allocate @p descriptor_set and UBO.
1113 *
1114 * @public @memberof render_gfx
1115 */
1116void
1117render_gfx_layer_projection(struct render_gfx *render, bool premultiplied_alpha, VkDescriptorSet descriptor_set);
1118
1119/*!
1120 * Dispatch a quad layer shader into the current target and view.
1121 *
1122 * Must have successfully called @ref render_gfx_layer_quad_alloc_and_write
1123 * before @ref render_gfx_begin_target to allocate @p descriptor_set and UBO.
1124 *
1125 * @public @memberof render_gfx
1126 */
1127void
1128render_gfx_layer_quad(struct render_gfx *render, bool premultiplied_alpha, VkDescriptorSet descriptor_set);
1129
1130/*!
1131 * @}
1132 */
1133
1134
1135/*
1136 *
1137 * Compute distortion.
1138 *
1139 */
1140
1141/*!
1142 * The semi-low level resources and operations required to squash layers and/or
1143 * apply distortion for a single frame using compute shaders.
1144 *
1145 * Unlike @ref render_gfx, this is a single stage process, and you pass all layers at a single time.
1146 *
1147 * @see comp_render_cs
1148 */
1150{
1151 //! Shared resources.
1153
1154 //! Layer descriptor set.
1156
1157 /*!
1158 * Shared descriptor set, used for the clear and distortion shaders. It
1159 * is used in the functions @ref render_compute_projection_timewarp,
1160 * @ref render_compute_projection, and @ref render_compute_clear.
1161 */
1162 VkDescriptorSet shared_descriptor_set;
1163};
1164
1165/*!
1166 * Push data that is sent to the blit shader.
1167 *
1168 * @relates render_compute
1169 */
1171{
1172 struct xrt_normalized_rect source_rect;
1173 struct xrt_rect target_rect;
1174};
1175
1176/*!
1177 * UBO data that is sent to the compute layer shaders.
1178 *
1179 * @relates render_compute
1180 */
1182{
1183 struct render_viewport_data view;
1184
1185 struct
1186 {
1187 uint32_t value;
1188 uint32_t padding[3]; // Padding up to a vec4.
1189 } layer_count;
1190
1191 struct xrt_normalized_rect pre_transform;
1192 struct xrt_normalized_rect post_transforms[RENDER_MAX_LAYERS];
1193
1194 /*!
1195 * Corresponds to enum xrt_layer_type and unpremultiplied alpha.
1196 *
1197 * std140 uvec2, because it is an array it gets padded to vec4.
1198 */
1199 struct
1200 {
1201 uint32_t layer_type;
1202 uint32_t unpremultiplied_alpha;
1203 uint32_t _padding0;
1204 uint32_t _padding1;
1206
1207 /*!
1208 * Which image/sampler(s) correspond to each layer.
1209 *
1210 * std140 uvec2, because it is an array it gets padded to vec4.
1211 */
1212 struct
1213 {
1214 uint32_t color_image_index;
1215 uint32_t depth_image_index;
1216
1217 //! @todo Implement separated samplers and images (and change to samplers[2])
1218 uint32_t _padding0;
1219 uint32_t _padding1;
1221
1222 //! Shared between cylinder and equirect2.
1224
1225
1226 /*!
1227 * For cylinder layer
1228 */
1229 struct
1230 {
1231 float radius;
1232 float central_angle;
1233 float aspect_ratio;
1234 float padding;
1236
1237
1238 /*!
1239 * For equirect2 layers
1240 */
1241 struct
1242 {
1243 float radius;
1244 float central_horizontal_angle;
1245 float upper_vertical_angle;
1246 float lower_vertical_angle;
1248
1249
1250 /*!
1251 * For projection layers
1252 */
1253
1254 //! Timewarp matrices
1256
1257 /*!
1258 * For quad layers
1259 */
1260
1261 //! All quad transforms and coordinates are in view space
1262 struct
1263 {
1264 struct xrt_vec3 val;
1265 float padding;
1267 struct
1268 {
1269 struct xrt_vec3 val;
1270 float padding;
1271 } quad_normal[RENDER_MAX_LAYERS];
1272 struct xrt_matrix_4x4 inverse_quad_transform[RENDER_MAX_LAYERS];
1273
1274 //! Quad extent in world scale
1275 struct
1276 {
1277 struct xrt_vec2 val;
1278 float padding[XRT_MAX_VIEWS];
1280};
1281
1282/*!
1283 * UBO data that is sent to the compute distortion shaders.
1284 *
1285 * @relates render_compute
1286 */
1288{
1289 struct render_viewport_data views[XRT_MAX_VIEWS];
1290 struct xrt_normalized_rect pre_transforms[XRT_MAX_VIEWS];
1291 struct xrt_normalized_rect post_transforms[XRT_MAX_VIEWS];
1292 struct xrt_matrix_4x4 transform_timewarp_scanout_begin[XRT_MAX_VIEWS];
1293 struct xrt_matrix_4x4 transform_timewarp_scanout_end[XRT_MAX_VIEWS];
1294};
1295
1296/*!
1297 * Init struct and create resources needed for compute rendering.
1298 *
1299 * @public @memberof render_compute
1300 */
1301bool
1302render_compute_init(struct render_compute *render, struct render_resources *r);
1303
1304/*!
1305 * Frees all resources held by the compute rendering, does not free the struct itself.
1306 *
1307 * @public @memberof render_compute
1308 */
1309void
1310render_compute_fini(struct render_compute *render);
1311
1312/*!
1313 * Begin the compute command buffer building, takes the vk_bundle's pool lock
1314 * and leaves it locked.
1315 *
1316 * @public @memberof render_compute
1317 */
1318bool
1319render_compute_begin(struct render_compute *render);
1320
1321/*!
1322 * Frees any unneeded resources and ends the command buffer so it can be used,
1323 * also unlocks the vk_bundle's pool lock that was taken by begin.
1324 *
1325 * @public @memberof render_compute
1326 */
1327bool
1328render_compute_end(struct render_compute *render);
1329
1330/*!
1331 * Updates the given @p descriptor_set and dispatches the layer shader. Unlike
1332 * other dispatch functions below this function doesn't do any layer barriers
1333 * before or after dispatching, this is to allow the callee to batch any such
1334 * image transitions.
1335 *
1336 * Expected layouts:
1337 * * Source images: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
1338 * * Target image: VK_IMAGE_LAYOUT_GENERAL
1339 *
1340 * @public @memberof render_compute
1341 */
1342void
1344 VkDescriptorSet descriptor_set,
1345 VkBuffer ubo,
1346 VkSampler src_samplers[RENDER_MAX_IMAGES_SIZE],
1347 VkImageView src_image_views[RENDER_MAX_IMAGES_SIZE],
1348 uint32_t num_srcs,
1349 VkImageView target_image_view,
1350 const struct render_viewport_data *view,
1351 bool timewarp);
1352
1353/*!
1354 * @public @memberof render_compute
1355 */
1356void
1357render_compute_projection_timewarp(struct render_compute *render,
1358 VkSampler src_samplers[XRT_MAX_VIEWS],
1359 VkImageView src_image_views[XRT_MAX_VIEWS],
1360 const struct xrt_normalized_rect src_rects[XRT_MAX_VIEWS],
1361 const struct xrt_pose src_poses[XRT_MAX_VIEWS],
1362 const struct xrt_fov src_fovs[XRT_MAX_VIEWS],
1363 const struct xrt_pose new_poses_scanout_begin[XRT_MAX_VIEWS],
1364 const struct xrt_pose new_poses_scanout_end[XRT_MAX_VIEWS],
1365 VkImage target_image,
1366 VkImageView target_image_view,
1367 const struct render_viewport_data views[XRT_MAX_VIEWS]);
1368
1369/*!
1370 * @public @memberof render_compute
1371 */
1372void
1373render_compute_projection_scanout_compensation(struct render_compute *render,
1374 VkSampler src_samplers[XRT_MAX_VIEWS],
1375 VkImageView src_image_views[XRT_MAX_VIEWS],
1376 const struct xrt_normalized_rect src_rects[XRT_MAX_VIEWS],
1377 const struct xrt_fov src_fovs[XRT_MAX_VIEWS],
1378 const struct xrt_pose new_poses_scanout_begin[XRT_MAX_VIEWS],
1379 const struct xrt_pose new_poses_scanout_end[XRT_MAX_VIEWS],
1380 VkImage target_image,
1381 VkImageView target_image_view,
1382 const struct render_viewport_data views[XRT_MAX_VIEWS]);
1383
1384/*!
1385 * @public @memberof render_compute
1386 */
1387void
1388render_compute_projection_no_timewarp(struct render_compute *render,
1389 VkSampler src_samplers[XRT_MAX_VIEWS],
1390 VkImageView src_image_views[XRT_MAX_VIEWS],
1391 const struct xrt_normalized_rect src_rects[XRT_MAX_VIEWS],
1392 VkImage target_image,
1393 VkImageView target_image_view,
1394 const struct render_viewport_data views[XRT_MAX_VIEWS]);
1395
1396/*!
1397 * @public @memberof render_compute
1398 */
1399void
1400render_compute_clear(struct render_compute *render,
1401 VkImage target_image,
1402 VkImageView target_image_view,
1403 const struct render_viewport_data views[XRT_MAX_VIEWS]);
1404
1405
1406
1407/*!
1408 * @}
1409 */
1410
1411
1412#ifdef __cplusplus
1413}
1414#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:1171
UBO data that is sent to the compute distortion shaders.
Definition: render_interface.h:1288
UBO data that is sent to the compute layer shaders.
Definition: render_interface.h:1182
struct xrt_matrix_4x4 transforms_timewarp[(XRT_MAX_LAYERS)]
For projection layers.
Definition: render_interface.h:1255
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 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:1223
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:1203
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:1150
struct render_resources * r
Shared resources.
Definition: render_interface.h:1152
VkDescriptorSet shared_descriptor_set
Shared descriptor set, used for the clear and distortion shaders.
Definition: render_interface.h:1162
VkDescriptorSet layer_descriptor_sets[(XRT_MAX_VIEWS)]
Layer descriptor set.
Definition: render_interface.h:1155
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:919
struct xrt_normalized_rect to_tangent
See render_calc_uv_to_tangent_lengths_rect.
Definition: render_interface.h:924
UBO data that is sent to the layer projection shader.
Definition: render_interface.h:938
UBO data that is sent to the layer quad shader.
Definition: render_interface.h:950
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:78
Small helper to manage lock around a command pool.
Definition: vk_cmd_pool.h:33
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.