Monado OpenXR Runtime
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_frame.h
 Small helper functions to manage frames.
 
file  comp_main_interface.h
 Header for the main compositor interface.
 
file  comp_mirror_to_debug_gui.c
 Compositor mirroring code.
 
file  comp_mirror_to_debug_gui.h
 Compositor mirroring code.
 
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_target.h
 Abstracted compositor rendering target.
 
file  comp_target_swapchain.c
 Target Vulkan swapchain code.
 
file  comp_target_swapchain.h
 Target Vulkan swapchain code header.
 
file  comp_window.h
 Compositor window header.
 
file  comp_window_android.c
 Android window code.
 
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_mswin.c
 Microsoft Windows window code.
 
file  comp_window_peek.c
 Displays the content of one or both eye onto a desktop window.
 
file  comp_window_peek.h
 Displays the content of one or both eye onto a desktop window.
 
file  comp_window_vk_display.c
 Direct mode on PLATFORM_DISPLAY_KHR code.
 
file  comp_window_wayland.c
 Wayland window code.
 
file  comp_window_xcb.c
 XCB window code.
 
file  comp_multi_interface.h
 Interface for the multi-client layer code.
 
file  comp_render_cs.c
 Compositor rendering code.
 

Data Structures

struct  comp_compositor
 Main compositor struct tying everything in the compositor together. More...
 
struct  comp_mirror_to_debug_gui
 Helper struct for mirroring the compositors rendering to the debug ui, which also enables recording. 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  comp_target_image
 Image and view pair for comp_target. More...
 
struct  comp_target_create_images_info
 Information given in when creating the swapchain images, argument to comp_target_create_images. More...
 
struct  comp_target_semaphores
 Collection of semaphores needed for a target. More...
 
struct  comp_target
 A compositor target: where the compositor renders to. More...
 
struct  comp_target_factory
 A factory of targets. More...
 
struct  comp_target_swapchain
 Wraps and manage VkSwapchainKHR and VkSurfaceKHR, used by Compositor code. More...
 

Enumerations

enum  comp_target_timing_point { COMP_TARGET_TIMING_POINT_WAKE_UP , COMP_TARGET_TIMING_POINT_BEGIN , COMP_TARGET_TIMING_POINT_SUBMIT_BEGIN , COMP_TARGET_TIMING_POINT_SUBMIT_END }
 For marking timepoints on a frame's lifetime, not a async event. More...
 
enum  comp_target_display_timing_usage { COMP_TARGET_FORCE_FAKE_DISPLAY_TIMING = 0 , COMP_TARGET_USE_DISPLAY_IF_AVAILABLE = 1 }
 If the target should use the display timing information. More...
 

Functions

void comp_settings_init (struct comp_settings *s, struct xrt_device *xdev)
 Initialize the settings struct with either defaults or loaded setting. More...
 
xrt_result_t comp_main_create_system_compositor (struct xrt_device *xdev, const struct comp_target_factory *ctf, struct xrt_system_compositor **out_xsysc)
 Creates the main compositor, it doesn't return itself but instead wraps itself with a system compositor. More...
 
struct comp_renderercomp_renderer::comp_renderer_create (struct comp_compositor *c, VkExtent2D scratch_extent)
 Called by the main compositor code to create the renderer. More...
 
void comp_renderer::comp_renderer_destroy (struct comp_renderer **ptr_r)
 Clean up and free the renderer. More...
 
XRT_CHECK_RESULT xrt_result_t comp_renderer::comp_renderer_draw (struct comp_renderer *r)
 Render frame. More...
 
static bool comp_target::comp_target_init_pre_vulkan (struct comp_target *ct)
 Do any initialization that is required to happen before Vulkan has been loaded. More...
 
static bool comp_target::comp_target_init_post_vulkan (struct comp_target *ct, uint32_t preferred_width, uint32_t preferred_height)
 Do any initialization that requires Vulkan to be loaded, you need to call create_images after calling this function. More...
 
static bool comp_target::comp_target_check_ready (struct comp_target *ct)
 Is this target ready for image creation? More...
 
static void comp_target::comp_target_create_images (struct comp_target *ct, const struct comp_target_create_images_info *create_info)
 Create or recreate the image(s) of the target, for swapchain based targets this will (re)create the swapchain. More...
 
static bool comp_target::comp_target_has_images (struct comp_target *ct)
 Has this target successfully had images created? More...
 
static VkResult comp_target::comp_target_acquire (struct comp_target *ct, uint32_t *out_index)
 Acquire the next image for rendering. More...
 
static VkResult comp_target::comp_target_present (struct comp_target *ct, VkQueue queue, uint32_t index, uint64_t timeline_semaphore_value, uint64_t desired_present_time_ns, uint64_t present_slop_ns)
 Present the image at index to the screen. More...
 
static void comp_target::comp_target_flush (struct comp_target *ct)
 Flush any WSI state before rendering. More...
 
static void comp_target::comp_target_calc_frame_pacing (struct comp_target *ct, int64_t *out_frame_id, uint64_t *out_wake_up_time_ns, uint64_t *out_desired_present_time_ns, uint64_t *out_present_slop_ns, uint64_t *out_predicted_display_time_ns)
 Predict when the next frame should be started and when it will be turned into photons by the hardware. More...
 
static void comp_target::comp_target_mark_wake_up (struct comp_target *ct, int64_t frame_id, uint64_t when_woke_ns)
 Quick helper for marking wake up. More...
 
static void comp_target::comp_target_mark_begin (struct comp_target *ct, int64_t frame_id, uint64_t when_began_ns)
 Quick helper for marking begin. More...
 
static void comp_target::comp_target_mark_submit_begin (struct comp_target *ct, int64_t frame_id, uint64_t when_submit_began_ns)
 Quick helper for marking submit began. More...
 
static void comp_target::comp_target_mark_submit_end (struct comp_target *ct, int64_t frame_id, uint64_t when_submit_end_ns)
 Quick helper for marking submit end. More...
 
static VkResult comp_target::comp_target_update_timings (struct comp_target *ct)
 Update timing information for this target, this function should be lightweight and is called multiple times during a frame to make sure that we get the timing data as soon as possible. More...
 
static void comp_target::comp_target_info_gpu (struct comp_target *ct, int64_t frame_id, uint64_t gpu_start_ns, uint64_t gpu_end_ns, uint64_t when_ns)
 Provide frame timing information about GPU start and stop time. More...
 
static void comp_target::comp_target_set_title (struct comp_target *ct, const char *title)
 If the target can show a title (like a window) set the title. More...
 
static void comp_target::comp_target_destroy (struct comp_target **ct_ptr)
 Destroys this target. More...
 
static bool comp_target_factory::comp_target_factory_detect (const struct comp_target_factory *ctf, struct comp_compositor *c)
 Checks if this target can be detected, is the preferred target or some other special consideration that this target should be used over all other targets. More...
 
static bool comp_target_factory::comp_target_factory_create_target (const struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct)
 Create a target from this factory, some targets requires Vulkan to have been initialised, see requires_vulkan_for_create. More...
 
void comp_target_swapchain::comp_target_swapchain_init_and_set_fnptrs (struct comp_target_swapchain *cts, enum comp_target_display_timing_usage timing_usage)
 Pre Vulkan initialisation, sets function pointers. More...
 
void comp_target_swapchain::comp_target_swapchain_override_extents (struct comp_target_swapchain *cts, VkExtent2D extent)
 Set that any size from the compositor should be ignored and that given size must be used for the VkSwapchain the helper code creates. More...
 
void comp_target_swapchain::comp_target_swapchain_cleanup (struct comp_target_swapchain *cts)
 Free all managed resources on the given comp_target_swapchain, does not free the struct itself. More...
 
struct comp_targetcomp_window_xcb::comp_window_xcb_create (struct comp_compositor *c)
 Create a xcb window. More...
 
struct comp_targetcomp_window_wayland::comp_window_wayland_create (struct comp_compositor *c)
 Create a wayland window. More...
 
struct comp_targetcomp_window_direct_randr::comp_window_direct_randr_create (struct comp_compositor *c)
 Create a direct surface to an HMD over RandR. More...
 
struct comp_targetcomp_window_direct_nvidia::comp_window_direct_nvidia_create (struct comp_compositor *c)
 Create a direct surface to an HMD on NVIDIA. More...
 
bool render_resources::render_resources_init (struct render_resources *r, struct render_shaders *shaders, struct vk_bundle *vk, struct xrt_device *xdev)
 Allocate pools and static resources. More...
 

Detailed Description

Main compositor code.

Enumeration Type Documentation

◆ comp_target_display_timing_usage

#include <compositor/main/comp_target.h>

If the target should use the display timing information.

◆ comp_target_timing_point

#include <compositor/main/comp_target.h>

For marking timepoints on a frame's lifetime, not a async event.

Enumerator
COMP_TARGET_TIMING_POINT_WAKE_UP 

Woke up after sleeping in wait frame.

COMP_TARGET_TIMING_POINT_BEGIN 

Began CPU side work for GPU.

COMP_TARGET_TIMING_POINT_SUBMIT_BEGIN 

Just before submitting work to the GPU.

COMP_TARGET_TIMING_POINT_SUBMIT_END 

Just after submitting work to the GPU.

Function Documentation

◆ comp_main_create_system_compositor()

xrt_result_t comp_main_create_system_compositor ( struct xrt_device xdev,
const struct comp_target_factory ctf,
struct xrt_system_compositor **  out_xsysc 
)
related

Creates the main compositor, it doesn't return itself but instead wraps itself with a system compositor.

The main compositor is a native compositor.

Parameters
xdevThe head device
ctfA compositor target factory to force the output device, must remain valid for the lifetime of the compositor. If NULL, factory is automatically selected
out_xsyscThe output compositor

◆ comp_renderer_create()

struct comp_renderer * comp_renderer_create ( struct comp_compositor c,
VkExtent2D  scratch_extent 
)

Called by the main compositor code to create the renderer.

Parameters
cOwning compositor.
scratch_extentSize for scratch image used when squashing layers.
See also
comp_compositor

References comp_renderer::c, renderer_init(), and U_TYPED_CALLOC.

◆ comp_renderer_destroy()

void comp_renderer_destroy ( struct comp_renderer **  ptr_r)

Clean up and free the renderer.

Does null checking and sets to null after freeing.

◆ comp_renderer_draw()

XRT_CHECK_RESULT xrt_result_t comp_renderer_draw ( struct comp_renderer r)

Render 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 xrt_device::hmd, xrt_hmd_parts::nominal_frame_interval_ns, and xrt_hmd_parts::screens.

◆ comp_target_acquire()

static VkResult comp_target_acquire ( struct comp_target ct,
uint32_t *  out_index 
)
inline

Acquire the next image for rendering.

If comp_target_semaphores::present_complete is not null, your use of this image should wait on it..

Precondition
has_images() returns true

◆ comp_target_calc_frame_pacing()

static void comp_target_calc_frame_pacing ( struct comp_target ct,
int64_t *  out_frame_id,
uint64_t *  out_wake_up_time_ns,
uint64_t *  out_desired_present_time_ns,
uint64_t *  out_present_slop_ns,
uint64_t *  out_predicted_display_time_ns 
)
inline

Predict when the next frame should be started and when it will be turned into photons by the hardware.

◆ comp_target_check_ready()

static bool comp_target_check_ready ( struct comp_target ct)
inline

Is this target ready for image creation?

Call before calling create_images

◆ comp_target_create_images()

static void comp_target_create_images ( struct comp_target ct,
const struct comp_target_create_images_info create_info 
)
inline

Create or recreate the image(s) of the target, for swapchain based targets this will (re)create the swapchain.

Precondition
check_ready returns true

◆ comp_target_destroy()

static void comp_target_destroy ( struct comp_target **  ct_ptr)
inline

Destroys this target.

Helper for calling through the function pointer: does a null check and sets ct_ptr to null if freed.

References comp_target::destroy.

◆ comp_target_factory_create_target()

static bool comp_target_factory_create_target ( const struct comp_target_factory ctf,
struct comp_compositor c,
struct comp_target **  out_ct 
)
inline

Create a target from this factory, some targets requires Vulkan to have been initialised, see requires_vulkan_for_create.

◆ comp_target_factory_detect()

static bool comp_target_factory_detect ( const struct comp_target_factory ctf,
struct comp_compositor c 
)
inline

Checks if this target can be detected, is the preferred target or some other special consideration that this target should be used over all other targets.

This is needed for NVIDIA direct mode which window must be created after vulkan has initialized.

◆ comp_target_flush()

static void comp_target_flush ( struct comp_target ct)
inline

Flush any WSI state before rendering.

◆ comp_target_has_images()

static bool comp_target_has_images ( struct comp_target ct)
inline

Has this target successfully had images created?

Call before calling acquire - if false but check_ready is true, you'll need to call create_images.

◆ comp_target_info_gpu()

static void comp_target_info_gpu ( struct comp_target ct,
int64_t  frame_id,
uint64_t  gpu_start_ns,
uint64_t  gpu_end_ns,
uint64_t  when_ns 
)
inline

Provide frame timing information about GPU start and stop time.

Depend on when the information is delivered this can be called at any point of the following frames.

Parameters
[in]ctThe compositor target.
[in]frame_idThe frame ID to record for.
[in]gpu_start_nsWhen the GPU work startred.
[in]gpu_end_nsWhen the GPU work stopped.
[in]when_nsWhen the informatioon collected, nominally from os_monotonic_get_ns.
See also
Frame Pacing/Timing.

◆ comp_target_init_post_vulkan()

static bool comp_target_init_post_vulkan ( struct comp_target ct,
uint32_t  preferred_width,
uint32_t  preferred_height 
)
inline

Do any initialization that requires Vulkan to be loaded, you need to call create_images after calling this function.

◆ comp_target_init_pre_vulkan()

static bool comp_target_init_pre_vulkan ( struct comp_target ct)
inline

Do any initialization that is required to happen before Vulkan has been loaded.

◆ comp_target_mark_begin()

static void comp_target_mark_begin ( struct comp_target ct,
int64_t  frame_id,
uint64_t  when_began_ns 
)
inline

Quick helper for marking begin.

The compositor tells the target a timing information about a single timing point on the frames lifecycle.

◆ comp_target_mark_submit_begin()

static void comp_target_mark_submit_begin ( struct comp_target ct,
int64_t  frame_id,
uint64_t  when_submit_began_ns 
)
inline

Quick helper for marking submit began.

The compositor tells the target a timing information about a single timing point on the frames lifecycle.

◆ comp_target_mark_submit_end()

static void comp_target_mark_submit_end ( struct comp_target ct,
int64_t  frame_id,
uint64_t  when_submit_end_ns 
)
inline

Quick helper for marking submit end.

The compositor tells the target a timing information about a single timing point on the frames lifecycle.

◆ comp_target_mark_wake_up()

static void comp_target_mark_wake_up ( struct comp_target ct,
int64_t  frame_id,
uint64_t  when_woke_ns 
)
inline

Quick helper for marking wake up.

The compositor tells the target a timing information about a single timing point on the frames lifecycle.

◆ comp_target_present()

static VkResult comp_target_present ( struct comp_target ct,
VkQueue  queue,
uint32_t  index,
uint64_t  timeline_semaphore_value,
uint64_t  desired_present_time_ns,
uint64_t  present_slop_ns 
)
inline

Present the image at index to the screen.

Precondition
acquire succeeded for the same semaphore and index you are passing
Parameters
ctself
queueThe Vulkan queue being used
indexThe swapchain image index to present
timeline_semaphore_valueThe value to await on comp_target_semaphores::render_complete if comp_target_semaphores::render_complete_is_timeline is true.
desired_present_time_nsThe timestamp to present at, ideally.
present_slop_nsTODO

◆ comp_target_set_title()

static void comp_target_set_title ( struct comp_target ct,
const char *  title 
)
inline

If the target can show a title (like a window) set the title.

◆ comp_target_swapchain_cleanup()

void comp_target_swapchain_cleanup ( struct comp_target_swapchain cts)
protected

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

Referenced by comp_window_mswin_destroy().

◆ comp_target_swapchain_init_and_set_fnptrs()

void comp_target_swapchain_init_and_set_fnptrs ( struct comp_target_swapchain cts,
enum comp_target_display_timing_usage  timing_usage 
)
protected

◆ comp_target_swapchain_override_extents()

void comp_target_swapchain_override_extents ( struct comp_target_swapchain cts,
VkExtent2D  extent 
)
protected

Set that any size from the compositor should be ignored and that given size must be used for the VkSwapchain the helper code creates.

References comp_target_swapchain::base, comp_target::c, comp_compositor::COMP_INFO, comp_target_swapchain::compositor_extent, comp_target_swapchain::extent, and comp_target::name.

◆ comp_target_update_timings()

static VkResult comp_target_update_timings ( struct comp_target ct)
inline

Update timing information for this target, this function should be lightweight and is called multiple times during a frame to make sure that we get the timing data as soon as possible.

◆ comp_window_direct_nvidia_create()

struct comp_target * comp_window_direct_nvidia_create ( struct comp_compositor c)

Create a direct surface to an HMD on NVIDIA.

References comp_target_swapchain::comp_target_swapchain_init_and_set_fnptrs(), and U_TYPED_CALLOC.

◆ comp_window_direct_randr_create()

struct comp_target * comp_window_direct_randr_create ( struct comp_compositor c)

Create a direct surface to an HMD over RandR.

References comp_target_swapchain::comp_target_swapchain_init_and_set_fnptrs(), and U_TYPED_CALLOC.

◆ comp_window_wayland_create()

struct comp_target * comp_window_wayland_create ( struct comp_compositor c)

◆ comp_window_xcb_create()

struct comp_target * comp_window_xcb_create ( struct comp_compositor c)

◆ render_resources_init()