]> git.cworth.org Git - fips/blob - metrics.h
Push oustanding-counter data down from context.c into metrics.c
[fips] / metrics.h
1 /* Copyright © 2013, Intel Corporation
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to deal
5  * in the Software without restriction, including without limitation the rights
6  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7  * copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19  * THE SOFTWARE.
20  */
21
22 #ifndef METRICS_H
23 #define METRICS_H
24
25 typedef enum
26 {
27         METRICS_OP_ACCUM,
28         METRICS_OP_BUFFER_DATA,
29         METRICS_OP_BUFFER_SUB_DATA,
30         METRICS_OP_BITMAP,
31         METRICS_OP_BLIT_FRAMEBUFFER,
32         METRICS_OP_CLEAR,
33         METRICS_OP_CLEAR_BUFFER_DATA,
34         METRICS_OP_CLEAR_TEX_IMAGE,
35         METRICS_OP_COPY_PIXELS,
36         METRICS_OP_COPY_TEX_IMAGE,
37         METRICS_OP_DRAW_PIXELS,
38         METRICS_OP_GET_TEX_IMAGE,
39         METRICS_OP_READ_PIXELS,
40         METRICS_OP_TEX_IMAGE,
41
42         /* METRICS_OP_SHADER must be last.
43          * 
44          * All larger values for metrics_op_t are interpreted as:
45          *
46          *      METRICS_OP_SHADER + shader_program_number
47          *
48          * to indicate a specific shader program.
49          */
50         METRICS_OP_SHADER
51 } metrics_op_t;
52
53 /* Timer query */
54 typedef struct timer_query
55 {
56         unsigned id;
57
58         metrics_op_t op;
59         struct timer_query *next;
60 } timer_query_t;
61
62 /* Performance-monitor query */
63 typedef struct monitor
64 {
65         unsigned id;
66
67         metrics_op_t op;
68         struct monitor *next;
69 } monitor_t;
70
71 typedef struct op_metrics
72 {
73         /* This happens to also be the index into the
74          * ctx->op_metrics array currently
75          */
76         metrics_op_t op;
77         double time_ns;
78
79         double **counters;
80 } op_metrics_t;
81
82 typedef struct metrics
83 {
84         metrics_op_t op;
85
86         /* GL_TIME_ELAPSED query for which glEndQuery has not yet
87          * been called. */
88         unsigned timer_begun_id;
89
90         /* GL_TIME_ELAPSED queries for which glEndQuery has been
91          * called, (but results have not yet been queried). */
92         timer_query_t *timer_head;
93         timer_query_t *timer_tail;
94
95         /* Performance monitor for which glEndPerfMonitorAMD has not
96          * yet been called. */
97         unsigned monitor_begun_id;
98
99         /* Performance monitors for which glEndPerfMonitorAMD has
100          * been called, (but results have not yet been queried). */
101         monitor_t *monitor_head;
102         monitor_t *monitor_tail;
103
104         int monitors_in_flight;
105
106         unsigned num_op_metrics;
107         op_metrics_t *op_metrics;
108 } metrics_t;
109
110 /* Initialize a metrics_t object for tracking metrics. */
111 void
112 metrics_init (metrics_t *metrics);
113
114 /* Cleanup a metrics_t object that's no longer needed. */
115 void
116 metrics_fini (metrics_t *metrics);
117
118 /* Start accumulating GPU time.
119  *
120  * The time accumulated will be accounted against the
121  * current program (as set with metrics_set_current_program).
122  */
123 void
124 metrics_counter_start (void);
125
126 /* Stop accumulating GPU time (stops the most-recently started counter) */
127 void
128 metrics_counter_stop (void);
129
130 /* Set a metrics_op_t value to indicate what kind of operation is
131  * being performed.
132  *
133  * The metrics-tracking code will account for timings by accumulating
134  * measured counter values into a separate counter for each
135  * metrics_op_t value, (so that the report can describe which
136  * operations are the most expensive).
137  *
138  * In addition, for the value METRICS_OP_SHADER, each specific shader
139  * program can be distinguished. To accomplish this, pass a value of
140  * METRICS_OP_SHADER + shader_program_number to this function.
141  */
142 void
143 metrics_set_current_op (metrics_op_t op);
144
145 /* Return the current metrics_op_t value, (the value most-recently-set
146  * with a call to metrics_set_current_op).
147  */
148 metrics_op_t
149 metrics_get_current_op (void);
150
151 /* Should be called at the end of every function wrapper for a
152  * function that ends a frame, (glXSwapBuffers and similar).
153  *
154  * This function performs whatever bookkeeping is necessary to
155  * generate a timing report, then emits that report.
156  */
157 void
158 metrics_end_frame (void);
159
160 /* Process outstanding metrics requests, accumulating results.
161  *
162  * This function is called automatically by metrics_end_frame.
163  *
164  * During a frame, it may be important to call this function to avoid
165  * too many oustanding timer/performance-monitor queries. At the same
166  * time, it's important not to call this function too frequently,
167  * since collection of metrics information will result in flushes of
168  * the OpenGL pipeline which can interfere with the behavior being
169  * measured.
170  */
171 void
172 metrics_collect_available (void);
173
174 #endif