i965: extract performance query metrics
[mesa.git] / src / mesa / drivers / dri / i965 / brw_performance_query.h
1 /*
2 * Copyright © 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #ifndef BRW_PERFORMANCE_QUERY_H
25 #define BRW_PERFORMANCE_QUERY_H
26
27 #include <stdint.h>
28
29 #include "brw_context.h"
30
31 struct gen_perf_query_info;
32
33 /*
34 * When currently allocate only one page for pipeline statistics queries. Here
35 * we derived the maximum number of counters for that amount.
36 */
37 #define STATS_BO_SIZE 4096
38 #define STATS_BO_END_OFFSET_BYTES (STATS_BO_SIZE / 2)
39 #define MAX_STAT_COUNTERS (STATS_BO_END_OFFSET_BYTES / 8)
40
41 /*
42 * The largest OA formats we can use include:
43 * For Haswell:
44 * 1 timestamp, 45 A counters, 8 B counters and 8 C counters.
45 * For Gen8+
46 * 1 timestamp, 1 clock, 36 A counters, 8 B counters and 8 C counters
47 */
48 #define MAX_OA_REPORT_COUNTERS 62
49
50 /**
51 * i965 representation of a performance query object.
52 *
53 * NB: We want to keep this structure relatively lean considering that
54 * applications may expect to allocate enough objects to be able to
55 * query around all draw calls in a frame.
56 */
57 struct brw_perf_query_object
58 {
59 struct gl_perf_query_object base;
60
61 const struct gen_perf_query_info *query;
62
63 /* See query->kind to know which state below is in use... */
64 union {
65 struct {
66
67 /**
68 * BO containing OA counter snapshots at query Begin/End time.
69 */
70 struct brw_bo *bo;
71
72 /**
73 * Address of mapped of @bo
74 */
75 void *map;
76
77 /**
78 * The MI_REPORT_PERF_COUNT command lets us specify a unique
79 * ID that will be reflected in the resulting OA report
80 * that's written by the GPU. This is the ID we're expecting
81 * in the begin report and the the end report should be
82 * @begin_report_id + 1.
83 */
84 int begin_report_id;
85
86 /**
87 * Reference the head of the brw->perfquery.sample_buffers
88 * list at the time that the query started (so we only need
89 * to look at nodes after this point when looking for samples
90 * related to this query)
91 *
92 * (See struct brw_oa_sample_buf description for more details)
93 */
94 struct exec_node *samples_head;
95
96 /**
97 * Storage for the final accumulated OA counters.
98 */
99 uint64_t accumulator[MAX_OA_REPORT_COUNTERS];
100
101 /**
102 * Hw ID used by the context on which the query was running.
103 */
104 uint32_t hw_id;
105
106 /**
107 * false while in the unaccumulated_elements list, and set to
108 * true when the final, end MI_RPC snapshot has been
109 * accumulated.
110 */
111 bool results_accumulated;
112
113 /**
114 * Number of reports accumulated to produce the results.
115 */
116 uint32_t reports_accumulated;
117
118 /**
119 * Frequency of the GT at begin and end of the query.
120 */
121 uint64_t gt_frequency[2];
122
123 /**
124 * Frequency in the slices of the GT at the begin and end of the
125 * query.
126 */
127 uint64_t slice_frequency[2];
128
129 /**
130 * Frequency in the unslice of the GT at the begin and end of the
131 * query.
132 */
133 uint64_t unslice_frequency[2];
134 } oa;
135
136 struct {
137 /**
138 * BO containing starting and ending snapshots for the
139 * statistics counters.
140 */
141 struct brw_bo *bo;
142 } pipeline_stats;
143 };
144 };
145
146 int brw_perf_query_get_mdapi_oa_data(struct brw_context *brw,
147 struct brw_perf_query_object *obj,
148 size_t data_size,
149 uint8_t *data);
150 void brw_perf_query_register_mdapi_oa_query(struct brw_context *brw);
151 void brw_perf_query_register_mdapi_statistic_query(struct brw_context *brw);
152
153 #endif /* BRW_PERFORMANCE_QUERY_H */