Discussion:
[PATCH 1/1] gallium/hud: use double values for all graphs
(too old to reply)
Christoph Haag
2017-06-17 14:57:37 UTC
Permalink
Raw Message
This specifically helps the fps graph. It calculates the fps like this:
(uint64_t)info->frames * 1000000 / (double)(now - info->last_time);
The timings when query_new_value() are called will vary, so fps values of
e.g. 59.9 fps will be truncated to 59 fps.

Rounding the value before casting to integer improves the fps graph, but
it may be useful to inspect fps variations more closely by increasing the
width and height of the graphs.

Signed-off-by: Christoph Haag <haagch+***@frickel.club>
---
src/gallium/auxiliary/hud/hud_context.c | 6 +++---
src/gallium/auxiliary/hud/hud_fps.c | 4 ++--
src/gallium/auxiliary/hud/hud_private.h | 4 ++--
3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
index cb7ed44659..22968aef10 100644
--- a/src/gallium/auxiliary/hud/hud_context.c
+++ b/src/gallium/auxiliary/hud/hud_context.c
@@ -250,7 +250,7 @@ hud_draw_string(struct hud_context *hud, unsigned x, unsigned y,
}

static void
-number_to_human_readable(uint64_t num, enum pipe_driver_query_type type,
+number_to_human_readable(double num, enum pipe_driver_query_type type,
char *out)
{
static const char *byte_units[] =
@@ -905,13 +905,13 @@ hud_pane_add_graph(struct hud_pane *pane, struct hud_graph *gr)
}

void
-hud_graph_add_value(struct hud_graph *gr, uint64_t value)
+hud_graph_add_value(struct hud_graph *gr, double value)
{
gr->current_value = value;
value = value > gr->pane->ceiling ? gr->pane->ceiling : value;

if (gr->fd)
- fprintf(gr->fd, "%" PRIu64 "\n", value);
+ fprintf(gr->fd, "%f\n", value);

if (gr->index == gr->pane->max_num_vertices) {
gr->vertices[0] = 0;
diff --git a/src/gallium/auxiliary/hud/hud_fps.c b/src/gallium/auxiliary/hud/hud_fps.c
index a360bc2ed0..8aa7a665a3 100644
--- a/src/gallium/auxiliary/hud/hud_fps.c
+++ b/src/gallium/auxiliary/hud/hud_fps.c
@@ -47,12 +47,12 @@ query_fps(struct hud_graph *gr)

if (info->last_time) {
if (info->last_time + gr->pane->period <= now) {
- double fps = (uint64_t)info->frames * 1000000 /
+ double fps = ((uint64_t)info->frames) * 1000000 /
(double)(now - info->last_time);
info->frames = 0;
info->last_time = now;

- hud_graph_add_value(gr, (uint64_t) fps);
+ hud_graph_add_value(gr, fps);
}
}
else {
diff --git a/src/gallium/auxiliary/hud/hud_private.h b/src/gallium/auxiliary/hud/hud_private.h
index bbc5ec70c8..2cc00dcc6f 100644
--- a/src/gallium/auxiliary/hud/hud_private.h
+++ b/src/gallium/auxiliary/hud/hud_private.h
@@ -48,7 +48,7 @@ struct hud_graph {
/* mutable variables */
unsigned num_vertices;
unsigned index; /* vertex index being updated */
- uint64_t current_value;
+ double current_value;
FILE *fd;
};

@@ -82,7 +82,7 @@ struct hud_pane {
/* core */
void hud_pane_add_graph(struct hud_pane *pane, struct hud_graph *gr);
void hud_pane_set_max_value(struct hud_pane *pane, uint64_t value);
-void hud_graph_add_value(struct hud_graph *gr, uint64_t value);
+void hud_graph_add_value(struct hud_graph *gr, double value);

/* graphs/queries */
struct hud_batch_query_context;
--
2.13.1
Marek Olšák
2017-06-19 19:38:13 UTC
Permalink
Raw Message
On Sat, Jun 17, 2017 at 4:57 PM, Christoph Haag
Post by Christoph Haag
(uint64_t)info->frames * 1000000 / (double)(now - info->last_time);
The timings when query_new_value() are called will vary, so fps values of
e.g. 59.9 fps will be truncated to 59 fps.
Rounding the value before casting to integer improves the fps graph, but
it may be useful to inspect fps variations more closely by increasing the
width and height of the graphs.
---
src/gallium/auxiliary/hud/hud_context.c | 6 +++---
src/gallium/auxiliary/hud/hud_fps.c | 4 ++--
src/gallium/auxiliary/hud/hud_private.h | 4 ++--
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
index cb7ed44659..22968aef10 100644
--- a/src/gallium/auxiliary/hud/hud_context.c
+++ b/src/gallium/auxiliary/hud/hud_context.c
@@ -250,7 +250,7 @@ hud_draw_string(struct hud_context *hud, unsigned x, unsigned y,
}
static void
-number_to_human_readable(uint64_t num, enum pipe_driver_query_type type,
+number_to_human_readable(double num, enum pipe_driver_query_type type,
char *out)
{
static const char *byte_units[] =
@@ -905,13 +905,13 @@ hud_pane_add_graph(struct hud_pane *pane, struct hud_graph *gr)
}
void
-hud_graph_add_value(struct hud_graph *gr, uint64_t value)
+hud_graph_add_value(struct hud_graph *gr, double value)
{
gr->current_value = value;
value = value > gr->pane->ceiling ? gr->pane->ceiling : value;
if (gr->fd)
- fprintf(gr->fd, "%" PRIu64 "\n", value);
+ fprintf(gr->fd, "%f\n", value);
if (gr->index == gr->pane->max_num_vertices) {
gr->vertices[0] = 0;
diff --git a/src/gallium/auxiliary/hud/hud_fps.c b/src/gallium/auxiliary/hud/hud_fps.c
index a360bc2ed0..8aa7a665a3 100644
--- a/src/gallium/auxiliary/hud/hud_fps.c
+++ b/src/gallium/auxiliary/hud/hud_fps.c
@@ -47,12 +47,12 @@ query_fps(struct hud_graph *gr)
if (info->last_time) {
if (info->last_time + gr->pane->period <= now) {
- double fps = (uint64_t)info->frames * 1000000 /
+ double fps = ((uint64_t)info->frames) * 1000000 /
The added parentheses are unnecessary.

The patch is OK with me.

Marek
Christoph Haag
2017-07-14 07:59:38 UTC
Permalink
Raw Message
The fps graph for example calculates the fps as double with small
variations based on when query_new_value() is called, which causes
many values to be truncated on the cast to uint64_t.

The HUD internally stores the values as double, so just use double
everywhere instead of fixing this with rounding. Using doubles also
allows the hud to show small variations instead of being clamped to
discrete values.

v2: Don't print decimals in the dump file when not necessary
Signed-off-by: Christoph Haag <haagch+***@frickel.club>
---
src/gallium/auxiliary/hud/hud_context.c | 14 ++++++++++----
src/gallium/auxiliary/hud/hud_fps.c | 4 ++--
src/gallium/auxiliary/hud/hud_private.h | 4 ++--
3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
index 8172313605..2deb48d18e 100644
--- a/src/gallium/auxiliary/hud/hud_context.c
+++ b/src/gallium/auxiliary/hud/hud_context.c
@@ -204,7 +204,7 @@ hud_draw_string(struct hud_context *hud, unsigned x, unsigned y,
}

static void
-number_to_human_readable(uint64_t num, enum pipe_driver_query_type type,
+number_to_human_readable(double num, enum pipe_driver_query_type type,
char *out)
{
static const char *byte_units[] =
@@ -861,13 +861,19 @@ hud_pane_add_graph(struct hud_pane *pane, struct hud_graph *gr)
}

void
-hud_graph_add_value(struct hud_graph *gr, uint64_t value)
+hud_graph_add_value(struct hud_graph *gr, double value)
{
gr->current_value = value;
value = value > gr->pane->ceiling ? gr->pane->ceiling : value;

- if (gr->fd)
- fprintf(gr->fd, "%" PRIu64 "\n", value);
+ if (gr->fd) {
+ if (fabs(value - lround(value)) > FLT_EPSILON) {
+ fprintf(gr->fd, "%f\n", value);
+ }
+ else {
+ fprintf(gr->fd, "%" PRIu64 "\n", (uint64_t) lround(value));
+ }
+ }

if (gr->index == gr->pane->max_num_vertices) {
gr->vertices[0] = 0;
diff --git a/src/gallium/auxiliary/hud/hud_fps.c b/src/gallium/auxiliary/hud/hud_fps.c
index a360bc2ed0..8aa7a665a3 100644
--- a/src/gallium/auxiliary/hud/hud_fps.c
+++ b/src/gallium/auxiliary/hud/hud_fps.c
@@ -47,12 +47,12 @@ query_fps(struct hud_graph *gr)

if (info->last_time) {
if (info->last_time + gr->pane->period <= now) {
- double fps = (uint64_t)info->frames * 1000000 /
+ double fps = ((uint64_t)info->frames) * 1000000 /
(double)(now - info->last_time);
info->frames = 0;
info->last_time = now;

- hud_graph_add_value(gr, (uint64_t) fps);
+ hud_graph_add_value(gr, fps);
}
}
else {
diff --git a/src/gallium/auxiliary/hud/hud_private.h b/src/gallium/auxiliary/hud/hud_private.h
index 2b1717d2c4..65baa8aa7e 100644
--- a/src/gallium/auxiliary/hud/hud_private.h
+++ b/src/gallium/auxiliary/hud/hud_private.h
@@ -104,7 +104,7 @@ struct hud_graph {
/* mutable variables */
unsigned num_vertices;
unsigned index; /* vertex index being updated */
- uint64_t current_value;
+ double current_value;
FILE *fd;
};

@@ -139,7 +139,7 @@ struct hud_pane {
/* core */
void hud_pane_add_graph(struct hud_pane *pane, struct hud_graph *gr);
void hud_pane_set_max_value(struct hud_pane *pane, uint64_t value);
-void hud_graph_add_value(struct hud_graph *gr, uint64_t value);
+void hud_graph_add_value(struct hud_graph *gr, double value);

/* graphs/queries */
struct hud_batch_query_context;
--
2.13.3
Marek Olšák
2017-07-14 15:36:42 UTC
Permalink
Raw Message
Pushed, thanks!

Marek

On Fri, Jul 14, 2017 at 9:59 AM, Christoph Haag
Post by Christoph Haag
The fps graph for example calculates the fps as double with small
variations based on when query_new_value() is called, which causes
many values to be truncated on the cast to uint64_t.
The HUD internally stores the values as double, so just use double
everywhere instead of fixing this with rounding. Using doubles also
allows the hud to show small variations instead of being clamped to
discrete values.
v2: Don't print decimals in the dump file when not necessary
---
src/gallium/auxiliary/hud/hud_context.c | 14 ++++++++++----
src/gallium/auxiliary/hud/hud_fps.c | 4 ++--
src/gallium/auxiliary/hud/hud_private.h | 4 ++--
3 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
index 8172313605..2deb48d18e 100644
--- a/src/gallium/auxiliary/hud/hud_context.c
+++ b/src/gallium/auxiliary/hud/hud_context.c
@@ -204,7 +204,7 @@ hud_draw_string(struct hud_context *hud, unsigned x, unsigned y,
}
static void
-number_to_human_readable(uint64_t num, enum pipe_driver_query_type type,
+number_to_human_readable(double num, enum pipe_driver_query_type type,
char *out)
{
static const char *byte_units[] =
@@ -861,13 +861,19 @@ hud_pane_add_graph(struct hud_pane *pane, struct hud_graph *gr)
}
void
-hud_graph_add_value(struct hud_graph *gr, uint64_t value)
+hud_graph_add_value(struct hud_graph *gr, double value)
{
gr->current_value = value;
value = value > gr->pane->ceiling ? gr->pane->ceiling : value;
- if (gr->fd)
- fprintf(gr->fd, "%" PRIu64 "\n", value);
+ if (gr->fd) {
+ if (fabs(value - lround(value)) > FLT_EPSILON) {
+ fprintf(gr->fd, "%f\n", value);
+ }
+ else {
+ fprintf(gr->fd, "%" PRIu64 "\n", (uint64_t) lround(value));
+ }
+ }
if (gr->index == gr->pane->max_num_vertices) {
gr->vertices[0] = 0;
diff --git a/src/gallium/auxiliary/hud/hud_fps.c b/src/gallium/auxiliary/hud/hud_fps.c
index a360bc2ed0..8aa7a665a3 100644
--- a/src/gallium/auxiliary/hud/hud_fps.c
+++ b/src/gallium/auxiliary/hud/hud_fps.c
@@ -47,12 +47,12 @@ query_fps(struct hud_graph *gr)
if (info->last_time) {
if (info->last_time + gr->pane->period <= now) {
- double fps = (uint64_t)info->frames * 1000000 /
+ double fps = ((uint64_t)info->frames) * 1000000 /
(double)(now - info->last_time);
info->frames = 0;
info->last_time = now;
- hud_graph_add_value(gr, (uint64_t) fps);
+ hud_graph_add_value(gr, fps);
}
}
else {
diff --git a/src/gallium/auxiliary/hud/hud_private.h b/src/gallium/auxiliary/hud/hud_private.h
index 2b1717d2c4..65baa8aa7e 100644
--- a/src/gallium/auxiliary/hud/hud_private.h
+++ b/src/gallium/auxiliary/hud/hud_private.h
@@ -104,7 +104,7 @@ struct hud_graph {
/* mutable variables */
unsigned num_vertices;
unsigned index; /* vertex index being updated */
- uint64_t current_value;
+ double current_value;
FILE *fd;
};
@@ -139,7 +139,7 @@ struct hud_pane {
/* core */
void hud_pane_add_graph(struct hud_pane *pane, struct hud_graph *gr);
void hud_pane_set_max_value(struct hud_pane *pane, uint64_t value);
-void hud_graph_add_value(struct hud_graph *gr, uint64_t value);
+void hud_graph_add_value(struct hud_graph *gr, double value);
/* graphs/queries */
struct hud_batch_query_context;
--
2.13.3
_______________________________________________
mesa-dev mailing list
https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Loading...