Monado OpenXR Runtime
Loading...
Searching...
No Matches
u_pacing.h
Go to the documentation of this file.
1// Copyright 2020-2022, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Shared pacing code.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @author Rylie Pavlik <rylie.pavlik@collabora.com>
8 * @ingroup aux_util
9 */
10
11#pragma once
12
13#include "xrt/xrt_compiler.h"
14#include "xrt/xrt_defines.h"
15
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21
22/*!
23 * @defgroup aux_pacing Frame and Render timing/pacing
24 *
25 * @ingroup aux_util
26 * @see @ref frame-pacing.
27 */
28
29
30/*!
31 * For marking timepoints on a frame's lifetime, not a async event.
32 *
33 * @ingroup aux_pacing
34 */
36{
37 //! Woke up after sleeping in "wait frame".
39
40 //! Began CPU side work for GPU.
42
43 //! Began submitting work to the GPU, only used by the compositor.
45
46 //! Finished submitting work to the GPU, only used by the compositor.
48};
49
50
51/*
52 *
53 * Compositor pacing helper.
54 *
55 */
56
57/*!
58 * Compositor pacing helper interface.
59 *
60 * This is used for the compositor's own frame timing/pacing. It is not responsible for getting the timing data from the
61 * graphics API, etc: instead it consumes timing data from the graphics API (if available) and from "markers" in the
62 * compositor's CPU code, and produces predictions that are used to guide the compositor.
63 *
64 * Pacing of the underlying app/client is handled by @ref u_pacing_app
65 *
66 * @ingroup aux_pacing
67 */
69{
70 /*!
71 * Allocate a new frame, this allocates a frame ID but does not make any predictions.
72 *
73 * Call @ref predict_frame afterwards with the returned ID. Between the two calls, the pacer may be given
74 * information that will influence the prediction, like @ref update_present_offset.
75 *
76 * @param[in] upc The compositor pacing helper.
77 * @param[out] out_frame_id Id used to refer to this frame again.
78 *
79 * @see @ref frame-pacing.
80 */
81 void (*allocate_frame)(struct u_pacing_compositor *upc, int64_t *out_frame_id);
82
83 /*!
84 * Predict timings for a frame previously allocated with @ref allocate_frame.
85 *
86 * @param[in] upc The compositor pacing helper.
87 * @param[in] frame_id The frame ID from @ref allocate_frame.
88 * @param[in] now_ns The current timestamp in nanoseconds, nominally from @ref
89 * os_monotonic_get_ns
90 * @param[out] out_wake_up_time_ns When should the compositor wake up.
91 * @param[out] out_desired_present_time_ns The GPU should start scanning out at this time.
92 * @param[out] out_present_slop_ns Any looseness to the desired present timing.
93 * @param[out] out_predicted_display_time_ns At what time have we predicted that pixels turns to photons.
94 * @param[out] out_predicted_display_period_ns Display period that we are running on.
95 * @param[out] out_min_display_period_ns The fastest theoretical display period.
96 *
97 * @see @ref frame-pacing.
98 */
100 int64_t frame_id,
101 int64_t now_ns,
102 int64_t *out_wake_up_time_ns,
103 int64_t *out_desired_present_time_ns,
104 int64_t *out_present_slop_ns,
105 int64_t *out_predicted_display_time_ns,
106 int64_t *out_predicted_display_period_ns,
107 int64_t *out_min_display_period_ns);
108
109 /*!
110 * Mark a point on the frame's lifetime.
111 *
112 * This is usually provided "when it happens" because the points to mark are steps in the CPU workload of the
113 * compositor.
114 *
115 * @param[in] upc The compositor pacing helper.
116 * @param[in] point The point to record for a frame.
117 * @param[in] frame_id The frame ID to record for.
118 * @param[in] when_ns The timestamp of the event.
119 *
120 * @see @ref frame-pacing.
121 */
122 void (*mark_point)(struct u_pacing_compositor *upc,
123 enum u_timing_point point,
124 int64_t frame_id,
125 int64_t when_ns);
126
127 /*!
128 * Provide frame timing information about a delivered frame.
129 *
130 * This is usually provided after-the-fact by the display system. These arguments currently
131 * matches 1-to-1 what VK_GOOGLE_display_timing provides, see
132 * https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkPastPresentationTimingGOOGLE.html
133 *
134 * Depend on when the information is delivered this can be called at any
135 * point of the following frames.
136 *
137 * @param[in] upc The compositor pacing helper.
138 * @param[in] frame_id The frame ID to record for.
139 * @param[in] desired_present_time_ns The time that we indicated the GPU should start scanning out at, or zero
140 * if we didn't provide such a time.
141 * @param[in] actual_present_time_ns The time that the GPU actually started scanning out.
142 * @param[in] earliest_present_time_ns The earliest the GPU could have presented - might be before @p
143 * actual_present_time_ns if a @p desired_present_time_ns was passed.
144 * @param[in] present_margin_ns How "early" present happened compared to when it needed to happen in
145 * order to finish at @p earliestPresentTime.
146 * @param[in] when_ns The time when we got the info, nominally from @ref
147 * os_monotonic_get_ns
148 *
149 * @see @ref frame-pacing.
150 */
151 void (*info)(struct u_pacing_compositor *upc,
152 int64_t frame_id,
153 int64_t desired_present_time_ns,
154 int64_t actual_present_time_ns,
155 int64_t earliest_present_time_ns,
156 int64_t present_margin_ns,
157 int64_t when_ns);
158
159 /*!
160 * Provide frame timing information about GPU start and stop time.
161 *
162 * Depend on when the information is delivered this can be called at any
163 * point of the following frames.
164 *
165 * @param[in] upc The compositor pacing helper.
166 * @param[in] frame_id The frame ID to record for.
167 * @param[in] gpu_start_ns When the GPU work startred.
168 * @param[in] gpu_end_ns When the GPU work stopped.
169 * @param[in] when_ns When the informatioon collected, nominally
170 * from @ref os_monotonic_get_ns.
171 *
172 * @see @ref frame-pacing.
173 */
174 void (*info_gpu)(struct u_pacing_compositor *upc,
175 int64_t frame_id,
176 int64_t gpu_start_ns,
177 int64_t gpu_end_ns,
178 int64_t when_ns);
179
180 /*!
181 * Provide a vblank timing information, derived from the
182 * VK_EXT_display_control extension. Since the extension only says when
183 * a vblank happened (somewhat inaccurate as well) but not if a specific
184 * present happened at that time no frame_id is given.
185 *
186 * @param[in] upc The compositor pacing helper.
187 * @param[in] last_vblank_ns The last time that the GPU started scanning out.
188 *
189 * @see @ref frame-pacing.
190 */
191 void (*update_vblank_from_display_control)(struct u_pacing_compositor *upc, int64_t last_vblank_ns);
192
193 /*!
194 * Provide an updated estimate of the present offset.
195 *
196 * This is usually used only for more complicated display systems. Call it after @ref allocate_frame and before
197 * @ref predict_frame to have it affect that frame's prediction.
198 *
199 * @param[in] upc The compositor pacing helper.
200 * @param[in] frame_id The frame ID to record for.
201 * @param[in] present_to_display_offset_ns The improved estimate of the time between "present" and photons.
202 *
203 * @see @ref frame-pacing.
204 */
206 int64_t frame_id,
207 int64_t present_to_display_offset_ns);
208
209 /*!
210 * Destroy this u_pacing_compositor.
211 */
212 void (*destroy)(struct u_pacing_compositor *upc);
213};
214
215/*!
216 * @copydoc u_pacing_compositor::allocate_frame
217 *
218 * Helper for calling through the function pointer.
219 *
220 * @public @memberof u_pacing_compositor
221 * @ingroup aux_pacing
222 */
223static inline void
224u_pc_allocate_frame(struct u_pacing_compositor *upc, int64_t *out_frame_id)
225{
226 upc->allocate_frame(upc, out_frame_id);
227}
228
229/*!
230 * @copydoc u_pacing_compositor::predict_frame
231 *
232 * Helper for calling through the function pointer.
233 *
234 * @public @memberof u_pacing_compositor
235 * @ingroup aux_pacing
236 */
237static inline void
239 int64_t frame_id,
240 int64_t now_ns,
241 int64_t *out_wake_up_time_ns,
242 int64_t *out_desired_present_time_ns,
243 int64_t *out_present_slop_ns,
244 int64_t *out_predicted_display_time_ns,
245 int64_t *out_predicted_display_period_ns,
246 int64_t *out_min_display_period_ns)
247{
248 upc->predict_frame(upc, //
249 frame_id, //
250 now_ns, //
251 out_wake_up_time_ns, //
252 out_desired_present_time_ns, //
253 out_present_slop_ns, //
254 out_predicted_display_time_ns, //
255 out_predicted_display_period_ns, //
256 out_min_display_period_ns); //
257}
258
259/*!
260 * @copydoc u_pacing_compositor::mark_point
261 *
262 * Helper for calling through the function pointer.
263 *
264 * @public @memberof u_pacing_compositor
265 * @ingroup aux_pacing
266 */
267static inline void
268u_pc_mark_point(struct u_pacing_compositor *upc, enum u_timing_point point, int64_t frame_id, int64_t when_ns)
269{
270 upc->mark_point(upc, point, frame_id, when_ns);
271}
272
273/*!
274 * @copydoc u_pacing_compositor::info
275 *
276 * Helper for calling through the function pointer.
277 *
278 * @public @memberof u_pacing_compositor
279 * @ingroup aux_pacing
280 */
281static inline void
283 int64_t frame_id,
284 int64_t desired_present_time_ns,
285 int64_t actual_present_time_ns,
286 int64_t earliest_present_time_ns,
287 int64_t present_margin_ns,
288 int64_t when_ns)
289{
290 upc->info(upc, frame_id, desired_present_time_ns, actual_present_time_ns, earliest_present_time_ns,
291 present_margin_ns, when_ns);
292}
293
294
295/*!
296 * @copydoc u_pacing_compositor::info_gpu
297 *
298 * Helper for calling through the function pointer.
299 *
300 * @public @memberof u_pacing_compositor
301 * @ingroup aux_pacing
302 */
303static inline void
305 struct u_pacing_compositor *upc, int64_t frame_id, int64_t gpu_start_ns, int64_t gpu_end_ns, int64_t when_ns)
306{
307 upc->info_gpu(upc, frame_id, gpu_start_ns, gpu_end_ns, when_ns);
308}
309
310/*!
311 * @copydoc u_pacing_compositor::update_vblank_from_display_control
312 *
313 * Helper for calling through the function pointer.
314 *
315 * @public @memberof u_pacing_compositor
316 * @ingroup aux_pacing
317 */
318static inline void
320{
321 upc->update_vblank_from_display_control(upc, last_vblank_ns);
322}
323
324/*!
325 * @copydoc u_pacing_compositor::update_present_offset
326 *
327 * Helper for calling through the function pointer.
328 *
329 * @public @memberof u_pacing_compositor
330 * @ingroup aux_pacing
331 */
332static inline void
333u_pc_update_present_offset(struct u_pacing_compositor *upc, int64_t frame_id, int64_t present_to_display_offset_ns)
334{
335 upc->update_present_offset(upc, frame_id, present_to_display_offset_ns);
336}
337
338/*!
339 * @copydoc u_pacing_compositor::destroy
340 *
341 * Helper for calling through the function pointer: does a null check and sets
342 * @p upc_ptr to null if freed.
343 *
344 * @public @memberof u_pacing_compositor
345 * @ingroup aux_pacing
346 */
347static inline void
349{
350 struct u_pacing_compositor *upc = *upc_ptr;
351 if (upc == NULL) {
352 return;
353 }
354
355 upc->destroy(upc);
356 *upc_ptr = NULL;
357}
358
359
360/*
361 *
362 * App pacer.
363 *
364 */
365
366/*!
367 * This application pacing helper is designed to schedule the rendering time of
368 * clients that submit frames to a compositor, which runs its own render loop
369 * that picks latest completed frames for that client.
370 *
371 * It manages the frame pacing of an app/client, rather than the compositor itself. The frame pacing of the compositor
372 * is handled by @ref u_pacing_compositor
373 *
374 * @ingroup aux_pacing
375 */
377{
378 /*!
379 * Predict when the client's next rendered frame will be displayed; when the
380 * client should be woken up from sleeping; and its display period.
381 *
382 * This is called from `xrWaitFrame`, but it does not do any waiting, the caller
383 * should wait till `out_wake_up_time`.
384 *
385 * @param upa Render timing helper.
386 * @param[in] now_ns The current timestamp in nanoseconds, nominally from @ref
387 * os_monotonic_get_ns
388 * @param[out] out_frame_id Frame ID of this predicted frame.
389 * @param[out] out_wake_up_time When the client should be woken up.
390 * @param[out] out_predicted_display_time Predicted display time.
391 * @param[out] out_predicted_display_period Predicted display period.
392 */
393 void (*predict)(struct u_pacing_app *upa,
394 int64_t now_ns,
395 int64_t *out_frame_id,
396 int64_t *out_wake_up_time,
397 int64_t *out_predicted_display_time,
398 int64_t *out_predicted_display_period);
399
400 /*!
401 * Mark a point on the frame's lifetime.
402 *
403 * @param upa Render timing helper.
404 * @param[in] frame_id The frame ID to record for.
405 * @param[in] point The point/event to record
406 * @param[in] when_ns The timestamp
407 *
408 * @see @ref frame-pacing.
409 */
410 void (*mark_point)(struct u_pacing_app *upa, int64_t frame_id, enum u_timing_point point, int64_t when_ns);
411
412 /*!
413 * When a frame has been discarded.
414 *
415 * @param upa Render timing helper.
416 * @param[in] frame_id The frame ID to mark as discarded.
417 * @param[in] when_ns The time when it was discarded, nominally from @ref os_monotonic_get_ns
418 */
419 void (*mark_discarded)(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns);
420
421 /*!
422 * A frame has been delivered from the client, see `xrEndFrame`. The GPU might
423 * still be rendering the work.
424 *
425 * @param upa Render timing helper.
426 * @param[in] frame_id The frame ID to mark as delivered.
427 * @param[in] when_ns The time when it was delivered, nominally from @ref os_monotonic_get_ns
428 * @param[in] display_time_ns The time the frame is to be displayed.
429 */
430 void (*mark_delivered)(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns, int64_t display_time_ns);
431
432 /*!
433 * A frame has been completed rendered by the GPU, this can happen after `xrEndFrame` has returned.
434 *
435 * @param upa Render timing helper.
436 * @param[in] frame_id The frame ID to mark as delivered.
437 * @param[in] when_ns The time when it the gpu was finished, nominally from @ref os_monotonic_get_ns
438 */
439 void (*mark_gpu_done)(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns);
440
441 /*!
442 * Latch a frame for rendering for delivery to the native compositor,
443 * may be called multiple times for the same frame should the app be on
444 * a frame cadence that is lower then the native compositor.
445 *
446 * @param upa App pacer struct.
447 * @param[in] frame_id The frame ID of the latched frame.
448 * @param[in] when_ns Time when the latching happened.
449 * @param[in] system_frame_id The ID of the system frame that is
450 * latching the app's frame.
451 */
452 void (*latched)(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns, int64_t system_frame_id);
453
454 /*!
455 * Mark a frame as completely retired, will never be latched (used by
456 * the native compositor again) as a new frame has been latched or a
457 * shutdown condition has been met.
458 *
459 * @param upa App pacer struct.
460 * @param[in] frame_id The frame ID of the latched frame.
461 * @param[in] when_ns Time when the latching happened.
462 */
463 void (*retired)(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns);
464
465 /*!
466 * Add a new sample point from the main render loop.
467 *
468 * This is called in the main renderer loop that tightly submits frames to the
469 * real compositor for displaying. This is only used to inform the render helper
470 * when the frame will be shown, not any timing information about the client.
471 *
472 * When this is called doesn't matter that much, as the render timing will need
473 * to be able to predict one or more frames into the future anyways. But
474 * preferably as soon as the main loop wakes up from wait frame.
475 *
476 * @param upa Self pointer
477 * @param predicted_display_time_ns Predicted display time for this sample.
478 * @param predicted_display_period_ns Predicted display period for this sample.
479 * @param extra_ns Time between display and when this sample
480 * was created, that is when the main loop
481 * was woken up by the main compositor.
482 */
483 void (*info)(struct u_pacing_app *upa,
484 int64_t predicted_display_time_ns,
485 int64_t predicted_display_period_ns,
486 int64_t extra_ns);
487
488 /*!
489 * Destroy this u_pacing_app.
490 */
491 void (*destroy)(struct u_pacing_app *upa);
492};
493
494/*!
495 * @copydoc u_pacing_app::predict
496 *
497 * Helper for calling through the function pointer.
498 *
499 * @public @memberof u_pacing_app
500 * @ingroup aux_pacing
501 */
502static inline void
504 int64_t now_ns,
505 int64_t *out_frame_id,
506 int64_t *out_wake_up_time,
507 int64_t *out_predicted_display_time,
508 int64_t *out_predicted_display_period)
509{
510 upa->predict(upa, now_ns, out_frame_id, out_wake_up_time, out_predicted_display_time,
511 out_predicted_display_period);
512}
513
514/*!
515 * @copydoc u_pacing_app::mark_point
516 *
517 * Helper for calling through the function pointer.
518 *
519 * @public @memberof u_pacing_app
520 * @ingroup aux_pacing
521 */
522static inline void
523u_pa_mark_point(struct u_pacing_app *upa, int64_t frame_id, enum u_timing_point point, int64_t when_ns)
524{
525 upa->mark_point(upa, frame_id, point, when_ns);
526}
527
528/*!
529 * @copydoc u_pacing_app::mark_discarded
530 *
531 * Helper for calling through the function pointer.
532 *
533 * @public @memberof u_pacing_app
534 * @ingroup aux_pacing
535 */
536static inline void
537u_pa_mark_discarded(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns)
538{
539 upa->mark_discarded(upa, frame_id, when_ns);
540}
541
542/*!
543 * @copydoc u_pacing_app::mark_delivered
544 *
545 * Helper for calling through the function pointer.
546 *
547 * @public @memberof u_pacing_app
548 * @ingroup aux_pacing
549 */
550static inline void
551u_pa_mark_delivered(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns, int64_t display_time_ns)
552{
553 upa->mark_delivered(upa, frame_id, when_ns, display_time_ns);
554}
555
556/*!
557 * @copydoc u_pacing_app::mark_gpu_done
558 *
559 * Helper for calling through the function pointer.
560 *
561 * @public @memberof u_pacing_app
562 * @ingroup aux_pacing
563 */
564static inline void
565u_pa_mark_gpu_done(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns)
566{
567 upa->mark_gpu_done(upa, frame_id, when_ns);
568}
569
570/*!
571 * @copydoc u_pacing_app::info
572 *
573 * Helper for calling through the function pointer.
574 *
575 * @public @memberof u_pacing_app
576 * @ingroup aux_pacing
577 */
578static inline void
580 int64_t predicted_display_time_ns,
581 int64_t predicted_display_period_ns,
582 int64_t extra_ns)
583{
584 upa->info(upa, predicted_display_time_ns, predicted_display_period_ns, extra_ns);
585}
586
587/*!
588 * @copydoc u_pacing_app::latched
589 *
590 * Helper for calling through the function pointer.
591 *
592 * @public @memberof u_pacing_app
593 * @ingroup aux_pacing
594 */
595static inline void
596u_pa_latched(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns, int64_t system_frame_id)
597{
598 upa->latched(upa, frame_id, when_ns, system_frame_id);
599}
600
601/*!
602 * @copydoc u_pacing_app::retired
603 *
604 * Helper for calling through the function pointer.
605 *
606 * @public @memberof u_pacing_app
607 * @ingroup aux_pacing
608 */
609static inline void
610u_pa_retired(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns)
611{
612 upa->retired(upa, frame_id, when_ns);
613}
614
615/*!
616 * @copydoc u_pacing_app::destroy
617 *
618 * Helper for calling through the function pointer: does a null check and sets
619 * upa_ptr to null if freed.
620 *
621 * @public @memberof u_pacing_app
622 * @ingroup aux_pacing
623 */
624static inline void
625u_pa_destroy(struct u_pacing_app **upa_ptr)
626{
627 struct u_pacing_app *upa = *upa_ptr;
628 if (upa == NULL) {
629 return;
630 }
631
632 upa->destroy(upa);
633 *upa_ptr = NULL;
634}
635
636
637/*
638 *
639 * App pacing factory.
640 *
641 */
642
643/*!
644 * Small helper that creates a app pacers, allows timing information to be
645 * collected and controlled to a central place.
646 */
648{
649 /*!
650 * Create a @ref u_pacing_app.
651 *
652 * @param upaf App pacing factory.
653 * @param[out] out_upa Created app pacer.
654 */
655 xrt_result_t (*create)(struct u_pacing_app_factory *upaf, struct u_pacing_app **out_upa);
656
657 /*!
658 * Destroy this u_pacing_app_factory.
659 */
660 void (*destroy)(struct u_pacing_app_factory *upaf);
661};
662
663/*!
664 * @copydoc u_pacing_app_factory::create
665 *
666 * Helper for calling through the function pointer.
667 *
668 * @public @memberof u_pacing_app_factory
669 * @ingroup aux_pacing
670 */
671static inline void
672u_paf_create(struct u_pacing_app_factory *upaf, struct u_pacing_app **out_upa)
673{
674 upaf->create(upaf, out_upa);
675}
676
677/*!
678 * @copydoc u_pacing_app_factory::destroy
679 *
680 * Helper for calling through the function pointer: does a null check and sets
681 * upa_ptr to null if freed.
682 *
683 * @public @memberof u_pacing_app_factory
684 * @ingroup aux_pacing
685 */
686static inline void
688{
689 struct u_pacing_app_factory *upaf = *upaf_ptr;
690 if (upaf == NULL) {
691 return;
692 }
693
694 upaf->destroy(upaf);
695 *upaf_ptr = NULL;
696}
697
698
699/*
700 *
701 * Configuration struct
702 *
703 */
704/*!
705 * Configuration for the "display-timing-aware" implementation of @ref u_pacing_compositor
706 *
707 * @see u_pc_display_timing_create
708 */
710{
711 //! How long after "present" is the image actually displayed
713 //! Extra margin that is added to compositor time, between end of draw and present
714 int64_t margin_ns;
715 /*!
716 * @name Frame-Relative Values
717 * All these values are in "percentage points of the nominal frame period" so they can work across
718 * devices of varying refresh rate/display interval.
719 * @{
720 */
721 //! The initial estimate of how much time the compositor needs
723 //! The maximum time we allow to the compositor
725 //! When missing a frame, back off in these increments
727 //! When not missing frames but adjusting app time at these increments
729 /*!
730 * @}
731 */
732};
733
734
735/*
736 *
737 * Implementations.
738 *
739 */
740
741/*!
742 * Gets the default configuration of the composition pacing helper.
743 *
744 * Some of the configuration values returned from this function can be
745 * configured using debug options.
746 *
747 * @ingroup aux_pacing
748 * @see u_pacing_compositor
749 */
752
753/*!
754 * Creates a new composition pacing helper that uses real display timing information.
755 *
756 * Meant to be used with `VK_GOOGLE_display_timing`.
757 *
758 * @param[in] estimated_frame_period_ns The estimated duration/period of a frame in nanoseconds.
759 * @param[in] config The configuration to use, see @ref u_pc_display_timing_get_default_config.
760 * @param[out] out_upc The pointer to populate with the created compositor pacing helper
761 *
762 * @ingroup aux_pacing
763 * @see u_pacing_compositor
764 */
766u_pc_display_timing_create(int64_t estimated_frame_period_ns,
767 const struct u_pc_display_timing_config *config,
768 struct u_pacing_compositor **out_upc);
769
770/*!
771 * Creates a new composition pacing helper that does not depend on display timing information.
772 *
773 * When you cannot get display timing information, use this.
774 *
775 * @param[in] estimated_frame_period_ns The estimated duration/period of a frame in nanoseconds.
776 * @param[in] now_ns The current timestamp in nanoseconds, nominally from @ref os_monotonic_get_ns
777 * @param[out] out_upc The pointer to populate with the created compositor pacing helper
778 *
779 * @ingroup aux_pacing
780 * @see u_pacing_compositor
781 */
783u_pc_fake_create(int64_t estimated_frame_period_ns, int64_t now_ns, struct u_pacing_compositor **out_upc);
784
785/*!
786 * Creates a new application pacing factory helper.
787 *
788 * @ingroup aux_pacing
789 * @see u_pacing_app
790 */
793
794
795#ifdef __cplusplus
796}
797#endif
static void u_pc_predict_frame(struct u_pacing_compositor *upc, int64_t frame_id, int64_t now_ns, 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, int64_t *out_predicted_display_period_ns, int64_t *out_min_display_period_ns)
Predict timings for a frame previously allocated with allocate_frame.
Definition u_pacing.h:238
static void u_pa_mark_discarded(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns)
When a frame has been discarded.
Definition u_pacing.h:537
u_timing_point
For marking timepoints on a frame's lifetime, not a async event.
Definition u_pacing.h:36
static void u_pa_mark_point(struct u_pacing_app *upa, int64_t frame_id, enum u_timing_point point, int64_t when_ns)
Mark a point on the frame's lifetime.
Definition u_pacing.h:523
xrt_result_t u_pc_display_timing_create(int64_t estimated_frame_period_ns, const struct u_pc_display_timing_config *config, struct u_pacing_compositor **out_upc)
Creates a new composition pacing helper that uses real display timing information.
Definition u_pacing_compositor.c:783
static void u_pc_info_gpu(struct u_pacing_compositor *upc, 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 u_pacing.h:304
xrt_result_t u_pa_factory_create(struct u_pacing_app_factory **out_upaf)
Creates a new application pacing factory helper.
Definition u_pacing_app.c:824
static void u_pa_retired(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns)
Mark a frame as completely retired, will never be latched (used by the native compositor again) as a ...
Definition u_pacing.h:610
static void u_pc_mark_point(struct u_pacing_compositor *upc, enum u_timing_point point, int64_t frame_id, int64_t when_ns)
Mark a point on the frame's lifetime.
Definition u_pacing.h:268
static void u_pa_predict(struct u_pacing_app *upa, int64_t now_ns, int64_t *out_frame_id, int64_t *out_wake_up_time, int64_t *out_predicted_display_time, int64_t *out_predicted_display_period)
Predict when the client's next rendered frame will be displayed; when the client should be woken up f...
Definition u_pacing.h:503
static void u_pc_destroy(struct u_pacing_compositor **upc_ptr)
Destroy this u_pacing_compositor.
Definition u_pacing.h:348
static void u_pa_destroy(struct u_pacing_app **upa_ptr)
Destroy this u_pacing_app.
Definition u_pacing.h:625
static void u_pa_mark_delivered(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns, int64_t display_time_ns)
A frame has been delivered from the client, see xrEndFrame.
Definition u_pacing.h:551
static void u_pa_info(struct u_pacing_app *upa, int64_t predicted_display_time_ns, int64_t predicted_display_period_ns, int64_t extra_ns)
Add a new sample point from the main render loop.
Definition u_pacing.h:579
static void u_paf_destroy(struct u_pacing_app_factory **upaf_ptr)
Destroy this u_pacing_app_factory.
Definition u_pacing.h:687
static void u_paf_create(struct u_pacing_app_factory *upaf, struct u_pacing_app **out_upa)
Create a u_pacing_app.
Definition u_pacing.h:672
static void u_pc_info(struct u_pacing_compositor *upc, int64_t frame_id, int64_t desired_present_time_ns, int64_t actual_present_time_ns, int64_t earliest_present_time_ns, int64_t present_margin_ns, int64_t when_ns)
Provide frame timing information about a delivered frame.
Definition u_pacing.h:282
xrt_result_t u_pc_fake_create(int64_t estimated_frame_period_ns, int64_t now_ns, struct u_pacing_compositor **out_upc)
Creates a new composition pacing helper that does not depend on display timing information.
Definition u_pacing_compositor_fake.c:470
static void u_pc_update_vblank_from_display_control(struct u_pacing_compositor *upc, int64_t last_vblank_ns)
Provide a vblank timing information, derived from the VK_EXT_display_control extension.
Definition u_pacing.h:319
static void u_pa_mark_gpu_done(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns)
A frame has been completed rendered by the GPU, this can happen after xrEndFrame has returned.
Definition u_pacing.h:565
static void u_pa_latched(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns, int64_t system_frame_id)
Latch a frame for rendering for delivery to the native compositor, may be called multiple times for t...
Definition u_pacing.h:596
struct u_pc_display_timing_config u_pc_display_timing_get_default_config(void)
Gets the default configuration of the composition pacing helper.
Definition u_pacing_compositor.c:760
static void u_pc_allocate_frame(struct u_pacing_compositor *upc, int64_t *out_frame_id)
Allocate a new frame, this allocates a frame ID but does not make any predictions.
Definition u_pacing.h:224
static void u_pc_update_present_offset(struct u_pacing_compositor *upc, int64_t frame_id, int64_t present_to_display_offset_ns)
Provide an updated estimate of the present offset.
Definition u_pacing.h:333
@ U_TIMING_POINT_SUBMIT_END
Finished submitting work to the GPU, only used by the compositor.
Definition u_pacing.h:47
@ U_TIMING_POINT_SUBMIT_BEGIN
Began submitting work to the GPU, only used by the compositor.
Definition u_pacing.h:44
@ U_TIMING_POINT_BEGIN
Began CPU side work for GPU.
Definition u_pacing.h:41
@ U_TIMING_POINT_WAKE_UP
Woke up after sleeping in "wait frame".
Definition u_pacing.h:38
enum xrt_result xrt_result_t
Result type used across Monado.
Small helper that creates a app pacers, allows timing information to be collected and controlled to a...
Definition u_pacing.h:648
void(* destroy)(struct u_pacing_app_factory *upaf)
Destroy this u_pacing_app_factory.
Definition u_pacing.h:660
xrt_result_t(* create)(struct u_pacing_app_factory *upaf, struct u_pacing_app **out_upa)
Create a u_pacing_app.
Definition u_pacing.h:655
This application pacing helper is designed to schedule the rendering time of clients that submit fram...
Definition u_pacing.h:377
void(* destroy)(struct u_pacing_app *upa)
Destroy this u_pacing_app.
Definition u_pacing.h:491
void(* mark_discarded)(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns)
When a frame has been discarded.
Definition u_pacing.h:419
void(* info)(struct u_pacing_app *upa, int64_t predicted_display_time_ns, int64_t predicted_display_period_ns, int64_t extra_ns)
Add a new sample point from the main render loop.
Definition u_pacing.h:483
void(* mark_delivered)(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns, int64_t display_time_ns)
A frame has been delivered from the client, see xrEndFrame.
Definition u_pacing.h:430
void(* latched)(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns, int64_t system_frame_id)
Latch a frame for rendering for delivery to the native compositor, may be called multiple times for t...
Definition u_pacing.h:452
void(* retired)(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns)
Mark a frame as completely retired, will never be latched (used by the native compositor again) as a ...
Definition u_pacing.h:463
void(* mark_point)(struct u_pacing_app *upa, int64_t frame_id, enum u_timing_point point, int64_t when_ns)
Mark a point on the frame's lifetime.
Definition u_pacing.h:410
void(* mark_gpu_done)(struct u_pacing_app *upa, int64_t frame_id, int64_t when_ns)
A frame has been completed rendered by the GPU, this can happen after xrEndFrame has returned.
Definition u_pacing.h:439
void(* predict)(struct u_pacing_app *upa, int64_t now_ns, int64_t *out_frame_id, int64_t *out_wake_up_time, int64_t *out_predicted_display_time, int64_t *out_predicted_display_period)
Predict when the client's next rendered frame will be displayed; when the client should be woken up f...
Definition u_pacing.h:393
Compositor pacing helper interface.
Definition u_pacing.h:69
void(* destroy)(struct u_pacing_compositor *upc)
Destroy this u_pacing_compositor.
Definition u_pacing.h:212
void(* update_present_offset)(struct u_pacing_compositor *upc, int64_t frame_id, int64_t present_to_display_offset_ns)
Provide an updated estimate of the present offset.
Definition u_pacing.h:205
void(* predict_frame)(struct u_pacing_compositor *upc, int64_t frame_id, int64_t now_ns, 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, int64_t *out_predicted_display_period_ns, int64_t *out_min_display_period_ns)
Predict timings for a frame previously allocated with allocate_frame.
Definition u_pacing.h:99
void(* update_vblank_from_display_control)(struct u_pacing_compositor *upc, int64_t last_vblank_ns)
Provide a vblank timing information, derived from the VK_EXT_display_control extension.
Definition u_pacing.h:191
void(* info)(struct u_pacing_compositor *upc, int64_t frame_id, int64_t desired_present_time_ns, int64_t actual_present_time_ns, int64_t earliest_present_time_ns, int64_t present_margin_ns, int64_t when_ns)
Provide frame timing information about a delivered frame.
Definition u_pacing.h:151
void(* mark_point)(struct u_pacing_compositor *upc, enum u_timing_point point, int64_t frame_id, int64_t when_ns)
Mark a point on the frame's lifetime.
Definition u_pacing.h:122
void(* allocate_frame)(struct u_pacing_compositor *upc, int64_t *out_frame_id)
Allocate a new frame, this allocates a frame ID but does not make any predictions.
Definition u_pacing.h:81
void(* info_gpu)(struct u_pacing_compositor *upc, 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 u_pacing.h:174
Configuration for the "display-timing-aware" implementation of u_pacing_compositor.
Definition u_pacing.h:710
int64_t margin_ns
Extra margin that is added to compositor time, between end of draw and present.
Definition u_pacing.h:714
uint32_t comp_time_max_fraction
The maximum time we allow to the compositor.
Definition u_pacing.h:724
uint32_t adjust_missed_fraction
When missing a frame, back off in these increments.
Definition u_pacing.h:726
uint32_t adjust_non_miss_fraction
When not missing frames but adjusting app time at these increments.
Definition u_pacing.h:728
int64_t present_to_display_offset_ns
How long after "present" is the image actually displayed.
Definition u_pacing.h:712
uint32_t comp_time_fraction
The initial estimate of how much time the compositor needs.
Definition u_pacing.h:722
Header holding common defines.
Common defines and enums for XRT.