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 you where to do
71 * two or more different compositions it's 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//! How large in pixels the distortion image is.
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//! Which binding does the layer projection and quad shader has it's UBO on.
85#define RENDER_BINDING_LAYER_SHARED_UBO 0
86
87//! Which binding does the shared layer fragment shader has it's 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's the callers 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 indivudial 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's the callers 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, only supports two views currently.
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 */
583bool
585 struct vk_bundle *vk,
586 struct xrt_device *xdev,
587 bool pre_rotate);
588
589/*!
590 * Free distortion images.
591 */
592void
594
595/*!
596 * Returns the timestamps for when the latest GPU work started and stopped that
597 * was submitted using @ref render_gfx or @ref render_compute cmd buf builders.
598 *
599 * Returned in the same time domain as returned by @ref os_monotonic_get_ns .
600 * Behaviour for this function is undefined if the GPU has not completed before
601 * calling this function, so make sure to call vkQueueWaitIdle or wait on the
602 * fence that the work was submitted with have fully completed. See other
603 * limitation mentioned for @ref vk_convert_timestamps_to_host_ns .
604 *
605 * @see vk_convert_timestamps_to_host_ns
606 *
607 * @public @memberof render_resources
608 */
609bool
610render_resources_get_timestamps(struct render_resources *r, uint64_t *out_gpu_start_ns, uint64_t *out_gpu_end_ns);
611
612/*!
613 * Returns the duration for the latest GPU work that was submitted using
614 * @ref render_gfx or @ref render_compute cmd buf builders.
615 *
616 * Behaviour for this function is undefined if the GPU has not completed before
617 * calling this function, so make sure to call vkQueueWaitIdle or wait on the
618 * fence that the work was submitted with have fully completed.
619 *
620 * @public @memberof render_resources
621 */
622bool
623render_resources_get_duration(struct render_resources *r, uint64_t *out_gpu_duration_ns);
624
625
626/*
627 *
628 * Scratch images.
629 *
630 */
631
632/*!
633 * Small helper struct to hold a scratch image, intended to be used with the
634 * compute pipeline where both srgb and unorm views are needed.
635 */
637{
638 VkDeviceMemory device_memory;
639 VkImage image;
640 VkImageView srgb_view;
641 VkImageView unorm_view;
642};
643
644/*!
645 * Helper struct to hold scratch images.
646 */
648{
649 VkExtent2D extent;
650
651 struct render_scratch_color_image color[XRT_MAX_VIEWS];
652};
653
654/*!
655 * Ensure that the scratch images are created and have the given extent.
656 */
657bool
658render_scratch_images_ensure(struct render_resources *r, struct render_scratch_images *rsi, VkExtent2D extent);
659
660/*!
661 * Close all resources on the given @ref render_scratch_images.
662 */
663void
665
666
667/*
668 *
669 * Shared between both gfx and compute.
670 *
671 */
672
673/*!
674 * The pure data information about a view that the renderer is rendering to.
675 */
677{
678 uint32_t x, y;
679 uint32_t w, h;
680};
681
682
683/*
684 *
685 * Render pass
686 *
687 */
688
689/*!
690 * A render pass while not depending on a @p VkFramebuffer does depend on the
691 * format of the target image(s), and other options for the render pass. These
692 * are used to create a @p VkRenderPass, all @p VkFramebuffer(s) and
693 * @p VkPipeline depends on the @p VkRenderPass so hang off this struct.
694 */
696{
697 struct render_resources *r;
698
699 //! The format of the image(s) we are rendering to.
700 VkFormat format;
701
702 //! Sample count for this render pass.
703 VkSampleCountFlagBits sample_count;
704
705 //! Load op used on the attachment(s).
706 VkAttachmentLoadOp load_op;
707
708 //! Final layout of the target image(s).
709 VkImageLayout final_layout;
710
711 //! Render pass used for rendering.
712 VkRenderPass render_pass;
713
714 struct
715 {
716 //! Pipeline layout used for mesh, without timewarp.
717 VkPipeline pipeline;
718
719 //! Pipeline layout used for mesh, with timewarp.
721 } mesh;
722
723 struct
724 {
725 VkPipeline cylinder_premultiplied_alpha;
726 VkPipeline cylinder_unpremultiplied_alpha;
727
728 VkPipeline equirect2_premultiplied_alpha;
729 VkPipeline equirect2_unpremultiplied_alpha;
730
731 VkPipeline proj_premultiplied_alpha;
732 VkPipeline proj_unpremultiplied_alpha;
733
734 VkPipeline quad_premultiplied_alpha;
735 VkPipeline quad_unpremultiplied_alpha;
736 } layer;
737};
738
739/*!
740 * Creates all resources held by the render pass, does not free the struct itself.
741 *
742 * @public @memberof render_gfx_render_pass
743 */
744bool
746 struct render_resources *r,
747 VkFormat format,
748 VkAttachmentLoadOp load_op,
749 VkImageLayout final_layout);
750
751/*!
752 * Frees all resources held by the render pass, does not free the struct itself.
753 *
754 * @public @memberof render_gfx_render_pass
755 */
756void
758
759
760/*
761 *
762 * Rendering target
763 *
764 */
765
766/*!
767 * Each rendering (@ref render_gfx) render to one or more targets
768 * (@ref render_gfx_target_resources), the target points to one render pass and
769 * it's pipelines (@ref render_gfx_render_pass). It is up to the code using
770 * these to do reuse of render passes and ensure they match.
771 *
772 * @see comp_render_gfx
773 */
775{
776 //! Collections of static resources.
778
779 //! Render pass.
781
782 // The extent of the framebuffer.
783 VkExtent2D extent;
784
785 //! Framebuffer for this target, depends on given VkImageView.
786 VkFramebuffer framebuffer;
787};
788
789/*!
790 * Init a target resource struct, caller has to keep target alive until closed.
791 *
792 * @public @memberof render_gfx_target_resources
793 */
794bool
796 struct render_resources *r,
797 struct render_gfx_render_pass *rgrp,
798 VkImageView target,
799 VkExtent2D extent);
800
801/*!
802 * Frees all resources held by the target, does not free the struct itself.
803 *
804 * @public @memberof render_gfx_target_resources
805 */
806void
808
809
810/*
811 *
812 * Rendering
813 *
814 */
815
816/*!
817 * A rendering is used to create command buffers needed to do one frame of
818 * compositor rendering, it holds onto resources used by the command buffer.
819 *
820 * @see comp_render_gfx
821 */
823{
824 //! Resources that we are based on.
826
827 //! Shared buffer that we sub-allocate UBOs from.
829
830 //! The current target we are rendering too, can change during command building.
832};
833
834/*!
835 * Init struct and create resources needed for rendering.
836 *
837 * @public @memberof render_gfx
838 */
839bool
840render_gfx_init(struct render_gfx *rr, struct render_resources *r);
841
842/*!
843 * Begins the rendering, takes the vk_bundle's pool lock and leaves it locked.
844 *
845 * @public @memberof render_gfx
846 */
847bool
848render_gfx_begin(struct render_gfx *rr);
849
850/*!
851 * Frees any unneeded resources and ends the command buffer so it can be used,
852 * also unlocks the vk_bundle's pool lock that was taken by begin.
853 *
854 * @public @memberof render_gfx
855 */
856bool
857render_gfx_end(struct render_gfx *rr);
858
859/*!
860 * Frees all resources held by the rendering, does not free the struct itself.
861 *
862 * @public @memberof render_gfx
863 */
864void
865render_gfx_fini(struct render_gfx *rr);
866
867
868/*
869 *
870 * Drawing
871 *
872 */
873
874/*!
875 * UBO data that is sent to the mesh shaders.
876 */
878{
879 struct xrt_matrix_2x2 vertex_rot;
880 struct xrt_normalized_rect post_transform;
881
882 // Only used for timewarp.
883 struct xrt_normalized_rect pre_transform;
884 struct xrt_matrix_4x4 transform;
885};
886
887/*!
888 * UBO data that is sent to the layer cylinder shader.
889 */
891{
892 struct xrt_normalized_rect post_transform;
893 struct xrt_matrix_4x4 mvp;
894 float radius;
895 float central_angle;
896 float aspect_ratio;
897 float _pad;
898};
899
900/*!
901 * UBO data that is sent to the layer equirect2 shader.
902 */
904{
905 struct xrt_normalized_rect post_transform;
906 struct xrt_matrix_4x4 mv_inverse;
907
908 //! See @ref render_calc_uv_to_tangent_lengths_rect.
910
911 float radius;
912 float central_horizontal_angle;
913 float upper_vertical_angle;
914 float lower_vertical_angle;
915};
916
917/*!
918 * UBO data that is sent to the layer projection shader.
919 */
921{
922 struct xrt_normalized_rect post_transform;
923 struct xrt_normalized_rect to_tanget;
924 struct xrt_matrix_4x4 mvp;
925};
926
927/*!
928 * UBO data that is sent to the layer quad shader.
929 */
931{
932 struct xrt_normalized_rect post_transform;
933 struct xrt_matrix_4x4 mvp;
934};
935
936
937/*!
938 * @name Drawing functions
939 * @{
940 */
941
942/*!
943 * This function allocates everything to start a single rendering. This is the
944 * first function you call when you start rendering, you follow up with a call
945 * to render_gfx_begin_view.
946 *
947 * @public @memberof render_gfx
948 */
949bool
950render_gfx_begin_target(struct render_gfx *rr, struct render_gfx_target_resources *rtr, const VkClearColorValue *color);
951
952/*!
953 * @public @memberof render_gfx
954 */
955void
956render_gfx_end_target(struct render_gfx *rr);
957
958/*!
959 * @public @memberof render_gfx
960 */
961void
962render_gfx_begin_view(struct render_gfx *rr, uint32_t view, const struct render_viewport_data *viewport_data);
963
964/*!
965 * @public @memberof render_gfx
966 */
967void
969
970/*!
971 * Allocate needed resources for one mesh shader dispatch, will also update the
972 * descriptor set, ubo will be filled out with the given @p data argument.
973 *
974 * Uses the @ref render_sub_alloc_tracker of the @ref render_gfx and the
975 * descriptor pool of @ref render_resources, both of which will be reset once
976 * closed, so don't save any reference to these objects beyond the frame.
977 *
978 * @public @memberof render_gfx
979 */
980XRT_CHECK_RESULT VkResult
982 const struct render_gfx_mesh_ubo_data *data,
983 VkSampler src_sampler,
984 VkImageView src_image_view,
985 VkDescriptorSet *out_descriptor_set);
986
987/*!
988 * Dispatch one mesh shader instance, using the give @p mesh_index as source for
989 * mesh geometry, timewarp selectable via @p do_timewarp.
990 *
991 * @public @memberof render_gfx
992 */
993void
994render_gfx_mesh_draw(struct render_gfx *rr, uint32_t mesh_index, VkDescriptorSet descriptor_set, bool do_timewarp);
995
996/*!
997 * Allocate and write a UBO and descriptor_set to be used for cylinder layer
998 * rendering, the content of @p data need to be valid at the time of the call.
999 *
1000 * @public @memberof render_gfx
1001 */
1002XRT_CHECK_RESULT VkResult
1004 const struct render_gfx_layer_cylinder_data *data,
1005 VkSampler src_sampler,
1006 VkImageView src_image_view,
1007 VkDescriptorSet *out_descriptor_set);
1008
1009/*!
1010 * Allocate and write a UBO and descriptor_set to be used for equirect2 layer
1011 * rendering, the content of @p data need to be valid at the time of the call.
1012 *
1013 * @public @memberof render_gfx
1014 */
1015XRT_CHECK_RESULT VkResult
1017 const struct render_gfx_layer_equirect2_data *data,
1018 VkSampler src_sampler,
1019 VkImageView src_image_view,
1020 VkDescriptorSet *out_descriptor_set);
1021
1022/*!
1023 * Allocate and write a UBO and descriptor_set to be used for projection layer
1024 * rendering, the content of @p data need to be valid at the time of the call.
1025 *
1026 * @public @memberof render_gfx
1027 */
1028XRT_CHECK_RESULT VkResult
1030 const struct render_gfx_layer_projection_data *data,
1031 VkSampler src_sampler,
1032 VkImageView src_image_view,
1033 VkDescriptorSet *out_descriptor_set);
1034
1035/*!
1036 * Allocate and write a UBO and descriptor_set to be used for quad layer
1037 * rendering, the content of @p data need to be valid at the time of the call.
1038 *
1039 * @public @memberof render_gfx
1040 */
1041XRT_CHECK_RESULT VkResult
1043 const struct render_gfx_layer_quad_data *data,
1044 VkSampler src_sampler,
1045 VkImageView src_image_view,
1046 VkDescriptorSet *out_descriptor_set);
1047
1048/*!
1049 * Dispatch a cylinder layer shader into the current target and view,
1050 * allocate @p descriptor_set and ubo with
1051 * @ref render_gfx_layer_cylinder_alloc_and_write.
1052 *
1053 * @public @memberof render_gfx
1054 */
1055void
1056render_gfx_layer_cylinder(struct render_gfx *rr, bool premultiplied_alpha, VkDescriptorSet descriptor_set);
1057
1058/*!
1059 * Dispatch a equirect2 layer shader into the current target and view,
1060 * allocate @p descriptor_set and ubo with
1061 * @ref render_gfx_layer_equirect2_alloc_and_write.
1062 *
1063 * @public @memberof render_gfx
1064 */
1065void
1066render_gfx_layer_equirect2(struct render_gfx *rr, bool premultiplied_alpha, VkDescriptorSet descriptor_set);
1067
1068/*!
1069 * Dispatch a projection layer shader into the current target and view,
1070 * allocate @p descriptor_set and ubo with
1071 * @ref render_gfx_layer_projection_alloc_and_write.
1072 *
1073 * @public @memberof render_gfx
1074 */
1075void
1076render_gfx_layer_projection(struct render_gfx *rr, bool premultiplied_alpha, VkDescriptorSet descriptor_set);
1077
1078/*!
1079 * Dispatch a quad layer shader into the current target and view, allocate
1080 * @p descriptor_set and ubo with @ref render_gfx_layer_quad_alloc_and_write.
1081 *
1082 * @public @memberof render_gfx
1083 */
1084void
1085render_gfx_layer_quad(struct render_gfx *rr, bool premultiplied_alpha, VkDescriptorSet descriptor_set);
1086
1087/*!
1088 * @}
1089 */
1090
1091
1092/*
1093 *
1094 * Compute distortion.
1095 *
1096 */
1097
1098/*!
1099 * A compute rendering is used to create command buffers needed to do one frame
1100 * of compositor rendering using compute shaders, it holds onto resources used
1101 * by the command buffer.
1102 *
1103 * @see comp_render_cs
1104 */
1106{
1107 //! Shared resources.
1109
1110 //! Layer descriptor set.
1112
1113 /*!
1114 * Shared descriptor set, used for the clear and distortion shaders. It
1115 * is used in the functions @ref render_compute_projection_timewarp,
1116 * @ref render_compute_projection, and @ref render_compute_clear.
1117 */
1118 VkDescriptorSet shared_descriptor_set;
1119};
1120
1121/*!
1122 * Push data that is sent to the blit shader.
1123 */
1125{
1126 struct xrt_normalized_rect source_rect;
1127 struct xrt_rect target_rect;
1128};
1129
1130/*!
1131 * UBO data that is sent to the compute layer shaders.
1132 *
1133 * Used in @ref render_compute
1134 */
1136{
1137 struct render_viewport_data view;
1138
1139 struct
1140 {
1141 uint32_t value;
1142 uint32_t padding[3];
1143 } layer_count;
1144
1145 struct xrt_normalized_rect pre_transform;
1146 struct xrt_normalized_rect post_transforms[RENDER_MAX_LAYERS];
1147
1148 //! std140 uvec2, corresponds to enum xrt_layer_type and unpremultiplied alpha.
1149 struct
1150 {
1151 uint32_t val;
1152 uint32_t unpremultiplied;
1153 uint32_t padding[XRT_MAX_VIEWS];
1155
1156 //! Which image/sampler(s) correspond to each layer.
1157 struct
1158 {
1159 uint32_t images[XRT_MAX_VIEWS];
1160 //! @todo Implement separated samplers and images (and change to samplers[2])
1161 uint32_t padding[XRT_MAX_VIEWS];
1163
1164 //! Shared between cylinder and equirect2.
1166
1167
1168 /*!
1169 * For cylinder layer
1170 */
1171 struct
1172 {
1173 float radius;
1174 float central_angle;
1175 float aspect_ratio;
1176 float padding;
1178
1179
1180 /*!
1181 * For equirect2 layers
1182 */
1183 struct
1184 {
1185 float radius;
1186 float central_horizontal_angle;
1187 float upper_vertical_angle;
1188 float lower_vertical_angle;
1190
1191
1192 /*!
1193 * For projection layers
1194 */
1195
1196 //! Timewarp matrices
1198
1199
1200 /*!
1201 * For quad layers
1202 */
1203
1204 //! All quad transforms and coordinates are in view space
1205 struct
1206 {
1207 struct xrt_vec3 val;
1208 float padding;
1210 struct
1211 {
1212 struct xrt_vec3 val;
1213 float padding;
1214 } quad_normal[RENDER_MAX_LAYERS];
1215 struct xrt_matrix_4x4 inverse_quad_transform[RENDER_MAX_LAYERS];
1216
1217 //! Quad extent in world scale
1218 struct
1219 {
1220 struct xrt_vec2 val;
1221 float padding[XRT_MAX_VIEWS];
1223};
1224
1225/*!
1226 * UBO data that is sent to the compute distortion shaders.
1227 *
1228 * Used in @ref render_compute
1229 */
1231{
1232 struct render_viewport_data views[XRT_MAX_VIEWS];
1233 struct xrt_normalized_rect pre_transforms[XRT_MAX_VIEWS];
1234 struct xrt_normalized_rect post_transforms[XRT_MAX_VIEWS];
1235 struct xrt_matrix_4x4 transforms[XRT_MAX_VIEWS];
1236};
1237
1238/*!
1239 * Init struct and create resources needed for compute rendering.
1240 *
1241 * @public @memberof render_compute
1242 */
1243bool
1245
1246/*!
1247 * Frees all resources held by the compute rendering, does not free the struct itself.
1248 *
1249 * @public @memberof render_compute
1250 */
1251void
1253
1254/*!
1255 * Begin the compute command buffer building, takes the vk_bundle's pool lock
1256 * and leaves it locked.
1257 *
1258 * @public @memberof render_compute
1259 */
1260bool
1262
1263/*!
1264 * Frees any unneeded resources and ends the command buffer so it can be used,
1265 * also unlocks the vk_bundle's pool lock that was taken by begin.
1266 *
1267 * @public @memberof render_compute
1268 */
1269bool
1271
1272/*!
1273 * Updates the given @p descriptor_set and dispatches the layer shader. Unlike
1274 * other dispatch functions below this function doesn't do any layer barriers
1275 * before or after dispatching, this is to allow the callee to batch any such
1276 * image transitions.
1277 *
1278 * Expected layouts:
1279 * * Source images: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
1280 * * Target image: VK_IMAGE_LAYOUT_GENERAL
1281 *
1282 * @public @memberof render_compute
1283 */
1284void
1286 VkDescriptorSet descriptor_set, //
1287 VkBuffer ubo, //
1288 VkSampler src_samplers[RENDER_MAX_IMAGES_SIZE], //
1289 VkImageView src_image_views[RENDER_MAX_IMAGES_SIZE], //
1290 uint32_t num_srcs, //
1291 VkImageView target_image_view, //
1292 const struct render_viewport_data *view, //
1293 bool timewarp); //
1294
1295/*!
1296 * @public @memberof render_compute
1297 */
1298void
1299render_compute_projection_timewarp(struct render_compute *crc,
1300 VkSampler src_samplers[XRT_MAX_VIEWS],
1301 VkImageView src_image_views[XRT_MAX_VIEWS],
1302 const struct xrt_normalized_rect src_rects[XRT_MAX_VIEWS],
1303 const struct xrt_pose src_poses[XRT_MAX_VIEWS],
1304 const struct xrt_fov src_fovs[XRT_MAX_VIEWS],
1305 const struct xrt_pose new_poses[XRT_MAX_VIEWS],
1306 VkImage target_image,
1307 VkImageView target_image_view,
1308 const struct render_viewport_data views[XRT_MAX_VIEWS]);
1309
1310/*!
1311 * @public @memberof render_compute
1312 */
1313void
1314render_compute_projection(struct render_compute *crc, //
1315 VkSampler src_samplers[XRT_MAX_VIEWS], //
1316 VkImageView src_image_views[XRT_MAX_VIEWS], //
1317 const struct xrt_normalized_rect src_rects[XRT_MAX_VIEWS], //
1318 VkImage target_image, //
1319 VkImageView target_image_view, //
1320 const struct render_viewport_data views[XRT_MAX_VIEWS]); //
1321
1322/*!
1323 * @public @memberof render_compute
1324 */
1325void
1326render_compute_clear(struct render_compute *crc, //
1327 VkImage target_image, //
1328 VkImageView target_image_view, //
1329 const struct render_viewport_data views[XRT_MAX_VIEWS]); //
1330
1331
1332
1333/*!
1334 * @}
1335 */
1336
1337
1338#ifdef __cplusplus
1339}
1340#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:959
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:1024
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:1163
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:1373
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:1357
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:1289
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:1389
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:971
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:914
#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:1047
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:1245
#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, does not free the struct itself.
Definition: render_gfx.c:709
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:1333
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:942
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:1267
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:1311
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:1006
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:1141
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:886
void render_gfx_end_view(struct render_gfx *rr)
Definition: render_gfx.c:1134
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:1125
UBO data that is sent to the compute distortion shaders.
Definition: render_interface.h:1231
UBO data that is sent to the compute layer shaders.
Definition: render_interface.h:1136
struct xrt_matrix_4x4 transforms[(XRT_MAX_LAYERS)]
For projection layers.
Definition: render_interface.h:1197
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:1165
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:1142
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:1106
struct render_resources * r
Shared resources.
Definition: render_interface.h:1108
VkDescriptorSet shared_descriptor_set
Shared descriptor set, used for the clear and distortion shaders.
Definition: render_interface.h:1118
VkDescriptorSet layer_descriptor_sets[(XRT_MAX_VIEWS)]
Layer descriptor set.
Definition: render_interface.h:1111
UBO data that is sent to the layer cylinder shader.
Definition: render_interface.h:891
UBO data that is sent to the layer equirect2 shader.
Definition: render_interface.h:904
struct xrt_normalized_rect to_tangent
See render_calc_uv_to_tangent_lengths_rect.
Definition: render_interface.h:909
UBO data that is sent to the layer projection shader.
Definition: render_interface.h:921
UBO data that is sent to the layer quad shader.
Definition: render_interface.h:931
UBO data that is sent to the mesh shaders.
Definition: render_interface.h:878
A render pass while not depending on a VkFramebuffer does depend on the format of the target image(s)...
Definition: render_interface.h:696
VkPipeline pipeline
Pipeline layout used for mesh, without timewarp.
Definition: render_interface.h:717
VkFormat format
The format of the image(s) we are rendering to.
Definition: render_interface.h:700
VkSampleCountFlagBits sample_count
Sample count for this render pass.
Definition: render_interface.h:703
VkAttachmentLoadOp load_op
Load op used on the attachment(s).
Definition: render_interface.h:706
VkImageLayout final_layout
Final layout of the target image(s).
Definition: render_interface.h:709
VkRenderPass render_pass
Render pass used for rendering.
Definition: render_interface.h:712
VkPipeline pipeline_timewarp
Pipeline layout used for mesh, with timewarp.
Definition: render_interface.h:720
Each rendering (render_gfx) render to one or more targets (render_gfx_target_resources),...
Definition: render_interface.h:775
struct render_resources * r
Collections of static resources.
Definition: render_interface.h:777
struct render_gfx_render_pass * rgrp
Render pass.
Definition: render_interface.h:780
VkFramebuffer framebuffer
Framebuffer for this target, depends on given VkImageView.
Definition: render_interface.h:786
A rendering is used to create command buffers needed to do one frame of compositor rendering,...
Definition: render_interface.h:823
struct render_resources * r
Resources that we are based on.
Definition: render_interface.h:825
struct render_gfx_target_resources * rtr
The current target we are rendering too, can change during command building.
Definition: render_interface.h:831
struct render_sub_alloc_tracker ubo_tracker
Shared buffer that we sub-allocate UBOs from.
Definition: render_interface.h:828
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, only supports two views currently.
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:637
Helper struct to hold scratch images.
Definition: render_interface.h:648
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's the callers responsibility to keep it alive for as long as the sub-...
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's the callers responsibility to keep it alive for as long as th...
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:677
A bundle of Vulkan functions and objects, used by both Compositor and Compositor client code.
Definition: vk_helpers.h:49
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.