Lines Matching refs:hud
40 #include "hud/hud_context.h"
41 #include "hud/hud_private.h"
71 hud_draw_colored_prims(struct hud_context *hud, unsigned prim,
76 struct cso_context *cso = hud->cso;
77 struct pipe_context *pipe = hud->pipe;
80 hud->constants.color[0] = r;
81 hud->constants.color[1] = g;
82 hud->constants.color[2] = b;
83 hud->constants.color[3] = a;
84 hud->constants.translate[0] = (float) (xoffset * hud_scale);
85 hud->constants.translate[1] = (float) (yoffset * hud_scale);
86 hud->constants.scale[0] = hud_scale;
87 hud->constants.scale[1] = yscale * hud_scale;
88 pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, false, &hud->constbuf);
90 u_upload_data(hud->pipe->stream_uploader, 0,
93 u_upload_unmap(hud->pipe->stream_uploader);
98 cso_set_fragment_shader_handle(hud->cso, hud->fs_color);
103 hud_draw_colored_quad(struct hud_context *hud, unsigned prim,
114 hud_draw_colored_prims(hud, prim, buffer, 4, r, g, b, a, 0, 0, 1);
118 hud_draw_background_quad(struct hud_context *hud,
121 float *vertices = hud->bg.vertices + hud->bg.num_vertices*2;
124 assert(hud->bg.num_vertices + 4 <= hud->bg.max_num_vertices);
138 hud->bg.num_vertices += num/2;
142 hud_draw_string(struct hud_context *hud, unsigned x, unsigned y,
147 float *vertices = hud->text.vertices + hud->text.num_vertices*4;
158 hud_draw_background_quad(hud,
160 x + strlen(buf)*hud->font.glyph_width,
161 y + hud->font.glyph_height);
166 unsigned x2 = x + hud->font.glyph_width;
167 unsigned y2 = y + hud->font.glyph_height;
168 unsigned tx1 = (*s % 16) * hud->font.glyph_width;
169 unsigned ty1 = (*s / 16) * hud->font.glyph_height;
170 unsigned tx2 = tx1 + hud->font.glyph_width;
171 unsigned ty2 = ty1 + hud->font.glyph_height;
174 x += hud->font.glyph_width;
179 assert(hud->text.num_vertices + num/4 + 4 <= hud->text.max_num_vertices);
201 x += hud->font.glyph_width;
205 hud->text.num_vertices += num/4;
301 hud_draw_graph_line_strip(struct hud_context *hud, const struct hud_graph *gr,
309 hud_draw_colored_prims(hud, PIPE_PRIM_LINE_STRIP,
318 hud_draw_colored_prims(hud, PIPE_PRIM_LINE_STRIP,
326 hud_pane_accumulate_vertices(struct hud_context *hud,
330 float *line_verts = hud->whitelines.vertices + hud->whitelines.num_vertices*2;
336 hud_draw_background_quad(hud,
345 hud->font.glyph_height / 2;
349 hud_draw_string(hud, x, y, "%s", str);
356 unsigned y = pane->y2 + 2 + i*hud->font.glyph_height;
359 hud_draw_string(hud, x, y, " %s: %s", gr->name, str);
364 assert(hud->whitelines.num_vertices + num/2 + 8 <= hud->whitelines.max_num_vertices);
390 assert(hud->whitelines.num_vertices + num/2 + 2 <= hud->whitelines.max_num_vertices);
397 hud->whitelines.num_vertices += num/2;
401 hud_pane_accumulate_vertices_simple(struct hud_context *hud,
412 unsigned y = pane->y_simple + i*hud->font.glyph_height;
415 hud_draw_string(hud, x, y, "%s: %s", gr->name, str);
421 hud_pane_draw_colored_objects(struct hud_context *hud,
431 unsigned y = pane->y2 + 2 + i*hud->font.glyph_height;
433 hud_draw_colored_quad(hud, PIPE_PRIM_QUADS, x + 1, y + 1, x + 12, y + 13,
440 hud_draw_graph_line_strip(hud, gr, pane->inner_x1, pane->inner_y2, pane->yscale);
445 hud_prepare_vertices(struct hud_context *hud, struct vertex_queue *v,
459 hud_draw_results(struct hud_context *hud, struct pipe_resource *tex)
461 struct cso_context *cso = hud->cso;
462 struct pipe_context *pipe = hud->pipe;
467 { &hud->font_sampler_state };
473 hud->fb_width = tex->width0;
474 hud->fb_height = tex->height0;
475 hud->constants.two_div_fb_width = 2.0f / hud->fb_width;
476 hud->constants.two_div_fb_height = 2.0f / hud->fb_height;
505 if (hud->has_srgb) {
517 fb.width = hud->fb_width;
518 fb.height = hud->fb_height;
520 viewport.scale[0] = 0.5f * hud->fb_width;
521 viewport.scale[1] = 0.5f * hud->fb_height;
523 viewport.translate[0] = 0.5f * hud->fb_width;
524 viewport.translate[1] = 0.5f * hud->fb_height;
534 cso_set_depth_stencil_alpha(cso, &hud->dsa);
535 cso_set_rasterizer(cso, &hud->rasterizer);
541 cso_set_vertex_shader_handle(cso, hud->vs_color);
542 cso_set_vertex_elements(cso, &hud->velems);
545 &hud->font_sampler_view);
547 pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, false, &hud->constbuf);
550 cso_set_blend(cso, &hud->alpha_blend);
551 cso_set_fragment_shader_handle(hud->cso, hud->fs_color);
553 if (hud->bg.num_vertices) {
554 hud->constants.color[0] = 0;
555 hud->constants.color[1] = 0;
556 hud->constants.color[2] = 0;
557 hud->constants.color[3] = 0.666f;
558 hud->constants.translate[0] = 0;
559 hud->constants.translate[1] = 0;
560 hud->constants.scale[0] = hud_scale;
561 hud->constants.scale[1] = hud_scale;
563 pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, false, &hud->constbuf);
565 cso_set_vertex_buffers(cso, 0, 1, 0, false, &hud->bg.vbuf);
566 cso_draw_arrays(cso, PIPE_PRIM_QUADS, 0, hud->bg.num_vertices);
568 pipe_resource_reference(&hud->bg.vbuf.buffer.resource, NULL);
571 if (hud->text.num_vertices) {
572 cso_set_vertex_shader_handle(cso, hud->vs_text);
573 cso_set_vertex_buffers(cso, 0, 1, 0, false, &hud->text.vbuf);
574 cso_set_fragment_shader_handle(hud->cso, hud->fs_text);
575 cso_draw_arrays(cso, PIPE_PRIM_QUADS, 0, hud->text.num_vertices);
577 pipe_resource_reference(&hud->text.vbuf.buffer.resource, NULL);
579 if (hud->simple)
583 cso_set_blend(cso, &hud->no_blend);
585 hud->constants.color[0] = 1;
586 hud->constants.color[1] = 1;
587 hud->constants.color[2] = 1;
588 hud->constants.color[3] = 1;
589 hud->constants.translate[0] = 0;
590 hud->constants.translate[1] = 0;
591 hud->constants.scale[0] = hud_scale;
592 hud->constants.scale[1] = hud_scale;
593 pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, false, &hud->constbuf);
595 if (hud->whitelines.num_vertices) {
596 cso_set_vertex_shader_handle(cso, hud->vs_color);
597 cso_set_vertex_buffers(cso, 0, 1, 0, false, &hud->whitelines.vbuf);
598 cso_set_fragment_shader_handle(hud->cso, hud->fs_color);
599 cso_draw_arrays(cso, PIPE_PRIM_LINES, 0, hud->whitelines.num_vertices);
601 pipe_resource_reference(&hud->whitelines.vbuf.buffer.resource, NULL);
604 cso_set_blend(cso, &hud->alpha_blend);
605 cso_set_rasterizer(cso, &hud->rasterizer_aa_lines);
606 LIST_FOR_EACH_ENTRY(pane, &hud->pane_list, head) {
608 hud_pane_draw_colored_objects(hud, pane);
615 if (hud->st) {
616 hud->st->invalidate_state(hud->st,
626 hud_start_queries(struct hud_context *hud, struct pipe_context *pipe)
632 hud_batch_query_begin(hud->batch_query, pipe);
634 LIST_FOR_EACH_ENTRY(pane, &hud->pane_list, head) {
644 hud_stop_queries(struct hud_context *hud, struct pipe_context *pipe)
650 hud_prepare_vertices(hud, &hud->bg, 16 * 256, 2 * sizeof(float));
651 hud_prepare_vertices(hud, &hud->whitelines, 4 * 256, 2 * sizeof(float));
652 hud_prepare_vertices(hud, &hud->text, 16 * 1024, 4 * sizeof(float));
658 hud->bg.buffer_size +
659 hud->whitelines.buffer_size +
660 hud->text.buffer_size,
661 16, &hud->bg.vbuf.buffer_offset, &hud->bg.vbuf.buffer.resource,
662 (void**)&hud->bg.vertices);
663 if (!hud->bg.vertices)
666 pipe_resource_reference(&hud->whitelines.vbuf.buffer.resource, hud->bg.vbuf.buffer.resource);
667 pipe_resource_reference(&hud->text.vbuf.buffer.resource, hud->bg.vbuf.buffer.resource);
669 hud->whitelines.vbuf.buffer_offset = hud->bg.vbuf.buffer_offset +
670 hud->bg.buffer_size;
671 hud->whitelines.vertices = hud->bg.vertices +
672 hud->bg.buffer_size / sizeof(float);
674 hud->text.vbuf.buffer_offset = hud->whitelines.vbuf.buffer_offset +
675 hud->whitelines.buffer_size;
676 hud->text.vertices = hud->whitelines.vertices +
677 hud->whitelines.buffer_size / sizeof(float);
680 hud_batch_query_update(hud->batch_query, pipe);
682 LIST_FOR_EACH_ENTRY(pane, &hud->pane_list, head) {
704 if (hud->simple)
705 hud_pane_accumulate_vertices_simple(hud, pane);
707 hud_pane_accumulate_vertices(hud, pane);
721 hud_run(struct hud_context *hud, struct cso_context *cso,
729 if (hud->record_pipe && (!pipe || pipe == hud->record_pipe))
730 hud_stop_queries(hud, hud->record_pipe);
732 if (hud->cso && (!cso || cso == hud->cso))
733 hud_draw_results(hud, tex);
735 if (hud->record_pipe && (!pipe || pipe == hud->record_pipe))
736 hud_start_queries(hud, hud->record_pipe);
744 hud_record_only(struct hud_context *hud, struct pipe_context *pipe)
749 if (pipe == hud->pipe || pipe != hud->record_pipe)
752 hud_stop_queries(hud, hud->record_pipe);
753 hud_start_queries(hud, hud->record_pipe);
869 hud_pane_create(struct hud_context *hud,
880 pane->hud = hud;
1180 hud_parse_env_var(struct hud_context *hud, struct pipe_screen *screen,
1198 hud->simple = true;
1232 pane = hud_pane_create(hud, x, y, x + width, y + height, y_simple,
1336 hud_pipe_query_install(&hud->batch_query, pane,
1345 hud_pipe_query_install(&hud->batch_query, pane,
1375 hud_pipe_query_install(&hud->batch_query, pane, name,
1386 if (!hud_driver_query_install(&hud->batch_query, pane,
1455 y += height + hud->font.glyph_height * (pane->num_graphs + 2);
1456 y_simple += hud->font.glyph_height * (pane->num_graphs + 1);
1460 list_addtail(&pane->head, &hud->pane_list);
1469 x += column_width + hud->font.glyph_width * 9;
1473 list_addtail(&pane->head, &hud->pane_list);
1496 list_addtail(&pane->head, &hud->pane_list);
1503 LIST_FOR_EACH_ENTRY(pane, &hud->pane_list, head) {
1622 hud_unset_draw_context(struct hud_context *hud)
1624 struct pipe_context *pipe = hud->pipe;
1629 pipe_sampler_view_reference(&hud->font_sampler_view, NULL);
1631 if (hud->fs_color) {
1632 pipe->delete_fs_state(pipe, hud->fs_color);
1633 hud->fs_color = NULL;
1635 if (hud->fs_text) {
1636 pipe->delete_fs_state(pipe, hud->fs_text);
1637 hud->fs_text = NULL;
1639 if (hud->vs_color) {
1640 pipe->delete_vs_state(pipe, hud->vs_color);
1641 hud->vs_color = NULL;
1643 if (hud->vs_text) {
1644 pipe->delete_vs_state(pipe, hud->vs_text);
1645 hud->vs_text = NULL;
1648 hud->cso = NULL;
1649 hud->pipe = NULL;
1653 hud_set_draw_context(struct hud_context *hud, struct cso_context *cso,
1658 assert(!hud->pipe);
1659 hud->pipe = pipe;
1660 hud->cso = cso;
1661 hud->st = st;
1665 &view_templ, hud->font.texture, hud->font.texture->format);
1666 hud->font_sampler_view = pipe->create_sampler_view(pipe, hud->font.texture,
1668 if (!hud->font_sampler_view)
1672 hud->fs_color =
1702 hud->fs_text = pipe->create_fs_state(pipe, &state);
1738 hud->vs_color = pipe->create_vs_state(pipe, &state);
1775 hud->vs_text = pipe->create_vs_state(pipe, &state);
1781 hud_unset_draw_context(hud);
1782 fprintf(stderr, "hud: failed to set a draw context");
1787 hud_unset_record_context(struct hud_context *hud)
1789 struct pipe_context *pipe = hud->record_pipe;
1796 LIST_FOR_EACH_ENTRY_SAFE(pane, pane_tmp, &hud->pane_list, head) {
1805 hud_batch_query_cleanup(&hud->batch_query, pipe);
1806 hud->record_pipe = NULL;
1810 hud_set_record_context(struct hud_context *hud, struct pipe_context *pipe)
1812 hud->record_pipe = pipe;
1857 struct hud_context *hud;
1878 hud = CALLOC_STRUCT(hud_context);
1879 if (!hud)
1884 UTIL_FONT_FIXED_8X13, &hud->font)) {
1885 FREE(hud);
1889 hud->refcount = 1;
1902 hud->has_srgb = (i == ARRAY_SIZE(srgb_formats));
1905 hud->no_blend.rt[0].colormask = PIPE_MASK_RGBA;
1907 hud->alpha_blend.rt[0].colormask = PIPE_MASK_RGBA;
1908 hud->alpha_blend.rt[0].blend_enable = 1;
1909 hud->alpha_blend.rt[0].rgb_func = PIPE_BLEND_ADD;
1910 hud->alpha_blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_SRC_ALPHA;
1911 hud->alpha_blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_INV_SRC_ALPHA;
1912 hud->alpha_blend.rt[0].alpha_func = PIPE_BLEND_ADD;
1913 hud->alpha_blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ZERO;
1914 hud->alpha_blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ONE;
1917 hud->rasterizer.half_pixel_center = 1;
1918 hud->rasterizer.bottom_edge_rule = 1;
1919 hud->rasterizer.depth_clip_near = 1;
1920 hud->rasterizer.depth_clip_far = 1;
1921 hud->rasterizer.line_width = 1;
1922 hud->rasterizer.line_last_pixel = 1;
1924 hud->rasterizer_aa_lines = hud->rasterizer;
1925 hud->rasterizer_aa_lines.line_smooth = 1;
1928 hud->velems.count = 2;
1930 hud->velems.velems[i].src_offset = i * 2 * sizeof(float);
1931 hud->velems.velems[i].src_format = PIPE_FORMAT_R32G32_FLOAT;
1932 hud->velems.velems[i].vertex_buffer_index = 0;
1936 hud->font_sampler_state.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
1937 hud->font_sampler_state.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
1938 hud->font_sampler_state.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
1939 hud->font_sampler_state.normalized_coords = 1;
1942 hud->constbuf.buffer_size = sizeof(hud->constants);
1943 hud->constbuf.user_buffer = &hud->constants;
1945 list_inithead(&hud->pane_list);
1947 /* setup sig handler once for all hud contexts */
1964 hud_set_record_context(hud, cso_get_pipe_context(cso));
1966 hud_set_draw_context(hud, cso, st);
1968 hud_parse_env_var(hud, screen, env);
1969 return hud;
1977 hud_destroy(struct hud_context *hud, struct cso_context *cso)
1979 if (!cso || hud->record_pipe == cso_get_pipe_context(cso))
1980 hud_unset_record_context(hud);
1982 if (!cso || hud->cso == cso)
1983 hud_unset_draw_context(hud);
1985 if (p_atomic_dec_zero(&hud->refcount)) {
1986 pipe_resource_reference(&hud->font.texture, NULL);
1987 FREE(hud);
1992 hud_add_queue_for_monitoring(struct hud_context *hud,
1995 assert(!hud->monitored_queue);
1996 hud->monitored_queue = queue_info;