Merge remote branch 'origin/master' into lp-binning
[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_memory.h"
29 #include "util/u_simple_list.h"
30
31 #include "pipe/p_screen.h"
32
33 #include "tr_dump.h"
34 #include "tr_dump_state.h"
35 #include "tr_state.h"
36 #include "tr_buffer.h"
37 #include "tr_screen.h"
38 #include "tr_texture.h"
39
40
41 static INLINE struct pipe_buffer *
42 trace_buffer_unwrap(struct trace_context *tr_ctx,
43 struct pipe_buffer *buffer)
44 {
45 struct trace_screen *tr_scr = trace_screen(tr_ctx->base.screen);
46 struct trace_buffer *tr_buf;
47
48 if(!buffer)
49 return NULL;
50
51 tr_buf = trace_buffer(buffer);
52
53 assert(tr_buf->buffer);
54 assert(tr_buf->buffer->screen == tr_scr->screen);
55 (void) tr_scr;
56 return tr_buf->buffer;
57 }
58
59
60 static INLINE struct pipe_texture *
61 trace_texture_unwrap(struct trace_context *tr_ctx,
62 struct pipe_texture *texture)
63 {
64 struct trace_texture *tr_tex;
65
66 if(!texture)
67 return NULL;
68
69 tr_tex = trace_texture(texture);
70
71 assert(tr_tex->texture);
72 return tr_tex->texture;
73 }
74
75
76 static INLINE struct pipe_surface *
77 trace_surface_unwrap(struct trace_context *tr_ctx,
78 struct pipe_surface *surface)
79 {
80 struct trace_screen *tr_scr = trace_screen(tr_ctx->base.screen);
81 struct trace_surface *tr_surf;
82
83 if(!surface)
84 return NULL;
85
86 assert(surface->texture);
87 if(!surface->texture)
88 return surface;
89
90 tr_surf = trace_surface(surface);
91
92 assert(tr_surf->surface);
93 assert(tr_surf->surface->texture->screen == tr_scr->screen);
94 (void) tr_scr;
95 return tr_surf->surface;
96 }
97
98
99 static INLINE void
100 trace_context_draw_block(struct trace_context *tr_ctx, int flag)
101 {
102 int k;
103
104 pipe_mutex_lock(tr_ctx->draw_mutex);
105
106 if (tr_ctx->draw_blocker & flag) {
107 tr_ctx->draw_blocked |= flag;
108 } else if ((tr_ctx->draw_rule.blocker & flag) &&
109 (tr_ctx->draw_blocker & 4)) {
110 boolean block = FALSE;
111 debug_printf("%s (%p %p) (%p %p) (%p %u) (%p %u)\n", __FUNCTION__,
112 (void *) tr_ctx->draw_rule.fs, (void *) tr_ctx->curr.fs,
113 (void *) tr_ctx->draw_rule.vs, (void *) tr_ctx->curr.vs,
114 (void *) tr_ctx->draw_rule.surf, 0,
115 (void *) tr_ctx->draw_rule.tex, 0);
116 if (tr_ctx->draw_rule.fs &&
117 tr_ctx->draw_rule.fs == tr_ctx->curr.fs)
118 block = TRUE;
119 if (tr_ctx->draw_rule.vs &&
120 tr_ctx->draw_rule.vs == tr_ctx->curr.vs)
121 block = TRUE;
122 if (tr_ctx->draw_rule.surf &&
123 tr_ctx->draw_rule.surf == tr_ctx->curr.zsbuf)
124 block = TRUE;
125 if (tr_ctx->draw_rule.surf)
126 for (k = 0; k < tr_ctx->curr.nr_cbufs; k++)
127 if (tr_ctx->draw_rule.surf == tr_ctx->curr.cbufs[k])
128 block = TRUE;
129 if (tr_ctx->draw_rule.tex) {
130 for (k = 0; k < tr_ctx->curr.num_texs; k++)
131 if (tr_ctx->draw_rule.tex == tr_ctx->curr.tex[k])
132 block = TRUE;
133 for (k = 0; k < tr_ctx->curr.num_vert_texs; k++) {
134 if (tr_ctx->draw_rule.tex == tr_ctx->curr.vert_tex[k]) {
135 block = TRUE;
136 }
137 }
138 }
139
140 if (block)
141 tr_ctx->draw_blocked |= (flag | 4);
142 }
143
144 if (tr_ctx->draw_blocked)
145 trace_rbug_notify_draw_blocked(tr_ctx);
146
147 /* wait for rbug to clear the blocked flag */
148 while (tr_ctx->draw_blocked & flag) {
149 tr_ctx->draw_blocked |= flag;
150 #ifdef PIPE_THREAD_HAVE_CONDVAR
151 pipe_condvar_wait(tr_ctx->draw_cond, tr_ctx->draw_mutex);
152 #else
153 pipe_mutex_unlock(tr_ctx->draw_mutex);
154 #ifdef PIPE_SUBSYSTEM_WINDOWS_USER
155 Sleep(1);
156 #endif
157 pipe_mutex_lock(tr_ctx->draw_mutex);
158 #endif
159 }
160
161 pipe_mutex_unlock(tr_ctx->draw_mutex);
162 }
163
164 static INLINE void
165 trace_context_draw_arrays(struct pipe_context *_pipe,
166 unsigned mode, unsigned start, unsigned count)
167 {
168 struct trace_context *tr_ctx = trace_context(_pipe);
169 struct pipe_context *pipe = tr_ctx->pipe;
170
171 if (tr_ctx->curr.fs->disabled || tr_ctx->curr.vs->disabled)
172 return;
173
174 trace_context_draw_block(tr_ctx, 1);
175
176 trace_dump_call_begin("pipe_context", "draw_arrays");
177
178 trace_dump_arg(ptr, pipe);
179 trace_dump_arg(uint, mode);
180 trace_dump_arg(uint, start);
181 trace_dump_arg(uint, count);
182
183 pipe->draw_arrays(pipe, mode, start, count);
184
185 trace_dump_call_end();
186
187 trace_context_draw_block(tr_ctx, 2);
188 }
189
190
191 static INLINE void
192 trace_context_draw_elements(struct pipe_context *_pipe,
193 struct pipe_buffer *_indexBuffer,
194 unsigned indexSize,
195 unsigned mode, unsigned start, unsigned count)
196 {
197 struct trace_context *tr_ctx = trace_context(_pipe);
198 struct trace_buffer *tr_buf = trace_buffer(_indexBuffer);
199 struct pipe_context *pipe = tr_ctx->pipe;
200 struct pipe_buffer *indexBuffer = tr_buf->buffer;
201
202 if (tr_ctx->curr.fs->disabled || tr_ctx->curr.vs->disabled)
203 return;
204
205 trace_context_draw_block(tr_ctx, 1);
206
207 trace_screen_user_buffer_update(_pipe->screen, indexBuffer);
208
209 trace_dump_call_begin("pipe_context", "draw_elements");
210
211 trace_dump_arg(ptr, pipe);
212 trace_dump_arg(ptr, indexBuffer);
213 trace_dump_arg(uint, indexSize);
214 trace_dump_arg(uint, mode);
215 trace_dump_arg(uint, start);
216 trace_dump_arg(uint, count);
217
218 pipe->draw_elements(pipe, indexBuffer, indexSize, mode, start, count);
219
220 trace_dump_call_end();
221
222 trace_context_draw_block(tr_ctx, 2);
223 }
224
225
226 static INLINE void
227 trace_context_draw_range_elements(struct pipe_context *_pipe,
228 struct pipe_buffer *_indexBuffer,
229 unsigned indexSize,
230 unsigned minIndex,
231 unsigned maxIndex,
232 unsigned mode,
233 unsigned start,
234 unsigned count)
235 {
236 struct trace_context *tr_ctx = trace_context(_pipe);
237 struct trace_buffer *tr_buf = trace_buffer(_indexBuffer);
238 struct pipe_context *pipe = tr_ctx->pipe;
239 struct pipe_buffer *indexBuffer = tr_buf->buffer;
240
241 if (tr_ctx->curr.fs->disabled || tr_ctx->curr.vs->disabled)
242 return;
243
244 trace_context_draw_block(tr_ctx, 1);
245
246 trace_screen_user_buffer_update(_pipe->screen, indexBuffer);
247
248 trace_dump_call_begin("pipe_context", "draw_range_elements");
249
250 trace_dump_arg(ptr, pipe);
251 trace_dump_arg(ptr, indexBuffer);
252 trace_dump_arg(uint, indexSize);
253 trace_dump_arg(uint, minIndex);
254 trace_dump_arg(uint, maxIndex);
255 trace_dump_arg(uint, mode);
256 trace_dump_arg(uint, start);
257 trace_dump_arg(uint, count);
258
259 pipe->draw_range_elements(pipe,
260 indexBuffer,
261 indexSize, minIndex, maxIndex,
262 mode, start, count);
263
264 trace_dump_call_end();
265
266 trace_context_draw_block(tr_ctx, 2);
267 }
268
269
270 static INLINE struct pipe_query *
271 trace_context_create_query(struct pipe_context *_pipe,
272 unsigned query_type)
273 {
274 struct trace_context *tr_ctx = trace_context(_pipe);
275 struct pipe_context *pipe = tr_ctx->pipe;
276 struct pipe_query *result;
277
278 trace_dump_call_begin("pipe_context", "create_query");
279
280 trace_dump_arg(ptr, pipe);
281 trace_dump_arg(uint, query_type);
282
283 result = pipe->create_query(pipe, query_type);
284
285 trace_dump_ret(ptr, result);
286
287 trace_dump_call_end();
288
289 return result;
290 }
291
292
293 static INLINE void
294 trace_context_destroy_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", "destroy_query");
301
302 trace_dump_arg(ptr, pipe);
303 trace_dump_arg(ptr, query);
304
305 pipe->destroy_query(pipe, query);
306
307 trace_dump_call_end();
308 }
309
310
311 static INLINE void
312 trace_context_begin_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", "begin_query");
319
320 trace_dump_arg(ptr, pipe);
321 trace_dump_arg(ptr, query);
322
323 pipe->begin_query(pipe, query);
324
325 trace_dump_call_end();
326 }
327
328
329 static INLINE void
330 trace_context_end_query(struct pipe_context *_pipe,
331 struct pipe_query *query)
332 {
333 struct trace_context *tr_ctx = trace_context(_pipe);
334 struct pipe_context *pipe = tr_ctx->pipe;
335
336 trace_dump_call_begin("pipe_context", "end_query");
337
338 trace_dump_arg(ptr, pipe);
339 trace_dump_arg(ptr, query);
340
341 pipe->end_query(pipe, query);
342
343 trace_dump_call_end();
344 }
345
346
347 static INLINE boolean
348 trace_context_get_query_result(struct pipe_context *_pipe,
349 struct pipe_query *query,
350 boolean wait,
351 uint64_t *presult)
352 {
353 struct trace_context *tr_ctx = trace_context(_pipe);
354 struct pipe_context *pipe = tr_ctx->pipe;
355 uint64_t result;
356 boolean _result;
357
358 trace_dump_call_begin("pipe_context", "get_query_result");
359
360 trace_dump_arg(ptr, pipe);
361
362 _result = pipe->get_query_result(pipe, query, wait, presult);
363 result = *presult;
364
365 trace_dump_arg(uint, result);
366 trace_dump_ret(bool, _result);
367
368 trace_dump_call_end();
369
370 return _result;
371 }
372
373
374 static INLINE void *
375 trace_context_create_blend_state(struct pipe_context *_pipe,
376 const struct pipe_blend_state *state)
377 {
378 struct trace_context *tr_ctx = trace_context(_pipe);
379 struct pipe_context *pipe = tr_ctx->pipe;
380 void * result;
381
382 trace_dump_call_begin("pipe_context", "create_blend_state");
383
384 trace_dump_arg(ptr, pipe);
385 trace_dump_arg(blend_state, state);
386
387 result = pipe->create_blend_state(pipe, state);
388
389 trace_dump_ret(ptr, result);
390
391 trace_dump_call_end();
392
393 return result;
394 }
395
396
397 static INLINE void
398 trace_context_bind_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", "bind_blend_state");
405
406 trace_dump_arg(ptr, pipe);
407 trace_dump_arg(ptr, state);
408
409 pipe->bind_blend_state(pipe, state);
410
411 trace_dump_call_end();
412 }
413
414
415 static INLINE void
416 trace_context_delete_blend_state(struct pipe_context *_pipe,
417 void *state)
418 {
419 struct trace_context *tr_ctx = trace_context(_pipe);
420 struct pipe_context *pipe = tr_ctx->pipe;
421
422 trace_dump_call_begin("pipe_context", "delete_blend_state");
423
424 trace_dump_arg(ptr, pipe);
425 trace_dump_arg(ptr, state);
426
427 pipe->delete_blend_state(pipe, state);
428
429 trace_dump_call_end();
430 }
431
432
433 static INLINE void *
434 trace_context_create_sampler_state(struct pipe_context *_pipe,
435 const struct pipe_sampler_state *state)
436 {
437 struct trace_context *tr_ctx = trace_context(_pipe);
438 struct pipe_context *pipe = tr_ctx->pipe;
439 void * result;
440
441 trace_dump_call_begin("pipe_context", "create_sampler_state");
442
443 trace_dump_arg(ptr, pipe);
444 trace_dump_arg(sampler_state, state);
445
446 result = pipe->create_sampler_state(pipe, state);
447
448 trace_dump_ret(ptr, result);
449
450 trace_dump_call_end();
451
452 return result;
453 }
454
455
456 static INLINE void
457 trace_context_bind_fragment_sampler_states(struct pipe_context *_pipe,
458 unsigned num_states,
459 void **states)
460 {
461 struct trace_context *tr_ctx = trace_context(_pipe);
462 struct pipe_context *pipe = tr_ctx->pipe;
463
464 trace_dump_call_begin("pipe_context", "bind_fragment_sampler_states");
465
466 trace_dump_arg(ptr, pipe);
467 trace_dump_arg(uint, num_states);
468 trace_dump_arg_array(ptr, states, num_states);
469
470 pipe->bind_fragment_sampler_states(pipe, num_states, states);
471
472 trace_dump_call_end();
473 }
474
475
476 static INLINE void
477 trace_context_bind_vertex_sampler_states(struct pipe_context *_pipe,
478 unsigned num_states,
479 void **states)
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", "bind_vertex_sampler_states");
485
486 trace_dump_arg(ptr, pipe);
487 trace_dump_arg(uint, num_states);
488 trace_dump_arg_array(ptr, states, num_states);
489
490 pipe->bind_vertex_sampler_states(pipe, num_states, states);
491
492 trace_dump_call_end();
493 }
494
495
496 static INLINE void
497 trace_context_delete_sampler_state(struct pipe_context *_pipe,
498 void *state)
499 {
500 struct trace_context *tr_ctx = trace_context(_pipe);
501 struct pipe_context *pipe = tr_ctx->pipe;
502
503 trace_dump_call_begin("pipe_context", "delete_sampler_state");
504
505 trace_dump_arg(ptr, pipe);
506 trace_dump_arg(ptr, state);
507
508 pipe->delete_sampler_state(pipe, state);
509
510 trace_dump_call_end();
511 }
512
513
514 static INLINE void *
515 trace_context_create_rasterizer_state(struct pipe_context *_pipe,
516 const struct pipe_rasterizer_state *state)
517 {
518 struct trace_context *tr_ctx = trace_context(_pipe);
519 struct pipe_context *pipe = tr_ctx->pipe;
520 void * result;
521
522 trace_dump_call_begin("pipe_context", "create_rasterizer_state");
523
524 trace_dump_arg(ptr, pipe);
525 trace_dump_arg(rasterizer_state, state);
526
527 result = pipe->create_rasterizer_state(pipe, state);
528
529 trace_dump_ret(ptr, result);
530
531 trace_dump_call_end();
532
533 return result;
534 }
535
536
537 static INLINE void
538 trace_context_bind_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", "bind_rasterizer_state");
545
546 trace_dump_arg(ptr, pipe);
547 trace_dump_arg(ptr, state);
548
549 pipe->bind_rasterizer_state(pipe, state);
550
551 trace_dump_call_end();
552 }
553
554
555 static INLINE void
556 trace_context_delete_rasterizer_state(struct pipe_context *_pipe,
557 void *state)
558 {
559 struct trace_context *tr_ctx = trace_context(_pipe);
560 struct pipe_context *pipe = tr_ctx->pipe;
561
562 trace_dump_call_begin("pipe_context", "delete_rasterizer_state");
563
564 trace_dump_arg(ptr, pipe);
565 trace_dump_arg(ptr, state);
566
567 pipe->delete_rasterizer_state(pipe, state);
568
569 trace_dump_call_end();
570 }
571
572
573 static INLINE void *
574 trace_context_create_depth_stencil_alpha_state(struct pipe_context *_pipe,
575 const struct pipe_depth_stencil_alpha_state *state)
576 {
577 struct trace_context *tr_ctx = trace_context(_pipe);
578 struct pipe_context *pipe = tr_ctx->pipe;
579 void * result;
580
581 trace_dump_call_begin("pipe_context", "create_depth_stencil_alpha_state");
582
583 result = pipe->create_depth_stencil_alpha_state(pipe, state);
584
585 trace_dump_arg(ptr, pipe);
586 trace_dump_arg(depth_stencil_alpha_state, state);
587
588 trace_dump_ret(ptr, result);
589
590 trace_dump_call_end();
591
592 return result;
593 }
594
595
596 static INLINE void
597 trace_context_bind_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", "bind_depth_stencil_alpha_state");
604
605 trace_dump_arg(ptr, pipe);
606 trace_dump_arg(ptr, state);
607
608 pipe->bind_depth_stencil_alpha_state(pipe, state);
609
610 trace_dump_call_end();
611 }
612
613
614 static INLINE void
615 trace_context_delete_depth_stencil_alpha_state(struct pipe_context *_pipe,
616 void *state)
617 {
618 struct trace_context *tr_ctx = trace_context(_pipe);
619 struct pipe_context *pipe = tr_ctx->pipe;
620
621 trace_dump_call_begin("pipe_context", "delete_depth_stencil_alpha_state");
622
623 trace_dump_arg(ptr, pipe);
624 trace_dump_arg(ptr, state);
625
626 pipe->delete_depth_stencil_alpha_state(pipe, state);
627
628 trace_dump_call_end();
629 }
630
631
632 static INLINE void *
633 trace_context_create_fs_state(struct pipe_context *_pipe,
634 const struct pipe_shader_state *state)
635 {
636 struct trace_context *tr_ctx = trace_context(_pipe);
637 struct pipe_context *pipe = tr_ctx->pipe;
638 void * result;
639
640 trace_dump_call_begin("pipe_context", "create_fs_state");
641
642 trace_dump_arg(ptr, pipe);
643 trace_dump_arg(shader_state, state);
644
645 result = pipe->create_fs_state(pipe, state);
646
647 trace_dump_ret(ptr, result);
648
649 trace_dump_call_end();
650
651 result = trace_shader_create(tr_ctx, state, result, TRACE_SHADER_FRAGMENT);
652
653 return result;
654 }
655
656
657 static INLINE void
658 trace_context_bind_fs_state(struct pipe_context *_pipe,
659 void *_state)
660 {
661 struct trace_context *tr_ctx = trace_context(_pipe);
662 struct trace_shader *tr_shdr = trace_shader(_state);
663 struct pipe_context *pipe = tr_ctx->pipe;
664 void *state = tr_shdr ? tr_shdr->state : NULL;
665
666 trace_dump_call_begin("pipe_context", "bind_fs_state");
667
668 trace_dump_arg(ptr, pipe);
669 trace_dump_arg(ptr, state);
670
671 tr_ctx->curr.fs = tr_shdr;
672
673 if (tr_shdr && tr_shdr->replaced)
674 state = tr_shdr->replaced;
675
676 pipe->bind_fs_state(pipe, state);
677
678 trace_dump_call_end();
679 }
680
681
682 static INLINE void
683 trace_context_delete_fs_state(struct pipe_context *_pipe,
684 void *_state)
685 {
686 struct trace_context *tr_ctx = trace_context(_pipe);
687 struct trace_shader *tr_shdr = trace_shader(_state);
688 struct pipe_context *pipe = tr_ctx->pipe;
689 void *state = tr_shdr->state;
690
691 trace_dump_call_begin("pipe_context", "delete_fs_state");
692
693 trace_dump_arg(ptr, pipe);
694 trace_dump_arg(ptr, state);
695
696 pipe->delete_fs_state(pipe, state);
697
698 trace_dump_call_end();
699
700 trace_shader_destroy(tr_ctx, tr_shdr);
701 }
702
703
704 static INLINE void *
705 trace_context_create_vs_state(struct pipe_context *_pipe,
706 const struct pipe_shader_state *state)
707 {
708 struct trace_context *tr_ctx = trace_context(_pipe);
709 struct pipe_context *pipe = tr_ctx->pipe;
710 void * result;
711
712 trace_dump_call_begin("pipe_context", "create_vs_state");
713
714 trace_dump_arg(ptr, pipe);
715 trace_dump_arg(shader_state, state);
716
717 result = pipe->create_vs_state(pipe, state);
718
719 trace_dump_ret(ptr, result);
720
721 trace_dump_call_end();
722
723 result = trace_shader_create(tr_ctx, state, result, TRACE_SHADER_VERTEX);
724
725 return result;
726 }
727
728
729 static INLINE void
730 trace_context_bind_vs_state(struct pipe_context *_pipe,
731 void *_state)
732 {
733 struct trace_context *tr_ctx = trace_context(_pipe);
734 struct trace_shader *tr_shdr = trace_shader(_state);
735 struct pipe_context *pipe = tr_ctx->pipe;
736 void *state = tr_shdr ? tr_shdr->state : NULL;
737
738 trace_dump_call_begin("pipe_context", "bind_vs_state");
739
740 trace_dump_arg(ptr, pipe);
741 trace_dump_arg(ptr, state);
742
743 tr_ctx->curr.vs = tr_shdr;
744
745 if (tr_shdr && tr_shdr->replaced)
746 state = tr_shdr->replaced;
747
748 pipe->bind_vs_state(pipe, state);
749
750 trace_dump_call_end();
751 }
752
753
754 static INLINE void
755 trace_context_delete_vs_state(struct pipe_context *_pipe,
756 void *_state)
757 {
758 struct trace_context *tr_ctx = trace_context(_pipe);
759 struct trace_shader *tr_shdr = trace_shader(_state);
760 struct pipe_context *pipe = tr_ctx->pipe;
761 void *state = tr_shdr->state;
762
763 trace_dump_call_begin("pipe_context", "delete_vs_state");
764
765 trace_dump_arg(ptr, pipe);
766 trace_dump_arg(ptr, state);
767
768 pipe->delete_vs_state(pipe, state);
769
770 trace_dump_call_end();
771
772 trace_shader_destroy(tr_ctx, tr_shdr);
773 }
774
775
776 static INLINE void
777 trace_context_set_blend_color(struct pipe_context *_pipe,
778 const struct pipe_blend_color *state)
779 {
780 struct trace_context *tr_ctx = trace_context(_pipe);
781 struct pipe_context *pipe = tr_ctx->pipe;
782
783 trace_dump_call_begin("pipe_context", "set_blend_color");
784
785 trace_dump_arg(ptr, pipe);
786 trace_dump_arg(blend_color, state);
787
788 pipe->set_blend_color(pipe, state);
789
790 trace_dump_call_end();
791 }
792
793
794 static INLINE void
795 trace_context_set_clip_state(struct pipe_context *_pipe,
796 const struct pipe_clip_state *state)
797 {
798 struct trace_context *tr_ctx = trace_context(_pipe);
799 struct pipe_context *pipe = tr_ctx->pipe;
800
801 trace_dump_call_begin("pipe_context", "set_clip_state");
802
803 trace_dump_arg(ptr, pipe);
804 trace_dump_arg(clip_state, state);
805
806 pipe->set_clip_state(pipe, state);
807
808 trace_dump_call_end();
809 }
810
811
812 static INLINE void
813 trace_context_set_constant_buffer(struct pipe_context *_pipe,
814 uint shader, uint index,
815 const struct pipe_constant_buffer *buffer)
816 {
817 struct trace_context *tr_ctx = trace_context(_pipe);
818 struct pipe_context *pipe = tr_ctx->pipe;
819
820 if (buffer)
821 trace_screen_user_buffer_update(_pipe->screen, buffer->buffer);
822
823 trace_dump_call_begin("pipe_context", "set_constant_buffer");
824
825 trace_dump_arg(ptr, pipe);
826 trace_dump_arg(uint, shader);
827 trace_dump_arg(uint, index);
828 trace_dump_arg(constant_buffer, buffer);
829
830 if (buffer) {
831 struct pipe_constant_buffer _buffer;
832 _buffer.buffer = trace_buffer_unwrap(tr_ctx, buffer->buffer);
833 pipe->set_constant_buffer(pipe, shader, index, &_buffer);
834 } else {
835 pipe->set_constant_buffer(pipe, shader, index, buffer);
836 }
837
838 trace_dump_call_end();
839 }
840
841
842 static INLINE void
843 trace_context_set_framebuffer_state(struct pipe_context *_pipe,
844 const struct pipe_framebuffer_state *state)
845 {
846 struct trace_context *tr_ctx = trace_context(_pipe);
847 struct pipe_context *pipe = tr_ctx->pipe;
848 struct pipe_framebuffer_state unwrapped_state;
849 unsigned i;
850
851 {
852 tr_ctx->curr.nr_cbufs = state->nr_cbufs;
853 for (i = 0; i < state->nr_cbufs; i++)
854 if (state->cbufs[i])
855 tr_ctx->curr.cbufs[i] = trace_texture(state->cbufs[i]->texture);
856 else
857 tr_ctx->curr.cbufs[i] = NULL;
858 if (state->zsbuf)
859 tr_ctx->curr.zsbuf = trace_texture(state->zsbuf->texture);
860 else
861 tr_ctx->curr.zsbuf = NULL;
862 }
863
864 /* Unwrap the input state */
865 memcpy(&unwrapped_state, state, sizeof(unwrapped_state));
866 for(i = 0; i < state->nr_cbufs; ++i)
867 unwrapped_state.cbufs[i] = trace_surface_unwrap(tr_ctx, state->cbufs[i]);
868 for(i = state->nr_cbufs; i < PIPE_MAX_COLOR_BUFS; ++i)
869 unwrapped_state.cbufs[i] = NULL;
870 unwrapped_state.zsbuf = trace_surface_unwrap(tr_ctx, state->zsbuf);
871 state = &unwrapped_state;
872
873 trace_dump_call_begin("pipe_context", "set_framebuffer_state");
874
875 trace_dump_arg(ptr, pipe);
876 trace_dump_arg(framebuffer_state, state);
877
878 pipe->set_framebuffer_state(pipe, state);
879
880 trace_dump_call_end();
881 }
882
883
884 static INLINE void
885 trace_context_set_polygon_stipple(struct pipe_context *_pipe,
886 const struct pipe_poly_stipple *state)
887 {
888 struct trace_context *tr_ctx = trace_context(_pipe);
889 struct pipe_context *pipe = tr_ctx->pipe;
890
891 trace_dump_call_begin("pipe_context", "set_polygon_stipple");
892
893 trace_dump_arg(ptr, pipe);
894 trace_dump_arg(poly_stipple, state);
895
896 pipe->set_polygon_stipple(pipe, state);
897
898 trace_dump_call_end();
899 }
900
901
902 static INLINE void
903 trace_context_set_scissor_state(struct pipe_context *_pipe,
904 const struct pipe_scissor_state *state)
905 {
906 struct trace_context *tr_ctx = trace_context(_pipe);
907 struct pipe_context *pipe = tr_ctx->pipe;
908
909 trace_dump_call_begin("pipe_context", "set_scissor_state");
910
911 trace_dump_arg(ptr, pipe);
912 trace_dump_arg(scissor_state, state);
913
914 pipe->set_scissor_state(pipe, state);
915
916 trace_dump_call_end();
917 }
918
919
920 static INLINE void
921 trace_context_set_viewport_state(struct pipe_context *_pipe,
922 const struct pipe_viewport_state *state)
923 {
924 struct trace_context *tr_ctx = trace_context(_pipe);
925 struct pipe_context *pipe = tr_ctx->pipe;
926
927 trace_dump_call_begin("pipe_context", "set_viewport_state");
928
929 trace_dump_arg(ptr, pipe);
930 trace_dump_arg(viewport_state, state);
931
932 pipe->set_viewport_state(pipe, state);
933
934 trace_dump_call_end();
935 }
936
937
938 static INLINE void
939 trace_context_set_fragment_sampler_textures(struct pipe_context *_pipe,
940 unsigned num_textures,
941 struct pipe_texture **textures)
942 {
943 struct trace_context *tr_ctx = trace_context(_pipe);
944 struct trace_texture *tr_tex;
945 struct pipe_context *pipe = tr_ctx->pipe;
946 struct pipe_texture *unwrapped_textures[PIPE_MAX_SAMPLERS];
947 unsigned i;
948
949 tr_ctx->curr.num_texs = num_textures;
950 for(i = 0; i < num_textures; ++i) {
951 tr_tex = trace_texture(textures[i]);
952 tr_ctx->curr.tex[i] = tr_tex;
953 unwrapped_textures[i] = tr_tex ? tr_tex->texture : NULL;
954 }
955 textures = unwrapped_textures;
956
957 trace_dump_call_begin("pipe_context", "set_fragment_sampler_textures");
958
959 trace_dump_arg(ptr, pipe);
960 trace_dump_arg(uint, num_textures);
961 trace_dump_arg_array(ptr, textures, num_textures);
962
963 pipe->set_fragment_sampler_textures(pipe, num_textures, textures);
964
965 trace_dump_call_end();
966 }
967
968
969 static INLINE void
970 trace_context_set_vertex_sampler_textures(struct pipe_context *_pipe,
971 unsigned num_textures,
972 struct pipe_texture **textures)
973 {
974 struct trace_context *tr_ctx = trace_context(_pipe);
975 struct trace_texture *tr_tex;
976 struct pipe_context *pipe = tr_ctx->pipe;
977 struct pipe_texture *unwrapped_textures[PIPE_MAX_VERTEX_SAMPLERS];
978 unsigned i;
979
980 tr_ctx->curr.num_vert_texs = num_textures;
981 for(i = 0; i < num_textures; ++i) {
982 tr_tex = trace_texture(textures[i]);
983 tr_ctx->curr.vert_tex[i] = tr_tex;
984 unwrapped_textures[i] = tr_tex ? tr_tex->texture : NULL;
985 }
986 textures = unwrapped_textures;
987
988 trace_dump_call_begin("pipe_context", "set_vertex_sampler_textures");
989
990 trace_dump_arg(ptr, pipe);
991 trace_dump_arg(uint, num_textures);
992 trace_dump_arg_array(ptr, textures, num_textures);
993
994 pipe->set_vertex_sampler_textures(pipe, num_textures, textures);
995
996 trace_dump_call_end();
997 }
998
999
1000 static INLINE void
1001 trace_context_set_vertex_buffers(struct pipe_context *_pipe,
1002 unsigned num_buffers,
1003 const struct pipe_vertex_buffer *buffers)
1004 {
1005 struct trace_context *tr_ctx = trace_context(_pipe);
1006 struct pipe_context *pipe = tr_ctx->pipe;
1007 unsigned i;
1008
1009 for(i = 0; i < num_buffers; ++i)
1010 trace_screen_user_buffer_update(_pipe->screen, buffers[i].buffer);
1011
1012 trace_dump_call_begin("pipe_context", "set_vertex_buffers");
1013
1014 trace_dump_arg(ptr, pipe);
1015 trace_dump_arg(uint, num_buffers);
1016
1017 trace_dump_arg_begin("buffers");
1018 trace_dump_struct_array(vertex_buffer, buffers, num_buffers);
1019 trace_dump_arg_end();
1020
1021 if (num_buffers) {
1022 struct pipe_vertex_buffer *_buffers = malloc(num_buffers * sizeof(*_buffers));
1023 memcpy(_buffers, buffers, num_buffers * sizeof(*_buffers));
1024 for (i = 0; i < num_buffers; i++)
1025 _buffers[i].buffer = trace_buffer_unwrap(tr_ctx, buffers[i].buffer);
1026 pipe->set_vertex_buffers(pipe, num_buffers, _buffers);
1027 free(_buffers);
1028 } else {
1029 pipe->set_vertex_buffers(pipe, num_buffers, NULL);
1030 }
1031
1032 trace_dump_call_end();
1033 }
1034
1035
1036 static INLINE void
1037 trace_context_set_vertex_elements(struct pipe_context *_pipe,
1038 unsigned num_elements,
1039 const struct pipe_vertex_element *elements)
1040 {
1041 struct trace_context *tr_ctx = trace_context(_pipe);
1042 struct pipe_context *pipe = tr_ctx->pipe;
1043
1044 trace_dump_call_begin("pipe_context", "set_vertex_elements");
1045
1046 trace_dump_arg(ptr, pipe);
1047 trace_dump_arg(uint, num_elements);
1048
1049 trace_dump_arg_begin("elements");
1050 trace_dump_struct_array(vertex_element, elements, num_elements);
1051 trace_dump_arg_end();
1052
1053 pipe->set_vertex_elements(pipe, num_elements, elements);
1054
1055 trace_dump_call_end();
1056 }
1057
1058
1059 static INLINE void
1060 trace_context_surface_copy(struct pipe_context *_pipe,
1061 struct pipe_surface *dest,
1062 unsigned destx, unsigned desty,
1063 struct pipe_surface *src,
1064 unsigned srcx, unsigned srcy,
1065 unsigned width, unsigned height)
1066 {
1067 struct trace_context *tr_ctx = trace_context(_pipe);
1068 struct pipe_context *pipe = tr_ctx->pipe;
1069
1070 dest = trace_surface_unwrap(tr_ctx, dest);
1071 src = trace_surface_unwrap(tr_ctx, src);
1072
1073 trace_dump_call_begin("pipe_context", "surface_copy");
1074
1075 trace_dump_arg(ptr, pipe);
1076 trace_dump_arg(ptr, dest);
1077 trace_dump_arg(uint, destx);
1078 trace_dump_arg(uint, desty);
1079 trace_dump_arg(ptr, src);
1080 trace_dump_arg(uint, srcx);
1081 trace_dump_arg(uint, srcy);
1082 trace_dump_arg(uint, width);
1083 trace_dump_arg(uint, height);
1084
1085 pipe->surface_copy(pipe,
1086 dest, destx, desty,
1087 src, srcx, srcy, width, height);
1088
1089 trace_dump_call_end();
1090 }
1091
1092
1093 static INLINE void
1094 trace_context_surface_fill(struct pipe_context *_pipe,
1095 struct pipe_surface *dst,
1096 unsigned dstx, unsigned dsty,
1097 unsigned width, unsigned height,
1098 unsigned value)
1099 {
1100 struct trace_context *tr_ctx = trace_context(_pipe);
1101 struct pipe_context *pipe = tr_ctx->pipe;
1102
1103 dst = trace_surface_unwrap(tr_ctx, dst);
1104
1105 trace_dump_call_begin("pipe_context", "surface_fill");
1106
1107 trace_dump_arg(ptr, pipe);
1108 trace_dump_arg(ptr, dst);
1109 trace_dump_arg(uint, dstx);
1110 trace_dump_arg(uint, dsty);
1111 trace_dump_arg(uint, width);
1112 trace_dump_arg(uint, height);
1113
1114 pipe->surface_fill(pipe, dst, dstx, dsty, width, height, value);
1115
1116 trace_dump_call_end();
1117 }
1118
1119
1120 static INLINE void
1121 trace_context_clear(struct pipe_context *_pipe,
1122 unsigned buffers,
1123 const float *rgba,
1124 double depth,
1125 unsigned stencil)
1126 {
1127 struct trace_context *tr_ctx = trace_context(_pipe);
1128 struct pipe_context *pipe = tr_ctx->pipe;
1129
1130 trace_dump_call_begin("pipe_context", "clear");
1131
1132 trace_dump_arg(ptr, pipe);
1133 trace_dump_arg(uint, buffers);
1134 trace_dump_arg_array(float, rgba, 4);
1135 trace_dump_arg(float, depth);
1136 trace_dump_arg(uint, stencil);
1137
1138 pipe->clear(pipe, buffers, rgba, depth, stencil);
1139
1140 trace_dump_call_end();
1141 }
1142
1143
1144 static INLINE void
1145 trace_context_flush(struct pipe_context *_pipe,
1146 unsigned flags,
1147 struct pipe_fence_handle **fence)
1148 {
1149 struct trace_context *tr_ctx = trace_context(_pipe);
1150 struct pipe_context *pipe = tr_ctx->pipe;
1151
1152 trace_dump_call_begin("pipe_context", "flush");
1153
1154 trace_dump_arg(ptr, pipe);
1155 trace_dump_arg(uint, flags);
1156
1157 pipe->flush(pipe, flags, fence);
1158
1159 if(fence)
1160 trace_dump_ret(ptr, *fence);
1161
1162 trace_dump_call_end();
1163 }
1164
1165
1166 static INLINE void
1167 trace_context_destroy(struct pipe_context *_pipe)
1168 {
1169 struct trace_screen *tr_scr = trace_screen(_pipe->screen);
1170 struct trace_context *tr_ctx = trace_context(_pipe);
1171 struct pipe_context *pipe = tr_ctx->pipe;
1172
1173 trace_dump_call_begin("pipe_context", "destroy");
1174 trace_dump_arg(ptr, pipe);
1175 trace_dump_call_end();
1176
1177 trace_screen_remove_from_list(tr_scr, contexts, tr_ctx);
1178
1179 pipe->destroy(pipe);
1180
1181 FREE(tr_ctx);
1182 }
1183
1184 static unsigned int
1185 trace_is_texture_referenced( struct pipe_context *_pipe,
1186 struct pipe_texture *_texture,
1187 unsigned face, unsigned level)
1188 {
1189 struct trace_context *tr_ctx = trace_context(_pipe);
1190 struct trace_texture *tr_tex = trace_texture(_texture);
1191 struct pipe_context *pipe = tr_ctx->pipe;
1192 struct pipe_texture *texture = tr_tex->texture;
1193 unsigned int referenced;
1194
1195 trace_dump_call_begin("pipe_context", "is_texture_referenced");
1196 trace_dump_arg(ptr, pipe);
1197 trace_dump_arg(ptr, texture);
1198 trace_dump_arg(uint, face);
1199 trace_dump_arg(uint, level);
1200
1201 referenced = pipe->is_texture_referenced(pipe, texture, face, level);
1202
1203 trace_dump_ret(uint, referenced);
1204 trace_dump_call_end();
1205
1206 return referenced;
1207 }
1208
1209 static unsigned int
1210 trace_is_buffer_referenced( struct pipe_context *_pipe,
1211 struct pipe_buffer *_buf)
1212 {
1213 struct trace_context *tr_ctx = trace_context(_pipe);
1214 struct trace_buffer *tr_buf = trace_buffer(_buf);
1215 struct pipe_context *pipe = tr_ctx->pipe;
1216 struct pipe_buffer *buf = tr_buf->buffer;
1217 unsigned int referenced;
1218
1219 trace_dump_call_begin("pipe_context", "is_buffer_referenced");
1220 trace_dump_arg(ptr, pipe);
1221 trace_dump_arg(ptr, buf);
1222
1223 referenced = pipe->is_buffer_referenced(pipe, buf);
1224
1225 trace_dump_ret(uint, referenced);
1226 trace_dump_call_end();
1227
1228 return referenced;
1229 }
1230
1231 static const struct debug_named_value rbug_blocker_flags[] = {
1232 {"before", 1},
1233 {"after", 2},
1234 {NULL, 0},
1235 };
1236
1237 struct pipe_context *
1238 trace_context_create(struct pipe_screen *_screen,
1239 struct pipe_context *pipe)
1240 {
1241 struct trace_screen *tr_scr;
1242 struct trace_context *tr_ctx;
1243 struct pipe_screen *screen;
1244
1245 if(!pipe)
1246 goto error1;
1247
1248 if(!trace_enabled())
1249 goto error1;
1250
1251 tr_scr = trace_screen(_screen);
1252 screen = tr_scr->screen;
1253
1254 tr_ctx = CALLOC_STRUCT(trace_context);
1255 if(!tr_ctx)
1256 goto error1;
1257
1258 tr_ctx->draw_blocker = debug_get_flags_option("RBUG_BLOCK",
1259 rbug_blocker_flags,
1260 0);
1261 pipe_mutex_init(tr_ctx->draw_mutex);
1262 pipe_condvar_init(tr_ctx->draw_cond);
1263 pipe_mutex_init(tr_ctx->list_mutex);
1264 make_empty_list(&tr_ctx->shaders);
1265
1266 tr_ctx->base.winsys = _screen->winsys;
1267 tr_ctx->base.screen = _screen;
1268 tr_ctx->base.destroy = trace_context_destroy;
1269 tr_ctx->base.draw_arrays = trace_context_draw_arrays;
1270 tr_ctx->base.draw_elements = trace_context_draw_elements;
1271 tr_ctx->base.draw_range_elements = trace_context_draw_range_elements;
1272 tr_ctx->base.create_query = trace_context_create_query;
1273 tr_ctx->base.destroy_query = trace_context_destroy_query;
1274 tr_ctx->base.begin_query = trace_context_begin_query;
1275 tr_ctx->base.end_query = trace_context_end_query;
1276 tr_ctx->base.get_query_result = trace_context_get_query_result;
1277 tr_ctx->base.create_blend_state = trace_context_create_blend_state;
1278 tr_ctx->base.bind_blend_state = trace_context_bind_blend_state;
1279 tr_ctx->base.delete_blend_state = trace_context_delete_blend_state;
1280 tr_ctx->base.create_sampler_state = trace_context_create_sampler_state;
1281 tr_ctx->base.bind_fragment_sampler_states = trace_context_bind_fragment_sampler_states;
1282 tr_ctx->base.bind_vertex_sampler_states = trace_context_bind_vertex_sampler_states;
1283 tr_ctx->base.delete_sampler_state = trace_context_delete_sampler_state;
1284 tr_ctx->base.create_rasterizer_state = trace_context_create_rasterizer_state;
1285 tr_ctx->base.bind_rasterizer_state = trace_context_bind_rasterizer_state;
1286 tr_ctx->base.delete_rasterizer_state = trace_context_delete_rasterizer_state;
1287 tr_ctx->base.create_depth_stencil_alpha_state = trace_context_create_depth_stencil_alpha_state;
1288 tr_ctx->base.bind_depth_stencil_alpha_state = trace_context_bind_depth_stencil_alpha_state;
1289 tr_ctx->base.delete_depth_stencil_alpha_state = trace_context_delete_depth_stencil_alpha_state;
1290 tr_ctx->base.create_fs_state = trace_context_create_fs_state;
1291 tr_ctx->base.bind_fs_state = trace_context_bind_fs_state;
1292 tr_ctx->base.delete_fs_state = trace_context_delete_fs_state;
1293 tr_ctx->base.create_vs_state = trace_context_create_vs_state;
1294 tr_ctx->base.bind_vs_state = trace_context_bind_vs_state;
1295 tr_ctx->base.delete_vs_state = trace_context_delete_vs_state;
1296 tr_ctx->base.set_blend_color = trace_context_set_blend_color;
1297 tr_ctx->base.set_clip_state = trace_context_set_clip_state;
1298 tr_ctx->base.set_constant_buffer = trace_context_set_constant_buffer;
1299 tr_ctx->base.set_framebuffer_state = trace_context_set_framebuffer_state;
1300 tr_ctx->base.set_polygon_stipple = trace_context_set_polygon_stipple;
1301 tr_ctx->base.set_scissor_state = trace_context_set_scissor_state;
1302 tr_ctx->base.set_viewport_state = trace_context_set_viewport_state;
1303 tr_ctx->base.set_fragment_sampler_textures = trace_context_set_fragment_sampler_textures;
1304 tr_ctx->base.set_vertex_sampler_textures = trace_context_set_vertex_sampler_textures;
1305 tr_ctx->base.set_vertex_buffers = trace_context_set_vertex_buffers;
1306 tr_ctx->base.set_vertex_elements = trace_context_set_vertex_elements;
1307 if (pipe->surface_copy)
1308 tr_ctx->base.surface_copy = trace_context_surface_copy;
1309 if (pipe->surface_fill)
1310 tr_ctx->base.surface_fill = trace_context_surface_fill;
1311 tr_ctx->base.clear = trace_context_clear;
1312 tr_ctx->base.flush = trace_context_flush;
1313 tr_ctx->base.is_texture_referenced = trace_is_texture_referenced;
1314 tr_ctx->base.is_buffer_referenced = trace_is_buffer_referenced;
1315
1316 tr_ctx->pipe = pipe;
1317
1318 trace_dump_call_begin("", "pipe_context_create");
1319 trace_dump_arg(ptr, screen);
1320 trace_dump_ret(ptr, pipe);
1321 trace_dump_call_end();
1322
1323 trace_screen_add_to_list(tr_scr, contexts, tr_ctx);
1324
1325 return &tr_ctx->base;
1326
1327 error1:
1328 return pipe;
1329 }