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