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;
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];
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];
91  } mesh;
92 
93  struct
94  {
95  struct xrt_matrix_2x2 rot;
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 
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
162  VkCommandBuffer command_buffer,
163  int eye);
164 
165 #ifdef __cplusplus
166 }
167 #endif
int viewport_id
Definition: comp_distortion.h:96
Helper struct that encapsulate a distortion rendering code.
Definition: comp_distortion.h:52
float aspect_x_over_y
Definition: comp_distortion.h:78
Main compositor written using Vulkan header.
VkPipelineLayout pipeline_layout
Definition: comp_distortion.h:100
VkMemoryPropertyFlags memoryPropertyFlags
Definition: comp_distortion.h:44
size_t num_vertices
Definition: comp_distortion.h:87
bool flip_y
Definition: comp_distortion.h:97
VkPipeline pipeline
Definition: comp_distortion.h:101
VkDeviceSize size
Definition: comp_distortion.h:40
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:48
int * indices
Definition: comp_distortion.h:85
Settings struct for compositor header.
Main compositor struct tying everything in the compositor together.
Definition: comp_compositor.h:73
size_t total_num_indices
Definition: comp_distortion.h:90
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:176
VkDescriptorSetLayout descriptor_set_layout
Definition: comp_distortion.h:103
void comp_distortion_destroy(struct comp_distortion *d)
Free and destroy all fields, does not free the destortion itself.
Definition: comp_distortion.c:222
float * vertices
Definition: comp_distortion.h:84
float warp_scale
Definition: comp_distortion.h:70
VkDeviceMemory memory
Definition: comp_distortion.h:38
void * mapped
Definition: comp_distortion.h:42
struct vk_bundle * vk
Definition: comp_distortion.h:55
uint64_t VkDeviceMemory
Definition: xrt_compositor.h:453
All of the device components that deals with interfacing to a users head.
Definition: xrt_device.h:92
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:494
float grow_for_undistort
Definition: comp_distortion.h:79
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:596
VkDescriptorBufferInfo descriptor
Definition: comp_distortion.h:39
bool quirk_draw_lines
Definition: comp_distortion.h:106
VkBufferUsageFlags usageFlags
Definition: comp_distortion.h:43
VkBuffer buffer
Definition: comp_distortion.h:37
VkDeviceSize alignment
Definition: comp_distortion.h:41
size_t stride
Definition: comp_distortion.h:86
A tightly packed 2x2 matrix of floats.
Definition: xrt_defines.h:255
A bundle of Vulkan functions and objects, used by both Compositor and Compositor client code...
Definition: vk_helpers.h:34
VkDevice device
Definition: comp_distortion.h:36
void comp_distortion_draw_mesh(struct comp_distortion *d, VkCommandBuffer command_buffer, int eye)
Definition: comp_distortion.c:615