Monado OpenXR Runtime
comp_distortion.h
Go to the documentation of this file.
1 // Copyright 2019, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Distortion shader code header.
6  * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
7  * @author Jakob Bornecrantz <jakob@collabora.com>
8  * @ingroup comp_main
9  */
10 
11 #pragma once
12 
13 #include "main/comp_settings.h"
14 #include "main/comp_compositor.h"
15 
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 
22 /*
23  *
24  * Structs
25  *
26  */
27 
28 
29 /*!
30  * Helper buffer for a single uniform buffer.
31  *
32  * @ingroup comp_main
33  */
35 {
36  VkDevice device;
37  VkBuffer buffer;
38  VkDeviceMemory memory;
39  VkDescriptorBufferInfo descriptor;
40  VkDeviceSize size;
41  VkDeviceSize alignment;
42  void *mapped;
43  VkBufferUsageFlags usageFlags;
44  VkMemoryPropertyFlags memoryPropertyFlags;
45 };
46 
47 /*!
48  * Helper struct that encapsulate a distortion rendering code.
49  *
50  * @ingroup comp_main
51  */
53 {
54  // Holds all of the needed common Vulkan things.
55  struct vk_bundle *vk;
56 
57  struct comp_uniform_buffer ubo_handle;
58  struct comp_uniform_buffer vbo_handle;
59  struct comp_uniform_buffer index_handle;
60  struct comp_uniform_buffer ubo_viewport_handles[2];
61 
62  enum xrt_distortion_model distortion_model;
63 
64  struct
65  {
66  float hmd_warp_param[4];
67  float aberr[4];
68  float lens_center[2][4];
69  float viewport_scale[2];
70  float warp_scale;
71  } ubo_pano;
72 
73  struct
74  {
75  float coefficients[2][3][4];
76  float center[2][4];
77  float undistort_r2_cutoff[4];
78  float aspect_x_over_y;
79  float grow_for_undistort;
80  } ubo_vive;
81 
82  struct
83  {
84  float *vertices;
85  int *indices;
86  size_t stride;
87  size_t num_vertices;
88  size_t num_indices[2];
89  size_t offset_indices[2];
90  size_t total_num_indices;
91  } mesh;
92 
93  struct
94  {
95  struct xrt_matrix_2x2 rot;
96  int viewport_id;
97  bool flip_y;
98  } ubo_vp_data[2];
99 
100  VkPipelineLayout pipeline_layout;
101  VkPipeline pipeline;
102 
103  VkDescriptorSetLayout descriptor_set_layout;
104  VkDescriptorSet descriptor_sets[2];
105 
106  bool quirk_draw_lines;
107 };
108 
109 
110 /*
111  *
112  * Functions.
113  *
114  */
115 
116 /*!
117  * Init a distortion, pass in the distortion so it can be embedded in a struct.
118  *
119  * @ingroup comp_main
120  */
121 void
123  struct comp_compositor *c,
124  VkRenderPass render_pass,
125  VkPipelineCache pipeline_cache,
126  enum xrt_distortion_model distortion_model,
127  struct xrt_hmd_parts *parts,
128  VkDescriptorPool descriptor_pool,
129  bool flip_y);
130 
131 /*!
132  * Free and destroy all fields, does not free the destortion itself.
133  *
134  * @ingroup comp_main
135  */
136 void
138 
139 /*!
140  * Update the descriptor set to a new image.
141  *
142  * @ingroup comp_main
143  */
144 void
146  VkSampler sampler,
147  VkImageView view,
148  uint32_t eye);
149 
150 /*!
151  * Submit draw commands to the given command_buffer.
152  *
153  * @ingroup comp_main
154  */
155 void
157  VkCommandBuffer command_buffer,
158  int eye);
159 
160 void
161 comp_distortion_draw_mesh(struct comp_distortion *d,
162  VkCommandBuffer command_buffer,
163  int eye);
164 
165 #ifdef __cplusplus
166 }
167 #endif
Helper struct that encapsulate a distortion rendering code.
Definition: comp_distortion.h:52
Main compositor written using Vulkan header.
Helper buffer for a single uniform buffer.
Definition: comp_distortion.h:34
xrt_distortion_model
Which distortion model does the device expose, used both as a bitfield and value. ...
Definition: xrt_defines.h:47
Settings struct for compositor header.
Main compositor struct tying everything in the compositor together.
Definition: comp_compositor.h:70
void comp_distortion_init(struct comp_distortion *d, struct comp_compositor *c, VkRenderPass render_pass, VkPipelineCache pipeline_cache, enum xrt_distortion_model distortion_model, struct xrt_hmd_parts *parts, VkDescriptorPool descriptor_pool, bool flip_y)
Init a distortion, pass in the distortion so it can be embedded in a struct.
Definition: comp_distortion.c:181
void comp_distortion_destroy(struct comp_distortion *d)
Free and destroy all fields, does not free the destortion itself.
Definition: comp_distortion.c:227
All of the device components that deals with interfacing to a users head.
Definition: xrt_device.h:93
void comp_distortion_update_descriptor_set(struct comp_distortion *d, VkSampler sampler, VkImageView view, uint32_t eye)
Update the descriptor set to a new image.
Definition: comp_distortion.c:572
void comp_distortion_draw_quad(struct comp_distortion *d, VkCommandBuffer command_buffer, int eye)
Submit draw commands to the given command_buffer.
Definition: comp_distortion.c:682
A tightly packed 2x2 matrix of floats.
Definition: xrt_defines.h:253
A bundle of Vulkan functions and objects, used by both Compositor and Compositor client code...
Definition: vk_helpers.h:34