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