<div dir="ltr"><div>It would be better to modify the existing query_fps function to compute the frame time as an option.</div><div><br></div><div>FPS in the HUD is not per second, but per HUD period. GALLIUM_HUD_PERIOD=0 gives you FPS = 1 / frametime. For greater period values, it's: frames / elapsed_time.<br></div><div><br></div><div>Marek<br></div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 15, 2018 at 11:39 AM, Matthias Groß <span dir="ltr"><<a href="mailto:grmat@sub.red" target="_blank">grmat@sub.red</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Frametimes are often a more useful metric than FPS, because fps are an<br>
averaged-value for the duration of a rather long period (one second).<br>
<br>
Example: 59 frames are rendered in 16 ms each, but one frame takes 56 ms<br>
to compute. That's exactly 60 FPS, but there is very noticeable stutter.<br>
Some modern game engines and game testers also utilise frametimes graphs.<br>
<br>
This graph is enabled via GALLIUM_HUD=frametime and will show the<br>
frametime of each frame and therefore also the stutter in a<br>
comprehensible way. It is useful to use the ceiling and/or dynamic<br>
modifier, though, to clip extreme anomalies, e.g. during loading.<br>
---<br>
src/gallium/auxiliary/hud/<wbr>hud_context.c | 4 ++<br>
src/gallium/auxiliary/hud/<wbr>hud_frametime.c | 85 +++++++++++++++++++++++<br>
src/gallium/auxiliary/hud/<wbr>hud_private.h | 1 +<br>
src/gallium/auxiliary/meson.b<wbr>uild | 1 +<br>
4 files changed, 91 insertions(+)<br>
create mode 100644 src/gallium/auxiliary/hud/hud_<wbr>frametime.c<br>
<br>
diff --git a/src/gallium/auxiliary/hud/hu<wbr>d_context.c b/src/gallium/auxiliary/hud/hu<wbr>d_context.c<br>
index 6ed9ccffdb..61db98b4b0 100644<br>
--- a/src/gallium/auxiliary/hud/hu<wbr>d_context.c<br>
+++ b/src/gallium/auxiliary/hud/hu<wbr>d_context.c<br>
@@ -1247,6 +1247,9 @@ hud_parse_env_var(struct hud_context *hud, struct pipe_screen *screen,<br>
if (strcmp(name, "fps") == 0) {<br>
hud_fps_graph_install(pane);<br>
}<br>
+ else if (strcmp(name, "frametime") == 0) {<br>
+ hud_frametime_graph_install(p<wbr>ane);<br>
+ }<br>
else if (strcmp(name, "cpu") == 0) {<br>
hud_cpu_graph_install(pane, ALL_CPUS);<br>
}<br>
@@ -1557,6 +1560,7 @@ print_help(struct pipe_screen *screen)<br>
puts("");<br>
puts(" Available names:");<br>
puts(" fps");<br>
+ puts(" frametime");<br>
puts(" cpu");<br>
<br>
for (i = 0; i < num_cpus; i++)<br>
diff --git a/src/gallium/auxiliary/hud/hu<wbr>d_frametime.c b/src/gallium/auxiliary/hud/hu<wbr>d_frametime.c<br>
new file mode 100644<br>
index 0000000000..0f5e9f7430<br>
--- /dev/null<br>
+++ b/src/gallium/auxiliary/hud/hu<wbr>d_frametime.c<br>
@@ -0,0 +1,85 @@<br>
+/****************************<wbr>******************************<wbr>****************<br>
+ *<br>
+ * Copyright 2018 <grmat@sub.red><br>
+ * All Rights Reserved.<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the<br>
+ * "Software"), to deal in the Software without restriction, including<br>
+ * without limitation the rights to use, copy, modify, merge, publish,<br>
+ * distribute, sub license, and/or sell copies of the Software, and to<br>
+ * permit persons to whom the Software is furnished to do so, subject to<br>
+ * the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the<br>
+ * next paragraph) shall be included in all copies or substantial portions<br>
+ * of the Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS<br>
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF<br>
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.<br>
+ * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR<br>
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,<br>
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE<br>
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.<br>
+ *<br>
+ ******************************<wbr>******************************<wbr>**************/<br>
+<br>
+/* This file contains code for displaying frametimes on the HUD.<br>
+ */<br>
+<br>
+#include "hud/hud_private.h"<br>
+#include "util/os_time.h"<br>
+#include "util/u_memory.h"<br>
+<br>
+struct frametime_info {<br>
+ uint64_t last_time;<br>
+};<br>
+<br>
+static void<br>
+query_frametime(struct hud_graph *gr, struct pipe_context *pipe)<br>
+{<br>
+ struct frametime_info *info = gr->query_data;<br>
+ uint64_t now = os_time_get();<br>
+<br>
+ if (info->last_time) {<br>
+ float frametime = ((double)now - (double)info->last_time) / 1000.0;<br>
+ info->last_time = now;<br>
+<br>
+ hud_graph_add_value(gr, frametime);<br>
+ }<br>
+ else {<br>
+ info->last_time = now;<br>
+ }<br>
+}<br>
+<br>
+static void<br>
+free_query_data(void *p, struct pipe_context *pipe)<br>
+{<br>
+ FREE(p);<br>
+}<br>
+<br>
+void<br>
+hud_frametime_graph_install(s<wbr>truct hud_pane *pane)<br>
+{<br>
+ struct hud_graph *gr = CALLOC_STRUCT(hud_graph);<br>
+<br>
+ if (!gr)<br>
+ return;<br>
+<br>
+ strcpy(gr->name, "frametime (ms)");<br>
+ gr->query_data = CALLOC_STRUCT(frametime_info);<br>
+ if (!gr->query_data) {<br>
+ FREE(gr);<br>
+ return;<br>
+ }<br>
+<br>
+ gr->query_new_value = query_frametime;<br>
+<br>
+ /* Don't use free() as our callback as that messes up Gallium's<br>
+ * memory debugger. Use simple free_query_data() wrapper.<br>
+ */<br>
+ gr->free_query_data = free_query_data;<br>
+<br>
+ hud_pane_add_graph(pane, gr);<br>
+}<br>
diff --git a/src/gallium/auxiliary/hud/hu<wbr>d_private.h b/src/gallium/auxiliary/hud/hu<wbr>d_private.h<br>
index b64e29e93e..deed329a8a 100644<br>
--- a/src/gallium/auxiliary/hud/hu<wbr>d_private.h<br>
+++ b/src/gallium/auxiliary/hud/hu<wbr>d_private.h<br>
@@ -157,6 +157,7 @@ struct hud_batch_query_context;<br>
int hud_get_num_cpus(void);<br>
<br>
void hud_fps_graph_install(struct hud_pane *pane);<br>
+void hud_frametime_graph_install(st<wbr>ruct hud_pane *pane);<br>
void hud_cpu_graph_install(struct hud_pane *pane, unsigned cpu_index);<br>
void hud_thread_busy_install(struct hud_pane *pane, const char *name, bool main);<br>
void hud_thread_counter_install(str<wbr>uct hud_pane *pane, const char *name,<br>
diff --git a/src/gallium/auxiliary/meson.<wbr>build b/src/gallium/auxiliary/meson.<wbr>build<br>
index 92cfb8f7af..7b019326a7 100644<br>
--- a/src/gallium/auxiliary/meson.<wbr>build<br>
+++ b/src/gallium/auxiliary/meson.<wbr>build<br>
@@ -117,6 +117,7 @@ files_libgallium = files(<br>
'hud/hud_sensors_temp.c',<br>
'hud/hud_driver_query.c',<br>
'hud/hud_fps.c',<br>
+ 'hud/hud_frametime.c',<br>
'hud/hud_private.h',<br>
'indices/u_indices.h',<br>
'indices/u_indices_priv.h',<br>
<span class="m_1210410093178106863HOEnZb"><font color="#888888">-- <br>
2.17.0<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div></div>