1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright (C) 2013 Rob Clark <robclark@freedesktop.org>
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21bf215546Sopenharmony_ci * SOFTWARE.
22bf215546Sopenharmony_ci *
23bf215546Sopenharmony_ci * Authors:
24bf215546Sopenharmony_ci *    Rob Clark <robclark@freedesktop.org>
25bf215546Sopenharmony_ci */
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#ifndef FREEDRENO_QUERY_H_
28bf215546Sopenharmony_ci#define FREEDRENO_QUERY_H_
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ci#include "pipe/p_context.h"
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_ci#include "util/u_threaded_context.h"
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#include "freedreno_util.h"
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_cistruct fd_context;
37bf215546Sopenharmony_cistruct fd_query;
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_cistruct fd_query_funcs {
40bf215546Sopenharmony_ci   void (*destroy_query)(struct fd_context *ctx, struct fd_query *q) dt;
41bf215546Sopenharmony_ci   void (*begin_query)(struct fd_context *ctx, struct fd_query *q) dt;
42bf215546Sopenharmony_ci   void (*end_query)(struct fd_context *ctx, struct fd_query *q) dt;
43bf215546Sopenharmony_ci   bool (*get_query_result)(struct fd_context *ctx, struct fd_query *q,
44bf215546Sopenharmony_ci                            bool wait, union pipe_query_result *result);
45bf215546Sopenharmony_ci};
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_cistruct fd_query {
48bf215546Sopenharmony_ci   struct threaded_query base;
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci   const struct fd_query_funcs *funcs;
51bf215546Sopenharmony_ci   int type;
52bf215546Sopenharmony_ci   unsigned index;
53bf215546Sopenharmony_ci};
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_cistatic inline struct fd_query *
56bf215546Sopenharmony_cifd_query(struct pipe_query *pq)
57bf215546Sopenharmony_ci{
58bf215546Sopenharmony_ci   return (struct fd_query *)pq;
59bf215546Sopenharmony_ci}
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ci#define FD_QUERY_DRAW_CALLS (PIPE_QUERY_DRIVER_SPECIFIC + 0)
62bf215546Sopenharmony_ci#define FD_QUERY_BATCH_TOTAL                                                   \
63bf215546Sopenharmony_ci   (PIPE_QUERY_DRIVER_SPECIFIC + 1) /* total # of batches (submits) */
64bf215546Sopenharmony_ci#define FD_QUERY_BATCH_SYSMEM                                                  \
65bf215546Sopenharmony_ci   (PIPE_QUERY_DRIVER_SPECIFIC +                                               \
66bf215546Sopenharmony_ci    2) /* batches using system memory (GMEM bypass) */
67bf215546Sopenharmony_ci#define FD_QUERY_BATCH_GMEM                                                    \
68bf215546Sopenharmony_ci   (PIPE_QUERY_DRIVER_SPECIFIC + 3) /* batches using GMEM */
69bf215546Sopenharmony_ci#define FD_QUERY_BATCH_NONDRAW                                                 \
70bf215546Sopenharmony_ci   (PIPE_QUERY_DRIVER_SPECIFIC + 4) /* compute/blit batches */
71bf215546Sopenharmony_ci#define FD_QUERY_BATCH_RESTORE                                                 \
72bf215546Sopenharmony_ci   (PIPE_QUERY_DRIVER_SPECIFIC + 5) /* batches requiring GMEM restore */
73bf215546Sopenharmony_ci#define FD_QUERY_STAGING_UPLOADS                                               \
74bf215546Sopenharmony_ci   (PIPE_QUERY_DRIVER_SPECIFIC +                                               \
75bf215546Sopenharmony_ci    6) /* texture/buffer uploads using staging blit */
76bf215546Sopenharmony_ci#define FD_QUERY_SHADOW_UPLOADS                                                \
77bf215546Sopenharmony_ci   (PIPE_QUERY_DRIVER_SPECIFIC +                                               \
78bf215546Sopenharmony_ci    7) /* texture/buffer uploads that shadowed rsc */
79bf215546Sopenharmony_ci#define FD_QUERY_VS_REGS                                                       \
80bf215546Sopenharmony_ci   (PIPE_QUERY_DRIVER_SPECIFIC +                                               \
81bf215546Sopenharmony_ci    8) /* avg # of VS registers (scaled up by 100x) */
82bf215546Sopenharmony_ci#define FD_QUERY_FS_REGS                                                       \
83bf215546Sopenharmony_ci   (PIPE_QUERY_DRIVER_SPECIFIC +                                               \
84bf215546Sopenharmony_ci    9) /* avg # of VS registers (scaled up by 100x) */
85bf215546Sopenharmony_ci/* insert any new non-perfcntr queries here, the first perfcntr index
86bf215546Sopenharmony_ci * needs to come last!
87bf215546Sopenharmony_ci */
88bf215546Sopenharmony_ci#define FD_QUERY_FIRST_PERFCNTR (PIPE_QUERY_DRIVER_SPECIFIC + 10)
89bf215546Sopenharmony_ci
90bf215546Sopenharmony_civoid fd_query_screen_init(struct pipe_screen *pscreen);
91bf215546Sopenharmony_civoid fd_query_context_init(struct pipe_context *pctx);
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_cistatic inline bool
94bf215546Sopenharmony_ciskip_begin_query(int type)
95bf215546Sopenharmony_ci{
96bf215546Sopenharmony_ci   switch (type) {
97bf215546Sopenharmony_ci   case PIPE_QUERY_TIMESTAMP:
98bf215546Sopenharmony_ci   case PIPE_QUERY_GPU_FINISHED:
99bf215546Sopenharmony_ci      return true;
100bf215546Sopenharmony_ci   default:
101bf215546Sopenharmony_ci      return false;
102bf215546Sopenharmony_ci   }
103bf215546Sopenharmony_ci}
104bf215546Sopenharmony_ci
105bf215546Sopenharmony_ci/* maps query_type to sample provider idx: */
106bf215546Sopenharmony_cistatic inline int
107bf215546Sopenharmony_cipidx(unsigned query_type)
108bf215546Sopenharmony_ci{
109bf215546Sopenharmony_ci   switch (query_type) {
110bf215546Sopenharmony_ci   case PIPE_QUERY_OCCLUSION_COUNTER:
111bf215546Sopenharmony_ci      return 0;
112bf215546Sopenharmony_ci   case PIPE_QUERY_OCCLUSION_PREDICATE:
113bf215546Sopenharmony_ci      return 1;
114bf215546Sopenharmony_ci   case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE:
115bf215546Sopenharmony_ci      return 2;
116bf215546Sopenharmony_ci   /* TODO currently queries only emitted in main pass (not in binning pass)..
117bf215546Sopenharmony_ci    * which is fine for occlusion query, but pretty much not anything else.
118bf215546Sopenharmony_ci    */
119bf215546Sopenharmony_ci   case PIPE_QUERY_TIME_ELAPSED:
120bf215546Sopenharmony_ci      return 3;
121bf215546Sopenharmony_ci   case PIPE_QUERY_TIMESTAMP:
122bf215546Sopenharmony_ci      return 4;
123bf215546Sopenharmony_ci
124bf215546Sopenharmony_ci   case PIPE_QUERY_PRIMITIVES_GENERATED:
125bf215546Sopenharmony_ci      return 5;
126bf215546Sopenharmony_ci   case PIPE_QUERY_PRIMITIVES_EMITTED:
127bf215546Sopenharmony_ci      return 6;
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_ci   default:
130bf215546Sopenharmony_ci      return -1;
131bf215546Sopenharmony_ci   }
132bf215546Sopenharmony_ci}
133bf215546Sopenharmony_ci
134bf215546Sopenharmony_ci/** Returns true if get_query_result is being called from the driver thread. */
135bf215546Sopenharmony_cistatic inline bool
136bf215546Sopenharmony_cifd_get_query_result_in_driver_thread(struct fd_query *q)
137bf215546Sopenharmony_ci{
138bf215546Sopenharmony_ci   return !q->base.flushed;
139bf215546Sopenharmony_ci}
140bf215546Sopenharmony_ci
141bf215546Sopenharmony_ci#endif /* FREEDRENO_QUERY_H_ */
142