1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #include "util/u_inlines.h"
29 #include "util/u_memory.h"
30 #include "util/u_simple_list.h"
32 #include "pipe/p_screen.h"
35 #include "tr_dump_state.h"
37 #include "tr_buffer.h"
38 #include "tr_screen.h"
39 #include "tr_texture.h"
42 static INLINE struct pipe_buffer *
43 trace_buffer_unwrap(struct trace_context *tr_ctx,
44 struct pipe_buffer *buffer)
46 struct trace_screen *tr_scr = trace_screen(tr_ctx->base.screen);
47 struct trace_buffer *tr_buf;
52 tr_buf = trace_buffer(buffer);
54 assert(tr_buf->buffer);
55 assert(tr_buf->buffer->screen == tr_scr->screen);
57 return tr_buf->buffer;
61 static INLINE struct pipe_texture *
62 trace_texture_unwrap(struct trace_context *tr_ctx,
63 struct pipe_texture *texture)
65 struct trace_texture *tr_tex;
70 tr_tex = trace_texture(texture);
72 assert(tr_tex->texture);
73 return tr_tex->texture;
77 static INLINE struct pipe_surface *
78 trace_surface_unwrap(struct trace_context *tr_ctx,
79 struct pipe_surface *surface)
81 struct trace_screen *tr_scr = trace_screen(tr_ctx->base.screen);
82 struct trace_surface *tr_surf;
87 assert(surface->texture);
91 tr_surf = trace_surface(surface);
93 assert(tr_surf->surface);
94 assert(tr_surf->surface->texture->screen == tr_scr->screen);
96 return tr_surf->surface;
101 trace_context_draw_block(struct trace_context *tr_ctx, int flag)
105 pipe_mutex_lock(tr_ctx->draw_mutex);
107 if (tr_ctx->draw_blocker & flag) {
108 tr_ctx->draw_blocked |= flag;
109 } else if ((tr_ctx->draw_rule.blocker & flag) &&
110 (tr_ctx->draw_blocker & 4)) {
111 boolean block = FALSE;
112 debug_printf("%s (%p %p) (%p %p) (%p %u) (%p %u)\n", __FUNCTION__,
113 (void *) tr_ctx->draw_rule.fs, (void *) tr_ctx->curr.fs,
114 (void *) tr_ctx->draw_rule.vs, (void *) tr_ctx->curr.vs,
115 (void *) tr_ctx->draw_rule.surf, 0,
116 (void *) tr_ctx->draw_rule.sampler_view, 0);
117 if (tr_ctx->draw_rule.fs &&
118 tr_ctx->draw_rule.fs == tr_ctx->curr.fs)
120 if (tr_ctx->draw_rule.vs &&
121 tr_ctx->draw_rule.vs == tr_ctx->curr.vs)
123 if (tr_ctx->draw_rule.surf &&
124 tr_ctx->draw_rule.surf == tr_ctx->curr.zsbuf)
126 if (tr_ctx->draw_rule.surf)
127 for (k = 0; k < tr_ctx->curr.nr_cbufs; k++)
128 if (tr_ctx->draw_rule.surf == tr_ctx->curr.cbufs[k])
130 if (tr_ctx->draw_rule.sampler_view) {
131 for (k = 0; k < tr_ctx->curr.num_sampler_views; k++)
132 if (tr_ctx->draw_rule.sampler_view == tr_ctx->curr.sampler_views[k])
134 for (k = 0; k < tr_ctx->curr.num_vert_sampler_views; k++) {
135 if (tr_ctx->draw_rule.sampler_view == tr_ctx->curr.vert_sampler_views[k]) {
142 tr_ctx->draw_blocked |= (flag | 4);
145 if (tr_ctx->draw_blocked)
146 trace_rbug_notify_draw_blocked(tr_ctx);
148 /* wait for rbug to clear the blocked flag */
149 while (tr_ctx->draw_blocked & flag) {
150 tr_ctx->draw_blocked |= flag;
151 #ifdef PIPE_THREAD_HAVE_CONDVAR
152 pipe_condvar_wait(tr_ctx->draw_cond, tr_ctx->draw_mutex);
154 pipe_mutex_unlock(tr_ctx->draw_mutex);
155 #ifdef PIPE_SUBSYSTEM_WINDOWS_USER
158 pipe_mutex_lock(tr_ctx->draw_mutex);
162 pipe_mutex_unlock(tr_ctx->draw_mutex);
166 trace_context_draw_arrays(struct pipe_context *_pipe,
167 unsigned mode, unsigned start, unsigned count)
169 struct trace_context *tr_ctx = trace_context(_pipe);
170 struct pipe_context *pipe = tr_ctx->pipe;
172 if (tr_ctx->curr.fs->disabled || tr_ctx->curr.vs->disabled)
175 trace_context_draw_block(tr_ctx, 1);
177 trace_dump_call_begin("pipe_context", "draw_arrays");
179 trace_dump_arg(ptr, pipe);
180 trace_dump_arg(uint, mode);
181 trace_dump_arg(uint, start);
182 trace_dump_arg(uint, count);
184 pipe->draw_arrays(pipe, mode, start, count);
186 trace_dump_call_end();
188 trace_context_draw_block(tr_ctx, 2);
193 trace_context_draw_elements(struct pipe_context *_pipe,
194 struct pipe_buffer *_indexBuffer,
196 unsigned mode, unsigned start, unsigned count)
198 struct trace_context *tr_ctx = trace_context(_pipe);
199 struct trace_buffer *tr_buf = trace_buffer(_indexBuffer);
200 struct pipe_context *pipe = tr_ctx->pipe;
201 struct pipe_buffer *indexBuffer = tr_buf->buffer;
203 if (tr_ctx->curr.fs->disabled || tr_ctx->curr.vs->disabled)
206 trace_context_draw_block(tr_ctx, 1);
208 trace_screen_user_buffer_update(_pipe->screen, indexBuffer);
210 trace_dump_call_begin("pipe_context", "draw_elements");
212 trace_dump_arg(ptr, pipe);
213 trace_dump_arg(ptr, indexBuffer);
214 trace_dump_arg(uint, indexSize);
215 trace_dump_arg(uint, mode);
216 trace_dump_arg(uint, start);
217 trace_dump_arg(uint, count);
219 pipe->draw_elements(pipe, indexBuffer, indexSize, mode, start, count);
221 trace_dump_call_end();
223 trace_context_draw_block(tr_ctx, 2);
228 trace_context_draw_range_elements(struct pipe_context *_pipe,
229 struct pipe_buffer *_indexBuffer,
237 struct trace_context *tr_ctx = trace_context(_pipe);
238 struct trace_buffer *tr_buf = trace_buffer(_indexBuffer);
239 struct pipe_context *pipe = tr_ctx->pipe;
240 struct pipe_buffer *indexBuffer = tr_buf->buffer;
242 if (tr_ctx->curr.fs->disabled || tr_ctx->curr.vs->disabled)
245 trace_context_draw_block(tr_ctx, 1);
247 trace_screen_user_buffer_update(_pipe->screen, indexBuffer);
249 trace_dump_call_begin("pipe_context", "draw_range_elements");
251 trace_dump_arg(ptr, pipe);
252 trace_dump_arg(ptr, indexBuffer);
253 trace_dump_arg(uint, indexSize);
254 trace_dump_arg(uint, minIndex);
255 trace_dump_arg(uint, maxIndex);
256 trace_dump_arg(uint, mode);
257 trace_dump_arg(uint, start);
258 trace_dump_arg(uint, count);
260 pipe->draw_range_elements(pipe,
262 indexSize, minIndex, maxIndex,
265 trace_dump_call_end();
267 trace_context_draw_block(tr_ctx, 2);
271 static INLINE struct pipe_query *
272 trace_context_create_query(struct pipe_context *_pipe,
275 struct trace_context *tr_ctx = trace_context(_pipe);
276 struct pipe_context *pipe = tr_ctx->pipe;
277 struct pipe_query *result;
279 trace_dump_call_begin("pipe_context", "create_query");
281 trace_dump_arg(ptr, pipe);
282 trace_dump_arg(uint, query_type);
284 result = pipe->create_query(pipe, query_type);
286 trace_dump_ret(ptr, result);
288 trace_dump_call_end();
295 trace_context_destroy_query(struct pipe_context *_pipe,
296 struct pipe_query *query)
298 struct trace_context *tr_ctx = trace_context(_pipe);
299 struct pipe_context *pipe = tr_ctx->pipe;
301 trace_dump_call_begin("pipe_context", "destroy_query");
303 trace_dump_arg(ptr, pipe);
304 trace_dump_arg(ptr, query);
306 pipe->destroy_query(pipe, query);
308 trace_dump_call_end();
313 trace_context_begin_query(struct pipe_context *_pipe,
314 struct pipe_query *query)
316 struct trace_context *tr_ctx = trace_context(_pipe);
317 struct pipe_context *pipe = tr_ctx->pipe;
319 trace_dump_call_begin("pipe_context", "begin_query");
321 trace_dump_arg(ptr, pipe);
322 trace_dump_arg(ptr, query);
324 pipe->begin_query(pipe, query);
326 trace_dump_call_end();
331 trace_context_end_query(struct pipe_context *_pipe,
332 struct pipe_query *query)
334 struct trace_context *tr_ctx = trace_context(_pipe);
335 struct pipe_context *pipe = tr_ctx->pipe;
337 trace_dump_call_begin("pipe_context", "end_query");
339 trace_dump_arg(ptr, pipe);
340 trace_dump_arg(ptr, query);
342 pipe->end_query(pipe, query);
344 trace_dump_call_end();
348 static INLINE boolean
349 trace_context_get_query_result(struct pipe_context *_pipe,
350 struct pipe_query *query,
354 struct trace_context *tr_ctx = trace_context(_pipe);
355 struct pipe_context *pipe = tr_ctx->pipe;
359 trace_dump_call_begin("pipe_context", "get_query_result");
361 trace_dump_arg(ptr, pipe);
363 _result = pipe->get_query_result(pipe, query, wait, presult);
366 trace_dump_arg(uint, result);
367 trace_dump_ret(bool, _result);
369 trace_dump_call_end();
376 trace_context_create_blend_state(struct pipe_context *_pipe,
377 const struct pipe_blend_state *state)
379 struct trace_context *tr_ctx = trace_context(_pipe);
380 struct pipe_context *pipe = tr_ctx->pipe;
383 trace_dump_call_begin("pipe_context", "create_blend_state");
385 trace_dump_arg(ptr, pipe);
386 trace_dump_arg(blend_state, state);
388 result = pipe->create_blend_state(pipe, state);
390 trace_dump_ret(ptr, result);
392 trace_dump_call_end();
399 trace_context_bind_blend_state(struct pipe_context *_pipe,
402 struct trace_context *tr_ctx = trace_context(_pipe);
403 struct pipe_context *pipe = tr_ctx->pipe;
405 trace_dump_call_begin("pipe_context", "bind_blend_state");
407 trace_dump_arg(ptr, pipe);
408 trace_dump_arg(ptr, state);
410 pipe->bind_blend_state(pipe, state);
412 trace_dump_call_end();
417 trace_context_delete_blend_state(struct pipe_context *_pipe,
420 struct trace_context *tr_ctx = trace_context(_pipe);
421 struct pipe_context *pipe = tr_ctx->pipe;
423 trace_dump_call_begin("pipe_context", "delete_blend_state");
425 trace_dump_arg(ptr, pipe);
426 trace_dump_arg(ptr, state);
428 pipe->delete_blend_state(pipe, state);
430 trace_dump_call_end();
435 trace_context_create_sampler_state(struct pipe_context *_pipe,
436 const struct pipe_sampler_state *state)
438 struct trace_context *tr_ctx = trace_context(_pipe);
439 struct pipe_context *pipe = tr_ctx->pipe;
442 trace_dump_call_begin("pipe_context", "create_sampler_state");
444 trace_dump_arg(ptr, pipe);
445 trace_dump_arg(sampler_state, state);
447 result = pipe->create_sampler_state(pipe, state);
449 trace_dump_ret(ptr, result);
451 trace_dump_call_end();
458 trace_context_bind_fragment_sampler_states(struct pipe_context *_pipe,
462 struct trace_context *tr_ctx = trace_context(_pipe);
463 struct pipe_context *pipe = tr_ctx->pipe;
465 trace_dump_call_begin("pipe_context", "bind_fragment_sampler_states");
467 trace_dump_arg(ptr, pipe);
468 trace_dump_arg(uint, num_states);
469 trace_dump_arg_array(ptr, states, num_states);
471 pipe->bind_fragment_sampler_states(pipe, num_states, states);
473 trace_dump_call_end();
478 trace_context_bind_vertex_sampler_states(struct pipe_context *_pipe,
482 struct trace_context *tr_ctx = trace_context(_pipe);
483 struct pipe_context *pipe = tr_ctx->pipe;
485 trace_dump_call_begin("pipe_context", "bind_vertex_sampler_states");
487 trace_dump_arg(ptr, pipe);
488 trace_dump_arg(uint, num_states);
489 trace_dump_arg_array(ptr, states, num_states);
491 pipe->bind_vertex_sampler_states(pipe, num_states, states);
493 trace_dump_call_end();
498 trace_context_delete_sampler_state(struct pipe_context *_pipe,
501 struct trace_context *tr_ctx = trace_context(_pipe);
502 struct pipe_context *pipe = tr_ctx->pipe;
504 trace_dump_call_begin("pipe_context", "delete_sampler_state");
506 trace_dump_arg(ptr, pipe);
507 trace_dump_arg(ptr, state);
509 pipe->delete_sampler_state(pipe, state);
511 trace_dump_call_end();
516 trace_context_create_rasterizer_state(struct pipe_context *_pipe,
517 const struct pipe_rasterizer_state *state)
519 struct trace_context *tr_ctx = trace_context(_pipe);
520 struct pipe_context *pipe = tr_ctx->pipe;
523 trace_dump_call_begin("pipe_context", "create_rasterizer_state");
525 trace_dump_arg(ptr, pipe);
526 trace_dump_arg(rasterizer_state, state);
528 result = pipe->create_rasterizer_state(pipe, state);
530 trace_dump_ret(ptr, result);
532 trace_dump_call_end();
539 trace_context_bind_rasterizer_state(struct pipe_context *_pipe,
542 struct trace_context *tr_ctx = trace_context(_pipe);
543 struct pipe_context *pipe = tr_ctx->pipe;
545 trace_dump_call_begin("pipe_context", "bind_rasterizer_state");
547 trace_dump_arg(ptr, pipe);
548 trace_dump_arg(ptr, state);
550 pipe->bind_rasterizer_state(pipe, state);
552 trace_dump_call_end();
557 trace_context_delete_rasterizer_state(struct pipe_context *_pipe,
560 struct trace_context *tr_ctx = trace_context(_pipe);
561 struct pipe_context *pipe = tr_ctx->pipe;
563 trace_dump_call_begin("pipe_context", "delete_rasterizer_state");
565 trace_dump_arg(ptr, pipe);
566 trace_dump_arg(ptr, state);
568 pipe->delete_rasterizer_state(pipe, state);
570 trace_dump_call_end();
575 trace_context_create_depth_stencil_alpha_state(struct pipe_context *_pipe,
576 const struct pipe_depth_stencil_alpha_state *state)
578 struct trace_context *tr_ctx = trace_context(_pipe);
579 struct pipe_context *pipe = tr_ctx->pipe;
582 trace_dump_call_begin("pipe_context", "create_depth_stencil_alpha_state");
584 result = pipe->create_depth_stencil_alpha_state(pipe, state);
586 trace_dump_arg(ptr, pipe);
587 trace_dump_arg(depth_stencil_alpha_state, state);
589 trace_dump_ret(ptr, result);
591 trace_dump_call_end();
598 trace_context_bind_depth_stencil_alpha_state(struct pipe_context *_pipe,
601 struct trace_context *tr_ctx = trace_context(_pipe);
602 struct pipe_context *pipe = tr_ctx->pipe;
604 trace_dump_call_begin("pipe_context", "bind_depth_stencil_alpha_state");
606 trace_dump_arg(ptr, pipe);
607 trace_dump_arg(ptr, state);
609 pipe->bind_depth_stencil_alpha_state(pipe, state);
611 trace_dump_call_end();
616 trace_context_delete_depth_stencil_alpha_state(struct pipe_context *_pipe,
619 struct trace_context *tr_ctx = trace_context(_pipe);
620 struct pipe_context *pipe = tr_ctx->pipe;
622 trace_dump_call_begin("pipe_context", "delete_depth_stencil_alpha_state");
624 trace_dump_arg(ptr, pipe);
625 trace_dump_arg(ptr, state);
627 pipe->delete_depth_stencil_alpha_state(pipe, state);
629 trace_dump_call_end();
634 trace_context_create_fs_state(struct pipe_context *_pipe,
635 const struct pipe_shader_state *state)
637 struct trace_context *tr_ctx = trace_context(_pipe);
638 struct pipe_context *pipe = tr_ctx->pipe;
641 trace_dump_call_begin("pipe_context", "create_fs_state");
643 trace_dump_arg(ptr, pipe);
644 trace_dump_arg(shader_state, state);
646 result = pipe->create_fs_state(pipe, state);
648 trace_dump_ret(ptr, result);
650 trace_dump_call_end();
652 result = trace_shader_create(tr_ctx, state, result, TRACE_SHADER_FRAGMENT);
659 trace_context_bind_fs_state(struct pipe_context *_pipe,
662 struct trace_context *tr_ctx = trace_context(_pipe);
663 struct trace_shader *tr_shdr = trace_shader(_state);
664 struct pipe_context *pipe = tr_ctx->pipe;
665 void *state = tr_shdr ? tr_shdr->state : NULL;
667 trace_dump_call_begin("pipe_context", "bind_fs_state");
669 trace_dump_arg(ptr, pipe);
670 trace_dump_arg(ptr, state);
672 tr_ctx->curr.fs = tr_shdr;
674 if (tr_shdr && tr_shdr->replaced)
675 state = tr_shdr->replaced;
677 pipe->bind_fs_state(pipe, state);
679 trace_dump_call_end();
684 trace_context_delete_fs_state(struct pipe_context *_pipe,
687 struct trace_context *tr_ctx = trace_context(_pipe);
688 struct trace_shader *tr_shdr = trace_shader(_state);
689 struct pipe_context *pipe = tr_ctx->pipe;
690 void *state = tr_shdr->state;
692 trace_dump_call_begin("pipe_context", "delete_fs_state");
694 trace_dump_arg(ptr, pipe);
695 trace_dump_arg(ptr, state);
697 pipe->delete_fs_state(pipe, state);
699 trace_dump_call_end();
701 trace_shader_destroy(tr_ctx, tr_shdr);
706 trace_context_create_vs_state(struct pipe_context *_pipe,
707 const struct pipe_shader_state *state)
709 struct trace_context *tr_ctx = trace_context(_pipe);
710 struct pipe_context *pipe = tr_ctx->pipe;
713 trace_dump_call_begin("pipe_context", "create_vs_state");
715 trace_dump_arg(ptr, pipe);
716 trace_dump_arg(shader_state, state);
718 result = pipe->create_vs_state(pipe, state);
720 trace_dump_ret(ptr, result);
722 trace_dump_call_end();
724 result = trace_shader_create(tr_ctx, state, result, TRACE_SHADER_VERTEX);
731 trace_context_bind_vs_state(struct pipe_context *_pipe,
734 struct trace_context *tr_ctx = trace_context(_pipe);
735 struct trace_shader *tr_shdr = trace_shader(_state);
736 struct pipe_context *pipe = tr_ctx->pipe;
737 void *state = tr_shdr ? tr_shdr->state : NULL;
739 trace_dump_call_begin("pipe_context", "bind_vs_state");
741 trace_dump_arg(ptr, pipe);
742 trace_dump_arg(ptr, state);
744 tr_ctx->curr.vs = tr_shdr;
746 if (tr_shdr && tr_shdr->replaced)
747 state = tr_shdr->replaced;
749 pipe->bind_vs_state(pipe, state);
751 trace_dump_call_end();
756 trace_context_delete_vs_state(struct pipe_context *_pipe,
759 struct trace_context *tr_ctx = trace_context(_pipe);
760 struct trace_shader *tr_shdr = trace_shader(_state);
761 struct pipe_context *pipe = tr_ctx->pipe;
762 void *state = tr_shdr->state;
764 trace_dump_call_begin("pipe_context", "delete_vs_state");
766 trace_dump_arg(ptr, pipe);
767 trace_dump_arg(ptr, state);
769 pipe->delete_vs_state(pipe, state);
771 trace_dump_call_end();
773 trace_shader_destroy(tr_ctx, tr_shdr);
778 trace_context_create_vertex_elements_state(struct pipe_context *_pipe,
779 unsigned num_elements,
780 const struct pipe_vertex_element *elements)
782 struct trace_context *tr_ctx = trace_context(_pipe);
783 struct pipe_context *pipe = tr_ctx->pipe;
786 trace_dump_call_begin("pipe_context", "create_vertex_elements_state");
788 trace_dump_arg(ptr, pipe);
789 trace_dump_arg(uint, num_elements);
791 trace_dump_arg_begin("elements");
792 trace_dump_struct_array(vertex_element, elements, num_elements);
793 trace_dump_arg_end();
795 result = pipe->create_vertex_elements_state(pipe, num_elements, elements);
797 trace_dump_ret(ptr, result);
799 trace_dump_call_end();
806 trace_context_bind_vertex_elements_state(struct pipe_context *_pipe,
809 struct trace_context *tr_ctx = trace_context(_pipe);
810 struct pipe_context *pipe = tr_ctx->pipe;
812 trace_dump_call_begin("pipe_context", "bind_vertex_elements_state");
814 trace_dump_arg(ptr, pipe);
815 trace_dump_arg(ptr, state);
817 pipe->bind_vertex_elements_state(pipe, state);
819 trace_dump_call_end();
824 trace_context_delete_vertex_elements_state(struct pipe_context *_pipe,
827 struct trace_context *tr_ctx = trace_context(_pipe);
828 struct pipe_context *pipe = tr_ctx->pipe;
830 trace_dump_call_begin("pipe_context", "delete_verte_elements_state");
832 trace_dump_arg(ptr, pipe);
833 trace_dump_arg(ptr, state);
835 pipe->delete_vertex_elements_state(pipe, state);
837 trace_dump_call_end();
842 trace_context_set_blend_color(struct pipe_context *_pipe,
843 const struct pipe_blend_color *state)
845 struct trace_context *tr_ctx = trace_context(_pipe);
846 struct pipe_context *pipe = tr_ctx->pipe;
848 trace_dump_call_begin("pipe_context", "set_blend_color");
850 trace_dump_arg(ptr, pipe);
851 trace_dump_arg(blend_color, state);
853 pipe->set_blend_color(pipe, state);
855 trace_dump_call_end();
860 trace_context_set_stencil_ref(struct pipe_context *_pipe,
861 const struct pipe_stencil_ref *state)
863 struct trace_context *tr_ctx = trace_context(_pipe);
864 struct pipe_context *pipe = tr_ctx->pipe;
866 trace_dump_call_begin("pipe_context", "set_stencil_ref");
868 trace_dump_arg(ptr, pipe);
869 trace_dump_arg(stencil_ref, state);
871 pipe->set_stencil_ref(pipe, state);
873 trace_dump_call_end();
878 trace_context_set_clip_state(struct pipe_context *_pipe,
879 const struct pipe_clip_state *state)
881 struct trace_context *tr_ctx = trace_context(_pipe);
882 struct pipe_context *pipe = tr_ctx->pipe;
884 trace_dump_call_begin("pipe_context", "set_clip_state");
886 trace_dump_arg(ptr, pipe);
887 trace_dump_arg(clip_state, state);
889 pipe->set_clip_state(pipe, state);
891 trace_dump_call_end();
896 trace_context_set_constant_buffer(struct pipe_context *_pipe,
897 uint shader, uint index,
898 struct pipe_buffer *buffer)
900 struct trace_context *tr_ctx = trace_context(_pipe);
901 struct pipe_context *pipe = tr_ctx->pipe;
904 trace_screen_user_buffer_update(_pipe->screen, buffer);
905 buffer = trace_buffer_unwrap(tr_ctx, buffer);
908 trace_dump_call_begin("pipe_context", "set_constant_buffer");
910 trace_dump_arg(ptr, pipe);
911 trace_dump_arg(uint, shader);
912 trace_dump_arg(uint, index);
913 trace_dump_arg(ptr, buffer);
915 pipe->set_constant_buffer(pipe, shader, index, buffer);
917 trace_dump_call_end();
922 trace_context_set_framebuffer_state(struct pipe_context *_pipe,
923 const struct pipe_framebuffer_state *state)
925 struct trace_context *tr_ctx = trace_context(_pipe);
926 struct pipe_context *pipe = tr_ctx->pipe;
927 struct pipe_framebuffer_state unwrapped_state;
931 tr_ctx->curr.nr_cbufs = state->nr_cbufs;
932 for (i = 0; i < state->nr_cbufs; i++)
934 tr_ctx->curr.cbufs[i] = trace_texture(state->cbufs[i]->texture);
936 tr_ctx->curr.cbufs[i] = NULL;
938 tr_ctx->curr.zsbuf = trace_texture(state->zsbuf->texture);
940 tr_ctx->curr.zsbuf = NULL;
943 /* Unwrap the input state */
944 memcpy(&unwrapped_state, state, sizeof(unwrapped_state));
945 for(i = 0; i < state->nr_cbufs; ++i)
946 unwrapped_state.cbufs[i] = trace_surface_unwrap(tr_ctx, state->cbufs[i]);
947 for(i = state->nr_cbufs; i < PIPE_MAX_COLOR_BUFS; ++i)
948 unwrapped_state.cbufs[i] = NULL;
949 unwrapped_state.zsbuf = trace_surface_unwrap(tr_ctx, state->zsbuf);
950 state = &unwrapped_state;
952 trace_dump_call_begin("pipe_context", "set_framebuffer_state");
954 trace_dump_arg(ptr, pipe);
955 trace_dump_arg(framebuffer_state, state);
957 pipe->set_framebuffer_state(pipe, state);
959 trace_dump_call_end();
964 trace_context_set_polygon_stipple(struct pipe_context *_pipe,
965 const struct pipe_poly_stipple *state)
967 struct trace_context *tr_ctx = trace_context(_pipe);
968 struct pipe_context *pipe = tr_ctx->pipe;
970 trace_dump_call_begin("pipe_context", "set_polygon_stipple");
972 trace_dump_arg(ptr, pipe);
973 trace_dump_arg(poly_stipple, state);
975 pipe->set_polygon_stipple(pipe, state);
977 trace_dump_call_end();
982 trace_context_set_scissor_state(struct pipe_context *_pipe,
983 const struct pipe_scissor_state *state)
985 struct trace_context *tr_ctx = trace_context(_pipe);
986 struct pipe_context *pipe = tr_ctx->pipe;
988 trace_dump_call_begin("pipe_context", "set_scissor_state");
990 trace_dump_arg(ptr, pipe);
991 trace_dump_arg(scissor_state, state);
993 pipe->set_scissor_state(pipe, state);
995 trace_dump_call_end();
1000 trace_context_set_viewport_state(struct pipe_context *_pipe,
1001 const struct pipe_viewport_state *state)
1003 struct trace_context *tr_ctx = trace_context(_pipe);
1004 struct pipe_context *pipe = tr_ctx->pipe;
1006 trace_dump_call_begin("pipe_context", "set_viewport_state");
1008 trace_dump_arg(ptr, pipe);
1009 trace_dump_arg(viewport_state, state);
1011 pipe->set_viewport_state(pipe, state);
1013 trace_dump_call_end();
1017 static struct pipe_sampler_view *
1018 trace_create_sampler_view(struct pipe_context *_pipe,
1019 struct pipe_texture *_texture,
1020 const struct pipe_sampler_view *templ)
1022 struct trace_context *tr_ctx = trace_context(_pipe);
1023 struct trace_texture *tr_tex = trace_texture(_texture);
1024 struct pipe_context *pipe = tr_ctx->pipe;
1025 struct pipe_texture *texture = tr_tex->texture;
1026 struct trace_sampler_view *result = CALLOC_STRUCT(trace_sampler_view);
1028 trace_dump_call_begin("pipe_context", "create_sampler_view");
1030 trace_dump_arg(ptr, pipe);
1031 trace_dump_arg(ptr, texture);
1032 trace_dump_arg(ptr, templ);
1034 result->sampler_view = pipe->create_sampler_view(pipe, texture, templ);
1036 result->base = *templ;
1037 result->base.reference.count = 1;
1038 result->base.texture = NULL;
1039 pipe_texture_reference(&result->base.texture, _texture);
1040 result->base.context = _pipe;
1042 trace_dump_ret(ptr, result);
1044 trace_dump_call_end();
1046 return &result->base;
1051 trace_sampler_view_destroy(struct pipe_context *_pipe,
1052 struct pipe_sampler_view *_view)
1054 struct trace_context *tr_ctx = trace_context(_pipe);
1055 struct trace_sampler_view *tr_view = trace_sampler_view(_view);
1056 struct pipe_context *pipe = tr_ctx->pipe;
1057 struct pipe_sampler_view *view = tr_view->sampler_view;
1059 trace_dump_call_begin("pipe_context", "sampler_view_destroy");
1061 trace_dump_arg(ptr, pipe);
1062 trace_dump_arg(ptr, view);
1064 pipe->sampler_view_destroy(pipe, view);
1066 trace_dump_call_end();
1068 pipe_texture_reference(&_view->texture, NULL);
1074 trace_context_set_fragment_sampler_views(struct pipe_context *_pipe,
1076 struct pipe_sampler_view **views)
1078 struct trace_context *tr_ctx = trace_context(_pipe);
1079 struct trace_sampler_view *tr_view;
1080 struct pipe_context *pipe = tr_ctx->pipe;
1081 struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS];
1084 tr_ctx->curr.num_sampler_views = num;
1085 for(i = 0; i < num; ++i) {
1086 tr_view = trace_sampler_view(views[i]);
1087 tr_ctx->curr.sampler_views[i] = tr_view;
1088 unwrapped_views[i] = tr_view ? tr_view->sampler_view : NULL;
1090 views = unwrapped_views;
1092 trace_dump_call_begin("pipe_context", "set_fragment_sampler_views");
1094 trace_dump_arg(ptr, pipe);
1095 trace_dump_arg(uint, num);
1096 trace_dump_arg_array(ptr, views, num);
1098 pipe->set_fragment_sampler_views(pipe, num, views);
1100 trace_dump_call_end();
1105 trace_context_set_vertex_sampler_views(struct pipe_context *_pipe,
1107 struct pipe_sampler_view **views)
1109 struct trace_context *tr_ctx = trace_context(_pipe);
1110 struct trace_sampler_view *tr_view;
1111 struct pipe_context *pipe = tr_ctx->pipe;
1112 struct pipe_sampler_view *unwrapped_views[PIPE_MAX_VERTEX_SAMPLERS];
1115 tr_ctx->curr.num_vert_sampler_views = num;
1116 for(i = 0; i < num; ++i) {
1117 tr_view = trace_sampler_view(views[i]);
1118 tr_ctx->curr.vert_sampler_views[i] = tr_view;
1119 unwrapped_views[i] = tr_view ? tr_view->sampler_view : NULL;
1121 views = unwrapped_views;
1123 trace_dump_call_begin("pipe_context", "set_vertex_sampler_views");
1125 trace_dump_arg(ptr, pipe);
1126 trace_dump_arg(uint, num);
1127 trace_dump_arg_array(ptr, views, num);
1129 pipe->set_vertex_sampler_views(pipe, num, views);
1131 trace_dump_call_end();
1136 trace_context_set_vertex_buffers(struct pipe_context *_pipe,
1137 unsigned num_buffers,
1138 const struct pipe_vertex_buffer *buffers)
1140 struct trace_context *tr_ctx = trace_context(_pipe);
1141 struct pipe_context *pipe = tr_ctx->pipe;
1144 for(i = 0; i < num_buffers; ++i)
1145 trace_screen_user_buffer_update(_pipe->screen, buffers[i].buffer);
1147 trace_dump_call_begin("pipe_context", "set_vertex_buffers");
1149 trace_dump_arg(ptr, pipe);
1150 trace_dump_arg(uint, num_buffers);
1152 trace_dump_arg_begin("buffers");
1153 trace_dump_struct_array(vertex_buffer, buffers, num_buffers);
1154 trace_dump_arg_end();
1157 struct pipe_vertex_buffer *_buffers = malloc(num_buffers * sizeof(*_buffers));
1158 memcpy(_buffers, buffers, num_buffers * sizeof(*_buffers));
1159 for (i = 0; i < num_buffers; i++)
1160 _buffers[i].buffer = trace_buffer_unwrap(tr_ctx, buffers[i].buffer);
1161 pipe->set_vertex_buffers(pipe, num_buffers, _buffers);
1164 pipe->set_vertex_buffers(pipe, num_buffers, NULL);
1167 trace_dump_call_end();
1172 trace_context_surface_copy(struct pipe_context *_pipe,
1173 struct pipe_surface *dest,
1174 unsigned destx, unsigned desty,
1175 struct pipe_surface *src,
1176 unsigned srcx, unsigned srcy,
1177 unsigned width, unsigned height)
1179 struct trace_context *tr_ctx = trace_context(_pipe);
1180 struct pipe_context *pipe = tr_ctx->pipe;
1182 dest = trace_surface_unwrap(tr_ctx, dest);
1183 src = trace_surface_unwrap(tr_ctx, src);
1185 trace_dump_call_begin("pipe_context", "surface_copy");
1187 trace_dump_arg(ptr, pipe);
1188 trace_dump_arg(ptr, dest);
1189 trace_dump_arg(uint, destx);
1190 trace_dump_arg(uint, desty);
1191 trace_dump_arg(ptr, src);
1192 trace_dump_arg(uint, srcx);
1193 trace_dump_arg(uint, srcy);
1194 trace_dump_arg(uint, width);
1195 trace_dump_arg(uint, height);
1197 pipe->surface_copy(pipe,
1199 src, srcx, srcy, width, height);
1201 trace_dump_call_end();
1206 trace_context_surface_fill(struct pipe_context *_pipe,
1207 struct pipe_surface *dst,
1208 unsigned dstx, unsigned dsty,
1209 unsigned width, unsigned height,
1212 struct trace_context *tr_ctx = trace_context(_pipe);
1213 struct pipe_context *pipe = tr_ctx->pipe;
1215 dst = trace_surface_unwrap(tr_ctx, dst);
1217 trace_dump_call_begin("pipe_context", "surface_fill");
1219 trace_dump_arg(ptr, pipe);
1220 trace_dump_arg(ptr, dst);
1221 trace_dump_arg(uint, dstx);
1222 trace_dump_arg(uint, dsty);
1223 trace_dump_arg(uint, width);
1224 trace_dump_arg(uint, height);
1226 pipe->surface_fill(pipe, dst, dstx, dsty, width, height, value);
1228 trace_dump_call_end();
1233 trace_context_clear(struct pipe_context *_pipe,
1239 struct trace_context *tr_ctx = trace_context(_pipe);
1240 struct pipe_context *pipe = tr_ctx->pipe;
1242 trace_dump_call_begin("pipe_context", "clear");
1244 trace_dump_arg(ptr, pipe);
1245 trace_dump_arg(uint, buffers);
1246 trace_dump_arg_array(float, rgba, 4);
1247 trace_dump_arg(float, depth);
1248 trace_dump_arg(uint, stencil);
1250 pipe->clear(pipe, buffers, rgba, depth, stencil);
1252 trace_dump_call_end();
1257 trace_context_flush(struct pipe_context *_pipe,
1259 struct pipe_fence_handle **fence)
1261 struct trace_context *tr_ctx = trace_context(_pipe);
1262 struct pipe_context *pipe = tr_ctx->pipe;
1264 trace_dump_call_begin("pipe_context", "flush");
1266 trace_dump_arg(ptr, pipe);
1267 trace_dump_arg(uint, flags);
1269 pipe->flush(pipe, flags, fence);
1272 trace_dump_ret(ptr, *fence);
1274 trace_dump_call_end();
1279 trace_context_destroy(struct pipe_context *_pipe)
1281 struct trace_screen *tr_scr = trace_screen(_pipe->screen);
1282 struct trace_context *tr_ctx = trace_context(_pipe);
1283 struct pipe_context *pipe = tr_ctx->pipe;
1285 trace_dump_call_begin("pipe_context", "destroy");
1286 trace_dump_arg(ptr, pipe);
1287 trace_dump_call_end();
1289 trace_screen_remove_from_list(tr_scr, contexts, tr_ctx);
1291 pipe->destroy(pipe);
1297 trace_is_texture_referenced( struct pipe_context *_pipe,
1298 struct pipe_texture *_texture,
1299 unsigned face, unsigned level)
1301 struct trace_context *tr_ctx = trace_context(_pipe);
1302 struct trace_texture *tr_tex = trace_texture(_texture);
1303 struct pipe_context *pipe = tr_ctx->pipe;
1304 struct pipe_texture *texture = tr_tex->texture;
1305 unsigned int referenced;
1307 trace_dump_call_begin("pipe_context", "is_texture_referenced");
1308 trace_dump_arg(ptr, pipe);
1309 trace_dump_arg(ptr, texture);
1310 trace_dump_arg(uint, face);
1311 trace_dump_arg(uint, level);
1313 referenced = pipe->is_texture_referenced(pipe, texture, face, level);
1315 trace_dump_ret(uint, referenced);
1316 trace_dump_call_end();
1322 trace_is_buffer_referenced( struct pipe_context *_pipe,
1323 struct pipe_buffer *_buf)
1325 struct trace_context *tr_ctx = trace_context(_pipe);
1326 struct trace_buffer *tr_buf = trace_buffer(_buf);
1327 struct pipe_context *pipe = tr_ctx->pipe;
1328 struct pipe_buffer *buf = tr_buf->buffer;
1329 unsigned int referenced;
1331 trace_dump_call_begin("pipe_context", "is_buffer_referenced");
1332 trace_dump_arg(ptr, pipe);
1333 trace_dump_arg(ptr, buf);
1335 referenced = pipe->is_buffer_referenced(pipe, buf);
1337 trace_dump_ret(uint, referenced);
1338 trace_dump_call_end();
1343 static const struct debug_named_value rbug_blocker_flags[] = {
1349 struct pipe_context *
1350 trace_context_create(struct trace_screen *tr_scr,
1351 struct pipe_context *pipe)
1353 struct trace_context *tr_ctx;
1358 if(!trace_enabled())
1361 tr_ctx = CALLOC_STRUCT(trace_context);
1365 tr_ctx->base.winsys = NULL;
1366 tr_ctx->base.priv = pipe->priv; /* expose wrapped priv data */
1367 tr_ctx->base.screen = &tr_scr->base;
1368 tr_ctx->draw_blocker = debug_get_flags_option("RBUG_BLOCK",
1371 pipe_mutex_init(tr_ctx->draw_mutex);
1372 pipe_condvar_init(tr_ctx->draw_cond);
1373 pipe_mutex_init(tr_ctx->list_mutex);
1374 make_empty_list(&tr_ctx->shaders);
1376 tr_ctx->base.destroy = trace_context_destroy;
1377 tr_ctx->base.draw_arrays = trace_context_draw_arrays;
1378 tr_ctx->base.draw_elements = trace_context_draw_elements;
1379 tr_ctx->base.draw_range_elements = trace_context_draw_range_elements;
1380 tr_ctx->base.create_query = trace_context_create_query;
1381 tr_ctx->base.destroy_query = trace_context_destroy_query;
1382 tr_ctx->base.begin_query = trace_context_begin_query;
1383 tr_ctx->base.end_query = trace_context_end_query;
1384 tr_ctx->base.get_query_result = trace_context_get_query_result;
1385 tr_ctx->base.create_blend_state = trace_context_create_blend_state;
1386 tr_ctx->base.bind_blend_state = trace_context_bind_blend_state;
1387 tr_ctx->base.delete_blend_state = trace_context_delete_blend_state;
1388 tr_ctx->base.create_sampler_state = trace_context_create_sampler_state;
1389 tr_ctx->base.bind_fragment_sampler_states = trace_context_bind_fragment_sampler_states;
1390 tr_ctx->base.bind_vertex_sampler_states = trace_context_bind_vertex_sampler_states;
1391 tr_ctx->base.delete_sampler_state = trace_context_delete_sampler_state;
1392 tr_ctx->base.create_rasterizer_state = trace_context_create_rasterizer_state;
1393 tr_ctx->base.bind_rasterizer_state = trace_context_bind_rasterizer_state;
1394 tr_ctx->base.delete_rasterizer_state = trace_context_delete_rasterizer_state;
1395 tr_ctx->base.create_depth_stencil_alpha_state = trace_context_create_depth_stencil_alpha_state;
1396 tr_ctx->base.bind_depth_stencil_alpha_state = trace_context_bind_depth_stencil_alpha_state;
1397 tr_ctx->base.delete_depth_stencil_alpha_state = trace_context_delete_depth_stencil_alpha_state;
1398 tr_ctx->base.create_fs_state = trace_context_create_fs_state;
1399 tr_ctx->base.bind_fs_state = trace_context_bind_fs_state;
1400 tr_ctx->base.delete_fs_state = trace_context_delete_fs_state;
1401 tr_ctx->base.create_vs_state = trace_context_create_vs_state;
1402 tr_ctx->base.bind_vs_state = trace_context_bind_vs_state;
1403 tr_ctx->base.delete_vs_state = trace_context_delete_vs_state;
1404 tr_ctx->base.create_vertex_elements_state = trace_context_create_vertex_elements_state;
1405 tr_ctx->base.bind_vertex_elements_state = trace_context_bind_vertex_elements_state;
1406 tr_ctx->base.delete_vertex_elements_state = trace_context_delete_vertex_elements_state;
1407 tr_ctx->base.set_blend_color = trace_context_set_blend_color;
1408 tr_ctx->base.set_stencil_ref = trace_context_set_stencil_ref;
1409 tr_ctx->base.set_clip_state = trace_context_set_clip_state;
1410 tr_ctx->base.set_constant_buffer = trace_context_set_constant_buffer;
1411 tr_ctx->base.set_framebuffer_state = trace_context_set_framebuffer_state;
1412 tr_ctx->base.set_polygon_stipple = trace_context_set_polygon_stipple;
1413 tr_ctx->base.set_scissor_state = trace_context_set_scissor_state;
1414 tr_ctx->base.set_viewport_state = trace_context_set_viewport_state;
1415 tr_ctx->base.set_fragment_sampler_views = trace_context_set_fragment_sampler_views;
1416 tr_ctx->base.set_vertex_sampler_views = trace_context_set_vertex_sampler_views;
1417 tr_ctx->base.create_sampler_view = trace_create_sampler_view;
1418 tr_ctx->base.sampler_view_destroy = trace_sampler_view_destroy;
1419 tr_ctx->base.set_vertex_buffers = trace_context_set_vertex_buffers;
1420 if (pipe->surface_copy)
1421 tr_ctx->base.surface_copy = trace_context_surface_copy;
1422 if (pipe->surface_fill)
1423 tr_ctx->base.surface_fill = trace_context_surface_fill;
1424 tr_ctx->base.clear = trace_context_clear;
1425 tr_ctx->base.flush = trace_context_flush;
1426 tr_ctx->base.is_texture_referenced = trace_is_texture_referenced;
1427 tr_ctx->base.is_buffer_referenced = trace_is_buffer_referenced;
1429 tr_ctx->pipe = pipe;
1431 trace_screen_add_to_list(tr_scr, contexts, tr_ctx);
1433 return &tr_ctx->base;