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