gallium/hud: add frametime graph (v2)

Thanks for your comment. This version has an additional boolean in the
fps_info struct to distinguish between fps and frame time calculation.
The struct is initialised in the respecting install functions for this
purpose.

Signed-off-by: Marek Olšák <marek.olsak@amd.com>
This commit is contained in:
Matthias Groß 2018-05-15 23:09:05 +02:00 committed by Marek Olšák
parent f3521ce2c4
commit 71892fbe19
3 changed files with 38 additions and 1 deletions

View file

@ -1247,6 +1247,9 @@ hud_parse_env_var(struct hud_context *hud, struct pipe_screen *screen,
if (strcmp(name, "fps") == 0) {
hud_fps_graph_install(pane);
}
else if (strcmp(name, "frametime") == 0) {
hud_frametime_graph_install(pane);
}
else if (strcmp(name, "cpu") == 0) {
hud_cpu_graph_install(pane, ALL_CPUS);
}
@ -1557,6 +1560,7 @@ print_help(struct pipe_screen *screen)
puts("");
puts(" Available names:");
puts(" fps");
puts(" frametime");
puts(" cpu");
for (i = 0; i < num_cpus; i++)

View file

@ -33,6 +33,7 @@
#include "util/u_memory.h"
struct fps_info {
boolean frametime;
int frames;
uint64_t last_time;
};
@ -46,7 +47,12 @@ query_fps(struct hud_graph *gr, struct pipe_context *pipe)
info->frames++;
if (info->last_time) {
if (info->last_time + gr->pane->period <= now) {
if (info->frametime) {
double frametime = ((double)now - (double)info->last_time) / 1000.0;
hud_graph_add_value(gr, frametime);
info->last_time = now;
}
else if (info->last_time + gr->pane->period <= now) {
double fps = ((uint64_t)info->frames) * 1000000 /
(double)(now - info->last_time);
info->frames = 0;
@ -80,6 +86,8 @@ hud_fps_graph_install(struct hud_pane *pane)
FREE(gr);
return;
}
struct fps_info *info = gr->query_data;
info->frametime = false;
gr->query_new_value = query_fps;
@ -90,3 +98,27 @@ hud_fps_graph_install(struct hud_pane *pane)
hud_pane_add_graph(pane, gr);
}
void
hud_frametime_graph_install(struct hud_pane *pane)
{
struct hud_graph *gr = CALLOC_STRUCT(hud_graph);
if (!gr)
return;
strcpy(gr->name, "frametime (ms)");
gr->query_data = CALLOC_STRUCT(fps_info);
if (!gr->query_data) {
FREE(gr);
return;
}
struct fps_info *info = gr->query_data;
info->frametime = true;
gr->query_new_value = query_fps;
gr->free_query_data = free_query_data;
hud_pane_add_graph(pane, gr);
}

View file

@ -157,6 +157,7 @@ struct hud_batch_query_context;
int hud_get_num_cpus(void);
void hud_fps_graph_install(struct hud_pane *pane);
void hud_frametime_graph_install(struct hud_pane *pane);
void hud_cpu_graph_install(struct hud_pane *pane, unsigned cpu_index);
void hud_thread_busy_install(struct hud_pane *pane, const char *name, bool main);
void hud_thread_counter_install(struct hud_pane *pane, const char *name,