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