gallium: Remove the standalone surfaces.
[mesa.git] / src / gallium / auxiliary / util / u_timed_winsys.c
1 /**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 *
26 *
27 **************************************************************************/
28 /*
29 * Authors: Keith Whitwell <keithw-at-tungstengraphics-dot-com>
30 */
31
32 #include "pipe/p_winsys.h"
33 #include "u_timed_winsys.h"
34 #include "util/u_memory.h"
35 #include "util/u_time.h"
36
37
38 struct timed_winsys {
39 struct pipe_winsys base;
40 struct pipe_winsys *backend;
41 uint64_t last_dump;
42 struct {
43 const char *name_key;
44 double total;
45 unsigned calls;
46 } funcs[13];
47 };
48
49
50 static struct timed_winsys *timed_winsys( struct pipe_winsys *winsys )
51 {
52 return (struct timed_winsys *)winsys;
53 }
54
55
56 static uint64_t time_start( void )
57 {
58 return util_time_micros();
59 }
60
61
62 static void time_display( struct pipe_winsys *winsys )
63 {
64 struct timed_winsys *tws = timed_winsys(winsys);
65 unsigned i;
66 double overall = 0;
67
68 for (i = 0; i < Elements(tws->funcs); i++) {
69 if (tws->funcs[i].name_key) {
70 debug_printf("*** %-25s %5.3fms (%d calls, avg %.3fms)\n",
71 tws->funcs[i].name_key,
72 tws->funcs[i].total,
73 tws->funcs[i].calls,
74 tws->funcs[i].total / tws->funcs[i].calls);
75 overall += tws->funcs[i].total;
76 tws->funcs[i].calls = 0;
77 tws->funcs[i].total = 0;
78 }
79 }
80
81 debug_printf("*** %-25s %5.3fms\n",
82 "OVERALL WINSYS",
83 overall);
84 }
85
86 static void time_finish( struct pipe_winsys *winsys,
87 long long startval,
88 unsigned idx,
89 const char *name )
90 {
91 struct timed_winsys *tws = timed_winsys(winsys);
92 uint64_t endval = util_time_micros();
93 double elapsed = (endval - startval)/1000.0;
94
95 if (endval - startval > 1000LL)
96 debug_printf("*** %s %.3f\n", name, elapsed );
97
98 assert( tws->funcs[idx].name_key == name ||
99 tws->funcs[idx].name_key == NULL);
100
101 tws->funcs[idx].name_key = name;
102 tws->funcs[idx].total += elapsed;
103 tws->funcs[idx].calls++;
104
105 if (endval - tws->last_dump > 10LL * 1000LL * 1000LL) {
106 time_display( winsys );
107 tws->last_dump = endval;
108 }
109 }
110
111
112 /* Pipe has no concept of pools, but the psb driver passes a flag that
113 * can be mapped onto pools in the backend.
114 */
115 static struct pipe_buffer *
116 timed_buffer_create(struct pipe_winsys *winsys,
117 unsigned alignment,
118 unsigned usage,
119 unsigned size )
120 {
121 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
122 uint64_t start = time_start();
123
124 struct pipe_buffer *buf = backend->buffer_create( backend, alignment, usage, size );
125
126 time_finish(winsys, start, 0, __FUNCTION__);
127
128 return buf;
129 }
130
131
132
133
134 static struct pipe_buffer *
135 timed_user_buffer_create(struct pipe_winsys *winsys,
136 void *data,
137 unsigned bytes)
138 {
139 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
140 uint64_t start = time_start();
141
142 struct pipe_buffer *buf = backend->user_buffer_create( backend, data, bytes );
143
144 time_finish(winsys, start, 1, __FUNCTION__);
145
146 return buf;
147 }
148
149
150 static void *
151 timed_buffer_map(struct pipe_winsys *winsys,
152 struct pipe_buffer *buf,
153 unsigned flags)
154 {
155 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
156 uint64_t start = time_start();
157
158 void *map = backend->buffer_map( backend, buf, flags );
159
160 time_finish(winsys, start, 2, __FUNCTION__);
161
162 return map;
163 }
164
165
166 static void
167 timed_buffer_unmap(struct pipe_winsys *winsys,
168 struct pipe_buffer *buf)
169 {
170 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
171 uint64_t start = time_start();
172
173 backend->buffer_unmap( backend, buf );
174
175 time_finish(winsys, start, 3, __FUNCTION__);
176 }
177
178
179 static void
180 timed_buffer_destroy(struct pipe_winsys *winsys,
181 struct pipe_buffer *buf)
182 {
183 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
184 uint64_t start = time_start();
185
186 backend->buffer_destroy( backend, buf );
187
188 time_finish(winsys, start, 4, __FUNCTION__);
189 }
190
191
192 static void
193 timed_flush_frontbuffer( struct pipe_winsys *winsys,
194 struct pipe_surface *surf,
195 void *context_private)
196 {
197 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
198 uint64_t start = time_start();
199
200 backend->flush_frontbuffer( backend, surf, context_private );
201
202 time_finish(winsys, start, 5, __FUNCTION__);
203 }
204
205
206
207
208 static struct pipe_buffer *
209 timed_surface_buffer_create(struct pipe_winsys *winsys,
210 unsigned width, unsigned height,
211 enum pipe_format format,
212 unsigned usage,
213 unsigned *stride)
214 {
215 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
216 uint64_t start = time_start();
217
218 struct pipe_buffer *ret = backend->surface_buffer_create( backend, width, height,
219 format, usage, stride );
220
221 time_finish(winsys, start, 7, __FUNCTION__);
222
223 return ret;
224 }
225
226
227 static const char *
228 timed_get_name( struct pipe_winsys *winsys )
229 {
230 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
231 uint64_t start = time_start();
232
233 const char *ret = backend->get_name( backend );
234
235 time_finish(winsys, start, 9, __FUNCTION__);
236
237 return ret;
238 }
239
240 static void
241 timed_fence_reference(struct pipe_winsys *winsys,
242 struct pipe_fence_handle **ptr,
243 struct pipe_fence_handle *fence)
244 {
245 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
246 uint64_t start = time_start();
247
248 backend->fence_reference( backend, ptr, fence );
249
250 time_finish(winsys, start, 10, __FUNCTION__);
251 }
252
253
254 static int
255 timed_fence_signalled( struct pipe_winsys *winsys,
256 struct pipe_fence_handle *fence,
257 unsigned flag )
258 {
259 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
260 uint64_t start = time_start();
261
262 int ret = backend->fence_signalled( backend, fence, flag );
263
264 time_finish(winsys, start, 11, __FUNCTION__);
265
266 return ret;
267 }
268
269 static int
270 timed_fence_finish( struct pipe_winsys *winsys,
271 struct pipe_fence_handle *fence,
272 unsigned flag )
273 {
274 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
275 uint64_t start = time_start();
276
277 int ret = backend->fence_finish( backend, fence, flag );
278
279 time_finish(winsys, start, 12, __FUNCTION__);
280
281 return ret;
282 }
283
284 static void
285 timed_winsys_destroy( struct pipe_winsys *winsys )
286 {
287 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
288 backend->destroy( backend );
289 FREE(winsys);
290 }
291
292
293
294 struct pipe_winsys *u_timed_winsys_create( struct pipe_winsys *backend )
295 {
296 struct timed_winsys *ws = CALLOC_STRUCT(timed_winsys);
297
298 ws->base.user_buffer_create = timed_user_buffer_create;
299 ws->base.buffer_map = timed_buffer_map;
300 ws->base.buffer_unmap = timed_buffer_unmap;
301 ws->base.buffer_destroy = timed_buffer_destroy;
302 ws->base.buffer_create = timed_buffer_create;
303 ws->base.flush_frontbuffer = timed_flush_frontbuffer;
304 ws->base.get_name = timed_get_name;
305 ws->base.surface_buffer_create = timed_surface_buffer_create;
306 ws->base.fence_reference = timed_fence_reference;
307 ws->base.fence_signalled = timed_fence_signalled;
308 ws->base.fence_finish = timed_fence_finish;
309 ws->base.destroy = timed_winsys_destroy;
310
311 ws->backend = backend;
312
313 return &ws->base;
314 }
315