radeon: split hw query buffer handling from cs emit
[mesa.git] / src / gallium / drivers / radeon / r600_query.h
1 /*
2 * Copyright 2015 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
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 OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors:
24 * Nicolai Hähnle <nicolai.haehnle@amd.com>
25 *
26 */
27
28 #ifndef R600_QUERY_H
29 #define R600_QUERY_H
30
31 #include "pipe/p_defines.h"
32 #include "util/list.h"
33
34 struct r600_common_context;
35 struct r600_query;
36 struct r600_query_hw;
37 struct r600_resource;
38
39 #define R600_QUERY_DRAW_CALLS (PIPE_QUERY_DRIVER_SPECIFIC + 0)
40 #define R600_QUERY_REQUESTED_VRAM (PIPE_QUERY_DRIVER_SPECIFIC + 1)
41 #define R600_QUERY_REQUESTED_GTT (PIPE_QUERY_DRIVER_SPECIFIC + 2)
42 #define R600_QUERY_BUFFER_WAIT_TIME (PIPE_QUERY_DRIVER_SPECIFIC + 3)
43 #define R600_QUERY_NUM_CS_FLUSHES (PIPE_QUERY_DRIVER_SPECIFIC + 4)
44 #define R600_QUERY_NUM_BYTES_MOVED (PIPE_QUERY_DRIVER_SPECIFIC + 5)
45 #define R600_QUERY_VRAM_USAGE (PIPE_QUERY_DRIVER_SPECIFIC + 6)
46 #define R600_QUERY_GTT_USAGE (PIPE_QUERY_DRIVER_SPECIFIC + 7)
47 #define R600_QUERY_GPU_TEMPERATURE (PIPE_QUERY_DRIVER_SPECIFIC + 8)
48 #define R600_QUERY_CURRENT_GPU_SCLK (PIPE_QUERY_DRIVER_SPECIFIC + 9)
49 #define R600_QUERY_CURRENT_GPU_MCLK (PIPE_QUERY_DRIVER_SPECIFIC + 10)
50 #define R600_QUERY_GPU_LOAD (PIPE_QUERY_DRIVER_SPECIFIC + 11)
51 #define R600_QUERY_NUM_COMPILATIONS (PIPE_QUERY_DRIVER_SPECIFIC + 12)
52 #define R600_QUERY_NUM_SHADERS_CREATED (PIPE_QUERY_DRIVER_SPECIFIC + 13)
53 #define R600_QUERY_FIRST_PERFCOUNTER (PIPE_QUERY_DRIVER_SPECIFIC + 100)
54
55 struct r600_query_ops {
56 void (*destroy)(struct r600_common_context *, struct r600_query *);
57 boolean (*begin)(struct r600_common_context *, struct r600_query *);
58 void (*end)(struct r600_common_context *, struct r600_query *);
59 boolean (*get_result)(struct r600_common_context *,
60 struct r600_query *, boolean wait,
61 union pipe_query_result *result);
62 };
63
64 struct r600_query {
65 struct r600_query_ops *ops;
66
67 /* The type of query */
68 unsigned type;
69 };
70
71 enum {
72 R600_QUERY_HW_FLAG_NO_START = (1 << 0),
73 R600_QUERY_HW_FLAG_TIMER = (1 << 1),
74 };
75
76 struct r600_query_hw_ops {
77 void (*prepare_buffer)(struct r600_common_context *,
78 struct r600_query_hw *,
79 struct r600_resource *);
80 void (*emit_start)(struct r600_common_context *,
81 struct r600_query_hw *,
82 struct r600_resource *buffer, uint64_t va);
83 void (*emit_stop)(struct r600_common_context *,
84 struct r600_query_hw *,
85 struct r600_resource *buffer, uint64_t va);
86 };
87
88 struct r600_query_buffer {
89 /* The buffer where query results are stored. */
90 struct r600_resource *buf;
91 /* Offset of the next free result after current query data */
92 unsigned results_end;
93 /* If a query buffer is full, a new buffer is created and the old one
94 * is put in here. When we calculate the result, we sum up the samples
95 * from all buffers. */
96 struct r600_query_buffer *previous;
97 };
98
99 struct r600_query_hw {
100 struct r600_query b;
101 struct r600_query_hw_ops *ops;
102 unsigned flags;
103
104 /* The query buffer and how many results are in it. */
105 struct r600_query_buffer buffer;
106 /* Size of the result in memory for both begin_query and end_query,
107 * this can be one or two numbers, or it could even be a size of a structure. */
108 unsigned result_size;
109 /* The number of dwords for begin_query or end_query. */
110 unsigned num_cs_dw;
111 /* Linked list of queries */
112 struct list_head list;
113 /* For transform feedback: which stream the query is for */
114 unsigned stream;
115 };
116
117 void r600_query_hw_destroy(struct r600_common_context *rctx,
118 struct r600_query *rquery);
119
120 #endif /* R600_QUERY_H */