Home | History | Annotate | Download | only in trace
      1 /**************************************************************************
      2  *
      3  * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
      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 TUNGSTEN GRAPHICS 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/u_simple_list.h"
     31 
     32 #include "tr_dump.h"
     33 #include "tr_dump_state.h"
     34 #include "tr_texture.h"
     35 #include "tr_context.h"
     36 #include "tr_screen.h"
     37 #include "tr_public.h"
     38 
     39 #include "pipe/p_format.h"
     40 
     41 
     42 static boolean trace = FALSE;
     43 
     44 static const char *
     45 trace_screen_get_name(struct pipe_screen *_screen)
     46 {
     47    struct trace_screen *tr_scr = trace_screen(_screen);
     48    struct pipe_screen *screen = tr_scr->screen;
     49    const char *result;
     50 
     51    trace_dump_call_begin("pipe_screen", "get_name");
     52 
     53    trace_dump_arg(ptr, screen);
     54 
     55    result = screen->get_name(screen);
     56 
     57    trace_dump_ret(string, result);
     58 
     59    trace_dump_call_end();
     60 
     61    return result;
     62 }
     63 
     64 
     65 static const char *
     66 trace_screen_get_vendor(struct pipe_screen *_screen)
     67 {
     68    struct trace_screen *tr_scr = trace_screen(_screen);
     69    struct pipe_screen *screen = tr_scr->screen;
     70    const char *result;
     71 
     72    trace_dump_call_begin("pipe_screen", "get_vendor");
     73 
     74    trace_dump_arg(ptr, screen);
     75 
     76    result = screen->get_vendor(screen);
     77 
     78    trace_dump_ret(string, result);
     79 
     80    trace_dump_call_end();
     81 
     82    return result;
     83 }
     84 
     85 
     86 static int
     87 trace_screen_get_param(struct pipe_screen *_screen,
     88                        enum pipe_cap param)
     89 {
     90    struct trace_screen *tr_scr = trace_screen(_screen);
     91    struct pipe_screen *screen = tr_scr->screen;
     92    int result;
     93 
     94    trace_dump_call_begin("pipe_screen", "get_param");
     95 
     96    trace_dump_arg(ptr, screen);
     97    trace_dump_arg(int, param);
     98 
     99    result = screen->get_param(screen, param);
    100 
    101    trace_dump_ret(int, result);
    102 
    103    trace_dump_call_end();
    104 
    105    return result;
    106 }
    107 
    108 
    109 static int
    110 trace_screen_get_shader_param(struct pipe_screen *_screen, unsigned shader,
    111                        enum pipe_shader_cap param)
    112 {
    113    struct trace_screen *tr_scr = trace_screen(_screen);
    114    struct pipe_screen *screen = tr_scr->screen;
    115    int result;
    116 
    117    trace_dump_call_begin("pipe_screen", "get_shader_param");
    118 
    119    trace_dump_arg(ptr, screen);
    120    trace_dump_arg(uint, shader);
    121    trace_dump_arg(int, param);
    122 
    123    result = screen->get_shader_param(screen, shader, param);
    124 
    125    trace_dump_ret(int, result);
    126 
    127    trace_dump_call_end();
    128 
    129    return result;
    130 }
    131 
    132 
    133 static float
    134 trace_screen_get_paramf(struct pipe_screen *_screen,
    135                         enum pipe_capf param)
    136 {
    137    struct trace_screen *tr_scr = trace_screen(_screen);
    138    struct pipe_screen *screen = tr_scr->screen;
    139    float result;
    140 
    141    trace_dump_call_begin("pipe_screen", "get_paramf");
    142 
    143    trace_dump_arg(ptr, screen);
    144    trace_dump_arg(int, param);
    145 
    146    result = screen->get_paramf(screen, param);
    147 
    148    trace_dump_ret(float, result);
    149 
    150    trace_dump_call_end();
    151 
    152    return result;
    153 }
    154 
    155 
    156 static boolean
    157 trace_screen_is_format_supported(struct pipe_screen *_screen,
    158                                  enum pipe_format format,
    159                                  enum pipe_texture_target target,
    160                                  unsigned sample_count,
    161                                  unsigned tex_usage)
    162 {
    163    struct trace_screen *tr_scr = trace_screen(_screen);
    164    struct pipe_screen *screen = tr_scr->screen;
    165    boolean result;
    166 
    167    trace_dump_call_begin("pipe_screen", "is_format_supported");
    168 
    169    trace_dump_arg(ptr, screen);
    170    trace_dump_arg(format, format);
    171    trace_dump_arg(int, target);
    172    trace_dump_arg(uint, sample_count);
    173    trace_dump_arg(uint, tex_usage);
    174 
    175    result = screen->is_format_supported(screen, format, target, sample_count,
    176                                         tex_usage);
    177 
    178    trace_dump_ret(bool, result);
    179 
    180    trace_dump_call_end();
    181 
    182    return result;
    183 }
    184 
    185 
    186 static struct pipe_context *
    187 trace_screen_context_create(struct pipe_screen *_screen, void *priv)
    188 {
    189    struct trace_screen *tr_scr = trace_screen(_screen);
    190    struct pipe_screen *screen = tr_scr->screen;
    191    struct pipe_context *result;
    192 
    193    trace_dump_call_begin("pipe_screen", "context_create");
    194 
    195    trace_dump_arg(ptr, screen);
    196 
    197    result = screen->context_create(screen, priv);
    198 
    199    trace_dump_ret(ptr, result);
    200 
    201    trace_dump_call_end();
    202 
    203    result = trace_context_create(tr_scr, result);
    204 
    205    return result;
    206 }
    207 
    208 
    209 static void
    210 trace_screen_flush_frontbuffer(struct pipe_screen *_screen,
    211                                struct pipe_resource *_resource,
    212                                unsigned level, unsigned layer,
    213                                void *context_private)
    214 {
    215    struct trace_screen *tr_scr = trace_screen(_screen);
    216    struct trace_resource *tr_res = trace_resource(_resource);
    217    struct pipe_screen *screen = tr_scr->screen;
    218    struct pipe_resource *resource = tr_res->resource;
    219 
    220    trace_dump_call_begin("pipe_screen", "flush_frontbuffer");
    221 
    222    trace_dump_arg(ptr, screen);
    223    trace_dump_arg(ptr, resource);
    224    trace_dump_arg(uint, level);
    225    trace_dump_arg(uint, layer);
    226    /* XXX: hide, as there is nothing we can do with this
    227    trace_dump_arg(ptr, context_private);
    228    */
    229 
    230    screen->flush_frontbuffer(screen, resource, level, layer, context_private);
    231 
    232    trace_dump_call_end();
    233 }
    234 
    235 
    236 /********************************************************************
    237  * texture
    238  */
    239 
    240 
    241 static struct pipe_resource *
    242 trace_screen_resource_create(struct pipe_screen *_screen,
    243                             const struct pipe_resource *templat)
    244 {
    245    struct trace_screen *tr_scr = trace_screen(_screen);
    246    struct pipe_screen *screen = tr_scr->screen;
    247    struct pipe_resource *result;
    248 
    249    trace_dump_call_begin("pipe_screen", "resource_create");
    250 
    251    trace_dump_arg(ptr, screen);
    252    trace_dump_arg(resource_template, templat);
    253 
    254    result = screen->resource_create(screen, templat);
    255 
    256    trace_dump_ret(ptr, result);
    257 
    258    trace_dump_call_end();
    259 
    260    result = trace_resource_create(tr_scr, result);
    261 
    262    return result;
    263 }
    264 
    265 static struct pipe_resource *
    266 trace_screen_resource_from_handle(struct pipe_screen *_screen,
    267                                  const struct pipe_resource *templ,
    268                                  struct winsys_handle *handle)
    269 {
    270    struct trace_screen *tr_screen = trace_screen(_screen);
    271    struct pipe_screen *screen = tr_screen->screen;
    272    struct pipe_resource *result;
    273 
    274    /* TODO trace call */
    275 
    276    result = screen->resource_from_handle(screen, templ, handle);
    277 
    278    result = trace_resource_create(trace_screen(_screen), result);
    279 
    280    return result;
    281 }
    282 
    283 static boolean
    284 trace_screen_resource_get_handle(struct pipe_screen *_screen,
    285                                 struct pipe_resource *_resource,
    286                                 struct winsys_handle *handle)
    287 {
    288    struct trace_screen *tr_screen = trace_screen(_screen);
    289    struct trace_resource *tr_resource = trace_resource(_resource);
    290    struct pipe_screen *screen = tr_screen->screen;
    291    struct pipe_resource *resource = tr_resource->resource;
    292 
    293    /* TODO trace call */
    294 
    295    return screen->resource_get_handle(screen, resource, handle);
    296 }
    297 
    298 
    299 
    300 static void
    301 trace_screen_resource_destroy(struct pipe_screen *_screen,
    302 			      struct pipe_resource *_resource)
    303 {
    304    struct trace_screen *tr_scr = trace_screen(_screen);
    305    struct trace_resource *tr_res = trace_resource(_resource);
    306    struct pipe_screen *screen = tr_scr->screen;
    307    struct pipe_resource *resource = tr_res->resource;
    308 
    309    assert(resource->screen == screen);
    310 
    311    trace_dump_call_begin("pipe_screen", "resource_destroy");
    312 
    313    trace_dump_arg(ptr, screen);
    314    trace_dump_arg(ptr, resource);
    315 
    316    trace_dump_call_end();
    317 
    318    trace_resource_destroy(tr_scr, tr_res);
    319 }
    320 
    321 
    322 /********************************************************************
    323  * fence
    324  */
    325 
    326 
    327 static void
    328 trace_screen_fence_reference(struct pipe_screen *_screen,
    329                              struct pipe_fence_handle **pdst,
    330                              struct pipe_fence_handle *src)
    331 {
    332    struct trace_screen *tr_scr = trace_screen(_screen);
    333    struct pipe_screen *screen = tr_scr->screen;
    334    struct pipe_fence_handle *dst;
    335 
    336    assert(pdst);
    337    dst = *pdst;
    338 
    339    trace_dump_call_begin("pipe_screen", "fence_reference");
    340 
    341    trace_dump_arg(ptr, screen);
    342    trace_dump_arg(ptr, dst);
    343    trace_dump_arg(ptr, src);
    344 
    345    screen->fence_reference(screen, pdst, src);
    346 
    347    trace_dump_call_end();
    348 }
    349 
    350 
    351 static boolean
    352 trace_screen_fence_signalled(struct pipe_screen *_screen,
    353                              struct pipe_fence_handle *fence)
    354 {
    355    struct trace_screen *tr_scr = trace_screen(_screen);
    356    struct pipe_screen *screen = tr_scr->screen;
    357    int result;
    358 
    359    trace_dump_call_begin("pipe_screen", "fence_signalled");
    360 
    361    trace_dump_arg(ptr, screen);
    362    trace_dump_arg(ptr, fence);
    363 
    364    result = screen->fence_signalled(screen, fence);
    365 
    366    trace_dump_ret(bool, result);
    367 
    368    trace_dump_call_end();
    369 
    370    return result;
    371 }
    372 
    373 
    374 static boolean
    375 trace_screen_fence_finish(struct pipe_screen *_screen,
    376                           struct pipe_fence_handle *fence,
    377                           uint64_t timeout)
    378 {
    379    struct trace_screen *tr_scr = trace_screen(_screen);
    380    struct pipe_screen *screen = tr_scr->screen;
    381    int result;
    382 
    383    trace_dump_call_begin("pipe_screen", "fence_finish");
    384 
    385    trace_dump_arg(ptr, screen);
    386    trace_dump_arg(ptr, fence);
    387    trace_dump_arg(uint, timeout);
    388 
    389    result = screen->fence_finish(screen, fence, timeout);
    390 
    391    trace_dump_ret(bool, result);
    392 
    393    trace_dump_call_end();
    394 
    395    return result;
    396 }
    397 
    398 
    399 /********************************************************************
    400  * screen
    401  */
    402 
    403 static uint64_t
    404 trace_screen_get_timestamp(struct pipe_screen *_screen)
    405 {
    406    struct trace_screen *tr_scr = trace_screen(_screen);
    407    struct pipe_screen *screen = tr_scr->screen;
    408    uint64_t result;
    409 
    410    trace_dump_call_begin("pipe_screen", "get_timestamp");
    411    trace_dump_arg(ptr, screen);
    412 
    413    result = screen->get_timestamp(screen);
    414 
    415    trace_dump_ret(uint, result);
    416    trace_dump_call_end();
    417 
    418    return result;
    419 }
    420 
    421 static void
    422 trace_screen_destroy(struct pipe_screen *_screen)
    423 {
    424    struct trace_screen *tr_scr = trace_screen(_screen);
    425    struct pipe_screen *screen = tr_scr->screen;
    426 
    427    trace_dump_call_begin("pipe_screen", "destroy");
    428    trace_dump_arg(ptr, screen);
    429    trace_dump_call_end();
    430    trace_dump_trace_end();
    431 
    432    screen->destroy(screen);
    433 
    434    FREE(tr_scr);
    435 }
    436 
    437 boolean
    438 trace_enabled(void)
    439 {
    440    static boolean firstrun = TRUE;
    441 
    442    if (!firstrun)
    443       return trace;
    444    firstrun = FALSE;
    445 
    446    if(trace_dump_trace_begin()) {
    447       trace_dumping_start();
    448       trace = TRUE;
    449    }
    450 
    451    return trace;
    452 }
    453 
    454 struct pipe_screen *
    455 trace_screen_create(struct pipe_screen *screen)
    456 {
    457    struct trace_screen *tr_scr;
    458 
    459    if(!screen)
    460       goto error1;
    461 
    462    if (!trace_enabled())
    463       goto error1;
    464 
    465    trace_dump_call_begin("", "pipe_screen_create");
    466 
    467    tr_scr = CALLOC_STRUCT(trace_screen);
    468    if(!tr_scr)
    469       goto error2;
    470 
    471    tr_scr->base.destroy = trace_screen_destroy;
    472    tr_scr->base.get_name = trace_screen_get_name;
    473    tr_scr->base.get_vendor = trace_screen_get_vendor;
    474    tr_scr->base.get_param = trace_screen_get_param;
    475    tr_scr->base.get_shader_param = trace_screen_get_shader_param;
    476    tr_scr->base.get_paramf = trace_screen_get_paramf;
    477    tr_scr->base.is_format_supported = trace_screen_is_format_supported;
    478    assert(screen->context_create);
    479    tr_scr->base.context_create = trace_screen_context_create;
    480    tr_scr->base.resource_create = trace_screen_resource_create;
    481    tr_scr->base.resource_from_handle = trace_screen_resource_from_handle;
    482    tr_scr->base.resource_get_handle = trace_screen_resource_get_handle;
    483    tr_scr->base.resource_destroy = trace_screen_resource_destroy;
    484    tr_scr->base.fence_reference = trace_screen_fence_reference;
    485    tr_scr->base.fence_signalled = trace_screen_fence_signalled;
    486    tr_scr->base.fence_finish = trace_screen_fence_finish;
    487    tr_scr->base.flush_frontbuffer = trace_screen_flush_frontbuffer;
    488    tr_scr->base.get_timestamp = trace_screen_get_timestamp;
    489 
    490    tr_scr->screen = screen;
    491 
    492    trace_dump_ret(ptr, screen);
    493    trace_dump_call_end();
    494 
    495    return &tr_scr->base;
    496 
    497 error2:
    498    trace_dump_ret(ptr, screen);
    499    trace_dump_call_end();
    500    trace_dump_trace_end();
    501 error1:
    502    return screen;
    503 }
    504 
    505 
    506 struct trace_screen *
    507 trace_screen(struct pipe_screen *screen)
    508 {
    509    assert(screen);
    510    assert(screen->destroy == trace_screen_destroy);
    511    return (struct trace_screen *)screen;
    512 }
    513