Debian Codegraph @

src/xrt/auxiliary/util/u_pacing_compositor_fake.c

raw symbols SCIP
1 // Copyright 2020-2024, Collabora, Ltd.cxx . . $ `<file>/src/xrt/auxiliary/util/u_pacing_compositor_fake.c`/
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4 * @file
5 * @brief For generating a fake timing.
6 * @author Jakob Bornecrantz <[email protected]>
7 * @ingroup aux_util
8 */
9
10 #include "os/os_time.h"cxx . . $ `<file>/src/xrt/auxiliary/os/os_time.h`/
11
12 #include "util/u_var.h"cxx . . $ `<file>/src/xrt/auxiliary/util/u_var.h`/
13 #include "util/u_time.h"cxx . . $ `<file>/src/xrt/auxiliary/util/u_time.h`/
14 #include "util/u_misc.h"cxx . . $ `<file>/src/xrt/auxiliary/util/u_misc.h`/
15 #include "util/u_debug.h"cxx . . $ `<file>/src/xrt/auxiliary/util/u_debug.h`/
16 #include "util/u_pacing.h"cxx . . $ `<file>/src/xrt/auxiliary/util/u_pacing.h`/
17 #include "util/u_metrics.h"cxx . . $ `<file>/src/xrt/auxiliary/util/u_metrics.h`/
18 #include "util/u_logging.h"cxx . . $ `<file>/src/xrt/auxiliary/util/u_logging.h`/
19 #include "util/u_live_stats.h"cxx . . $ `<file>/src/xrt/auxiliary/util/u_live_stats.h`/
20 #include "util/u_trace_marker.h"cxx . . $ `<file>/src/xrt/auxiliary/util/u_trace_marker.h`/
21
22 #include <stdio.h>
23 #include <assert.h>
24
25
26 /*
27 *
28 * Structs and defines.
29 *
30 */
31
32 DEBUG_GET_ONCE_FLOAT_OPTIONcxx . . $ `src/xrt/auxiliary/util/u_debug.h:144:9`!(present_to_display_offset_ms, "U_PACING_COMP_PRESENT_TO_DISPLAY_OFFSET_MS", 4.0f)
33 DEBUG_GET_ONCE_FLOAT_OPTIONcxx . . $ `src/xrt/auxiliary/util/u_debug.h:144:9`!(min_comp_time_ms, "U_PACING_COMP_MIN_TIME_MS", 3.0f)
34 DEBUG_GET_ONCE_BOOL_OPTIONcxx . . $ `src/xrt/auxiliary/util/u_debug.h:120:9`!(live_stats, "U_PACING_LIVE_STATS", falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!)
35
36 // We keep track of this number of frames.
37 #define FRAME_COUNTcxx . . $ `src/xrt/auxiliary/util/u_pacing_compositor_fake.c:37:9`! 8
38
39 /*
40 * Internal helper for keeping track of frame data.
41 */
42 struct framecxx . . $ frame#
43 {
44 //! An arbitrary id that identifies this frame. Set in `pc_predict`.
45 int64_tcxx . . $ int64_t# frame_idcxx . . $ frame#frame_id.;
46
47 //! When should the compositor wake up. Set in `pc_predict`.
48 int64_tcxx . . $ int64_t# predicted_wake_up_time_nscxx . . $ frame#predicted_wake_up_time_ns.;
49
50 //! When should the compositor present the frame.
51 int64_tcxx . . $ int64_t# predicted_present_time_nscxx . . $ frame#predicted_present_time_ns.;
52
53 //! When should the frame be displayed.
54 int64_tcxx . . $ int64_t# predicted_display_time_nscxx . . $ frame#predicted_display_time_ns.;
55
56 //! The period that the pacer used for this frame.
57 int64_tcxx . . $ int64_t# predicted_display_period_nscxx . . $ frame#predicted_display_period_ns.;
58
59 //! When this frame was last used for a prediction. Set in `pc_predict`.
60 int64_tcxx . . $ int64_t# when_predict_nscxx . . $ frame#when_predict_ns.;
61
62 /*!
63 * When the compositor woke up after its equivalent of wait_frame.
64 * Set in `pc_mark_point` with `U_TIMING_POINT_WAKE_UP`.
65 */
66 int64_tcxx . . $ int64_t# when_woke_nscxx . . $ frame#when_woke_ns.;
67
68 /*!
69 * When the compositor began rendering a frame. Set in `pc_mark_point`
70 * with `U_TIMING_POINT_BEGIN`.
71 */
72 int64_tcxx . . $ int64_t# when_began_nscxx . . $ frame#when_began_ns.;
73
74 /*!
75 * When the compositor began submitting the work to the GPU, after
76 * it completed building the command buffers. Set in `pc_mark_point`
77 * with `U_TIMING_POINT_SUBMIT_BEGIN`.
78 */
79 int64_tcxx . . $ int64_t# when_submit_began_nscxx . . $ frame#when_submit_began_ns.;
80
81 /*!
82 * When the compositor completed submitting the work to the GPU. Set in
83 * `pc_mark_point` with `U_TIMING_POINT_SUBMIT_END`.
84 */
85 int64_tcxx . . $ int64_t# when_submit_end_nscxx . . $ frame#when_submit_end_ns.;
86 };
87
88 /*!
89 * A very simple pacer that tries it best to pace a compositor. Used when the
90 * compositor can't get any good or limited feedback from the presentation
91 * engine about timing.
92 */
93 struct fake_timingcxx . . $ fake_timing#
94 {
95 struct u_pacing_compositorcxx . . $ u_pacing_compositor# basecxx . . $ fake_timing#base.;
96
97 /*!
98 * The periodicity of the display.
99 */
100 int64_tcxx . . $ int64_t# frame_period_nscxx . . $ fake_timing#frame_period_ns.;
101
102 /*!
103 * When the last frame was presented, not displayed.
104 */
105 int64_tcxx . . $ int64_t# last_present_time_nscxx . . $ fake_timing#last_present_time_ns.;
106
107 /*!
108 * Very often the present time that we get from the system is only when
109 * the display engine starts scanning out from the buffers we provided,
110 * and not when the pixels turned into photons that the user sees.
111 */
112 struct u_var_draggable_f32cxx . . $ u_var_draggable_f32# present_to_display_offset_mscxx . . $ fake_timing#present_to_display_offset_ms.;
113
114 //! The amount of time that the application needs to render frame.
115 int64_tcxx . . $ int64_t# comp_time_nscxx . . $ fake_timing#comp_time_ns.;
116
117 //! This won't run out, trust me.
118 int64_tcxx . . $ int64_t# frame_id_generatorcxx . . $ fake_timing#frame_id_generator.;
119
120 //! Frames we keep track off.
121 struct framecxx . . $ frame# framescxx . . $ fake_timing#frames.[FRAME_COUNTcxx . . $ `src/xrt/auxiliary/util/u_pacing_compositor_fake.c:37:9`!];
122
123 //! Live stats we keep track off.
124 struct u_live_stats_nscxx . . $ u_live_stats_ns# cpucxx . . $ fake_timing#cpu., drawcxx . . $ fake_timing#draw., submitcxx . . $ fake_timing#submit., gpucxx . . $ fake_timing#gpu., gpu_delaycxx . . $ fake_timing#gpu_delay., total_framecxx . . $ fake_timing#total_frame.;
125 };
126
127
128 /*
129 *
130 * Helper functions.
131 *
132 */
133
134 static inline struct fake_timingcxx . . $ fake_timing# *
135 fake_timingcxx . . $ fake_timing(1d7467c12676fde2).(struct u_pacing_compositorcxx . . $ u_pacing_compositor# *upc)
136 {
137 return (struct fake_timingcxx . . $ fake_timing# *)upc;
138 }
139
140 static struct framecxx . . $ frame# *
141 get_frame_or_nullcxx . . $ get_frame_or_null(4924a1c045e29345).(struct fake_timingcxx . . $ fake_timing# *ft, int64_tcxx . . $ int64_t# frame_id)
142 {
143 uint64_tcxx . . $ uint64_t# index = (uint64_tcxx . . $ uint64_t#)frame_id % FRAME_COUNTcxx . . $ `src/xrt/auxiliary/util/u_pacing_compositor_fake.c:37:9`!;
144 struct framecxx . . $ frame# *f = &ft->framescxx . . $ fake_timing#frames.[index];
145
146 if (f->frame_idcxx . . $ frame#frame_id. == frame_id) {
147 return f;
148 }
149 // Just drop it, doesn't happen during normal operation.
150 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
151 }
152
153 static struct framecxx . . $ frame# *
154 get_new_framecxx . . $ get_new_frame(572cebaceb97b6a6).(struct fake_timingcxx . . $ fake_timing# *ft)
155 {
156 int64_tcxx . . $ int64_t# frame_id = ft->frame_id_generatorcxx . . $ fake_timing#frame_id_generator.++;
157
158 uint64_tcxx . . $ uint64_t# index = (uint64_tcxx . . $ uint64_t#)frame_id % FRAME_COUNTcxx . . $ `src/xrt/auxiliary/util/u_pacing_compositor_fake.c:37:9`!;
159 struct framecxx . . $ frame# *f = &ft->framescxx . . $ fake_timing#frames.[index];
160
161 // We don't care if it has been fully finished.
162 U_ZEROcxx . . $ `src/xrt/auxiliary/util/u_misc.h:68:9`!(f);
163 f->frame_idcxx . . $ frame#frame_id. = frame_id;
164
165 return f;
166 }
167
168 static int64_tcxx . . $ int64_t#
169 predict_next_frame_present_timecxx . . $ predict_next_frame_present_time(28aeea6d36a7def5).(struct fake_timingcxx . . $ fake_timing# *ft, int64_tcxx . . $ int64_t# now_ns)
170 {
171 int64_tcxx . . $ int64_t# time_needed_ns = ft->comp_time_nscxx . . $ fake_timing#comp_time_ns.;
172 int64_tcxx . . $ int64_t# predicted_present_time_ns = ft->last_present_time_nscxx . . $ fake_timing#last_present_time_ns. + ft->frame_period_nscxx . . $ fake_timing#frame_period_ns.;
173
174 while (now_ns + time_needed_ns > predicted_present_time_ns) {
175 predicted_present_time_ns += ft->frame_period_nscxx . . $ fake_timing#frame_period_ns.;
176 }
177
178 return predicted_present_time_ns;
179 }
180
181 static int64_tcxx . . $ int64_t#
182 calc_display_timecxx . . $ calc_display_time(28aeea6d36a7def5).(struct fake_timingcxx . . $ fake_timing# *ft, int64_tcxx . . $ int64_t# present_time_ns)
183 {
184 double offset_ms = ft->present_to_display_offset_mscxx . . $ fake_timing#present_to_display_offset_ms..valcxx . . $ u_var_draggable_f32#val.;
185 int64_tcxx . . $ int64_t# offset_ns = time_ms_f_to_nscxx . . $ time_ms_f_to_ns(a6e4a4c8b00c35a3).(offset_ms);
186 return present_time_ns + offset_ns;
187 }
188
189 static int64_tcxx . . $ int64_t#
190 get_percent_of_timecxx . . $ get_percent_of_time(5e06c073c9468c32).(int64_tcxx . . $ int64_t# time_ns, uint32_tcxx . . $ uint32_t# fraction_percent)
191 {
192 double fraction = (double)fraction_percent / 100.0;
193 return time_s_to_nscxx . . $ time_s_to_ns(a6e4a4c8b00c35a3).(time_ns_to_scxx . . $ time_ns_to_s(66f4a6ec74012662).(time_ns) * fraction);
194 }
195
196 static void
197 print_and_resetcxx . . $ print_and_reset(3ed21f6ff98d290b).(struct fake_timingcxx . . $ fake_timing# *ft)
198 {
199 struct u_pp_sink_stack_onlycxx . . $ u_pp_sink_stack_only# sink;
200 u_pp_delegate_tcxx . . $ u_pp_delegate_t# dg = u_pp_sink_stack_only_initcxx . . $ u_pp_sink_stack_only_init(b0c9b8c1f7039c8d).(&sink);
201
202 u_ppcxx . . $ u_pp(217bc8b61f451940).(dg, "Compositor frame timing:\n");
203 u_ls_ns_print_headercxx . . $ u_ls_ns_print_header(1bf2e36d18a4adde).(dg);
204 u_ppcxx . . $ u_pp(217bc8b61f451940).(dg, "\n");
205 u_ls_ns_print_and_resetcxx . . $ u_ls_ns_print_and_reset(359110bce21c97c3).(&ft->cpucxx . . $ fake_timing#cpu., dg);
206 u_ppcxx . . $ u_pp(217bc8b61f451940).(dg, "\n");
207 u_ls_ns_print_and_resetcxx . . $ u_ls_ns_print_and_reset(359110bce21c97c3).(&ft->drawcxx . . $ fake_timing#draw., dg);
208 u_ppcxx . . $ u_pp(217bc8b61f451940).(dg, "\n");
209 u_ls_ns_print_and_resetcxx . . $ u_ls_ns_print_and_reset(359110bce21c97c3).(&ft->submitcxx . . $ fake_timing#submit., dg);
210 u_ppcxx . . $ u_pp(217bc8b61f451940).(dg, "\n");
211 u_ls_ns_print_and_resetcxx . . $ u_ls_ns_print_and_reset(359110bce21c97c3).(&ft->gpucxx . . $ fake_timing#gpu., dg);
212 u_ppcxx . . $ u_pp(217bc8b61f451940).(dg, "\n");
213 u_ls_ns_print_and_resetcxx . . $ u_ls_ns_print_and_reset(359110bce21c97c3).(&ft->gpu_delaycxx . . $ fake_timing#gpu_delay., dg);
214 u_ppcxx . . $ u_pp(217bc8b61f451940).(dg, "\n");
215 u_ls_ns_print_and_resetcxx . . $ u_ls_ns_print_and_reset(359110bce21c97c3).(&ft->total_framecxx . . $ fake_timing#total_frame., dg);
216
217 U_LOG_IFL_Icxx . . $ `src/xrt/auxiliary/util/u_logging.h:327:9`!(U_LOGGING_INFO, "%s", sink.buffer);
218 }
219
220 static void
221 calc_frame_statscxx . . $ calc_frame_stats(40efa6870372e2aa).(struct fake_timingcxx . . $ fake_timing# *ft, struct framecxx . . $ frame# *f)
222 {
223 if (!debug_get_bool_option_live_statscxx . . $ debug_get_bool_option_live_stats(c9857a73d68e59ba).()) {
224 return;
225 }
226
227 int64_tcxx . . $ int64_t# cpu_ns = f->when_began_nscxx . . $ frame#when_began_ns. - f->when_woke_nscxx . . $ frame#when_woke_ns.;
228 int64_tcxx . . $ int64_t# draw_ns = f->when_submit_began_nscxx . . $ frame#when_submit_began_ns. - f->when_began_nscxx . . $ frame#when_began_ns.;
229 int64_tcxx . . $ int64_t# submit_ns = f->when_submit_end_nscxx . . $ frame#when_submit_end_ns. - f->when_submit_began_nscxx . . $ frame#when_submit_began_ns.;
230
231 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! full = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
232 full |= u_ls_ns_addcxx . . $ u_ls_ns_add(46ca4e0f4a429d1a).(&ft->cpucxx . . $ fake_timing#cpu., cpu_ns);
233 full |= u_ls_ns_addcxx . . $ u_ls_ns_add(46ca4e0f4a429d1a).(&ft->drawcxx . . $ fake_timing#draw., draw_ns);
234 full |= u_ls_ns_addcxx . . $ u_ls_ns_add(46ca4e0f4a429d1a).(&ft->submitcxx . . $ fake_timing#submit., submit_ns);
235
236 if (full) {
237 print_and_resetcxx . . $ print_and_reset(3ed21f6ff98d290b).(ft);
238 }
239 }
240
241 static void
242 calc_gpu_statscxx . . $ calc_gpu_stats(a45966c5a412a19a).(struct fake_timingcxx . . $ fake_timing# *ft, struct framecxx . . $ frame# *f, int64_tcxx . . $ int64_t# gpu_start_ns, int64_tcxx . . $ int64_t# gpu_end_ns)
243 {
244 if (!debug_get_bool_option_live_statscxx . . $ debug_get_bool_option_live_stats(c9857a73d68e59ba).()) {
245 return;
246 }
247
248 int64_tcxx . . $ int64_t# then_ns = f->when_submit_began_nscxx . . $ frame#when_submit_began_ns.;
249 int64_tcxx . . $ int64_t# delay_ns = gpu_start_ns > then_ns ? gpu_start_ns - then_ns : 0;
250 int64_tcxx . . $ int64_t# gpu_ns = gpu_end_ns - gpu_start_ns;
251 int64_tcxx . . $ int64_t# frame_ns = gpu_end_ns - f->when_woke_nscxx . . $ frame#when_woke_ns.;
252
253 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! full = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
254 full |= u_ls_ns_addcxx . . $ u_ls_ns_add(46ca4e0f4a429d1a).(&ft->gpucxx . . $ fake_timing#gpu., gpu_ns);
255 full |= u_ls_ns_addcxx . . $ u_ls_ns_add(46ca4e0f4a429d1a).(&ft->gpu_delaycxx . . $ fake_timing#gpu_delay., delay_ns);
256 full |= u_ls_ns_addcxx . . $ u_ls_ns_add(46ca4e0f4a429d1a).(&ft->total_framecxx . . $ fake_timing#total_frame., frame_ns);
257
258 if (full) {
259 print_and_resetcxx . . $ print_and_reset(3ed21f6ff98d290b).(ft);
260 }
261 }
262
263
264 /*
265 *
266 * Member functions.
267 *
268 */
269
270 static void
271 pc_predictcxx . . $ pc_predict(e744d4acf589aa6d).(struct u_pacing_compositorcxx . . $ u_pacing_compositor# *upc,
272 int64_tcxx . . $ int64_t# now_ns,
273 int64_tcxx . . $ int64_t# *out_frame_id,
274 int64_tcxx . . $ int64_t# *out_wake_up_time_ns,
275 int64_tcxx . . $ int64_t# *out_desired_present_time_ns,
276 int64_tcxx . . $ int64_t# *out_present_slop_ns,
277 int64_tcxx . . $ int64_t# *out_predicted_display_time_ns,
278 int64_tcxx . . $ int64_t# *out_predicted_display_period_ns,
279 int64_tcxx . . $ int64_t# *out_min_display_period_ns)
280 {
281 struct fake_timingcxx . . $ fake_timing# *ft = fake_timingcxx . . $ fake_timing(1d7467c12676fde2).(upc);
282
283 struct framecxx . . $ frame# *f = get_new_framecxx . . $ get_new_frame(572cebaceb97b6a6).(ft);
284
285 int64_tcxx . . $ int64_t# frame_id = f->frame_idcxx . . $ frame#frame_id.;
286 int64_tcxx . . $ int64_t# desired_present_time_ns = predict_next_frame_present_timecxx . . $ predict_next_frame_present_time(28aeea6d36a7def5).(ft, now_ns);
287 int64_tcxx . . $ int64_t# predicted_display_time_ns = calc_display_timecxx . . $ calc_display_time(28aeea6d36a7def5).(ft, desired_present_time_ns);
288
289 int64_tcxx . . $ int64_t# wake_up_time_ns = desired_present_time_ns - ft->comp_time_nscxx . . $ fake_timing#comp_time_ns.;
290 int64_tcxx . . $ int64_t# present_slop_ns = U_TIME_HALF_MS_IN_NScxx . . $ `src/xrt/auxiliary/util/u_time.h:61:9`!;
291 int64_tcxx . . $ int64_t# predicted_display_period_ns = ft->frame_period_nscxx . . $ fake_timing#frame_period_ns.;
292 int64_tcxx . . $ int64_t# min_display_period_ns = ft->frame_period_nscxx . . $ fake_timing#frame_period_ns.;
293
294 // Set the frame info.
295 f->predicted_wake_up_time_nscxx . . $ frame#predicted_wake_up_time_ns. = wake_up_time_ns;
296 f->predicted_present_time_nscxx . . $ frame#predicted_present_time_ns. = desired_present_time_ns;
297 f->predicted_display_time_nscxx . . $ frame#predicted_display_time_ns. = predicted_display_time_ns;
298 f->predicted_display_period_nscxx . . $ frame#predicted_display_period_ns. = predicted_display_period_ns;
299
300 *out_frame_id = frame_id;
301 *out_wake_up_time_ns = wake_up_time_ns;
302 *out_desired_present_time_ns = desired_present_time_ns;
303 *out_present_slop_ns = present_slop_ns;
304 *out_predicted_display_time_ns = predicted_display_time_ns;
305 *out_predicted_display_period_ns = predicted_display_period_ns;
306 *out_min_display_period_ns = min_display_period_ns;
307
308 if (!u_metrics_is_activecxx . . $ u_metrics_is_active(c9857a73d68e59ba).()) {
309 return;
310 }
311
312 struct u_metrics_system_framecxx . . $ u_metrics_system_frame# umsf = {
313 .frame_id = frame_id,
314 .predicted_display_time_ns = predicted_display_time_ns,
315 .predicted_display_period_ns = predicted_display_period_ns,
316 .desired_present_time_ns = desired_present_time_ns,
317 .wake_up_time_ns = wake_up_time_ns,
318 .present_slop_ns = present_slop_ns,
319 };
320
321 u_metrics_write_system_framecxx . . $ u_metrics_write_system_frame(2915cd8fab426ce8).(&umsf);
322 }
323
324 static void
325 pc_mark_pointcxx . . $ pc_mark_point(45471c04d9a39e).(struct u_pacing_compositorcxx . . $ u_pacing_compositor# *upc, enum u_timing_pointcxx . . $ u_timing_point# point, int64_tcxx . . $ int64_t# frame_id, int64_tcxx . . $ int64_t# when_ns)
326 {
327 struct fake_timingcxx . . $ fake_timing# *ft = fake_timingcxx . . $ fake_timing(1d7467c12676fde2).(upc);
328 struct framecxx . . $ frame# *f = get_frame_or_nullcxx . . $ get_frame_or_null(4924a1c045e29345).(ft, frame_id);
329
330 // Just drop info if no frame found.
331 if (f == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
332 return;
333 }
334
335 // To help validate calling code.
336 switch (point) {
337 case U_TIMING_POINT_WAKE_UPcxx . . $ U_TIMING_POINT_WAKE_UP.: f->when_woke_nscxx . . $ frame#when_woke_ns. = when_ns; break;
338 case U_TIMING_POINT_BEGINcxx . . $ U_TIMING_POINT_BEGIN.: f->when_began_nscxx . . $ frame#when_began_ns. = when_ns; break;
339 case U_TIMING_POINT_SUBMIT_BEGINcxx . . $ U_TIMING_POINT_SUBMIT_BEGIN.: f->when_submit_began_nscxx . . $ frame#when_submit_began_ns. = when_ns; break;
340 case U_TIMING_POINT_SUBMIT_ENDcxx . . $ U_TIMING_POINT_SUBMIT_END.:
341 f->when_submit_end_nscxx . . $ frame#when_submit_end_ns. = when_ns;
342 calc_frame_statscxx . . $ calc_frame_stats(40efa6870372e2aa).(ft, f);
343 break;
344 default: assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!);
345 }
346 }
347
348 static void
349 pc_infocxx . . $ pc_info(caeb35eb00003a2c).(struct u_pacing_compositorcxx . . $ u_pacing_compositor# *upc,
350 int64_tcxx . . $ int64_t# frame_id,
351 int64_tcxx . . $ int64_t# desired_present_time_ns,
352 int64_tcxx . . $ int64_t# actual_present_time_ns,
353 int64_tcxx . . $ int64_t# earliest_present_time_ns,
354 int64_tcxx . . $ int64_t# present_margin_ns,
355 int64_tcxx . . $ int64_t# when_ns)
356 {
357 /*
358 * The compositor might call this function because it selected the
359 * fake timing code even tho displaying timing is available.
360 */
361 }
362
363 static void
364 pc_info_gpucxx . . $ pc_info_gpu(c5d2cf95f0c2004f).(
365 struct u_pacing_compositorcxx . . $ u_pacing_compositor# *upc, int64_tcxx . . $ int64_t# frame_id, int64_tcxx . . $ int64_t# gpu_start_ns, int64_tcxx . . $ int64_t# gpu_end_ns, int64_tcxx . . $ int64_t# when_ns)
366 {
367 struct fake_timingcxx . . $ fake_timing# *ft = fake_timingcxx . . $ fake_timing(1d7467c12676fde2).(upc);
368
369 struct framecxx . . $ frame# *f = get_frame_or_nullcxx . . $ get_frame_or_null(4924a1c045e29345).(ft, frame_id);
370 if (f != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
371 calc_gpu_statscxx . . $ calc_gpu_stats(a45966c5a412a19a).(ft, f, gpu_start_ns, gpu_end_ns);
372 }
373
374 if (u_metrics_is_activecxx . . $ u_metrics_is_active(c9857a73d68e59ba).()) {
375 struct u_metrics_system_gpu_infocxx . . $ u_metrics_system_gpu_info# umgi = {
376 .frame_id = frame_id,
377 .gpu_start_ns = gpu_start_ns,
378 .gpu_end_ns = gpu_end_ns,
379 .when_ns = when_ns,
380 };
381
382 u_metrics_write_system_gpu_infocxx . . $ u_metrics_write_system_gpu_info(1cd6169f18652288).(&umgi);
383 }
384
385 #ifdef U_TRACE_PERCETTO // Uses Percetto specific things.
386 if (U_TRACE_CATEGORY_IS_ENABLED(timing)) {
387 #define TE_BEG(TRACK, TIME, NAME) U_TRACE_EVENT_BEGIN_ON_TRACK_DATA(timing, TRACK, TIME, NAME, PERCETTO_I(frame_id))
388 #define TE_END(TRACK, TIME) U_TRACE_EVENT_END_ON_TRACK(timing, TRACK, TIME)
389
390 TE_BEG(pc_gpu, gpu_start_ns, "gpu");
391 TE_END(pc_gpu, gpu_end_ns);
392
393 #undef TE_BEG
394 #undef TE_END
395 }
396 #endif
397
398 #ifdef U_TRACE_TRACY
399 int64_t diff_ns = gpu_end_ns - gpu_start_ns;
400 TracyCPlot("Compositor GPU(ms)", time_ns_to_ms_f(diff_ns));
401 #endif
402 }
403
404 static void
405 pc_update_vblank_from_display_controlcxx . . $ pc_update_vblank_from_display_control(25c1bfd5273daef7).(struct u_pacing_compositorcxx . . $ u_pacing_compositor# *upc, int64_tcxx . . $ int64_t# last_vblank_ns)
406 {
407 struct fake_timingcxx . . $ fake_timing# *ft = fake_timingcxx . . $ fake_timing(1d7467c12676fde2).(upc);
408
409 // Use the last vblank time to sync to the output.
410 ft->last_present_time_nscxx . . $ fake_timing#last_present_time_ns. = last_vblank_ns;
411 }
412
413 static void
414 pc_update_present_offsetcxx . . $ pc_update_present_offset(d658e2b83fe2da01).(struct u_pacing_compositorcxx . . $ u_pacing_compositor# *upc, int64_tcxx . . $ int64_t# frame_id, int64_tcxx . . $ int64_t# present_to_display_offset_ns)
415 {
416 struct fake_timingcxx . . $ fake_timing# *ft = fake_timingcxx . . $ fake_timing(1d7467c12676fde2).(upc);
417
418 // not associating with frame IDs right now.
419 (void)frame_id;
420
421 double offset_ms = time_ns_to_ms_fcxx . . $ time_ns_to_ms_f(66f4a6ec74012662).(present_to_display_offset_ns);
422
423 ft->present_to_display_offset_mscxx . . $ fake_timing#present_to_display_offset_ms..valcxx . . $ u_var_draggable_f32#val. = offset_ms;
424 }
425
426 static void
427 pc_destroycxx . . $ pc_destroy(90801425daa917af).(struct u_pacing_compositorcxx . . $ u_pacing_compositor# *upc)
428 {
429 struct fake_timingcxx . . $ fake_timing# *ft = fake_timingcxx . . $ fake_timing(1d7467c12676fde2).(upc);
430
431 u_var_remove_rootcxx . . $ u_var_remove_root(5d22bdacc48458e8).(ft);
432
433 freecxx . . $ free(5d22bdacc48458e8).(ft);
434 }
435
436
437 /*
438 *
439 * 'Exported' functions.
440 *
441 */
442
443 xrt_result_tcxx . . $ xrt_result_t#
444 u_pc_fake_createcxx . . $ u_pc_fake_create(f6bbaeeaf976eaed).(int64_tcxx . . $ int64_t# estimated_frame_period_ns, int64_tcxx . . $ int64_t# now_ns, struct u_pacing_compositorcxx . . $ u_pacing_compositor# **out_upc)
445 {
446 struct fake_timingcxx . . $ fake_timing# *ft = U_TYPED_CALLOCcxx . . $ `src/xrt/auxiliary/util/u_misc.h:47:9`!(struct fake_timing);
447 ft->basecxx . . $ fake_timing#base..predictcxx . . $ u_pacing_compositor#predict. = pc_predictcxx . . $ pc_predict(e744d4acf589aa6d).;
448 ft->basecxx . . $ fake_timing#base..mark_pointcxx . . $ u_pacing_compositor#mark_point. = pc_mark_pointcxx . . $ pc_mark_point(45471c04d9a39e).;
449 ft->basecxx . . $ fake_timing#base..infocxx . . $ u_pacing_compositor#info. = pc_infocxx . . $ pc_info(caeb35eb00003a2c).;
450 ft->basecxx . . $ fake_timing#base..info_gpucxx . . $ u_pacing_compositor#info_gpu. = pc_info_gpucxx . . $ pc_info_gpu(c5d2cf95f0c2004f).;
451 ft->basecxx . . $ fake_timing#base..update_vblank_from_display_controlcxx . . $ u_pacing_compositor#update_vblank_from_display_control. = pc_update_vblank_from_display_controlcxx . . $ pc_update_vblank_from_display_control(25c1bfd5273daef7).;
452 ft->basecxx . . $ fake_timing#base..update_present_offsetcxx . . $ u_pacing_compositor#update_present_offset. = pc_update_present_offsetcxx . . $ pc_update_present_offset(d658e2b83fe2da01).;
453 ft->basecxx . . $ fake_timing#base..destroycxx . . $ u_pacing_compositor#destroy. = pc_destroycxx . . $ pc_destroy(90801425daa917af).;
454 ft->frame_period_nscxx . . $ fake_timing#frame_period_ns. = estimated_frame_period_ns;
455
456 snprintfcxx . . $ snprintf(ea502d73e74c754c).(ft->cpucxx . . $ fake_timing#cpu..namecxx . . $ u_live_stats_ns#name., ARRAY_SIZEcxx . . $ `src/xrt/include/xrt/xrt_compiler.h:30:9`!(ft->cpu.name), "cpu");
457 snprintfcxx . . $ snprintf(ea502d73e74c754c).(ft->drawcxx . . $ fake_timing#draw..namecxx . . $ u_live_stats_ns#name., ARRAY_SIZEcxx . . $ `src/xrt/include/xrt/xrt_compiler.h:30:9`!(ft->draw.name), "draw");
458 snprintfcxx . . $ snprintf(ea502d73e74c754c).(ft->submitcxx . . $ fake_timing#submit..namecxx . . $ u_live_stats_ns#name., ARRAY_SIZEcxx . . $ `src/xrt/include/xrt/xrt_compiler.h:30:9`!(ft->submit.name), "submit");
459 snprintfcxx . . $ snprintf(ea502d73e74c754c).(ft->gpucxx . . $ fake_timing#gpu..namecxx . . $ u_live_stats_ns#name., ARRAY_SIZEcxx . . $ `src/xrt/include/xrt/xrt_compiler.h:30:9`!(ft->gpu.name), "gpu");
460 snprintfcxx . . $ snprintf(ea502d73e74c754c).(ft->gpu_delaycxx . . $ fake_timing#gpu_delay..namecxx . . $ u_live_stats_ns#name., ARRAY_SIZEcxx . . $ `src/xrt/include/xrt/xrt_compiler.h:30:9`!(ft->gpu_delay.name), "gpu_delay");
461 snprintfcxx . . $ snprintf(ea502d73e74c754c).(ft->total_framecxx . . $ fake_timing#total_frame..namecxx . . $ u_live_stats_ns#name., ARRAY_SIZEcxx . . $ `src/xrt/include/xrt/xrt_compiler.h:30:9`!(ft->total_frame.name), "total_frame");
462
463 // To make sure the code can start from a non-zero frame id.
464 ft->frame_id_generatorcxx . . $ fake_timing#frame_id_generator. = 5;
465
466 // An arbitrary guess, that happens to be based on Index.
467 float present_to_display_offset_ms = debug_get_float_option_present_to_display_offset_mscxx . . $ debug_get_float_option_present_to_display_offset_ms(9b8c9e39889c762c).();
468
469 // Present to display offset, aka vblank to pixel turning into photons.
470 ft->present_to_display_offset_mscxx . . $ fake_timing#present_to_display_offset_ms. = (struct u_var_draggable_f32cxx . . $ u_var_draggable_f32#){
471 .val = present_to_display_offset_ms,
472 .min = 1.0, // A lot of things assumes this is not negative.
473 .step = 0.1,
474 .max = +40.0,
475 };
476
477 // 20% of the frame time.
478 ft->comp_time_nscxx . . $ fake_timing#comp_time_ns. = get_percent_of_timecxx . . $ get_percent_of_time(5e06c073c9468c32).(estimated_frame_period_ns, 20);
479
480 // Or at least a certain amount of time.
481 float min_comp_time_ms_f = debug_get_float_option_min_comp_time_mscxx . . $ debug_get_float_option_min_comp_time_ms(9b8c9e39889c762c).();
482 int64_tcxx . . $ int64_t# min_comp_time_ns = time_ms_f_to_nscxx . . $ time_ms_f_to_ns(a6e4a4c8b00c35a3).(min_comp_time_ms_f);
483
484 if (ft->comp_time_nscxx . . $ fake_timing#comp_time_ns. < min_comp_time_ns) {
485 ft->comp_time_nscxx . . $ fake_timing#comp_time_ns. = min_comp_time_ns;
486 }
487
488 // Make the next present time be in the future.
489 ft->last_present_time_nscxx . . $ fake_timing#last_present_time_ns. = now_ns + U_TIME_1MS_IN_NScxx . . $ `src/xrt/auxiliary/util/u_time.h:54:9`! * 50;
490
491 // U variable tracking.
492 u_var_add_rootcxx . . $ u_var_add_root(4edd542771b76ca).(ft, "Compositor timing info", truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!);
493 u_var_add_draggable_f32cxx . . $ u_var_add_draggable_f32(effe2207bac9d9d0).(ft, &ft->present_to_display_offset_mscxx . . $ fake_timing#present_to_display_offset_ms., "Present to display offset(ms)");
494 u_var_add_ro_i64cxx . . $ u_var_add_ro_i64(ac4ff4e3705d1bc3).(ft, &ft->frame_period_nscxx . . $ fake_timing#frame_period_ns., "Frame period(ns)");
495 u_var_add_ro_i64cxx . . $ u_var_add_ro_i64(ac4ff4e3705d1bc3).(ft, &ft->comp_time_nscxx . . $ fake_timing#comp_time_ns., "Compositor time(ns)");
496 u_var_add_ro_i64cxx . . $ u_var_add_ro_i64(ac4ff4e3705d1bc3).(ft, &ft->last_present_time_nscxx . . $ fake_timing#last_present_time_ns., "Last present time(ns)");
497
498 // Return value.
499 *out_upc = &ft->basecxx . . $ fake_timing#base.;
500
501 U_LOG_Icxx . . $ `src/xrt/auxiliary/util/u_logging.h:298:9`!("Created fake timing");
502
503 return XRT_SUCCESScxx . . $ XRT_SUCCESS.;
504 }