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