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_format.h"
33 #include "pipe/p_screen.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"
46 static INLINE struct pipe_resource *
47 trace_resource_unwrap(struct trace_context *tr_ctx,
48 struct pipe_resource *resource)
50 struct trace_resource *tr_res;
55 tr_res = trace_resource(resource);
57 assert(tr_res->resource);
58 return tr_res->resource;
62 static INLINE struct pipe_surface *
63 trace_surface_unwrap(struct trace_context *tr_ctx,
64 struct pipe_surface *surface)
66 struct trace_screen *tr_scr = trace_screen(tr_ctx->base.screen);
67 struct trace_surface *tr_surf;
72 assert(surface->texture);
76 tr_surf = trace_surface(surface);
78 assert(tr_surf->surface);
79 assert(tr_surf->surface->texture->screen == tr_scr->screen);
81 return tr_surf->surface;
86 trace_context_draw_vbo(struct pipe_context *_pipe,
87 const struct pipe_draw_info *info)
89 struct trace_context *tr_ctx = trace_context(_pipe);
90 struct pipe_context *pipe = tr_ctx->pipe;
92 trace_dump_call_begin("pipe_context", "draw_vbo");
94 trace_dump_arg(ptr, pipe);
95 trace_dump_arg(draw_info, info);
97 pipe->draw_vbo(pipe, info);
99 trace_dump_call_end();
103 static INLINE struct pipe_query *
104 trace_context_create_query(struct pipe_context *_pipe,
107 struct trace_context *tr_ctx = trace_context(_pipe);
108 struct pipe_context *pipe = tr_ctx->pipe;
109 struct pipe_query *result;
111 trace_dump_call_begin("pipe_context", "create_query");
113 trace_dump_arg(ptr, pipe);
114 trace_dump_arg(uint, query_type);
116 result = pipe->create_query(pipe, query_type);
118 trace_dump_ret(ptr, result);
120 trace_dump_call_end();
127 trace_context_destroy_query(struct pipe_context *_pipe,
128 struct pipe_query *query)
130 struct trace_context *tr_ctx = trace_context(_pipe);
131 struct pipe_context *pipe = tr_ctx->pipe;
133 trace_dump_call_begin("pipe_context", "destroy_query");
135 trace_dump_arg(ptr, pipe);
136 trace_dump_arg(ptr, query);
138 pipe->destroy_query(pipe, query);
140 trace_dump_call_end();
145 trace_context_begin_query(struct pipe_context *_pipe,
146 struct pipe_query *query)
148 struct trace_context *tr_ctx = trace_context(_pipe);
149 struct pipe_context *pipe = tr_ctx->pipe;
151 trace_dump_call_begin("pipe_context", "begin_query");
153 trace_dump_arg(ptr, pipe);
154 trace_dump_arg(ptr, query);
156 pipe->begin_query(pipe, query);
158 trace_dump_call_end();
163 trace_context_end_query(struct pipe_context *_pipe,
164 struct pipe_query *query)
166 struct trace_context *tr_ctx = trace_context(_pipe);
167 struct pipe_context *pipe = tr_ctx->pipe;
169 trace_dump_call_begin("pipe_context", "end_query");
171 trace_dump_arg(ptr, pipe);
172 trace_dump_arg(ptr, query);
174 pipe->end_query(pipe, query);
176 trace_dump_call_end();
180 static INLINE boolean
181 trace_context_get_query_result(struct pipe_context *_pipe,
182 struct pipe_query *query,
184 union pipe_query_result *presult)
186 struct trace_context *tr_ctx = trace_context(_pipe);
187 struct pipe_context *pipe = tr_ctx->pipe;
191 trace_dump_call_begin("pipe_context", "get_query_result");
193 trace_dump_arg(ptr, pipe);
195 _result = pipe->get_query_result(pipe, query, wait, presult);
196 /* XXX this depends on the query type */
197 result = *((uint64_t*)presult);
199 trace_dump_arg(uint, result);
200 trace_dump_ret(bool, _result);
202 trace_dump_call_end();
209 trace_context_create_blend_state(struct pipe_context *_pipe,
210 const struct pipe_blend_state *state)
212 struct trace_context *tr_ctx = trace_context(_pipe);
213 struct pipe_context *pipe = tr_ctx->pipe;
216 trace_dump_call_begin("pipe_context", "create_blend_state");
218 trace_dump_arg(ptr, pipe);
219 trace_dump_arg(blend_state, state);
221 result = pipe->create_blend_state(pipe, state);
223 trace_dump_ret(ptr, result);
225 trace_dump_call_end();
232 trace_context_bind_blend_state(struct pipe_context *_pipe,
235 struct trace_context *tr_ctx = trace_context(_pipe);
236 struct pipe_context *pipe = tr_ctx->pipe;
238 trace_dump_call_begin("pipe_context", "bind_blend_state");
240 trace_dump_arg(ptr, pipe);
241 trace_dump_arg(ptr, state);
243 pipe->bind_blend_state(pipe, state);
245 trace_dump_call_end();
250 trace_context_delete_blend_state(struct pipe_context *_pipe,
253 struct trace_context *tr_ctx = trace_context(_pipe);
254 struct pipe_context *pipe = tr_ctx->pipe;
256 trace_dump_call_begin("pipe_context", "delete_blend_state");
258 trace_dump_arg(ptr, pipe);
259 trace_dump_arg(ptr, state);
261 pipe->delete_blend_state(pipe, state);
263 trace_dump_call_end();
268 trace_context_create_sampler_state(struct pipe_context *_pipe,
269 const struct pipe_sampler_state *state)
271 struct trace_context *tr_ctx = trace_context(_pipe);
272 struct pipe_context *pipe = tr_ctx->pipe;
275 trace_dump_call_begin("pipe_context", "create_sampler_state");
277 trace_dump_arg(ptr, pipe);
278 trace_dump_arg(sampler_state, state);
280 result = pipe->create_sampler_state(pipe, state);
282 trace_dump_ret(ptr, result);
284 trace_dump_call_end();
291 trace_context_bind_sampler_states(struct pipe_context *_pipe,
297 struct trace_context *tr_ctx = trace_context(_pipe);
298 struct pipe_context *pipe = tr_ctx->pipe;
300 /* remove this when we have pipe->bind_sampler_states(..., start, ...) */
304 case PIPE_SHADER_VERTEX:
305 trace_dump_call_begin("pipe_context", "bind_vertex_sampler_states");
307 case PIPE_SHADER_GEOMETRY:
308 trace_dump_call_begin("pipe_context", "bind_geometry_sampler_states");
310 case PIPE_SHADER_FRAGMENT:
311 trace_dump_call_begin("pipe_context", "bind_fragment_sampler_states");
314 debug_error("Unexpected shader in trace_context_bind_sampler_states()");
317 trace_dump_arg(ptr, pipe);
318 trace_dump_arg(uint, num_states);
319 trace_dump_arg_array(ptr, states, num_states);
322 case PIPE_SHADER_VERTEX:
323 pipe->bind_vertex_sampler_states(pipe, num_states, states);
325 case PIPE_SHADER_GEOMETRY:
326 pipe->bind_geometry_sampler_states(pipe, num_states, states);
328 case PIPE_SHADER_FRAGMENT:
329 pipe->bind_fragment_sampler_states(pipe, num_states, states);
332 debug_error("Unexpected shader in trace_context_bind_sampler_states()");
335 trace_dump_call_end();
340 trace_context_bind_fragment_sampler_states(struct pipe_context *_pipe,
344 trace_context_bind_sampler_states(_pipe, PIPE_SHADER_FRAGMENT,
350 trace_context_bind_vertex_sampler_states(struct pipe_context *_pipe,
354 trace_context_bind_sampler_states(_pipe, PIPE_SHADER_VERTEX,
360 trace_context_delete_sampler_state(struct pipe_context *_pipe,
363 struct trace_context *tr_ctx = trace_context(_pipe);
364 struct pipe_context *pipe = tr_ctx->pipe;
366 trace_dump_call_begin("pipe_context", "delete_sampler_state");
368 trace_dump_arg(ptr, pipe);
369 trace_dump_arg(ptr, state);
371 pipe->delete_sampler_state(pipe, state);
373 trace_dump_call_end();
378 trace_context_create_rasterizer_state(struct pipe_context *_pipe,
379 const struct pipe_rasterizer_state *state)
381 struct trace_context *tr_ctx = trace_context(_pipe);
382 struct pipe_context *pipe = tr_ctx->pipe;
385 trace_dump_call_begin("pipe_context", "create_rasterizer_state");
387 trace_dump_arg(ptr, pipe);
388 trace_dump_arg(rasterizer_state, state);
390 result = pipe->create_rasterizer_state(pipe, state);
392 trace_dump_ret(ptr, result);
394 trace_dump_call_end();
401 trace_context_bind_rasterizer_state(struct pipe_context *_pipe,
404 struct trace_context *tr_ctx = trace_context(_pipe);
405 struct pipe_context *pipe = tr_ctx->pipe;
407 trace_dump_call_begin("pipe_context", "bind_rasterizer_state");
409 trace_dump_arg(ptr, pipe);
410 trace_dump_arg(ptr, state);
412 pipe->bind_rasterizer_state(pipe, state);
414 trace_dump_call_end();
419 trace_context_delete_rasterizer_state(struct pipe_context *_pipe,
422 struct trace_context *tr_ctx = trace_context(_pipe);
423 struct pipe_context *pipe = tr_ctx->pipe;
425 trace_dump_call_begin("pipe_context", "delete_rasterizer_state");
427 trace_dump_arg(ptr, pipe);
428 trace_dump_arg(ptr, state);
430 pipe->delete_rasterizer_state(pipe, state);
432 trace_dump_call_end();
437 trace_context_create_depth_stencil_alpha_state(struct pipe_context *_pipe,
438 const struct pipe_depth_stencil_alpha_state *state)
440 struct trace_context *tr_ctx = trace_context(_pipe);
441 struct pipe_context *pipe = tr_ctx->pipe;
444 trace_dump_call_begin("pipe_context", "create_depth_stencil_alpha_state");
446 result = pipe->create_depth_stencil_alpha_state(pipe, state);
448 trace_dump_arg(ptr, pipe);
449 trace_dump_arg(depth_stencil_alpha_state, state);
451 trace_dump_ret(ptr, result);
453 trace_dump_call_end();
460 trace_context_bind_depth_stencil_alpha_state(struct pipe_context *_pipe,
463 struct trace_context *tr_ctx = trace_context(_pipe);
464 struct pipe_context *pipe = tr_ctx->pipe;
466 trace_dump_call_begin("pipe_context", "bind_depth_stencil_alpha_state");
468 trace_dump_arg(ptr, pipe);
469 trace_dump_arg(ptr, state);
471 pipe->bind_depth_stencil_alpha_state(pipe, state);
473 trace_dump_call_end();
478 trace_context_delete_depth_stencil_alpha_state(struct pipe_context *_pipe,
481 struct trace_context *tr_ctx = trace_context(_pipe);
482 struct pipe_context *pipe = tr_ctx->pipe;
484 trace_dump_call_begin("pipe_context", "delete_depth_stencil_alpha_state");
486 trace_dump_arg(ptr, pipe);
487 trace_dump_arg(ptr, state);
489 pipe->delete_depth_stencil_alpha_state(pipe, state);
491 trace_dump_call_end();
496 trace_context_create_fs_state(struct pipe_context *_pipe,
497 const struct pipe_shader_state *state)
499 struct trace_context *tr_ctx = trace_context(_pipe);
500 struct pipe_context *pipe = tr_ctx->pipe;
503 trace_dump_call_begin("pipe_context", "create_fs_state");
505 trace_dump_arg(ptr, pipe);
506 trace_dump_arg(shader_state, state);
508 result = pipe->create_fs_state(pipe, state);
510 trace_dump_ret(ptr, result);
512 trace_dump_call_end();
519 trace_context_bind_fs_state(struct pipe_context *_pipe,
522 struct trace_context *tr_ctx = trace_context(_pipe);
523 struct pipe_context *pipe = tr_ctx->pipe;
525 trace_dump_call_begin("pipe_context", "bind_fs_state");
527 trace_dump_arg(ptr, pipe);
528 trace_dump_arg(ptr, state);
530 pipe->bind_fs_state(pipe, state);
532 trace_dump_call_end();
537 trace_context_delete_fs_state(struct pipe_context *_pipe,
540 struct trace_context *tr_ctx = trace_context(_pipe);
541 struct pipe_context *pipe = tr_ctx->pipe;
543 trace_dump_call_begin("pipe_context", "delete_fs_state");
545 trace_dump_arg(ptr, pipe);
546 trace_dump_arg(ptr, state);
548 pipe->delete_fs_state(pipe, state);
550 trace_dump_call_end();
555 trace_context_create_vs_state(struct pipe_context *_pipe,
556 const struct pipe_shader_state *state)
558 struct trace_context *tr_ctx = trace_context(_pipe);
559 struct pipe_context *pipe = tr_ctx->pipe;
562 trace_dump_call_begin("pipe_context", "create_vs_state");
564 trace_dump_arg(ptr, pipe);
565 trace_dump_arg(shader_state, state);
567 result = pipe->create_vs_state(pipe, state);
569 trace_dump_ret(ptr, result);
571 trace_dump_call_end();
578 trace_context_bind_vs_state(struct pipe_context *_pipe,
581 struct trace_context *tr_ctx = trace_context(_pipe);
582 struct pipe_context *pipe = tr_ctx->pipe;
584 trace_dump_call_begin("pipe_context", "bind_vs_state");
586 trace_dump_arg(ptr, pipe);
587 trace_dump_arg(ptr, state);
589 pipe->bind_vs_state(pipe, state);
591 trace_dump_call_end();
596 trace_context_delete_vs_state(struct pipe_context *_pipe,
599 struct trace_context *tr_ctx = trace_context(_pipe);
600 struct pipe_context *pipe = tr_ctx->pipe;
602 trace_dump_call_begin("pipe_context", "delete_vs_state");
604 trace_dump_arg(ptr, pipe);
605 trace_dump_arg(ptr, state);
607 pipe->delete_vs_state(pipe, state);
609 trace_dump_call_end();
614 trace_context_create_vertex_elements_state(struct pipe_context *_pipe,
615 unsigned num_elements,
616 const struct pipe_vertex_element *elements)
618 struct trace_context *tr_ctx = trace_context(_pipe);
619 struct pipe_context *pipe = tr_ctx->pipe;
622 trace_dump_call_begin("pipe_context", "create_vertex_elements_state");
624 trace_dump_arg(ptr, pipe);
625 trace_dump_arg(uint, num_elements);
627 trace_dump_arg_begin("elements");
628 trace_dump_struct_array(vertex_element, elements, num_elements);
629 trace_dump_arg_end();
631 result = pipe->create_vertex_elements_state(pipe, num_elements, elements);
633 trace_dump_ret(ptr, result);
635 trace_dump_call_end();
642 trace_context_bind_vertex_elements_state(struct pipe_context *_pipe,
645 struct trace_context *tr_ctx = trace_context(_pipe);
646 struct pipe_context *pipe = tr_ctx->pipe;
648 trace_dump_call_begin("pipe_context", "bind_vertex_elements_state");
650 trace_dump_arg(ptr, pipe);
651 trace_dump_arg(ptr, state);
653 pipe->bind_vertex_elements_state(pipe, state);
655 trace_dump_call_end();
660 trace_context_delete_vertex_elements_state(struct pipe_context *_pipe,
663 struct trace_context *tr_ctx = trace_context(_pipe);
664 struct pipe_context *pipe = tr_ctx->pipe;
666 trace_dump_call_begin("pipe_context", "delete_vertex_elements_state");
668 trace_dump_arg(ptr, pipe);
669 trace_dump_arg(ptr, state);
671 pipe->delete_vertex_elements_state(pipe, state);
673 trace_dump_call_end();
678 trace_context_set_blend_color(struct pipe_context *_pipe,
679 const struct pipe_blend_color *state)
681 struct trace_context *tr_ctx = trace_context(_pipe);
682 struct pipe_context *pipe = tr_ctx->pipe;
684 trace_dump_call_begin("pipe_context", "set_blend_color");
686 trace_dump_arg(ptr, pipe);
687 trace_dump_arg(blend_color, state);
689 pipe->set_blend_color(pipe, state);
691 trace_dump_call_end();
696 trace_context_set_stencil_ref(struct pipe_context *_pipe,
697 const struct pipe_stencil_ref *state)
699 struct trace_context *tr_ctx = trace_context(_pipe);
700 struct pipe_context *pipe = tr_ctx->pipe;
702 trace_dump_call_begin("pipe_context", "set_stencil_ref");
704 trace_dump_arg(ptr, pipe);
705 trace_dump_arg(stencil_ref, state);
707 pipe->set_stencil_ref(pipe, state);
709 trace_dump_call_end();
714 trace_context_set_clip_state(struct pipe_context *_pipe,
715 const struct pipe_clip_state *state)
717 struct trace_context *tr_ctx = trace_context(_pipe);
718 struct pipe_context *pipe = tr_ctx->pipe;
720 trace_dump_call_begin("pipe_context", "set_clip_state");
722 trace_dump_arg(ptr, pipe);
723 trace_dump_arg(clip_state, state);
725 pipe->set_clip_state(pipe, state);
727 trace_dump_call_end();
731 trace_context_set_sample_mask(struct pipe_context *_pipe,
732 unsigned sample_mask)
734 struct trace_context *tr_ctx = trace_context(_pipe);
735 struct pipe_context *pipe = tr_ctx->pipe;
737 trace_dump_call_begin("pipe_context", "set_sample_mask");
739 trace_dump_arg(ptr, pipe);
740 trace_dump_arg(uint, sample_mask);
742 pipe->set_sample_mask(pipe, sample_mask);
744 trace_dump_call_end();
748 trace_context_set_constant_buffer(struct pipe_context *_pipe,
749 uint shader, uint index,
750 struct pipe_constant_buffer *constant_buffer)
752 struct trace_context *tr_ctx = trace_context(_pipe);
753 struct pipe_context *pipe = tr_ctx->pipe;
754 struct pipe_constant_buffer cb;
756 if (constant_buffer) {
757 cb = *constant_buffer;
758 cb.buffer = trace_resource_unwrap(tr_ctx, constant_buffer->buffer);
761 trace_dump_call_begin("pipe_context", "set_constant_buffer");
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();
773 trace_dump_arg(ptr, constant_buffer);
776 pipe->set_constant_buffer(pipe, shader, index,
777 constant_buffer ? &cb : NULL);
779 trace_dump_call_end();
784 trace_context_set_framebuffer_state(struct pipe_context *_pipe,
785 const struct pipe_framebuffer_state *state)
787 struct trace_context *tr_ctx = trace_context(_pipe);
788 struct pipe_context *pipe = tr_ctx->pipe;
789 struct pipe_framebuffer_state unwrapped_state;
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;
802 trace_dump_call_begin("pipe_context", "set_framebuffer_state");
804 trace_dump_arg(ptr, pipe);
805 trace_dump_arg(framebuffer_state, state);
807 pipe->set_framebuffer_state(pipe, state);
809 trace_dump_call_end();
814 trace_context_set_polygon_stipple(struct pipe_context *_pipe,
815 const struct pipe_poly_stipple *state)
817 struct trace_context *tr_ctx = trace_context(_pipe);
818 struct pipe_context *pipe = tr_ctx->pipe;
820 trace_dump_call_begin("pipe_context", "set_polygon_stipple");
822 trace_dump_arg(ptr, pipe);
823 trace_dump_arg(poly_stipple, state);
825 pipe->set_polygon_stipple(pipe, state);
827 trace_dump_call_end();
832 trace_context_set_scissor_state(struct pipe_context *_pipe,
833 const struct pipe_scissor_state *state)
835 struct trace_context *tr_ctx = trace_context(_pipe);
836 struct pipe_context *pipe = tr_ctx->pipe;
838 trace_dump_call_begin("pipe_context", "set_scissor_state");
840 trace_dump_arg(ptr, pipe);
841 trace_dump_arg(scissor_state, state);
843 pipe->set_scissor_state(pipe, state);
845 trace_dump_call_end();
850 trace_context_set_viewport_state(struct pipe_context *_pipe,
851 const struct pipe_viewport_state *state)
853 struct trace_context *tr_ctx = trace_context(_pipe);
854 struct pipe_context *pipe = tr_ctx->pipe;
856 trace_dump_call_begin("pipe_context", "set_viewport_state");
858 trace_dump_arg(ptr, pipe);
859 trace_dump_arg(viewport_state, state);
861 pipe->set_viewport_state(pipe, state);
863 trace_dump_call_end();
867 static struct pipe_sampler_view *
868 trace_context_create_sampler_view(struct pipe_context *_pipe,
869 struct pipe_resource *_resource,
870 const struct pipe_sampler_view *templ)
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;
879 trace_dump_call_begin("pipe_context", "create_sampler_view");
881 trace_dump_arg(ptr, pipe);
882 trace_dump_arg(ptr, resource);
884 trace_dump_arg_begin("templ");
885 trace_dump_sampler_view_template(templ, resource->target);
886 trace_dump_arg_end();
888 result = pipe->create_sampler_view(pipe, resource, templ);
890 trace_dump_ret(ptr, result);
892 trace_dump_call_end();
895 * Wrap pipe_sampler_view
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;
911 trace_context_sampler_view_destroy(struct pipe_context *_pipe,
912 struct pipe_sampler_view *_view)
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;
919 trace_dump_call_begin("pipe_context", "sampler_view_destroy");
921 trace_dump_arg(ptr, pipe);
922 trace_dump_arg(ptr, view);
924 pipe_sampler_view_reference(&tr_view->sampler_view, NULL);
926 trace_dump_call_end();
928 pipe_resource_reference(&_view->texture, NULL);
932 /********************************************************************
937 static struct pipe_surface *
938 trace_context_create_surface(struct pipe_context *_pipe,
939 struct pipe_resource *_resource,
940 const struct pipe_surface *surf_tmpl)
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;
948 trace_dump_call_begin("pipe_context", "create_surface");
950 trace_dump_arg(ptr, pipe);
951 trace_dump_arg(ptr, resource);
953 trace_dump_arg_begin("surf_tmpl");
954 trace_dump_surface_template(surf_tmpl, resource->target);
955 trace_dump_arg_end();
958 result = pipe->create_surface(pipe, resource, surf_tmpl);
960 trace_dump_ret(ptr, result);
962 trace_dump_call_end();
964 result = trace_surf_create(tr_res, result);
971 trace_context_surface_destroy(struct pipe_context *_pipe,
972 struct pipe_surface *_surface)
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;
979 trace_dump_call_begin("pipe_context", "surface_destroy");
981 trace_dump_arg(ptr, pipe);
982 trace_dump_arg(ptr, surface);
984 trace_dump_call_end();
986 trace_surf_destroy(tr_surf);
991 trace_context_set_sampler_views(struct pipe_context *_pipe,
995 struct pipe_sampler_view **views)
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];
1003 /* remove this when we have pipe->set_sampler_views(..., start, ...) */
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;
1010 views = unwrapped_views;
1013 case PIPE_SHADER_VERTEX:
1014 trace_dump_call_begin("pipe_context", "set_vertex_sampler_views");
1016 case PIPE_SHADER_GEOMETRY:
1017 trace_dump_call_begin("pipe_context", "set_geometry_sampler_views");
1019 case PIPE_SHADER_FRAGMENT:
1020 trace_dump_call_begin("pipe_context", "set_fragment_sampler_views");
1023 debug_error("Unexpected shader in trace_context_set_sampler_views()");
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);
1032 case PIPE_SHADER_VERTEX:
1033 pipe->set_vertex_sampler_views(pipe, num, views);
1035 case PIPE_SHADER_GEOMETRY:
1036 pipe->set_geometry_sampler_views(pipe, num, views);
1038 case PIPE_SHADER_FRAGMENT:
1039 pipe->set_fragment_sampler_views(pipe, num, views);
1042 debug_error("Unexpected shader in trace_context_set_sampler_views()");
1045 trace_dump_call_end();
1050 trace_context_set_fragment_sampler_views(struct pipe_context *_pipe,
1052 struct pipe_sampler_view **views)
1054 trace_context_set_sampler_views(_pipe, PIPE_SHADER_FRAGMENT, 0, num, views);
1059 trace_context_set_vertex_sampler_views(struct pipe_context *_pipe,
1061 struct pipe_sampler_view **views)
1063 trace_context_set_sampler_views(_pipe, PIPE_SHADER_VERTEX, 0, num, views);
1068 trace_context_set_vertex_buffers(struct pipe_context *_pipe,
1069 unsigned num_buffers,
1070 const struct pipe_vertex_buffer *buffers)
1072 struct trace_context *tr_ctx = trace_context(_pipe);
1073 struct pipe_context *pipe = tr_ctx->pipe;
1076 trace_dump_call_begin("pipe_context", "set_vertex_buffers");
1078 trace_dump_arg(ptr, pipe);
1079 trace_dump_arg(uint, num_buffers);
1081 trace_dump_arg_begin("buffers");
1082 trace_dump_struct_array(vertex_buffer, buffers, num_buffers);
1083 trace_dump_arg_end();
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);
1093 pipe->set_vertex_buffers(pipe, num_buffers, NULL);
1096 trace_dump_call_end();
1101 trace_context_set_index_buffer(struct pipe_context *_pipe,
1102 const struct pipe_index_buffer *ib)
1104 struct trace_context *tr_ctx = trace_context(_pipe);
1105 struct pipe_context *pipe = tr_ctx->pipe;
1107 trace_dump_call_begin("pipe_context", "set_index_buffer");
1109 trace_dump_arg(ptr, pipe);
1110 trace_dump_arg(index_buffer, ib);
1113 struct pipe_index_buffer _ib;
1115 _ib.buffer = trace_resource_unwrap(tr_ctx, ib->buffer);
1116 pipe->set_index_buffer(pipe, &_ib);
1118 pipe->set_index_buffer(pipe, NULL);
1121 trace_dump_call_end();
1125 static INLINE struct pipe_stream_output_target *
1126 trace_context_create_stream_output_target(struct pipe_context *_pipe,
1127 struct pipe_resource *res,
1128 unsigned buffer_offset,
1129 unsigned buffer_size)
1131 struct trace_context *tr_ctx = trace_context(_pipe);
1132 struct pipe_context *pipe = tr_ctx->pipe;
1133 struct pipe_stream_output_target *result;
1135 res = trace_resource_unwrap(tr_ctx, res);
1137 trace_dump_call_begin("pipe_context", "create_stream_output_target");
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);
1144 result = pipe->create_stream_output_target(pipe,
1145 res, buffer_offset, buffer_size);
1147 trace_dump_call_end();
1154 trace_context_stream_output_target_destroy(
1155 struct pipe_context *_pipe,
1156 struct pipe_stream_output_target *target)
1158 struct trace_context *tr_ctx = trace_context(_pipe);
1159 struct pipe_context *pipe = tr_ctx->pipe;
1161 trace_dump_call_begin("pipe_context", "stream_output_target_destroy");
1163 trace_dump_arg(ptr, pipe);
1164 trace_dump_arg(ptr, target);
1166 pipe->stream_output_target_destroy(pipe, target);
1168 trace_dump_call_end();
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)
1178 struct trace_context *tr_ctx = trace_context(_pipe);
1179 struct pipe_context *pipe = tr_ctx->pipe;
1181 trace_dump_call_begin("pipe_context", "set_stream_output_targets");
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);
1188 pipe->set_stream_output_targets(pipe, num_targets, tgs, append_bitmask);
1190 trace_dump_call_end();
1195 trace_context_resource_copy_region(struct pipe_context *_pipe,
1196 struct pipe_resource *dst,
1198 unsigned dstx, unsigned dsty, unsigned dstz,
1199 struct pipe_resource *src,
1201 const struct pipe_box *src_box)
1203 struct trace_context *tr_ctx = trace_context(_pipe);
1204 struct pipe_context *pipe = tr_ctx->pipe;
1206 dst = trace_resource_unwrap(tr_ctx, dst);
1207 src = trace_resource_unwrap(tr_ctx, src);
1209 trace_dump_call_begin("pipe_context", "resource_copy_region");
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);
1221 pipe->resource_copy_region(pipe,
1222 dst, dst_level, dstx, dsty, dstz,
1223 src, src_level, src_box);
1225 trace_dump_call_end();
1230 trace_context_clear(struct pipe_context *_pipe,
1232 const union pipe_color_union *color,
1236 struct trace_context *tr_ctx = trace_context(_pipe);
1237 struct pipe_context *pipe = tr_ctx->pipe;
1239 trace_dump_call_begin("pipe_context", "clear");
1241 trace_dump_arg(ptr, pipe);
1242 trace_dump_arg(uint, buffers);
1243 trace_dump_arg_begin("color");
1245 trace_dump_array(float, color->f, 4);
1248 trace_dump_arg_end();
1249 trace_dump_arg(float, depth);
1250 trace_dump_arg(uint, stencil);
1252 pipe->clear(pipe, buffers, color, depth, stencil);
1254 trace_dump_call_end();
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)
1265 struct trace_context *tr_ctx = trace_context(_pipe);
1266 struct pipe_context *pipe = tr_ctx->pipe;
1268 dst = trace_surface_unwrap(tr_ctx, dst);
1270 trace_dump_call_begin("pipe_context", "clear_render_target");
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);
1280 pipe->clear_render_target(pipe, dst, color, dstx, dsty, width, height);
1282 trace_dump_call_end();
1286 trace_context_clear_depth_stencil(struct pipe_context *_pipe,
1287 struct pipe_surface *dst,
1288 unsigned clear_flags,
1291 unsigned dstx, unsigned dsty,
1292 unsigned width, unsigned height)
1294 struct trace_context *tr_ctx = trace_context(_pipe);
1295 struct pipe_context *pipe = tr_ctx->pipe;
1297 dst = trace_surface_unwrap(tr_ctx, dst);
1299 trace_dump_call_begin("pipe_context", "clear_depth_stencil");
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);
1311 pipe->clear_depth_stencil(pipe, dst, clear_flags, depth, stencil,
1312 dstx, dsty, width, height);
1314 trace_dump_call_end();
1318 trace_context_flush(struct pipe_context *_pipe,
1319 struct pipe_fence_handle **fence)
1321 struct trace_context *tr_ctx = trace_context(_pipe);
1322 struct pipe_context *pipe = tr_ctx->pipe;
1324 trace_dump_call_begin("pipe_context", "flush");
1326 trace_dump_arg(ptr, pipe);
1328 pipe->flush(pipe, fence);
1331 trace_dump_ret(ptr, *fence);
1333 trace_dump_call_end();
1338 trace_context_destroy(struct pipe_context *_pipe)
1340 struct trace_context *tr_ctx = trace_context(_pipe);
1341 struct pipe_context *pipe = tr_ctx->pipe;
1343 trace_dump_call_begin("pipe_context", "destroy");
1344 trace_dump_arg(ptr, pipe);
1345 trace_dump_call_end();
1347 pipe->destroy(pipe);
1353 /********************************************************************
1358 static struct pipe_transfer *
1359 trace_context_get_transfer(struct pipe_context *_context,
1360 struct pipe_resource *_resource,
1363 const struct pipe_box *box)
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;
1371 assert(texture->screen == context->screen);
1374 * Map and transfers can't be serialized so we convert all write transfers
1375 * to transfer_inline_write and ignore read transfers.
1378 result = context->get_transfer(context, texture, level, usage, box);
1381 result = trace_transfer_create(tr_context, tr_res, result);
1388 trace_context_transfer_destroy(struct pipe_context *_context,
1389 struct pipe_transfer *_transfer)
1391 struct trace_context *tr_context = trace_context(_context);
1392 struct trace_transfer *tr_trans = trace_transfer(_transfer);
1394 trace_transfer_destroy(tr_context, tr_trans);
1399 trace_context_transfer_map(struct pipe_context *_context,
1400 struct pipe_transfer *_transfer)
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;
1408 map = context->transfer_map(context, transfer);
1410 if(transfer->usage & PIPE_TRANSFER_WRITE) {
1411 assert(!tr_trans->map);
1412 tr_trans->map = map;
1421 trace_context_transfer_flush_region( struct pipe_context *_context,
1422 struct pipe_transfer *_transfer,
1423 const struct pipe_box *box)
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;
1430 context->transfer_flush_region(context,
1436 trace_context_transfer_unmap(struct pipe_context *_context,
1437 struct pipe_transfer *_transfer)
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;
1446 * Fake a transfer_inline_write
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;
1456 trace_dump_call_begin("pipe_context", "transfer_inline_write");
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);
1464 trace_dump_arg_begin("data");
1465 trace_dump_box_bytes(tr_trans->map,
1470 trace_dump_arg_end();
1472 trace_dump_arg(uint, stride);
1473 trace_dump_arg(uint, layer_stride);
1475 trace_dump_call_end();
1477 tr_trans->map = NULL;
1480 context->transfer_unmap(context, transfer);
1485 trace_context_transfer_inline_write(struct pipe_context *_context,
1486 struct pipe_resource *_resource,
1489 const struct pipe_box *box,
1492 unsigned layer_stride)
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;
1499 assert(resource->screen == context->screen);
1501 trace_dump_call_begin("pipe_context", "transfer_inline_write");
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);
1509 trace_dump_arg_begin("data");
1510 trace_dump_box_bytes(data,
1515 trace_dump_arg_end();
1517 trace_dump_arg(uint, stride);
1518 trace_dump_arg(uint, layer_stride);
1520 trace_dump_call_end();
1522 context->transfer_inline_write(context, resource,
1523 level, usage, box, data, stride, layer_stride);
1527 static void trace_context_render_condition(struct pipe_context *_context,
1528 struct pipe_query *query,
1531 struct trace_context *tr_context = trace_context(_context);
1532 struct pipe_context *context = tr_context->pipe;
1534 trace_dump_call_begin("pipe_context", "render_condition");
1536 trace_dump_arg(ptr, context);
1537 trace_dump_arg(ptr, query);
1538 trace_dump_arg(uint, mode);
1540 trace_dump_call_end();
1542 context->render_condition(context, query, mode);
1546 static void trace_context_texture_barrier(struct pipe_context *_context)
1548 struct trace_context *tr_context = trace_context(_context);
1549 struct pipe_context *context = tr_context->pipe;
1551 trace_dump_call_begin("pipe_context", "texture_barrier");
1553 trace_dump_arg(ptr, context);
1555 trace_dump_call_end();
1557 context->texture_barrier(context);
1561 static const struct debug_named_value rbug_blocker_flags[] = {
1562 {"before", 1, NULL},
1564 DEBUG_NAMED_VALUE_END
1567 struct pipe_context *
1568 trace_context_create(struct trace_screen *tr_scr,
1569 struct pipe_context *pipe)
1571 struct trace_context *tr_ctx;
1576 if(!trace_enabled())
1579 tr_ctx = CALLOC_STRUCT(trace_context);
1583 tr_ctx->base.priv = pipe->priv; /* expose wrapped priv data */
1584 tr_ctx->base.screen = &tr_scr->base;
1586 tr_ctx->base.destroy = trace_context_destroy;
1588 #define TR_CTX_INIT(_member) \
1589 tr_ctx->base . _member = pipe -> _member ? trace_context_ ## _member : NULL
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);
1641 TR_CTX_INIT(clear_render_target);
1642 TR_CTX_INIT(clear_depth_stencil);
1644 TR_CTX_INIT(render_condition);
1645 TR_CTX_INIT(texture_barrier);
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);
1656 tr_ctx->pipe = pipe;
1658 return &tr_ctx->base;