r600: don't enable depth test if there is no depth buffer
[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_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"
37
38
39 struct timed_winsys {
40 struct pipe_winsys base;
41 struct pipe_winsys *backend;
42 uint64_t last_dump;
43 struct {
44 const char *name_key;
45 double total;
46 unsigned calls;
47 } funcs[13];
48 };
49
50
51 static struct timed_winsys *timed_winsys( struct pipe_winsys *winsys )
52 {
53 return (struct timed_winsys *)winsys;
54 }
55
56
57 static void time_display( struct pipe_winsys *winsys )
58 {
59 struct timed_winsys *tws = timed_winsys(winsys);
60 unsigned i;
61 double overall = 0;
62
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,
67 tws->funcs[i].total,
68 tws->funcs[i].calls,
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;
73 }
74 }
75
76 debug_printf("*** %-25s %5.3fms\n",
77 "OVERALL WINSYS",
78 overall);
79 }
80
81 static void time_finish( struct pipe_winsys *winsys,
82 long long startval,
83 unsigned idx,
84 const char *name )
85 {
86 struct timed_winsys *tws = timed_winsys(winsys);
87 int64_t endval = os_time_get();
88 double elapsed = (endval - startval)/1000.0;
89
90 if (endval - startval > 1000LL)
91 debug_printf("*** %s %.3f\n", name, elapsed );
92
93 assert( tws->funcs[idx].name_key == name ||
94 tws->funcs[idx].name_key == NULL);
95
96 tws->funcs[idx].name_key = name;
97 tws->funcs[idx].total += elapsed;
98 tws->funcs[idx].calls++;
99
100 if (endval - tws->last_dump > 10LL * 1000LL * 1000LL) {
101 time_display( winsys );
102 tws->last_dump = endval;
103 }
104 }
105
106
107 /* Pipe has no concept of pools, but the psb driver passes a flag that
108 * can be mapped onto pools in the backend.
109 */
110 static struct pipe_buffer *
111 timed_buffer_create(struct pipe_winsys *winsys,
112 unsigned alignment,
113 unsigned usage,
114 unsigned size )
115 {
116 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
117 int64_t start = os_time_get();
118
119 struct pipe_buffer *buf =
120 backend->buffer_create( backend, alignment, usage, size );
121
122 time_finish(winsys, start, 0, __FUNCTION__);
123
124 return buf;
125 }
126
127
128
129
130 static struct pipe_buffer *
131 timed_user_buffer_create(struct pipe_winsys *winsys,
132 void *data,
133 unsigned bytes)
134 {
135 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
136 int64_t start = os_time_get();
137
138 struct pipe_buffer *buf = backend->user_buffer_create( backend, data, bytes );
139
140 time_finish(winsys, start, 1, __FUNCTION__);
141
142 return buf;
143 }
144
145
146 static void *
147 timed_buffer_map(struct pipe_winsys *winsys,
148 struct pipe_buffer *buf,
149 unsigned flags)
150 {
151 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
152 int64_t start = os_time_get();
153
154 void *map = backend->buffer_map( backend, buf, flags );
155
156 time_finish(winsys, start, 2, __FUNCTION__);
157
158 return map;
159 }
160
161
162 static void
163 timed_buffer_unmap(struct pipe_winsys *winsys,
164 struct pipe_buffer *buf)
165 {
166 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
167 int64_t start = os_time_get();
168
169 backend->buffer_unmap( backend, buf );
170
171 time_finish(winsys, start, 3, __FUNCTION__);
172 }
173
174
175 static void
176 timed_buffer_destroy(struct pipe_buffer *buf)
177 {
178 struct pipe_winsys *winsys = buf->screen->winsys;
179 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
180 int64_t start = os_time_get();
181
182 backend->buffer_destroy( buf );
183
184 time_finish(winsys, start, 4, __FUNCTION__);
185 }
186
187
188 static void
189 timed_flush_frontbuffer( struct pipe_winsys *winsys,
190 struct pipe_surface *surf,
191 void *context_private)
192 {
193 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
194 int64_t start = os_time_get();
195
196 backend->flush_frontbuffer( backend, surf, context_private );
197
198 time_finish(winsys, start, 5, __FUNCTION__);
199 }
200
201
202
203
204 static struct pipe_buffer *
205 timed_surface_buffer_create(struct pipe_winsys *winsys,
206 unsigned width, unsigned height,
207 enum pipe_format format,
208 unsigned usage,
209 unsigned tex_usage,
210 unsigned *stride)
211 {
212 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
213 int64_t start = os_time_get();
214
215 struct pipe_buffer *ret = backend->surface_buffer_create( backend, width, height,
216 format, usage, tex_usage, stride );
217
218 time_finish(winsys, start, 7, __FUNCTION__);
219
220 return ret;
221 }
222
223
224 static const char *
225 timed_get_name( struct pipe_winsys *winsys )
226 {
227 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
228 int64_t start = os_time_get();
229
230 const char *ret = backend->get_name( backend );
231
232 time_finish(winsys, start, 9, __FUNCTION__);
233
234 return ret;
235 }
236
237 static void
238 timed_fence_reference(struct pipe_winsys *winsys,
239 struct pipe_fence_handle **ptr,
240 struct pipe_fence_handle *fence)
241 {
242 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
243 int64_t start = os_time_get();
244
245 backend->fence_reference( backend, ptr, fence );
246
247 time_finish(winsys, start, 10, __FUNCTION__);
248 }
249
250
251 static int
252 timed_fence_signalled( struct pipe_winsys *winsys,
253 struct pipe_fence_handle *fence,
254 unsigned flag )
255 {
256 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
257 int64_t start = os_time_get();
258
259 int ret = backend->fence_signalled( backend, fence, flag );
260
261 time_finish(winsys, start, 11, __FUNCTION__);
262
263 return ret;
264 }
265
266 static int
267 timed_fence_finish( struct pipe_winsys *winsys,
268 struct pipe_fence_handle *fence,
269 unsigned flag )
270 {
271 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
272 int64_t start = os_time_get();
273
274 int ret = backend->fence_finish( backend, fence, flag );
275
276 time_finish(winsys, start, 12, __FUNCTION__);
277
278 return ret;
279 }
280
281 static void
282 timed_winsys_destroy( struct pipe_winsys *winsys )
283 {
284 struct pipe_winsys *backend = timed_winsys(winsys)->backend;
285 backend->destroy( backend );
286 FREE(winsys);
287 }
288
289
290
291 struct pipe_winsys *u_timed_winsys_create( struct pipe_winsys *backend )
292 {
293 struct timed_winsys *ws = CALLOC_STRUCT(timed_winsys);
294
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;
307
308 ws->backend = backend;
309
310 return &ws->base;
311 }
312