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