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"
35 #include "util/u_time.h"
39 struct pipe_winsys base
;
40 struct pipe_winsys
*backend
;
50 static struct timed_winsys
*timed_winsys( struct pipe_winsys
*winsys
)
52 return (struct timed_winsys
*)winsys
;
56 static uint64_t time_start( void )
58 return util_time_micros();
62 static void time_display( struct pipe_winsys
*winsys
)
64 struct timed_winsys
*tws
= timed_winsys(winsys
);
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
,
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;
81 debug_printf("*** %-25s %5.3fms\n",
86 static void time_finish( struct pipe_winsys
*winsys
,
91 struct timed_winsys
*tws
= timed_winsys(winsys
);
92 uint64_t endval
= util_time_micros();
93 double elapsed
= (endval
- startval
)/1000.0;
95 if (endval
- startval
> 1000LL)
96 debug_printf("*** %s %.3f\n", name
, elapsed
);
98 assert( tws
->funcs
[idx
].name_key
== name
||
99 tws
->funcs
[idx
].name_key
== NULL
);
101 tws
->funcs
[idx
].name_key
= name
;
102 tws
->funcs
[idx
].total
+= elapsed
;
103 tws
->funcs
[idx
].calls
++;
105 if (endval
- tws
->last_dump
> 10LL * 1000LL * 1000LL) {
106 time_display( winsys
);
107 tws
->last_dump
= endval
;
112 /* Pipe has no concept of pools, but the psb driver passes a flag that
113 * can be mapped onto pools in the backend.
115 static struct pipe_buffer
*
116 timed_buffer_create(struct pipe_winsys
*winsys
,
121 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
122 uint64_t start
= time_start();
124 struct pipe_buffer
*buf
= backend
->buffer_create( backend
, alignment
, usage
, size
);
126 time_finish(winsys
, start
, 0, __FUNCTION__
);
134 static struct pipe_buffer
*
135 timed_user_buffer_create(struct pipe_winsys
*winsys
,
139 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
140 uint64_t start
= time_start();
142 struct pipe_buffer
*buf
= backend
->user_buffer_create( backend
, data
, bytes
);
144 time_finish(winsys
, start
, 1, __FUNCTION__
);
151 timed_buffer_map(struct pipe_winsys
*winsys
,
152 struct pipe_buffer
*buf
,
155 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
156 uint64_t start
= time_start();
158 void *map
= backend
->buffer_map( backend
, buf
, flags
);
160 time_finish(winsys
, start
, 2, __FUNCTION__
);
167 timed_buffer_unmap(struct pipe_winsys
*winsys
,
168 struct pipe_buffer
*buf
)
170 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
171 uint64_t start
= time_start();
173 backend
->buffer_unmap( backend
, buf
);
175 time_finish(winsys
, start
, 3, __FUNCTION__
);
180 timed_buffer_destroy(struct pipe_winsys
*winsys
,
181 struct pipe_buffer
*buf
)
183 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
184 uint64_t start
= time_start();
186 backend
->buffer_destroy( backend
, buf
);
188 time_finish(winsys
, start
, 4, __FUNCTION__
);
193 timed_flush_frontbuffer( struct pipe_winsys
*winsys
,
194 struct pipe_surface
*surf
,
195 void *context_private
)
197 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
198 uint64_t start
= time_start();
200 backend
->flush_frontbuffer( backend
, surf
, context_private
);
202 time_finish(winsys
, start
, 5, __FUNCTION__
);
208 static struct pipe_surface
*
209 timed_surface_alloc(struct pipe_winsys
*winsys
)
211 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
212 uint64_t start
= time_start();
214 struct pipe_surface
*surf
= backend
->surface_alloc( backend
);
216 time_finish(winsys
, start
, 6, __FUNCTION__
);
224 timed_surface_alloc_storage(struct pipe_winsys
*winsys
,
225 struct pipe_surface
*surf
,
226 unsigned width
, unsigned height
,
227 enum pipe_format format
,
231 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
232 uint64_t start
= time_start();
234 int ret
= backend
->surface_alloc_storage( backend
, surf
, width
, height
,
235 format
, flags
, tex_usage
);
237 time_finish(winsys
, start
, 7, __FUNCTION__
);
244 timed_surface_release(struct pipe_winsys
*winsys
, struct pipe_surface
**s
)
246 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
247 uint64_t start
= time_start();
249 backend
->surface_release( backend
, s
);
251 time_finish(winsys
, start
, 8, __FUNCTION__
);
257 timed_get_name( struct pipe_winsys
*winsys
)
259 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
260 uint64_t start
= time_start();
262 const char *ret
= backend
->get_name( backend
);
264 time_finish(winsys
, start
, 9, __FUNCTION__
);
270 timed_fence_reference(struct pipe_winsys
*winsys
,
271 struct pipe_fence_handle
**ptr
,
272 struct pipe_fence_handle
*fence
)
274 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
275 uint64_t start
= time_start();
277 backend
->fence_reference( backend
, ptr
, fence
);
279 time_finish(winsys
, start
, 10, __FUNCTION__
);
284 timed_fence_signalled( struct pipe_winsys
*winsys
,
285 struct pipe_fence_handle
*fence
,
288 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
289 uint64_t start
= time_start();
291 int ret
= backend
->fence_signalled( backend
, fence
, flag
);
293 time_finish(winsys
, start
, 11, __FUNCTION__
);
299 timed_fence_finish( struct pipe_winsys
*winsys
,
300 struct pipe_fence_handle
*fence
,
303 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
304 uint64_t start
= time_start();
306 int ret
= backend
->fence_finish( backend
, fence
, flag
);
308 time_finish(winsys
, start
, 12, __FUNCTION__
);
314 timed_winsys_destroy( struct pipe_winsys
*winsys
)
316 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
317 backend
->destroy( backend
);
323 struct pipe_winsys
*u_timed_winsys_create( struct pipe_winsys
*backend
)
325 struct timed_winsys
*ws
= CALLOC_STRUCT(timed_winsys
);
327 ws
->base
.user_buffer_create
= timed_user_buffer_create
;
328 ws
->base
.buffer_map
= timed_buffer_map
;
329 ws
->base
.buffer_unmap
= timed_buffer_unmap
;
330 ws
->base
.buffer_destroy
= timed_buffer_destroy
;
331 ws
->base
.buffer_create
= timed_buffer_create
;
332 ws
->base
.flush_frontbuffer
= timed_flush_frontbuffer
;
333 ws
->base
.get_name
= timed_get_name
;
334 ws
->base
.surface_alloc
= timed_surface_alloc
;
335 ws
->base
.surface_alloc_storage
= timed_surface_alloc_storage
;
336 ws
->base
.surface_release
= timed_surface_release
;
337 ws
->base
.fence_reference
= timed_fence_reference
;
338 ws
->base
.fence_signalled
= timed_fence_signalled
;
339 ws
->base
.fence_finish
= timed_fence_finish
;
340 ws
->base
.destroy
= timed_winsys_destroy
;
342 ws
->backend
= backend
;