1 /************************************************************************** 2 * 3 * Copyright 2013 Marek Olšák <[email protected]> 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 "hud/hud_context.h" 36 #include "cso_cache/cso_context.h" 37 38 enum hud_counter { 39 HUD_COUNTER_OFFLOADED, 40 HUD_COUNTER_DIRECT, 41 HUD_COUNTER_SYNCS, 42 HUD_COUNTER_BATCHES, 43 }; 44 45 struct hud_context { 46 int refcount; 47 bool simple; 48 49 /* Context where queries are executed. */ 50 struct pipe_context *record_pipe; 51 52 /* Context where the HUD is drawn: */ 53 struct pipe_context *pipe; 54 struct cso_context *cso; 55 56 /* For notifying st_context to rebind states that we clobbered. */ 57 struct st_context *st; 58 hud_st_invalidate_state_func st_invalidate_state; 59 60 struct hud_batch_query_context *batch_query; 61 struct list_head pane_list; 62 63 struct util_queue_monitoring *monitored_queue; 64 65 /* states */ 66 struct pipe_blend_state no_blend, alpha_blend; 67 struct pipe_depth_stencil_alpha_state dsa; 68 void *fs_color, *fs_text; 69 struct pipe_rasterizer_state rasterizer, rasterizer_aa_lines; 70 void *vs_color, *vs_text; 71 struct cso_velems_state velems; 72 struct cso_velems_state text_velems; 73 74 /* font */ 75 struct util_font font; 76 struct pipe_sampler_view *font_sampler_view; 77 struct pipe_sampler_state font_sampler_state; 78 79 /* VS constant buffer */ 80 struct { 81 float color[4]; 82 float two_div_fb_width; 83 float two_div_fb_height; 84 float translate[2]; 85 float scale[2]; 86 float padding[2]; 87 float rotate[4]; 88 } constants; 89 struct pipe_constant_buffer constbuf; 90 91 unsigned fb_width, fb_height; 92 93 /* vertices for text and background drawing are accumulated here and then 94 * drawn all at once */ 95 struct vertex_queue { 96 float *vertices; 97 struct pipe_vertex_buffer vbuf; 98 unsigned max_num_vertices; 99 unsigned num_vertices; 100 unsigned buffer_size; 101 } text, bg, whitelines; 102 103 bool has_srgb; 104 }; 105 106 struct hud_graph { 107 /* initialized by common code */ 108 struct list_head head; 109 struct hud_pane *pane; 110 float color[3]; 111 float *vertices; /* ring buffer of vertices */ 112 113 /* name and query */ 114 char name[128]; 115 void *query_data; 116 void (*begin_query)(struct hud_graph *gr, struct pipe_context *pipe); 117 void (*query_new_value)(struct hud_graph *gr, struct pipe_context *pipe); 118 /* use this instead of ordinary free() */ 119 void (*free_query_data)(void *ptr, struct pipe_context *pipe); 120 121 /* mutable variables */ 122 unsigned num_vertices; 123 unsigned index; /* vertex index being updated */ 124 double current_value; 125 FILE *fd; 126 const char *separator; 127 }; 128 129 struct hud_pane { 130 struct list_head head; 131 struct hud_context *hud; 132 unsigned x1, y1, x2, y2, y_simple; 133 unsigned inner_x1; 134 unsigned inner_y1; 135 unsigned inner_x2; 136 unsigned inner_y2; 137 unsigned inner_width; 138 unsigned inner_height; 139 float yscale; 140 unsigned max_num_vertices; 141 unsigned last_line; /* index of the last describing line in the graph */ 142 uint64_t max_value; 143 uint64_t initial_max_value; 144 uint64_t ceiling; 145 unsigned dyn_ceil_last_ran; 146 bool dyn_ceiling; 147 bool sort_items; 148 enum pipe_driver_query_type type; 149 uint64_t period; /* in microseconds */ 150 151 struct list_head graph_list; 152 unsigned num_graphs; 153 unsigned next_color; 154 }; 155 156 157 /* core */ 158 void hud_pane_add_graph(struct hud_pane *pane, struct hud_graph *gr); 159 void hud_pane_set_max_value(struct hud_pane *pane, uint64_t value); 160 void hud_graph_add_value(struct hud_graph *gr, double value); 161 162 /* graphs/queries */ 163 struct hud_batch_query_context; 164 165 #define ALL_CPUS ~0 /* optionally set as cpu_index */ 166 167 int hud_get_num_cpus(void); 168 169 void hud_fps_graph_install(struct hud_pane *pane); 170 void hud_frametime_graph_install(struct hud_pane *pane); 171 void hud_cpu_graph_install(struct hud_pane *pane, unsigned cpu_index); 172 void hud_thread_busy_install(struct hud_pane *pane, const char *name, bool main); 173 void hud_thread_counter_install(struct hud_pane *pane, const char *name, 174 enum hud_counter counter); 175 void hud_pipe_query_install(struct hud_batch_query_context **pbq, 176 struct hud_pane *pane, 177 const char *name, 178 enum pipe_query_type query_type, 179 unsigned result_index, 180 uint64_t max_value, 181 enum pipe_driver_query_type type, 182 enum pipe_driver_query_result_type result_type, 183 unsigned flags); 184 bool hud_driver_query_install(struct hud_batch_query_context **pbq, 185 struct hud_pane *pane, 186 struct pipe_screen *screen, const char *name); 187 void hud_batch_query_begin(struct hud_batch_query_context *bq, 188 struct pipe_context *pipe); 189 void hud_batch_query_update(struct hud_batch_query_context *bq, 190 struct pipe_context *pipe); 191 void hud_batch_query_cleanup(struct hud_batch_query_context **pbq, 192 struct pipe_context *pipe); 193 194 #ifdef HAVE_GALLIUM_EXTRA_HUD 195 int hud_get_num_nics(bool displayhelp); 196 #define NIC_DIRECTION_RX 1 197 #define NIC_DIRECTION_TX 2 198 #define NIC_RSSI_DBM 3 199 void hud_nic_graph_install(struct hud_pane *pane, const char *nic_index, 200 unsigned int mode); 201 202 int hud_get_num_disks(bool displayhelp); 203 #define DISKSTAT_RD 1 204 #define DISKSTAT_WR 2 205 void hud_diskstat_graph_install(struct hud_pane *pane, const char *dev_name, 206 unsigned int mode); 207 208 int hud_get_num_cpufreq(bool displayhelp); 209 #define CPUFREQ_MINIMUM 1 210 #define CPUFREQ_CURRENT 2 211 #define CPUFREQ_MAXIMUM 3 212 void hud_cpufreq_graph_install(struct hud_pane *pane, int cpu_index, unsigned int mode); 213 #endif 214 215 #ifdef HAVE_LIBSENSORS 216 int hud_get_num_sensors(bool displayhelp); 217 #define SENSORS_TEMP_CURRENT 1 218 #define SENSORS_TEMP_CRITICAL 2 219 #define SENSORS_VOLTAGE_CURRENT 3 220 #define SENSORS_CURRENT_CURRENT 4 221 #define SENSORS_POWER_CURRENT 5 222 void hud_sensors_temp_graph_install(struct hud_pane *pane, const char *dev_name, 223 unsigned int mode); 224 #endif 225 226 #endif 227