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_state.h"
33 #include "util/u_simple_screen.h"
34 #include "u_timed_winsys.h"
35 #include "util/u_memory.h"
36 #include "os/os_time.h"
40 struct pipe_winsys base
;
41 struct pipe_winsys
*backend
;
51 static struct timed_winsys
*timed_winsys( struct pipe_winsys
*winsys
)
53 return (struct timed_winsys
*)winsys
;
57 static void time_display( struct pipe_winsys
*winsys
)
59 struct timed_winsys
*tws
= timed_winsys(winsys
);
63 for (i
= 0; i
< Elements(tws
->funcs
); i
++) {
64 if (tws
->funcs
[i
].name_key
) {
65 debug_printf("*** %-25s %5.3fms (%d calls, avg %.3fms)\n",
66 tws
->funcs
[i
].name_key
,
69 tws
->funcs
[i
].total
/ tws
->funcs
[i
].calls
);
70 overall
+= tws
->funcs
[i
].total
;
71 tws
->funcs
[i
].calls
= 0;
72 tws
->funcs
[i
].total
= 0;
76 debug_printf("*** %-25s %5.3fms\n",
81 static void time_finish( struct pipe_winsys
*winsys
,
86 struct timed_winsys
*tws
= timed_winsys(winsys
);
87 int64_t endval
= os_time_get();
88 double elapsed
= (endval
- startval
)/1000.0;
90 if (endval
- startval
> 1000LL)
91 debug_printf("*** %s %.3f\n", name
, elapsed
);
93 assert( tws
->funcs
[idx
].name_key
== name
||
94 tws
->funcs
[idx
].name_key
== NULL
);
96 tws
->funcs
[idx
].name_key
= name
;
97 tws
->funcs
[idx
].total
+= elapsed
;
98 tws
->funcs
[idx
].calls
++;
100 if (endval
- tws
->last_dump
> 10LL * 1000LL * 1000LL) {
101 time_display( winsys
);
102 tws
->last_dump
= endval
;
107 /* Pipe has no concept of pools, but the psb driver passes a flag that
108 * can be mapped onto pools in the backend.
110 static struct pipe_buffer
*
111 timed_buffer_create(struct pipe_winsys
*winsys
,
116 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
117 int64_t start
= os_time_get();
119 struct pipe_buffer
*buf
=
120 backend
->buffer_create( backend
, alignment
, usage
, size
);
122 time_finish(winsys
, start
, 0, __FUNCTION__
);
130 static struct pipe_buffer
*
131 timed_user_buffer_create(struct pipe_winsys
*winsys
,
135 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
136 int64_t start
= os_time_get();
138 struct pipe_buffer
*buf
= backend
->user_buffer_create( backend
, data
, bytes
);
140 time_finish(winsys
, start
, 1, __FUNCTION__
);
147 timed_buffer_map(struct pipe_winsys
*winsys
,
148 struct pipe_buffer
*buf
,
151 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
152 int64_t start
= os_time_get();
154 void *map
= backend
->buffer_map( backend
, buf
, flags
);
156 time_finish(winsys
, start
, 2, __FUNCTION__
);
163 timed_buffer_unmap(struct pipe_winsys
*winsys
,
164 struct pipe_buffer
*buf
)
166 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
167 int64_t start
= os_time_get();
169 backend
->buffer_unmap( backend
, buf
);
171 time_finish(winsys
, start
, 3, __FUNCTION__
);
176 timed_buffer_destroy(struct pipe_buffer
*buf
)
178 struct pipe_winsys
*winsys
= buf
->screen
->winsys
;
179 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
180 int64_t start
= os_time_get();
182 backend
->buffer_destroy( buf
);
184 time_finish(winsys
, start
, 4, __FUNCTION__
);
189 timed_flush_frontbuffer( struct pipe_winsys
*winsys
,
190 struct pipe_surface
*surf
,
191 void *context_private
)
193 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
194 int64_t start
= os_time_get();
196 backend
->flush_frontbuffer( backend
, surf
, context_private
);
198 time_finish(winsys
, start
, 5, __FUNCTION__
);
204 static struct pipe_buffer
*
205 timed_surface_buffer_create(struct pipe_winsys
*winsys
,
206 unsigned width
, unsigned height
,
207 enum pipe_format format
,
212 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
213 int64_t start
= os_time_get();
215 struct pipe_buffer
*ret
= backend
->surface_buffer_create( backend
, width
, height
,
216 format
, usage
, tex_usage
, stride
);
218 time_finish(winsys
, start
, 7, __FUNCTION__
);
225 timed_get_name( struct pipe_winsys
*winsys
)
227 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
228 int64_t start
= os_time_get();
230 const char *ret
= backend
->get_name( backend
);
232 time_finish(winsys
, start
, 9, __FUNCTION__
);
238 timed_fence_reference(struct pipe_winsys
*winsys
,
239 struct pipe_fence_handle
**ptr
,
240 struct pipe_fence_handle
*fence
)
242 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
243 int64_t start
= os_time_get();
245 backend
->fence_reference( backend
, ptr
, fence
);
247 time_finish(winsys
, start
, 10, __FUNCTION__
);
252 timed_fence_signalled( struct pipe_winsys
*winsys
,
253 struct pipe_fence_handle
*fence
,
256 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
257 int64_t start
= os_time_get();
259 int ret
= backend
->fence_signalled( backend
, fence
, flag
);
261 time_finish(winsys
, start
, 11, __FUNCTION__
);
267 timed_fence_finish( struct pipe_winsys
*winsys
,
268 struct pipe_fence_handle
*fence
,
271 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
272 int64_t start
= os_time_get();
274 int ret
= backend
->fence_finish( backend
, fence
, flag
);
276 time_finish(winsys
, start
, 12, __FUNCTION__
);
282 timed_winsys_destroy( struct pipe_winsys
*winsys
)
284 struct pipe_winsys
*backend
= timed_winsys(winsys
)->backend
;
285 backend
->destroy( backend
);
291 struct pipe_winsys
*u_timed_winsys_create( struct pipe_winsys
*backend
)
293 struct timed_winsys
*ws
= CALLOC_STRUCT(timed_winsys
);
295 ws
->base
.user_buffer_create
= timed_user_buffer_create
;
296 ws
->base
.buffer_map
= timed_buffer_map
;
297 ws
->base
.buffer_unmap
= timed_buffer_unmap
;
298 ws
->base
.buffer_destroy
= timed_buffer_destroy
;
299 ws
->base
.buffer_create
= timed_buffer_create
;
300 ws
->base
.surface_buffer_create
= timed_surface_buffer_create
;
301 ws
->base
.flush_frontbuffer
= timed_flush_frontbuffer
;
302 ws
->base
.get_name
= timed_get_name
;
303 ws
->base
.fence_reference
= timed_fence_reference
;
304 ws
->base
.fence_signalled
= timed_fence_signalled
;
305 ws
->base
.fence_finish
= timed_fence_finish
;
306 ws
->base
.destroy
= timed_winsys_destroy
;
308 ws
->backend
= backend
;