2 * Copyright 2011 Christoph Bumiller
3 * Copyright 2015 Samuel Pitoiset
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
24 #include "nvc0/nvc0_context.h"
26 #include "nvc0_query_sw.h"
28 /* === DRIVER STATISTICS === */
30 #ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS
32 static const char *nvc0_sw_query_drv_stat_names
[] =
34 "drv-tex_obj_current_count",
35 "drv-tex_obj_current_bytes",
36 "drv-buf_obj_current_count",
37 "drv-buf_obj_current_bytes_vid",
38 "drv-buf_obj_current_bytes_sys",
39 "drv-tex_transfers_rd",
40 "drv-tex_transfers_wr",
43 "drv-tex_cache_flush_count",
44 "drv-buf_transfers_rd",
45 "drv-buf_transfers_wr",
46 "drv-buf_read_bytes_staging_vid",
47 "drv-buf_write_bytes_direct",
48 "drv-buf_write_bytes_staging_vid",
49 "drv-buf_write_bytes_staging_sys",
51 "drv-buf_non_kernel_fence_sync_count",
52 "drv-any_non_kernel_fence_sync_count",
53 "drv-query_sync_count",
54 "drv-gpu_serialize_count",
55 "drv-draw_calls_array",
56 "drv-draw_calls_indexed",
57 "drv-draw_calls_fallback_count",
58 "drv-user_buffer_upload_bytes",
59 "drv-constbuf_upload_count",
60 "drv-constbuf_upload_bytes",
62 "drv-resource_validate_count"
65 #endif /* NOUVEAU_ENABLE_DRIVER_STATISTICS */
68 nvc0_sw_destroy_query(struct nvc0_context
*nvc0
, struct nvc0_query
*q
)
70 struct nvc0_sw_query
*sq
= nvc0_sw_query(q
);
75 nvc0_sw_begin_query(struct nvc0_context
*nvc0
, struct nvc0_query
*q
)
77 #ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS
78 struct nvc0_sw_query
*sq
= nvc0_sw_query(q
);
81 sq
->value
= nvc0
->screen
->base
.stats
.v
[q
->index
];
90 nvc0_sw_end_query(struct nvc0_context
*nvc0
, struct nvc0_query
*q
)
92 #ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS
93 struct nvc0_sw_query
*sq
= nvc0_sw_query(q
);
94 sq
->value
= nvc0
->screen
->base
.stats
.v
[q
->index
] - sq
->value
;
99 nvc0_sw_get_query_result(struct nvc0_context
*nvc0
, struct nvc0_query
*q
,
100 boolean wait
, union pipe_query_result
*result
)
102 #ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS
103 struct nvc0_sw_query
*sq
= nvc0_sw_query(q
);
104 uint64_t *res64
= (uint64_t *)result
;
106 res64
[0] = sq
->value
;
111 static const struct nvc0_query_funcs sw_query_funcs
= {
112 .destroy_query
= nvc0_sw_destroy_query
,
113 .begin_query
= nvc0_sw_begin_query
,
114 .end_query
= nvc0_sw_end_query
,
115 .get_query_result
= nvc0_sw_get_query_result
,
119 nvc0_sw_create_query(struct nvc0_context
*nvcO
, unsigned type
, unsigned index
)
121 struct nvc0_sw_query
*sq
;
122 struct nvc0_query
*q
;
124 if (type
< NVC0_SW_QUERY_DRV_STAT(0) || type
> NVC0_SW_QUERY_DRV_STAT_LAST
)
127 sq
= CALLOC_STRUCT(nvc0_sw_query
);
132 q
->funcs
= &sw_query_funcs
;
134 q
->index
= type
- NVC0_SW_QUERY_DRV_STAT(0);
140 nvc0_sw_get_driver_query_info(struct nvc0_screen
*screen
, unsigned id
,
141 struct pipe_driver_query_info
*info
)
145 count
+= NVC0_SW_QUERY_DRV_STAT_COUNT
;
149 #ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS
151 info
->name
= nvc0_sw_query_drv_stat_names
[id
];
152 info
->query_type
= NVC0_SW_QUERY_DRV_STAT(id
);
153 info
->type
= PIPE_DRIVER_QUERY_TYPE_UINT64
;
154 info
->max_value
.u64
= 0;
155 if (strstr(info
->name
, "bytes"))
156 info
->type
= PIPE_DRIVER_QUERY_TYPE_BYTES
;
157 info
->group_id
= NVC0_SW_QUERY_DRV_STAT_GROUP
;