1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
4 * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * Rob Clark <robclark@freedesktop.org>
29 #ifndef FREEDRENO_QUERY_HW_H_
30 #define FREEDRENO_QUERY_HW_H_
32 #include "util/list.h"
34 #include "freedreno_query.h"
35 #include "freedreno_context.h"
41 * See: https://github.com/freedreno/freedreno/wiki/Queries#hardware-queries
43 * Hardware queries will be specific to gpu generation, but they need
44 * some common infrastructure for triggering start/stop samples at
45 * various points (for example, to exclude mem2gmem/gmem2mem or clear)
46 * as well as per tile tracking.
48 * NOTE: in at least some cases hw writes sample values to memory addr
49 * specified in some register. So we don't really have the option to
50 * just sample the same counter multiple times for multiple different
51 * queries with the same query_type. So we cache per sample provider
52 * the most recent sample since the last draw. This way multiple
53 * sample periods for multiple queries can reference the same sample.
55 * fd_hw_sample_provider:
56 * - one per query type, registered/implemented by gpu generation
58 * - can construct fd_hw_samples on demand
59 * - most recent sample (since last draw) cached so multiple
60 * different queries can ref the same sample
63 * - abstracts one snapshot of counter value(s) across N tiles
64 * - backing object not allocated until submit time when number
65 * of samples and number of tiles is known
67 * fd_hw_sample_period:
68 * - consists of start and stop sample
69 * - a query accumulates a list of sample periods
70 * - the query result is the sum of the sample periods
73 struct fd_hw_sample_provider
{
76 /* stages applicable to the query type: */
77 enum fd_render_stage active
;
79 /* Optional hook for enabling a counter. Guaranteed to happen
80 * at least once before the first ->get_sample() in a batch.
82 void (*enable
)(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
);
84 /* when a new sample is required, emit appropriate cmdstream
85 * and return a sample object:
87 struct fd_hw_sample
*(*get_sample
)(struct fd_context
*ctx
,
88 struct fd_ringbuffer
*ring
);
90 /* accumulate the results from specified sample period: */
91 void (*accumulate_result
)(struct fd_context
*ctx
,
92 const void *start
, const void *end
,
93 union pipe_query_result
*result
);
97 struct pipe_reference reference
; /* keep this first */
99 /* offset and size of the sample are know at the time the
100 * sample is constructed.
105 /* backing object, offset/stride/etc are determined not when
106 * the sample is constructed, but when the batch is submitted.
107 * This way we can defer allocation until total # of requested
108 * samples, and total # of tiles, is known.
112 uint32_t tile_stride
;
115 struct fd_hw_sample_period
;
118 struct fd_query base
;
120 const struct fd_hw_sample_provider
*provider
;
122 /* list of fd_hw_sample_period in previous submits: */
123 struct list_head periods
;
125 /* list of fd_hw_sample_period's in current submit: */
126 struct list_head current_periods
;
128 /* if active and not paused, the current sample period (not
129 * yet added to current_periods):
131 struct fd_hw_sample_period
*period
;
133 struct list_head list
; /* list-node in ctx->active_queries */
136 static inline struct fd_hw_query
*
137 fd_hw_query(struct fd_query
*q
)
139 return (struct fd_hw_query
*)q
;
142 struct fd_query
* fd_hw_create_query(struct fd_context
*ctx
, unsigned query_type
);
143 /* helper for sample providers: */
144 struct fd_hw_sample
* fd_hw_sample_init(struct fd_context
*ctx
, uint32_t size
);
145 /* don't call directly, use fd_hw_sample_reference() */
146 void __fd_hw_sample_destroy(struct fd_context
*ctx
, struct fd_hw_sample
*samp
);
147 void fd_hw_query_prepare(struct fd_context
*ctx
, uint32_t num_tiles
);
148 void fd_hw_query_prepare_tile(struct fd_context
*ctx
, uint32_t n
,
149 struct fd_ringbuffer
*ring
);
150 void fd_hw_query_set_stage(struct fd_context
*ctx
,
151 struct fd_ringbuffer
*ring
, enum fd_render_stage stage
);
152 void fd_hw_query_enable(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
);
153 void fd_hw_query_register_provider(struct pipe_context
*pctx
,
154 const struct fd_hw_sample_provider
*provider
);
155 void fd_hw_query_init(struct pipe_context
*pctx
);
156 void fd_hw_query_fini(struct pipe_context
*pctx
);
159 fd_hw_sample_reference(struct fd_context
*ctx
,
160 struct fd_hw_sample
**ptr
, struct fd_hw_sample
*samp
)
162 struct fd_hw_sample
*old_samp
= *ptr
;
164 if (pipe_reference(&(*ptr
)->reference
, &samp
->reference
))
165 __fd_hw_sample_destroy(ctx
, old_samp
);
170 #endif /* FREEDRENO_QUERY_HW_H_ */