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