2020-10-05 22:30:31 +00:00
|
|
|
// Copyright 2019-2020, Collabora, Ltd.
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief The NEW compositor rendering code header.
|
|
|
|
* @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
|
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
2021-11-03 17:45:39 +00:00
|
|
|
* @ingroup comp_render
|
2020-10-05 22:30:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "xrt/xrt_compiler.h"
|
|
|
|
#include "xrt/xrt_defines.h"
|
|
|
|
|
|
|
|
#include "vk/vk_helpers.h"
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2021-11-03 17:45:39 +00:00
|
|
|
* @defgroup comp_render Compositor render code
|
|
|
|
* @ingroup comp
|
|
|
|
*
|
|
|
|
* @brief Rendering helper that is used by the compositor to render.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @addtogroup comp_render
|
2020-10-05 22:30:31 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2021-05-04 17:24:38 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Defines
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
//! How large in pixels the distortion image is.
|
|
|
|
#define COMP_DISTORTION_IMAGE_DIMENSIONS (128)
|
|
|
|
|
|
|
|
//! How many distortion images we have, one for each channel (3 rgb) and per view, total 6.
|
|
|
|
#define COMP_DISTORTION_NUM_IMAGES (6)
|
|
|
|
|
|
|
|
|
2021-10-01 19:50:09 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Util functions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Calculates a timewarp matrix which takes in NDC coords and gives out results
|
|
|
|
* in [-1, 1] space that needs a perspective divide.
|
|
|
|
*/
|
|
|
|
void
|
2022-03-27 21:10:25 +00:00
|
|
|
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);
|
2021-10-01 19:50:09 +00:00
|
|
|
|
|
|
|
|
2021-10-01 20:07:47 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Shaders.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Holds all shaders.
|
|
|
|
*/
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_shaders
|
2021-10-01 20:07:47 +00:00
|
|
|
{
|
|
|
|
VkShaderModule clear_comp;
|
|
|
|
VkShaderModule distortion_comp;
|
|
|
|
VkShaderModule distortion_timewarp_comp;
|
|
|
|
|
|
|
|
VkShaderModule mesh_vert;
|
|
|
|
VkShaderModule mesh_frag;
|
|
|
|
|
|
|
|
VkShaderModule equirect1_vert;
|
|
|
|
VkShaderModule equirect1_frag;
|
|
|
|
|
|
|
|
VkShaderModule equirect2_vert;
|
|
|
|
VkShaderModule equirect2_frag;
|
|
|
|
|
|
|
|
VkShaderModule layer_vert;
|
|
|
|
VkShaderModule layer_frag;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Loads all of the shaders that the compositor uses.
|
|
|
|
*/
|
|
|
|
bool
|
2022-03-27 21:10:25 +00:00
|
|
|
render_shaders_load(struct render_shaders *s, struct vk_bundle *vk);
|
2021-10-01 20:07:47 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Unload and cleanup shaders.
|
|
|
|
*/
|
|
|
|
void
|
2022-03-27 21:10:25 +00:00
|
|
|
render_shaders_close(struct render_shaders *s, struct vk_bundle *vk);
|
2021-10-01 20:07:47 +00:00
|
|
|
|
|
|
|
|
2020-10-05 22:30:31 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Buffer
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
2021-11-03 22:28:17 +00:00
|
|
|
* Helper struct holding a buffer and its memory.
|
2020-10-05 22:30:31 +00:00
|
|
|
*/
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_buffer
|
2020-10-05 22:30:31 +00:00
|
|
|
{
|
|
|
|
//! Backing memory.
|
|
|
|
VkDeviceMemory memory;
|
|
|
|
|
|
|
|
//! Buffer.
|
|
|
|
VkBuffer buffer;
|
|
|
|
|
2022-03-02 15:49:21 +00:00
|
|
|
//! Size requested for the buffer.
|
2020-10-05 22:30:31 +00:00
|
|
|
VkDeviceSize size;
|
|
|
|
|
|
|
|
//! Size of the memory allocation.
|
|
|
|
VkDeviceSize allocation_size;
|
|
|
|
|
|
|
|
//! Alignment of the buffer.
|
|
|
|
VkDeviceSize alignment;
|
|
|
|
|
|
|
|
void *mapped;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Initialize a buffer.
|
|
|
|
*/
|
|
|
|
VkResult
|
2022-03-27 21:10:25 +00:00
|
|
|
render_buffer_init(struct vk_bundle *vk,
|
|
|
|
struct render_buffer *buffer,
|
|
|
|
VkBufferUsageFlags usage_flags,
|
|
|
|
VkMemoryPropertyFlags memory_property_flags,
|
|
|
|
VkDeviceSize size);
|
2020-10-05 22:30:31 +00:00
|
|
|
|
2022-03-22 11:05:46 +00:00
|
|
|
/*!
|
|
|
|
* Initialize a buffer, making it exportable.
|
|
|
|
*/
|
|
|
|
VkResult
|
2022-03-27 21:10:25 +00:00
|
|
|
render_buffer_init_exportable(struct vk_bundle *vk,
|
|
|
|
struct render_buffer *buffer,
|
|
|
|
VkBufferUsageFlags usage_flags,
|
|
|
|
VkMemoryPropertyFlags memory_property_flags,
|
|
|
|
VkDeviceSize size);
|
2022-03-22 11:05:46 +00:00
|
|
|
|
2020-10-05 22:30:31 +00:00
|
|
|
/*!
|
2021-03-30 16:51:28 +00:00
|
|
|
* Frees all resources that this buffer has, but does not free the buffer itself.
|
2020-10-05 22:30:31 +00:00
|
|
|
*/
|
|
|
|
void
|
2022-03-27 21:10:25 +00:00
|
|
|
render_buffer_close(struct vk_bundle *vk, struct render_buffer *buffer);
|
2020-10-05 22:30:31 +00:00
|
|
|
|
|
|
|
/*!
|
2022-03-27 21:10:25 +00:00
|
|
|
* Maps the memory, sets render_buffer::mapped to the memory.
|
2020-10-05 22:30:31 +00:00
|
|
|
*/
|
|
|
|
VkResult
|
2022-03-27 21:10:25 +00:00
|
|
|
render_buffer_map(struct vk_bundle *vk, struct render_buffer *buffer);
|
2020-10-05 22:30:31 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Unmaps the memory.
|
|
|
|
*/
|
|
|
|
void
|
2022-03-27 21:10:25 +00:00
|
|
|
render_buffer_unmap(struct vk_bundle *vk, struct render_buffer *buffer);
|
2020-10-05 22:30:31 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Maps the buffer, and copies the given data to the buffer.
|
|
|
|
*/
|
|
|
|
VkResult
|
2022-03-27 21:10:25 +00:00
|
|
|
render_buffer_map_and_write(struct vk_bundle *vk, struct render_buffer *buffer, void *data, VkDeviceSize size);
|
2020-10-05 22:30:31 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Writes the given data to the buffer, will map it temporarily if not mapped.
|
|
|
|
*/
|
|
|
|
VkResult
|
2022-03-27 21:10:25 +00:00
|
|
|
render_buffer_write(struct vk_bundle *vk, struct render_buffer *buffer, void *data, VkDeviceSize size);
|
2020-10-05 22:30:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Resources
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Holds all pools and static resources for rendering.
|
|
|
|
*/
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_resources
|
2020-10-05 22:30:31 +00:00
|
|
|
{
|
2021-11-02 18:37:07 +00:00
|
|
|
//! Vulkan resources.
|
|
|
|
struct vk_bundle *vk;
|
|
|
|
|
2021-10-01 20:07:47 +00:00
|
|
|
/*
|
|
|
|
* Loaded resources.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//! All shaders loaded.
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_shaders *shaders;
|
2021-10-01 20:07:47 +00:00
|
|
|
|
|
|
|
|
2020-10-05 22:30:31 +00:00
|
|
|
/*
|
|
|
|
* Shared pools and caches.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//! Shared for all rendering.
|
|
|
|
VkPipelineCache pipeline_cache;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Static
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
//! The binding index for the source texture.
|
|
|
|
uint32_t src_binding;
|
|
|
|
|
|
|
|
//! The binding index for the UBO.
|
|
|
|
uint32_t ubo_binding;
|
|
|
|
|
|
|
|
//! Descriptor set layout for mesh distortion.
|
|
|
|
VkDescriptorSetLayout descriptor_set_layout;
|
|
|
|
|
|
|
|
//! Pipeline layout used for mesh.
|
|
|
|
VkPipelineLayout pipeline_layout;
|
|
|
|
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_buffer vbo;
|
|
|
|
struct render_buffer ibo;
|
2020-10-05 22:30:31 +00:00
|
|
|
|
2021-11-08 21:02:03 +00:00
|
|
|
uint32_t vertex_count;
|
|
|
|
uint32_t index_counts[2];
|
2020-10-05 22:30:31 +00:00
|
|
|
uint32_t stride;
|
2021-11-08 21:02:03 +00:00
|
|
|
uint32_t index_offsets[2];
|
|
|
|
uint32_t index_count_total;
|
2021-09-29 16:35:05 +00:00
|
|
|
|
|
|
|
//! Descriptor pool for mesh shaders.
|
|
|
|
VkDescriptorPool descriptor_pool;
|
|
|
|
|
|
|
|
//! Info ubos, only supports two views currently.
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_buffer ubos[2];
|
2020-10-05 22:30:31 +00:00
|
|
|
} mesh;
|
2021-05-04 17:24:38 +00:00
|
|
|
|
2022-02-21 20:31:46 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
VkImage image;
|
|
|
|
VkImageView image_view;
|
|
|
|
VkDeviceMemory memory;
|
|
|
|
} color;
|
|
|
|
} dummy;
|
|
|
|
|
2021-05-04 17:24:38 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
//! Descriptor pool for compute work.
|
|
|
|
VkDescriptorPool descriptor_pool;
|
|
|
|
|
|
|
|
//! The source projection view binding point.
|
|
|
|
uint32_t src_binding;
|
|
|
|
|
|
|
|
//! Image storing the distortion.
|
|
|
|
uint32_t distortion_binding;
|
|
|
|
|
|
|
|
//! Writing the image out too.
|
|
|
|
uint32_t target_binding;
|
|
|
|
|
|
|
|
//! Uniform data binding.
|
|
|
|
uint32_t ubo_binding;
|
|
|
|
|
|
|
|
//! Dummy sampler for null images.
|
|
|
|
VkSampler default_sampler;
|
|
|
|
|
|
|
|
//! Descriptor set layout for compute distortion.
|
|
|
|
VkDescriptorSetLayout descriptor_set_layout;
|
|
|
|
|
|
|
|
//! Pipeline layout used for compute distortion.
|
|
|
|
VkPipelineLayout pipeline_layout;
|
|
|
|
|
|
|
|
//! Doesn't depend on target so is static.
|
|
|
|
VkPipeline clear_pipeline;
|
|
|
|
|
|
|
|
//! Doesn't depend on target so is static.
|
|
|
|
VkPipeline distortion_pipeline;
|
|
|
|
|
2021-08-02 15:42:26 +00:00
|
|
|
//! Doesn't depend on target so is static.
|
|
|
|
VkPipeline distortion_timewarp_pipeline;
|
|
|
|
|
2021-05-04 17:24:38 +00:00
|
|
|
//! Target info.
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_buffer ubo;
|
2021-05-04 17:24:38 +00:00
|
|
|
} compute;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
2021-08-02 15:42:26 +00:00
|
|
|
//! Transform to go from UV to tangle angles.
|
|
|
|
struct xrt_normalized_rect uv_to_tanangle[2];
|
|
|
|
|
2021-05-04 17:24:38 +00:00
|
|
|
//! Backing memory to distortion images.
|
|
|
|
VkDeviceMemory device_memories[COMP_DISTORTION_NUM_IMAGES];
|
|
|
|
|
|
|
|
//! Distortion images.
|
|
|
|
VkImage images[COMP_DISTORTION_NUM_IMAGES];
|
|
|
|
|
|
|
|
//! The views into the distortion images.
|
|
|
|
VkImageView image_views[COMP_DISTORTION_NUM_IMAGES];
|
|
|
|
} distortion;
|
2020-10-05 22:30:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Allocate pools and static resources.
|
|
|
|
*
|
|
|
|
* @ingroup comp_main
|
|
|
|
*/
|
|
|
|
bool
|
2022-03-27 21:10:25 +00:00
|
|
|
render_resources_init(struct render_resources *r,
|
|
|
|
struct render_shaders *shaders,
|
|
|
|
struct vk_bundle *vk,
|
|
|
|
struct xrt_device *xdev);
|
2020-10-05 22:30:31 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Free all pools and static resources, does not free the struct itself.
|
|
|
|
*/
|
|
|
|
void
|
2022-03-27 21:10:25 +00:00
|
|
|
render_resources_close(struct render_resources *r);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Shared between both gfx and compute.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* The pure data information about a view that the renderer is rendering to.
|
|
|
|
*/
|
|
|
|
struct render_viewport_data
|
|
|
|
{
|
|
|
|
uint32_t x, y;
|
|
|
|
uint32_t w, h;
|
|
|
|
};
|
2020-10-05 22:30:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
2021-09-23 19:11:53 +00:00
|
|
|
* Rendering target
|
2020-10-05 22:30:31 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
2022-03-27 21:10:25 +00:00
|
|
|
* Each rendering (@ref render_gfx
|
|
|
|
) render to one or more targets
|
|
|
|
* (@ref render_gfx_target_resources), each target can have one or more
|
|
|
|
* views (@ref render_gfx_view), this struct holds all the data that is
|
2021-09-23 19:11:53 +00:00
|
|
|
* specific to the target.
|
2020-10-05 22:30:31 +00:00
|
|
|
*/
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_gfx_target_data
|
2020-10-05 22:30:31 +00:00
|
|
|
{
|
|
|
|
// The format that should be used to read from the target.
|
|
|
|
VkFormat format;
|
|
|
|
|
|
|
|
// Is this target a external target.
|
|
|
|
bool is_external;
|
|
|
|
|
|
|
|
//! Total height and width of the target.
|
|
|
|
uint32_t width, height;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
2022-03-27 21:10:25 +00:00
|
|
|
* Each rendering (@ref render_gfx) render to one or more targets
|
|
|
|
* (@ref render_gfx_target_resources), each target can have one or more
|
|
|
|
* views (@ref render_gfx_view), this struct holds all the vulkan resources
|
2021-09-23 19:11:53 +00:00
|
|
|
* that is specific to the target.
|
|
|
|
*
|
|
|
|
* Technically the framebuffer could be moved out of this struct and all of this
|
|
|
|
* state be turned into a CSO object that depends only only the format and
|
|
|
|
* external status of the target, but is combined to reduce the number of
|
|
|
|
* objects needed to render.
|
|
|
|
*/
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_gfx_target_resources
|
2021-09-23 19:11:53 +00:00
|
|
|
{
|
|
|
|
//! Collections of static resources.
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_resources *r;
|
2021-09-23 19:11:53 +00:00
|
|
|
|
|
|
|
//! The data for this target.
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_gfx_target_data data;
|
2021-09-23 19:11:53 +00:00
|
|
|
|
|
|
|
//! Render pass used for rendering, does not depend on framebuffer.
|
|
|
|
VkRenderPass render_pass;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
//! Pipeline layout used for mesh, does not depend on framebuffer.
|
|
|
|
VkPipeline pipeline;
|
|
|
|
} mesh;
|
|
|
|
|
|
|
|
//! Framebuffer for this target, depends on given VkImageView.
|
|
|
|
VkFramebuffer framebuffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Init a target resource struct, caller has to keep target alive until closed.
|
|
|
|
*/
|
|
|
|
bool
|
2022-03-27 21:10:25 +00:00
|
|
|
render_gfx_target_resources_init(struct render_gfx_target_resources *rtr,
|
|
|
|
struct render_resources *r,
|
|
|
|
VkImageView target,
|
|
|
|
struct render_gfx_target_data *data);
|
2021-09-23 19:11:53 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Frees all resources held by the target, does not free the struct itself.
|
|
|
|
*/
|
|
|
|
void
|
2022-03-27 21:10:25 +00:00
|
|
|
render_gfx_target_resources_close(struct render_gfx_target_resources *rtr);
|
2021-09-23 19:11:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Rendering
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
2022-03-27 21:10:25 +00:00
|
|
|
* Each rendering (@ref render_gfx) render to one or more targets
|
|
|
|
* (@ref render_gfx_target_resources), each target can have one or more
|
|
|
|
* views (@ref render_gfx_view), this struct holds all the vulkan resources
|
2021-09-23 19:11:53 +00:00
|
|
|
* that is specific to the view.
|
2020-10-05 22:30:31 +00:00
|
|
|
*/
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_gfx_view
|
2020-10-05 22:30:31 +00:00
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
VkDescriptorSet descriptor_set;
|
|
|
|
} mesh;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* A rendering is used to create command buffers needed to do one frame of
|
|
|
|
* compositor rendering, it holds onto resources used by the command buffer.
|
|
|
|
*/
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_gfx
|
2020-10-05 22:30:31 +00:00
|
|
|
{
|
2021-09-23 19:11:53 +00:00
|
|
|
//! Resources that we are based on.
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_resources *r;
|
2020-10-05 22:30:31 +00:00
|
|
|
|
2021-09-23 19:11:53 +00:00
|
|
|
//! The current target we are rendering too, can change during command building.
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_gfx_target_resources *rtr;
|
2021-09-23 19:11:53 +00:00
|
|
|
|
2020-10-05 22:30:31 +00:00
|
|
|
//! Command buffer where all commands are recorded.
|
|
|
|
VkCommandBuffer cmd;
|
|
|
|
|
|
|
|
//! Holds per view data.
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_gfx_view views[2];
|
2020-10-05 22:30:31 +00:00
|
|
|
|
|
|
|
//! The current view we are rendering to.
|
|
|
|
uint32_t current_view;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Init struct and create resources needed for rendering.
|
|
|
|
*/
|
|
|
|
bool
|
2022-03-27 21:10:25 +00:00
|
|
|
render_gfx_init(struct render_gfx *rr, struct render_resources *r);
|
2021-09-23 19:11:53 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Frees any unneeded resources and ends the command buffer so it can be used.
|
|
|
|
*/
|
|
|
|
void
|
2022-03-27 21:10:25 +00:00
|
|
|
render_gfx_finalize(struct render_gfx *rr);
|
2020-10-05 22:30:31 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Frees all resources held by the rendering, does not free the struct itself.
|
|
|
|
*/
|
|
|
|
void
|
2022-03-27 21:10:25 +00:00
|
|
|
render_gfx_close(struct render_gfx *rr);
|
2020-10-05 22:30:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Drawing
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* UBO data that is sent to the mesh shaders.
|
|
|
|
*/
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_gfx_mesh_ubo_data
|
2020-10-05 22:30:31 +00:00
|
|
|
{
|
2021-04-12 17:30:22 +00:00
|
|
|
struct xrt_matrix_2x2 vertex_rot;
|
2021-09-29 20:53:35 +00:00
|
|
|
|
|
|
|
struct xrt_normalized_rect post_transform;
|
2020-10-05 22:30:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* This function allocates everything to start a single rendering. This is the
|
|
|
|
* first function you call when you start rendering, you follow up with a call
|
2022-03-27 21:10:25 +00:00
|
|
|
* to render_gfx_begin_view.
|
2020-10-05 22:30:31 +00:00
|
|
|
*/
|
|
|
|
bool
|
2022-03-27 21:10:25 +00:00
|
|
|
render_gfx_begin_target(struct render_gfx *rr, struct render_gfx_target_resources *rtr);
|
2020-10-05 22:30:31 +00:00
|
|
|
|
|
|
|
void
|
2022-03-27 21:10:25 +00:00
|
|
|
render_gfx_end_target(struct render_gfx *rr);
|
2020-10-05 22:30:31 +00:00
|
|
|
|
|
|
|
void
|
2022-03-27 21:10:25 +00:00
|
|
|
render_gfx_begin_view(struct render_gfx *rr, uint32_t view, struct render_viewport_data *viewport_data);
|
2020-10-05 22:30:31 +00:00
|
|
|
|
|
|
|
void
|
2022-03-27 21:10:25 +00:00
|
|
|
render_gfx_end_view(struct render_gfx *rr);
|
2020-10-05 22:30:31 +00:00
|
|
|
|
|
|
|
void
|
2022-03-27 21:10:25 +00:00
|
|
|
render_gfx_distortion(struct render_gfx *rr);
|
2021-04-15 20:25:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Update functions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2022-03-27 21:10:25 +00:00
|
|
|
render_gfx_update_distortion(struct render_gfx *rr,
|
|
|
|
uint32_t view,
|
|
|
|
VkSampler sampler,
|
|
|
|
VkImageView image_view,
|
|
|
|
struct render_gfx_mesh_ubo_data *data);
|
2021-04-15 20:25:39 +00:00
|
|
|
|
2020-10-05 22:30:31 +00:00
|
|
|
|
2021-05-04 17:24:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Compute distortion.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* A compute rendering is used to create command buffers needed to do one frame
|
|
|
|
* of compositor rendering using compute shaders, it holds onto resources used
|
|
|
|
* by the command buffer.
|
|
|
|
*/
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_compute
|
2021-05-04 17:24:38 +00:00
|
|
|
{
|
2021-11-02 18:37:07 +00:00
|
|
|
//! Shared resources.
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_resources *r;
|
2021-05-04 17:24:38 +00:00
|
|
|
|
|
|
|
//! Command buffer where all commands are recorded.
|
|
|
|
VkCommandBuffer cmd;
|
|
|
|
|
2021-09-25 14:45:11 +00:00
|
|
|
//! Shared descriptor set between clear, projection and timewarp.
|
|
|
|
VkDescriptorSet descriptor_set;
|
2021-05-04 17:24:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* UBO data that is sent to the compute distortion shaders.
|
|
|
|
*/
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_compute_distortion_ubo_data
|
|
|
|
|
2021-05-04 17:24:38 +00:00
|
|
|
{
|
2022-03-27 21:10:25 +00:00
|
|
|
struct render_viewport_data views[2];
|
2021-05-04 17:24:38 +00:00
|
|
|
struct xrt_normalized_rect pre_transforms[2];
|
|
|
|
struct xrt_normalized_rect post_transforms[2];
|
|
|
|
struct xrt_matrix_4x4 transforms[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Init struct and create resources needed for compute rendering.
|
|
|
|
*/
|
|
|
|
bool
|
2022-03-27 21:10:25 +00:00
|
|
|
render_compute_init(struct render_compute *crc, struct render_resources *r);
|
2021-05-04 17:24:38 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Frees all resources held by the compute rendering, does not free the struct itself.
|
|
|
|
*/
|
|
|
|
void
|
2022-03-27 21:10:25 +00:00
|
|
|
render_compute_close(struct render_compute *crc);
|
2021-05-04 17:24:38 +00:00
|
|
|
|
|
|
|
bool
|
2022-03-27 21:10:25 +00:00
|
|
|
render_compute_begin(struct render_compute *crc);
|
2021-05-04 17:24:38 +00:00
|
|
|
|
2021-08-02 15:42:26 +00:00
|
|
|
void
|
2022-03-27 21:10:25 +00:00
|
|
|
render_compute_projection_timewarp(struct render_compute *crc,
|
|
|
|
VkSampler src_samplers[2],
|
|
|
|
VkImageView src_image_views[2],
|
|
|
|
const struct xrt_normalized_rect src_rects[2],
|
|
|
|
const struct xrt_pose src_poses[2],
|
|
|
|
const struct xrt_fov src_fovs[2],
|
|
|
|
const struct xrt_pose new_poses[2],
|
|
|
|
VkImage target_image,
|
|
|
|
VkImageView target_image_view,
|
|
|
|
const struct render_viewport_data views[2]);
|
2021-08-02 15:42:26 +00:00
|
|
|
|
2021-05-04 17:24:38 +00:00
|
|
|
void
|
2022-03-27 21:10:25 +00:00
|
|
|
render_compute_projection(struct render_compute *crc, //
|
|
|
|
VkSampler src_samplers[2], //
|
|
|
|
VkImageView src_image_views[2], //
|
|
|
|
const struct xrt_normalized_rect src_rects[2], //
|
|
|
|
VkImage target_image, //
|
|
|
|
VkImageView target_image_view, //
|
|
|
|
const struct render_viewport_data views[2]); //
|
2021-05-04 17:24:38 +00:00
|
|
|
|
|
|
|
void
|
2022-03-27 21:10:25 +00:00
|
|
|
render_compute_clear(struct render_compute *crc, //
|
|
|
|
VkImage target_image, //
|
|
|
|
VkImageView target_image_view, //
|
|
|
|
const struct render_viewport_data views[2]); //
|
2021-05-04 17:24:38 +00:00
|
|
|
|
|
|
|
bool
|
2022-03-27 21:10:25 +00:00
|
|
|
render_compute_end(struct render_compute *crc);
|
2021-05-04 17:24:38 +00:00
|
|
|
|
|
|
|
|
2020-10-05 22:30:31 +00:00
|
|
|
/*!
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|