1 /*
2 * Copyright (C) 2013 Rob Clark <robclark@freedesktop.org>
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 FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors:
24 * Rob Clark <robclark@freedesktop.org>
25 */
26
27 #ifndef FREEDRENO_QUERY_H_
28 #define FREEDRENO_QUERY_H_
29
30 #include "pipe/p_context.h"
31
32 #include "util/u_threaded_context.h"
33
34 #include "freedreno_util.h"
35
36 struct fd_context;
37 struct fd_query;
38 struct fd_resource;
39
40 struct fd_query_funcs {
41 void (*destroy_query)(struct fd_context *ctx, struct fd_query *q) dt;
42 void (*begin_query)(struct fd_context *ctx, struct fd_query *q) dt;
43 void (*end_query)(struct fd_context *ctx, struct fd_query *q) dt;
44 bool (*get_query_result)(struct fd_context *ctx, struct fd_query *q,
45 bool wait, union pipe_query_result *result);
46 void (*get_query_result_resource)(struct fd_context *ctx, struct fd_query *q,
47 enum pipe_query_flags flags,
48 enum pipe_query_value_type result_type,
49 int index, struct fd_resource *dst,
50 unsigned offset) dt;
51 };
52
53 struct fd_query {
54 struct threaded_query base;
55
56 const struct fd_query_funcs *funcs;
57 int type;
58 unsigned index;
59 };
60
61 static inline struct fd_query *
fd_query(struct pipe_query * pq)62 fd_query(struct pipe_query *pq)
63 {
64 return (struct fd_query *)pq;
65 }
66
67 #define FD_QUERY_DRAW_CALLS (PIPE_QUERY_DRIVER_SPECIFIC + 0)
68 #define FD_QUERY_BATCH_TOTAL \
69 (PIPE_QUERY_DRIVER_SPECIFIC + 1) /* total # of batches (submits) */
70 #define FD_QUERY_BATCH_SYSMEM \
71 (PIPE_QUERY_DRIVER_SPECIFIC + \
72 2) /* batches using system memory (GMEM bypass) */
73 #define FD_QUERY_BATCH_GMEM \
74 (PIPE_QUERY_DRIVER_SPECIFIC + 3) /* batches using GMEM */
75 #define FD_QUERY_BATCH_NONDRAW \
76 (PIPE_QUERY_DRIVER_SPECIFIC + 4) /* compute/blit batches */
77 #define FD_QUERY_BATCH_RESTORE \
78 (PIPE_QUERY_DRIVER_SPECIFIC + 5) /* batches requiring GMEM restore */
79 #define FD_QUERY_STAGING_UPLOADS \
80 (PIPE_QUERY_DRIVER_SPECIFIC + \
81 6) /* texture/buffer uploads using staging blit */
82 #define FD_QUERY_SHADOW_UPLOADS \
83 (PIPE_QUERY_DRIVER_SPECIFIC + \
84 7) /* texture/buffer uploads that shadowed rsc */
85 #define FD_QUERY_VS_REGS \
86 (PIPE_QUERY_DRIVER_SPECIFIC + \
87 8) /* avg # of VS registers (scaled up by 100x) */
88 #define FD_QUERY_FS_REGS \
89 (PIPE_QUERY_DRIVER_SPECIFIC + \
90 9) /* avg # of VS registers (scaled up by 100x) */
91 /* insert any new non-perfcntr queries here, the first perfcntr index
92 * needs to come last!
93 */
94 #define FD_QUERY_FIRST_PERFCNTR (PIPE_QUERY_DRIVER_SPECIFIC + 10)
95
96 void fd_query_screen_init(struct pipe_screen *pscreen);
97 void fd_query_context_init(struct pipe_context *pctx);
98
99 static inline bool
skip_begin_query(int type)100 skip_begin_query(int type)
101 {
102 switch (type) {
103 case PIPE_QUERY_TIMESTAMP:
104 case PIPE_QUERY_GPU_FINISHED:
105 return true;
106 default:
107 return false;
108 }
109 }
110
111 /* maps query_type to sample provider idx: */
112 static inline int
pidx(unsigned query_type)113 pidx(unsigned query_type)
114 {
115 switch (query_type) {
116 case PIPE_QUERY_OCCLUSION_COUNTER:
117 return 0;
118 case PIPE_QUERY_OCCLUSION_PREDICATE:
119 return 1;
120 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE:
121 return 2;
122 /* TODO currently queries only emitted in main pass (not in binning pass)..
123 * which is fine for occlusion query, but pretty much not anything else.
124 */
125 case PIPE_QUERY_TIME_ELAPSED:
126 return 3;
127 case PIPE_QUERY_TIMESTAMP:
128 return 4;
129
130 case PIPE_QUERY_PRIMITIVES_GENERATED:
131 return 5;
132 case PIPE_QUERY_PRIMITIVES_EMITTED:
133 return 6;
134 case PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE:
135 return 7;
136 case PIPE_QUERY_SO_OVERFLOW_PREDICATE:
137 return 8;
138 case PIPE_QUERY_PIPELINE_STATISTICS_SINGLE:
139 return 9;
140
141 default:
142 return -1;
143 }
144 }
145
146 /** Returns true if get_query_result is being called from the driver thread. */
147 static inline bool
fd_get_query_result_in_driver_thread(struct fd_query * q)148 fd_get_query_result_in_driver_thread(struct fd_query *q)
149 {
150 return !q->base.flushed;
151 }
152
153 #endif /* FREEDRENO_QUERY_H_ */
154