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