Monado OpenXR Runtime
comp_target.h
Go to the documentation of this file.
1// Copyright 2020-2026, Collabora, Ltd.
2// Copyright 2024-2026, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Abstracted compositor rendering target.
7 * @author Jakob Bornecrantz <jakob@collabora.com>
8 * @ingroup comp_main
9 */
10
11#pragma once
12
13#include "xrt/xrt_compiler.h"
14#include "xrt/xrt_defines.h"
15
16#include "vk/vk_helpers.h"
17
18#include "util/u_trace_marker.h"
19
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25
26/*!
27 * For marking timepoints on a frame's lifetime, not a async event.
28 *
29 * @ingroup comp_main
30 */
32{
33 //! Woke up after sleeping in wait frame.
35
36 //! Began CPU side work for GPU.
38
39 //! Just before submitting work to the GPU.
41
42 //! Just after submitting work to the GPU.
44};
45
46/*!
47 * If the target should use the display timing information.
48 *
49 * @ingroup comp_main
50 */
52{
53 COMP_TARGET_FORCE_FAKE_DISPLAY_TIMING = 0,
54 COMP_TARGET_USE_DISPLAY_IF_AVAILABLE = 1,
55};
56
57/*!
58 * Image and view pair for @ref comp_target.
59 *
60 * @ingroup comp_main
61 */
63{
64 VkImage handle;
65 VkImageView view;
66};
67
68/*!
69 * Information given in when creating the swapchain images,
70 * argument to @ref comp_target_create_images.
71 *
72 * @ingroup comp_main
73 */
75{
76 //! Image usage for the images, must be followed.
77 VkImageUsageFlags image_usage;
78
79 //! Acceptable formats for the images, must be followed.
81
82 // Number of formats.
83 uint32_t format_count;
84
85 //! Preferred extent, can be ignored by the target.
86 VkExtent2D extent;
87
88 //! Preferred color space, can be ignored by the target.
89 VkColorSpaceKHR color_space;
90
91 // Preferred present_mode, can be ignored by the target.
92 VkPresentModeKHR present_mode;
93};
94
95/*!
96 * Collection of semaphores needed for a target.
97 *
98 * @ingroup comp_main
99 */
101{
102 /*!
103 * Optional semaphore the target should signal when present is complete.
104 */
105 VkSemaphore present_complete;
106
107 /*!
108 * Semaphore the renderer (consuming this target)
109 * should signal when rendering is complete.
110 */
111 VkSemaphore render_complete;
112
113 /*!
114 * If true, @ref render_complete is a timeline
115 * semaphore instead of a binary semaphore.
116 */
118};
119
120/*!
121 * @brief A compositor target: where the compositor renders to.
122 *
123 * A target is essentially a swapchain, but it is such a overloaded term so
124 * we are differentiating swapchains that the compositor provides to clients and
125 * swapchains that the compositor renders by naming the latter to target.
126 *
127 * For design purposes, when amending this interface, remember that targets may not necessarily be backed by a
128 * swapchain in all cases, for instance with remote rendering.
129 *
130 * @ingroup comp_main
131 */
133{
134 //! Owning compositor.
136
137 //! Name of the backing system.
138 const char *name;
139
140 //! Current dimensions of the target.
141 uint32_t width, height;
142
143 //! The format that the renderpass targeting this target should use.
144 VkFormat format;
145
146 //! The final layout that the renderpass should leave this target in.
147 VkImageLayout final_layout;
148
149 //! Number of images that this target has.
150 uint32_t image_count;
151 //! Array of images and image views for rendering.
153
154 //! Transformation of the current surface, required for pre-rotation
155 VkSurfaceTransformFlagBitsKHR surface_transform;
156
157 //! Holds semaphore information.
159
160 //! Whether wait_for_present is supported by this comp_target.
162
163 /*
164 *
165 * Vulkan functions.
166 *
167 */
168
169 /*!
170 * Do any initialization that is required to happen before Vulkan has
171 * been loaded.
172 */
174
175 /*!
176 * Do any initialization that requires Vulkan to be loaded, you need to
177 * call @ref create_images after calling this function.
178 */
179 bool (*init_post_vulkan)(struct comp_target *ct, uint32_t preferred_width, uint32_t preferred_height);
180
181 /*!
182 * Is this target ready for image creation?
183 *
184 * Call before calling @ref create_images
185 */
187
188 /*!
189 * Create or recreate the image(s) of the target, for swapchain based
190 * targets this will (re)create the swapchain.
191 *
192 * @param ct self
193 * @param create_info Image creation parameters
194 * @param present_queue The queue that will be used for presentation operations (must not be NULL)
195 *
196 * @pre @ref check_ready returns true
197 */
198 void (*create_images)(struct comp_target *ct,
199 const struct comp_target_create_images_info *create_info,
200 struct vk_bundle_queue *present_queue);
201
202 /*!
203 * Has this target successfully had images created?
204 *
205 * Call before calling @ref acquire - if false but @ref check_ready is
206 * true, you'll need to call @ref create_images.
207 */
209
210 /*!
211 * Acquire the next image for rendering.
212 *
213 * If @ref comp_target_semaphores::present_complete is not null,
214 * your use of this image should wait on it..
215 *
216 * @pre @ref has_images() returns true
217 */
218 VkResult (*acquire)(struct comp_target *ct, uint32_t *out_index);
219
220 /*!
221 * Present the image at index to the screen.
222 *
223 * @pre @ref acquire succeeded for the same @p semaphore and @p index you are passing
224 *
225 * @param ct self
226 * @param present_queue The Vulkan queue bundle being used for presentation (must not be NULL)
227 * @param index The swapchain image index to present
228 * @param timeline_semaphore_value The value to await on @ref comp_target_semaphores::render_complete
229 * if @ref comp_target_semaphores::render_complete_is_timeline is true.
230 * @param desired_present_time_ns The timestamp to present at, ideally.
231 * @param present_slop_ns TODO
232 */
233 VkResult (*present)(struct comp_target *ct,
234 struct vk_bundle_queue *present_queue,
235 uint32_t index,
236 uint64_t timeline_semaphore_value,
237 int64_t desired_present_time_ns,
238 int64_t present_slop_ns);
239
240 /*!
241 * Wait for the latest presented image to be displayed to the user.
242 *
243 * @param ct self
244 * @param timeout_ns The amount of time to wait for presentation to succeed.
245 */
246 VkResult (*wait_for_present)(struct comp_target *ct, time_duration_ns timeout_ns);
247
248 /*!
249 * Flush any WSI state before rendering.
250 */
251 void (*flush)(struct comp_target *ct);
252
253
254 /*
255 *
256 * Timing functions.
257 *
258 */
259
260 /*!
261 * Predict when the next frame should be started and when it will be
262 * turned into photons by the hardware.
263 */
264 void (*calc_frame_pacing)(struct comp_target *ct,
265 int64_t *out_frame_id,
266 int64_t *out_wake_up_time_ns,
267 int64_t *out_desired_present_time_ns,
268 int64_t *out_present_slop_ns,
269 int64_t *out_predicted_display_time_ns);
270
271 /*!
272 * The compositor tells the target a timing information about a single
273 * timing point on the frames lifecycle.
274 */
275 void (*mark_timing_point)(struct comp_target *ct,
276 enum comp_target_timing_point point,
277 int64_t frame_id,
278 int64_t when_ns);
279
280 /*!
281 * Update timing information for this target, this function should be
282 * lightweight and is called multiple times during a frame to make sure
283 * that we get the timing data as soon as possible.
284 */
285 VkResult (*update_timings)(struct comp_target *ct);
286
287 /*!
288 * Provide frame timing information about GPU start and stop time.
289 *
290 * Depend on when the information is delivered this can be called at any
291 * point of the following frames.
292 *
293 * @param[in] ct The compositor target.
294 * @param[in] frame_id The frame ID to record for.
295 * @param[in] gpu_start_ns When the GPU work startred.
296 * @param[in] gpu_end_ns When the GPU work stopped.
297 * @param[in] when_ns When the informatioon collected, nominally
298 * from @ref os_monotonic_get_ns.
299 *
300 * @see @ref frame-pacing.
301 */
302 void (*info_gpu)(
303 struct comp_target *ct, int64_t frame_id, int64_t gpu_start_ns, int64_t gpu_end_ns, int64_t when_ns);
304
305 /*
306 *
307 * Misc functions.
308 *
309 */
310
311 /*!
312 * If the target can show a title (like a window) set the title.
313 */
314 void (*set_title)(struct comp_target *ct, const char *title);
315
316 /*!
317 * Get the available refresh rates for the compositor target
318 *
319 * @param ct The compositor target.
320 * @param count The number or refresh rates.
321 * @param refresh_rates_hz The refresh rates, in Hz. Must be allocated by caller, and have at least
322 * XRT_MAX_SUPPORTED_REFRESH_RATES elements
323 */
325 uint32_t *out_count,
326 float *out_display_refresh_rates_hz);
327
328 /*!
329 * Get the current refresh rate for the compositor target
330 *
331 * @param ct The compositor target.
332 * @param out_display_refresh_rate_hz The current refresh rate, in Hz
333 */
334 xrt_result_t (*get_current_refresh_rate)(struct comp_target *ct, float *out_display_refresh_rate_hz);
335
336 /*!
337 * Get the current refresh rate for the compositor target
338 *
339 * @param ct The compositor target.
340 * @param display_refresh_rate_hz The requested refresh rate, in Hz.
341 */
342 xrt_result_t (*request_refresh_rate)(struct comp_target *ct, float display_refresh_rate_hz);
343
344 /*!
345 * Queries if a particular queue supports presentation ops/cmds for the compositor target
346 *
347 * @param ct The compositor target.
348 * @param queue The vulkan queue to query
349 * @param out_supported If the @ref queue supports presentation ops/cmds
350 * for @ref ct present surface.
351 */
352 VkResult (*queue_supports_present)(struct comp_target *ct,
353 struct vk_bundle_queue *queue,
354 VkBool32 *out_supported);
355
356 /*!
357 * Destroys this target.
358 */
359 void (*destroy)(struct comp_target *ct);
360};
361
362/*!
363 * @copydoc comp_target::init_pre_vulkan
364 *
365 * @public @memberof comp_target
366 * @ingroup comp_main
367 */
368static inline bool
370{
371 COMP_TRACE_MARKER();
372
373 return ct->init_pre_vulkan(ct);
374}
375
376/*!
377 * @copydoc comp_target::init_post_vulkan
378 *
379 * @public @memberof comp_target
380 * @ingroup comp_main
381 */
382static inline bool
383comp_target_init_post_vulkan(struct comp_target *ct, uint32_t preferred_width, uint32_t preferred_height)
384{
385 COMP_TRACE_MARKER();
386
387 return ct->init_post_vulkan(ct, preferred_width, preferred_height);
388}
389
390/*!
391 * @copydoc comp_target::check_ready
392 *
393 * @public @memberof comp_target
394 * @ingroup comp_main
395 */
396static inline bool
398{
399 COMP_TRACE_MARKER();
400
401 return ct->check_ready(ct);
402}
403
404/*!
405 * @copydoc comp_target::create_images
406 *
407 * @public @memberof comp_target
408 * @ingroup comp_main
409 */
410static inline void
412 const struct comp_target_create_images_info *create_info,
413 struct vk_bundle_queue *present_queue)
414{
415 COMP_TRACE_MARKER();
416
417 ct->create_images(ct, create_info, present_queue);
418}
419
420/*!
421 * @copydoc comp_target::has_images
422 *
423 * @public @memberof comp_target
424 * @ingroup comp_main
425 */
426static inline bool
428{
429 COMP_TRACE_MARKER();
430
431 return ct->has_images(ct);
432}
433
434/*!
435 * @copydoc comp_target::acquire
436 *
437 * @public @memberof comp_target
438 * @ingroup comp_main
439 */
440static inline VkResult
441comp_target_acquire(struct comp_target *ct, uint32_t *out_index)
442{
443 COMP_TRACE_MARKER();
444
445 return ct->acquire(ct, out_index);
446}
447
448/*!
449 * @copydoc comp_target::present
450 *
451 * @public @memberof comp_target
452 * @ingroup comp_main
453 */
454static inline VkResult
456 struct vk_bundle_queue *present_queue,
457 uint32_t index,
458 uint64_t timeline_semaphore_value,
459 int64_t desired_present_time_ns,
460 int64_t present_slop_ns)
461
462{
463 COMP_TRACE_MARKER();
464
465 return ct->present( //
466 ct, //
467 present_queue, //
468 index, //
469 timeline_semaphore_value, //
470 desired_present_time_ns, //
471 present_slop_ns); //
472}
473
474/*!
475 * @copydoc comp_target::wait_for_present
476 *
477 * @public @memberof comp_target
478 * @ingroup comp_main
479 */
480static inline VkResult
482{
483 COMP_TRACE_MARKER();
484
485 return ct->wait_for_present( //
486 ct, //
487 timeout); //
488}
489
490/*!
491 * @copydoc comp_target::flush
492 *
493 * @public @memberof comp_target
494 * @ingroup comp_main
495 */
496static inline void
498{
499 COMP_TRACE_MARKER();
500
501 ct->flush(ct);
502}
503
504/*!
505 * @copydoc comp_target::calc_frame_pacing
506 *
507 * @public @memberof comp_target
508 * @ingroup comp_main
509 */
510static inline void
512 int64_t *out_frame_id,
513 int64_t *out_wake_up_time_ns,
514 int64_t *out_desired_present_time_ns,
515 int64_t *out_present_slop_ns,
516 int64_t *out_predicted_display_time_ns)
517{
518 COMP_TRACE_MARKER();
519
520 ct->calc_frame_pacing( //
521 ct, //
522 out_frame_id, //
523 out_wake_up_time_ns, //
524 out_desired_present_time_ns, //
525 out_present_slop_ns, //
526 out_predicted_display_time_ns); //
527}
528
529/*!
530 * Quick helper for marking wake up.
531 * @copydoc comp_target::mark_timing_point
532 *
533 * @public @memberof comp_target
534 * @ingroup comp_main
535 */
536static inline void
537comp_target_mark_wake_up(struct comp_target *ct, int64_t frame_id, int64_t when_woke_ns)
538{
539 COMP_TRACE_MARKER();
540
541 ct->mark_timing_point(ct, COMP_TARGET_TIMING_POINT_WAKE_UP, frame_id, when_woke_ns);
542}
543
544/*!
545 * Quick helper for marking begin.
546 * @copydoc comp_target::mark_timing_point
547 *
548 * @public @memberof comp_target
549 * @ingroup comp_main
550 */
551static inline void
552comp_target_mark_begin(struct comp_target *ct, int64_t frame_id, int64_t when_began_ns)
553{
554 COMP_TRACE_MARKER();
555
556 ct->mark_timing_point(ct, COMP_TARGET_TIMING_POINT_BEGIN, frame_id, when_began_ns);
557}
558
559/*!
560 * Quick helper for marking submit began.
561 * @copydoc comp_target::mark_timing_point
562 *
563 * @public @memberof comp_target
564 * @ingroup comp_main
565 */
566static inline void
567comp_target_mark_submit_begin(struct comp_target *ct, int64_t frame_id, int64_t when_submit_began_ns)
568{
569 COMP_TRACE_MARKER();
570
571 ct->mark_timing_point(ct, COMP_TARGET_TIMING_POINT_SUBMIT_BEGIN, frame_id, when_submit_began_ns);
572}
573
574/*!
575 * Quick helper for marking submit end.
576 * @copydoc comp_target::mark_timing_point
577 *
578 * @public @memberof comp_target
579 * @ingroup comp_main
580 */
581static inline void
582comp_target_mark_submit_end(struct comp_target *ct, int64_t frame_id, int64_t when_submit_end_ns)
583{
584 COMP_TRACE_MARKER();
585
586 ct->mark_timing_point(ct, COMP_TARGET_TIMING_POINT_SUBMIT_END, frame_id, when_submit_end_ns);
587}
588
589/*!
590 * @copydoc comp_target::update_timings
591 *
592 * @public @memberof comp_target
593 * @ingroup comp_main
594 */
595static inline VkResult
597{
598 COMP_TRACE_MARKER();
599
600 return ct->update_timings(ct);
601}
602
603/*!
604 * @copydoc comp_target::info_gpu
605 *
606 * @public @memberof comp_target
607 * @ingroup comp_main
608 */
609static inline void
611 struct comp_target *ct, int64_t frame_id, int64_t gpu_start_ns, int64_t gpu_end_ns, int64_t when_ns)
612{
613 COMP_TRACE_MARKER();
614
615 ct->info_gpu(ct, frame_id, gpu_start_ns, gpu_end_ns, when_ns);
616}
617
618/*!
619 * @copydoc comp_target::set_title
620 *
621 * @public @memberof comp_target
622 * @ingroup comp_main
623 */
624static inline void
625comp_target_set_title(struct comp_target *ct, const char *title)
626{
627 COMP_TRACE_MARKER();
628
629 ct->set_title(ct, title);
630}
631
632/*!
633 * @copydoc comp_target::get_refresh_rates
634 *
635 * @public @memberof comp_target
636 * @ingroup comp_main
637 */
638static inline xrt_result_t
639comp_target_get_refresh_rates(struct comp_target *ct, uint32_t *count, float *rates)
640{
641 COMP_TRACE_MARKER();
642
643 return ct->get_refresh_rates(ct, count, rates);
644}
645
646/*!
647 * @copydoc comp_target::get_current_refresh_rate
648 *
649 * @public @memberof comp_target
650 * @ingroup comp_main
651 */
652static inline xrt_result_t
653comp_target_get_current_refresh_rate(struct comp_target *ct, float *out_display_refresh_rate_hz)
654{
655 COMP_TRACE_MARKER();
656
657 return ct->get_current_refresh_rate(ct, out_display_refresh_rate_hz);
658}
659
660/*!
661 * @copydoc comp_target::request_refresh_rate
662 *
663 * @public @memberof comp_target
664 * @ingroup comp_main
665 */
666static inline xrt_result_t
667comp_target_request_refresh_rate(struct comp_target *ct, float ratedisplay_refresh_rate_hz)
668{
669 COMP_TRACE_MARKER();
670
671 return ct->request_refresh_rate(ct, ratedisplay_refresh_rate_hz);
672}
673
674/*!
675 * @copydoc comp_target::queue_supports_present
676 *
677 * @public @memberof comp_target
678 * @ingroup comp_main
679 */
680static inline VkResult
681comp_target_queue_supports_present(struct comp_target *ct, struct vk_bundle_queue *queue, VkBool32 *out_supported)
682{
683 COMP_TRACE_MARKER();
684 return ct->queue_supports_present(ct, queue, out_supported);
685}
686
687/*!
688 * @copydoc comp_target::destroy
689 *
690 * Helper for calling through the function pointer: does a null check and sets
691 * ct_ptr to null if freed.
692 *
693 * @public @memberof comp_target
694 * @ingroup comp_main
695 */
696static inline void
698{
699 struct comp_target *ct = *ct_ptr;
700 if (ct == NULL) {
701 return;
702 }
703
704 ct->destroy(ct);
705 *ct_ptr = NULL;
706}
707
708/*!
709 * A factory of targets.
710 *
711 * @ingroup comp_main
712 */
714{
715 //! Pretty loggable name of target type.
716 const char *name;
717
718 //! Short all lowercase identifier for target type.
719 const char *identifier;
720
721 //! Does this factory require Vulkan to have been initialized.
723
724 /*!
725 * Is this a deferred target that can have it's creation
726 * delayed even further then after Vulkan initialization.
727 */
729
730 /*!
731 * Vulkan version that is required or 0 if no specific
732 * requirement, equivalent to VK_MAKE_VERSION(1, 0, 0)
733 */
735
736 //! Required instance extensions.
738
739 //! Required instance extension count.
741
742 //! Optional device extensions.
744
745 //! Optional device extension count.
747
748 /*!
749 * Checks if this target can be detected, is the preferred target or
750 * some other special consideration that this target should be used over
751 * all other targets.
752 *
753 * This is needed for NVIDIA direct mode which window must be created
754 * after vulkan has initialized.
755 */
756 bool (*detect)(const struct comp_target_factory *ctf, struct comp_compositor *c);
757
758 /*!
759 * Create a target from this factory, some targets requires Vulkan to
760 * have been initialised, see @ref requires_vulkan_for_create.
761 */
763 struct comp_compositor *c,
764 struct comp_target **out_ct);
765};
766
767/*!
768 * @copydoc comp_target_factory::detect
769 *
770 * @public @memberof comp_target_factory
771 * @ingroup comp_main
772 */
773static inline bool
775{
776 COMP_TRACE_MARKER();
777
778 return ctf->detect(ctf, c);
779}
780
781/*!
782 * @copydoc comp_target_factory::create_target
783 *
784 * @public @memberof comp_target_factory
785 * @ingroup comp_main
786 */
787static inline bool
789 struct comp_compositor *c,
790 struct comp_target **out_ct)
791{
792 COMP_TRACE_MARKER();
793
794 return ctf->create_target(ctf, c, out_ct);
795}
796
797
798#ifdef __cplusplus
799}
800#endif
int64_t time_duration_ns
Integer duration type in nanoseconds.
Definition: u_time.h:88
static void comp_target_mark_wake_up(struct comp_target *ct, int64_t frame_id, int64_t when_woke_ns)
Quick helper for marking wake up.
Definition: comp_target.h:537
static VkResult comp_target_wait_for_present(struct comp_target *ct, time_duration_ns timeout)
Wait for the latest presented image to be displayed to the user.
Definition: comp_target.h:481
static void comp_target_destroy(struct comp_target **ct_ptr)
Destroys this target.
Definition: comp_target.h:697
comp_target_display_timing_usage
If the target should use the display timing information.
Definition: comp_target.h:52
static VkResult comp_target_acquire(struct comp_target *ct, uint32_t *out_index)
Acquire the next image for rendering.
Definition: comp_target.h:441
static void comp_target_mark_submit_begin(struct comp_target *ct, int64_t frame_id, int64_t when_submit_began_ns)
Quick helper for marking submit began.
Definition: comp_target.h:567
static VkResult comp_target_update_timings(struct comp_target *ct)
Update timing information for this target, this function should be lightweight and is called multiple...
Definition: comp_target.h:596
static void comp_target_flush(struct comp_target *ct)
Flush any WSI state before rendering.
Definition: comp_target.h:497
static VkResult comp_target_queue_supports_present(struct comp_target *ct, struct vk_bundle_queue *queue, VkBool32 *out_supported)
Queries if a particular queue supports presentation ops/cmds for the compositor target.
Definition: comp_target.h:681
static bool comp_target_has_images(struct comp_target *ct)
Has this target successfully had images created?
Definition: comp_target.h:427
static xrt_result_t comp_target_get_current_refresh_rate(struct comp_target *ct, float *out_display_refresh_rate_hz)
Get the current refresh rate for the compositor target.
Definition: comp_target.h:653
static void comp_target_set_title(struct comp_target *ct, const char *title)
If the target can show a title (like a window) set the title.
Definition: comp_target.h:625
static VkResult comp_target_present(struct comp_target *ct, struct vk_bundle_queue *present_queue, uint32_t index, uint64_t timeline_semaphore_value, int64_t desired_present_time_ns, int64_t present_slop_ns)
Present the image at index to the screen.
Definition: comp_target.h:455
static xrt_result_t comp_target_get_refresh_rates(struct comp_target *ct, uint32_t *count, float *rates)
Get the available refresh rates for the compositor target.
Definition: comp_target.h:639
static bool comp_target_check_ready(struct comp_target *ct)
Is this target ready for image creation?
Definition: comp_target.h:397
static void comp_target_create_images(struct comp_target *ct, const struct comp_target_create_images_info *create_info, struct vk_bundle_queue *present_queue)
Create or recreate the image(s) of the target, for swapchain based targets this will (re)create the s...
Definition: comp_target.h:411
static void comp_target_calc_frame_pacing(struct comp_target *ct, int64_t *out_frame_id, int64_t *out_wake_up_time_ns, int64_t *out_desired_present_time_ns, int64_t *out_present_slop_ns, int64_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...
Definition: comp_target.h:511
comp_target_timing_point
For marking timepoints on a frame's lifetime, not a async event.
Definition: comp_target.h:32
static void comp_target_mark_begin(struct comp_target *ct, int64_t frame_id, int64_t when_began_ns)
Quick helper for marking begin.
Definition: comp_target.h:552
static bool 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 th...
Definition: comp_target.h:774
static void comp_target_mark_submit_end(struct comp_target *ct, int64_t frame_id, int64_t when_submit_end_ns)
Quick helper for marking submit end.
Definition: comp_target.h:582
static xrt_result_t comp_target_request_refresh_rate(struct comp_target *ct, float ratedisplay_refresh_rate_hz)
Get the current refresh rate for the compositor target.
Definition: comp_target.h:667
static bool 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,...
Definition: comp_target.h:788
static bool comp_target_init_pre_vulkan(struct comp_target *ct)
Do any initialization that is required to happen before Vulkan has been loaded.
Definition: comp_target.h:369
static void comp_target_info_gpu(struct comp_target *ct, int64_t frame_id, int64_t gpu_start_ns, int64_t gpu_end_ns, int64_t when_ns)
Provide frame timing information about GPU start and stop time.
Definition: comp_target.h:610
static bool 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...
Definition: comp_target.h:383
@ COMP_TARGET_TIMING_POINT_SUBMIT_BEGIN
Just before submitting work to the GPU.
Definition: comp_target.h:40
@ COMP_TARGET_TIMING_POINT_BEGIN
Began CPU side work for GPU.
Definition: comp_target.h:37
@ COMP_TARGET_TIMING_POINT_WAKE_UP
Woke up after sleeping in wait frame.
Definition: comp_target.h:34
@ COMP_TARGET_TIMING_POINT_SUBMIT_END
Just after submitting work to the GPU.
Definition: comp_target.h:43
enum xrt_result xrt_result_t
Result type used across Monado.
#define XRT_MAX_SWAPCHAIN_FORMATS
Max formats supported by a compositor, artificial limit.
Definition: xrt_limits.h:58
Main compositor struct tying everything in the compositor together.
Definition: comp_compositor.h:91
Information given in when creating the swapchain images, argument to comp_target_create_images.
Definition: comp_target.h:75
VkColorSpaceKHR color_space
Preferred color space, can be ignored by the target.
Definition: comp_target.h:89
VkExtent2D extent
Preferred extent, can be ignored by the target.
Definition: comp_target.h:86
VkImageUsageFlags image_usage
Image usage for the images, must be followed.
Definition: comp_target.h:77
VkFormat formats[XRT_MAX_SWAPCHAIN_FORMATS]
Acceptable formats for the images, must be followed.
Definition: comp_target.h:80
A factory of targets.
Definition: comp_target.h:714
const char ** required_instance_extensions
Required instance extensions.
Definition: comp_target.h:737
bool requires_vulkan_for_create
Does this factory require Vulkan to have been initialized.
Definition: comp_target.h:722
size_t required_instance_extension_count
Required instance extension count.
Definition: comp_target.h:740
const char * identifier
Short all lowercase identifier for target type.
Definition: comp_target.h:719
size_t optional_device_extension_count
Optional device extension count.
Definition: comp_target.h:746
const char ** optional_device_extensions
Optional device extensions.
Definition: comp_target.h:743
const char * name
Pretty loggable name of target type.
Definition: comp_target.h:716
bool(* 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 th...
Definition: comp_target.h:756
uint32_t required_instance_version
Vulkan version that is required or 0 if no specific requirement, equivalent to VK_MAKE_VERSION(1,...
Definition: comp_target.h:734
bool is_deferred
Is this a deferred target that can have it's creation delayed even further then after Vulkan initiali...
Definition: comp_target.h:728
bool(* 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,...
Definition: comp_target.h:762
Image and view pair for comp_target.
Definition: comp_target.h:63
Collection of semaphores needed for a target.
Definition: comp_target.h:101
VkSemaphore render_complete
Semaphore the renderer (consuming this target) should signal when rendering is complete.
Definition: comp_target.h:111
VkSemaphore present_complete
Optional semaphore the target should signal when present is complete.
Definition: comp_target.h:105
bool render_complete_is_timeline
If true, render_complete is a timeline semaphore instead of a binary semaphore.
Definition: comp_target.h:117
A compositor target: where the compositor renders to.
Definition: comp_target.h:133
bool(* has_images)(struct comp_target *ct)
Has this target successfully had images created?
Definition: comp_target.h:208
void(* create_images)(struct comp_target *ct, const struct comp_target_create_images_info *create_info, struct vk_bundle_queue *present_queue)
Create or recreate the image(s) of the target, for swapchain based targets this will (re)create the s...
Definition: comp_target.h:198
bool(* check_ready)(struct comp_target *ct)
Is this target ready for image creation?
Definition: comp_target.h:186
xrt_result_t(* request_refresh_rate)(struct comp_target *ct, float display_refresh_rate_hz)
Get the current refresh rate for the compositor target.
Definition: comp_target.h:342
void(* flush)(struct comp_target *ct)
Flush any WSI state before rendering.
Definition: comp_target.h:251
VkResult(* present)(struct comp_target *ct, struct vk_bundle_queue *present_queue, uint32_t index, uint64_t timeline_semaphore_value, int64_t desired_present_time_ns, int64_t present_slop_ns)
Present the image at index to the screen.
Definition: comp_target.h:233
uint32_t width
Current dimensions of the target.
Definition: comp_target.h:141
void(* set_title)(struct comp_target *ct, const char *title)
If the target can show a title (like a window) set the title.
Definition: comp_target.h:314
bool(* 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...
Definition: comp_target.h:179
void(* destroy)(struct comp_target *ct)
Destroys this target.
Definition: comp_target.h:359
struct comp_target_image * images
Array of images and image views for rendering.
Definition: comp_target.h:152
VkResult(* wait_for_present)(struct comp_target *ct, time_duration_ns timeout_ns)
Wait for the latest presented image to be displayed to the user.
Definition: comp_target.h:246
uint32_t image_count
Number of images that this target has.
Definition: comp_target.h:150
VkResult(* acquire)(struct comp_target *ct, uint32_t *out_index)
Acquire the next image for rendering.
Definition: comp_target.h:218
void(* mark_timing_point)(struct comp_target *ct, enum comp_target_timing_point point, int64_t frame_id, int64_t when_ns)
The compositor tells the target a timing information about a single timing point on the frames lifecy...
Definition: comp_target.h:275
void(* info_gpu)(struct comp_target *ct, int64_t frame_id, int64_t gpu_start_ns, int64_t gpu_end_ns, int64_t when_ns)
Provide frame timing information about GPU start and stop time.
Definition: comp_target.h:302
bool(* init_pre_vulkan)(struct comp_target *ct)
Do any initialization that is required to happen before Vulkan has been loaded.
Definition: comp_target.h:173
VkResult(* update_timings)(struct comp_target *ct)
Update timing information for this target, this function should be lightweight and is called multiple...
Definition: comp_target.h:285
const char * name
Name of the backing system.
Definition: comp_target.h:138
struct comp_target_semaphores semaphores
Holds semaphore information.
Definition: comp_target.h:158
VkSurfaceTransformFlagBitsKHR surface_transform
Transformation of the current surface, required for pre-rotation.
Definition: comp_target.h:155
void(* calc_frame_pacing)(struct comp_target *ct, int64_t *out_frame_id, int64_t *out_wake_up_time_ns, int64_t *out_desired_present_time_ns, int64_t *out_present_slop_ns, int64_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...
Definition: comp_target.h:264
VkResult(* queue_supports_present)(struct comp_target *ct, struct vk_bundle_queue *queue, VkBool32 *out_supported)
Queries if a particular queue supports presentation ops/cmds for the compositor target.
Definition: comp_target.h:352
xrt_result_t(* get_refresh_rates)(struct comp_target *ct, uint32_t *out_count, float *out_display_refresh_rates_hz)
Get the available refresh rates for the compositor target.
Definition: comp_target.h:324
struct comp_compositor * c
Owning compositor.
Definition: comp_target.h:135
bool wait_for_present_supported
Whether wait_for_present is supported by this comp_target.
Definition: comp_target.h:161
VkFormat format
The format that the renderpass targeting this target should use.
Definition: comp_target.h:144
xrt_result_t(* get_current_refresh_rate)(struct comp_target *ct, float *out_display_refresh_rate_hz)
Get the current refresh rate for the compositor target.
Definition: comp_target.h:334
VkImageLayout final_layout
The final layout that the renderpass should leave this target in.
Definition: comp_target.h:147
Definition: vk_helpers.h:56
VkQueue queue
The Vulkan queue handle.
Definition: vk_helpers.h:58
uint32_t index
The queue (instance) index.
Definition: vk_helpers.h:62
Tracing support code, see Tracing support.
Common Vulkan code header.
Header holding common defines.
Common defines and enums for XRT.