1 /* -*- mode: C; c-file-style: "k&r"; ttxab-width 4; indent-tabs-mode: t; -*- */
4 * Copyright (C) 2012 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 #include "pipe/p_state.h"
30 #include "util/u_string.h"
31 #include "util/u_memory.h"
32 #include "util/u_inlines.h"
33 #include "os/os_time.h"
35 #include "freedreno_query.h"
36 #include "freedreno_context.h"
37 #include "freedreno_util.h"
39 #define FD_QUERY_DRAW_CALLS (PIPE_QUERY_DRIVER_SPECIFIC + 0)
40 #define FD_QUERY_BATCH_TOTAL (PIPE_QUERY_DRIVER_SPECIFIC + 1) /* total # of batches (submits) */
41 #define FD_QUERY_BATCH_SYSMEM (PIPE_QUERY_DRIVER_SPECIFIC + 2) /* batches using system memory (GMEM bypass) */
42 #define FD_QUERY_BATCH_GMEM (PIPE_QUERY_DRIVER_SPECIFIC + 3) /* batches using GMEM */
43 #define FD_QUERY_BATCH_RESTORE (PIPE_QUERY_DRIVER_SPECIFIC + 4) /* batches requiring GMEM restore */
45 /* Currently just simple cpu query's supported.. probably need
46 * to refactor this a bit when I'm eventually ready to add gpu
51 /* storage for the collected data */
52 union pipe_query_result data
;
54 uint64_t begin_value
, end_value
;
55 uint64_t begin_time
, end_time
;
58 static inline struct fd_query
*
59 fd_query(struct pipe_query
*pq
)
61 return (struct fd_query
*)pq
;
64 static struct pipe_query
*
65 fd_create_query(struct pipe_context
*pctx
, unsigned query_type
)
70 case PIPE_QUERY_PRIMITIVES_GENERATED
:
71 case PIPE_QUERY_PRIMITIVES_EMITTED
:
72 case FD_QUERY_DRAW_CALLS
:
73 case FD_QUERY_BATCH_TOTAL
:
74 case FD_QUERY_BATCH_SYSMEM
:
75 case FD_QUERY_BATCH_GMEM
:
76 case FD_QUERY_BATCH_RESTORE
:
82 q
= CALLOC_STRUCT(fd_query
);
88 return (struct pipe_query
*) q
;
92 fd_destroy_query(struct pipe_context
*pctx
, struct pipe_query
*pq
)
94 struct fd_query
*q
= fd_query(pq
);
99 read_counter(struct pipe_context
*pctx
, int type
)
101 struct fd_context
*ctx
= fd_context(pctx
);
103 case PIPE_QUERY_PRIMITIVES_GENERATED
:
104 /* for now same thing as _PRIMITIVES_EMITTED */
105 case PIPE_QUERY_PRIMITIVES_EMITTED
:
106 return ctx
->stats
.prims_emitted
;
107 case FD_QUERY_DRAW_CALLS
:
108 return ctx
->stats
.draw_calls
;
109 case FD_QUERY_BATCH_TOTAL
:
110 return ctx
->stats
.batch_total
;
111 case FD_QUERY_BATCH_SYSMEM
:
112 return ctx
->stats
.batch_sysmem
;
113 case FD_QUERY_BATCH_GMEM
:
114 return ctx
->stats
.batch_gmem
;
115 case FD_QUERY_BATCH_RESTORE
:
116 return ctx
->stats
.batch_restore
;
122 is_rate_query(struct fd_query
*q
)
125 case FD_QUERY_BATCH_TOTAL
:
126 case FD_QUERY_BATCH_SYSMEM
:
127 case FD_QUERY_BATCH_GMEM
:
128 case FD_QUERY_BATCH_RESTORE
:
136 fd_begin_query(struct pipe_context
*pctx
, struct pipe_query
*pq
)
138 struct fd_query
*q
= fd_query(pq
);
140 q
->begin_value
= read_counter(pctx
, q
->type
);
141 if (is_rate_query(q
))
142 q
->begin_time
= os_time_get();
146 fd_end_query(struct pipe_context
*pctx
, struct pipe_query
*pq
)
148 struct fd_query
*q
= fd_query(pq
);
150 q
->end_value
= read_counter(pctx
, q
->type
);
151 if (is_rate_query(q
))
152 q
->end_time
= os_time_get();
156 fd_get_query_result(struct pipe_context
*pctx
, struct pipe_query
*pq
,
157 boolean wait
, union pipe_query_result
*result
)
159 struct fd_query
*q
= fd_query(pq
);
164 util_query_clear_result(result
, q
->type
);
166 result
->u64
= q
->end_value
- q
->begin_value
;
168 if (is_rate_query(q
)) {
169 double fps
= (result
->u64
* 1000000) /
170 (double)(q
->end_time
- q
->begin_time
);
171 result
->u64
= (uint64_t)fps
;
178 fd_get_driver_query_info(struct pipe_screen
*pscreen
,
179 unsigned index
, struct pipe_driver_query_info
*info
)
181 struct pipe_driver_query_info list
[] = {
182 {"draw-calls", FD_QUERY_DRAW_CALLS
, 0},
183 {"batches", FD_QUERY_BATCH_TOTAL
, 0},
184 {"batches-sysmem", FD_QUERY_BATCH_SYSMEM
, 0},
185 {"batches-gmem", FD_QUERY_BATCH_GMEM
, 0},
186 {"restores", FD_QUERY_BATCH_RESTORE
, 0},
187 {"prims-emitted", PIPE_QUERY_PRIMITIVES_EMITTED
, 0},
191 return ARRAY_SIZE(list
);
193 if (index
>= ARRAY_SIZE(list
))
201 fd_query_screen_init(struct pipe_screen
*pscreen
)
203 pscreen
->get_driver_query_info
= fd_get_driver_query_info
;
207 fd_query_context_init(struct pipe_context
*pctx
)
209 pctx
->create_query
= fd_create_query
;
210 pctx
->destroy_query
= fd_destroy_query
;
211 pctx
->begin_query
= fd_begin_query
;
212 pctx
->end_query
= fd_end_query
;
213 pctx
->get_query_result
= fd_get_query_result
;