/* This head-up display module can draw transparent graphs on top of what
* the app is rendering, visualizing various data like framerate, cpu load,
- * performance counters, etc. It can be hook up into any state tracker.
+ * performance counters, etc. It can be hook up into any gallium frontend.
*
* The HUD is controlled with the GALLIUM_HUD environment variable.
* Set GALLIUM_HUD=help for more info.
#include "cso_cache/cso_context.h"
#include "util/u_draw_quad.h"
-#include "util/u_format.h"
+#include "util/format/u_format.h"
#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "util/u_math.h"
/* Control the visibility of all HUD contexts */
static boolean huds_visible = TRUE;
+static int hud_scale = 1;
#ifdef PIPE_OS_UNIX
hud->constants.color[1] = g;
hud->constants.color[2] = b;
hud->constants.color[3] = a;
- hud->constants.translate[0] = (float) xoffset;
- hud->constants.translate[1] = (float) yoffset;
- hud->constants.scale[0] = 1;
- hud->constants.scale[1] = yscale;
+ hud->constants.translate[0] = (float) (xoffset * hud_scale);
+ hud->constants.translate[1] = (float) (yoffset * hud_scale);
+ hud->constants.scale[0] = hud_scale;
+ hud->constants.scale[1] = yscale * hud_scale;
cso_set_constant_buffer(cso, PIPE_SHADER_VERTEX, 0, &hud->constbuf);
- cso_set_vertex_buffers(cso, cso_get_aux_vertex_buffer_slot(cso),
- 1, &hud->color_prims.vbuf);
+ cso_set_vertex_buffers(cso, 0, 1, &hud->color_prims.vbuf);
cso_set_fragment_shader_handle(hud->cso, hud->fs_color);
cso_draw_arrays(cso, prim, 0, num_vertices);
va_list ap;
va_start(ap, str);
- util_vsnprintf(buf, sizeof(buf), str, ap);
+ vsnprintf(buf, sizeof(buf), str, ap);
va_end(ap);
if (!*s)
static const char *volt_units[] = {" mV", " V"};
static const char *amp_units[] = {" mA", " A"};
static const char *watt_units[] = {" mW", " W"};
+ static const char *float_units[] = {""};
const char **units;
unsigned max_unit;
max_unit = ARRAY_SIZE(temperature_units)-1;
units = temperature_units;
break;
+ case PIPE_DRIVER_QUERY_TYPE_FLOAT:
+ max_unit = ARRAY_SIZE(float_units)-1;
+ units = float_units;
+ break;
case PIPE_DRIVER_QUERY_TYPE_PERCENTAGE:
max_unit = ARRAY_SIZE(percent_units)-1;
units = percent_units;
hud->whitelines.num_vertices += num/2;
}
+static void
+hud_pane_accumulate_vertices_simple(struct hud_context *hud,
+ const struct hud_pane *pane)
+{
+ struct hud_graph *gr;
+ unsigned i;
+ char str[32];
+
+ /* draw info below the pane */
+ i = 0;
+ LIST_FOR_EACH_ENTRY(gr, &pane->graph_list, head) {
+ unsigned x = pane->x1;
+ unsigned y = pane->y_simple + i*hud->font.glyph_height;
+
+ number_to_human_readable(gr->current_value, pane->type, str);
+ hud_draw_string(hud, x, y, "%s: %s", gr->name, str);
+ i++;
+ }
+}
+
static void
hud_pane_draw_colored_objects(struct hud_context *hud,
const struct hud_pane *pane)
cso_set_tesseval_shader_handle(cso, NULL);
cso_set_geometry_shader_handle(cso, NULL);
cso_set_vertex_shader_handle(cso, hud->vs);
- cso_set_vertex_elements(cso, 2, hud->velems);
+ cso_set_vertex_elements(cso, &hud->velems);
cso_set_render_condition(cso, NULL, FALSE, 0);
cso_set_sampler_views(cso, PIPE_SHADER_FRAGMENT, 1,
&hud->font_sampler_view);
hud->constants.color[3] = 0.666f;
hud->constants.translate[0] = 0;
hud->constants.translate[1] = 0;
- hud->constants.scale[0] = 1;
- hud->constants.scale[1] = 1;
+ hud->constants.scale[0] = hud_scale;
+ hud->constants.scale[1] = hud_scale;
cso_set_constant_buffer(cso, PIPE_SHADER_VERTEX, 0, &hud->constbuf);
- cso_set_vertex_buffers(cso, cso_get_aux_vertex_buffer_slot(cso), 1,
- &hud->bg.vbuf);
+
+ cso_set_vertex_buffers(cso, 0, 1, &hud->bg.vbuf);
cso_draw_arrays(cso, PIPE_PRIM_QUADS, 0, hud->bg.num_vertices);
}
pipe_resource_reference(&hud->bg.vbuf.buffer.resource, NULL);
+ /* draw accumulated vertices for text */
+ if (hud->text.num_vertices) {
+ cso_set_vertex_buffers(cso, 0, 1, &hud->text.vbuf);
+ cso_set_fragment_shader_handle(hud->cso, hud->fs_text);
+ cso_draw_arrays(cso, PIPE_PRIM_QUADS, 0, hud->text.num_vertices);
+ }
+ pipe_resource_reference(&hud->text.vbuf.buffer.resource, NULL);
+
+ if (hud->simple) {
+ cso_restore_state(cso);
+ cso_restore_constant_buffer_slot0(cso, PIPE_SHADER_VERTEX);
+
+ pipe_surface_reference(&surf, NULL);
+ return;
+ }
+
/* draw accumulated vertices for white lines */
cso_set_blend(cso, &hud->no_blend);
hud->constants.color[3] = 1;
hud->constants.translate[0] = 0;
hud->constants.translate[1] = 0;
- hud->constants.scale[0] = 1;
- hud->constants.scale[1] = 1;
+ hud->constants.scale[0] = hud_scale;
+ hud->constants.scale[1] = hud_scale;
cso_set_constant_buffer(cso, PIPE_SHADER_VERTEX, 0, &hud->constbuf);
if (hud->whitelines.num_vertices) {
- cso_set_vertex_buffers(cso, cso_get_aux_vertex_buffer_slot(cso), 1,
- &hud->whitelines.vbuf);
+ cso_set_vertex_buffers(cso, 0, 1, &hud->whitelines.vbuf);
cso_set_fragment_shader_handle(hud->cso, hud->fs_color);
cso_draw_arrays(cso, PIPE_PRIM_LINES, 0, hud->whitelines.num_vertices);
}
pipe_resource_reference(&hud->whitelines.vbuf.buffer.resource, NULL);
- /* draw accumulated vertices for text */
- cso_set_blend(cso, &hud->alpha_blend);
- if (hud->text.num_vertices) {
- cso_set_vertex_buffers(cso, cso_get_aux_vertex_buffer_slot(cso), 1,
- &hud->text.vbuf);
- cso_set_fragment_shader_handle(hud->cso, hud->fs_text);
- cso_draw_arrays(cso, PIPE_PRIM_QUADS, 0, hud->text.num_vertices);
- }
- pipe_resource_reference(&hud->text.vbuf.buffer.resource, NULL);
-
/* draw the rest */
+ cso_set_blend(cso, &hud->alpha_blend);
cso_set_rasterizer(cso, &hud->rasterizer_aa_lines);
LIST_FOR_EACH_ENTRY(pane, &hud->pane_list, head) {
if (pane)
*/
if (gr->current_value <
LIST_ENTRY(struct hud_graph, next, head)->current_value) {
- LIST_DEL(&gr->head);
- LIST_ADD(&gr->head, &next->head);
+ list_del(&gr->head);
+ list_add(&gr->head, &next->head);
}
}
}
- hud_pane_accumulate_vertices(hud, pane);
+ if (hud->simple)
+ hud_pane_accumulate_vertices_simple(hud, pane);
+ else
+ hud_pane_accumulate_vertices(hud, pane);
}
/* unmap the uploader's vertex buffer before drawing */
static struct hud_pane *
hud_pane_create(struct hud_context *hud,
unsigned x1, unsigned y1, unsigned x2, unsigned y2,
+ unsigned y_simple,
unsigned period, uint64_t max_value, uint64_t ceiling,
boolean dyn_ceiling, boolean sort_items)
{
pane->y1 = y1;
pane->x2 = x2;
pane->y2 = y2;
+ pane->y_simple = y_simple;
pane->inner_x1 = x1 + 1;
pane->inner_x2 = x2 - 1;
pane->inner_y1 = y1 + 1;
pane->sort_items = sort_items;
pane->initial_max_value = max_value;
hud_pane_set_max_value(pane, max_value);
- LIST_INITHEAD(&pane->graph_list);
+ list_inithead(&pane->graph_list);
return pane;
}
gr->color[1] = colors[color][1];
gr->color[2] = colors[color][2];
gr->pane = pane;
- LIST_ADDTAIL(&gr->head, &pane->graph_list);
+ list_addtail(&gr->head, &pane->graph_list);
pane->num_graphs++;
pane->next_color++;
}
char name_a[256], s[256];
char *name;
struct hud_pane *pane = NULL;
- unsigned x = 10, y = 10;
+ unsigned x = 10, y = 10, y_simple = 10;
unsigned width = 251, height = 100;
unsigned period = 500 * 1000; /* default period (1/2 second) */
uint64_t ceiling = UINT64_MAX;
boolean sort_items = false;
const char *period_env;
+ if (strncmp(env, "simple,", 7) == 0) {
+ hud->simple = true;
+ env += 7;
+ }
+
/*
* The GALLIUM_HUD_PERIOD env var sets the graph update rate.
* The env var is in seconds (a float).
}
while ((num = parse_string(env, name_a)) != 0) {
+ bool added = true;
+
env += num;
/* check for explicit location, size and etc. settings */
column_width = width > column_width ? width : column_width;
if (!pane) {
- pane = hud_pane_create(hud, x, y, x + width, y + height, period, 10,
- ceiling, dyn_ceiling, sort_items);
+ pane = hud_pane_create(hud, x, y, x + width, y + height, y_simple,
+ period, 10, ceiling, dyn_ceiling, sort_items);
if (!pane)
return;
}
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);
}
screen, name)) {
fprintf(stderr, "gallium_hud: unknown driver query '%s'\n", name);
fflush(stderr);
+ added = false;
}
}
}
env += num;
strip_hyphens(s);
- if (!LIST_IS_EMPTY(&pane->graph_list)) {
+ if (added && !list_is_empty(&pane->graph_list)) {
struct hud_graph *graph;
graph = LIST_ENTRY(struct hud_graph, pane->graph_list.prev, head);
strncpy(graph->name, s, sizeof(graph->name)-1);
break;
y += height + hud->font.glyph_height * (pane->num_graphs + 2);
+ y_simple += hud->font.glyph_height * (pane->num_graphs + 1);
height = 100;
if (pane && pane->num_graphs) {
- LIST_ADDTAIL(&pane->head, &hud->pane_list);
+ list_addtail(&pane->head, &hud->pane_list);
pane = NULL;
}
break;
case ';':
env++;
y = 10;
+ y_simple = 10;
x += column_width + hud->font.glyph_width * 9;
height = 100;
if (pane && pane->num_graphs) {
- LIST_ADDTAIL(&pane->head, &hud->pane_list);
+ list_addtail(&pane->head, &hud->pane_list);
pane = NULL;
}
if (pane) {
if (pane->num_graphs) {
- LIST_ADDTAIL(&pane->head, &hud->pane_list);
+ list_addtail(&pane->head, &hud->pane_list);
}
else {
FREE(pane);
puts(" the Y axis does not go above the restriction imposed by 'c' while");
puts(" still adjusting the value of the Y axis down when appropriate.");
puts("");
+ puts(" You can change behavior of the whole HUD by adding these options at");
+ puts(" the beginning of the environment variable:");
+ puts(" 'simple,' disables all the fancy stuff and only draws text.");
+ puts("");
puts(" Example: GALLIUM_HUD=\".w256.h64.x1600.y520.d.c1000fps+cpu,.datom-count\"");
puts("");
puts(" Available names:");
puts(" fps");
+ puts(" frametime");
puts(" cpu");
for (i = 0; i < num_cpus; i++)
LIST_FOR_EACH_ENTRY_SAFE(pane, pane_tmp, &hud->pane_list, head) {
LIST_FOR_EACH_ENTRY_SAFE(graph, graph_tmp, &pane->graph_list, head) {
- LIST_DEL(&graph->head);
+ list_del(&graph->head);
hud_graph_destroy(graph, pipe);
}
- LIST_DEL(&pane->head);
+ list_del(&pane->head);
FREE(pane);
}
#ifdef PIPE_OS_UNIX
unsigned signo = debug_get_num_option("GALLIUM_HUD_TOGGLE_SIGNAL", 0);
static boolean sig_handled = FALSE;
- struct sigaction action = {};
+ struct sigaction action;
+
+ memset(&action, 0, sizeof(action));
#endif
huds_visible = debug_get_bool_option("GALLIUM_HUD_VISIBLE", TRUE);
+ hud_scale = debug_get_num_option("GALLIUM_HUD_SCALE", 1);
if (!env || !*env)
return NULL;
hud->refcount = 1;
hud->has_srgb = screen->is_format_supported(screen,
PIPE_FORMAT_B8G8R8A8_SRGB,
- PIPE_TEXTURE_2D, 0,
+ PIPE_TEXTURE_2D, 0, 0,
PIPE_BIND_RENDER_TARGET) != 0;
/* blend state */
/* rasterizer */
hud->rasterizer.half_pixel_center = 1;
hud->rasterizer.bottom_edge_rule = 1;
- hud->rasterizer.depth_clip = 1;
+ hud->rasterizer.depth_clip_near = 1;
+ hud->rasterizer.depth_clip_far = 1;
hud->rasterizer.line_width = 1;
hud->rasterizer.line_last_pixel = 1;
hud->rasterizer_aa_lines.line_smooth = 1;
/* vertex elements */
+ hud->velems.count = 2;
for (i = 0; i < 2; i++) {
- hud->velems[i].src_offset = i * 2 * sizeof(float);
- hud->velems[i].src_format = PIPE_FORMAT_R32G32_FLOAT;
- hud->velems[i].vertex_buffer_index = cso_get_aux_vertex_buffer_slot(cso);
+ hud->velems.velems[i].src_offset = i * 2 * sizeof(float);
+ hud->velems.velems[i].src_format = PIPE_FORMAT_R32G32_FLOAT;
+ hud->velems.velems[i].vertex_buffer_index = 0;
}
/* sampler state (for font drawing) */
hud->constbuf.buffer_size = sizeof(hud->constants);
hud->constbuf.user_buffer = &hud->constants;
- LIST_INITHEAD(&hud->pane_list);
+ list_inithead(&hud->pane_list);
/* setup sig handler once for all hud contexts */
#ifdef PIPE_OS_UNIX