1 /**************************************************************************
3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
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:
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.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
27 **************************************************************************/
29 * Authors: Keith Whitwell <keithw-at-tungstengraphics-dot-com>
32 #include "pipe/p_winsys.h"
33 #include "u_timed_winsys.h"
34 #include "util/u_memory.h"
40 struct pipe_winsys base
;
41 struct pipe_winsys
*backend
;
42 unsigned long long last_dump
;
51 static struct timed_winsys
*timed_winsys( struct pipe_winsys
*winsys
)
53 return (struct timed_winsys
*)winsys
;
57 static unsigned long long get_time( void )
59 struct timeval systime
;
60 gettimeofday( &systime
, NULL
);
61 return (((unsigned long long) systime
.tv_sec
) * 1000000LL) + systime
.tv_usec
;
65 static unsigned long long time_start( void )
71 static void time_display( struct pipe_winsys
*winsys
)
73 struct timed_winsys
*tws
= timed_winsys(winsys
);
77 for (i
= 0; i
< Elements(tws
->funcs
); i
++) {
78 if (tws
->funcs
[i
].name_key
) {
79 debug_printf("*** %-25s %5.3fms (%d calls, avg %.3fms)\n",
80 tws
->funcs
[i
].name_key
,
83 tws
->funcs
[i
].total
/ tws
->funcs
[i
].calls
);
84 overall
+= tws
->funcs
[i
].total
;
85 tws
->funcs
[i
].calls
= 0;
86 tws
->funcs
[i
].total
= 0;
90 debug_printf("*** %-25s %5.3fms\n",
95 static void time_finish( struct pipe_winsys
*winsys
,
100 struct timed_winsys
*tws
= timed_winsys(winsys
);
101 unsigned long long endval
= get_time();
102 double elapsed
= (endval
- startval
)/1000.0;
104 if (endval
- startval
> 1000LL)
105 debug_printf("*** %s %.3f\n", name
, elapsed
);
107 assert( tws
->funcs
[idx
].name_key
== name
||
108 tws
->funcs
[idx
].name_key
== NULL
);
110 tws
->funcs
[idx
].name_key
= name
;
111 tws
->funcs
[idx
].total
+= elapsed
;
112 tws
->funcs
[idx
].calls
++;
114 if (endval
- tws
->last_dump
> 10LL * 1000LL * 1000LL) {
115 time_display( winsys
);
116 tws
->last_dump
= endval
;
121 /* Pipe has no concept of pools, but the psb driver passes a flag that
122 * can be mapped onto pools in the backend.
124 static struct pipe_buffer
*
125 timed_buffer_create(struct pipe_winsys
*winsys
,
130 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
131 unsigned long long start
= time_start();
133 struct pipe_buffer
*buf
= backend
->buffer_create( backend
, alignment
, usage
, size
);
135 time_finish(winsys
, start
, 0, __FUNCTION__
);
143 static struct pipe_buffer
*
144 timed_user_buffer_create(struct pipe_winsys
*winsys
,
148 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
149 unsigned long long start
= time_start();
151 struct pipe_buffer
*buf
= backend
->user_buffer_create( backend
, data
, bytes
);
153 time_finish(winsys
, start
, 1, __FUNCTION__
);
160 timed_buffer_map(struct pipe_winsys
*winsys
,
161 struct pipe_buffer
*buf
,
164 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
165 unsigned long long start
= time_start();
167 void *map
= backend
->buffer_map( backend
, buf
, flags
);
169 time_finish(winsys
, start
, 2, __FUNCTION__
);
176 timed_buffer_unmap(struct pipe_winsys
*winsys
,
177 struct pipe_buffer
*buf
)
179 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
180 unsigned long long start
= time_start();
182 backend
->buffer_unmap( backend
, buf
);
184 time_finish(winsys
, start
, 3, __FUNCTION__
);
189 timed_buffer_destroy(struct pipe_winsys
*winsys
,
190 struct pipe_buffer
*buf
)
192 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
193 unsigned long long start
= time_start();
195 backend
->buffer_destroy( backend
, buf
);
197 time_finish(winsys
, start
, 4, __FUNCTION__
);
202 timed_flush_frontbuffer( struct pipe_winsys
*winsys
,
203 struct pipe_surface
*surf
,
204 void *context_private
)
206 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
207 unsigned long long start
= time_start();
209 backend
->flush_frontbuffer( backend
, surf
, context_private
);
211 time_finish(winsys
, start
, 5, __FUNCTION__
);
217 static struct pipe_surface
*
218 timed_surface_alloc(struct pipe_winsys
*winsys
)
220 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
221 unsigned long long start
= time_start();
223 struct pipe_surface
*surf
= backend
->surface_alloc( backend
);
225 time_finish(winsys
, start
, 6, __FUNCTION__
);
233 timed_surface_alloc_storage(struct pipe_winsys
*winsys
,
234 struct pipe_surface
*surf
,
235 unsigned width
, unsigned height
,
236 enum pipe_format format
,
240 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
241 unsigned long long start
= time_start();
243 int ret
= backend
->surface_alloc_storage( backend
, surf
, width
, height
,
244 format
, flags
, tex_usage
);
246 time_finish(winsys
, start
, 7, __FUNCTION__
);
253 timed_surface_release(struct pipe_winsys
*winsys
, struct pipe_surface
**s
)
255 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
256 unsigned long long start
= time_start();
258 backend
->surface_release( backend
, s
);
260 time_finish(winsys
, start
, 8, __FUNCTION__
);
266 timed_get_name( struct pipe_winsys
*winsys
)
268 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
269 unsigned long long start
= time_start();
271 const char *ret
= backend
->get_name( backend
);
273 time_finish(winsys
, start
, 9, __FUNCTION__
);
279 timed_fence_reference(struct pipe_winsys
*winsys
,
280 struct pipe_fence_handle
**ptr
,
281 struct pipe_fence_handle
*fence
)
283 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
284 unsigned long long start
= time_start();
286 backend
->fence_reference( backend
, ptr
, fence
);
288 time_finish(winsys
, start
, 10, __FUNCTION__
);
293 timed_fence_signalled( struct pipe_winsys
*winsys
,
294 struct pipe_fence_handle
*fence
,
297 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
298 unsigned long long start
= time_start();
300 int ret
= backend
->fence_signalled( backend
, fence
, flag
);
302 time_finish(winsys
, start
, 11, __FUNCTION__
);
308 timed_fence_finish( struct pipe_winsys
*winsys
,
309 struct pipe_fence_handle
*fence
,
312 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
313 unsigned long long start
= time_start();
315 int ret
= backend
->fence_finish( backend
, fence
, flag
);
317 time_finish(winsys
, start
, 12, __FUNCTION__
);
323 timed_winsys_destroy( struct pipe_winsys
*winsys
)
325 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
326 backend
->destroy( backend
);
332 struct pipe_winsys
*u_timed_winsys_create( struct pipe_winsys
*backend
)
334 struct timed_winsys
*ws
= CALLOC_STRUCT(timed_winsys
);
336 ws
->base
.user_buffer_create
= timed_user_buffer_create
;
337 ws
->base
.buffer_map
= timed_buffer_map
;
338 ws
->base
.buffer_unmap
= timed_buffer_unmap
;
339 ws
->base
.buffer_destroy
= timed_buffer_destroy
;
340 ws
->base
.buffer_create
= timed_buffer_create
;
341 ws
->base
.flush_frontbuffer
= timed_flush_frontbuffer
;
342 ws
->base
.get_name
= timed_get_name
;
343 ws
->base
.surface_alloc
= timed_surface_alloc
;
344 ws
->base
.surface_alloc_storage
= timed_surface_alloc_storage
;
345 ws
->base
.surface_release
= timed_surface_release
;
346 ws
->base
.fence_reference
= timed_fence_reference
;
347 ws
->base
.fence_signalled
= timed_fence_signalled
;
348 ws
->base
.fence_finish
= timed_fence_finish
;
349 ws
->base
.destroy
= timed_winsys_destroy
;
351 ws
->backend
= backend
;