summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/trace
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/drivers/trace')
-rw-r--r--src/gallium/drivers/trace/README37
-rw-r--r--src/gallium/drivers/trace/SConscript16
-rw-r--r--src/gallium/drivers/trace/tr_context.c1064
-rw-r--r--src/gallium/drivers/trace/tr_context.h58
-rw-r--r--src/gallium/drivers/trace/tr_dump.c364
-rw-r--r--src/gallium/drivers/trace/tr_dump.h134
-rw-r--r--src/gallium/drivers/trace/tr_screen.c383
-rw-r--r--src/gallium/drivers/trace/tr_screen.h63
-rw-r--r--src/gallium/drivers/trace/tr_state.c488
-rw-r--r--src/gallium/drivers/trace/tr_state.h95
-rw-r--r--src/gallium/drivers/trace/tr_stream.c100
-rw-r--r--src/gallium/drivers/trace/tr_stream.h52
-rw-r--r--src/gallium/drivers/trace/tr_winsys.c462
-rw-r--r--src/gallium/drivers/trace/tr_winsys.h66
-rw-r--r--src/gallium/drivers/trace/trace.xsl185
15 files changed, 3567 insertions, 0 deletions
diff --git a/src/gallium/drivers/trace/README b/src/gallium/drivers/trace/README
new file mode 100644
index 0000000000..81da610bd5
--- /dev/null
+++ b/src/gallium/drivers/trace/README
@@ -0,0 +1,37 @@
+This directory contains a Gallium3D pipe driver which traces all incoming calls.
+
+To build, invoke scons on the top dir as
+
+ scons statetrackers=mesa drivers=softpipe,i915simple,trace winsys=xlib
+
+To use do
+
+ ln -s libGL.so build/linux-x86-debug/gallium/winsys/xlib/libGL.so.1
+ export LD_LIBRARY_PATH=$PWD/build/linux-x86-debug/gallium/winsys/xlib
+ export GALLIUM_TRACE=y
+
+ensure the right libGL.so is being picked by doing
+
+ ldd `which glxingo`
+
+and then try running
+
+ glxinfo
+
+which should create a gallium.*.trace file, which is an XML file. You can view
+copying trace.xsl and trace.css to the same directory, and opening with a
+XSLT capable browser like Firefox or Internet Explorer. It often happens that
+the trace file was not properly terminated, and a
+
+ </trace>
+
+closing tag is missing from the file end. Add it before try to open or
+further transform it by doing
+
+ echo '</trace>' >> gallium.??.trace
+
+
+This is still work in progress.
+
+--
+Jose Fonseca <jrfonseca@tungstengraphics.com>
diff --git a/src/gallium/drivers/trace/SConscript b/src/gallium/drivers/trace/SConscript
new file mode 100644
index 0000000000..35507e21e4
--- /dev/null
+++ b/src/gallium/drivers/trace/SConscript
@@ -0,0 +1,16 @@
+Import('*')
+
+env = env.Clone()
+
+trace = env.ConvenienceLibrary(
+ target = 'trace',
+ source = [
+ 'tr_context.c',
+ 'tr_dump.c',
+ 'tr_screen.c',
+ 'tr_state.c',
+ 'tr_stream.c',
+ 'tr_winsys.c',
+ ])
+
+Export('trace') \ No newline at end of file
diff --git a/src/gallium/drivers/trace/tr_context.c b/src/gallium/drivers/trace/tr_context.c
new file mode 100644
index 0000000000..47a217ec7c
--- /dev/null
+++ b/src/gallium/drivers/trace/tr_context.c
@@ -0,0 +1,1064 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include "pipe/p_util.h"
+
+#include "tr_stream.h"
+#include "tr_dump.h"
+#include "tr_state.h"
+#include "tr_winsys.h"
+#include "tr_screen.h"
+#include "tr_context.h"
+
+
+static INLINE void
+trace_context_set_edgeflags(struct pipe_context *_pipe,
+ const unsigned *bitfield)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "set_edgeflags");
+
+ trace_dump_arg(stream, ptr, pipe);
+ /* FIXME: we don't know how big this array is */
+ trace_dump_arg(stream, ptr, bitfield);
+
+ pipe->set_edgeflags(pipe, bitfield);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE boolean
+trace_context_draw_arrays(struct pipe_context *_pipe,
+ unsigned mode, unsigned start, unsigned count)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+ boolean result;
+
+ trace_dump_call_begin(stream, "pipe_context", "draw_arrays");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, uint, mode);
+ trace_dump_arg(stream, uint, start);
+ trace_dump_arg(stream, uint, count);
+
+ result = pipe->draw_arrays(pipe, mode, start, count);;
+
+ trace_dump_ret(stream, bool, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static INLINE boolean
+trace_context_draw_elements(struct pipe_context *_pipe,
+ struct pipe_buffer *indexBuffer,
+ unsigned indexSize,
+ unsigned mode, unsigned start, unsigned count)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+ boolean result;
+
+ trace_dump_call_begin(stream, "pipe_context", "draw_elements");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, ptr, indexBuffer);
+ trace_dump_arg(stream, uint, indexSize);
+ trace_dump_arg(stream, uint, mode);
+ trace_dump_arg(stream, uint, start);
+ trace_dump_arg(stream, uint, count);
+
+ result = pipe->draw_elements(pipe, indexBuffer, indexSize, mode, start, count);;
+
+ trace_dump_ret(stream, bool, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static INLINE boolean
+trace_context_draw_range_elements(struct pipe_context *_pipe,
+ struct pipe_buffer *indexBuffer,
+ unsigned indexSize,
+ unsigned minIndex,
+ unsigned maxIndex,
+ unsigned mode,
+ unsigned start,
+ unsigned count)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+ boolean result;
+
+ trace_dump_call_begin(stream, "pipe_context", "draw_range_elements");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, ptr, indexBuffer);
+ trace_dump_arg(stream, uint, indexSize);
+ trace_dump_arg(stream, uint, minIndex);
+ trace_dump_arg(stream, uint, maxIndex);
+ trace_dump_arg(stream, uint, mode);
+ trace_dump_arg(stream, uint, start);
+ trace_dump_arg(stream, uint, count);
+
+ result = pipe->draw_range_elements(pipe,
+ indexBuffer,
+ indexSize, minIndex, maxIndex,
+ mode, start, count);
+
+ trace_dump_ret(stream, bool, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static INLINE struct pipe_query *
+trace_context_create_query(struct pipe_context *_pipe,
+ unsigned query_type)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+ struct pipe_query *result;
+
+ trace_dump_call_begin(stream, "pipe_context", "create_query");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, uint, query_type);
+
+ result = pipe->create_query(pipe, query_type);;
+
+ trace_dump_ret(stream, ptr, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static INLINE void
+trace_context_destroy_query(struct pipe_context *_pipe,
+ struct pipe_query *query)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "destroy_query");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, ptr, query);
+
+ pipe->destroy_query(pipe, query);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_begin_query(struct pipe_context *_pipe,
+ struct pipe_query *query)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "begin_query");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, ptr, query);
+
+ pipe->begin_query(pipe, query);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_end_query(struct pipe_context *_pipe,
+ struct pipe_query *query)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "end_query");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, ptr, query);
+
+ pipe->end_query(pipe, query);
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE boolean
+trace_context_get_query_result(struct pipe_context *_pipe,
+ struct pipe_query *query,
+ boolean wait,
+ uint64 *presult)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+ uint64 result;
+ boolean _result;
+
+ trace_dump_call_begin(stream, "pipe_context", "get_query_result");
+
+ trace_dump_arg(stream, ptr, pipe);
+
+ _result = pipe->get_query_result(pipe, query, wait, presult);;
+ result = *presult;
+
+ trace_dump_arg(stream, uint, result);
+ trace_dump_ret(stream, bool, _result);
+
+ trace_dump_call_end(stream);
+
+ return _result;
+}
+
+
+static INLINE void *
+trace_context_create_blend_state(struct pipe_context *_pipe,
+ const struct pipe_blend_state *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+ void * result;
+
+ trace_dump_call_begin(stream, "pipe_context", "create_blend_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, blend_state, state);
+
+ result = pipe->create_blend_state(pipe, state);;
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static INLINE void
+trace_context_bind_blend_state(struct pipe_context *_pipe,
+ void *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "bind_blend_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, ptr, state);
+
+ pipe->bind_blend_state(pipe, state);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_delete_blend_state(struct pipe_context *_pipe,
+ void *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "delete_blend_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, ptr, state);
+
+ pipe->delete_blend_state(pipe, state);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void *
+trace_context_create_sampler_state(struct pipe_context *_pipe,
+ const struct pipe_sampler_state *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+ void * result;
+
+ trace_dump_call_begin(stream, "pipe_context", "create_sampler_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, ptr, state);
+
+ result = pipe->create_sampler_state(pipe, state);;
+
+ trace_dump_ret(stream, sampler_state, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static INLINE void
+trace_context_bind_sampler_states(struct pipe_context *_pipe,
+ unsigned num_states, void **states)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "bind_sampler_states");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, uint, num_states);
+ trace_dump_arg_array(stream, ptr, states, num_states);
+
+ pipe->bind_sampler_states(pipe, num_states, states);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_delete_sampler_state(struct pipe_context *_pipe,
+ void *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "delete_sampler_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, ptr, state);
+
+ pipe->delete_sampler_state(pipe, state);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void *
+trace_context_create_rasterizer_state(struct pipe_context *_pipe,
+ const struct pipe_rasterizer_state *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+ void * result;
+
+ trace_dump_call_begin(stream, "pipe_context", "create_rasterizer_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, rasterizer_state, state);
+
+ result = pipe->create_rasterizer_state(pipe, state);;
+
+ trace_dump_ret(stream, ptr, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static INLINE void
+trace_context_bind_rasterizer_state(struct pipe_context *_pipe,
+ void *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "bind_rasterizer_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, ptr, state);
+
+ pipe->bind_rasterizer_state(pipe, state);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_delete_rasterizer_state(struct pipe_context *_pipe,
+ void *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "delete_rasterizer_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, ptr, state);
+
+ pipe->delete_rasterizer_state(pipe, state);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void *
+trace_context_create_depth_stencil_alpha_state(struct pipe_context *_pipe,
+ const struct pipe_depth_stencil_alpha_state *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+ void * result;
+
+ trace_dump_call_begin(stream, "pipe_context", "create_depth_stencil_alpha_state");
+
+ result = pipe->create_depth_stencil_alpha_state(pipe, state);;
+
+ trace_dump_ret(stream, ptr, result);
+ trace_dump_arg(stream, depth_stencil_alpha_state, state);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static INLINE void
+trace_context_bind_depth_stencil_alpha_state(struct pipe_context *_pipe,
+ void *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "bind_depth_stencil_alpha_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, ptr, state);
+
+ pipe->bind_depth_stencil_alpha_state(pipe, state);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_delete_depth_stencil_alpha_state(struct pipe_context *_pipe,
+ void *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "delete_depth_stencil_alpha_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, ptr, state);
+
+ pipe->delete_depth_stencil_alpha_state(pipe, state);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void *
+trace_context_create_fs_state(struct pipe_context *_pipe,
+ const struct pipe_shader_state *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+ void * result;
+
+ trace_dump_call_begin(stream, "pipe_context", "create_fs_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, shader_state, state);
+
+ result = pipe->create_fs_state(pipe, state);;
+
+ trace_dump_ret(stream, ptr, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static INLINE void
+trace_context_bind_fs_state(struct pipe_context *_pipe,
+ void *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "bind_fs_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, ptr, state);
+
+ pipe->bind_fs_state(pipe, state);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_delete_fs_state(struct pipe_context *_pipe,
+ void *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "delete_fs_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, ptr, state);
+
+ pipe->delete_fs_state(pipe, state);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void *
+trace_context_create_vs_state(struct pipe_context *_pipe,
+ const struct pipe_shader_state *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+ void * result;
+
+ trace_dump_call_begin(stream, "pipe_context", "create_vs_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, shader_state, state);
+
+ result = pipe->create_vs_state(pipe, state);;
+
+ trace_dump_ret(stream, ptr, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static INLINE void
+trace_context_bind_vs_state(struct pipe_context *_pipe,
+ void *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "bind_vs_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, ptr, state);
+
+ pipe->bind_vs_state(pipe, state);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_delete_vs_state(struct pipe_context *_pipe,
+ void *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "delete_vs_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, ptr, state);
+
+ pipe->delete_vs_state(pipe, state);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_set_blend_color(struct pipe_context *_pipe,
+ const struct pipe_blend_color *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "set_blend_color");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, blend_color, state);
+
+ pipe->set_blend_color(pipe, state);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_set_clip_state(struct pipe_context *_pipe,
+ const struct pipe_clip_state *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "set_clip_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, clip_state, state);
+
+ pipe->set_clip_state(pipe, state);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_set_constant_buffer(struct pipe_context *_pipe,
+ uint shader, uint index,
+ const struct pipe_constant_buffer *buffer)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "set_constant_buffer");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, uint, shader);
+ trace_dump_arg(stream, uint, index);
+ trace_dump_arg(stream, constant_buffer, buffer);
+
+ pipe->set_constant_buffer(pipe, shader, index, buffer);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_set_framebuffer_state(struct pipe_context *_pipe,
+ const struct pipe_framebuffer_state *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "set_framebuffer_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, framebuffer_state, state);
+
+ pipe->set_framebuffer_state(pipe, state);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_set_polygon_stipple(struct pipe_context *_pipe,
+ const struct pipe_poly_stipple *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "set_polygon_stipple");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, poly_stipple, state);
+
+ pipe->set_polygon_stipple(pipe, state);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_set_scissor_state(struct pipe_context *_pipe,
+ const struct pipe_scissor_state *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "set_scissor_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, scissor_state, state);
+
+ pipe->set_scissor_state(pipe, state);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_set_viewport_state(struct pipe_context *_pipe,
+ const struct pipe_viewport_state *state)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "set_viewport_state");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, viewport_state, state);
+
+ pipe->set_viewport_state(pipe, state);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_set_sampler_textures(struct pipe_context *_pipe,
+ unsigned num_textures,
+ struct pipe_texture **textures)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "set_sampler_textures");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, uint, num_textures);
+ trace_dump_arg_array(stream, ptr, textures, num_textures);
+
+ pipe->set_sampler_textures(pipe, num_textures, textures);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_set_vertex_buffers(struct pipe_context *_pipe,
+ unsigned num_buffers,
+ const struct pipe_vertex_buffer *buffers)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "set_vertex_buffers");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, uint, num_buffers);
+
+ trace_dump_arg_begin(stream, "buffers");
+ trace_dump_struct_array(stream, vertex_buffer, buffers, num_buffers);
+ trace_dump_arg_end(stream);
+
+ pipe->set_vertex_buffers(pipe, num_buffers, buffers);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_set_vertex_elements(struct pipe_context *_pipe,
+ unsigned num_elements,
+ const struct pipe_vertex_element *elements)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "set_vertex_elements");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, uint, num_elements);
+ trace_dump_arg(stream, ptr, elements);
+
+ trace_dump_arg_begin(stream, "elements");
+ trace_dump_struct_array(stream, vertex_element, elements, num_elements);
+ trace_dump_arg_end(stream);
+
+ pipe->set_vertex_elements(pipe, num_elements, elements);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_surface_copy(struct pipe_context *_pipe,
+ boolean do_flip,
+ struct pipe_surface *dest,
+ unsigned destx, unsigned desty,
+ struct pipe_surface *src,
+ unsigned srcx, unsigned srcy,
+ unsigned width, unsigned height)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "surface_copy");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, bool, do_flip);
+ trace_dump_arg(stream, ptr, dest);
+ trace_dump_arg(stream, uint, destx);
+ trace_dump_arg(stream, uint, desty);
+ trace_dump_arg(stream, ptr, src);
+ trace_dump_arg(stream, uint, srcx);
+ trace_dump_arg(stream, uint, srcy);
+ trace_dump_arg(stream, uint, width);
+ trace_dump_arg(stream, uint, height);
+
+ pipe->surface_copy(pipe, do_flip,
+ dest, destx, desty,
+ src, srcx, srcy, width, height);
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_surface_fill(struct pipe_context *_pipe,
+ struct pipe_surface *dst,
+ unsigned dstx, unsigned dsty,
+ unsigned width, unsigned height,
+ unsigned value)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "surface_fill");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, ptr, dst);
+ trace_dump_arg(stream, uint, dstx);
+ trace_dump_arg(stream, uint, dsty);
+ trace_dump_arg(stream, uint, width);
+ trace_dump_arg(stream, uint, height);
+
+ pipe->surface_fill(pipe, dst, dstx, dsty, width, height, value);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_clear(struct pipe_context *_pipe,
+ struct pipe_surface *surface,
+ unsigned clearValue)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "clear");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, ptr, surface);
+ trace_dump_arg(stream, uint, clearValue);
+
+ pipe->clear(pipe, surface, clearValue);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_flush(struct pipe_context *_pipe,
+ unsigned flags,
+ struct pipe_fence_handle **fence)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "flush");
+
+ trace_dump_arg(stream, ptr, pipe);
+ trace_dump_arg(stream, uint, flags);
+ trace_dump_arg(stream, ptr, fence);
+
+ pipe->flush(pipe, flags, fence);;
+
+ trace_dump_call_end(stream);
+}
+
+
+static INLINE void
+trace_context_destroy(struct pipe_context *_pipe)
+{
+ struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_context *pipe = tr_ctx->pipe;
+
+ trace_dump_call_begin(stream, "pipe_context", "destroy");
+
+ trace_dump_arg(stream, ptr, pipe);
+
+ pipe->destroy(pipe);
+
+ trace_dump_call_end(stream);
+
+ FREE(tr_ctx);
+}
+
+
+struct pipe_context *
+trace_context_create(struct pipe_context *pipe)
+{
+ struct trace_context *tr_ctx;
+
+ if(!debug_get_bool_option("GALLIUM_TRACE", FALSE))
+ return pipe;
+
+ tr_ctx = CALLOC_STRUCT(trace_context);
+ if(!tr_ctx)
+ return NULL;
+
+ tr_ctx->base.winsys = pipe->winsys;
+ tr_ctx->base.screen = pipe->screen;
+ tr_ctx->base.destroy = trace_context_destroy;
+ tr_ctx->base.set_edgeflags = trace_context_set_edgeflags;
+ tr_ctx->base.draw_arrays = trace_context_draw_arrays;
+ tr_ctx->base.draw_elements = trace_context_draw_elements;
+ tr_ctx->base.draw_range_elements = trace_context_draw_range_elements;
+ tr_ctx->base.create_query = trace_context_create_query;
+ tr_ctx->base.destroy_query = trace_context_destroy_query;
+ tr_ctx->base.begin_query = trace_context_begin_query;
+ tr_ctx->base.end_query = trace_context_end_query;
+ tr_ctx->base.get_query_result = trace_context_get_query_result;
+ tr_ctx->base.create_blend_state = trace_context_create_blend_state;
+ tr_ctx->base.bind_blend_state = trace_context_bind_blend_state;
+ tr_ctx->base.delete_blend_state = trace_context_delete_blend_state;
+ tr_ctx->base.create_sampler_state = trace_context_create_sampler_state;
+ tr_ctx->base.bind_sampler_states = trace_context_bind_sampler_states;
+ tr_ctx->base.delete_sampler_state = trace_context_delete_sampler_state;
+ tr_ctx->base.create_rasterizer_state = trace_context_create_rasterizer_state;
+ tr_ctx->base.bind_rasterizer_state = trace_context_bind_rasterizer_state;
+ tr_ctx->base.delete_rasterizer_state = trace_context_delete_rasterizer_state;
+ tr_ctx->base.create_depth_stencil_alpha_state = trace_context_create_depth_stencil_alpha_state;
+ tr_ctx->base.bind_depth_stencil_alpha_state = trace_context_bind_depth_stencil_alpha_state;
+ tr_ctx->base.delete_depth_stencil_alpha_state = trace_context_delete_depth_stencil_alpha_state;
+ tr_ctx->base.create_fs_state = trace_context_create_fs_state;
+ tr_ctx->base.bind_fs_state = trace_context_bind_fs_state;
+ tr_ctx->base.delete_fs_state = trace_context_delete_fs_state;
+ tr_ctx->base.create_vs_state = trace_context_create_vs_state;
+ tr_ctx->base.bind_vs_state = trace_context_bind_vs_state;
+ tr_ctx->base.delete_vs_state = trace_context_delete_vs_state;
+ tr_ctx->base.set_blend_color = trace_context_set_blend_color;
+ tr_ctx->base.set_clip_state = trace_context_set_clip_state;
+ tr_ctx->base.set_constant_buffer = trace_context_set_constant_buffer;
+ tr_ctx->base.set_framebuffer_state = trace_context_set_framebuffer_state;
+ tr_ctx->base.set_polygon_stipple = trace_context_set_polygon_stipple;
+ tr_ctx->base.set_scissor_state = trace_context_set_scissor_state;
+ tr_ctx->base.set_viewport_state = trace_context_set_viewport_state;
+ tr_ctx->base.set_sampler_textures = trace_context_set_sampler_textures;
+ tr_ctx->base.set_vertex_buffers = trace_context_set_vertex_buffers;
+ tr_ctx->base.set_vertex_elements = trace_context_set_vertex_elements;
+ tr_ctx->base.surface_copy = trace_context_surface_copy;
+ tr_ctx->base.surface_fill = trace_context_surface_fill;
+ tr_ctx->base.clear = trace_context_clear;
+ tr_ctx->base.flush = trace_context_flush;
+
+ tr_ctx->pipe = pipe;
+
+ /* We don't want to trace the internal pipe calls */
+ pipe->winsys = trace_winsys(pipe->winsys)->winsys;
+ pipe->screen = trace_screen(pipe->screen)->screen;
+
+ return &tr_ctx->base;
+}
diff --git a/src/gallium/drivers/trace/tr_context.h b/src/gallium/drivers/trace/tr_context.h
new file mode 100644
index 0000000000..80fb5980d6
--- /dev/null
+++ b/src/gallium/drivers/trace/tr_context.h
@@ -0,0 +1,58 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef TR_CONTEXT_H_
+#define TR_CONTEXT_H_
+
+
+#include "pipe/p_compiler.h"
+#include "pipe/p_debug.h"
+#include "pipe/p_context.h"
+
+
+struct trace_context
+{
+ struct pipe_context base;
+
+ struct pipe_context *pipe;
+};
+
+
+static INLINE struct trace_context *
+trace_context(struct pipe_context *pipe)
+{
+ assert(pipe);
+ return (struct trace_context *)pipe;
+}
+
+
+
+struct pipe_context *
+trace_context_create(struct pipe_context *pipe);
+
+
+#endif /* TR_CONTEXT_H_ */
diff --git a/src/gallium/drivers/trace/tr_dump.c b/src/gallium/drivers/trace/tr_dump.c
new file mode 100644
index 0000000000..f545de30f4
--- /dev/null
+++ b/src/gallium/drivers/trace/tr_dump.c
@@ -0,0 +1,364 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+/**
+ * @file
+ * Trace dumping functions.
+ *
+ * For now we just use standard XML for dumping the trace calls, as this is
+ * simple to write, parse, and visually inspect, but the actual representation
+ * is abstracted out of this file, so that we can switch to a binary
+ * representation if/when it becomes justified.
+ *
+ * @author Jose Fonseca <jrfonseca@tungstengraphics.com>
+ */
+
+
+#include "pipe/p_compiler.h"
+#include "util/u_string.h"
+
+#include "tr_stream.h"
+#include "tr_dump.h"
+
+
+static INLINE void
+trace_dump_write(struct trace_stream *stream, const char *s)
+{
+ trace_stream_write(stream, s, strlen(s));
+}
+
+
+static INLINE void
+trace_dump_writef(struct trace_stream *stream, const char *format, ...)
+{
+ char buf[1024];
+ va_list ap;
+ va_start(ap, format);
+ util_vsnprintf(buf, sizeof(buf), format, ap);
+ va_end(ap);
+ trace_dump_write(stream, buf);
+}
+
+
+static INLINE void
+trace_dump_escape(struct trace_stream *stream, const char *str)
+{
+ const unsigned char *p = (const unsigned char *)str;
+ unsigned char c;
+ while((c = *p++) != 0) {
+ if(c == '<')
+ trace_dump_write(stream, "&lt;");
+ else if(c == '>')
+ trace_dump_write(stream, "&gt;");
+ else if(c == '&')
+ trace_dump_write(stream, "&amp;");
+ else if(c == '\'')
+ trace_dump_write(stream, "&apos;");
+ else if(c == '\"')
+ trace_dump_write(stream, "&quot;");
+ else if(c >= 0x20 && c <= 0x7e)
+ trace_dump_writef(stream, "%c", c);
+ else
+ trace_dump_writef(stream, "&#%u;", c);
+ }
+}
+
+
+static INLINE void
+trace_dump_indent(struct trace_stream *stream, unsigned level)
+{
+ unsigned i;
+ for(i = 0; i < level; ++i)
+ trace_dump_write(stream, "\t");
+}
+
+
+static INLINE void
+trace_dump_newline(struct trace_stream *stream)
+{
+ trace_dump_write(stream, "\n");
+}
+
+
+static INLINE void
+trace_dump_tag(struct trace_stream *stream,
+ const char *name)
+{
+ trace_dump_write(stream, "<");
+ trace_dump_write(stream, name);
+ trace_dump_write(stream, "/>");
+}
+
+
+static INLINE void
+trace_dump_tag_begin(struct trace_stream *stream,
+ const char *name)
+{
+ trace_dump_write(stream, "<");
+ trace_dump_write(stream, name);
+ trace_dump_write(stream, ">");
+}
+
+static INLINE void
+trace_dump_tag_begin1(struct trace_stream *stream,
+ const char *name,
+ const char *attr1, const char *value1)
+{
+ trace_dump_write(stream, "<");
+ trace_dump_write(stream, name);
+ trace_dump_write(stream, " ");
+ trace_dump_write(stream, attr1);
+ trace_dump_write(stream, "='");
+ trace_dump_escape(stream, value1);
+ trace_dump_write(stream, "'>");
+}
+
+
+static INLINE void
+trace_dump_tag_begin2(struct trace_stream *stream,
+ const char *name,
+ const char *attr1, const char *value1,
+ const char *attr2, const char *value2)
+{
+ trace_dump_write(stream, "<");
+ trace_dump_write(stream, name);
+ trace_dump_write(stream, " ");
+ trace_dump_write(stream, attr1);
+ trace_dump_write(stream, "=\'");
+ trace_dump_escape(stream, value1);
+ trace_dump_write(stream, "\' ");
+ trace_dump_write(stream, attr2);
+ trace_dump_write(stream, "=\'");
+ trace_dump_escape(stream, value2);
+ trace_dump_write(stream, "\'>");
+}
+
+
+static INLINE void
+trace_dump_tag_begin3(struct trace_stream *stream,
+ const char *name,
+ const char *attr1, const char *value1,
+ const char *attr2, const char *value2,
+ const char *attr3, const char *value3)
+{
+ trace_dump_write(stream, "<");
+ trace_dump_write(stream, name);
+ trace_dump_write(stream, " ");
+ trace_dump_write(stream, attr1);
+ trace_dump_write(stream, "=\'");
+ trace_dump_escape(stream, value1);
+ trace_dump_write(stream, "\' ");
+ trace_dump_write(stream, attr2);
+ trace_dump_write(stream, "=\'");
+ trace_dump_escape(stream, value2);
+ trace_dump_write(stream, "\' ");
+ trace_dump_write(stream, attr3);
+ trace_dump_write(stream, "=\'");
+ trace_dump_escape(stream, value3);
+ trace_dump_write(stream, "\'>");
+}
+
+
+static INLINE void
+trace_dump_tag_end(struct trace_stream *stream,
+ const char *name)
+{
+ trace_dump_write(stream, "</");
+ trace_dump_write(stream, name);
+ trace_dump_write(stream, ">");
+}
+
+
+void trace_dump_trace_begin(struct trace_stream *stream,
+ unsigned version)
+{
+ trace_dump_write(stream, "<?xml version='1.0' encoding='UTF-8'?>\n");
+ trace_dump_write(stream, "<?xml-stylesheet type='text/xsl' href='trace.xsl'?>\n");
+ trace_dump_writef(stream, "<trace version='%u'>\n", version);
+}
+
+
+void trace_dump_trace_end(struct trace_stream *stream)
+{
+ trace_dump_write(stream, "</trace>\n");
+}
+
+void trace_dump_call_begin(struct trace_stream *stream,
+ const char *klass, const char *method)
+{
+ trace_dump_indent(stream, 1);
+ trace_dump_tag_begin2(stream, "call", "class", klass, "method", method);
+ trace_dump_newline(stream);
+}
+
+void trace_dump_call_end(struct trace_stream *stream)
+{
+ trace_dump_indent(stream, 1);
+ trace_dump_tag_end(stream, "call");
+ trace_dump_newline(stream);
+}
+
+void trace_dump_arg_begin(struct trace_stream *stream,
+ const char *name)
+{
+ trace_dump_indent(stream, 2);
+ trace_dump_tag_begin1(stream, "arg", "name", name);
+}
+
+void trace_dump_arg_end(struct trace_stream *stream)
+{
+ trace_dump_tag_end(stream, "arg");
+ trace_dump_newline(stream);
+}
+
+void trace_dump_ret_begin(struct trace_stream *stream)
+{
+ trace_dump_indent(stream, 2);
+ trace_dump_tag_begin(stream, "ret");
+}
+
+void trace_dump_ret_end(struct trace_stream *stream)
+{
+ trace_dump_tag_end(stream, "ret");
+ trace_dump_newline(stream);
+}
+
+void trace_dump_bool(struct trace_stream *stream,
+ int value)
+{
+ trace_dump_writef(stream, "<bool>%c</bool>", value ? '1' : '0');
+}
+
+void trace_dump_int(struct trace_stream *stream,
+ long int value)
+{
+ trace_dump_writef(stream, "<int>%li</int>", value);
+}
+
+void trace_dump_uint(struct trace_stream *stream,
+ long unsigned value)
+{
+ trace_dump_writef(stream, "<uint>%lu</uint>", value);
+}
+
+void trace_dump_float(struct trace_stream *stream,
+ double value)
+{
+ trace_dump_writef(stream, "<float>%g</float>", value);
+}
+
+void trace_dump_bytes(struct trace_stream *stream,
+ const void *data,
+ long unsigned size)
+{
+ static char hex_table[] = "0123456789ABCDE";
+ const uint8_t *p = data;
+ long unsigned i;
+ trace_dump_write(stream, "<bytes>");
+ for(i = 0; i < size; ++i) {
+ uint8_t byte = *p++;
+ char str[3];
+ str[0] = hex_table[byte >> 4];
+ str[1] = hex_table[byte & 0xf];
+ str[2] = 0;
+ trace_dump_write(stream, str);
+ }
+ trace_dump_write(stream, "</bytes>");
+}
+
+void trace_dump_string(struct trace_stream *stream,
+ const char *str)
+{
+ trace_dump_write(stream, "<string>");
+ trace_dump_escape(stream, str);
+ trace_dump_write(stream, "</string>");
+}
+
+void trace_dump_enum(struct trace_stream *stream,
+ const char *value)
+{
+ trace_dump_write(stream, "<enum>");
+ trace_dump_escape(stream, value);
+ trace_dump_write(stream, "</enum>");
+}
+
+void trace_dump_array_begin(struct trace_stream *stream)
+{
+ trace_dump_write(stream, "<array>");
+}
+
+void trace_dump_array_end(struct trace_stream *stream)
+{
+ trace_dump_write(stream, "</array>");
+}
+
+void trace_dump_elem_begin(struct trace_stream *stream)
+{
+ trace_dump_write(stream, "<elem>");
+}
+
+void trace_dump_elem_end(struct trace_stream *stream)
+{
+ trace_dump_write(stream, "</elem>");
+}
+
+void trace_dump_struct_begin(struct trace_stream *stream,
+ const char *name)
+{
+ trace_dump_writef(stream, "<struct name='%s'>", name);
+}
+
+void trace_dump_struct_end(struct trace_stream *stream)
+{
+ trace_dump_write(stream, "</struct>");
+}
+
+void trace_dump_member_begin(struct trace_stream *stream,
+ const char *name)
+{
+ trace_dump_writef(stream, "<member name='%s'>", name);
+}
+
+void trace_dump_member_end(struct trace_stream *stream)
+{
+ trace_dump_write(stream, "</member>");
+}
+
+void trace_dump_null(struct trace_stream *stream)
+{
+ trace_dump_write(stream, "<null/>");
+}
+
+void trace_dump_ptr(struct trace_stream *stream,
+ const void *value)
+{
+ if(value)
+ trace_dump_writef(stream, "<ptr>%p</ptr>", value);
+ else
+ trace_dump_null(stream);
+}
diff --git a/src/gallium/drivers/trace/tr_dump.h b/src/gallium/drivers/trace/tr_dump.h
new file mode 100644
index 0000000000..b2367c3288
--- /dev/null
+++ b/src/gallium/drivers/trace/tr_dump.h
@@ -0,0 +1,134 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation streams (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/**
+ * @file
+ * Trace data dumping primitives.
+ */
+
+#ifndef TR_DUMP_H
+#define TR_DUMP_H
+
+
+#include "pipe/p_util.h"
+
+
+struct trace_stream;
+
+
+void trace_dump_trace_begin(struct trace_stream *stream, unsigned version);
+void trace_dump_trace_end(struct trace_stream *stream);
+void trace_dump_call_begin(struct trace_stream *stream, const char *klass, const char *method);
+void trace_dump_call_end(struct trace_stream *stream);
+void trace_dump_arg_begin(struct trace_stream *stream, const char *name);
+void trace_dump_arg_end(struct trace_stream *stream);
+void trace_dump_ret_begin(struct trace_stream *stream);
+void trace_dump_ret_end(struct trace_stream *stream);
+void trace_dump_bool(struct trace_stream *stream, int value);
+void trace_dump_int(struct trace_stream *stream, long int value);
+void trace_dump_uint(struct trace_stream *stream, long unsigned value);
+void trace_dump_float(struct trace_stream *stream, double value);
+void trace_dump_bytes(struct trace_stream *stream, const void *data, long unsigned size);
+void trace_dump_string(struct trace_stream *stream, const char *str);
+void trace_dump_enum(struct trace_stream *stream, const char *value);
+void trace_dump_array_begin(struct trace_stream *stream);
+void trace_dump_array_end(struct trace_stream *stream);
+void trace_dump_elem_begin(struct trace_stream *stream);
+void trace_dump_elem_end(struct trace_stream *stream);
+void trace_dump_struct_begin(struct trace_stream *stream, const char *name);
+void trace_dump_struct_end(struct trace_stream *stream);
+void trace_dump_member_begin(struct trace_stream *stream, const char *name);
+void trace_dump_member_end(struct trace_stream *stream);
+void trace_dump_null(struct trace_stream *stream);
+void trace_dump_ptr(struct trace_stream *stream, const void *value);
+
+
+/*
+ * Code saving macros.
+ */
+
+#define trace_dump_arg(_stream, _type, _arg) \
+ do { \
+ trace_dump_arg_begin(_stream, #_arg); \
+ trace_dump_##_type(_stream, _arg); \
+ trace_dump_arg_end(_stream); \
+ } while(0)
+
+#define trace_dump_ret(_stream, _type, _arg) \
+ do { \
+ trace_dump_ret_begin(_stream); \
+ trace_dump_##_type(_stream, _arg); \
+ trace_dump_ret_end(_stream); \
+ } while(0)
+
+#define trace_dump_array(_stream, _type, _obj, _size) \
+ do { \
+ unsigned long idx; \
+ trace_dump_array_begin(_stream); \
+ for(idx = 0; idx < (_size); ++idx) { \
+ trace_dump_elem_begin(_stream); \
+ trace_dump_##_type(_stream, (_obj)[idx]); \
+ trace_dump_elem_end(_stream); \
+ } \
+ trace_dump_array_end(_stream); \
+ } while(0)
+
+#define trace_dump_struct_array(_stream, _type, _obj, _size) \
+ do { \
+ unsigned long idx; \
+ trace_dump_array_begin(_stream); \
+ for(idx = 0; idx < (_size); ++idx) { \
+ trace_dump_elem_begin(_stream); \
+ trace_dump_##_type(_stream, &(_obj)[idx]); \
+ trace_dump_elem_end(_stream); \
+ } \
+ trace_dump_array_end(_stream); \
+ } while(0)
+
+#define trace_dump_member(_stream, _type, _obj, _member) \
+ do { \
+ trace_dump_member_begin(_stream, #_member); \
+ trace_dump_##_type(_stream, (_obj)->_member); \
+ trace_dump_member_end(_stream); \
+ } while(0)
+
+#define trace_dump_arg_array(_stream, _type, _arg, _size) \
+ do { \
+ trace_dump_arg_begin(_stream, #_arg); \
+ trace_dump_array(_stream, _type, _arg, _size); \
+ trace_dump_arg_end(_stream); \
+ } while(0)
+
+#define trace_dump_member_array(_stream, _type, _obj, _member) \
+ do { \
+ trace_dump_member_begin(_stream, #_member); \
+ trace_dump_array(_stream, _type, (_obj)->_member, sizeof((_obj)->_member)/sizeof((_obj)->_member[0])); \
+ trace_dump_member_end(_stream); \
+ } while(0)
+
+
+#endif /* TR_DUMP_H */
diff --git a/src/gallium/drivers/trace/tr_screen.c b/src/gallium/drivers/trace/tr_screen.c
new file mode 100644
index 0000000000..de885abae2
--- /dev/null
+++ b/src/gallium/drivers/trace/tr_screen.c
@@ -0,0 +1,383 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include "pipe/p_util.h"
+
+#include "tr_stream.h"
+#include "tr_dump.h"
+#include "tr_state.h"
+#include "tr_winsys.h"
+#include "tr_screen.h"
+
+
+static const char *
+trace_screen_get_name(struct pipe_screen *_screen)
+{
+ struct trace_screen *tr_scr = trace_screen(_screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_screen *screen = tr_scr->screen;
+ const char *result;
+
+ trace_dump_call_begin(stream, "pipe_screen", "get_name");
+
+ trace_dump_arg(stream, ptr, screen);
+
+ result = screen->get_name(screen);
+
+ trace_dump_ret(stream, string, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static const char *
+trace_screen_get_vendor(struct pipe_screen *_screen)
+{
+ struct trace_screen *tr_scr = trace_screen(_screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_screen *screen = tr_scr->screen;
+ const char *result;
+
+ trace_dump_call_begin(stream, "pipe_screen", "get_vendor");
+
+ trace_dump_arg(stream, ptr, screen);
+
+ result = screen->get_vendor(screen);
+
+ trace_dump_ret(stream, string, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static int
+trace_screen_get_param(struct pipe_screen *_screen,
+ int param)
+{
+ struct trace_screen *tr_scr = trace_screen(_screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_screen *screen = tr_scr->screen;
+ int result;
+
+ trace_dump_call_begin(stream, "pipe_screen", "get_param");
+
+ trace_dump_arg(stream, ptr, screen);
+ trace_dump_arg(stream, int, param);
+
+ result = screen->get_param(screen, param);
+
+ trace_dump_ret(stream, int, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static float
+trace_screen_get_paramf(struct pipe_screen *_screen,
+ int param)
+{
+ struct trace_screen *tr_scr = trace_screen(_screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_screen *screen = tr_scr->screen;
+ float result;
+
+ trace_dump_call_begin(stream, "pipe_screen", "get_paramf");
+
+ trace_dump_arg(stream, ptr, screen);
+ trace_dump_arg(stream, int, param);
+
+ result = screen->get_paramf(screen, param);
+
+ trace_dump_ret(stream, float, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static boolean
+trace_screen_is_format_supported(struct pipe_screen *_screen,
+ enum pipe_format format,
+ enum pipe_texture_target target,
+ unsigned tex_usage,
+ unsigned geom_flags)
+{
+ struct trace_screen *tr_scr = trace_screen(_screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_screen *screen = tr_scr->screen;
+ boolean result;
+
+ trace_dump_call_begin(stream, "pipe_screen", "is_format_supported");
+
+ trace_dump_arg(stream, ptr, screen);
+ trace_dump_arg(stream, format, format);
+ trace_dump_arg(stream, int, target);
+ trace_dump_arg(stream, uint, tex_usage);
+ trace_dump_arg(stream, uint, geom_flags);
+
+ result = screen->is_format_supported(screen, format, target, tex_usage, geom_flags);
+
+ trace_dump_ret(stream, bool, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static struct pipe_texture *
+trace_screen_texture_create(struct pipe_screen *_screen,
+ const struct pipe_texture *templat)
+{
+ struct trace_screen *tr_scr = trace_screen(_screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_screen *screen = tr_scr->screen;
+ struct pipe_texture *result;
+
+ trace_dump_call_begin(stream, "pipe_screen", "texture_create");
+
+ trace_dump_arg(stream, ptr, screen);
+ trace_dump_arg(stream, template, templat);
+
+ result = screen->texture_create(screen, templat);
+
+ trace_dump_ret(stream, ptr, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static struct pipe_texture *
+trace_screen_texture_blanket(struct pipe_screen *_screen,
+ const struct pipe_texture *templat,
+ const unsigned *ppitch,
+ struct pipe_buffer *buffer)
+{
+ struct trace_screen *tr_scr = trace_screen(_screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_screen *screen = tr_scr->screen;
+ unsigned pitch = *ppitch;
+ struct pipe_texture *result;
+
+ trace_dump_call_begin(stream, "pipe_screen", "texture_blanket");
+
+ trace_dump_arg(stream, ptr, screen);
+ trace_dump_arg(stream, template, templat);
+ trace_dump_arg(stream, uint, pitch);
+ trace_dump_arg(stream, ptr, buffer);
+
+ result = screen->texture_blanket(screen, templat, ppitch, buffer);
+
+ trace_dump_ret(stream, ptr, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static void
+trace_screen_texture_release(struct pipe_screen *_screen,
+ struct pipe_texture **ptexture)
+{
+ struct trace_screen *tr_scr = trace_screen(_screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_screen *screen = tr_scr->screen;
+ struct pipe_texture *texture = *ptexture;
+
+ trace_dump_call_begin(stream, "pipe_screen", "texture_release");
+
+ trace_dump_arg(stream, ptr, screen);
+ trace_dump_arg(stream, ptr, texture);
+
+ screen->texture_release(screen, ptexture);
+
+ trace_dump_call_end(stream);
+}
+
+static struct pipe_surface *
+trace_screen_get_tex_surface(struct pipe_screen *_screen,
+ struct pipe_texture *texture,
+ unsigned face, unsigned level,
+ unsigned zslice,
+ unsigned usage)
+{
+ struct trace_screen *tr_scr = trace_screen(_screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_screen *screen = tr_scr->screen;
+ struct pipe_surface *result;
+
+ trace_dump_call_begin(stream, "pipe_screen", "get_tex_surface");
+
+ trace_dump_arg(stream, ptr, screen);
+ trace_dump_arg(stream, ptr, texture);
+ trace_dump_arg(stream, uint, face);
+ trace_dump_arg(stream, uint, level);
+ trace_dump_arg(stream, uint, zslice);
+ trace_dump_arg(stream, uint, usage);
+
+ result = screen->get_tex_surface(screen, texture, face, level, zslice, usage);
+
+ trace_dump_ret(stream, ptr, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static void
+trace_screen_tex_surface_release(struct pipe_screen *_screen,
+ struct pipe_surface **psurface)
+{
+ struct trace_screen *tr_scr = trace_screen(_screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_screen *screen = tr_scr->screen;
+ struct pipe_surface *surface = *psurface;
+
+ trace_dump_call_begin(stream, "pipe_screen", "tex_surface_release");
+
+ trace_dump_arg(stream, ptr, screen);
+ trace_dump_arg(stream, ptr, surface);
+
+ screen->tex_surface_release(screen, psurface);
+
+ trace_dump_call_end(stream);
+}
+
+
+static void *
+trace_screen_surface_map(struct pipe_screen *_screen,
+ struct pipe_surface *surface,
+ unsigned flags)
+{
+ struct trace_screen *tr_scr = trace_screen(_screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_screen *screen = tr_scr->screen;
+ struct pipe_surface *result;
+
+ trace_dump_call_begin(stream, "pipe_screen", "surface_map");
+
+ trace_dump_arg(stream, ptr, screen);
+ trace_dump_arg(stream, ptr, surface);
+ trace_dump_arg(stream, uint, flags);
+
+ result = screen->surface_map(screen, surface, flags);
+
+ trace_dump_ret(stream, ptr, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static void
+trace_screen_surface_unmap(struct pipe_screen *_screen,
+ struct pipe_surface *surface)
+{
+ struct trace_screen *tr_scr = trace_screen(_screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_screen *screen = tr_scr->screen;
+
+ trace_dump_call_begin(stream, "pipe_screen", "surface_unmap");
+
+ trace_dump_arg(stream, ptr, screen);
+ trace_dump_arg(stream, ptr, surface);
+
+ screen->surface_unmap(screen, surface);
+
+ trace_dump_call_end(stream);
+}
+
+
+static void
+trace_screen_destroy(struct pipe_screen *_screen)
+{
+ struct trace_screen *tr_scr = trace_screen(_screen);
+ struct trace_stream *stream = tr_scr->stream;
+ struct pipe_screen *screen = tr_scr->screen;
+
+ trace_dump_call_begin(stream, "pipe_screen", "destroy");
+
+ trace_dump_arg(stream, ptr, screen);
+
+ screen->destroy(screen);
+
+ trace_dump_call_end(stream);
+
+ FREE(tr_scr);
+}
+
+
+struct pipe_screen *
+trace_screen_create(struct pipe_screen *screen)
+{
+ struct trace_screen *tr_scr;
+
+ if(!debug_get_bool_option("GALLIUM_TRACE", FALSE))
+ return screen;
+
+ tr_scr = CALLOC_STRUCT(trace_screen);
+ if(!tr_scr)
+ return NULL;
+
+ tr_scr->base.winsys = screen->winsys;
+ tr_scr->base.destroy = trace_screen_destroy;
+ tr_scr->base.get_name = trace_screen_get_name;
+ tr_scr->base.get_vendor = trace_screen_get_vendor;
+ tr_scr->base.get_param = trace_screen_get_param;
+ tr_scr->base.get_paramf = trace_screen_get_paramf;
+ tr_scr->base.is_format_supported = trace_screen_is_format_supported;
+ tr_scr->base.texture_create = trace_screen_texture_create;
+ tr_scr->base.texture_blanket = trace_screen_texture_blanket;
+ tr_scr->base.texture_release = trace_screen_texture_release;
+ tr_scr->base.get_tex_surface = trace_screen_get_tex_surface;
+ tr_scr->base.tex_surface_release = trace_screen_tex_surface_release;
+ tr_scr->base.surface_map = trace_screen_surface_map;
+ tr_scr->base.surface_unmap = trace_screen_surface_unmap;
+
+ tr_scr->screen = screen;
+
+ tr_scr->stream = trace_winsys(screen->winsys)->stream;
+ if(!tr_scr->stream)
+ return NULL;
+
+ /* We don't want to trace the internal pipe calls */
+ screen->winsys = trace_winsys(screen->winsys)->winsys;
+
+ return &tr_scr->base;
+}
diff --git a/src/gallium/drivers/trace/tr_screen.h b/src/gallium/drivers/trace/tr_screen.h
new file mode 100644
index 0000000000..40b844778f
--- /dev/null
+++ b/src/gallium/drivers/trace/tr_screen.h
@@ -0,0 +1,63 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef TR_SCREEN_H_
+#define TR_SCREEN_H_
+
+
+#include "pipe/p_compiler.h"
+#include "pipe/p_debug.h"
+#include "pipe/p_screen.h"
+
+
+struct trace_stream;
+
+
+struct trace_screen
+{
+ struct pipe_screen base;
+
+ struct pipe_screen *screen;
+
+ struct trace_stream *stream;
+};
+
+
+static INLINE struct trace_screen *
+trace_screen(struct pipe_screen *screen)
+{
+ assert(screen);
+ return (struct trace_screen *)screen;
+}
+
+
+
+struct pipe_screen *
+trace_screen_create(struct pipe_screen *screen);
+
+
+#endif /* TR_SCREEN_H_ */
diff --git a/src/gallium/drivers/trace/tr_state.c b/src/gallium/drivers/trace/tr_state.c
new file mode 100644
index 0000000000..9ffe77146d
--- /dev/null
+++ b/src/gallium/drivers/trace/tr_state.c
@@ -0,0 +1,488 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#include "pipe/p_compiler.h"
+#include "tgsi/tgsi_dump.h"
+
+#include "tr_dump.h"
+#include "tr_state.h"
+
+
+void trace_dump_format(struct trace_stream *stream,
+ enum pipe_format format)
+{
+ trace_dump_enum(stream, pf_name(format) );
+}
+
+
+void trace_dump_block(struct trace_stream *stream,
+ const struct pipe_format_block *block)
+{
+ trace_dump_struct_begin(stream, "pipe_format_block");
+ trace_dump_member(stream, uint, block, size);
+ trace_dump_member(stream, uint, block, width);
+ trace_dump_member(stream, uint, block, height);
+ trace_dump_struct_end(stream);
+}
+
+
+void trace_dump_template(struct trace_stream *stream,
+ const struct pipe_texture *templat)
+{
+ assert(templat);
+ if(!templat) {
+ trace_dump_null(stream);
+ return;
+ }
+
+ trace_dump_struct_begin(stream, "pipe_texture");
+
+ trace_dump_member(stream, int, templat, target);
+ trace_dump_member(stream, format, templat, format);
+
+ trace_dump_member_begin(stream, "width");
+ trace_dump_array(stream, uint, templat->width, 1);
+ trace_dump_member_end(stream);
+
+ trace_dump_member_begin(stream, "height");
+ trace_dump_array(stream, uint, templat->height, 1);
+ trace_dump_member_end(stream);
+
+ trace_dump_member_begin(stream, "block");
+ trace_dump_block(stream, &templat->block);
+ trace_dump_member_end(stream);
+
+ trace_dump_member(stream, uint, templat, last_level);
+ trace_dump_member(stream, uint, templat, tex_usage);
+
+ trace_dump_struct_end(stream);
+}
+
+
+void trace_dump_rasterizer_state(struct trace_stream *stream,
+ const struct pipe_rasterizer_state *state)
+{
+ assert(state);
+ if(!state) {
+ trace_dump_null(stream);
+ return;
+ }
+
+ trace_dump_struct_begin(stream, "pipe_rasterizer_state");
+
+ trace_dump_member(stream, bool, state, flatshade);
+ trace_dump_member(stream, bool, state, light_twoside);
+ trace_dump_member(stream, uint, state, front_winding);
+ trace_dump_member(stream, uint, state, cull_mode);
+ trace_dump_member(stream, uint, state, fill_cw);
+ trace_dump_member(stream, uint, state, fill_ccw);
+ trace_dump_member(stream, bool, state, offset_cw);
+ trace_dump_member(stream, bool, state, offset_ccw);
+ trace_dump_member(stream, bool, state, scissor);
+ trace_dump_member(stream, bool, state, poly_smooth);
+ trace_dump_member(stream, bool, state, poly_stipple_enable);
+ trace_dump_member(stream, bool, state, point_smooth);
+ trace_dump_member(stream, bool, state, point_sprite);
+ trace_dump_member(stream, bool, state, point_size_per_vertex);
+ trace_dump_member(stream, bool, state, multisample);
+ trace_dump_member(stream, bool, state, line_smooth);
+ trace_dump_member(stream, bool, state, line_stipple_enable);
+ trace_dump_member(stream, uint, state, line_stipple_factor);
+ trace_dump_member(stream, uint, state, line_stipple_pattern);
+ trace_dump_member(stream, bool, state, line_last_pixel);
+ trace_dump_member(stream, bool, state, bypass_clipping);
+ trace_dump_member(stream, bool, state, bypass_vs);
+ trace_dump_member(stream, bool, state, origin_lower_left);
+ trace_dump_member(stream, bool, state, flatshade_first);
+ trace_dump_member(stream, bool, state, gl_rasterization_rules);
+
+ trace_dump_member(stream, float, state, line_width);
+ trace_dump_member(stream, float, state, point_size);
+ trace_dump_member(stream, float, state, point_size_min);
+ trace_dump_member(stream, float, state, point_size_max);
+ trace_dump_member(stream, float, state, offset_units);
+ trace_dump_member(stream, float, state, offset_scale);
+
+ trace_dump_member_array(stream, uint, state, sprite_coord_mode);
+
+ trace_dump_struct_end(stream);
+}
+
+
+void trace_dump_poly_stipple(struct trace_stream *stream,
+ const struct pipe_poly_stipple *state)
+{
+ assert(state);
+ if(!state) {
+ trace_dump_null(stream);
+ return;
+ }
+
+ trace_dump_struct_begin(stream, "pipe_poly_stipple");
+
+ trace_dump_member_begin(stream, "stipple");
+ trace_dump_bytes(stream,
+ state->stipple,
+ sizeof(state->stipple));
+ trace_dump_member_end(stream);
+
+ trace_dump_struct_end(stream);
+}
+
+
+void trace_dump_viewport_state(struct trace_stream *stream,
+ const struct pipe_viewport_state *state)
+{
+ assert(state);
+ if(!state) {
+ trace_dump_null(stream);
+ return;
+ }
+
+ trace_dump_struct_begin(stream, "pipe_viewport_state");
+
+ trace_dump_member_array(stream, float, state, scale);
+ trace_dump_member_array(stream, float, state, translate);
+
+ trace_dump_struct_end(stream);
+}
+
+
+void trace_dump_scissor_state(struct trace_stream *stream,
+ const struct pipe_scissor_state *state)
+{
+ assert(state);
+ if(!state) {
+ trace_dump_null(stream);
+ return;
+ }
+
+ trace_dump_struct_begin(stream, "pipe_scissor_state");
+
+ trace_dump_member(stream, uint, state, minx);
+ trace_dump_member(stream, uint, state, miny);
+ trace_dump_member(stream, uint, state, maxx);
+ trace_dump_member(stream, uint, state, maxy);
+
+ trace_dump_struct_end(stream);
+}
+
+
+void trace_dump_clip_state(struct trace_stream *stream,
+ const struct pipe_clip_state *state)
+{
+ unsigned i;
+
+ assert(state);
+ if(!state) {
+ trace_dump_null(stream);
+ return;
+ }
+
+ trace_dump_struct_begin(stream, "pipe_scissor_state");
+
+ trace_dump_member_begin(stream, "ucp");
+ trace_dump_array_begin(stream);
+ for(i = 0; i < PIPE_MAX_CLIP_PLANES; ++i)
+ trace_dump_array(stream, float, state->ucp[i], 4);
+ trace_dump_array_end(stream);
+ trace_dump_member_end(stream);
+
+ trace_dump_member(stream, uint, state, nr);
+
+ trace_dump_struct_end(stream);
+}
+
+
+void trace_dump_constant_buffer(struct trace_stream *stream,
+ const struct pipe_constant_buffer *state)
+{
+ assert(state);
+ if(!state) {
+ trace_dump_null(stream);
+ return;
+ }
+
+ trace_dump_struct_begin(stream, "pipe_constant_buffer");
+
+ trace_dump_member(stream, ptr, state, buffer);
+ trace_dump_member(stream, uint, state, size);
+
+ trace_dump_struct_end(stream);
+}
+
+
+void trace_dump_shader_state(struct trace_stream *stream,
+ const struct pipe_shader_state *state)
+{
+ static char str[8192];
+ assert(state);
+ if(!state) {
+ trace_dump_null(stream);
+ return;
+ }
+
+ tgsi_dump_str(state->tokens, 0, str, sizeof(str));
+
+ trace_dump_struct_begin(stream, "pipe_shader_state");
+
+ trace_dump_member_begin(stream, "tokens");
+ trace_dump_string(stream, str);
+ trace_dump_member_end(stream);
+
+ trace_dump_struct_end(stream);
+}
+
+
+void trace_dump_depth_stencil_alpha_state(struct trace_stream *stream,
+ const struct pipe_depth_stencil_alpha_state *state)
+{
+ unsigned i;
+
+ assert(state);
+ if(!state) {
+ trace_dump_null(stream);
+ return;
+ }
+
+ trace_dump_struct_begin(stream, "pipe_depth_stencil_alpha_state");
+
+ trace_dump_member_begin(stream, "depth");
+ trace_dump_struct_begin(stream, "");
+ trace_dump_member(stream, bool, &state->depth, enabled);
+ trace_dump_member(stream, bool, &state->depth, writemask);
+ trace_dump_member(stream, uint, &state->depth, func);
+ trace_dump_member(stream, bool, &state->depth, occlusion_count);
+ trace_dump_struct_end(stream);
+ trace_dump_member_end(stream);
+
+ trace_dump_member_begin(stream, "stencil");
+ trace_dump_array_begin(stream);
+ for(i = 0; i < Elements(state->stencil); ++i) {
+ trace_dump_elem_begin(stream);
+ trace_dump_struct_begin(stream, "");
+ trace_dump_member(stream, bool, &state->stencil[i], enabled);
+ trace_dump_member(stream, uint, &state->stencil[i], func);
+ trace_dump_member(stream, uint, &state->stencil[i], fail_op);
+ trace_dump_member(stream, uint, &state->stencil[i], zpass_op);
+ trace_dump_member(stream, uint, &state->stencil[i], zfail_op);
+ trace_dump_member(stream, uint, &state->stencil[i], ref_value);
+ trace_dump_member(stream, uint, &state->stencil[i], value_mask);
+ trace_dump_member(stream, uint, &state->stencil[i], write_mask);
+ trace_dump_struct_end(stream);
+ trace_dump_elem_end(stream);
+ }
+ trace_dump_array_end(stream);
+ trace_dump_member_end(stream);
+
+ trace_dump_member_begin(stream, "alpha");
+ trace_dump_struct_begin(stream, "");
+ trace_dump_member(stream, bool, &state->alpha, enabled);
+ trace_dump_member(stream, uint, &state->alpha, func);
+ trace_dump_member(stream, float, &state->alpha, ref);
+ trace_dump_struct_end(stream);
+ trace_dump_member_end(stream);
+
+ trace_dump_struct_end(stream);
+}
+
+
+void trace_dump_blend_state(struct trace_stream *stream,
+ const struct pipe_blend_state *state)
+{
+ assert(state);
+ if(!state) {
+ trace_dump_null(stream);
+ return;
+ }
+
+ trace_dump_struct_begin(stream, "pipe_blend_state");
+
+ trace_dump_member(stream, bool, state, blend_enable);
+
+ trace_dump_member(stream, uint, state, rgb_func);
+ trace_dump_member(stream, uint, state, rgb_src_factor);
+ trace_dump_member(stream, uint, state, rgb_dst_factor);
+
+ trace_dump_member(stream, uint, state, alpha_func);
+ trace_dump_member(stream, uint, state, alpha_src_factor);
+ trace_dump_member(stream, uint, state, alpha_dst_factor);
+
+ trace_dump_member(stream, bool, state, logicop_enable);
+ trace_dump_member(stream, uint, state, logicop_func);
+
+ trace_dump_member(stream, uint, state, colormask);
+ trace_dump_member(stream, bool, state, dither);
+
+ trace_dump_struct_end(stream);
+}
+
+
+void trace_dump_blend_color(struct trace_stream *stream,
+ const struct pipe_blend_color *state)
+{
+ assert(state);
+ if(!state) {
+ trace_dump_null(stream);
+ return;
+ }
+
+ trace_dump_struct_begin(stream, "pipe_blend_color");
+
+ trace_dump_member_array(stream, float, state, color);
+
+ trace_dump_struct_end(stream);
+}
+
+
+void trace_dump_framebuffer_state(struct trace_stream *stream,
+ const struct pipe_framebuffer_state *state)
+{
+ trace_dump_struct_begin(stream, "pipe_framebuffer_state");
+
+ trace_dump_member(stream, uint, state, width);
+ trace_dump_member(stream, uint, state, height);
+ trace_dump_member(stream, uint, state, num_cbufs);
+ trace_dump_member_array(stream, ptr, state, cbufs);
+ trace_dump_member(stream, ptr, state, zsbuf);
+
+ trace_dump_struct_end(stream);
+}
+
+
+void trace_dump_sampler_state(struct trace_stream *stream,
+ const struct pipe_sampler_state *state)
+{
+ assert(state);
+ if(!state) {
+ trace_dump_null(stream);
+ return;
+ }
+
+ trace_dump_struct_begin(stream, "pipe_sampler_state");
+
+ trace_dump_member(stream, uint, state, wrap_s);
+ trace_dump_member(stream, uint, state, wrap_t);
+ trace_dump_member(stream, uint, state, wrap_r);
+ trace_dump_member(stream, uint, state, min_img_filter);
+ trace_dump_member(stream, uint, state, min_mip_filter);
+ trace_dump_member(stream, uint, state, mag_img_filter);
+ trace_dump_member(stream, bool, state, compare_mode);
+ trace_dump_member(stream, uint, state, compare_func);
+ trace_dump_member(stream, bool, state, normalized_coords);
+ trace_dump_member(stream, uint, state, prefilter);
+ trace_dump_member(stream, float, state, shadow_ambient);
+ trace_dump_member(stream, float, state, lod_bias);
+ trace_dump_member(stream, float, state, min_lod);
+ trace_dump_member(stream, float, state, max_lod);
+ trace_dump_member_array(stream, float, state, border_color);
+ trace_dump_member(stream, float, state, max_anisotropy);
+
+ trace_dump_struct_end(stream);
+}
+
+
+void trace_dump_surface(struct trace_stream *stream,
+ const struct pipe_surface *state)
+{
+ assert(state);
+ if(!state) {
+ trace_dump_null(stream);
+ return;
+ }
+
+ trace_dump_struct_begin(stream, "pipe_surface");
+
+ trace_dump_member(stream, ptr, state, buffer);
+ trace_dump_member(stream, format, state, format);
+ trace_dump_member(stream, uint, state, status);
+ trace_dump_member(stream, uint, state, clear_value);
+ trace_dump_member(stream, uint, state, width);
+ trace_dump_member(stream, uint, state, height);
+
+ trace_dump_member_begin(stream, "block");
+ trace_dump_block(stream, &state->block);
+ trace_dump_member_end(stream);
+
+ trace_dump_member(stream, uint, state, nblocksx);
+ trace_dump_member(stream, uint, state, nblocksy);
+ trace_dump_member(stream, uint, state, stride);
+ trace_dump_member(stream, uint, state, layout);
+ trace_dump_member(stream, uint, state, offset);
+ trace_dump_member(stream, uint, state, refcount);
+ trace_dump_member(stream, uint, state, usage);
+
+ trace_dump_member(stream, ptr, state, texture);
+ trace_dump_member(stream, uint, state, face);
+ trace_dump_member(stream, uint, state, level);
+ trace_dump_member(stream, uint, state, zslice);
+
+ trace_dump_struct_end(stream);
+}
+
+
+void trace_dump_vertex_buffer(struct trace_stream *stream,
+ const struct pipe_vertex_buffer *state)
+{
+ assert(state);
+ if(!state) {
+ trace_dump_null(stream);
+ return;
+ }
+
+ trace_dump_struct_begin(stream, "pipe_vertex_buffer");
+
+ trace_dump_member(stream, uint, state, pitch);
+ trace_dump_member(stream, uint, state, max_index);
+ trace_dump_member(stream, uint, state, buffer_offset);
+ trace_dump_member(stream, ptr, state, buffer);
+
+ trace_dump_struct_end(stream);
+}
+
+
+void trace_dump_vertex_element(struct trace_stream *stream,
+ const struct pipe_vertex_element *state)
+{
+ assert(state);
+ if(!state) {
+ trace_dump_null(stream);
+ return;
+ }
+
+ trace_dump_struct_begin(stream, "pipe_vertex_element");
+
+ trace_dump_member(stream, uint, state, src_offset);
+
+ trace_dump_member(stream, uint, state, vertex_buffer_index);
+ trace_dump_member(stream, uint, state, nr_components);
+
+ trace_dump_member(stream, format, state, src_format);
+
+ trace_dump_struct_end(stream);
+}
diff --git a/src/gallium/drivers/trace/tr_state.h b/src/gallium/drivers/trace/tr_state.h
new file mode 100644
index 0000000000..c1df63db6a
--- /dev/null
+++ b/src/gallium/drivers/trace/tr_state.h
@@ -0,0 +1,95 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation streams (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef TR_STATE_H
+#define TR_STATE_H
+
+#include "pipe/p_format.h"
+#include "pipe/p_state.h"
+#include "pipe/p_shader_tokens.h"
+
+
+void trace_dump_format(struct trace_stream *stream,
+ enum pipe_format format);
+
+void trace_dump_block(struct trace_stream *stream,
+ const struct pipe_format_block *block);
+
+void trace_dump_template(struct trace_stream *stream,
+ const struct pipe_texture *templat);
+
+
+void trace_dump_rasterizer_state(struct trace_stream *stream,
+ const struct pipe_rasterizer_state *state);
+
+void trace_dump_poly_stipple(struct trace_stream *stream,
+ const struct pipe_poly_stipple *state);
+
+void trace_dump_viewport_state(struct trace_stream *stream,
+ const struct pipe_viewport_state *state);
+
+void trace_dump_scissor_state(struct trace_stream *stream,
+ const struct pipe_scissor_state *state);
+
+void trace_dump_clip_state(struct trace_stream *stream,
+ const struct pipe_clip_state *state);
+
+void trace_dump_constant_buffer(struct trace_stream *stream,
+ const struct pipe_constant_buffer *state);
+
+void trace_dump_token(struct trace_stream *stream,
+ const struct tgsi_token *token);
+
+void trace_dump_shader_state(struct trace_stream *stream,
+ const struct pipe_shader_state *state);
+
+void trace_dump_depth_stencil_alpha_state(struct trace_stream *stream,
+ const struct pipe_depth_stencil_alpha_state *state);
+
+void trace_dump_blend_state(struct trace_stream *stream,
+ const struct pipe_blend_state *state);
+
+void trace_dump_blend_color(struct trace_stream *stream,
+ const struct pipe_blend_color *state);
+
+void trace_dump_framebuffer_state(struct trace_stream *stream,
+ const struct pipe_framebuffer_state *state);
+
+void trace_dump_sampler_state(struct trace_stream *stream,
+ const struct pipe_sampler_state *state);
+
+void trace_dump_surface(struct trace_stream *stream,
+ const struct pipe_surface *state);
+
+void trace_dump_vertex_buffer(struct trace_stream *stream,
+ const struct pipe_vertex_buffer *state);
+
+void trace_dump_vertex_element(struct trace_stream *stream,
+ const struct pipe_vertex_element *state);
+
+
+#endif /* TR_STATE_H */
diff --git a/src/gallium/drivers/trace/tr_stream.c b/src/gallium/drivers/trace/tr_stream.c
new file mode 100644
index 0000000000..14cc257e15
--- /dev/null
+++ b/src/gallium/drivers/trace/tr_stream.c
@@ -0,0 +1,100 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include "pipe/p_config.h"
+
+#if defined(PIPE_OS_LINUX)
+#include <stdio.h>
+#else
+#error Unsupported platform
+#endif
+
+#include "pipe/p_util.h"
+
+#include "tr_stream.h"
+
+
+struct trace_stream
+{
+#if defined(PIPE_OS_LINUX)
+ FILE *file;
+#endif
+};
+
+
+struct trace_stream *
+trace_stream_create(const char *name, const char *ext)
+{
+ struct trace_stream *stream;
+ static unsigned file_no = 0;
+ char filename[1024];
+
+ stream = CALLOC_STRUCT(trace_stream);
+ if(!stream)
+ goto error1;
+
+ snprintf(filename, sizeof(filename), "%s.%u.%s", name, file_no, ext);
+
+#if defined(PIPE_OS_LINUX)
+ stream->file = fopen(filename, "w");
+ if(!stream->file)
+ goto error2;
+#endif
+
+ return stream;
+
+error2:
+ FREE(stream);
+error1:
+ return NULL;
+}
+
+
+boolean
+trace_stream_write(struct trace_stream *stream, const void *data, size_t size)
+{
+ if(!stream)
+ return FALSE;
+
+#if defined(PIPE_OS_LINUX)
+ return fwrite(data, size, 1, stream->file) == size ? TRUE : FALSE;
+#endif
+}
+
+
+void
+trace_stream_close(struct trace_stream *stream)
+{
+ if(!stream)
+ return;
+
+#if defined(PIPE_OS_LINUX)
+ fclose(stream->file);
+#endif
+
+ FREE(stream);
+}
diff --git a/src/gallium/drivers/trace/tr_stream.h b/src/gallium/drivers/trace/tr_stream.h
new file mode 100644
index 0000000000..d50fed2691
--- /dev/null
+++ b/src/gallium/drivers/trace/tr_stream.h
@@ -0,0 +1,52 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation streams (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/**
+ * @file
+ * Cross-platform sequential access stream abstraction.
+ */
+
+#ifndef TR_STREAM_H
+#define TR_STREAM_H
+
+
+#include "pipe/p_compiler.h"
+
+struct trace_stream;
+
+
+struct trace_stream *
+trace_stream_create(const char *name, const char *ext);
+
+boolean
+trace_stream_write(struct trace_stream *stream, const void *data, size_t size);
+
+void
+trace_stream_close(struct trace_stream *stream);
+
+
+#endif /* TR_STREAM_H */
diff --git a/src/gallium/drivers/trace/tr_winsys.c b/src/gallium/drivers/trace/tr_winsys.c
new file mode 100644
index 0000000000..964da5677b
--- /dev/null
+++ b/src/gallium/drivers/trace/tr_winsys.c
@@ -0,0 +1,462 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include "pipe/p_util.h"
+#include "util/u_hash_table.h"
+
+#include "tr_stream.h"
+#include "tr_dump.h"
+#include "tr_state.h"
+#include "tr_winsys.h"
+
+
+static unsigned trace_buffer_hash(void *buffer)
+{
+ return (unsigned)(uintptr_t)buffer;
+}
+
+
+static int trace_buffer_compare(void *buffer1, void *buffer2)
+{
+ return (char *)buffer2 - (char *)buffer1;
+}
+
+
+static const char *
+trace_winsys_get_name(struct pipe_winsys *_winsys)
+{
+ struct trace_winsys *tr_ws = trace_winsys(_winsys);
+ struct trace_stream *stream = tr_ws->stream;
+ struct pipe_winsys *winsys = tr_ws->winsys;
+ const char *result;
+
+ trace_dump_call_begin(stream, "pipe_winsys", "get_name");
+
+ trace_dump_arg(stream, ptr, winsys);
+
+ result = winsys->get_name(winsys);
+
+ trace_dump_ret(stream, string, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static void
+trace_winsys_flush_frontbuffer(struct pipe_winsys *_winsys,
+ struct pipe_surface *surface,
+ void *context_private)
+{
+ struct trace_winsys *tr_ws = trace_winsys(_winsys);
+ struct trace_stream *stream = tr_ws->stream;
+ struct pipe_winsys *winsys = tr_ws->winsys;
+
+ trace_dump_call_begin(stream, "pipe_winsys", "flush_frontbuffer");
+
+ trace_dump_arg(stream, ptr, winsys);
+ trace_dump_arg(stream, ptr, surface);
+ trace_dump_arg(stream, ptr, context_private);
+
+ winsys->flush_frontbuffer(winsys, surface, context_private);
+
+ trace_dump_call_end(stream);
+}
+
+
+static struct pipe_surface *
+trace_winsys_surface_alloc(struct pipe_winsys *_winsys)
+{
+ struct trace_winsys *tr_ws = trace_winsys(_winsys);
+ struct trace_stream *stream = tr_ws->stream;
+ struct pipe_winsys *winsys = tr_ws->winsys;
+ struct pipe_surface *result;
+
+ trace_dump_call_begin(stream, "pipe_winsys", "surface_alloc");
+
+ trace_dump_arg(stream, ptr, winsys);
+
+ result = winsys->surface_alloc(winsys);
+
+ trace_dump_ret(stream, ptr, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static int
+trace_winsys_surface_alloc_storage(struct pipe_winsys *_winsys,
+ struct pipe_surface *surface,
+ unsigned width, unsigned height,
+ enum pipe_format format,
+ unsigned flags,
+ unsigned tex_usage)
+{
+ struct trace_winsys *tr_ws = trace_winsys(_winsys);
+ struct trace_stream *stream = tr_ws->stream;
+ struct pipe_winsys *winsys = tr_ws->winsys;
+ int result;
+
+ trace_dump_call_begin(stream, "pipe_winsys", "surface_alloc_storage");
+
+ trace_dump_arg(stream, ptr, winsys);
+ trace_dump_arg(stream, ptr, surface);
+ trace_dump_arg(stream, uint, width);
+ trace_dump_arg(stream, uint, height);
+ trace_dump_arg(stream, format, format);
+ trace_dump_arg(stream, uint, flags);
+ trace_dump_arg(stream, uint, tex_usage);
+
+ result = winsys->surface_alloc_storage(winsys,
+ surface,
+ width, height,
+ format,
+ flags,
+ tex_usage);
+
+ trace_dump_ret(stream, int, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static void
+trace_winsys_surface_release(struct pipe_winsys *_winsys,
+ struct pipe_surface **psurface)
+{
+ struct trace_winsys *tr_ws = trace_winsys(_winsys);
+ struct trace_stream *stream = tr_ws->stream;
+ struct pipe_winsys *winsys = tr_ws->winsys;
+ struct pipe_surface *surface = *psurface;
+
+ trace_dump_call_begin(stream, "pipe_winsys", "surface_release");
+
+ trace_dump_arg(stream, ptr, winsys);
+ trace_dump_arg(stream, ptr, surface);
+
+ winsys->surface_release(winsys, psurface);
+
+ trace_dump_call_end(stream);
+}
+
+
+static struct pipe_buffer *
+trace_winsys_buffer_create(struct pipe_winsys *_winsys,
+ unsigned alignment,
+ unsigned usage,
+ unsigned size)
+{
+ struct trace_winsys *tr_ws = trace_winsys(_winsys);
+ struct trace_stream *stream = tr_ws->stream;
+ struct pipe_winsys *winsys = tr_ws->winsys;
+ struct pipe_buffer *result;
+
+ trace_dump_call_begin(stream, "pipe_winsys", "buffer_create");
+
+ trace_dump_arg(stream, ptr, winsys);
+ trace_dump_arg(stream, uint, alignment);
+ trace_dump_arg(stream, uint, usage);
+ trace_dump_arg(stream, uint, size);
+
+ result = winsys->buffer_create(winsys, alignment, usage, size);
+
+ trace_dump_ret(stream, ptr, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static struct pipe_buffer *
+trace_winsys_user_buffer_create(struct pipe_winsys *_winsys,
+ void *ptr,
+ unsigned bytes)
+{
+ struct trace_winsys *tr_ws = trace_winsys(_winsys);
+ struct trace_stream *stream = tr_ws->stream;
+ struct pipe_winsys *winsys = tr_ws->winsys;
+ struct pipe_buffer *result;
+
+ trace_dump_call_begin(stream, "pipe_winsys", "user_buffer_create");
+
+ trace_dump_arg(stream, ptr, winsys);
+ trace_dump_arg(stream, ptr, ptr);
+ trace_dump_arg(stream, uint, bytes);
+
+ result = winsys->user_buffer_create(winsys, ptr, bytes);
+
+ trace_dump_ret(stream, ptr, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static void *
+trace_winsys_buffer_map(struct pipe_winsys *_winsys,
+ struct pipe_buffer *buffer,
+ unsigned usage)
+{
+ struct trace_winsys *tr_ws = trace_winsys(_winsys);
+ struct trace_stream *stream = tr_ws->stream;
+ struct pipe_winsys *winsys = tr_ws->winsys;
+ void *result;
+
+ trace_dump_call_begin(stream, "pipe_winsys", "buffer_map");
+
+ trace_dump_arg(stream, ptr, winsys);
+ trace_dump_arg(stream, ptr, buffer);
+ trace_dump_arg(stream, uint, usage);
+
+ result = winsys->buffer_map(winsys, buffer, usage);
+
+ trace_dump_ret(stream, ptr, result);
+
+ trace_dump_call_end(stream);
+
+ if(result) {
+ if(usage & PIPE_BUFFER_USAGE_CPU_WRITE) {
+ assert(!hash_table_get(tr_ws->buffer_maps, buffer));
+ hash_table_set(tr_ws->buffer_maps, buffer, result);
+ }
+ }
+
+ return result;
+}
+
+
+static void
+trace_winsys_buffer_unmap(struct pipe_winsys *_winsys,
+ struct pipe_buffer *buffer)
+{
+ struct trace_winsys *tr_ws = trace_winsys(_winsys);
+ struct trace_stream *stream = tr_ws->stream;
+ struct pipe_winsys *winsys = tr_ws->winsys;
+ const void *map;
+
+ map = hash_table_get(tr_ws->buffer_maps, buffer);
+ if(map) {
+ trace_dump_call_begin(stream, "", "memcpy");
+
+ trace_dump_arg_begin(stream, "dst");
+ trace_dump_ptr(stream, map);
+ trace_dump_arg_end(stream);
+
+ trace_dump_arg_begin(stream, "src");
+ trace_dump_bytes(stream, map, buffer->size);
+ trace_dump_arg_end(stream);
+
+ trace_dump_arg_begin(stream, "size");
+ trace_dump_uint(stream, buffer->size);
+ trace_dump_arg_end(stream);
+
+ trace_dump_call_end(stream);
+
+ winsys->buffer_unmap(winsys, buffer);
+
+ hash_table_remove(tr_ws->buffer_maps, buffer);
+ }
+
+ trace_dump_call_begin(stream, "pipe_winsys", "buffer_unmap");
+
+ trace_dump_arg(stream, ptr, winsys);
+ trace_dump_arg(stream, ptr, buffer);
+
+ winsys->buffer_unmap(winsys, buffer);
+
+ trace_dump_call_end(stream);
+}
+
+
+static void
+trace_winsys_buffer_destroy(struct pipe_winsys *_winsys,
+ struct pipe_buffer *buffer)
+{
+ struct trace_winsys *tr_ws = trace_winsys(_winsys);
+ struct trace_stream *stream = tr_ws->stream;
+ struct pipe_winsys *winsys = tr_ws->winsys;
+
+ trace_dump_call_begin(stream, "pipe_winsys", "buffer_destroy");
+
+ trace_dump_arg(stream, ptr, winsys);
+ trace_dump_arg(stream, ptr, buffer);
+
+ winsys->buffer_destroy(winsys, buffer);
+
+ trace_dump_call_end(stream);
+}
+
+
+static void
+trace_winsys_fence_reference(struct pipe_winsys *_winsys,
+ struct pipe_fence_handle **pdst,
+ struct pipe_fence_handle *src)
+{
+ struct trace_winsys *tr_ws = trace_winsys(_winsys);
+ struct trace_stream *stream = tr_ws->stream;
+ struct pipe_winsys *winsys = tr_ws->winsys;
+ struct pipe_fence_handle *dst = *pdst;
+
+ trace_dump_call_begin(stream, "pipe_winsys", "fence_reference");
+
+ trace_dump_arg(stream, ptr, winsys);
+ trace_dump_arg(stream, ptr, dst);
+ trace_dump_arg(stream, ptr, src);
+
+ winsys->fence_reference(winsys, pdst, src);
+
+ trace_dump_call_end(stream);
+}
+
+
+static int
+trace_winsys_fence_signalled(struct pipe_winsys *_winsys,
+ struct pipe_fence_handle *fence,
+ unsigned flag)
+{
+ struct trace_winsys *tr_ws = trace_winsys(_winsys);
+ struct trace_stream *stream = tr_ws->stream;
+ struct pipe_winsys *winsys = tr_ws->winsys;
+ int result;
+
+ trace_dump_call_begin(stream, "pipe_winsys", "fence_signalled");
+
+ trace_dump_arg(stream, ptr, winsys);
+ trace_dump_arg(stream, ptr, fence);
+ trace_dump_arg(stream, uint, flag);
+
+ result = winsys->fence_signalled(winsys, fence, flag);
+
+ trace_dump_ret(stream, int, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static int
+trace_winsys_fence_finish(struct pipe_winsys *_winsys,
+ struct pipe_fence_handle *fence,
+ unsigned flag)
+{
+ struct trace_winsys *tr_ws = trace_winsys(_winsys);
+ struct trace_stream *stream = tr_ws->stream;
+ struct pipe_winsys *winsys = tr_ws->winsys;
+ int result;
+
+ trace_dump_call_begin(stream, "pipe_winsys", "fence_finish");
+
+ trace_dump_arg(stream, ptr, winsys);
+ trace_dump_arg(stream, ptr, fence);
+ trace_dump_arg(stream, uint, flag);
+
+ result = winsys->fence_finish(winsys, fence, flag);
+
+ trace_dump_ret(stream, int, result);
+
+ trace_dump_call_end(stream);
+
+ return result;
+}
+
+
+static void
+trace_winsys_destroy(struct pipe_winsys *_winsys)
+{
+ struct trace_winsys *tr_ws = trace_winsys(_winsys);
+ struct trace_stream *stream = tr_ws->stream;
+ struct pipe_winsys *winsys = tr_ws->winsys;
+
+ trace_dump_call_begin(stream, "pipe_winsys", "destroy");
+
+ trace_dump_arg(stream, ptr, winsys);
+
+ winsys->destroy(winsys);
+
+ trace_dump_call_end(stream);
+
+ trace_dump_trace_end(stream);
+
+ hash_table_destroy(tr_ws->buffer_maps);
+
+ trace_stream_close(tr_ws->stream);
+
+ FREE(tr_ws);
+}
+
+
+struct pipe_winsys *
+trace_winsys_create(struct pipe_winsys *winsys)
+{
+ struct trace_winsys *tr_ws;
+
+ if(!debug_get_bool_option("GALLIUM_TRACE", FALSE))
+ return winsys;
+
+ tr_ws = CALLOC_STRUCT(trace_winsys);
+ if(!tr_ws)
+ return NULL;
+
+ tr_ws->base.destroy = trace_winsys_destroy;
+ tr_ws->base.get_name = trace_winsys_get_name;
+ tr_ws->base.flush_frontbuffer = trace_winsys_flush_frontbuffer;
+ tr_ws->base.surface_alloc = trace_winsys_surface_alloc;
+ tr_ws->base.surface_alloc_storage = trace_winsys_surface_alloc_storage;
+ tr_ws->base.surface_release = trace_winsys_surface_release;
+ tr_ws->base.buffer_create = trace_winsys_buffer_create;
+ tr_ws->base.user_buffer_create = trace_winsys_user_buffer_create;
+ tr_ws->base.buffer_map = trace_winsys_buffer_map;
+ tr_ws->base.buffer_unmap = trace_winsys_buffer_unmap;
+ tr_ws->base.buffer_destroy = trace_winsys_buffer_destroy;
+ tr_ws->base.fence_reference = trace_winsys_fence_reference;
+ tr_ws->base.fence_signalled = trace_winsys_fence_signalled;
+ tr_ws->base.fence_finish = trace_winsys_fence_finish;
+
+ tr_ws->winsys = winsys;
+
+ tr_ws->stream = trace_stream_create("gallium", "trace");
+ if(!tr_ws->stream)
+ return NULL;
+
+ tr_ws->buffer_maps = hash_table_create(trace_buffer_hash,
+ trace_buffer_compare);
+ if(!tr_ws->buffer_maps)
+ return NULL;
+
+
+ trace_dump_trace_begin(tr_ws->stream, 0);
+
+ return &tr_ws->base;
+}
diff --git a/src/gallium/drivers/trace/tr_winsys.h b/src/gallium/drivers/trace/tr_winsys.h
new file mode 100644
index 0000000000..a3576da867
--- /dev/null
+++ b/src/gallium/drivers/trace/tr_winsys.h
@@ -0,0 +1,66 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef TR_WINSYS_H_
+#define TR_WINSYS_H_
+
+
+#include "pipe/p_compiler.h"
+#include "pipe/p_debug.h"
+#include "pipe/p_winsys.h"
+
+
+struct hash_table;
+struct trace_stream;
+
+
+struct trace_winsys
+{
+ struct pipe_winsys base;
+
+ struct pipe_winsys *winsys;
+
+ struct trace_stream *stream;
+
+ struct hash_table *buffer_maps;
+};
+
+
+static INLINE struct trace_winsys *
+trace_winsys(struct pipe_winsys *winsys)
+{
+ assert(winsys);
+ return (struct trace_winsys *)winsys;
+}
+
+
+
+struct pipe_winsys *
+trace_winsys_create(struct pipe_winsys *winsys);
+
+
+#endif /* TR_WINSYS_H_ */
diff --git a/src/gallium/drivers/trace/trace.xsl b/src/gallium/drivers/trace/trace.xsl
new file mode 100644
index 0000000000..9cd621e7ab
--- /dev/null
+++ b/src/gallium/drivers/trace/trace.xsl
@@ -0,0 +1,185 @@
+<?xml version="1.0"?>
+
+<!--
+
+Copyright 2008 Tungsten Graphics, Inc.
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as published
+by the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+!-->
+
+<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+ <xsl:output method="html" />
+
+ <xsl:strip-space elements="*" />
+
+ <xsl:template match="/trace">
+ <html>
+ <head>
+ <title>Gallium Trace</title>
+ </head>
+ <style>
+ body {
+ font-family: verdana, sans-serif;
+ font-size: 11px;
+ font-weight: normal;
+ text-align : left;
+ }
+
+ .fun {
+ font-weight: bold;
+ }
+
+ .var {
+ font-style: italic;
+ }
+
+ .typ {
+ display: none;
+ }
+
+ .lit {
+ color: #0000ff;
+ }
+
+ .ptr {
+ color: #008000;
+ }
+ </style>
+ <body>
+ <ol class="calls">
+ <xsl:apply-templates/>
+ </ol>
+ </body>
+ </html>
+ </xsl:template>
+
+ <xsl:template match="call">
+ <li>
+ <span class="fun">
+ <xsl:value-of select="@class"/>
+ <xsl:text>::</xsl:text>
+ <xsl:value-of select="@method"/>
+ </span>
+ <xsl:text>(</xsl:text>
+ <xsl:apply-templates select="arg"/>
+ <xsl:text>)</xsl:text>
+ <xsl:apply-templates select="ret"/>
+ </li>
+ </xsl:template>
+
+ <xsl:template match="arg|member">
+ <xsl:apply-templates select="@name"/>
+ <xsl:text> = </xsl:text>
+ <xsl:apply-templates />
+ <xsl:if test="position() != last()">
+ <xsl:text>, </xsl:text>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match="ret">
+ <xsl:text> = </xsl:text>
+ <xsl:apply-templates />
+ </xsl:template>
+
+ <xsl:template match="bool|int|uint|float|enum">
+ <span class="lit">
+ <xsl:value-of select="text()"/>
+ </span>
+ </xsl:template>
+
+ <xsl:template match="bytes">
+ <span class="lit">
+ <xsl:text>...</xsl:text>
+ </span>
+ </xsl:template>
+
+ <xsl:template match="string">
+ <span class="lit">
+ <xsl:text>"</xsl:text>
+ <xsl:call-template name="break">
+ <xsl:with-param name="text" select="text()"/>
+ </xsl:call-template>
+ <xsl:text>"</xsl:text>
+ </span>
+ </xsl:template>
+
+ <xsl:template match="array|struct">
+ <xsl:text>{</xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>}</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="elem">
+ <xsl:apply-templates />
+ <xsl:if test="position() != last()">
+ <xsl:text>, </xsl:text>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match="null">
+ <span class="ptr">
+ <xsl:text>NULL</xsl:text>
+ </span>
+ </xsl:template>
+
+ <xsl:template match="ptr">
+ <span class="ptr">
+ <xsl:value-of select="text()"/>
+ </span>
+ </xsl:template>
+
+ <xsl:template match="@name">
+ <span class="var">
+ <xsl:value-of select="."/>
+ </span>
+ </xsl:template>
+
+ <xsl:template name="break">
+ <xsl:param name="text" select="."/>
+ <xsl:choose>
+ <xsl:when test="contains($text, '&#xa;')">
+ <xsl:value-of select="substring-before($text, '&#xa;')"/>
+ <br/>
+ <xsl:call-template name="break">
+ <xsl:with-param name="text" select="substring-after($text, '&#xa;')"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$text"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template name="replace">
+ <xsl:param name="text"/>
+ <xsl:param name="from"/>
+ <xsl:param name="to"/>
+ <xsl:choose>
+ <xsl:when test="contains($text,$from)">
+ <xsl:value-of select="concat(substring-before($text,$from),$to)"/>
+ <xsl:call-template name="replace">
+ <xsl:with-param name="text" select="substring-after($text,$from)"/>
+ <xsl:with-param name="from" select="$from"/>
+ <xsl:with-param name="to" select="$to"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$text"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+</xsl:transform>