1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
4 * Copyright (C) 2014 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_sw.h"
36 #include "freedreno_context.h"
37 #include "freedreno_util.h"
42 * In the core, we have some support for basic sw counters
46 fd_sw_destroy_query(struct fd_context
*ctx
, struct fd_query
*q
)
48 struct fd_sw_query
*sq
= fd_sw_query(q
);
53 read_counter(struct fd_context
*ctx
, int type
)
56 case PIPE_QUERY_PRIMITIVES_GENERATED
:
57 /* for now same thing as _PRIMITIVES_EMITTED */
58 case PIPE_QUERY_PRIMITIVES_EMITTED
:
59 return ctx
->stats
.prims_emitted
;
60 case FD_QUERY_DRAW_CALLS
:
61 return ctx
->stats
.draw_calls
;
62 case FD_QUERY_BATCH_TOTAL
:
63 return ctx
->stats
.batch_total
;
64 case FD_QUERY_BATCH_SYSMEM
:
65 return ctx
->stats
.batch_sysmem
;
66 case FD_QUERY_BATCH_GMEM
:
67 return ctx
->stats
.batch_gmem
;
68 case FD_QUERY_BATCH_RESTORE
:
69 return ctx
->stats
.batch_restore
;
75 is_rate_query(struct fd_query
*q
)
78 case FD_QUERY_BATCH_TOTAL
:
79 case FD_QUERY_BATCH_SYSMEM
:
80 case FD_QUERY_BATCH_GMEM
:
81 case FD_QUERY_BATCH_RESTORE
:
89 fd_sw_begin_query(struct fd_context
*ctx
, struct fd_query
*q
)
91 struct fd_sw_query
*sq
= fd_sw_query(q
);
93 sq
->begin_value
= read_counter(ctx
, q
->type
);
95 sq
->begin_time
= os_time_get();
99 fd_sw_end_query(struct fd_context
*ctx
, struct fd_query
*q
)
101 struct fd_sw_query
*sq
= fd_sw_query(q
);
103 sq
->end_value
= read_counter(ctx
, q
->type
);
104 if (is_rate_query(q
))
105 sq
->end_time
= os_time_get();
109 fd_sw_get_query_result(struct fd_context
*ctx
, struct fd_query
*q
,
110 boolean wait
, union pipe_query_result
*result
)
112 struct fd_sw_query
*sq
= fd_sw_query(q
);
117 util_query_clear_result(result
, q
->type
);
119 result
->u64
= sq
->end_value
- sq
->begin_value
;
121 if (is_rate_query(q
)) {
122 double fps
= (result
->u64
* 1000000) /
123 (double)(sq
->end_time
- sq
->begin_time
);
124 result
->u64
= (uint64_t)fps
;
130 static const struct fd_query_funcs sw_query_funcs
= {
131 .destroy_query
= fd_sw_destroy_query
,
132 .begin_query
= fd_sw_begin_query
,
133 .end_query
= fd_sw_end_query
,
134 .get_query_result
= fd_sw_get_query_result
,
138 fd_sw_create_query(struct fd_context
*ctx
, unsigned query_type
)
140 struct fd_sw_query
*sq
;
143 switch (query_type
) {
144 case PIPE_QUERY_PRIMITIVES_GENERATED
:
145 case PIPE_QUERY_PRIMITIVES_EMITTED
:
146 case FD_QUERY_DRAW_CALLS
:
147 case FD_QUERY_BATCH_TOTAL
:
148 case FD_QUERY_BATCH_SYSMEM
:
149 case FD_QUERY_BATCH_GMEM
:
150 case FD_QUERY_BATCH_RESTORE
:
156 sq
= CALLOC_STRUCT(fd_sw_query
);
161 q
->funcs
= &sw_query_funcs
;
162 q
->type
= query_type
;