1 /************************************************************************** 2 * 3 * Copyright 2013 Marek Olšák <maraeo@gmail.com> 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28 #ifndef HUD_PRIVATE_H 29 #define HUD_PRIVATE_H 30 31 #include "pipe/p_context.h" 32 #include "pipe/p_state.h" 33 #include "util/list.h" 34 #include "hud/font.h" 35 #include "cso_cache/cso_context.h" 36 37 enum hud_counter { 38 HUD_COUNTER_OFFLOADED, 39 HUD_COUNTER_DIRECT, 40 HUD_COUNTER_SYNCS, 41 }; 42 43 struct hud_context { 44 int refcount; 45 bool simple; 46 47 /* Context where queries are executed. */ 48 struct pipe_context *record_pipe; 49 50 /* Context where the HUD is drawn: */ 51 struct pipe_context *pipe; 52 struct cso_context *cso; 53 struct st_context_iface *st; 54 55 struct hud_batch_query_context *batch_query; 56 struct list_head pane_list; 57 58 struct util_queue_monitoring *monitored_queue; 59 60 /* states */ 61 struct pipe_blend_state no_blend, alpha_blend; 62 struct pipe_depth_stencil_alpha_state dsa; 63 void *fs_color, *fs_text; 64 struct pipe_rasterizer_state rasterizer, rasterizer_aa_lines; 65 void *vs_color, *vs_text; 66 struct cso_velems_state velems; 67 68 /* font */ 69 struct util_font font; 70 struct pipe_sampler_view *font_sampler_view; 71 struct pipe_sampler_state font_sampler_state; 72 73 /* VS constant buffer */ 74 struct { 75 float color[4]; 76 float two_div_fb_width; 77 float two_div_fb_height; 78 float translate[2]; 79 float scale[2]; 80 float padding[2]; 81 } constants; 82 struct pipe_constant_buffer constbuf; 83 84 unsigned fb_width, fb_height; 85 86 /* vertices for text and background drawing are accumulated here and then 87 * drawn all at once */ 88 struct vertex_queue { 89 float *vertices; 90 struct pipe_vertex_buffer vbuf; 91 unsigned max_num_vertices; 92 unsigned num_vertices; 93 unsigned buffer_size; 94 } text, bg, whitelines; 95 96 bool has_srgb; 97 }; 98 99 struct hud_graph { 100 /* initialized by common code */ 101 struct list_head head; 102 struct hud_pane *pane; 103 float color[3]; 104 float *vertices; /* ring buffer of vertices */ 105 106 /* name and query */ 107 char name[128]; 108 void *query_data; 109 void (*begin_query)(struct hud_graph *gr, struct pipe_context *pipe); 110 void (*query_new_value)(struct hud_graph *gr, struct pipe_context *pipe); 111 /* use this instead of ordinary free() */ 112 void (*free_query_data)(void *ptr, struct pipe_context *pipe); 113 114 /* mutable variables */ 115 unsigned num_vertices; 116 unsigned index; /* vertex index being updated */ 117 double current_value; 118 FILE *fd; 119 }; 120 121 struct hud_pane { 122 struct list_head head; 123 struct hud_context *hud; 124 unsigned x1, y1, x2, y2, y_simple; 125 unsigned inner_x1; 126 unsigned inner_y1; 127 unsigned inner_x2; 128 unsigned inner_y2; 129 unsigned inner_width; 130 unsigned inner_height; 131 float yscale; 132 unsigned max_num_vertices; 133 unsigned last_line; /* index of the last describing line in the graph */ 134 uint64_t max_value; 135 uint64_t initial_max_value; 136 uint64_t ceiling; 137 unsigned dyn_ceil_last_ran; 138 boolean dyn_ceiling; 139 boolean sort_items; 140 enum pipe_driver_query_type type; 141 uint64_t period; /* in microseconds */ 142 143 struct list_head graph_list; 144 unsigned num_graphs; 145 unsigned next_color; 146 }; 147 148 149 /* core */ 150 void hud_pane_add_graph(struct hud_pane *pane, struct hud_graph *gr); 151 void hud_pane_set_max_value(struct hud_pane *pane, uint64_t value); 152 void hud_graph_add_value(struct hud_graph *gr, double value); 153 154 /* graphs/queries */ 155 struct hud_batch_query_context; 156 157 #define ALL_CPUS ~0 /* optionally set as cpu_index */ 158 159 int hud_get_num_cpus(void); 160 161 void hud_fps_graph_install(struct hud_pane *pane); 162 void hud_frametime_graph_install(struct hud_pane *pane); 163 void hud_cpu_graph_install(struct hud_pane *pane, unsigned cpu_index); 164 void hud_thread_busy_install(struct hud_pane *pane, const char *name, bool main); 165 void hud_thread_counter_install(struct hud_pane *pane, const char *name, 166 enum hud_counter counter); 167 void hud_pipe_query_install(struct hud_batch_query_context **pbq, 168 struct hud_pane *pane, 169 const char *name, 170 enum pipe_query_type query_type, 171 unsigned result_index, 172 uint64_t max_value, 173 enum pipe_driver_query_type type, 174 enum pipe_driver_query_result_type result_type, 175 unsigned flags); 176 boolean hud_driver_query_install(struct hud_batch_query_context **pbq, 177 struct hud_pane *pane, 178 struct pipe_screen *screen, const char *name); 179 void hud_batch_query_begin(struct hud_batch_query_context *bq, 180 struct pipe_context *pipe); 181 void hud_batch_query_update(struct hud_batch_query_context *bq, 182 struct pipe_context *pipe); 183 void hud_batch_query_cleanup(struct hud_batch_query_context **pbq, 184 struct pipe_context *pipe); 185 186 #ifdef HAVE_GALLIUM_EXTRA_HUD 187 int hud_get_num_nics(bool displayhelp); 188 #define NIC_DIRECTION_RX 1 189 #define NIC_DIRECTION_TX 2 190 #define NIC_RSSI_DBM 3 191 void hud_nic_graph_install(struct hud_pane *pane, const char *nic_index, 192 unsigned int mode); 193 194 int hud_get_num_disks(bool displayhelp); 195 #define DISKSTAT_RD 1 196 #define DISKSTAT_WR 2 197 void hud_diskstat_graph_install(struct hud_pane *pane, const char *dev_name, 198 unsigned int mode); 199 200 int hud_get_num_cpufreq(bool displayhelp); 201 #define CPUFREQ_MINIMUM 1 202 #define CPUFREQ_CURRENT 2 203 #define CPUFREQ_MAXIMUM 3 204 void hud_cpufreq_graph_install(struct hud_pane *pane, int cpu_index, unsigned int mode); 205 #endif 206 207 #ifdef HAVE_LIBSENSORS 208 int hud_get_num_sensors(bool displayhelp); 209 #define SENSORS_TEMP_CURRENT 1 210 #define SENSORS_TEMP_CRITICAL 2 211 #define SENSORS_VOLTAGE_CURRENT 3 212 #define SENSORS_CURRENT_CURRENT 4 213 #define SENSORS_POWER_CURRENT 5 214 void hud_sensors_temp_graph_install(struct hud_pane *pane, const char *dev_name, 215 unsigned int mode); 216 #endif 217 218 #endif 219