From: Marek Olšák <marek.ol...@amd.com> This improves readability a lot. --- src/gallium/auxiliary/hud/hud_context.c | 80 ++++++++++++++++++++++++++-- src/gallium/auxiliary/hud/hud_driver_query.c | 3 +- src/gallium/auxiliary/hud/hud_private.h | 1 + 3 files changed, 80 insertions(+), 4 deletions(-)
diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c index ac971d8..3453bda 100644 --- a/src/gallium/auxiliary/hud/hud_context.c +++ b/src/gallium/auxiliary/hud/hud_context.c @@ -337,21 +337,21 @@ hud_draw_graph_line_strip(struct hud_context *hud, const struct hud_graph *gr, } static void hud_pane_accumulate_vertices(struct hud_context *hud, const struct hud_pane *pane) { struct hud_graph *gr; float *line_verts = hud->whitelines.vertices + hud->whitelines.num_vertices*2; unsigned i, num = 0; char str[32]; - const unsigned last_line = 5; + const unsigned last_line = pane->last_line; /* draw background */ hud_draw_background_quad(hud, pane->x1, pane->y1, pane->x2, pane->y2); /* draw numbers on the right-hand side */ for (i = 0; i <= last_line; i++) { unsigned x = pane->x2 + 2; unsigned y = pane->inner_y1 + @@ -537,21 +537,21 @@ hud_draw(struct hud_context *hud, struct pipe_resource *tex) 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_render_condition(cso, NULL, FALSE, 0); cso_set_sampler_views(cso, PIPE_SHADER_FRAGMENT, 1, &hud->font_sampler_view); cso_set_samplers(cso, PIPE_SHADER_FRAGMENT, 1, sampler_states); cso_set_constant_buffer(cso, PIPE_SHADER_VERTEX, 0, &hud->constbuf); /* prepare vertex buffers */ - hud_alloc_vertices(hud, &hud->bg, 4 * 128, 2 * sizeof(float)); + hud_alloc_vertices(hud, &hud->bg, 4 * 256, 2 * sizeof(float)); hud_alloc_vertices(hud, &hud->whitelines, 4 * 256, 2 * sizeof(float)); hud_alloc_vertices(hud, &hud->text, 4 * 1024, 4 * sizeof(float)); /* prepare all graphs */ hud_batch_query_update(hud->batch_query); LIST_FOR_EACH_ENTRY(pane, &hud->pane_list, head) { LIST_FOR_EACH_ENTRY(gr, &pane->graph_list, head) { gr->query_new_value(gr); } @@ -620,28 +620,102 @@ hud_draw(struct hud_context *hud, struct pipe_resource *tex) if (pane) hud_pane_draw_colored_objects(hud, pane); } cso_restore_state(cso); cso_restore_constant_buffer_slot0(cso, PIPE_SHADER_VERTEX); pipe_surface_reference(&surf, NULL); } +static void +fixup_bytes(enum pipe_driver_query_type type, int position, uint64_t *exp10) +{ + if (type == PIPE_DRIVER_QUERY_TYPE_BYTES && position % 3 == 0) + *exp10 = (*exp10 / 1000) * 1024; +} + /** * Set the maximum value for the Y axis of the graph. * This scales the graph accordingly. */ void hud_pane_set_max_value(struct hud_pane *pane, uint64_t value) { - pane->max_value = value; + double leftmost_digit; + uint64_t exp10; + int i; + + /* The following code determines the max_value in the graph as well as + * how many describing lines are drawn. The max_value is rounded up, + * so that all drawn numbers are rounded for readability. + * We want to print multiples of a simple number instead of multiples of + * hard-to-read numbers like 1.753. + */ + + /* Find the left-most digit. */ + exp10 = 1; + for (i = 0; value > 9 * exp10; i++) { + exp10 *= 10; + fixup_bytes(pane->type, i + 1, &exp10); + } + + leftmost_digit = DIV_ROUND_UP(value, exp10); + + /* Round 9 to 10. */ + if (leftmost_digit == 9) { + leftmost_digit = 1; + exp10 *= 10; + fixup_bytes(pane->type, i + 1, &exp10); + } + + switch ((unsigned)leftmost_digit) { + case 1: + pane->last_line = 5; /* lines in +1/5 increments */ + break; + case 2: + pane->last_line = 8; /* lines in +1/4 increments. */ + break; + case 3: + case 4: + pane->last_line = leftmost_digit * 2; /* lines in +1/2 increments */ + break; + case 5: + case 6: + case 7: + case 8: + pane->last_line = leftmost_digit; /* lines in +1 increments */ + break; + default: + assert(0); + } + + /* Truncate {3,4} to {2.5, 3.5} if possible. */ + for (i = 3; i <= 4; i++) { + if (leftmost_digit == i && value <= (i - 0.5) * exp10) { + leftmost_digit = i - 0.5; + pane->last_line = leftmost_digit * 2; /* lines in +1/2 increments. */ + } + } + + /* Truncate 2 to a multiple of 0.2 in (1, 1.6] if possible. */ + if (leftmost_digit == 2) { + for (i = 1; i <= 3; i++) { + if (value <= (1 + i*0.2) * exp10) { + leftmost_digit = 1 + i*0.2; + pane->last_line = 5 + i; /* lines in +1/5 increments. */ + break; + } + } + } + + pane->max_value = leftmost_digit * exp10; pane->yscale = -(int)pane->inner_height / (float)pane->max_value; } static void hud_pane_update_dyn_ceiling(struct hud_graph *gr, struct hud_pane *pane) { unsigned i; float tmp = 0.0f; if (pane->dyn_ceil_last_ran != gr->index) { diff --git a/src/gallium/auxiliary/hud/hud_driver_query.c b/src/gallium/auxiliary/hud/hud_driver_query.c index a7d28bc..40ea120 100644 --- a/src/gallium/auxiliary/hud/hud_driver_query.c +++ b/src/gallium/auxiliary/hud/hud_driver_query.c @@ -372,23 +372,24 @@ hud_pipe_query_install(struct hud_batch_query_context **pbq, if (flags & PIPE_DRIVER_QUERY_FLAG_BATCH) { if (!batch_query_add(pbq, pipe, query_type, &info->result_index)) goto fail_info; info->batch = *pbq; } else { info->query_type = query_type; info->result_index = result_index; } hud_pane_add_graph(pane, gr); + pane->type = type; /* must be set before updating the max_value */ + if (pane->max_value < max_value) hud_pane_set_max_value(pane, max_value); - pane->type = type; return; fail_info: FREE(info); fail_gr: FREE(gr); } boolean hud_driver_query_install(struct hud_batch_query_context **pbq, diff --git a/src/gallium/auxiliary/hud/hud_private.h b/src/gallium/auxiliary/hud/hud_private.h index 4a788bb..2104c27 100644 --- a/src/gallium/auxiliary/hud/hud_private.h +++ b/src/gallium/auxiliary/hud/hud_private.h @@ -54,20 +54,21 @@ struct hud_pane { struct list_head head; unsigned x1, y1, x2, y2; unsigned inner_x1; unsigned inner_y1; unsigned inner_x2; unsigned inner_y2; unsigned inner_width; unsigned inner_height; float yscale; unsigned max_num_vertices; + unsigned last_line; /* index of the last describing line in the graph */ uint64_t max_value; uint64_t initial_max_value; uint64_t ceiling; unsigned dyn_ceil_last_ran; boolean dyn_ceiling; enum pipe_driver_query_type type; uint64_t period; /* in microseconds */ struct list_head graph_list; unsigned num_graphs; -- 2.7.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev