1848b8605Smrg/************************************************************************** 2848b8605Smrg * 3848b8605Smrg * Copyright 2013 Marek Olšák <maraeo@gmail.com> 4848b8605Smrg * All Rights Reserved. 5848b8605Smrg * 6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7848b8605Smrg * copy of this software and associated documentation files (the 8848b8605Smrg * "Software"), to deal in the Software without restriction, including 9848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish, 10848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to 11848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to 12848b8605Smrg * the following conditions: 13848b8605Smrg * 14848b8605Smrg * The above copyright notice and this permission notice (including the 15848b8605Smrg * next paragraph) shall be included in all copies or substantial portions 16848b8605Smrg * of the Software. 17848b8605Smrg * 18848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20848b8605Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21848b8605Smrg * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR 22848b8605Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23848b8605Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24848b8605Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25848b8605Smrg * 26848b8605Smrg **************************************************************************/ 27848b8605Smrg 28848b8605Smrg#ifndef HUD_PRIVATE_H 29848b8605Smrg#define HUD_PRIVATE_H 30848b8605Smrg 31848b8605Smrg#include "pipe/p_context.h" 32b8e80941Smrg#include "pipe/p_state.h" 33b8e80941Smrg#include "util/list.h" 34b8e80941Smrg#include "hud/font.h" 35b8e80941Smrg 36b8e80941Smrgenum hud_counter { 37b8e80941Smrg HUD_COUNTER_OFFLOADED, 38b8e80941Smrg HUD_COUNTER_DIRECT, 39b8e80941Smrg HUD_COUNTER_SYNCS, 40b8e80941Smrg}; 41b8e80941Smrg 42b8e80941Smrgstruct hud_context { 43b8e80941Smrg int refcount; 44b8e80941Smrg bool simple; 45b8e80941Smrg 46b8e80941Smrg /* Context where queries are executed. */ 47b8e80941Smrg struct pipe_context *record_pipe; 48b8e80941Smrg 49b8e80941Smrg /* Context where the HUD is drawn: */ 50b8e80941Smrg struct pipe_context *pipe; 51b8e80941Smrg struct cso_context *cso; 52b8e80941Smrg 53b8e80941Smrg struct hud_batch_query_context *batch_query; 54b8e80941Smrg struct list_head pane_list; 55b8e80941Smrg 56b8e80941Smrg struct util_queue_monitoring *monitored_queue; 57b8e80941Smrg 58b8e80941Smrg /* states */ 59b8e80941Smrg struct pipe_blend_state no_blend, alpha_blend; 60b8e80941Smrg struct pipe_depth_stencil_alpha_state dsa; 61b8e80941Smrg void *fs_color, *fs_text; 62b8e80941Smrg struct pipe_rasterizer_state rasterizer, rasterizer_aa_lines; 63b8e80941Smrg void *vs; 64b8e80941Smrg struct pipe_vertex_element velems[2]; 65b8e80941Smrg 66b8e80941Smrg /* font */ 67b8e80941Smrg struct util_font font; 68b8e80941Smrg struct pipe_sampler_view *font_sampler_view; 69b8e80941Smrg struct pipe_sampler_state font_sampler_state; 70b8e80941Smrg 71b8e80941Smrg /* VS constant buffer */ 72b8e80941Smrg struct { 73b8e80941Smrg float color[4]; 74b8e80941Smrg float two_div_fb_width; 75b8e80941Smrg float two_div_fb_height; 76b8e80941Smrg float translate[2]; 77b8e80941Smrg float scale[2]; 78b8e80941Smrg float padding[2]; 79b8e80941Smrg } constants; 80b8e80941Smrg struct pipe_constant_buffer constbuf; 81b8e80941Smrg 82b8e80941Smrg unsigned fb_width, fb_height; 83b8e80941Smrg 84b8e80941Smrg /* vertices for text and background drawing are accumulated here and then 85b8e80941Smrg * drawn all at once */ 86b8e80941Smrg struct vertex_queue { 87b8e80941Smrg float *vertices; 88b8e80941Smrg struct pipe_vertex_buffer vbuf; 89b8e80941Smrg unsigned max_num_vertices; 90b8e80941Smrg unsigned num_vertices; 91b8e80941Smrg unsigned buffer_size; 92b8e80941Smrg } text, bg, whitelines, color_prims; 93b8e80941Smrg 94b8e80941Smrg bool has_srgb; 95b8e80941Smrg}; 96848b8605Smrg 97848b8605Smrgstruct hud_graph { 98848b8605Smrg /* initialized by common code */ 99848b8605Smrg struct list_head head; 100848b8605Smrg struct hud_pane *pane; 101848b8605Smrg float color[3]; 102848b8605Smrg float *vertices; /* ring buffer of vertices */ 103848b8605Smrg 104848b8605Smrg /* name and query */ 105848b8605Smrg char name[128]; 106848b8605Smrg void *query_data; 107b8e80941Smrg void (*begin_query)(struct hud_graph *gr, struct pipe_context *pipe); 108b8e80941Smrg void (*query_new_value)(struct hud_graph *gr, struct pipe_context *pipe); 109b8e80941Smrg /* use this instead of ordinary free() */ 110b8e80941Smrg void (*free_query_data)(void *ptr, struct pipe_context *pipe); 111848b8605Smrg 112848b8605Smrg /* mutable variables */ 113848b8605Smrg unsigned num_vertices; 114848b8605Smrg unsigned index; /* vertex index being updated */ 115b8e80941Smrg double current_value; 116b8e80941Smrg FILE *fd; 117848b8605Smrg}; 118848b8605Smrg 119848b8605Smrgstruct hud_pane { 120848b8605Smrg struct list_head head; 121b8e80941Smrg struct hud_context *hud; 122b8e80941Smrg unsigned x1, y1, x2, y2, y_simple; 123848b8605Smrg unsigned inner_x1; 124848b8605Smrg unsigned inner_y1; 125848b8605Smrg unsigned inner_x2; 126848b8605Smrg unsigned inner_y2; 127848b8605Smrg unsigned inner_width; 128848b8605Smrg unsigned inner_height; 129848b8605Smrg float yscale; 130848b8605Smrg unsigned max_num_vertices; 131b8e80941Smrg unsigned last_line; /* index of the last describing line in the graph */ 132848b8605Smrg uint64_t max_value; 133b8e80941Smrg uint64_t initial_max_value; 134b8e80941Smrg uint64_t ceiling; 135b8e80941Smrg unsigned dyn_ceil_last_ran; 136b8e80941Smrg boolean dyn_ceiling; 137b8e80941Smrg boolean sort_items; 138b8e80941Smrg enum pipe_driver_query_type type; 139848b8605Smrg uint64_t period; /* in microseconds */ 140848b8605Smrg 141848b8605Smrg struct list_head graph_list; 142848b8605Smrg unsigned num_graphs; 143b8e80941Smrg unsigned next_color; 144848b8605Smrg}; 145848b8605Smrg 146848b8605Smrg 147848b8605Smrg/* core */ 148848b8605Smrgvoid hud_pane_add_graph(struct hud_pane *pane, struct hud_graph *gr); 149848b8605Smrgvoid hud_pane_set_max_value(struct hud_pane *pane, uint64_t value); 150b8e80941Smrgvoid hud_graph_add_value(struct hud_graph *gr, double value); 151848b8605Smrg 152848b8605Smrg/* graphs/queries */ 153b8e80941Smrgstruct hud_batch_query_context; 154b8e80941Smrg 155848b8605Smrg#define ALL_CPUS ~0 /* optionally set as cpu_index */ 156848b8605Smrg 157848b8605Smrgint hud_get_num_cpus(void); 158848b8605Smrg 159848b8605Smrgvoid hud_fps_graph_install(struct hud_pane *pane); 160b8e80941Smrgvoid hud_frametime_graph_install(struct hud_pane *pane); 161848b8605Smrgvoid hud_cpu_graph_install(struct hud_pane *pane, unsigned cpu_index); 162b8e80941Smrgvoid hud_thread_busy_install(struct hud_pane *pane, const char *name, bool main); 163b8e80941Smrgvoid hud_thread_counter_install(struct hud_pane *pane, const char *name, 164b8e80941Smrg enum hud_counter counter); 165b8e80941Smrgvoid hud_pipe_query_install(struct hud_batch_query_context **pbq, 166b8e80941Smrg struct hud_pane *pane, 167b8e80941Smrg const char *name, 168b8e80941Smrg enum pipe_query_type query_type, 169848b8605Smrg unsigned result_index, 170b8e80941Smrg uint64_t max_value, 171b8e80941Smrg enum pipe_driver_query_type type, 172b8e80941Smrg enum pipe_driver_query_result_type result_type, 173b8e80941Smrg unsigned flags); 174b8e80941Smrgboolean hud_driver_query_install(struct hud_batch_query_context **pbq, 175b8e80941Smrg struct hud_pane *pane, 176b8e80941Smrg struct pipe_screen *screen, const char *name); 177b8e80941Smrgvoid hud_batch_query_begin(struct hud_batch_query_context *bq, 178b8e80941Smrg struct pipe_context *pipe); 179b8e80941Smrgvoid hud_batch_query_update(struct hud_batch_query_context *bq, 180b8e80941Smrg struct pipe_context *pipe); 181b8e80941Smrgvoid hud_batch_query_cleanup(struct hud_batch_query_context **pbq, 182b8e80941Smrg struct pipe_context *pipe); 183b8e80941Smrg 184b8e80941Smrg#ifdef HAVE_GALLIUM_EXTRA_HUD 185b8e80941Smrgint hud_get_num_nics(bool displayhelp); 186b8e80941Smrg#define NIC_DIRECTION_RX 1 187b8e80941Smrg#define NIC_DIRECTION_TX 2 188b8e80941Smrg#define NIC_RSSI_DBM 3 189b8e80941Smrgvoid hud_nic_graph_install(struct hud_pane *pane, const char *nic_index, 190b8e80941Smrg unsigned int mode); 191b8e80941Smrg 192b8e80941Smrgint hud_get_num_disks(bool displayhelp); 193b8e80941Smrg#define DISKSTAT_RD 1 194b8e80941Smrg#define DISKSTAT_WR 2 195b8e80941Smrgvoid hud_diskstat_graph_install(struct hud_pane *pane, const char *dev_name, 196b8e80941Smrg unsigned int mode); 197b8e80941Smrg 198b8e80941Smrgint hud_get_num_cpufreq(bool displayhelp); 199b8e80941Smrg#define CPUFREQ_MINIMUM 1 200b8e80941Smrg#define CPUFREQ_CURRENT 2 201b8e80941Smrg#define CPUFREQ_MAXIMUM 3 202b8e80941Smrgvoid hud_cpufreq_graph_install(struct hud_pane *pane, int cpu_index, unsigned int mode); 203b8e80941Smrg#endif 204b8e80941Smrg 205b8e80941Smrg#ifdef HAVE_LIBSENSORS 206b8e80941Smrgint hud_get_num_sensors(bool displayhelp); 207b8e80941Smrg#define SENSORS_TEMP_CURRENT 1 208b8e80941Smrg#define SENSORS_TEMP_CRITICAL 2 209b8e80941Smrg#define SENSORS_VOLTAGE_CURRENT 3 210b8e80941Smrg#define SENSORS_CURRENT_CURRENT 4 211b8e80941Smrg#define SENSORS_POWER_CURRENT 5 212b8e80941Smrgvoid hud_sensors_temp_graph_install(struct hud_pane *pane, const char *dev_name, 213b8e80941Smrg unsigned int mode); 214b8e80941Smrg#endif 215848b8605Smrg 216848b8605Smrg#endif 217