summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/iris/iris_performance_query.c
blob: f3a56ed83dab0058577feda27789b68df6b1a0fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
 * Copyright © 2019 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#include <xf86drm.h>

#include "iris_context.h"
#include "iris_perf.h"

struct iris_perf_query {
   struct gl_perf_query_object base;
   struct intel_perf_query_object *query;
};

static unsigned
iris_init_perf_query_info(struct pipe_context *pipe)
{
   struct iris_context *ice = (void *) pipe;
   struct iris_screen *screen = (struct iris_screen *) ice->ctx.screen;
   struct intel_perf_config *perf_cfg = NULL;

   /* make sure pipe perf counter type/data-type enums are matched with intel_perf's */
   STATIC_ASSERT(PIPE_PERF_COUNTER_TYPE_EVENT == (enum pipe_perf_counter_type)GEN_PERF_COUNTER_TYPE_EVENT);
   STATIC_ASSERT(PIPE_PERF_COUNTER_TYPE_DURATION_NORM == (enum pipe_perf_counter_type)GEN_PERF_COUNTER_TYPE_DURATION_NORM);
   STATIC_ASSERT(PIPE_PERF_COUNTER_TYPE_DURATION_RAW == (enum pipe_perf_counter_type)GEN_PERF_COUNTER_TYPE_DURATION_RAW);
   STATIC_ASSERT(PIPE_PERF_COUNTER_TYPE_THROUGHPUT == (enum pipe_perf_counter_type)GEN_PERF_COUNTER_TYPE_THROUGHPUT);
   STATIC_ASSERT(PIPE_PERF_COUNTER_TYPE_RAW == (enum pipe_perf_counter_type)GEN_PERF_COUNTER_TYPE_RAW);

   STATIC_ASSERT(PIPE_PERF_COUNTER_DATA_TYPE_BOOL32 == (enum pipe_perf_counter_data_type)GEN_PERF_COUNTER_DATA_TYPE_BOOL32);
   STATIC_ASSERT(PIPE_PERF_COUNTER_DATA_TYPE_UINT32 == (enum pipe_perf_counter_data_type)GEN_PERF_COUNTER_DATA_TYPE_UINT32);
   STATIC_ASSERT(PIPE_PERF_COUNTER_DATA_TYPE_UINT64 == (enum pipe_perf_counter_data_type)GEN_PERF_COUNTER_DATA_TYPE_UINT64);
   STATIC_ASSERT(PIPE_PERF_COUNTER_DATA_TYPE_FLOAT == (enum pipe_perf_counter_data_type)GEN_PERF_COUNTER_DATA_TYPE_FLOAT);
   STATIC_ASSERT(PIPE_PERF_COUNTER_DATA_TYPE_DOUBLE == (enum pipe_perf_counter_data_type)GEN_PERF_COUNTER_DATA_TYPE_DOUBLE);

   if (!ice->perf_ctx)
      ice->perf_ctx = intel_perf_new_context(ice);

   if (unlikely(!ice->perf_ctx))
      return 0;

   perf_cfg = intel_perf_config(ice->perf_ctx);

   if (perf_cfg)
      return perf_cfg->n_queries;

   perf_cfg = intel_perf_new(ice->perf_ctx);

   iris_perf_init_vtbl(perf_cfg);

   intel_perf_init_context(ice->perf_ctx,
                         perf_cfg,
                         ice,
                         ice,
                         screen->bufmgr,
                         &screen->devinfo,
                         ice->batches[IRIS_BATCH_RENDER].hw_ctx_id,
                         screen->fd);

   intel_perf_init_metrics(perf_cfg, &screen->devinfo, screen->fd, true /* pipeline_statistics */);

   return perf_cfg->n_queries;
}

static struct pipe_query *
iris_new_perf_query_obj(struct pipe_context *pipe, unsigned query_index)
{
   struct iris_context *ice = (void *) pipe;
   struct intel_perf_context *perf_ctx = ice->perf_ctx;
   struct intel_perf_query_object * obj = intel_perf_new_query(perf_ctx, query_index);
   if (unlikely(!obj))
      return NULL;

   struct iris_perf_query *q = calloc(1, sizeof(struct iris_perf_query));
   if (unlikely(!q)) {
      intel_perf_delete_query(perf_ctx, obj);
      return NULL;
   }

   q->query = obj;
   return (struct pipe_query *)&q->base;
}

static bool
iris_begin_perf_query(struct pipe_context *pipe, struct pipe_query *q)
{
   struct iris_context *ice = (void *) pipe;
   struct iris_perf_query *perf_query= (struct iris_perf_query *) q;
   struct intel_perf_query_object *obj = perf_query->query;
   struct intel_perf_context *perf_ctx = ice->perf_ctx;

   return intel_perf_begin_query(perf_ctx, obj);
}

static void
iris_end_perf_query(struct pipe_context *pipe, struct pipe_query *q)
{
   struct iris_context *ice = (void *) pipe;
   struct iris_perf_query *perf_query = (struct iris_perf_query *) q;
   struct intel_perf_query_object *obj = perf_query->query;
   struct intel_perf_context *perf_ctx = ice->perf_ctx;

   intel_perf_end_query(perf_ctx, obj);
}

static void
iris_delete_perf_query(struct pipe_context *pipe, struct pipe_query *q)
{
   struct iris_context *ice = (void *) pipe;
   struct iris_perf_query *perf_query = (struct iris_perf_query *) q;
   struct intel_perf_query_object *obj = perf_query->query;
   struct intel_perf_context *perf_ctx = ice->perf_ctx;

   intel_perf_delete_query(perf_ctx, obj);
   free(q);
}

static void
iris_get_perf_query_info(struct pipe_context *pipe,
                         unsigned query_index,
                         const char **name,
                         uint32_t *data_size,
                         uint32_t *n_counters,
                         uint32_t *n_active)
{
   struct iris_context *ice = (void *) pipe;
   struct intel_perf_context *perf_ctx = ice->perf_ctx;
   struct intel_perf_config *perf_cfg = intel_perf_config(perf_ctx);
   const struct intel_perf_query_info *info = &perf_cfg->queries[query_index];

   *name = info->name;
   *data_size = info->data_size;
   *n_counters = info->n_counters;
   *n_active = intel_perf_active_queries(perf_ctx, info);
}

static void
iris_get_perf_counter_info(struct pipe_context *pipe,
                           unsigned query_index,
                           unsigned counter_index,
                           const char **name,
                           const char **desc,
                           uint32_t *offset,
                           uint32_t *data_size,
                           uint32_t *type_enum,
                           uint32_t *data_type_enum,
                           uint64_t *raw_max)
{
   struct iris_context *ice = (void *) pipe;
   struct intel_perf_context *perf_ctx = ice->perf_ctx;
   struct intel_perf_config *perf_cfg = intel_perf_config(perf_ctx);
   const struct intel_perf_query_info *info = &perf_cfg->queries[query_index];
   const struct intel_perf_query_counter *counter = &info->counters[counter_index];

   *name = counter->name;
   *desc = counter->desc;
   *offset = counter->offset;
   *data_size = intel_perf_query_counter_get_size(counter);
   *type_enum = counter->type;
   *data_type_enum = counter->data_type;
   *raw_max = counter->raw_max;
}

static void
iris_wait_perf_query(struct pipe_context *pipe, struct pipe_query *q)
{
   struct iris_context *ice = (void *) pipe;
   struct iris_perf_query *perf_query = (struct iris_perf_query *) q;
   struct intel_perf_query_object *obj = perf_query->query;
   struct intel_perf_context *perf_ctx = ice->perf_ctx;

   intel_perf_wait_query(perf_ctx, obj, &ice->batches[IRIS_BATCH_RENDER]);
}

static bool
iris_is_perf_query_ready(struct pipe_context *pipe, struct pipe_query *q)
{
   struct iris_context *ice = (void *) pipe;
   struct iris_perf_query *perf_query = (struct iris_perf_query *) q;
   struct intel_perf_query_object *obj = perf_query->query;
   struct intel_perf_context *perf_ctx = ice->perf_ctx;

   if (perf_query->base.Ready)
      return true;

   return intel_perf_is_query_ready(perf_ctx, obj, &ice->batches[IRIS_BATCH_RENDER]);
}

static void
iris_get_perf_query_data(struct pipe_context *pipe,
                         struct pipe_query *q,
                         size_t data_size,
                         uint32_t *data,
                         uint32_t *bytes_written)
{
   struct iris_context *ice = (void *) pipe;
   struct iris_perf_query *perf_query = (struct iris_perf_query *) q;
   struct intel_perf_query_object *obj = perf_query->query;
   struct intel_perf_context *perf_ctx = ice->perf_ctx;

   intel_perf_get_query_data(perf_ctx, obj, &ice->batches[IRIS_BATCH_RENDER],
         data_size, data, bytes_written);
}

void
iris_init_perfquery_functions(struct pipe_context *ctx)
{
   ctx->init_intel_perf_query_info = iris_init_perf_query_info;
   ctx->get_intel_perf_query_info = iris_get_perf_query_info;
   ctx->get_intel_perf_query_counter_info = iris_get_perf_counter_info;
   ctx->new_intel_perf_query_obj = iris_new_perf_query_obj;
   ctx->begin_intel_perf_query = iris_begin_perf_query;
   ctx->end_intel_perf_query = iris_end_perf_query;
   ctx->delete_intel_perf_query = iris_delete_perf_query;
   ctx->wait_intel_perf_query = iris_wait_perf_query;
   ctx->is_intel_perf_query_ready = iris_is_perf_query_ready;
   ctx->get_intel_perf_query_data = iris_get_perf_query_data;
}