1 /*
2 * Copyright © 2017 Rob Clark <[email protected]>
3 * SPDX-License-Identifier: MIT
4 *
5 * Authors:
6 * Rob Clark <[email protected]>
7 */
8
9 #ifndef FREEDRENO_QUERY_ACC_H_
10 #define FREEDRENO_QUERY_ACC_H_
11
12 #include "util/list.h"
13
14 #include "freedreno_context.h"
15 #include "freedreno_query.h"
16 #include "freedreno_resource.h"
17
18 BEGINC;
19
20 /*
21 * Accumulated HW Queries:
22 *
23 * Unlike the original HW Queries in earlier adreno generations (see
24 * freedreno_query_hw.[ch], later generations can accumulate the per-
25 * tile results of some (a4xx) or all (a5xx+?) queries in the cmdstream.
26 * But we still need to handle pausing/resuming the query across stage
27 * changes (in particular when switching between batches).
28 *
29 * fd_acc_sample_provider:
30 * - one per accumulated query type, registered/implemented by gpu
31 * generation specific code
32 * - knows how to emit cmdstream to pause/resume a query instance
33 *
34 * fd_acc_query:
35 * - one instance per query object
36 * - each query object has it's own result buffer, which may
37 * span multiple batches, etc.
38 */
39
40 struct fd_acc_query;
41
42 /**
43 * Base class for all query samples, on the GPU 'avail' is written to
44 * one when the query result is available.
45 */
46 struct PACKED fd_acc_query_sample {
47 uint64_t avail;
48 };
49
50
51 /**
52 * Helper to assert sample struct field has required alignment (ie. to
53 * catch issues at compile time if struct fd_acc_query_sample header
54 * ever changed, and to make the hw requirements more obvious)
55 */
56 #define ASSERT_ALIGNED(type, field, nbytes) \
57 STATIC_ASSERT((offsetof(type, field) % nbytes) == 0)
58
59 struct fd_acc_sample_provider {
60 unsigned query_type;
61
62 /* Set if the provider should still count while !ctx->active_queries */
63 bool always;
64
65 unsigned size;
66
67 void (*resume)(struct fd_acc_query *aq, struct fd_batch *batch) dt;
68 void (*pause)(struct fd_acc_query *aq, struct fd_batch *batch) dt;
69
70 void (*result)(struct fd_acc_query *aq, struct fd_acc_query_sample *s,
71 union pipe_query_result *result);
72 void (*result_resource)(struct fd_acc_query *aq, struct fd_ringbuffer *ring,
73 enum pipe_query_value_type result_type, int index,
74 struct fd_resource *dst, unsigned offset);
75 };
76
77 struct fd_acc_query {
78 struct fd_query base;
79
80 const struct fd_acc_sample_provider *provider;
81
82 struct pipe_resource *prsc;
83
84 /* Pointer to the batch that our query has had resume() called on (if
85 * any).
86 */
87 struct fd_batch *batch;
88
89 /* usually the same as provider->size but for batch queries we
90 * need to calculate the size dynamically when the query is
91 * allocated:
92 */
93 unsigned size;
94
95 struct list_head node; /* list-node in ctx->active_acc_queries */
96
97 void *query_data; /* query specific data */
98 };
99
100 static inline struct fd_acc_query *
fd_acc_query(struct fd_query * q)101 fd_acc_query(struct fd_query *q)
102 {
103 return (struct fd_acc_query *)q;
104 }
105
106 struct fd_query *fd_acc_create_query(struct fd_context *ctx,
107 unsigned query_type, unsigned index);
108 struct fd_query *
109 fd_acc_create_query2(struct fd_context *ctx, unsigned query_type,
110 unsigned index,
111 const struct fd_acc_sample_provider *provider);
112 void fd_acc_query_update_batch(struct fd_batch *batch,
113 bool disable_all) assert_dt;
114 void
115 fd_acc_query_register_provider(struct pipe_context *pctx,
116 const struct fd_acc_sample_provider *provider);
117
118 static inline void
copy_result(struct fd_ringbuffer * ring,enum pipe_query_value_type result_type,struct fd_resource * dst,unsigned dst_offset,struct fd_resource * src,unsigned src_offset)119 copy_result(struct fd_ringbuffer *ring, enum pipe_query_value_type result_type,
120 struct fd_resource *dst, unsigned dst_offset,
121 struct fd_resource *src, unsigned src_offset)
122 {
123 fd_ringbuffer_attach_bo(ring, dst->bo);
124 fd_ringbuffer_attach_bo(ring, src->bo);
125
126 OUT_PKT7(ring, CP_MEM_TO_MEM, 5);
127 OUT_RING(ring, COND(result_type >= PIPE_QUERY_TYPE_I64, CP_MEM_TO_MEM_0_DOUBLE));
128 OUT_RELOC(ring, dst->bo, dst_offset, 0, 0);
129 OUT_RELOC(ring, src->bo, src_offset, 0, 0);
130 }
131
132 ENDC;
133
134 #endif /* FREEDRENO_QUERY_ACC_H_ */
135