monado/src/xrt/compositor/main/comp_distortion.h

168 lines
3.3 KiB
C
Raw Normal View History

2019-03-18 05:52:32 +00:00
// Copyright 2019, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Distortion shader code header.
* @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
* @author Jakob Bornecrantz <jakob@collabora.com>
2020-03-01 10:31:21 +00:00
* @ingroup comp_main
2019-03-18 05:52:32 +00:00
*/
#pragma once
#include "main/comp_settings.h"
#include "main/comp_compositor.h"
2019-10-07 23:12:06 +00:00
2019-03-18 05:52:32 +00:00
#ifdef __cplusplus
extern "C" {
#endif
/*
*
* Structs
*
*/
/*!
* Helper buffer for a single uniform buffer.
*
2020-03-01 10:31:21 +00:00
* @ingroup comp_main
2019-03-18 05:52:32 +00:00
*/
struct comp_uniform_buffer
{
VkDevice device;
VkBuffer buffer;
VkDeviceMemory memory;
VkDescriptorBufferInfo descriptor;
VkDeviceSize size;
VkDeviceSize alignment;
void *mapped;
VkBufferUsageFlags usageFlags;
VkMemoryPropertyFlags memoryPropertyFlags;
};
/*!
* Helper struct that encapsulate a distortion rendering code.
*
2020-03-01 10:31:21 +00:00
* @ingroup comp_main
2019-03-18 05:52:32 +00:00
*/
struct comp_distortion
{
// Holds all of the needed common Vulkan things.
struct vk_bundle *vk;
struct comp_uniform_buffer ubo_handle;
2019-10-07 23:12:06 +00:00
struct comp_uniform_buffer vbo_handle;
2019-10-23 21:00:22 +00:00
struct comp_uniform_buffer index_handle;
2019-03-18 05:52:32 +00:00
struct comp_uniform_buffer ubo_viewport_handles[2];
enum xrt_distortion_model distortion_model;
2019-03-18 05:52:32 +00:00
struct
{
float hmd_warp_param[4];
float aberr[4];
float lens_center[2][4];
float viewport_scale[2];
float warp_scale;
2019-03-14 15:23:32 +00:00
} ubo_pano;
2019-03-18 05:52:32 +00:00
struct
{
float coefficients[2][3][4];
float center[2][4];
float undistort_r2_cutoff[4];
float aspect_x_over_y;
float grow_for_undistort;
} ubo_vive;
2019-10-07 23:12:06 +00:00
struct
{
2019-10-23 21:00:22 +00:00
float *vertices;
int *indices;
2019-10-07 23:12:06 +00:00
size_t stride;
2019-10-23 21:00:22 +00:00
size_t num_vertices;
size_t num_indices[2];
size_t offset_indices[2];
size_t total_num_indices;
} mesh;
2019-10-07 23:12:06 +00:00
2019-03-18 05:52:32 +00:00
struct
{
struct xrt_matrix_2x2 rot;
int viewport_id;
bool flip_y;
} ubo_vp_data[2];
VkPipelineLayout pipeline_layout;
VkPipeline pipeline;
VkDescriptorSetLayout descriptor_set_layout;
VkDescriptorSet descriptor_sets[2];
2019-10-23 21:00:22 +00:00
bool quirk_draw_lines;
2019-03-18 05:52:32 +00:00
};
/*
*
* Functions.
*
*/
/*!
* Init a distortion, pass in the distortion so it can be embedded in a struct.
*
2020-03-01 10:31:21 +00:00
* @ingroup comp_main
2019-03-18 05:52:32 +00:00
*/
void
comp_distortion_init(struct comp_distortion *d,
struct comp_compositor *c,
VkRenderPass render_pass,
VkPipelineCache pipeline_cache,
enum xrt_distortion_model distortion_model,
2019-10-07 23:12:06 +00:00
struct xrt_hmd_parts *parts,
2019-03-18 05:52:32 +00:00
VkDescriptorPool descriptor_pool,
bool flip_y);
/*!
* Free and destroy all fields, does not free the destortion itself.
*
2020-03-01 10:31:21 +00:00
* @ingroup comp_main
2019-03-18 05:52:32 +00:00
*/
void
comp_distortion_destroy(struct comp_distortion *d);
/*!
* Update the descriptor set to a new image.
*
2020-03-01 10:31:21 +00:00
* @ingroup comp_main
2019-03-18 05:52:32 +00:00
*/
void
comp_distortion_update_descriptor_set(struct comp_distortion *d,
VkSampler sampler,
VkImageView view,
uint32_t eye);
/*!
* Submit draw commands to the given command_buffer.
*
2020-03-01 10:31:21 +00:00
* @ingroup comp_main
2019-03-18 05:52:32 +00:00
*/
void
comp_distortion_draw_quad(struct comp_distortion *d,
VkCommandBuffer command_buffer,
int eye);
2019-10-07 23:12:06 +00:00
void
comp_distortion_draw_mesh(struct comp_distortion *d,
VkCommandBuffer command_buffer,
int eye);
2019-03-18 05:52:32 +00:00
#ifdef __cplusplus
}
#endif