• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright 2008 VMware, Inc.
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 above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27 
28 #include "util/u_format.h"
29 #include "util/u_memory.h"
30 #include "util/simple_list.h"
31 
32 #include "tr_dump.h"
33 #include "tr_dump_defines.h"
34 #include "tr_dump_state.h"
35 #include "tr_texture.h"
36 #include "tr_context.h"
37 #include "tr_screen.h"
38 #include "tr_public.h"
39 
40 
41 static boolean trace = FALSE;
42 
43 static const char *
trace_screen_get_name(struct pipe_screen * _screen)44 trace_screen_get_name(struct pipe_screen *_screen)
45 {
46    struct trace_screen *tr_scr = trace_screen(_screen);
47    struct pipe_screen *screen = tr_scr->screen;
48    const char *result;
49 
50    trace_dump_call_begin("pipe_screen", "get_name");
51 
52    trace_dump_arg(ptr, screen);
53 
54    result = screen->get_name(screen);
55 
56    trace_dump_ret(string, result);
57 
58    trace_dump_call_end();
59 
60    return result;
61 }
62 
63 
64 static const char *
trace_screen_get_vendor(struct pipe_screen * _screen)65 trace_screen_get_vendor(struct pipe_screen *_screen)
66 {
67    struct trace_screen *tr_scr = trace_screen(_screen);
68    struct pipe_screen *screen = tr_scr->screen;
69    const char *result;
70 
71    trace_dump_call_begin("pipe_screen", "get_vendor");
72 
73    trace_dump_arg(ptr, screen);
74 
75    result = screen->get_vendor(screen);
76 
77    trace_dump_ret(string, result);
78 
79    trace_dump_call_end();
80 
81    return result;
82 }
83 
84 
85 static const char *
trace_screen_get_device_vendor(struct pipe_screen * _screen)86 trace_screen_get_device_vendor(struct pipe_screen *_screen)
87 {
88    struct trace_screen *tr_scr = trace_screen(_screen);
89    struct pipe_screen *screen = tr_scr->screen;
90    const char *result;
91 
92    trace_dump_call_begin("pipe_screen", "get_device_vendor");
93 
94    trace_dump_arg(ptr, screen);
95 
96    result = screen->get_device_vendor(screen);
97 
98    trace_dump_ret(string, result);
99 
100    trace_dump_call_end();
101 
102    return result;
103 }
104 
105 
106 static struct disk_cache *
trace_screen_get_disk_shader_cache(struct pipe_screen * _screen)107 trace_screen_get_disk_shader_cache(struct pipe_screen *_screen)
108 {
109    struct trace_screen *tr_scr = trace_screen(_screen);
110    struct pipe_screen *screen = tr_scr->screen;
111 
112    trace_dump_call_begin("pipe_screen", "get_disk_shader_cache");
113 
114    trace_dump_arg(ptr, screen);
115 
116    struct disk_cache *result = screen->get_disk_shader_cache(screen);
117 
118    trace_dump_ret(ptr, result);
119 
120    trace_dump_call_end();
121 
122    return result;
123 }
124 
125 
126 static int
trace_screen_get_param(struct pipe_screen * _screen,enum pipe_cap param)127 trace_screen_get_param(struct pipe_screen *_screen,
128                        enum pipe_cap param)
129 {
130    struct trace_screen *tr_scr = trace_screen(_screen);
131    struct pipe_screen *screen = tr_scr->screen;
132    int result;
133 
134    trace_dump_call_begin("pipe_screen", "get_param");
135 
136    trace_dump_arg(ptr, screen);
137    trace_dump_arg(int, param);
138 
139    result = screen->get_param(screen, param);
140 
141    trace_dump_ret(int, result);
142 
143    trace_dump_call_end();
144 
145    return result;
146 }
147 
148 
149 static int
trace_screen_get_shader_param(struct pipe_screen * _screen,enum pipe_shader_type shader,enum pipe_shader_cap param)150 trace_screen_get_shader_param(struct pipe_screen *_screen,
151                               enum pipe_shader_type shader,
152                               enum pipe_shader_cap param)
153 {
154    struct trace_screen *tr_scr = trace_screen(_screen);
155    struct pipe_screen *screen = tr_scr->screen;
156    int result;
157 
158    trace_dump_call_begin("pipe_screen", "get_shader_param");
159 
160    trace_dump_arg(ptr, screen);
161    trace_dump_arg(uint, shader);
162    trace_dump_arg(int, param);
163 
164    result = screen->get_shader_param(screen, shader, param);
165 
166    trace_dump_ret(int, result);
167 
168    trace_dump_call_end();
169 
170    return result;
171 }
172 
173 
174 static float
trace_screen_get_paramf(struct pipe_screen * _screen,enum pipe_capf param)175 trace_screen_get_paramf(struct pipe_screen *_screen,
176                         enum pipe_capf param)
177 {
178    struct trace_screen *tr_scr = trace_screen(_screen);
179    struct pipe_screen *screen = tr_scr->screen;
180    float result;
181 
182    trace_dump_call_begin("pipe_screen", "get_paramf");
183 
184    trace_dump_arg(ptr, screen);
185    trace_dump_arg(int, param);
186 
187    result = screen->get_paramf(screen, param);
188 
189    trace_dump_ret(float, result);
190 
191    trace_dump_call_end();
192 
193    return result;
194 }
195 
196 
197 static int
trace_screen_get_compute_param(struct pipe_screen * _screen,enum pipe_shader_ir ir_type,enum pipe_compute_cap param,void * data)198 trace_screen_get_compute_param(struct pipe_screen *_screen,
199                                enum pipe_shader_ir ir_type,
200                                enum pipe_compute_cap param, void *data)
201 {
202    struct trace_screen *tr_scr = trace_screen(_screen);
203    struct pipe_screen *screen = tr_scr->screen;
204    int result;
205 
206    trace_dump_call_begin("pipe_screen", "get_compute_param");
207 
208    trace_dump_arg(ptr, screen);
209    trace_dump_arg(int, ir_type);
210    trace_dump_arg(int, param);
211    trace_dump_arg(ptr, data);
212 
213    result = screen->get_compute_param(screen, ir_type, param, data);
214 
215    trace_dump_ret(int, result);
216 
217    trace_dump_call_end();
218 
219    return result;
220 }
221 
222 
223 static boolean
trace_screen_is_format_supported(struct pipe_screen * _screen,enum pipe_format format,enum pipe_texture_target target,unsigned sample_count,unsigned tex_usage)224 trace_screen_is_format_supported(struct pipe_screen *_screen,
225                                  enum pipe_format format,
226                                  enum pipe_texture_target target,
227                                  unsigned sample_count,
228                                  unsigned tex_usage)
229 {
230    struct trace_screen *tr_scr = trace_screen(_screen);
231    struct pipe_screen *screen = tr_scr->screen;
232    boolean result;
233 
234    trace_dump_call_begin("pipe_screen", "is_format_supported");
235 
236    trace_dump_arg(ptr, screen);
237    trace_dump_arg(format, format);
238    trace_dump_arg(int, target);
239    trace_dump_arg(uint, sample_count);
240    trace_dump_arg(uint, tex_usage);
241 
242    result = screen->is_format_supported(screen, format, target, sample_count,
243                                         tex_usage);
244 
245    trace_dump_ret(bool, result);
246 
247    trace_dump_call_end();
248 
249    return result;
250 }
251 
252 
253 static struct pipe_context *
trace_screen_context_create(struct pipe_screen * _screen,void * priv,unsigned flags)254 trace_screen_context_create(struct pipe_screen *_screen, void *priv,
255                             unsigned flags)
256 {
257    struct trace_screen *tr_scr = trace_screen(_screen);
258    struct pipe_screen *screen = tr_scr->screen;
259    struct pipe_context *result;
260 
261    trace_dump_call_begin("pipe_screen", "context_create");
262 
263    trace_dump_arg(ptr, screen);
264    trace_dump_arg(ptr, priv);
265    trace_dump_arg(uint, flags);
266 
267    result = screen->context_create(screen, priv, flags);
268 
269    trace_dump_ret(ptr, result);
270 
271    trace_dump_call_end();
272 
273    result = trace_context_create(tr_scr, result);
274 
275    return result;
276 }
277 
278 
279 static void
trace_screen_flush_frontbuffer(struct pipe_screen * _screen,struct pipe_resource * resource,unsigned level,unsigned layer,void * context_private,struct pipe_box * sub_box)280 trace_screen_flush_frontbuffer(struct pipe_screen *_screen,
281                                struct pipe_resource *resource,
282                                unsigned level, unsigned layer,
283                                void *context_private,
284                                struct pipe_box *sub_box)
285 {
286    struct trace_screen *tr_scr = trace_screen(_screen);
287    struct pipe_screen *screen = tr_scr->screen;
288 
289    trace_dump_call_begin("pipe_screen", "flush_frontbuffer");
290 
291    trace_dump_arg(ptr, screen);
292    trace_dump_arg(ptr, resource);
293    trace_dump_arg(uint, level);
294    trace_dump_arg(uint, layer);
295    /* XXX: hide, as there is nothing we can do with this
296    trace_dump_arg(ptr, context_private);
297    */
298 
299    screen->flush_frontbuffer(screen, resource, level, layer, context_private, sub_box);
300 
301    trace_dump_call_end();
302 }
303 
304 
305 static void
trace_screen_get_driver_uuid(struct pipe_screen * _screen,char * uuid)306 trace_screen_get_driver_uuid(struct pipe_screen *_screen, char *uuid)
307 {
308    struct pipe_screen *screen = trace_screen(_screen)->screen;
309 
310    trace_dump_call_begin("pipe_screen", "get_driver_uuid");
311    trace_dump_arg(ptr, screen);
312 
313    screen->get_driver_uuid(screen, uuid);
314 
315    trace_dump_ret(string, uuid);
316    trace_dump_call_end();
317 }
318 
319 static void
trace_screen_get_device_uuid(struct pipe_screen * _screen,char * uuid)320 trace_screen_get_device_uuid(struct pipe_screen *_screen, char *uuid)
321 {
322    struct pipe_screen *screen = trace_screen(_screen)->screen;
323 
324    trace_dump_call_begin("pipe_screen", "get_device_uuid");
325    trace_dump_arg(ptr, screen);
326 
327    screen->get_device_uuid(screen, uuid);
328 
329    trace_dump_ret(string, uuid);
330    trace_dump_call_end();
331 }
332 
333 
334 /********************************************************************
335  * texture
336  */
337 
338 
339 static struct pipe_resource *
trace_screen_resource_create(struct pipe_screen * _screen,const struct pipe_resource * templat)340 trace_screen_resource_create(struct pipe_screen *_screen,
341                             const struct pipe_resource *templat)
342 {
343    struct trace_screen *tr_scr = trace_screen(_screen);
344    struct pipe_screen *screen = tr_scr->screen;
345    struct pipe_resource *result;
346 
347    trace_dump_call_begin("pipe_screen", "resource_create");
348 
349    trace_dump_arg(ptr, screen);
350    trace_dump_arg(resource_template, templat);
351 
352    result = screen->resource_create(screen, templat);
353 
354    trace_dump_ret(ptr, result);
355 
356    trace_dump_call_end();
357 
358    if (result)
359       result->screen = _screen;
360    return result;
361 }
362 
363 static struct pipe_resource *
trace_screen_resource_from_handle(struct pipe_screen * _screen,const struct pipe_resource * templ,struct winsys_handle * handle,unsigned usage)364 trace_screen_resource_from_handle(struct pipe_screen *_screen,
365                                  const struct pipe_resource *templ,
366                                  struct winsys_handle *handle,
367                                   unsigned usage)
368 {
369    struct trace_screen *tr_screen = trace_screen(_screen);
370    struct pipe_screen *screen = tr_screen->screen;
371    struct pipe_resource *result;
372 
373    /* TODO trace call */
374 
375    result = screen->resource_from_handle(screen, templ, handle, usage);
376 
377    if (result)
378       result->screen = _screen;
379    return result;
380 }
381 
382 static bool
trace_screen_check_resource_capability(struct pipe_screen * _screen,struct pipe_resource * resource,unsigned bind)383 trace_screen_check_resource_capability(struct pipe_screen *_screen,
384                                        struct pipe_resource *resource,
385                                        unsigned bind)
386 {
387    struct pipe_screen *screen = trace_screen(_screen)->screen;
388 
389    return screen->check_resource_capability(screen, resource, bind);
390 }
391 
392 static boolean
trace_screen_resource_get_handle(struct pipe_screen * _screen,struct pipe_context * _pipe,struct pipe_resource * resource,struct winsys_handle * handle,unsigned usage)393 trace_screen_resource_get_handle(struct pipe_screen *_screen,
394                                  struct pipe_context *_pipe,
395                                 struct pipe_resource *resource,
396                                 struct winsys_handle *handle,
397                                  unsigned usage)
398 {
399    struct trace_screen *tr_screen = trace_screen(_screen);
400    struct trace_context *tr_pipe = _pipe ? trace_context(_pipe) : NULL;
401    struct pipe_screen *screen = tr_screen->screen;
402 
403    /* TODO trace call */
404 
405    return screen->resource_get_handle(screen, tr_pipe ? tr_pipe->pipe : NULL,
406                                       resource, handle, usage);
407 }
408 
409 static struct pipe_resource *
trace_screen_resource_from_memobj(struct pipe_screen * _screen,const struct pipe_resource * templ,struct pipe_memory_object * memobj,uint64_t offset)410 trace_screen_resource_from_memobj(struct pipe_screen *_screen,
411                                   const struct pipe_resource *templ,
412                                   struct pipe_memory_object *memobj,
413                                   uint64_t offset)
414 {
415    struct pipe_screen *screen = trace_screen(_screen)->screen;
416 
417    trace_dump_call_begin("pipe_screen", "resource_from_memobj");
418    trace_dump_arg(ptr, screen);
419    trace_dump_arg(resource_template, templ);
420    trace_dump_arg(ptr, memobj);
421    trace_dump_arg(uint, offset);
422 
423    struct pipe_resource *res =
424       screen->resource_from_memobj(screen, templ, memobj, offset);
425 
426    if (!res)
427       return NULL;
428    res->screen = _screen;
429 
430    trace_dump_ret(ptr, res);
431    trace_dump_call_end();
432    return res;
433 }
434 
435 static void
trace_screen_resource_changed(struct pipe_screen * _screen,struct pipe_resource * resource)436 trace_screen_resource_changed(struct pipe_screen *_screen,
437                               struct pipe_resource *resource)
438 {
439    struct trace_screen *tr_scr = trace_screen(_screen);
440    struct pipe_screen *screen = tr_scr->screen;
441 
442    trace_dump_call_begin("pipe_screen", "resource_changed");
443 
444    trace_dump_arg(ptr, screen);
445    trace_dump_arg(ptr, resource);
446 
447    screen->resource_changed(screen, resource);
448 
449    trace_dump_call_end();
450 }
451 
452 static void
trace_screen_resource_destroy(struct pipe_screen * _screen,struct pipe_resource * resource)453 trace_screen_resource_destroy(struct pipe_screen *_screen,
454 			      struct pipe_resource *resource)
455 {
456    struct trace_screen *tr_scr = trace_screen(_screen);
457    struct pipe_screen *screen = tr_scr->screen;
458 
459    /* Don't trace this, because due to the lack of pipe_resource wrapping,
460     * we can get this call from inside of driver calls, which would try
461     * to lock an already-locked mutex.
462     */
463    screen->resource_destroy(screen, resource);
464 }
465 
466 
467 /********************************************************************
468  * fence
469  */
470 
471 
472 static void
trace_screen_fence_reference(struct pipe_screen * _screen,struct pipe_fence_handle ** pdst,struct pipe_fence_handle * src)473 trace_screen_fence_reference(struct pipe_screen *_screen,
474                              struct pipe_fence_handle **pdst,
475                              struct pipe_fence_handle *src)
476 {
477    struct trace_screen *tr_scr = trace_screen(_screen);
478    struct pipe_screen *screen = tr_scr->screen;
479    struct pipe_fence_handle *dst;
480 
481    assert(pdst);
482    dst = *pdst;
483 
484    trace_dump_call_begin("pipe_screen", "fence_reference");
485 
486    trace_dump_arg(ptr, screen);
487    trace_dump_arg(ptr, dst);
488    trace_dump_arg(ptr, src);
489 
490    screen->fence_reference(screen, pdst, src);
491 
492    trace_dump_call_end();
493 }
494 
495 
496 static boolean
trace_screen_fence_finish(struct pipe_screen * _screen,struct pipe_context * _ctx,struct pipe_fence_handle * fence,uint64_t timeout)497 trace_screen_fence_finish(struct pipe_screen *_screen,
498                           struct pipe_context *_ctx,
499                           struct pipe_fence_handle *fence,
500                           uint64_t timeout)
501 {
502    struct trace_screen *tr_scr = trace_screen(_screen);
503    struct pipe_screen *screen = tr_scr->screen;
504    struct pipe_context *ctx = _ctx ? trace_context(_ctx)->pipe : NULL;
505    int result;
506 
507    trace_dump_call_begin("pipe_screen", "fence_finish");
508 
509    trace_dump_arg(ptr, screen);
510    trace_dump_arg(ptr, ctx);
511    trace_dump_arg(ptr, fence);
512    trace_dump_arg(uint, timeout);
513 
514    result = screen->fence_finish(screen, ctx, fence, timeout);
515 
516    trace_dump_ret(bool, result);
517 
518    trace_dump_call_end();
519 
520    return result;
521 }
522 
523 
524 /********************************************************************
525  * memobj
526  */
527 
528 static struct pipe_memory_object *
trace_screen_memobj_create_from_handle(struct pipe_screen * _screen,struct winsys_handle * handle,bool dedicated)529 trace_screen_memobj_create_from_handle(struct pipe_screen *_screen,
530                                        struct winsys_handle *handle,
531                                        bool dedicated)
532 {
533    struct pipe_screen *screen = trace_screen(_screen)->screen;
534 
535    trace_dump_call_begin("pipe_screen", "memobj_create_from_handle");
536    trace_dump_arg(ptr, screen);
537    trace_dump_arg(ptr, handle);
538    trace_dump_arg(bool, dedicated);
539 
540    struct pipe_memory_object *res =
541       screen->memobj_create_from_handle(screen, handle, dedicated);
542 
543    trace_dump_ret(ptr, res);
544    trace_dump_call_end();
545 
546    return res;
547 }
548 
549 static void
trace_screen_memobj_destroy(struct pipe_screen * _screen,struct pipe_memory_object * memobj)550 trace_screen_memobj_destroy(struct pipe_screen *_screen,
551                             struct pipe_memory_object *memobj)
552 {
553    struct pipe_screen *screen = trace_screen(_screen)->screen;
554 
555    trace_dump_call_begin("pipe_screen", "memobj_destroy");
556    trace_dump_arg(ptr, screen);
557    trace_dump_arg(ptr, memobj);
558    trace_dump_call_end();
559 
560    screen->memobj_destroy(screen, memobj);
561 }
562 
563 
564 /********************************************************************
565  * screen
566  */
567 
568 static uint64_t
trace_screen_get_timestamp(struct pipe_screen * _screen)569 trace_screen_get_timestamp(struct pipe_screen *_screen)
570 {
571    struct trace_screen *tr_scr = trace_screen(_screen);
572    struct pipe_screen *screen = tr_scr->screen;
573    uint64_t result;
574 
575    trace_dump_call_begin("pipe_screen", "get_timestamp");
576    trace_dump_arg(ptr, screen);
577 
578    result = screen->get_timestamp(screen);
579 
580    trace_dump_ret(uint, result);
581    trace_dump_call_end();
582 
583    return result;
584 }
585 
586 static void
trace_screen_destroy(struct pipe_screen * _screen)587 trace_screen_destroy(struct pipe_screen *_screen)
588 {
589    struct trace_screen *tr_scr = trace_screen(_screen);
590    struct pipe_screen *screen = tr_scr->screen;
591 
592    trace_dump_call_begin("pipe_screen", "destroy");
593    trace_dump_arg(ptr, screen);
594    trace_dump_call_end();
595 
596    screen->destroy(screen);
597 
598    FREE(tr_scr);
599 }
600 
601 boolean
trace_enabled(void)602 trace_enabled(void)
603 {
604    static boolean firstrun = TRUE;
605 
606    if (!firstrun)
607       return trace;
608    firstrun = FALSE;
609 
610    if(trace_dump_trace_begin()) {
611       trace_dumping_start();
612       trace = TRUE;
613    }
614 
615    return trace;
616 }
617 
618 struct pipe_screen *
trace_screen_create(struct pipe_screen * screen)619 trace_screen_create(struct pipe_screen *screen)
620 {
621    struct trace_screen *tr_scr;
622 
623    if (!trace_enabled())
624       goto error1;
625 
626    trace_dump_call_begin("", "pipe_screen_create");
627 
628    tr_scr = CALLOC_STRUCT(trace_screen);
629    if (!tr_scr)
630       goto error2;
631 
632 #define SCR_INIT(_member) \
633    tr_scr->base._member = screen->_member ? trace_screen_##_member : NULL
634 
635    tr_scr->base.destroy = trace_screen_destroy;
636    tr_scr->base.get_name = trace_screen_get_name;
637    tr_scr->base.get_vendor = trace_screen_get_vendor;
638    tr_scr->base.get_device_vendor = trace_screen_get_device_vendor;
639    SCR_INIT(get_disk_shader_cache);
640    tr_scr->base.get_param = trace_screen_get_param;
641    tr_scr->base.get_shader_param = trace_screen_get_shader_param;
642    tr_scr->base.get_paramf = trace_screen_get_paramf;
643    tr_scr->base.get_compute_param = trace_screen_get_compute_param;
644    tr_scr->base.is_format_supported = trace_screen_is_format_supported;
645    assert(screen->context_create);
646    tr_scr->base.context_create = trace_screen_context_create;
647    tr_scr->base.resource_create = trace_screen_resource_create;
648    tr_scr->base.resource_from_handle = trace_screen_resource_from_handle;
649    SCR_INIT(check_resource_capability);
650    tr_scr->base.resource_get_handle = trace_screen_resource_get_handle;
651    SCR_INIT(resource_from_memobj);
652    SCR_INIT(resource_changed);
653    tr_scr->base.resource_destroy = trace_screen_resource_destroy;
654    tr_scr->base.fence_reference = trace_screen_fence_reference;
655    tr_scr->base.fence_finish = trace_screen_fence_finish;
656    SCR_INIT(memobj_create_from_handle);
657    SCR_INIT(memobj_destroy);
658    tr_scr->base.flush_frontbuffer = trace_screen_flush_frontbuffer;
659    tr_scr->base.get_timestamp = trace_screen_get_timestamp;
660    SCR_INIT(get_driver_uuid);
661    SCR_INIT(get_device_uuid);
662 
663    tr_scr->screen = screen;
664 
665    trace_dump_ret(ptr, screen);
666    trace_dump_call_end();
667 
668    return &tr_scr->base;
669 
670 error2:
671    trace_dump_ret(ptr, screen);
672    trace_dump_call_end();
673 error1:
674    return screen;
675 }
676 
677 
678 struct trace_screen *
trace_screen(struct pipe_screen * screen)679 trace_screen(struct pipe_screen *screen)
680 {
681    assert(screen);
682    assert(screen->destroy == trace_screen_destroy);
683    return (struct trace_screen *)screen;
684 }
685