Squashed commit of the following:
[profile/ivi/mesa.git] / src / gallium / drivers / trace / tr_context.c
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_inlines.h"
29 #include "util/u_memory.h"
30 #include "util/u_simple_list.h"
31 #include "util/u_format.h"
32
33 #include "pipe/p_format.h"
34 #include "pipe/p_screen.h"
35
36 #include "tr_dump.h"
37 #include "tr_dump_state.h"
38 #include "tr_state.h"
39 #include "tr_screen.h"
40 #include "tr_texture.h"
41
42
43
44
45
46 static INLINE struct pipe_resource *
47 trace_resource_unwrap(struct trace_context *tr_ctx,
48                      struct pipe_resource *resource)
49 {
50    struct trace_resource *tr_tex;
51
52    if(!resource)
53       return NULL;
54
55    tr_tex = trace_resource(resource);
56
57    assert(tr_tex->resource);
58    return tr_tex->resource;
59 }
60
61
62 static INLINE struct pipe_surface *
63 trace_surface_unwrap(struct trace_context *tr_ctx,
64                      struct pipe_surface *surface)
65 {
66    struct trace_screen *tr_scr = trace_screen(tr_ctx->base.screen);
67    struct trace_surface *tr_surf;
68
69    if(!surface)
70       return NULL;
71
72    assert(surface->texture);
73    if(!surface->texture)
74       return surface;
75
76    tr_surf = trace_surface(surface);
77
78    assert(tr_surf->surface);
79    assert(tr_surf->surface->texture->screen == tr_scr->screen);
80    (void) tr_scr;
81    return tr_surf->surface;
82 }
83
84
85 static INLINE void
86 trace_context_draw_block(struct trace_context *tr_ctx, int flag)
87 {
88    int k;
89
90    pipe_mutex_lock(tr_ctx->draw_mutex);
91
92    if (tr_ctx->draw_blocker & flag) {
93       tr_ctx->draw_blocked |= flag;
94    } else if ((tr_ctx->draw_rule.blocker & flag) &&
95               (tr_ctx->draw_blocker & 4)) {
96       boolean block = FALSE;
97       debug_printf("%s (%p %p) (%p %p) (%p %u) (%p %u)\n", __FUNCTION__,
98                    (void *) tr_ctx->draw_rule.fs, (void *) tr_ctx->curr.fs,
99                    (void *) tr_ctx->draw_rule.vs, (void *) tr_ctx->curr.vs,
100                    (void *) tr_ctx->draw_rule.surf, 0,
101                    (void *) tr_ctx->draw_rule.sampler_view, 0);
102       if (tr_ctx->draw_rule.fs &&
103           tr_ctx->draw_rule.fs == tr_ctx->curr.fs)
104          block = TRUE;
105       if (tr_ctx->draw_rule.vs &&
106           tr_ctx->draw_rule.vs == tr_ctx->curr.vs)
107          block = TRUE;
108       if (tr_ctx->draw_rule.surf &&
109           tr_ctx->draw_rule.surf == tr_ctx->curr.zsbuf)
110             block = TRUE;
111       if (tr_ctx->draw_rule.surf)
112          for (k = 0; k < tr_ctx->curr.nr_cbufs; k++)
113             if (tr_ctx->draw_rule.surf == tr_ctx->curr.cbufs[k])
114                block = TRUE;
115       if (tr_ctx->draw_rule.sampler_view) {
116          for (k = 0; k < tr_ctx->curr.num_sampler_views; k++)
117             if (tr_ctx->draw_rule.sampler_view == tr_ctx->curr.sampler_views[k])
118                block = TRUE;
119          for (k = 0; k < tr_ctx->curr.num_vert_sampler_views; k++) {
120             if (tr_ctx->draw_rule.sampler_view == tr_ctx->curr.vert_sampler_views[k]) {
121                block = TRUE;
122             }
123          }
124       }
125
126       if (block)
127          tr_ctx->draw_blocked |= (flag | 4);
128    }
129
130    if (tr_ctx->draw_blocked)
131       trace_rbug_notify_draw_blocked(tr_ctx);
132
133    /* wait for rbug to clear the blocked flag */
134    while (tr_ctx->draw_blocked & flag) {
135       tr_ctx->draw_blocked |= flag;
136 #ifdef PIPE_THREAD_HAVE_CONDVAR
137       pipe_condvar_wait(tr_ctx->draw_cond, tr_ctx->draw_mutex);
138 #else
139       pipe_mutex_unlock(tr_ctx->draw_mutex);
140 #ifdef PIPE_SUBSYSTEM_WINDOWS_USER
141       Sleep(1);
142 #endif
143       pipe_mutex_lock(tr_ctx->draw_mutex);
144 #endif
145    }
146
147    pipe_mutex_unlock(tr_ctx->draw_mutex);
148 }
149
150 static INLINE void
151 trace_context_draw_arrays(struct pipe_context *_pipe,
152                           unsigned mode, unsigned start, unsigned count)
153 {
154    struct trace_context *tr_ctx = trace_context(_pipe);
155    struct pipe_context *pipe = tr_ctx->pipe;
156
157    if (tr_ctx->curr.fs->disabled || tr_ctx->curr.vs->disabled)
158       return;
159
160    trace_context_draw_block(tr_ctx, 1);
161
162    trace_dump_call_begin("pipe_context", "draw_arrays");
163
164    trace_dump_arg(ptr, pipe);
165    trace_dump_arg(uint, mode);
166    trace_dump_arg(uint, start);
167    trace_dump_arg(uint, count);
168
169    pipe->draw_arrays(pipe, mode, start, count);
170
171    trace_dump_call_end();
172
173    trace_context_draw_block(tr_ctx, 2);
174 }
175
176
177 static INLINE void
178 trace_context_draw_elements(struct pipe_context *_pipe,
179                           struct pipe_resource *_indexBuffer,
180                           unsigned indexSize,
181                           unsigned mode, unsigned start, unsigned count)
182 {
183    struct trace_context *tr_ctx = trace_context(_pipe);
184    struct trace_resource *tr_buf = trace_resource(_indexBuffer);
185    struct pipe_context *pipe = tr_ctx->pipe;
186    struct pipe_resource *indexBuffer = tr_buf->resource;
187
188    if (tr_ctx->curr.fs->disabled || tr_ctx->curr.vs->disabled)
189       return;
190
191    trace_context_draw_block(tr_ctx, 1);
192
193    trace_dump_call_begin("pipe_context", "draw_elements");
194
195    trace_dump_arg(ptr, pipe);
196    trace_dump_arg(ptr, indexBuffer);
197    trace_dump_arg(uint, indexSize);
198    trace_dump_arg(uint, mode);
199    trace_dump_arg(uint, start);
200    trace_dump_arg(uint, count);
201
202    pipe->draw_elements(pipe, indexBuffer, indexSize, mode, start, count);
203
204    trace_dump_call_end();
205
206    trace_context_draw_block(tr_ctx, 2);
207 }
208
209
210 static INLINE void
211 trace_context_draw_range_elements(struct pipe_context *_pipe,
212                                   struct pipe_resource *_indexBuffer,
213                                   unsigned indexSize,
214                                   unsigned minIndex,
215                                   unsigned maxIndex,
216                                   unsigned mode,
217                                   unsigned start,
218                                   unsigned count)
219 {
220    struct trace_context *tr_ctx = trace_context(_pipe);
221    struct trace_resource *tr_buf = trace_resource(_indexBuffer);
222    struct pipe_context *pipe = tr_ctx->pipe;
223    struct pipe_resource *indexBuffer = tr_buf->resource;
224
225    if (tr_ctx->curr.fs->disabled || tr_ctx->curr.vs->disabled)
226       return;
227
228    trace_context_draw_block(tr_ctx, 1);
229
230    trace_dump_call_begin("pipe_context", "draw_range_elements");
231
232    trace_dump_arg(ptr, pipe);
233    trace_dump_arg(ptr, indexBuffer);
234    trace_dump_arg(uint, indexSize);
235    trace_dump_arg(uint, minIndex);
236    trace_dump_arg(uint, maxIndex);
237    trace_dump_arg(uint, mode);
238    trace_dump_arg(uint, start);
239    trace_dump_arg(uint, count);
240
241    pipe->draw_range_elements(pipe,
242                              indexBuffer,
243                              indexSize, minIndex, maxIndex,
244                              mode, start, count);
245
246    trace_dump_call_end();
247
248    trace_context_draw_block(tr_ctx, 2);
249 }
250
251
252 static INLINE struct pipe_query *
253 trace_context_create_query(struct pipe_context *_pipe,
254                            unsigned query_type)
255 {
256    struct trace_context *tr_ctx = trace_context(_pipe);
257    struct pipe_context *pipe = tr_ctx->pipe;
258    struct pipe_query *result;
259
260    trace_dump_call_begin("pipe_context", "create_query");
261
262    trace_dump_arg(ptr, pipe);
263    trace_dump_arg(uint, query_type);
264
265    result = pipe->create_query(pipe, query_type);
266
267    trace_dump_ret(ptr, result);
268
269    trace_dump_call_end();
270
271    return result;
272 }
273
274
275 static INLINE void
276 trace_context_destroy_query(struct pipe_context *_pipe,
277                             struct pipe_query *query)
278 {
279    struct trace_context *tr_ctx = trace_context(_pipe);
280    struct pipe_context *pipe = tr_ctx->pipe;
281
282    trace_dump_call_begin("pipe_context", "destroy_query");
283
284    trace_dump_arg(ptr, pipe);
285    trace_dump_arg(ptr, query);
286
287    pipe->destroy_query(pipe, query);
288
289    trace_dump_call_end();
290 }
291
292
293 static INLINE void
294 trace_context_begin_query(struct pipe_context *_pipe,
295                           struct pipe_query *query)
296 {
297    struct trace_context *tr_ctx = trace_context(_pipe);
298    struct pipe_context *pipe = tr_ctx->pipe;
299
300    trace_dump_call_begin("pipe_context", "begin_query");
301
302    trace_dump_arg(ptr, pipe);
303    trace_dump_arg(ptr, query);
304
305    pipe->begin_query(pipe, query);
306
307    trace_dump_call_end();
308 }
309
310
311 static INLINE void
312 trace_context_end_query(struct pipe_context *_pipe,
313                         struct pipe_query *query)
314 {
315    struct trace_context *tr_ctx = trace_context(_pipe);
316    struct pipe_context *pipe = tr_ctx->pipe;
317
318    trace_dump_call_begin("pipe_context", "end_query");
319
320    trace_dump_arg(ptr, pipe);
321    trace_dump_arg(ptr, query);
322
323    pipe->end_query(pipe, query);
324
325    trace_dump_call_end();
326 }
327
328
329 static INLINE boolean
330 trace_context_get_query_result(struct pipe_context *_pipe,
331                                struct pipe_query *query,
332                                boolean wait,
333                                uint64_t *presult)
334 {
335    struct trace_context *tr_ctx = trace_context(_pipe);
336    struct pipe_context *pipe = tr_ctx->pipe;
337    uint64_t result;
338    boolean _result;
339
340    trace_dump_call_begin("pipe_context", "get_query_result");
341
342    trace_dump_arg(ptr, pipe);
343
344    _result = pipe->get_query_result(pipe, query, wait, presult);
345    result = *presult;
346
347    trace_dump_arg(uint, result);
348    trace_dump_ret(bool, _result);
349
350    trace_dump_call_end();
351
352    return _result;
353 }
354
355
356 static INLINE void *
357 trace_context_create_blend_state(struct pipe_context *_pipe,
358                                  const struct pipe_blend_state *state)
359 {
360    struct trace_context *tr_ctx = trace_context(_pipe);
361    struct pipe_context *pipe = tr_ctx->pipe;
362    void * result;
363
364    trace_dump_call_begin("pipe_context", "create_blend_state");
365
366    trace_dump_arg(ptr, pipe);
367    trace_dump_arg(blend_state, state);
368
369    result = pipe->create_blend_state(pipe, state);
370
371    trace_dump_ret(ptr, result);
372
373    trace_dump_call_end();
374
375    return result;
376 }
377
378
379 static INLINE void
380 trace_context_bind_blend_state(struct pipe_context *_pipe,
381                                void *state)
382 {
383    struct trace_context *tr_ctx = trace_context(_pipe);
384    struct pipe_context *pipe = tr_ctx->pipe;
385
386    trace_dump_call_begin("pipe_context", "bind_blend_state");
387
388    trace_dump_arg(ptr, pipe);
389    trace_dump_arg(ptr, state);
390
391    pipe->bind_blend_state(pipe, state);
392
393    trace_dump_call_end();
394 }
395
396
397 static INLINE void
398 trace_context_delete_blend_state(struct pipe_context *_pipe,
399                                  void *state)
400 {
401    struct trace_context *tr_ctx = trace_context(_pipe);
402    struct pipe_context *pipe = tr_ctx->pipe;
403
404    trace_dump_call_begin("pipe_context", "delete_blend_state");
405
406    trace_dump_arg(ptr, pipe);
407    trace_dump_arg(ptr, state);
408
409    pipe->delete_blend_state(pipe, state);
410
411    trace_dump_call_end();
412 }
413
414
415 static INLINE void *
416 trace_context_create_sampler_state(struct pipe_context *_pipe,
417                                    const struct pipe_sampler_state *state)
418 {
419    struct trace_context *tr_ctx = trace_context(_pipe);
420    struct pipe_context *pipe = tr_ctx->pipe;
421    void * result;
422
423    trace_dump_call_begin("pipe_context", "create_sampler_state");
424
425    trace_dump_arg(ptr, pipe);
426    trace_dump_arg(sampler_state, state);
427
428    result = pipe->create_sampler_state(pipe, state);
429
430    trace_dump_ret(ptr, result);
431
432    trace_dump_call_end();
433
434    return result;
435 }
436
437
438 static INLINE void
439 trace_context_bind_fragment_sampler_states(struct pipe_context *_pipe,
440                                            unsigned num_states,
441                                            void **states)
442 {
443    struct trace_context *tr_ctx = trace_context(_pipe);
444    struct pipe_context *pipe = tr_ctx->pipe;
445
446    trace_dump_call_begin("pipe_context", "bind_fragment_sampler_states");
447
448    trace_dump_arg(ptr, pipe);
449    trace_dump_arg(uint, num_states);
450    trace_dump_arg_array(ptr, states, num_states);
451
452    pipe->bind_fragment_sampler_states(pipe, num_states, states);
453
454    trace_dump_call_end();
455 }
456
457
458 static INLINE void
459 trace_context_bind_vertex_sampler_states(struct pipe_context *_pipe,
460                                          unsigned num_states,
461                                          void **states)
462 {
463    struct trace_context *tr_ctx = trace_context(_pipe);
464    struct pipe_context *pipe = tr_ctx->pipe;
465
466    trace_dump_call_begin("pipe_context", "bind_vertex_sampler_states");
467
468    trace_dump_arg(ptr, pipe);
469    trace_dump_arg(uint, num_states);
470    trace_dump_arg_array(ptr, states, num_states);
471
472    pipe->bind_vertex_sampler_states(pipe, num_states, states);
473
474    trace_dump_call_end();
475 }
476
477
478 static INLINE void
479 trace_context_delete_sampler_state(struct pipe_context *_pipe,
480                                    void *state)
481 {
482    struct trace_context *tr_ctx = trace_context(_pipe);
483    struct pipe_context *pipe = tr_ctx->pipe;
484
485    trace_dump_call_begin("pipe_context", "delete_sampler_state");
486
487    trace_dump_arg(ptr, pipe);
488    trace_dump_arg(ptr, state);
489
490    pipe->delete_sampler_state(pipe, state);
491
492    trace_dump_call_end();
493 }
494
495
496 static INLINE void *
497 trace_context_create_rasterizer_state(struct pipe_context *_pipe,
498                                       const struct pipe_rasterizer_state *state)
499 {
500    struct trace_context *tr_ctx = trace_context(_pipe);
501    struct pipe_context *pipe = tr_ctx->pipe;
502    void * result;
503
504    trace_dump_call_begin("pipe_context", "create_rasterizer_state");
505
506    trace_dump_arg(ptr, pipe);
507    trace_dump_arg(rasterizer_state, state);
508
509    result = pipe->create_rasterizer_state(pipe, state);
510
511    trace_dump_ret(ptr, result);
512
513    trace_dump_call_end();
514
515    return result;
516 }
517
518
519 static INLINE void
520 trace_context_bind_rasterizer_state(struct pipe_context *_pipe,
521                                     void *state)
522 {
523    struct trace_context *tr_ctx = trace_context(_pipe);
524    struct pipe_context *pipe = tr_ctx->pipe;
525
526    trace_dump_call_begin("pipe_context", "bind_rasterizer_state");
527
528    trace_dump_arg(ptr, pipe);
529    trace_dump_arg(ptr, state);
530
531    pipe->bind_rasterizer_state(pipe, state);
532
533    trace_dump_call_end();
534 }
535
536
537 static INLINE void
538 trace_context_delete_rasterizer_state(struct pipe_context *_pipe,
539                                       void *state)
540 {
541    struct trace_context *tr_ctx = trace_context(_pipe);
542    struct pipe_context *pipe = tr_ctx->pipe;
543
544    trace_dump_call_begin("pipe_context", "delete_rasterizer_state");
545
546    trace_dump_arg(ptr, pipe);
547    trace_dump_arg(ptr, state);
548
549    pipe->delete_rasterizer_state(pipe, state);
550
551    trace_dump_call_end();
552 }
553
554
555 static INLINE void *
556 trace_context_create_depth_stencil_alpha_state(struct pipe_context *_pipe,
557                                                const struct pipe_depth_stencil_alpha_state *state)
558 {
559    struct trace_context *tr_ctx = trace_context(_pipe);
560    struct pipe_context *pipe = tr_ctx->pipe;
561    void * result;
562
563    trace_dump_call_begin("pipe_context", "create_depth_stencil_alpha_state");
564
565    result = pipe->create_depth_stencil_alpha_state(pipe, state);
566
567    trace_dump_arg(ptr, pipe);
568    trace_dump_arg(depth_stencil_alpha_state, state);
569
570    trace_dump_ret(ptr, result);
571
572    trace_dump_call_end();
573
574    return result;
575 }
576
577
578 static INLINE void
579 trace_context_bind_depth_stencil_alpha_state(struct pipe_context *_pipe,
580                                              void *state)
581 {
582    struct trace_context *tr_ctx = trace_context(_pipe);
583    struct pipe_context *pipe = tr_ctx->pipe;
584
585    trace_dump_call_begin("pipe_context", "bind_depth_stencil_alpha_state");
586
587    trace_dump_arg(ptr, pipe);
588    trace_dump_arg(ptr, state);
589
590    pipe->bind_depth_stencil_alpha_state(pipe, state);
591
592    trace_dump_call_end();
593 }
594
595
596 static INLINE void
597 trace_context_delete_depth_stencil_alpha_state(struct pipe_context *_pipe,
598                                                void *state)
599 {
600    struct trace_context *tr_ctx = trace_context(_pipe);
601    struct pipe_context *pipe = tr_ctx->pipe;
602
603    trace_dump_call_begin("pipe_context", "delete_depth_stencil_alpha_state");
604
605    trace_dump_arg(ptr, pipe);
606    trace_dump_arg(ptr, state);
607
608    pipe->delete_depth_stencil_alpha_state(pipe, state);
609
610    trace_dump_call_end();
611 }
612
613
614 static INLINE void *
615 trace_context_create_fs_state(struct pipe_context *_pipe,
616                               const struct pipe_shader_state *state)
617 {
618    struct trace_context *tr_ctx = trace_context(_pipe);
619    struct pipe_context *pipe = tr_ctx->pipe;
620    void * result;
621
622    trace_dump_call_begin("pipe_context", "create_fs_state");
623
624    trace_dump_arg(ptr, pipe);
625    trace_dump_arg(shader_state, state);
626
627    result = pipe->create_fs_state(pipe, state);
628
629    trace_dump_ret(ptr, result);
630
631    trace_dump_call_end();
632
633    result = trace_shader_create(tr_ctx, state, result, TRACE_SHADER_FRAGMENT);
634
635    return result;
636 }
637
638
639 static INLINE void
640 trace_context_bind_fs_state(struct pipe_context *_pipe,
641                             void *_state)
642 {
643    struct trace_context *tr_ctx = trace_context(_pipe);
644    struct trace_shader *tr_shdr = trace_shader(_state);
645    struct pipe_context *pipe = tr_ctx->pipe;
646    void *state = tr_shdr ? tr_shdr->state : NULL;
647
648    trace_dump_call_begin("pipe_context", "bind_fs_state");
649
650    trace_dump_arg(ptr, pipe);
651    trace_dump_arg(ptr, state);
652
653    tr_ctx->curr.fs = tr_shdr;
654
655    if (tr_shdr && tr_shdr->replaced)
656       state = tr_shdr->replaced;
657
658    pipe->bind_fs_state(pipe, state);
659
660    trace_dump_call_end();
661 }
662
663
664 static INLINE void
665 trace_context_delete_fs_state(struct pipe_context *_pipe,
666                               void *_state)
667 {
668    struct trace_context *tr_ctx = trace_context(_pipe);
669    struct trace_shader *tr_shdr = trace_shader(_state);
670    struct pipe_context *pipe = tr_ctx->pipe;
671    void *state = tr_shdr->state;
672
673    trace_dump_call_begin("pipe_context", "delete_fs_state");
674
675    trace_dump_arg(ptr, pipe);
676    trace_dump_arg(ptr, state);
677
678    pipe->delete_fs_state(pipe, state);
679
680    trace_dump_call_end();
681
682    trace_shader_destroy(tr_ctx, tr_shdr);
683 }
684
685
686 static INLINE void *
687 trace_context_create_vs_state(struct pipe_context *_pipe,
688                               const struct pipe_shader_state *state)
689 {
690    struct trace_context *tr_ctx = trace_context(_pipe);
691    struct pipe_context *pipe = tr_ctx->pipe;
692    void * result;
693
694    trace_dump_call_begin("pipe_context", "create_vs_state");
695
696    trace_dump_arg(ptr, pipe);
697    trace_dump_arg(shader_state, state);
698
699    result = pipe->create_vs_state(pipe, state);
700
701    trace_dump_ret(ptr, result);
702
703    trace_dump_call_end();
704
705    result = trace_shader_create(tr_ctx, state, result, TRACE_SHADER_VERTEX);
706
707    return result;
708 }
709
710
711 static INLINE void
712 trace_context_bind_vs_state(struct pipe_context *_pipe,
713                             void *_state)
714 {
715    struct trace_context *tr_ctx = trace_context(_pipe);
716    struct trace_shader *tr_shdr = trace_shader(_state);
717    struct pipe_context *pipe = tr_ctx->pipe;
718    void *state = tr_shdr ? tr_shdr->state : NULL;
719
720    trace_dump_call_begin("pipe_context", "bind_vs_state");
721
722    trace_dump_arg(ptr, pipe);
723    trace_dump_arg(ptr, state);
724
725    tr_ctx->curr.vs = tr_shdr;
726
727    if (tr_shdr && tr_shdr->replaced)
728       state = tr_shdr->replaced;
729
730    pipe->bind_vs_state(pipe, state);
731
732    trace_dump_call_end();
733 }
734
735
736 static INLINE void
737 trace_context_delete_vs_state(struct pipe_context *_pipe,
738                               void *_state)
739 {
740    struct trace_context *tr_ctx = trace_context(_pipe);
741    struct trace_shader *tr_shdr = trace_shader(_state);
742    struct pipe_context *pipe = tr_ctx->pipe;
743    void *state = tr_shdr->state;
744
745    trace_dump_call_begin("pipe_context", "delete_vs_state");
746
747    trace_dump_arg(ptr, pipe);
748    trace_dump_arg(ptr, state);
749
750    pipe->delete_vs_state(pipe, state);
751
752    trace_dump_call_end();
753
754    trace_shader_destroy(tr_ctx, tr_shdr);
755 }
756
757
758 static INLINE void *
759 trace_context_create_vertex_elements_state(struct pipe_context *_pipe,
760                                            unsigned num_elements,
761                                            const struct  pipe_vertex_element *elements)
762 {
763    struct trace_context *tr_ctx = trace_context(_pipe);
764    struct pipe_context *pipe = tr_ctx->pipe;
765    void * result;
766
767    trace_dump_call_begin("pipe_context", "create_vertex_elements_state");
768
769    trace_dump_arg(ptr, pipe);
770    trace_dump_arg(uint, num_elements);
771
772    trace_dump_arg_begin("elements");
773    trace_dump_struct_array(vertex_element, elements, num_elements);
774    trace_dump_arg_end();
775
776    result = pipe->create_vertex_elements_state(pipe, num_elements, elements);
777
778    trace_dump_ret(ptr, result);
779
780    trace_dump_call_end();
781
782    return result;
783 }
784
785
786 static INLINE void
787 trace_context_bind_vertex_elements_state(struct pipe_context *_pipe,
788                                          void *state)
789 {
790    struct trace_context *tr_ctx = trace_context(_pipe);
791    struct pipe_context *pipe = tr_ctx->pipe;
792
793    trace_dump_call_begin("pipe_context", "bind_vertex_elements_state");
794
795    trace_dump_arg(ptr, pipe);
796    trace_dump_arg(ptr, state);
797
798    pipe->bind_vertex_elements_state(pipe, state);
799
800    trace_dump_call_end();
801 }
802
803
804 static INLINE void
805 trace_context_delete_vertex_elements_state(struct pipe_context *_pipe,
806                                            void *state)
807 {
808    struct trace_context *tr_ctx = trace_context(_pipe);
809    struct pipe_context *pipe = tr_ctx->pipe;
810
811    trace_dump_call_begin("pipe_context", "delete_verte_elements_state");
812
813    trace_dump_arg(ptr, pipe);
814    trace_dump_arg(ptr, state);
815
816    pipe->delete_vertex_elements_state(pipe, state);
817
818    trace_dump_call_end();
819 }
820
821
822 static INLINE void
823 trace_context_set_blend_color(struct pipe_context *_pipe,
824                               const struct pipe_blend_color *state)
825 {
826    struct trace_context *tr_ctx = trace_context(_pipe);
827    struct pipe_context *pipe = tr_ctx->pipe;
828
829    trace_dump_call_begin("pipe_context", "set_blend_color");
830
831    trace_dump_arg(ptr, pipe);
832    trace_dump_arg(blend_color, state);
833
834    pipe->set_blend_color(pipe, state);
835
836    trace_dump_call_end();
837 }
838
839
840 static INLINE void
841 trace_context_set_stencil_ref(struct pipe_context *_pipe,
842                               const struct pipe_stencil_ref *state)
843 {
844    struct trace_context *tr_ctx = trace_context(_pipe);
845    struct pipe_context *pipe = tr_ctx->pipe;
846
847    trace_dump_call_begin("pipe_context", "set_stencil_ref");
848
849    trace_dump_arg(ptr, pipe);
850    trace_dump_arg(stencil_ref, state);
851
852    pipe->set_stencil_ref(pipe, state);
853
854    trace_dump_call_end();
855 }
856
857
858 static INLINE void
859 trace_context_set_clip_state(struct pipe_context *_pipe,
860                              const struct pipe_clip_state *state)
861 {
862    struct trace_context *tr_ctx = trace_context(_pipe);
863    struct pipe_context *pipe = tr_ctx->pipe;
864
865    trace_dump_call_begin("pipe_context", "set_clip_state");
866
867    trace_dump_arg(ptr, pipe);
868    trace_dump_arg(clip_state, state);
869
870    pipe->set_clip_state(pipe, state);
871
872    trace_dump_call_end();
873 }
874
875
876 static INLINE void
877 trace_context_set_constant_buffer(struct pipe_context *_pipe,
878                                   uint shader, uint index,
879                                   struct pipe_resource *buffer)
880 {
881    struct trace_context *tr_ctx = trace_context(_pipe);
882    struct pipe_context *pipe = tr_ctx->pipe;
883
884    if (buffer) {
885       buffer = trace_resource_unwrap(tr_ctx, buffer);
886    }
887
888    trace_dump_call_begin("pipe_context", "set_constant_buffer");
889
890    trace_dump_arg(ptr, pipe);
891    trace_dump_arg(uint, shader);
892    trace_dump_arg(uint, index);
893    trace_dump_arg(ptr, buffer);
894
895    pipe->set_constant_buffer(pipe, shader, index, buffer);
896
897    trace_dump_call_end();
898 }
899
900
901 static INLINE void
902 trace_context_set_framebuffer_state(struct pipe_context *_pipe,
903                                     const struct pipe_framebuffer_state *state)
904 {
905    struct trace_context *tr_ctx = trace_context(_pipe);
906    struct pipe_context *pipe = tr_ctx->pipe;
907    struct pipe_framebuffer_state unwrapped_state;
908    unsigned i;
909
910    {
911       tr_ctx->curr.nr_cbufs = state->nr_cbufs;
912       for (i = 0; i < state->nr_cbufs; i++)
913          if (state->cbufs[i])
914             tr_ctx->curr.cbufs[i] = trace_resource(state->cbufs[i]->texture);
915          else
916             tr_ctx->curr.cbufs[i] = NULL;
917       if (state->zsbuf)
918          tr_ctx->curr.zsbuf = trace_resource(state->zsbuf->texture);
919       else
920          tr_ctx->curr.zsbuf = NULL;
921    }
922
923    /* Unwrap the input state */
924    memcpy(&unwrapped_state, state, sizeof(unwrapped_state));
925    for(i = 0; i < state->nr_cbufs; ++i)
926       unwrapped_state.cbufs[i] = trace_surface_unwrap(tr_ctx, state->cbufs[i]);
927    for(i = state->nr_cbufs; i < PIPE_MAX_COLOR_BUFS; ++i)
928       unwrapped_state.cbufs[i] = NULL;
929    unwrapped_state.zsbuf = trace_surface_unwrap(tr_ctx, state->zsbuf);
930    state = &unwrapped_state;
931
932    trace_dump_call_begin("pipe_context", "set_framebuffer_state");
933
934    trace_dump_arg(ptr, pipe);
935    trace_dump_arg(framebuffer_state, state);
936
937    pipe->set_framebuffer_state(pipe, state);
938
939    trace_dump_call_end();
940 }
941
942
943 static INLINE void
944 trace_context_set_polygon_stipple(struct pipe_context *_pipe,
945                                   const struct pipe_poly_stipple *state)
946 {
947    struct trace_context *tr_ctx = trace_context(_pipe);
948    struct pipe_context *pipe = tr_ctx->pipe;
949
950    trace_dump_call_begin("pipe_context", "set_polygon_stipple");
951
952    trace_dump_arg(ptr, pipe);
953    trace_dump_arg(poly_stipple, state);
954
955    pipe->set_polygon_stipple(pipe, state);
956
957    trace_dump_call_end();
958 }
959
960
961 static INLINE void
962 trace_context_set_scissor_state(struct pipe_context *_pipe,
963                                 const struct pipe_scissor_state *state)
964 {
965    struct trace_context *tr_ctx = trace_context(_pipe);
966    struct pipe_context *pipe = tr_ctx->pipe;
967
968    trace_dump_call_begin("pipe_context", "set_scissor_state");
969
970    trace_dump_arg(ptr, pipe);
971    trace_dump_arg(scissor_state, state);
972
973    pipe->set_scissor_state(pipe, state);
974
975    trace_dump_call_end();
976 }
977
978
979 static INLINE void
980 trace_context_set_viewport_state(struct pipe_context *_pipe,
981                                  const struct pipe_viewport_state *state)
982 {
983    struct trace_context *tr_ctx = trace_context(_pipe);
984    struct pipe_context *pipe = tr_ctx->pipe;
985
986    trace_dump_call_begin("pipe_context", "set_viewport_state");
987
988    trace_dump_arg(ptr, pipe);
989    trace_dump_arg(viewport_state, state);
990
991    pipe->set_viewport_state(pipe, state);
992
993    trace_dump_call_end();
994 }
995
996
997 static struct pipe_sampler_view *
998 trace_create_sampler_view(struct pipe_context *_pipe,
999                           struct pipe_resource *_resource,
1000                           const struct pipe_sampler_view *templ)
1001 {
1002    struct trace_context *tr_ctx = trace_context(_pipe);
1003    struct trace_resource *tr_tex = trace_resource(_resource);
1004    struct pipe_context *pipe = tr_ctx->pipe;
1005    struct pipe_resource *texture = tr_tex->resource;
1006    struct trace_sampler_view *result = CALLOC_STRUCT(trace_sampler_view);
1007
1008    trace_dump_call_begin("pipe_context", "create_sampler_view");
1009
1010    trace_dump_arg(ptr, pipe);
1011    trace_dump_arg(ptr, texture);
1012    trace_dump_arg(ptr, templ);
1013
1014    result->sampler_view = pipe->create_sampler_view(pipe, texture, templ);
1015
1016    result->base = *templ;
1017    result->base.reference.count = 1;
1018    result->base.texture = NULL;
1019    pipe_resource_reference(&result->base.texture, _resource);
1020    result->base.context = _pipe;
1021
1022    trace_dump_ret(ptr, result);
1023
1024    trace_dump_call_end();
1025
1026    return &result->base;
1027 }
1028
1029
1030 static void
1031 trace_sampler_view_destroy(struct pipe_context *_pipe,
1032                            struct pipe_sampler_view *_view)
1033 {
1034    struct trace_context *tr_ctx = trace_context(_pipe);
1035    struct trace_sampler_view *tr_view = trace_sampler_view(_view);
1036    struct pipe_context *pipe = tr_ctx->pipe;
1037    struct pipe_sampler_view *view = tr_view->sampler_view;
1038
1039    trace_dump_call_begin("pipe_context", "sampler_view_destroy");
1040
1041    trace_dump_arg(ptr, pipe);
1042    trace_dump_arg(ptr, view);
1043
1044    pipe->sampler_view_destroy(pipe, view);
1045
1046    trace_dump_call_end();
1047
1048    pipe_resource_reference(&_view->texture, NULL);
1049    FREE(_view);
1050 }
1051
1052
1053 static INLINE void
1054 trace_context_set_fragment_sampler_views(struct pipe_context *_pipe,
1055                                          unsigned num,
1056                                          struct pipe_sampler_view **views)
1057 {
1058    struct trace_context *tr_ctx = trace_context(_pipe);
1059    struct trace_sampler_view *tr_view;
1060    struct pipe_context *pipe = tr_ctx->pipe;
1061    struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS];
1062    unsigned i;
1063
1064    tr_ctx->curr.num_sampler_views = num;
1065    for(i = 0; i < num; ++i) {
1066       tr_view = trace_sampler_view(views[i]);
1067       tr_ctx->curr.sampler_views[i] = tr_view;
1068       unwrapped_views[i] = tr_view ? tr_view->sampler_view : NULL;
1069    }
1070    views = unwrapped_views;
1071
1072    trace_dump_call_begin("pipe_context", "set_fragment_sampler_views");
1073
1074    trace_dump_arg(ptr, pipe);
1075    trace_dump_arg(uint, num);
1076    trace_dump_arg_array(ptr, views, num);
1077
1078    pipe->set_fragment_sampler_views(pipe, num, views);
1079
1080    trace_dump_call_end();
1081 }
1082
1083
1084 static INLINE void
1085 trace_context_set_vertex_sampler_views(struct pipe_context *_pipe,
1086                                        unsigned num,
1087                                        struct pipe_sampler_view **views)
1088 {
1089    struct trace_context *tr_ctx = trace_context(_pipe);
1090    struct trace_sampler_view *tr_view;
1091    struct pipe_context *pipe = tr_ctx->pipe;
1092    struct pipe_sampler_view *unwrapped_views[PIPE_MAX_VERTEX_SAMPLERS];
1093    unsigned i;
1094
1095    tr_ctx->curr.num_vert_sampler_views = num;
1096    for(i = 0; i < num; ++i) {
1097       tr_view = trace_sampler_view(views[i]);
1098       tr_ctx->curr.vert_sampler_views[i] = tr_view;
1099       unwrapped_views[i] = tr_view ? tr_view->sampler_view : NULL;
1100    }
1101    views = unwrapped_views;
1102
1103    trace_dump_call_begin("pipe_context", "set_vertex_sampler_views");
1104
1105    trace_dump_arg(ptr, pipe);
1106    trace_dump_arg(uint, num);
1107    trace_dump_arg_array(ptr, views, num);
1108
1109    pipe->set_vertex_sampler_views(pipe, num, views);
1110
1111    trace_dump_call_end();
1112 }
1113
1114
1115 static INLINE void
1116 trace_context_set_vertex_buffers(struct pipe_context *_pipe,
1117                                  unsigned num_buffers,
1118                                  const struct pipe_vertex_buffer *buffers)
1119 {
1120    struct trace_context *tr_ctx = trace_context(_pipe);
1121    struct pipe_context *pipe = tr_ctx->pipe;
1122    unsigned i;
1123
1124    trace_dump_call_begin("pipe_context", "set_vertex_buffers");
1125
1126    trace_dump_arg(ptr, pipe);
1127    trace_dump_arg(uint, num_buffers);
1128
1129    trace_dump_arg_begin("buffers");
1130    trace_dump_struct_array(vertex_buffer, buffers, num_buffers);
1131    trace_dump_arg_end();
1132
1133    if (num_buffers) {
1134       struct pipe_vertex_buffer *_buffers = malloc(num_buffers * sizeof(*_buffers));
1135       memcpy(_buffers, buffers, num_buffers * sizeof(*_buffers));
1136       for (i = 0; i < num_buffers; i++)
1137          _buffers[i].buffer = trace_resource_unwrap(tr_ctx, buffers[i].buffer);
1138       pipe->set_vertex_buffers(pipe, num_buffers, _buffers);
1139       free(_buffers);
1140    } else {
1141       pipe->set_vertex_buffers(pipe, num_buffers, NULL);
1142    }
1143
1144    trace_dump_call_end();
1145 }
1146
1147
1148 static INLINE void
1149 trace_context_surface_copy(struct pipe_context *_pipe,
1150                            struct pipe_surface *dest,
1151                            unsigned destx, unsigned desty,
1152                            struct pipe_surface *src,
1153                            unsigned srcx, unsigned srcy,
1154                            unsigned width, unsigned height)
1155 {
1156    struct trace_context *tr_ctx = trace_context(_pipe);
1157    struct pipe_context *pipe = tr_ctx->pipe;
1158
1159    dest = trace_surface_unwrap(tr_ctx, dest);
1160    src = trace_surface_unwrap(tr_ctx, src);
1161
1162    trace_dump_call_begin("pipe_context", "surface_copy");
1163
1164    trace_dump_arg(ptr, pipe);
1165    trace_dump_arg(ptr, dest);
1166    trace_dump_arg(uint, destx);
1167    trace_dump_arg(uint, desty);
1168    trace_dump_arg(ptr, src);
1169    trace_dump_arg(uint, srcx);
1170    trace_dump_arg(uint, srcy);
1171    trace_dump_arg(uint, width);
1172    trace_dump_arg(uint, height);
1173
1174    pipe->surface_copy(pipe,
1175                       dest, destx, desty,
1176                       src, srcx, srcy, width, height);
1177
1178    trace_dump_call_end();
1179 }
1180
1181
1182 static INLINE void
1183 trace_context_surface_fill(struct pipe_context *_pipe,
1184                            struct pipe_surface *dst,
1185                            unsigned dstx, unsigned dsty,
1186                            unsigned width, unsigned height,
1187                            unsigned value)
1188 {
1189    struct trace_context *tr_ctx = trace_context(_pipe);
1190    struct pipe_context *pipe = tr_ctx->pipe;
1191
1192    dst = trace_surface_unwrap(tr_ctx, dst);
1193
1194    trace_dump_call_begin("pipe_context", "surface_fill");
1195
1196    trace_dump_arg(ptr, pipe);
1197    trace_dump_arg(ptr, dst);
1198    trace_dump_arg(uint, dstx);
1199    trace_dump_arg(uint, dsty);
1200    trace_dump_arg(uint, width);
1201    trace_dump_arg(uint, height);
1202
1203    pipe->surface_fill(pipe, dst, dstx, dsty, width, height, value);
1204
1205    trace_dump_call_end();
1206 }
1207
1208
1209 static INLINE void
1210 trace_context_clear(struct pipe_context *_pipe,
1211                     unsigned buffers,
1212                     const float *rgba,
1213                     double depth,
1214                     unsigned stencil)
1215 {
1216    struct trace_context *tr_ctx = trace_context(_pipe);
1217    struct pipe_context *pipe = tr_ctx->pipe;
1218
1219    trace_dump_call_begin("pipe_context", "clear");
1220
1221    trace_dump_arg(ptr, pipe);
1222    trace_dump_arg(uint, buffers);
1223    trace_dump_arg_array(float, rgba, 4);
1224    trace_dump_arg(float, depth);
1225    trace_dump_arg(uint, stencil);
1226
1227    pipe->clear(pipe, buffers, rgba, depth, stencil);
1228
1229    trace_dump_call_end();
1230 }
1231
1232
1233 static INLINE void
1234 trace_context_flush(struct pipe_context *_pipe,
1235                     unsigned flags,
1236                     struct pipe_fence_handle **fence)
1237 {
1238    struct trace_context *tr_ctx = trace_context(_pipe);
1239    struct pipe_context *pipe = tr_ctx->pipe;
1240
1241    trace_dump_call_begin("pipe_context", "flush");
1242
1243    trace_dump_arg(ptr, pipe);
1244    trace_dump_arg(uint, flags);
1245
1246    pipe->flush(pipe, flags, fence);
1247
1248    if(fence)
1249       trace_dump_ret(ptr, *fence);
1250
1251    trace_dump_call_end();
1252 }
1253
1254
1255 static INLINE void
1256 trace_context_destroy(struct pipe_context *_pipe)
1257 {
1258    struct trace_screen *tr_scr = trace_screen(_pipe->screen);
1259    struct trace_context *tr_ctx = trace_context(_pipe);
1260    struct pipe_context *pipe = tr_ctx->pipe;
1261
1262    trace_dump_call_begin("pipe_context", "destroy");
1263    trace_dump_arg(ptr, pipe);
1264    trace_dump_call_end();
1265
1266    trace_screen_remove_from_list(tr_scr, contexts, tr_ctx);
1267
1268    pipe->destroy(pipe);
1269
1270    FREE(tr_ctx);
1271 }
1272
1273 static unsigned int
1274 trace_is_resource_referenced( struct pipe_context *_pipe,
1275                               struct pipe_resource *_resource,
1276                               unsigned face, unsigned level)
1277 {
1278    struct trace_context *tr_ctx = trace_context(_pipe);
1279    struct trace_resource *tr_tex = trace_resource(_resource);
1280    struct pipe_context *pipe = tr_ctx->pipe;
1281    struct pipe_resource *texture = tr_tex->resource;
1282    unsigned int referenced;
1283
1284    trace_dump_call_begin("pipe_context", "is_resource_referenced");
1285    trace_dump_arg(ptr, pipe);
1286    trace_dump_arg(ptr, texture);
1287    trace_dump_arg(uint, face);
1288    trace_dump_arg(uint, level);
1289
1290    referenced = pipe->is_resource_referenced(pipe, texture, face, level);
1291
1292    trace_dump_ret(uint, referenced);
1293    trace_dump_call_end();
1294
1295    return referenced;
1296 }
1297
1298
1299 /********************************************************************
1300  * transfer
1301  */
1302
1303
1304 static struct pipe_transfer *
1305 trace_context_get_transfer(struct pipe_context *_context,
1306                            struct pipe_resource *_resource,
1307                            struct pipe_subresource sr,
1308                            unsigned usage,
1309                            const struct pipe_box *box)
1310 {
1311    struct trace_context *tr_context = trace_context(_context);
1312    struct trace_resource *tr_tex = trace_resource(_resource);
1313    struct pipe_context *context = tr_context->pipe;
1314    struct pipe_resource *texture = tr_tex->resource;
1315    struct pipe_transfer *result = NULL;
1316
1317    assert(texture->screen == context->screen);
1318
1319    trace_dump_call_begin("pipe_context", "get_transfer");
1320
1321    trace_dump_arg(ptr, context);
1322    trace_dump_arg(ptr, texture);
1323    trace_dump_arg(uint, sr.face);
1324    trace_dump_arg(uint, sr.level);
1325    trace_dump_arg(uint, usage);
1326    trace_dump_arg(uint, box->x);
1327    trace_dump_arg(uint, box->y);
1328    trace_dump_arg(uint, box->z);
1329    trace_dump_arg(uint, box->width);
1330    trace_dump_arg(uint, box->height);
1331    trace_dump_arg(uint, box->depth);
1332
1333    result = context->get_transfer(context, texture, sr, usage, box);
1334
1335    trace_dump_ret(ptr, result);
1336
1337    trace_dump_call_end();
1338
1339    if (result)
1340       result = trace_transfer_create(tr_context, tr_tex, result);
1341
1342    return result;
1343 }
1344
1345
1346 static void
1347 trace_context_transfer_destroy(struct pipe_context *_context,
1348                                    struct pipe_transfer *_transfer)
1349 {
1350    struct trace_context *tr_context = trace_context(_context);
1351    struct trace_transfer *tr_trans = trace_transfer(_transfer);
1352    struct pipe_context *context = tr_context->pipe;
1353    struct pipe_transfer *transfer = tr_trans->transfer;
1354
1355    trace_dump_call_begin("pipe_context", "transfer_destroy");
1356
1357    trace_dump_arg(ptr, context);
1358    trace_dump_arg(ptr, transfer);
1359
1360    trace_dump_call_end();
1361
1362    trace_transfer_destroy(tr_context, tr_trans);
1363 }
1364
1365
1366 static void *
1367 trace_context_transfer_map(struct pipe_context *_context,
1368                           struct pipe_transfer *_transfer)
1369 {
1370    struct trace_context *tr_context = trace_context(_context);
1371    struct trace_transfer *tr_trans = trace_transfer(_transfer);
1372    struct pipe_context *context = tr_context->pipe;
1373    struct pipe_transfer *transfer = tr_trans->transfer;
1374    void *map;
1375
1376    map = context->transfer_map(context, transfer);
1377    if(map) {
1378       if(transfer->usage & PIPE_TRANSFER_WRITE) {
1379          assert(!tr_trans->map);
1380          tr_trans->map = map;
1381       }
1382    }
1383
1384    return map;
1385 }
1386
1387
1388 static void
1389 trace_context_transfer_flush_region( struct pipe_context *_context,
1390                                      struct pipe_transfer *_transfer,
1391                                      const struct pipe_box *box)
1392 {
1393    struct trace_context *tr_context = trace_context(_context);
1394    struct trace_transfer *tr_transfer = trace_transfer(_transfer);
1395    struct pipe_context *context = tr_context->pipe;
1396    struct pipe_transfer *transfer = tr_transfer->transfer;
1397
1398    trace_dump_call_begin("pipe_context", "transfer_flush_region");
1399
1400    trace_dump_arg(ptr, context);
1401    trace_dump_arg(ptr, transfer);
1402    trace_dump_arg(uint, box->x);
1403    trace_dump_arg(uint, box->y);
1404    trace_dump_arg(uint, box->z);
1405    trace_dump_arg(uint, box->width);
1406    trace_dump_arg(uint, box->height);
1407    trace_dump_arg(uint, box->depth);
1408    trace_dump_call_end();
1409
1410    context->transfer_flush_region(context,
1411                                   transfer,
1412                                   box);
1413 }
1414
1415 static void
1416 trace_context_transfer_unmap(struct pipe_context *_context,
1417                              struct pipe_transfer *_transfer)
1418 {
1419    struct trace_context *tr_ctx = trace_context(_context);
1420    struct trace_transfer *tr_trans = trace_transfer(_transfer);
1421    struct pipe_context *context = tr_ctx->pipe;
1422    struct pipe_transfer *transfer = tr_trans->transfer;
1423
1424    if(tr_trans->map) {
1425       trace_dump_call_begin("pipe_context", "transfer_write");
1426
1427       trace_dump_arg(ptr, context);
1428
1429       trace_dump_arg(ptr, transfer);
1430
1431       trace_dump_arg_begin("stride");
1432       trace_dump_uint(transfer->stride);
1433       trace_dump_arg_end();
1434
1435       trace_dump_arg_begin("data");
1436       trace_dump_box_bytes(tr_trans->map,
1437                            transfer->resource->format,
1438                            &transfer->box,
1439                            transfer->stride,
1440                            transfer->slice_stride);
1441       trace_dump_arg_end();
1442
1443 //      trace_dump_arg_begin("size");
1444 //      trace_dump_uint(size);
1445 //      trace_dump_arg_end();
1446
1447       trace_dump_call_end();
1448
1449       tr_trans->map = NULL;
1450    }
1451
1452    context->transfer_unmap(context, transfer);
1453 }
1454
1455
1456 static void
1457 trace_context_transfer_inline_write(struct pipe_context *_context,
1458                                     struct pipe_resource *_resource,
1459                                     struct pipe_subresource sr,
1460                                     unsigned usage,
1461                                     const struct pipe_box *box,
1462                                     const void *data,
1463                                     unsigned stride,
1464                                     unsigned slice_stride)
1465 {
1466    struct trace_context *tr_context = trace_context(_context);
1467    struct trace_resource *tr_tex = trace_resource(_resource);
1468    struct pipe_context *context = tr_context->pipe;
1469    struct pipe_resource *resource = tr_tex->resource;
1470
1471    assert(resource->screen == context->screen);
1472
1473    trace_dump_call_begin("pipe_context", "transfer_inline_write");
1474
1475    trace_dump_arg(ptr, context);
1476    trace_dump_arg(ptr, resource);
1477    trace_dump_arg(uint, sr.face);
1478    trace_dump_arg(uint, sr.level);
1479    trace_dump_arg(uint, usage);
1480    trace_dump_arg(uint, box->x);
1481    trace_dump_arg(uint, box->y);
1482    trace_dump_arg(uint, box->z);
1483    trace_dump_arg(uint, box->width);
1484    trace_dump_arg(uint, box->height);
1485    trace_dump_arg(uint, box->depth);
1486    trace_dump_arg(uint, stride);
1487    trace_dump_arg(uint, slice_stride);
1488
1489    trace_dump_arg_begin("data");
1490    trace_dump_box_bytes(data,
1491                         resource->format,
1492                         box,
1493                         stride,
1494                         slice_stride);
1495    trace_dump_arg_end();
1496
1497    trace_dump_call_end();
1498
1499    context->transfer_inline_write(context, resource,
1500                                   sr, usage, box, data, stride, slice_stride);
1501 }
1502
1503
1504
1505
1506 static const struct debug_named_value rbug_blocker_flags[] = {
1507    {"before", 1},
1508    {"after", 2},
1509    {NULL, 0},
1510 };
1511
1512 struct pipe_context *
1513 trace_context_create(struct trace_screen *tr_scr,
1514                      struct pipe_context *pipe)
1515 {
1516    struct trace_context *tr_ctx;
1517
1518    if(!pipe)
1519       goto error1;
1520
1521    if(!trace_enabled())
1522       goto error1;
1523
1524    tr_ctx = CALLOC_STRUCT(trace_context);
1525    if(!tr_ctx)
1526       goto error1;
1527
1528    tr_ctx->base.winsys = NULL;
1529    tr_ctx->base.priv = pipe->priv; /* expose wrapped priv data */
1530    tr_ctx->base.screen = &tr_scr->base;
1531    tr_ctx->draw_blocker = debug_get_flags_option("RBUG_BLOCK",
1532                                                  rbug_blocker_flags,
1533                                                  0);
1534    pipe_mutex_init(tr_ctx->draw_mutex);
1535    pipe_condvar_init(tr_ctx->draw_cond);
1536    pipe_mutex_init(tr_ctx->list_mutex);
1537    make_empty_list(&tr_ctx->shaders);
1538
1539    tr_ctx->base.destroy = trace_context_destroy;
1540    tr_ctx->base.draw_arrays = trace_context_draw_arrays;
1541    tr_ctx->base.draw_elements = trace_context_draw_elements;
1542    tr_ctx->base.draw_range_elements = trace_context_draw_range_elements;
1543    tr_ctx->base.create_query = trace_context_create_query;
1544    tr_ctx->base.destroy_query = trace_context_destroy_query;
1545    tr_ctx->base.begin_query = trace_context_begin_query;
1546    tr_ctx->base.end_query = trace_context_end_query;
1547    tr_ctx->base.get_query_result = trace_context_get_query_result;
1548    tr_ctx->base.create_blend_state = trace_context_create_blend_state;
1549    tr_ctx->base.bind_blend_state = trace_context_bind_blend_state;
1550    tr_ctx->base.delete_blend_state = trace_context_delete_blend_state;
1551    tr_ctx->base.create_sampler_state = trace_context_create_sampler_state;
1552    tr_ctx->base.bind_fragment_sampler_states = trace_context_bind_fragment_sampler_states;
1553    tr_ctx->base.bind_vertex_sampler_states = trace_context_bind_vertex_sampler_states;
1554    tr_ctx->base.delete_sampler_state = trace_context_delete_sampler_state;
1555    tr_ctx->base.create_rasterizer_state = trace_context_create_rasterizer_state;
1556    tr_ctx->base.bind_rasterizer_state = trace_context_bind_rasterizer_state;
1557    tr_ctx->base.delete_rasterizer_state = trace_context_delete_rasterizer_state;
1558    tr_ctx->base.create_depth_stencil_alpha_state = trace_context_create_depth_stencil_alpha_state;
1559    tr_ctx->base.bind_depth_stencil_alpha_state = trace_context_bind_depth_stencil_alpha_state;
1560    tr_ctx->base.delete_depth_stencil_alpha_state = trace_context_delete_depth_stencil_alpha_state;
1561    tr_ctx->base.create_fs_state = trace_context_create_fs_state;
1562    tr_ctx->base.bind_fs_state = trace_context_bind_fs_state;
1563    tr_ctx->base.delete_fs_state = trace_context_delete_fs_state;
1564    tr_ctx->base.create_vs_state = trace_context_create_vs_state;
1565    tr_ctx->base.bind_vs_state = trace_context_bind_vs_state;
1566    tr_ctx->base.delete_vs_state = trace_context_delete_vs_state;
1567    tr_ctx->base.create_vertex_elements_state = trace_context_create_vertex_elements_state;
1568    tr_ctx->base.bind_vertex_elements_state = trace_context_bind_vertex_elements_state;
1569    tr_ctx->base.delete_vertex_elements_state = trace_context_delete_vertex_elements_state;
1570    tr_ctx->base.set_blend_color = trace_context_set_blend_color;
1571    tr_ctx->base.set_stencil_ref = trace_context_set_stencil_ref;
1572    tr_ctx->base.set_clip_state = trace_context_set_clip_state;
1573    tr_ctx->base.set_constant_buffer = trace_context_set_constant_buffer;
1574    tr_ctx->base.set_framebuffer_state = trace_context_set_framebuffer_state;
1575    tr_ctx->base.set_polygon_stipple = trace_context_set_polygon_stipple;
1576    tr_ctx->base.set_scissor_state = trace_context_set_scissor_state;
1577    tr_ctx->base.set_viewport_state = trace_context_set_viewport_state;
1578    tr_ctx->base.set_fragment_sampler_views = trace_context_set_fragment_sampler_views;
1579    tr_ctx->base.set_vertex_sampler_views = trace_context_set_vertex_sampler_views;
1580    tr_ctx->base.create_sampler_view = trace_create_sampler_view;
1581    tr_ctx->base.sampler_view_destroy = trace_sampler_view_destroy;
1582    tr_ctx->base.set_vertex_buffers = trace_context_set_vertex_buffers;
1583    if (pipe->surface_copy)
1584       tr_ctx->base.surface_copy = trace_context_surface_copy;
1585    if (pipe->surface_fill)
1586       tr_ctx->base.surface_fill = trace_context_surface_fill;
1587    tr_ctx->base.clear = trace_context_clear;
1588    tr_ctx->base.flush = trace_context_flush;
1589    tr_ctx->base.is_resource_referenced = trace_is_resource_referenced;
1590
1591    tr_ctx->base.get_transfer = trace_context_get_transfer;
1592    tr_ctx->base.transfer_destroy = trace_context_transfer_destroy;
1593    tr_ctx->base.transfer_map = trace_context_transfer_map;
1594    tr_ctx->base.transfer_unmap = trace_context_transfer_unmap;
1595    tr_ctx->base.transfer_flush_region = trace_context_transfer_flush_region;
1596    tr_ctx->base.transfer_inline_write = trace_context_transfer_inline_write;
1597
1598    tr_ctx->pipe = pipe;
1599
1600    trace_screen_add_to_list(tr_scr, contexts, tr_ctx);
1601
1602    return &tr_ctx->base;
1603
1604 error1:
1605    return pipe;
1606 }