Skip to content

Commit 8d15eb5

Browse files
committed
vulkan_sdl3: use common func for FPS pretty printout
A common way would be to use generic FPS indicator. But a slight problem is that _putf return value isn't entirely reliable for this module, since the frame may be dropped later doe to insufficient performance. Because of the above, do not use the generic indicator, at least for now. But use the common function to make the output "prettier" (bold/color and if not performing well also use a color for FPS).
1 parent 2169772 commit 8d15eb5

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

src/video_display.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,26 @@ struct video_frame *display_get_frame(struct display *d)
345345
}
346346
}
347347

348+
/**
349+
* print display FPS
350+
*
351+
* Usually called from display_frame_helper for displays that use generic FPS
352+
* indicator but externally linked for those that do not, like vulkan_sdl3.
353+
*/
354+
void
355+
display_print_fps(const char *prefix, double seconds, int frames,
356+
double nominal_fps)
357+
{
358+
const double fps = frames / seconds;
359+
const char *const fps_col = get_stat_color(fps / nominal_fps);
360+
361+
log_msg(LOG_LEVEL_INFO,
362+
TERM_BOLD TERM_FG_MAGENTA "%s" TERM_RESET
363+
"%d frames in %g seconds = " TERM_BOLD
364+
"%s%g FPS" TERM_RESET "\n",
365+
prefix, frames, seconds, fps_col, fps);
366+
}
367+
348368
static bool display_frame_helper(struct display *d, struct video_frame *frame, long long timeout_ns)
349369
{
350370
enum {
@@ -364,15 +384,9 @@ static bool display_frame_helper(struct display *d, struct video_frame *frame, l
364384
long long seconds_ns = t - d->t0;
365385
if (seconds_ns > 5 * NS_IN_SEC) {
366386
const double seconds = (double) seconds_ns / NS_IN_SEC;
367-
const double fps = d->frames / seconds;
368-
const char *const fps_col = get_stat_color(fps / frame_fps);
369-
370-
log_msg(LOG_LEVEL_INFO,
371-
TERM_BOLD TERM_FG_MAGENTA
372-
"%s" TERM_RESET "%d frames in %g seconds = " TERM_BOLD
373-
"%s%g FPS" TERM_RESET "\n",
374-
d->funcs->generic_fps_indicator_prefix, d->frames,
375-
seconds, fps_col, fps);
387+
display_print_fps(d->funcs->generic_fps_indicator_prefix,
388+
seconds, d->frames, frame_fps);
389+
376390
d->frames = 0;
377391
d->t0 = t;
378392
}

src/video_display.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @ingroup display
1414
*/
1515
/* Copyright (c) 2001-2003 University of Southern California
16-
* Copyright (c) 2005-2023 CESNET z.s.p.o.
16+
* Copyright (c) 2005-2025 CESNET, zájmové sdružení právnických osob
1717
*
1818
* Redistribution and use in source and binary forms, with or without
1919
* modification, is permitted provided that the following conditions
@@ -211,6 +211,9 @@ bool display_reconfigure_audio(struct display *d, int quant_
211211
struct video_frame *get_splashscreen(void);
212212
const char *get_audio_conn_flag_name(int audio_init_flag);
213213

214+
void display_print_fps(const char *prefix, double seconds, int frames,
215+
double nominal_fps);
216+
214217
#ifdef __cplusplus
215218
}
216219
#endif // __cplusplus

src/video_display/vulkan/vulkan_sdl3.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,9 @@ void display_vulkan_run(void* state) {
394394
auto now = chrono::steady_clock::now();
395395
double seconds = chrono::duration<double>{ now - s->time }.count();
396396
if (seconds > 5) {
397-
double fps = s->frames / seconds;
398-
log_msg(LOG_LEVEL_INFO, MOD_NAME "%llu frames in %g seconds = %g FPS\n",
399-
static_cast<long long unsigned>(s->frames), seconds, fps);
397+
display_print_fps(MOD_NAME, seconds, (int) s->frames,
398+
s->current_desc.fps);
399+
400400
s->time = now;
401401
s->frames = 0;
402402
}

0 commit comments

Comments
 (0)