The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

u/pacing: Add variable tracking to fake pacer

+33 -6
+33 -6
src/xrt/auxiliary/util/u_pacing_compositor_fake.c
··· 1 - // Copyright 2020-2021, Collabora, Ltd. 1 + // Copyright 2020-2023, Collabora, Ltd. 2 2 // SPDX-License-Identifier: BSL-1.0 3 3 /*! 4 4 * @file ··· 9 9 10 10 #include "os/os_time.h" 11 11 12 + #include "util/u_var.h" 12 13 #include "util/u_time.h" 13 14 #include "util/u_misc.h" 14 15 #include "util/u_debug.h" ··· 48 49 * the display engine starts scanning out from the buffers we provided, 49 50 * and not when the pixels turned into photons that the user sees. 50 51 */ 51 - uint64_t present_to_display_offset_ns; 52 + struct u_var_draggable_f32 present_to_display_offset_ms; 52 53 53 54 // The amount of time that the application needs to render frame. 54 55 uint64_t comp_time_ns; ··· 83 84 } 84 85 85 86 static uint64_t 87 + calc_display_time(struct fake_timing *ft, uint64_t present_time_ns) 88 + { 89 + double offset_ms = ft->present_to_display_offset_ms.val; 90 + uint64_t offset_ns = (uint64_t)(offset_ms * (double)U_TIME_1MS_IN_NS); 91 + return present_time_ns + offset_ns; 92 + } 93 + 94 + static uint64_t 86 95 get_percent_of_time(uint64_t time_ns, uint32_t fraction_percent) 87 96 { 88 97 double fraction = (double)fraction_percent / 100.0; ··· 111 120 112 121 int64_t frame_id = ft->frame_id_generator++; 113 122 uint64_t desired_present_time_ns = predict_next_frame_present_time(ft, now_ns); 114 - uint64_t predicted_display_time_ns = desired_present_time_ns + ft->present_to_display_offset_ns; 123 + uint64_t predicted_display_time_ns = calc_display_time(ft, desired_present_time_ns); 124 + 115 125 uint64_t wake_up_time_ns = desired_present_time_ns - ft->comp_time_ns; 116 126 uint64_t present_slop_ns = U_TIME_HALF_MS_IN_NS; 117 127 uint64_t predicted_display_period_ns = ft->frame_period_ns; ··· 219 229 // not associating with frame IDs right now. 220 230 (void)frame_id; 221 231 222 - ft->present_to_display_offset_ns = present_to_display_offset_ns; 232 + double offset_ms = (double)present_to_display_offset_ns / (double)U_TIME_1MS_IN_NS; 233 + 234 + ft->present_to_display_offset_ms.val = offset_ms; 223 235 } 224 236 225 237 static void 226 238 pc_destroy(struct u_pacing_compositor *upc) 227 239 { 228 240 struct fake_timing *ft = fake_timing(upc); 241 + 242 + u_var_remove_root(ft); 243 + 229 244 free(ft); 230 245 } 231 246 ··· 253 268 // To make sure the code can start from a non-zero frame id. 254 269 ft->frame_id_generator = 5; 255 270 256 - // An arbitrary guess. 257 - ft->present_to_display_offset_ns = U_TIME_1MS_IN_NS * 4; 271 + // Present to display offset, aka vblank to pixel turning into photons. 272 + ft->present_to_display_offset_ms = (struct u_var_draggable_f32){ 273 + .val = 4.0, // An arbitrary guess, that happens to be based on Index. 274 + .min = 1.0, // A lot of things assumes this is not negative. 275 + .step = 0.1, 276 + .max = +40.0, 277 + }; 258 278 259 279 // 20% of the frame time. 260 280 ft->comp_time_ns = get_percent_of_time(estimated_frame_period_ns, 20); ··· 266 286 267 287 // Make the next present time be in the future. 268 288 ft->last_present_time_ns = now_ns + U_TIME_1MS_IN_NS * 50; 289 + 290 + // U variable tracking. 291 + u_var_add_root(ft, "Compositor timing info", true); 292 + u_var_add_draggable_f32(ft, &ft->present_to_display_offset_ms, "Present to display offset(ms)"); 293 + u_var_add_ro_u64(ft, &ft->frame_period_ns, "Frame period(ns)"); 294 + u_var_add_ro_u64(ft, &ft->comp_time_ns, "Compositor time(ns)"); 295 + u_var_add_ro_u64(ft, &ft->last_present_time_ns, "Last present time(ns)"); 269 296 270 297 // Return value. 271 298 *out_upc = &ft->base;