Monado OpenXR Runtime
Files | Data Structures | Macros | Typedefs | Enumerations | Functions
Main compositor code

Main compositor code. More...

Collaboration diagram for Main compositor code:

Files

file  comp_compositor.c
 Main compositor written using Vulkan implementation.
 
file  comp_compositor.h
 Main compositor written using Vulkan header.
 
file  comp_distortion.c
 Distortion shader code.
 
file  comp_distortion.h
 Distortion shader code header.
 
file  comp_renderer.c
 Compositor rendering code.
 
file  comp_renderer.h
 Compositor rendering code header.
 
file  comp_settings.c
 Settings struct for compositor.
 
file  comp_settings.h
 Settings struct for compositor header.
 
file  comp_swapchain.c
 Swapchain code for the main compositor.
 
file  comp_vk_swapchain.c
 Vulkan swapchain code.
 
file  comp_vk_swapchain.h
 Vulkan swapchain code header.
 
file  comp_window.h
 Compositor window header.
 
file  comp_window_direct.c
 Common direct mode window code.
 
file  comp_window_direct.h
 Common direct mode window code header.
 
file  comp_window_direct_nvidia.c
 Direct mode window code.
 
file  comp_window_direct_randr.c
 Direct mode window code.
 
file  comp_window_wayland.c
 Wayland window code.
 
file  comp_window_xcb.c
 XCB window code.
 

Data Structures

struct  comp_swapchain_image
 A single swapchain image, holds the needed state for tracking image usage. More...
 
struct  comp_swapchain
 A swapchain that is almost a one to one mapping to a OpenXR swapchain. More...
 
struct  comp_compositor
 Main compositor struct tying everything in the compositor together. More...
 
struct  comp_uniform_buffer
 Helper buffer for a single uniform buffer. More...
 
struct  comp_distortion
 Helper struct that encapsulate a distortion rendering code. More...
 
struct  comp_renderer
 Holds associated vulkan objects and state to render with a distortion. More...
 
struct  comp_settings
 Settings for the compositor. More...
 
struct  vk_swapchain_buffer
 A pair of VkImage and VkImageView. More...
 
struct  vk_swapchain
 Wraps and manage VkSwapchainKHR and VkSurfaceKHR, used by Compositor code. More...
 
struct  comp_window
 A output device or a window, often directly connected to the device. More...
 

Macros

#define COMP_SPEW(c, ...)
 Spew level logging. More...
 
#define COMP_DEBUG(c, ...)
 Debug level logging. More...
 
#define COMP_PRINT_MODE(c, ...)
 Mode printing. More...
 
#define COMP_ERROR(c, ...)
 Error level logging. More...
 

Typedefs

typedef void(* vk_swapchain_cb) (uint32_t width, uint32_t height, void *priv)
 Callback when a vk_swapchain changes size. More...
 

Enumerations

enum  window_type {
  WINDOW_NONE = 0, WINDOW_AUTO, WINDOW_XCB, WINDOW_WAYLAND,
  WINDOW_DIRECT_RANDR, WINDOW_DIRECT_NVIDIA
}
 Window type to use. More...
 

Functions

void comp_compositor_garbage_collect (struct comp_compositor *c)
 Do garbage collection, destroying any resources that has been scheduled for destruction from other threads. More...
 
struct xrt_swapchaincomp_swapchain_create (struct xrt_compositor *xc, enum xrt_swapchain_create_flags create, enum xrt_swapchain_usage_bits bits, int64_t format, uint32_t sample_count, uint32_t width, uint32_t height, uint32_t face_count, uint32_t array_size, uint32_t mip_count)
 A compositor function that is implemented in the swapchain code. More...
 
void comp_swapchain_really_destroy (struct comp_swapchain *sc)
 Swapchain destruct is delayed until it is safe to destroy them, this function does the actual destruction and is called from comp_compositor_garbage_collect. More...
 
void comp_swapchain_image_cleanup (struct vk_bundle *vk, uint32_t array_size, struct comp_swapchain_image *image)
 Free and destroy any initialized fields on the given image, safe to pass in images that has one or all fields set to NULL. More...
 
void comp_compositor_print (struct comp_compositor *c, const char *func, const char *fmt,...) XRT_PRINTF_FORMAT(3
 Printer helper. More...
 
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. More...
 
void comp_distortion_destroy (struct comp_distortion *d)
 Free and destroy all fields, does not free the destortion itself. More...
 
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. More...
 
void comp_distortion_draw_quad (struct comp_distortion *d, VkCommandBuffer command_buffer, int eye)
 Submit draw commands to the given command_buffer. More...
 
struct comp_renderercomp_renderer_create (struct comp_compositor *c)
 Called by the main compositor code to create the renderer. More...
 
void comp_renderer_frame (struct comp_renderer *r, struct comp_swapchain_image *left, uint32_t left_layer, struct comp_swapchain_image *right, uint32_t right_layer)
 Render a distorted stereo frame. More...
 
void comp_renderer_destroy (struct comp_renderer *r)
 Clean up and free the renderer. More...
 
void comp_settings_init (struct comp_settings *s, struct xrt_device *xdev)
 Initialize the settings struct with either defaults or loaded setting. More...
 
void vk_swapchain_init (struct vk_swapchain *sc, struct vk_bundle *vk, vk_swapchain_cb dimension_cb, void *priv)
 Wraps and manage VkSwapchainKHR and VkSurfaceKHR, used by Compositor code. More...
 
void vk_swapchain_create (struct vk_swapchain *sc, uint32_t width, uint32_t height, VkFormat color_format, VkColorSpaceKHR color_space, VkPresentModeKHR present_mode)
 Initialize the given vk_swapchain, does not allocate. More...
 
VkResult vk_swapchain_acquire_next_image (struct vk_swapchain *sc, VkSemaphore semaphore, uint32_t *index)
 Acquire a image index from the given vk_swapchain for rendering. More...
 
VkResult vk_swapchain_present (struct vk_swapchain *sc, VkQueue queue, uint32_t index, VkSemaphore semaphore)
 Make the given vk_swapchain present the next acquired image. More...
 
void vk_swapchain_cleanup (struct vk_swapchain *sc)
 Free all managed resources on the given vk_swapchain, does not free the struct itself. More...
 
struct comp_windowcomp_window_xcb_create (struct comp_compositor *c)
 Create a xcb window. More...
 
struct comp_windowcomp_window_wayland_create (struct comp_compositor *c)
 Create a wayland window. More...
 
struct comp_windowcomp_window_direct_randr_create (struct comp_compositor *c)
 Create a direct surface to a HMD over RandR. More...
 
struct comp_windowcomp_window_direct_nvidia_create (struct comp_compositor *c)
 Create a direct surface to a HMD on NVIDIA. More...
 

Detailed Description

Main compositor code.

Macro Definition Documentation

◆ COMP_DEBUG

#define COMP_DEBUG (   c,
  ... 
)

#include <compositor/main/comp_compositor.h>

Value:
do { \
if (c->settings.print_debug) { \
comp_compositor_print(c, __func__, __VA_ARGS__); \
} \
} while (false)

Debug level logging.

Referenced by comp_window_direct_create_surface(), and comp_window_direct_get_primary_display_mode().

◆ COMP_ERROR

#define COMP_ERROR (   c,
  ... 
)

◆ COMP_PRINT_MODE

#define COMP_PRINT_MODE (   c,
  ... 
)

#include <compositor/main/comp_compositor.h>

Value:
do { \
if (c->settings.print_modes) { \
comp_compositor_print(c, __func__, __VA_ARGS__); \
} \
} while (false)

Mode printing.

◆ COMP_SPEW

#define COMP_SPEW (   c,
  ... 
)

#include <compositor/main/comp_compositor.h>

Value:
do { \
if (c->settings.print_spew) { \
comp_compositor_print(c, __func__, __VA_ARGS__); \
} \
} while (false)

Spew level logging.

Referenced by comp_swapchain_really_destroy().

Typedef Documentation

◆ vk_swapchain_cb

typedef void(* vk_swapchain_cb) (uint32_t width, uint32_t height, void *priv)

#include <compositor/main/comp_vk_swapchain.h>

Callback when a vk_swapchain changes size.

Enumeration Type Documentation

◆ window_type

#include <compositor/main/comp_settings.h>

Window type to use.

Enumerator
WINDOW_NONE 
WINDOW_AUTO 
WINDOW_XCB 
WINDOW_WAYLAND 
WINDOW_DIRECT_RANDR 
WINDOW_DIRECT_NVIDIA 

Function Documentation

◆ comp_compositor_garbage_collect()

void comp_compositor_garbage_collect ( struct comp_compositor c)

#include <compositor/main/comp_compositor.h>

Do garbage collection, destroying any resources that has been scheduled for destruction from other threads.

◆ comp_compositor_print()

void comp_compositor_print ( struct comp_compositor c,
const char *  func,
const char *  fmt,
  ... 
)

#include <compositor/main/comp_compositor.h>

Printer helper.

◆ comp_distortion_destroy()

void comp_distortion_destroy ( struct comp_distortion d)

#include <compositor/main/comp_distortion.h>

Free and destroy all fields, does not free the destortion itself.

References comp_distortion::descriptor_set_layout, vk_bundle::device, comp_distortion::vk, and vk_bundle::vkDestroyDescriptorSetLayout.

◆ comp_distortion_draw_quad()

void comp_distortion_draw_quad ( struct comp_distortion d,
VkCommandBuffer  command_buffer,
int  eye 
)

◆ comp_distortion_init()

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 
)

◆ comp_distortion_update_descriptor_set()

void comp_distortion_update_descriptor_set ( struct comp_distortion d,
VkSampler  sampler,
VkImageView  view,
uint32_t  eye 
)

#include <compositor/main/comp_distortion.h>

Update the descriptor set to a new image.

References comp_distortion::vk.

◆ comp_renderer_create()

struct comp_renderer* comp_renderer_create ( struct comp_compositor c)

#include <compositor/main/comp_renderer.h>

Called by the main compositor code to create the renderer.

References U_TYPED_CALLOC.

◆ comp_renderer_destroy()

void comp_renderer_destroy ( struct comp_renderer r)

#include <compositor/main/comp_renderer.h>

Clean up and free the renderer.

◆ comp_renderer_frame()

void comp_renderer_frame ( struct comp_renderer r,
struct comp_swapchain_image left,
uint32_t  left_layer,
struct comp_swapchain_image right,
uint32_t  right_layer 
)

#include <compositor/main/comp_renderer.h>

Render a distorted stereo frame.

◆ comp_settings_init()

void comp_settings_init ( struct comp_settings s,
struct xrt_device xdev 
)

#include <compositor/main/comp_settings.h>

Initialize the settings struct with either defaults or loaded setting.

References WINDOW_AUTO, WINDOW_DIRECT_NVIDIA, WINDOW_DIRECT_RANDR, WINDOW_WAYLAND, and WINDOW_XCB.

◆ comp_swapchain_create()

struct xrt_swapchain* comp_swapchain_create ( struct xrt_compositor xc,
enum xrt_swapchain_create_flags  create,
enum xrt_swapchain_usage_bits  bits,
int64_t  format,
uint32_t  sample_count,
uint32_t  width,
uint32_t  height,
uint32_t  face_count,
uint32_t  array_size,
uint32_t  mip_count 
)

#include <compositor/main/comp_compositor.h>

A compositor function that is implemented in the swapchain code.

Todo:
memory leak of image fds and swapchain

Referenced by xrt_gfx_provider_create_fd().

◆ comp_swapchain_image_cleanup()

void comp_swapchain_image_cleanup ( struct vk_bundle vk,
uint32_t  array_size,
struct comp_swapchain_image image 
)

◆ comp_swapchain_really_destroy()

void comp_swapchain_really_destroy ( struct comp_swapchain sc)

#include <compositor/main/comp_compositor.h>

Swapchain destruct is delayed until it is safe to destroy them, this function does the actual destruction and is called from comp_compositor_garbage_collect.

References xrt_swapchain::array_size, comp_swapchain::base, xrt_swapchain_fd::base, comp_swapchain::c, COMP_SPEW, comp_swapchain_image_cleanup(), comp_swapchain::images, xrt_swapchain::num_images, and comp_compositor::vk.

◆ comp_window_direct_nvidia_create()

struct comp_window* comp_window_direct_nvidia_create ( struct comp_compositor c)

#include <compositor/main/comp_window.h>

Create a direct surface to a HMD on NVIDIA.

References comp_window_direct_nvidia::base, comp_window::destroy, comp_window::name, and U_TYPED_CALLOC.

◆ comp_window_direct_randr_create()

struct comp_window* comp_window_direct_randr_create ( struct comp_compositor c)

#include <compositor/main/comp_window.h>

Create a direct surface to a HMD over RandR.

References comp_window_direct_randr::base, comp_window::destroy, comp_window::name, and U_TYPED_CALLOC.

◆ comp_window_wayland_create()

struct comp_window* comp_window_wayland_create ( struct comp_compositor c)

◆ comp_window_xcb_create()

struct comp_window* comp_window_xcb_create ( struct comp_compositor c)

◆ vk_swapchain_acquire_next_image()

VkResult vk_swapchain_acquire_next_image ( struct vk_swapchain sc,
VkSemaphore  semaphore,
uint32_t *  index 
)

◆ vk_swapchain_cleanup()

void vk_swapchain_cleanup ( struct vk_swapchain sc)

#include <compositor/main/comp_vk_swapchain.h>

Free all managed resources on the given vk_swapchain, does not free the struct itself.

◆ vk_swapchain_create()

void vk_swapchain_create ( struct vk_swapchain sc,
uint32_t  width,
uint32_t  height,
VkFormat  color_format,
VkColorSpaceKHR  color_space,
VkPresentModeKHR  present_mode 
)

#include <compositor/main/comp_vk_swapchain.h>

Initialize the given vk_swapchain, does not allocate.

Referenced by comp_window_direct_init_swapchain().

◆ vk_swapchain_init()

void vk_swapchain_init ( struct vk_swapchain sc,
struct vk_bundle vk,
vk_swapchain_cb  dimension_cb,
void *  priv 
)

#include <compositor/main/comp_vk_swapchain.h>

Wraps and manage VkSwapchainKHR and VkSurfaceKHR, used by Compositor code.

References vk_swapchain::cb_priv, vk_swapchain::dimension_cb, and vk_swapchain::vk.

◆ vk_swapchain_present()

VkResult vk_swapchain_present ( struct vk_swapchain sc,
VkQueue  queue,
uint32_t  index,
VkSemaphore  semaphore 
)

#include <compositor/main/comp_vk_swapchain.h>

Make the given vk_swapchain present the next acquired image.

References vk_swapchain::swap_chain, vk_swapchain::vk, and vk_bundle::vkQueuePresentKHR.