diff options
Diffstat (limited to 'src/gallium/drivers/trace')
-rw-r--r-- | src/gallium/drivers/trace/Makefile | 8 | ||||
-rw-r--r-- | src/gallium/drivers/trace/SConscript | 4 | ||||
-rw-r--r-- | src/gallium/drivers/trace/tr_buffer.c | 70 | ||||
-rw-r--r-- | src/gallium/drivers/trace/tr_buffer.h (renamed from src/gallium/drivers/trace/tr_winsys.h) | 56 | ||||
-rw-r--r-- | src/gallium/drivers/trace/tr_context.c | 210 | ||||
-rw-r--r-- | src/gallium/drivers/trace/tr_context.h | 6 | ||||
-rw-r--r-- | src/gallium/drivers/trace/tr_dump.c | 117 | ||||
-rw-r--r-- | src/gallium/drivers/trace/tr_dump.h | 13 | ||||
-rw-r--r-- | src/gallium/drivers/trace/tr_screen.c | 777 | ||||
-rw-r--r-- | src/gallium/drivers/trace/tr_screen.h | 17 | ||||
-rw-r--r-- | src/gallium/drivers/trace/tr_state.c | 76 | ||||
-rw-r--r-- | src/gallium/drivers/trace/tr_state.h | 2 | ||||
-rw-r--r-- | src/gallium/drivers/trace/tr_texture.c | 80 | ||||
-rw-r--r-- | src/gallium/drivers/trace/tr_texture.h | 42 | ||||
-rw-r--r-- | src/gallium/drivers/trace/tr_winsys.c | 450 |
15 files changed, 1102 insertions, 826 deletions
diff --git a/src/gallium/drivers/trace/Makefile b/src/gallium/drivers/trace/Makefile index 3859b8acb06..e087db169aa 100644 --- a/src/gallium/drivers/trace/Makefile +++ b/src/gallium/drivers/trace/Makefile @@ -4,15 +4,11 @@ include $(TOP)/configs/current LIBNAME = trace C_SOURCES = \ + tr_buffer.c \ tr_context.c \ tr_dump.c \ tr_screen.c \ tr_state.c \ - tr_texture.c \ - tr_winsys.c - + tr_texture.c include ../../Makefile.template - -symlinks: - diff --git a/src/gallium/drivers/trace/SConscript b/src/gallium/drivers/trace/SConscript index 0a6bfb8f4c7..4215215d1a1 100644 --- a/src/gallium/drivers/trace/SConscript +++ b/src/gallium/drivers/trace/SConscript @@ -5,12 +5,12 @@ env = env.Clone() trace = env.ConvenienceLibrary( target = 'trace', source = [ + 'tr_buffer.c', 'tr_context.c', 'tr_dump.c', 'tr_screen.c', 'tr_state.c', 'tr_texture.c', - 'tr_winsys.c', ]) -Export('trace')
\ No newline at end of file +Export('trace') diff --git a/src/gallium/drivers/trace/tr_buffer.c b/src/gallium/drivers/trace/tr_buffer.c new file mode 100644 index 00000000000..6ffce1660ec --- /dev/null +++ b/src/gallium/drivers/trace/tr_buffer.c @@ -0,0 +1,70 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * 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 "util/u_memory.h" + +#include "tr_buffer.h" + + +struct pipe_buffer * +trace_buffer_create(struct trace_screen *tr_scr, + struct pipe_buffer *buffer) +{ + struct trace_buffer *tr_buf; + + if(!buffer) + goto error; + + assert(buffer->screen == tr_scr->screen); + + tr_buf = CALLOC_STRUCT(trace_buffer); + if(!tr_buf) + goto error; + + memcpy(&tr_buf->base, buffer, sizeof(struct pipe_buffer)); + + pipe_reference_init(&tr_buf->base.reference, 1); + tr_buf->base.screen = &tr_scr->base; + tr_buf->buffer = buffer; + + return &tr_buf->base; + +error: + pipe_buffer_reference(&buffer, NULL); + return NULL; +} + + +void +trace_buffer_destroy(struct trace_screen *tr_scr, + struct pipe_buffer *buffer) +{ + struct trace_buffer *tr_buf = trace_buffer(tr_scr, buffer); + pipe_buffer_reference(&tr_buf->buffer, NULL); + FREE(tr_buf); +} diff --git a/src/gallium/drivers/trace/tr_winsys.h b/src/gallium/drivers/trace/tr_buffer.h index 0fd2a405569..e9e4d354dad 100644 --- a/src/gallium/drivers/trace/tr_winsys.h +++ b/src/gallium/drivers/trace/tr_buffer.h @@ -1,6 +1,6 @@ /************************************************************************** * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2009 VMware, Inc. * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -25,52 +25,46 @@ * **************************************************************************/ -#ifndef TR_WINSYS_H_ -#define TR_WINSYS_H_ +#ifndef TR_BUFFER_H_ +#define TR_BUFFER_H_ #include "pipe/p_compiler.h" -#include "pipe/p_debug.h" -#include "pipe/internal/p_winsys_screen.h" +#include "pipe/p_state.h" +#include "tr_screen.h" -/** - * It often happens that new data is written directly to the user buffers - * without mapping/unmapping. This flag marks user buffers, so that their - * contents can be dumpped before being used by the pipe context. - */ -#define TRACE_BUFFER_USAGE_USER (1 << 31) +struct trace_buffer +{ + struct pipe_buffer base; -struct hash_table; - + struct pipe_buffer *buffer; -struct trace_winsys -{ - struct pipe_winsys base; - - struct pipe_winsys *winsys; - - struct hash_table *buffer_maps; + void *map; + boolean range_flushed; }; -static INLINE struct trace_winsys * -trace_winsys(struct pipe_winsys *winsys) +static INLINE struct trace_buffer * +trace_buffer(struct trace_screen *tr_scr, + struct pipe_buffer *buffer) { - assert(winsys); - return (struct trace_winsys *)winsys; + if(!buffer) + return NULL; + assert(tr_scr); + assert(buffer->screen == &tr_scr->base); + return (struct trace_buffer *)buffer; } - -struct pipe_winsys * -trace_winsys_create(struct pipe_winsys *winsys); - +struct pipe_buffer * +trace_buffer_create(struct trace_screen *tr_scr, + struct pipe_buffer *buffer); void -trace_winsys_user_buffer_update(struct pipe_winsys *winsys, - struct pipe_buffer *buffer); +trace_buffer_destroy(struct trace_screen *tr_scr, + struct pipe_buffer *buffer); -#endif /* TR_WINSYS_H_ */ +#endif diff --git a/src/gallium/drivers/trace/tr_context.c b/src/gallium/drivers/trace/tr_context.c index ec8be27077f..c8949729047 100644 --- a/src/gallium/drivers/trace/tr_context.c +++ b/src/gallium/drivers/trace/tr_context.c @@ -30,48 +30,66 @@ #include "tr_dump.h" #include "tr_state.h" +#include "tr_buffer.h" #include "tr_screen.h" #include "tr_texture.h" -#include "tr_winsys.h" #include "tr_context.h" -static INLINE struct pipe_texture * +static INLINE struct pipe_buffer * +trace_buffer_unwrap(struct trace_context *tr_ctx, + struct pipe_buffer *buffer) +{ + struct trace_screen *tr_scr = trace_screen(tr_ctx->base.screen); + struct trace_buffer *tr_buf; + + if(!buffer) + return NULL; + + tr_buf = trace_buffer(tr_scr, buffer); + + assert(tr_buf->buffer); + assert(tr_buf->buffer->screen == tr_scr->screen); + return tr_buf->buffer; +} + + +static INLINE struct pipe_texture * trace_texture_unwrap(struct trace_context *tr_ctx, struct pipe_texture *texture) { - struct trace_screen *tr_scr = trace_screen(tr_ctx->base.screen); + struct trace_screen *tr_scr = trace_screen(tr_ctx->base.screen); struct trace_texture *tr_tex; - + if(!texture) return NULL; - + tr_tex = trace_texture(tr_scr, texture); - + assert(tr_tex->texture); assert(tr_tex->texture->screen == tr_scr->screen); return tr_tex->texture; } -static INLINE struct pipe_surface * +static INLINE struct pipe_surface * trace_surface_unwrap(struct trace_context *tr_ctx, struct pipe_surface *surface) { - struct trace_screen *tr_scr = trace_screen(tr_ctx->base.screen); + struct trace_screen *tr_scr = trace_screen(tr_ctx->base.screen); struct trace_texture *tr_tex; struct trace_surface *tr_surf; - + if(!surface) return NULL; assert(surface->texture); if(!surface->texture) return surface; - + tr_tex = trace_texture(tr_scr, surface->texture); tr_surf = trace_surface(tr_tex, surface); - + assert(tr_surf->surface); assert(tr_surf->surface->texture->screen == tr_scr->screen); return tr_surf->surface; @@ -86,7 +104,7 @@ trace_context_set_edgeflags(struct pipe_context *_pipe, struct pipe_context *pipe = tr_ctx->pipe; trace_dump_call_begin("pipe_context", "set_edgeflags"); - + trace_dump_arg(ptr, pipe); /* FIXME: we don't know how big this array is */ trace_dump_arg(ptr, bitfield); @@ -115,24 +133,27 @@ trace_context_draw_arrays(struct pipe_context *_pipe, result = pipe->draw_arrays(pipe, mode, start, count);; trace_dump_ret(bool, result); - + trace_dump_call_end(); - + return result; } static INLINE boolean trace_context_draw_elements(struct pipe_context *_pipe, - struct pipe_buffer *indexBuffer, + struct pipe_buffer *_indexBuffer, unsigned indexSize, unsigned mode, unsigned start, unsigned count) { + struct trace_screen *tr_scr = trace_screen(_pipe->screen); struct trace_context *tr_ctx = trace_context(_pipe); + struct trace_buffer *tr_buf = trace_buffer(tr_scr, _indexBuffer); struct pipe_context *pipe = tr_ctx->pipe; + struct pipe_buffer *indexBuffer = tr_buf->buffer; boolean result; - trace_winsys_user_buffer_update(_pipe->winsys, indexBuffer); + trace_screen_user_buffer_update(_pipe->screen, indexBuffer); trace_dump_call_begin("pipe_context", "draw_elements"); @@ -146,28 +167,31 @@ trace_context_draw_elements(struct pipe_context *_pipe, result = pipe->draw_elements(pipe, indexBuffer, indexSize, mode, start, count);; trace_dump_ret(bool, result); - + trace_dump_call_end(); - + return result; } static INLINE boolean trace_context_draw_range_elements(struct pipe_context *_pipe, - struct pipe_buffer *indexBuffer, + struct pipe_buffer *_indexBuffer, unsigned indexSize, unsigned minIndex, unsigned maxIndex, - unsigned mode, - unsigned start, + unsigned mode, + unsigned start, unsigned count) { + struct trace_screen *tr_scr = trace_screen(_pipe->screen); struct trace_context *tr_ctx = trace_context(_pipe); + struct trace_buffer *tr_buf = trace_buffer(tr_scr, _indexBuffer); struct pipe_context *pipe = tr_ctx->pipe; + struct pipe_buffer *indexBuffer = tr_buf->buffer; boolean result; - trace_winsys_user_buffer_update(_pipe->winsys, indexBuffer); + trace_screen_user_buffer_update(_pipe->screen, indexBuffer); trace_dump_call_begin("pipe_context", "draw_range_elements"); @@ -180,15 +204,15 @@ trace_context_draw_range_elements(struct pipe_context *_pipe, trace_dump_arg(uint, start); trace_dump_arg(uint, count); - result = pipe->draw_range_elements(pipe, - indexBuffer, - indexSize, minIndex, maxIndex, + result = pipe->draw_range_elements(pipe, + indexBuffer, + indexSize, minIndex, maxIndex, mode, start, count); - + trace_dump_ret(bool, result); - + trace_dump_call_end(); - + return result; } @@ -209,9 +233,9 @@ trace_context_create_query(struct pipe_context *_pipe, result = pipe->create_query(pipe, query_type);; trace_dump_ret(ptr, result); - + trace_dump_call_end(); - + return result; } @@ -235,7 +259,7 @@ trace_context_destroy_query(struct pipe_context *_pipe, static INLINE void -trace_context_begin_query(struct pipe_context *_pipe, +trace_context_begin_query(struct pipe_context *_pipe, struct pipe_query *query) { struct trace_context *tr_ctx = trace_context(_pipe); @@ -253,7 +277,7 @@ trace_context_begin_query(struct pipe_context *_pipe, static INLINE void -trace_context_end_query(struct pipe_context *_pipe, +trace_context_end_query(struct pipe_context *_pipe, struct pipe_query *query) { struct trace_context *tr_ctx = trace_context(_pipe); @@ -271,7 +295,7 @@ trace_context_end_query(struct pipe_context *_pipe, static INLINE boolean -trace_context_get_query_result(struct pipe_context *_pipe, +trace_context_get_query_result(struct pipe_context *_pipe, struct pipe_query *query, boolean wait, uint64_t *presult) @@ -290,9 +314,9 @@ trace_context_get_query_result(struct pipe_context *_pipe, trace_dump_arg(uint, result); trace_dump_ret(bool, _result); - + trace_dump_call_end(); - + return _result; } @@ -315,13 +339,13 @@ trace_context_create_blend_state(struct pipe_context *_pipe, trace_dump_ret(ptr, result); trace_dump_call_end(); - + return result; } static INLINE void -trace_context_bind_blend_state(struct pipe_context *_pipe, +trace_context_bind_blend_state(struct pipe_context *_pipe, void *state) { struct trace_context *tr_ctx = trace_context(_pipe); @@ -339,7 +363,7 @@ trace_context_bind_blend_state(struct pipe_context *_pipe, static INLINE void -trace_context_delete_blend_state(struct pipe_context *_pipe, +trace_context_delete_blend_state(struct pipe_context *_pipe, void *state) { struct trace_context *tr_ctx = trace_context(_pipe); @@ -372,15 +396,15 @@ trace_context_create_sampler_state(struct pipe_context *_pipe, result = pipe->create_sampler_state(pipe, state);; trace_dump_ret(ptr, result); - + trace_dump_call_end(); - + return result; } static INLINE void -trace_context_bind_sampler_states(struct pipe_context *_pipe, +trace_context_bind_sampler_states(struct pipe_context *_pipe, unsigned num_states, void **states) { struct trace_context *tr_ctx = trace_context(_pipe); @@ -399,7 +423,7 @@ trace_context_bind_sampler_states(struct pipe_context *_pipe, static INLINE void -trace_context_delete_sampler_state(struct pipe_context *_pipe, +trace_context_delete_sampler_state(struct pipe_context *_pipe, void *state) { struct trace_context *tr_ctx = trace_context(_pipe); @@ -432,15 +456,15 @@ trace_context_create_rasterizer_state(struct pipe_context *_pipe, result = pipe->create_rasterizer_state(pipe, state);; trace_dump_ret(ptr, result); - + trace_dump_call_end(); - + return result; } static INLINE void -trace_context_bind_rasterizer_state(struct pipe_context *_pipe, +trace_context_bind_rasterizer_state(struct pipe_context *_pipe, void *state) { struct trace_context *tr_ctx = trace_context(_pipe); @@ -458,7 +482,7 @@ trace_context_bind_rasterizer_state(struct pipe_context *_pipe, static INLINE void -trace_context_delete_rasterizer_state(struct pipe_context *_pipe, +trace_context_delete_rasterizer_state(struct pipe_context *_pipe, void *state) { struct trace_context *tr_ctx = trace_context(_pipe); @@ -489,17 +513,17 @@ trace_context_create_depth_stencil_alpha_state(struct pipe_context *_pipe, trace_dump_arg(ptr, pipe); trace_dump_arg(depth_stencil_alpha_state, state); - + trace_dump_ret(ptr, result); trace_dump_call_end(); - + return result; } static INLINE void -trace_context_bind_depth_stencil_alpha_state(struct pipe_context *_pipe, +trace_context_bind_depth_stencil_alpha_state(struct pipe_context *_pipe, void *state) { struct trace_context *tr_ctx = trace_context(_pipe); @@ -517,7 +541,7 @@ trace_context_bind_depth_stencil_alpha_state(struct pipe_context *_pipe, static INLINE void -trace_context_delete_depth_stencil_alpha_state(struct pipe_context *_pipe, +trace_context_delete_depth_stencil_alpha_state(struct pipe_context *_pipe, void *state) { struct trace_context *tr_ctx = trace_context(_pipe); @@ -550,15 +574,15 @@ trace_context_create_fs_state(struct pipe_context *_pipe, result = pipe->create_fs_state(pipe, state);; trace_dump_ret(ptr, result); - + trace_dump_call_end(); - + return result; } static INLINE void -trace_context_bind_fs_state(struct pipe_context *_pipe, +trace_context_bind_fs_state(struct pipe_context *_pipe, void *state) { struct trace_context *tr_ctx = trace_context(_pipe); @@ -576,7 +600,7 @@ trace_context_bind_fs_state(struct pipe_context *_pipe, static INLINE void -trace_context_delete_fs_state(struct pipe_context *_pipe, +trace_context_delete_fs_state(struct pipe_context *_pipe, void *state) { struct trace_context *tr_ctx = trace_context(_pipe); @@ -609,15 +633,15 @@ trace_context_create_vs_state(struct pipe_context *_pipe, result = pipe->create_vs_state(pipe, state);; trace_dump_ret(ptr, result); - + trace_dump_call_end(); - + return result; } static INLINE void -trace_context_bind_vs_state(struct pipe_context *_pipe, +trace_context_bind_vs_state(struct pipe_context *_pipe, void *state) { struct trace_context *tr_ctx = trace_context(_pipe); @@ -635,7 +659,7 @@ trace_context_bind_vs_state(struct pipe_context *_pipe, static INLINE void -trace_context_delete_vs_state(struct pipe_context *_pipe, +trace_context_delete_vs_state(struct pipe_context *_pipe, void *state) { struct trace_context *tr_ctx = trace_context(_pipe); @@ -696,8 +720,9 @@ trace_context_set_constant_buffer(struct pipe_context *_pipe, struct trace_context *tr_ctx = trace_context(_pipe); struct pipe_context *pipe = tr_ctx->pipe; - trace_winsys_user_buffer_update(_pipe->winsys, (struct pipe_buffer *)buffer); - + if (buffer) + trace_screen_user_buffer_update(_pipe->screen, buffer->buffer); + trace_dump_call_begin("pipe_context", "set_constant_buffer"); trace_dump_arg(ptr, pipe); @@ -705,7 +730,13 @@ trace_context_set_constant_buffer(struct pipe_context *_pipe, trace_dump_arg(uint, index); trace_dump_arg(constant_buffer, buffer); - pipe->set_constant_buffer(pipe, shader, index, buffer);; + if (buffer) { + struct pipe_constant_buffer _buffer; + _buffer.buffer = trace_buffer_unwrap(tr_ctx, buffer->buffer); + pipe->set_constant_buffer(pipe, shader, index, &_buffer); + } else { + pipe->set_constant_buffer(pipe, shader, index, buffer); + } trace_dump_call_end(); } @@ -719,7 +750,7 @@ trace_context_set_framebuffer_state(struct pipe_context *_pipe, struct pipe_context *pipe = tr_ctx->pipe; struct pipe_framebuffer_state unwrapped_state; unsigned i; - + /* Unwrap the input state */ memcpy(&unwrapped_state, state, sizeof(unwrapped_state)); for(i = 0; i < state->nr_cbufs; ++i) @@ -728,7 +759,7 @@ trace_context_set_framebuffer_state(struct pipe_context *_pipe, unwrapped_state.cbufs[i] = NULL; unwrapped_state.zsbuf = trace_surface_unwrap(tr_ctx, state->zsbuf); state = &unwrapped_state; - + trace_dump_call_begin("pipe_context", "set_framebuffer_state"); trace_dump_arg(ptr, pipe); @@ -803,7 +834,7 @@ trace_context_set_sampler_textures(struct pipe_context *_pipe, struct pipe_context *pipe = tr_ctx->pipe; struct pipe_texture *unwrapped_textures[PIPE_MAX_SAMPLERS]; unsigned i; - + for(i = 0; i < num_textures; ++i) unwrapped_textures[i] = trace_texture_unwrap(tr_ctx, textures[i]); textures = unwrapped_textures; @@ -830,18 +861,27 @@ trace_context_set_vertex_buffers(struct pipe_context *_pipe, unsigned i; for(i = 0; i < num_buffers; ++i) - trace_winsys_user_buffer_update(_pipe->winsys, buffers[i].buffer); + trace_screen_user_buffer_update(_pipe->screen, buffers[i].buffer); trace_dump_call_begin("pipe_context", "set_vertex_buffers"); trace_dump_arg(ptr, pipe); trace_dump_arg(uint, num_buffers); - + trace_dump_arg_begin("buffers"); trace_dump_struct_array(vertex_buffer, buffers, num_buffers); trace_dump_arg_end(); - pipe->set_vertex_buffers(pipe, num_buffers, buffers);; + if (num_buffers) { + struct pipe_vertex_buffer *_buffers = malloc(num_buffers * sizeof(*_buffers)); + memcpy(_buffers, buffers, num_buffers * sizeof(*_buffers)); + for (i = 0; i < num_buffers; i++) + _buffers[i].buffer = trace_buffer_unwrap(tr_ctx, buffers[i].buffer); + pipe->set_vertex_buffers(pipe, num_buffers, _buffers); + free(_buffers); + } else { + pipe->set_vertex_buffers(pipe, num_buffers, NULL); + } trace_dump_call_end(); } @@ -872,7 +912,6 @@ trace_context_set_vertex_elements(struct pipe_context *_pipe, 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, @@ -884,11 +923,10 @@ trace_context_surface_copy(struct pipe_context *_pipe, dest = trace_surface_unwrap(tr_ctx, dest); src = trace_surface_unwrap(tr_ctx, src); - + trace_dump_call_begin("pipe_context", "surface_copy"); trace_dump_arg(ptr, pipe); - trace_dump_arg(bool, do_flip); trace_dump_arg(ptr, dest); trace_dump_arg(uint, destx); trace_dump_arg(uint, desty); @@ -898,10 +936,10 @@ trace_context_surface_copy(struct pipe_context *_pipe, trace_dump_arg(uint, width); trace_dump_arg(uint, height); - pipe->surface_copy(pipe, do_flip, - dest, destx, desty, + pipe->surface_copy(pipe, + dest, destx, desty, src, srcx, srcy, width, height); - + trace_dump_call_end(); } @@ -934,7 +972,7 @@ trace_context_surface_fill(struct pipe_context *_pipe, static INLINE void -trace_context_clear(struct pipe_context *_pipe, +trace_context_clear(struct pipe_context *_pipe, struct pipe_surface *surface, unsigned clearValue) { @@ -988,7 +1026,7 @@ trace_context_destroy(struct pipe_context *_pipe) trace_dump_arg(ptr, pipe); pipe->destroy(pipe); - + trace_dump_call_end(); FREE(tr_ctx); @@ -996,23 +1034,25 @@ trace_context_destroy(struct pipe_context *_pipe) struct pipe_context * -trace_context_create(struct pipe_screen *screen, +trace_context_create(struct pipe_screen *_screen, struct pipe_context *pipe) { + struct trace_screen *tr_scr = trace_screen(_screen); struct trace_context *tr_ctx; - + struct pipe_screen *screen = tr_scr->screen; + if(!pipe) goto error1; - + if(!trace_dump_enabled()) goto error1; - + tr_ctx = CALLOC_STRUCT(trace_context); if(!tr_ctx) goto error1; - tr_ctx->base.winsys = screen->winsys; - tr_ctx->base.screen = screen; + tr_ctx->base.winsys = _screen->winsys; + tr_ctx->base.screen = _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; @@ -1057,16 +1097,14 @@ trace_context_create(struct pipe_screen *screen, tr_ctx->base.flush = trace_context_flush; tr_ctx->pipe = pipe; - + trace_dump_call_begin("", "pipe_context_create"); - trace_dump_arg_begin("screen"); - trace_dump_ptr(pipe->screen); - trace_dump_arg_end(); + trace_dump_arg(ptr, screen); trace_dump_ret(ptr, pipe); trace_dump_call_end(); return &tr_ctx->base; - + error1: return pipe; } diff --git a/src/gallium/drivers/trace/tr_context.h b/src/gallium/drivers/trace/tr_context.h index 7831900ec29..d02b22a069b 100644 --- a/src/gallium/drivers/trace/tr_context.h +++ b/src/gallium/drivers/trace/tr_context.h @@ -30,7 +30,7 @@ #include "pipe/p_compiler.h" -#include "pipe/p_debug.h" +#include "util/u_debug.h" #include "pipe/p_context.h" @@ -38,11 +38,11 @@ extern "C" { #endif - + struct trace_context { struct pipe_context base; - + struct pipe_context *pipe; }; diff --git a/src/gallium/drivers/trace/tr_dump.c b/src/gallium/drivers/trace/tr_dump.c index a0ead0ded33..6837c94542d 100644 --- a/src/gallium/drivers/trace/tr_dump.c +++ b/src/gallium/drivers/trace/tr_dump.c @@ -29,35 +29,38 @@ /** * @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 + * 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 <[email protected]> + * + * @author Jose Fonseca <[email protected]> */ #include "pipe/p_config.h" -#if defined(PIPE_OS_LINUX) +#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) #include <stdlib.h> #endif #include "pipe/p_compiler.h" -#include "pipe/p_debug.h" +#include "util/u_debug.h" #include "util/u_memory.h" #include "util/u_string.h" #include "util/u_stream.h" #include "tr_dump.h" +#include "tr_screen.h" +#include "tr_texture.h" +#include "tr_buffer.h" static struct util_stream *stream = NULL; static unsigned refcount = 0; -static INLINE void +static INLINE void trace_dump_write(const char *buf, size_t size) { if(stream) @@ -65,14 +68,14 @@ trace_dump_write(const char *buf, size_t size) } -static INLINE void +static INLINE void trace_dump_writes(const char *s) { trace_dump_write(s, strlen(s)); } -static INLINE void +static INLINE void trace_dump_writef(const char *format, ...) { static char buf[1024]; @@ -85,8 +88,8 @@ trace_dump_writef(const char *format, ...) } -static INLINE void -trace_dump_escape(const char *str) +static INLINE void +trace_dump_escape(const char *str) { const unsigned char *p = (const unsigned char *)str; unsigned char c; @@ -109,7 +112,7 @@ trace_dump_escape(const char *str) } -static INLINE void +static INLINE void trace_dump_indent(unsigned level) { unsigned i; @@ -118,14 +121,14 @@ trace_dump_indent(unsigned level) } -static INLINE void -trace_dump_newline(void) +static INLINE void +trace_dump_newline(void) { trace_dump_writes("\n"); } -static INLINE void +static INLINE void trace_dump_tag(const char *name) { trace_dump_writes("<"); @@ -134,7 +137,7 @@ trace_dump_tag(const char *name) } -static INLINE void +static INLINE void trace_dump_tag_begin(const char *name) { trace_dump_writes("<"); @@ -142,8 +145,8 @@ trace_dump_tag_begin(const char *name) trace_dump_writes(">"); } -static INLINE void -trace_dump_tag_begin1(const char *name, +static INLINE void +trace_dump_tag_begin1(const char *name, const char *attr1, const char *value1) { trace_dump_writes("<"); @@ -156,8 +159,8 @@ trace_dump_tag_begin1(const char *name, } -static INLINE void -trace_dump_tag_begin2(const char *name, +static INLINE void +trace_dump_tag_begin2(const char *name, const char *attr1, const char *value1, const char *attr2, const char *value2) { @@ -175,8 +178,8 @@ trace_dump_tag_begin2(const char *name, } -static INLINE void -trace_dump_tag_begin3(const char *name, +static INLINE void +trace_dump_tag_begin3(const char *name, const char *attr1, const char *value1, const char *attr2, const char *value2, const char *attr3, const char *value3) @@ -207,7 +210,7 @@ trace_dump_tag_end(const char *name) trace_dump_writes(">"); } -static void +static void trace_dump_trace_close(void) { if(stream) { @@ -221,30 +224,30 @@ trace_dump_trace_close(void) boolean trace_dump_trace_begin() { const char *filename; - + filename = debug_get_option("GALLIUM_TRACE", NULL); if(!filename) return FALSE; - + if(!stream) { - + stream = util_stream_create(filename, 0); if(!stream) return FALSE; - + trace_dump_writes("<?xml version='1.0' encoding='UTF-8'?>\n"); trace_dump_writes("<?xml-stylesheet type='text/xsl' href='trace.xsl'?>\n"); trace_dump_writes("<trace version='0.1'>\n"); - -#if defined(PIPE_OS_LINUX) - /* Linux applications rarely cleanup GL / Gallium resources so catch - * application exit here */ + +#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) + /* Linux applications rarely cleanup GL / Gallium resources so catch + * application exit here */ atexit(trace_dump_trace_close); #endif } - + ++refcount; - + return TRUE; } @@ -402,3 +405,49 @@ void trace_dump_ptr(const void *value) else trace_dump_null(); } + +void trace_dump_buffer_ptr(struct pipe_buffer *_buffer) +{ + if (_buffer) { + struct trace_screen *tr_scr = trace_screen(_buffer->screen); + struct trace_buffer *tr_buf = trace_buffer(tr_scr, _buffer); + trace_dump_ptr(tr_buf->buffer); + } else { + trace_dump_null(); + } +} + +void trace_dump_texture_ptr(struct pipe_texture *_texture) +{ + if (_texture) { + struct trace_screen *tr_scr = trace_screen(_texture->screen); + struct trace_texture *tr_tex = trace_texture(tr_scr, _texture); + trace_dump_ptr(tr_tex->texture); + } else { + trace_dump_null(); + } +} + +void trace_dump_surface_ptr(struct pipe_surface *_surface) +{ + if (_surface) { + struct trace_screen *tr_scr = trace_screen(_surface->texture->screen); + struct trace_texture *tr_tex = trace_texture(tr_scr, _surface->texture); + struct trace_surface *tr_surf = trace_surface(tr_tex, _surface); + trace_dump_ptr(tr_surf->surface); + } else { + trace_dump_null(); + } +} + +void trace_dump_transfer_ptr(struct pipe_transfer *_transfer) +{ + if (_transfer) { + struct trace_screen *tr_scr = trace_screen(_transfer->texture->screen); + struct trace_texture *tr_tex = trace_texture(tr_scr, _transfer->texture); + struct trace_transfer *tr_tran = trace_transfer(tr_tex, _transfer); + trace_dump_ptr(tr_tran->transfer); + } else { + trace_dump_null(); + } +} diff --git a/src/gallium/drivers/trace/tr_dump.h b/src/gallium/drivers/trace/tr_dump.h index 76a53731b31..26409f26c66 100644 --- a/src/gallium/drivers/trace/tr_dump.h +++ b/src/gallium/drivers/trace/tr_dump.h @@ -37,6 +37,11 @@ #include "pipe/p_compiler.h" +struct pipe_buffer; +struct pipe_texture; +struct pipe_surface; +struct pipe_transfer; + boolean trace_dump_trace_begin(void); boolean trace_dump_enabled(void); void trace_dump_trace_end(void); @@ -63,10 +68,14 @@ void trace_dump_member_begin(const char *name); void trace_dump_member_end(void); void trace_dump_null(void); void trace_dump_ptr(const void *value); - +/* will turn a wrapped object into the real one and dump ptr */ +void trace_dump_buffer_ptr(struct pipe_buffer *_buffer); +void trace_dump_texture_ptr(struct pipe_texture *_texture); +void trace_dump_surface_ptr(struct pipe_surface *_surface); +void trace_dump_transfer_ptr(struct pipe_transfer *_transfer); /* - * Code saving macros. + * Code saving macros. */ #define trace_dump_arg(_type, _arg) \ diff --git a/src/gallium/drivers/trace/tr_screen.c b/src/gallium/drivers/trace/tr_screen.c index 8789f86b1a8..954576d7217 100644 --- a/src/gallium/drivers/trace/tr_screen.c +++ b/src/gallium/drivers/trace/tr_screen.c @@ -27,12 +27,14 @@ #include "util/u_memory.h" +#include "tr_buffer.h" #include "tr_dump.h" #include "tr_state.h" -#include "tr_winsys.h" #include "tr_texture.h" #include "tr_screen.h" +#include "pipe/p_inlines.h" + static const char * trace_screen_get_name(struct pipe_screen *_screen) @@ -40,17 +42,17 @@ trace_screen_get_name(struct pipe_screen *_screen) struct trace_screen *tr_scr = trace_screen(_screen); struct pipe_screen *screen = tr_scr->screen; const char *result; - + trace_dump_call_begin("pipe_screen", "get_name"); - + trace_dump_arg(ptr, screen); result = screen->get_name(screen); - + trace_dump_ret(string, result); - + trace_dump_call_end(); - + return result; } @@ -61,80 +63,80 @@ trace_screen_get_vendor(struct pipe_screen *_screen) struct trace_screen *tr_scr = trace_screen(_screen); struct pipe_screen *screen = tr_scr->screen; const char *result; - + trace_dump_call_begin("pipe_screen", "get_vendor"); - + trace_dump_arg(ptr, screen); - + result = screen->get_vendor(screen); - + trace_dump_ret(string, result); - + trace_dump_call_end(); - + return result; } -static int -trace_screen_get_param(struct pipe_screen *_screen, +static int +trace_screen_get_param(struct pipe_screen *_screen, int param) { struct trace_screen *tr_scr = trace_screen(_screen); struct pipe_screen *screen = tr_scr->screen; int result; - + trace_dump_call_begin("pipe_screen", "get_param"); - + trace_dump_arg(ptr, screen); trace_dump_arg(int, param); result = screen->get_param(screen, param); - + trace_dump_ret(int, result); - + trace_dump_call_end(); - + return result; } -static float -trace_screen_get_paramf(struct pipe_screen *_screen, +static float +trace_screen_get_paramf(struct pipe_screen *_screen, int param) { struct trace_screen *tr_scr = trace_screen(_screen); struct pipe_screen *screen = tr_scr->screen; float result; - + trace_dump_call_begin("pipe_screen", "get_paramf"); - + trace_dump_arg(ptr, screen); trace_dump_arg(int, param); result = screen->get_paramf(screen, param); - + trace_dump_ret(float, result); - + trace_dump_call_end(); - + return result; } -static boolean +static boolean trace_screen_is_format_supported(struct pipe_screen *_screen, enum pipe_format format, enum pipe_texture_target target, - unsigned tex_usage, + unsigned tex_usage, unsigned geom_flags) { struct trace_screen *tr_scr = trace_screen(_screen); struct pipe_screen *screen = tr_scr->screen; boolean result; - + trace_dump_call_begin("pipe_screen", "is_format_supported"); - + trace_dump_arg(ptr, screen); trace_dump_arg(format, format); trace_dump_arg(int, target); @@ -142,15 +144,45 @@ trace_screen_is_format_supported(struct pipe_screen *_screen, trace_dump_arg(uint, geom_flags); result = screen->is_format_supported(screen, format, target, tex_usage, geom_flags); - + trace_dump_ret(bool, result); - + trace_dump_call_end(); - + return result; } +static void +trace_screen_flush_frontbuffer(struct pipe_screen *_screen, + struct pipe_surface *_surface, + void *context_private) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct trace_texture *tr_tex = trace_texture(tr_scr, _surface->texture); + struct trace_surface *tr_surf = trace_surface(tr_tex, _surface); + struct pipe_screen *screen = tr_scr->screen; + struct pipe_surface *surface = tr_surf->surface; + + trace_dump_call_begin("pipe_screen", "flush_frontbuffer"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, surface); + /* XXX: hide, as there is nothing we can do with this + trace_dump_arg(ptr, context_private); + */ + + screen->flush_frontbuffer(screen, surface, context_private); + + trace_dump_call_end(); +} + + +/******************************************************************** + * texture + */ + + static struct pipe_texture * trace_screen_texture_create(struct pipe_screen *_screen, const struct pipe_texture *templat) @@ -158,20 +190,20 @@ trace_screen_texture_create(struct pipe_screen *_screen, struct trace_screen *tr_scr = trace_screen(_screen); struct pipe_screen *screen = tr_scr->screen; struct pipe_texture *result; - + trace_dump_call_begin("pipe_screen", "texture_create"); trace_dump_arg(ptr, screen); trace_dump_arg(template, templat); result = screen->texture_create(screen, templat); - + trace_dump_ret(ptr, result); - + trace_dump_call_end(); - + result = trace_texture_create(tr_scr, result); - + return result; } @@ -195,71 +227,60 @@ trace_screen_texture_blanket(struct pipe_screen *_screen, trace_dump_arg(ptr, buffer); result = screen->texture_blanket(screen, templat, ppitch, buffer); - + trace_dump_ret(ptr, result); - + trace_dump_call_end(); - + result = trace_texture_create(tr_scr, result); - + return result; } -static void -trace_screen_texture_release(struct pipe_screen *_screen, - struct pipe_texture **ptexture) +static void +trace_screen_texture_destroy(struct pipe_texture *_texture) { - struct trace_screen *tr_scr = trace_screen(_screen); + struct trace_screen *tr_scr = trace_screen(_texture->screen); + struct trace_texture *tr_tex = trace_texture(tr_scr, _texture); struct pipe_screen *screen = tr_scr->screen; - struct trace_texture *tr_tex; - struct pipe_texture *texture; - - assert(ptexture); - if(*ptexture) { - tr_tex = trace_texture(tr_scr, *ptexture); - texture = tr_tex->texture; - assert(texture->screen == screen); - } - else - texture = NULL; - - if (*ptexture) { - if (!--(*ptexture)->refcount) { - trace_dump_call_begin("pipe_screen", "texture_destroy"); - - trace_dump_arg(ptr, screen); - trace_dump_arg(ptr, texture); - - trace_texture_destroy(tr_scr, *ptexture); - - trace_dump_call_end(); - } - - *ptexture = NULL; - } + struct pipe_texture *texture = tr_tex->texture; + + assert(texture->screen == screen); + + trace_dump_call_begin("pipe_screen", "texture_destroy"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, texture); + + trace_dump_call_end(); + + trace_texture_destroy(tr_scr, _texture); } +/******************************************************************** + * surface + */ + + static struct pipe_surface * trace_screen_get_tex_surface(struct pipe_screen *_screen, - struct pipe_texture *texture, + struct pipe_texture *_texture, unsigned face, unsigned level, unsigned zslice, unsigned usage) { struct trace_screen *tr_scr = trace_screen(_screen); + struct trace_texture *tr_tex = trace_texture(tr_scr, _texture); struct pipe_screen *screen = tr_scr->screen; - struct trace_texture *tr_tex; - struct pipe_surface *result; - - assert(texture); - tr_tex = trace_texture(tr_scr, texture); - texture = tr_tex->texture; + struct pipe_texture *texture = tr_tex->texture; + struct pipe_surface *result = NULL; + assert(texture->screen == screen); - + trace_dump_call_begin("pipe_screen", "get_tex_surface"); - + trace_dump_arg(ptr, screen); trace_dump_arg(ptr, texture); trace_dump_arg(uint, face); @@ -270,133 +291,538 @@ trace_screen_get_tex_surface(struct pipe_screen *_screen, result = screen->get_tex_surface(screen, texture, face, level, zslice, usage); trace_dump_ret(ptr, result); - + trace_dump_call_end(); - + result = trace_surface_create(tr_tex, result); return result; } -static void -trace_screen_tex_surface_release(struct pipe_screen *_screen, - struct pipe_surface **psurface) +static void +trace_screen_tex_surface_destroy(struct pipe_surface *_surface) +{ + struct trace_screen *tr_scr = trace_screen(_surface->texture->screen); + struct trace_texture *tr_tex = trace_texture(tr_scr, _surface->texture); + struct trace_surface *tr_surf = trace_surface(tr_tex, _surface); + struct pipe_screen *screen = tr_scr->screen; + struct pipe_surface *surface = tr_surf->surface; + + trace_dump_call_begin("pipe_screen", "tex_surface_destroy"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, surface); + + trace_dump_call_end(); + + trace_surface_destroy(tr_tex, _surface); +} + + +/******************************************************************** + * transfer + */ + + +static struct pipe_transfer * +trace_screen_get_tex_transfer(struct pipe_screen *_screen, + struct pipe_texture *_texture, + unsigned face, unsigned level, + unsigned zslice, + enum pipe_transfer_usage usage, + unsigned x, unsigned y, unsigned w, unsigned h) { struct trace_screen *tr_scr = trace_screen(_screen); + struct trace_texture *tr_tex = trace_texture(tr_scr, _texture); struct pipe_screen *screen = tr_scr->screen; - struct trace_texture *tr_tex; - struct trace_surface *tr_surf; - struct pipe_surface *surface; - - assert(psurface); - if(*psurface) { - tr_tex = trace_texture(tr_scr, (*psurface)->texture); - tr_surf = trace_surface(tr_tex, *psurface); - surface = tr_surf->surface; - } - else - surface = NULL; - - if (*psurface) { - if (!--(*psurface)->refcount) { - trace_dump_call_begin("pipe_screen", "tex_surface_destroy"); - - trace_dump_arg(ptr, screen); - trace_dump_arg(ptr, surface); + struct pipe_texture *texture = tr_tex->texture; + struct pipe_transfer *result = NULL; - trace_surface_destroy(tr_tex, *psurface); + assert(texture->screen == screen); - trace_dump_call_end(); - } - - *psurface = NULL; - } + trace_dump_call_begin("pipe_screen", "get_tex_transfer"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, texture); + trace_dump_arg(uint, face); + trace_dump_arg(uint, level); + trace_dump_arg(uint, zslice); + trace_dump_arg(uint, usage); + + trace_dump_arg(uint, x); + trace_dump_arg(uint, y); + trace_dump_arg(uint, w); + trace_dump_arg(uint, h); + + result = screen->get_tex_transfer(screen, texture, face, level, zslice, usage, + x, y, w, h); + + trace_dump_ret(ptr, result); + + trace_dump_call_end(); + + result = trace_transfer_create(tr_tex, result); + + return result; +} + + +static void +trace_screen_tex_transfer_destroy(struct pipe_transfer *_transfer) +{ + struct trace_screen *tr_scr = trace_screen(_transfer->texture->screen); + struct trace_texture *tr_tex = trace_texture(tr_scr, _transfer->texture); + struct trace_transfer *tr_tran = trace_transfer(tr_tex, _transfer); + struct pipe_screen *screen = tr_scr->screen; + struct pipe_transfer *transfer = tr_tran->transfer; + + trace_dump_call_begin("pipe_screen", "tex_transfer_destroy"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, transfer); + + trace_dump_call_end(); + + trace_transfer_destroy(tr_tex, _transfer); } static void * -trace_screen_surface_map(struct pipe_screen *_screen, - struct pipe_surface *surface, - unsigned flags) +trace_screen_transfer_map(struct pipe_screen *_screen, + struct pipe_transfer *_transfer) { struct trace_screen *tr_scr = trace_screen(_screen); + struct trace_texture *tr_tex = trace_texture(tr_scr, _transfer->texture); + struct trace_transfer *tr_trans = trace_transfer(tr_tex, _transfer); struct pipe_screen *screen = tr_scr->screen; - struct trace_texture *tr_tex; - struct trace_surface *tr_surf; + struct pipe_transfer *transfer = tr_trans->transfer; void *map; - - tr_tex = trace_texture(tr_scr, surface->texture); - tr_surf = trace_surface(tr_tex, surface); - surface = tr_surf->surface; - map = screen->surface_map(screen, surface, flags); + map = screen->transfer_map(screen, transfer); if(map) { - if(flags & PIPE_BUFFER_USAGE_CPU_WRITE) { - assert(!tr_surf->map); - tr_surf->map = map; + if(transfer->usage != PIPE_TRANSFER_READ) { + assert(!tr_trans->map); + tr_trans->map = map; } } - + return map; } -static void -trace_screen_surface_unmap(struct pipe_screen *_screen, - struct pipe_surface *surface) +static void +trace_screen_transfer_unmap(struct pipe_screen *_screen, + struct pipe_transfer *_transfer) { struct trace_screen *tr_scr = trace_screen(_screen); + struct trace_texture *tr_tex = trace_texture(tr_scr, _transfer->texture); + struct trace_transfer *tr_trans = trace_transfer(tr_tex, _transfer); struct pipe_screen *screen = tr_scr->screen; - struct trace_texture *tr_tex; - struct trace_surface *tr_surf; - - tr_tex = trace_texture(tr_scr, surface->texture); - tr_surf = trace_surface(tr_tex, surface); - surface = tr_surf->surface; - - if(tr_surf->map) { - size_t size = surface->nblocksy * surface->stride; - - trace_dump_call_begin("pipe_winsys", "surface_write"); - + struct pipe_transfer *transfer = tr_trans->transfer; + + if(tr_trans->map) { + size_t size = transfer->nblocksy * transfer->stride; + + trace_dump_call_begin("pipe_screen", "transfer_write"); + trace_dump_arg(ptr, screen); - - trace_dump_arg(ptr, surface); - - trace_dump_arg_begin("data"); - trace_dump_bytes(tr_surf->map, size); - trace_dump_arg_end(); + + trace_dump_arg(ptr, transfer); trace_dump_arg_begin("stride"); - trace_dump_uint(surface->stride); + trace_dump_uint(transfer->stride); + trace_dump_arg_end(); + + trace_dump_arg_begin("data"); + trace_dump_bytes(tr_trans->map, size); trace_dump_arg_end(); trace_dump_arg_begin("size"); trace_dump_uint(size); trace_dump_arg_end(); - + trace_dump_call_end(); - tr_surf->map = NULL; + tr_trans->map = NULL; + } + + screen->transfer_unmap(screen, transfer); +} + + +/******************************************************************** + * buffer + */ + + +static struct pipe_buffer * +trace_screen_surface_buffer_create(struct pipe_screen *_screen, + unsigned width, unsigned height, + enum pipe_format format, + unsigned usage, + unsigned *pstride) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + unsigned stride; + struct pipe_buffer *result; + + trace_dump_call_begin("pipe_screen", "surface_buffer_create"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(uint, width); + trace_dump_arg(uint, height); + trace_dump_arg(format, format); + trace_dump_arg(uint, usage); + + result = screen->surface_buffer_create(screen, + width, height, + format, + usage, + pstride); + + stride = *pstride; + + trace_dump_arg(uint, stride); + + trace_dump_ret(ptr, result); + + trace_dump_call_end(); + + return trace_buffer_create(tr_scr, result); +} + + +static struct pipe_buffer * +trace_screen_buffer_create(struct pipe_screen *_screen, + unsigned alignment, + unsigned usage, + unsigned size) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + struct pipe_buffer *result; + + trace_dump_call_begin("pipe_screen", "buffer_create"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(uint, alignment); + trace_dump_arg(uint, usage); + trace_dump_arg(uint, size); + + result = screen->buffer_create(screen, alignment, usage, size); + + trace_dump_ret(ptr, result); + + trace_dump_call_end(); + + /* Zero the buffer to avoid dumping uninitialized memory */ + if(result->usage & PIPE_BUFFER_USAGE_CPU_WRITE) { + void *map; + map = pipe_buffer_map(screen, result, PIPE_BUFFER_USAGE_CPU_WRITE); + if(map) { + memset(map, 0, result->size); + screen->buffer_unmap(screen, result); + } + } + + return trace_buffer_create(tr_scr, result); +} + + +static struct pipe_buffer * +trace_screen_user_buffer_create(struct pipe_screen *_screen, + void *data, + unsigned size) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + struct pipe_buffer *result; + + trace_dump_call_begin("pipe_screen", "user_buffer_create"); + + trace_dump_arg(ptr, screen); + trace_dump_arg_begin("data"); + trace_dump_bytes(data, size); + trace_dump_arg_end(); + trace_dump_arg(uint, size); + + result = screen->user_buffer_create(screen, data, size); + + trace_dump_ret(ptr, result); + + trace_dump_call_end(); + + if(result) { + assert(!(result->usage & TRACE_BUFFER_USAGE_USER)); + result->usage |= TRACE_BUFFER_USAGE_USER; + } + + return trace_buffer_create(tr_scr, result); +} + + +/** + * This function is used to track if data has been changed on a user buffer + * without map/unmap being called. + */ +void +trace_screen_user_buffer_update(struct pipe_screen *_screen, + struct pipe_buffer *_buffer) +{ +#if 0 + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + const void *map; + + if(buffer && buffer->usage & TRACE_BUFFER_USAGE_USER) { + map = screen->buffer_map(screen, buffer, PIPE_BUFFER_USAGE_CPU_READ); + if(map) { + trace_dump_call_begin("pipe_winsys", "buffer_write"); + + trace_dump_arg(ptr, screen); + + trace_dump_arg(ptr, buffer); + + trace_dump_arg_begin("data"); + trace_dump_bytes(map, buffer->size); + trace_dump_arg_end(); + + trace_dump_arg_begin("size"); + trace_dump_uint(buffer->size); + trace_dump_arg_end(); + + trace_dump_call_end(); + + screen->buffer_unmap(screen, buffer); + } + } +#endif +} + + +static void * +trace_screen_buffer_map(struct pipe_screen *_screen, + struct pipe_buffer *_buffer, + unsigned usage) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct trace_buffer *tr_buf = trace_buffer(tr_scr, _buffer); + struct pipe_screen *screen = tr_scr->screen; + struct pipe_buffer *buffer = tr_buf->buffer; + void *map; + + assert(screen->buffer_map); + map = screen->buffer_map(screen, buffer, usage); + if(map) { + if(usage & PIPE_BUFFER_USAGE_CPU_WRITE) { + tr_buf->map = map; + } + } + + return map; +} + + +static void * +trace_screen_buffer_map_range(struct pipe_screen *_screen, + struct pipe_buffer *_buffer, + unsigned offset, + unsigned length, + unsigned usage) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct trace_buffer *tr_buf = trace_buffer(tr_scr, _buffer); + struct pipe_screen *screen = tr_scr->screen; + struct pipe_buffer *buffer = tr_buf->buffer; + void *map; + + assert(screen->buffer_map_range); + map = screen->buffer_map_range(screen, buffer, offset, length, usage); + if(map) { + if(usage & PIPE_BUFFER_USAGE_CPU_WRITE) { + tr_buf->map = map; + } } - screen->surface_unmap(screen, surface); + return map; +} + + +static void +buffer_write(struct pipe_screen *screen, + struct pipe_buffer *buffer, + unsigned offset, + const char *map, + unsigned size) +{ + assert(map); + + trace_dump_call_begin("pipe_screen", "buffer_write"); + + trace_dump_arg(ptr, screen); + + trace_dump_arg(ptr, buffer); + + trace_dump_arg(uint, offset); + + trace_dump_arg_begin("data"); + trace_dump_bytes(map + offset, size); + trace_dump_arg_end(); + + trace_dump_arg(uint, size); + + trace_dump_call_end(); + +} + + +static void +trace_screen_buffer_flush_mapped_range(struct pipe_screen *_screen, + struct pipe_buffer *_buffer, + unsigned offset, + unsigned length) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct trace_buffer *tr_buf = trace_buffer(tr_scr, _buffer); + struct pipe_screen *screen = tr_scr->screen; + struct pipe_buffer *buffer = tr_buf->buffer; + + assert(tr_buf->map); + buffer_write(screen, buffer, offset, tr_buf->map, length); + tr_buf->range_flushed = TRUE; + screen->buffer_flush_mapped_range(screen, buffer, offset, length); +} + + +static void +trace_screen_buffer_unmap(struct pipe_screen *_screen, + struct pipe_buffer *_buffer) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct trace_buffer *tr_buf = trace_buffer(tr_scr, _buffer); + struct pipe_screen *screen = tr_scr->screen; + struct pipe_buffer *buffer = tr_buf->buffer; + + if (tr_buf->map && !tr_buf->range_flushed) + buffer_write(screen, buffer, tr_buf->map, 0, buffer->size); + tr_buf->map = NULL; + tr_buf->range_flushed = FALSE; + screen->buffer_unmap(screen, buffer); +} + + +static void +trace_screen_buffer_destroy(struct pipe_buffer *_buffer) +{ + struct trace_screen *tr_scr = trace_screen(_buffer->screen); + struct trace_buffer *tr_buf = trace_buffer(tr_scr, _buffer); + struct pipe_screen *screen = tr_scr->screen; + struct pipe_buffer *buffer = tr_buf->buffer; + + trace_dump_call_begin("pipe_screen", "buffer_destroy"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, buffer); + + trace_dump_call_end(); + + trace_buffer_destroy(tr_scr, _buffer); +} + + +/******************************************************************** + * fence + */ + + +static void +trace_screen_fence_reference(struct pipe_screen *_screen, + struct pipe_fence_handle **dst, + struct pipe_fence_handle *src) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + + trace_dump_call_begin("pipe_screen", "fence_reference"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, dst); + trace_dump_arg(ptr, src); + + screen->fence_reference(screen, dst, src); + + trace_dump_call_end(); +} + + +static int +trace_screen_fence_signalled(struct pipe_screen *_screen, + struct pipe_fence_handle *fence, + unsigned flag) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + int result; + + trace_dump_call_begin("pipe_screen", "fence_signalled"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, fence); + trace_dump_arg(uint, flag); + + result = screen->fence_signalled(screen, fence, flag); + + trace_dump_ret(int, result); + + trace_dump_call_end(); + + return result; } +static int +trace_screen_fence_finish(struct pipe_screen *_screen, + struct pipe_fence_handle *fence, + unsigned flag) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + int result; + + trace_dump_call_begin("pipe_screen", "fence_finish"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, fence); + trace_dump_arg(uint, flag); + + result = screen->fence_finish(screen, fence, flag); + + trace_dump_ret(int, result); + + trace_dump_call_end(); + + return result; +} + + +/******************************************************************** + * screen + */ + static void trace_screen_destroy(struct pipe_screen *_screen) { struct trace_screen *tr_scr = trace_screen(_screen); struct pipe_screen *screen = tr_scr->screen; - + trace_dump_call_begin("pipe_screen", "destroy"); - + trace_dump_arg(ptr, screen); screen->destroy(screen); - + trace_dump_call_end(); trace_dump_trace_end(); @@ -410,21 +836,27 @@ trace_screen_create(struct pipe_screen *screen) { struct trace_screen *tr_scr; struct pipe_winsys *winsys; - + if(!screen) goto error1; if(!trace_dump_trace_begin()) goto error1; + trace_dump_call_begin("", "pipe_screen_create"); + tr_scr = CALLOC_STRUCT(trace_screen); if(!tr_scr) goto error2; +#if 0 winsys = trace_winsys_create(screen->winsys); if(!winsys) goto error3; - +#else + winsys = screen->winsys; +#endif + tr_scr->base.winsys = winsys; tr_scr->base.destroy = trace_screen_destroy; tr_scr->base.get_name = trace_screen_get_name; @@ -434,26 +866,43 @@ trace_screen_create(struct pipe_screen *screen) 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.texture_destroy = trace_screen_texture_destroy; 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->base.tex_surface_destroy = trace_screen_tex_surface_destroy; + tr_scr->base.get_tex_transfer = trace_screen_get_tex_transfer; + tr_scr->base.tex_transfer_destroy = trace_screen_tex_transfer_destroy; + tr_scr->base.transfer_map = trace_screen_transfer_map; + tr_scr->base.transfer_unmap = trace_screen_transfer_unmap; + tr_scr->base.buffer_create = trace_screen_buffer_create; + tr_scr->base.user_buffer_create = trace_screen_user_buffer_create; + tr_scr->base.surface_buffer_create = trace_screen_surface_buffer_create; + if (screen->buffer_map) + tr_scr->base.buffer_map = trace_screen_buffer_map; + if (screen->buffer_map_range) + tr_scr->base.buffer_map_range = trace_screen_buffer_map_range; + if (screen->buffer_flush_mapped_range) + tr_scr->base.buffer_flush_mapped_range = trace_screen_buffer_flush_mapped_range; + if (screen->buffer_unmap) + tr_scr->base.buffer_unmap = trace_screen_buffer_unmap; + tr_scr->base.buffer_destroy = trace_screen_buffer_destroy; + tr_scr->base.fence_reference = trace_screen_fence_reference; + tr_scr->base.fence_signalled = trace_screen_fence_signalled; + tr_scr->base.fence_finish = trace_screen_fence_finish; + tr_scr->base.flush_frontbuffer = trace_screen_flush_frontbuffer; tr_scr->screen = screen; - trace_dump_call_begin("", "pipe_screen_create"); - trace_dump_arg_begin("winsys"); - trace_dump_ptr(screen->winsys); - trace_dump_arg_end(); trace_dump_ret(ptr, screen); trace_dump_call_end(); return &tr_scr->base; +#if 0 error3: FREE(tr_scr); +#endif error2: + trace_dump_ret(ptr, screen); + trace_dump_call_end(); trace_dump_trace_end(); error1: return screen; diff --git a/src/gallium/drivers/trace/tr_screen.h b/src/gallium/drivers/trace/tr_screen.h index 93fefdb9a5f..8c65516b509 100644 --- a/src/gallium/drivers/trace/tr_screen.h +++ b/src/gallium/drivers/trace/tr_screen.h @@ -36,11 +36,19 @@ extern "C" { #endif - + +/** + * It often happens that new data is written directly to the user buffers + * without mapping/unmapping. This flag marks user buffers, so that their + * contents can be dumpped before being used by the pipe context. + */ +#define TRACE_BUFFER_USAGE_USER (1 << 31) + + struct trace_screen { struct pipe_screen base; - + struct pipe_screen *screen; }; @@ -53,6 +61,11 @@ struct pipe_screen * trace_screen_create(struct pipe_screen *screen); +void +trace_screen_user_buffer_update(struct pipe_screen *screen, + struct pipe_buffer *buffer); + + #ifdef __cplusplus } #endif diff --git a/src/gallium/drivers/trace/tr_state.c b/src/gallium/drivers/trace/tr_state.c index 524f2d61948..b6a1ce0d625 100644 --- a/src/gallium/drivers/trace/tr_state.c +++ b/src/gallium/drivers/trace/tr_state.c @@ -50,6 +50,14 @@ void trace_dump_block(const struct pipe_format_block *block) } +static void trace_dump_reference(const struct pipe_reference *reference) +{ + trace_dump_struct_begin("pipe_reference"); + trace_dump_member(int, &reference->count, count); + trace_dump_struct_end(); +} + + void trace_dump_template(const struct pipe_texture *templat) { if(!templat) { @@ -58,10 +66,10 @@ void trace_dump_template(const struct pipe_texture *templat) } trace_dump_struct_begin("pipe_texture"); - + trace_dump_member(int, templat, target); trace_dump_member(format, templat, format); - + trace_dump_member_begin("width"); trace_dump_array(uint, templat->width, 1); trace_dump_member_end(); @@ -77,10 +85,10 @@ void trace_dump_template(const struct pipe_texture *templat) trace_dump_member_begin("block"); trace_dump_block(&templat->block); trace_dump_member_end(); - + trace_dump_member(uint, templat, last_level); trace_dump_member(uint, templat, tex_usage); - + trace_dump_struct_end(); } @@ -114,8 +122,7 @@ void trace_dump_rasterizer_state(const struct pipe_rasterizer_state *state) trace_dump_member(uint, state, line_stipple_factor); trace_dump_member(uint, state, line_stipple_pattern); trace_dump_member(bool, state, line_last_pixel); - trace_dump_member(bool, state, bypass_clipping); - trace_dump_member(bool, state, bypass_vs); + trace_dump_member(bool, state, bypass_vs_clip_and_viewport); trace_dump_member(bool, state, origin_lower_left); trace_dump_member(bool, state, flatshade_first); trace_dump_member(bool, state, gl_rasterization_rules); @@ -126,9 +133,9 @@ void trace_dump_rasterizer_state(const struct pipe_rasterizer_state *state) trace_dump_member(float, state, point_size_max); trace_dump_member(float, state, offset_units); trace_dump_member(float, state, offset_scale); - + trace_dump_member_array(uint, state, sprite_coord_mode); - + trace_dump_struct_end(); } @@ -144,10 +151,10 @@ void trace_dump_poly_stipple(const struct pipe_poly_stipple *state) trace_dump_member_begin("stipple"); trace_dump_array(uint, - state->stipple, + state->stipple, Elements(state->stipple)); trace_dump_member_end(); - + trace_dump_struct_end(); } @@ -163,7 +170,7 @@ void trace_dump_viewport_state(const struct pipe_viewport_state *state) trace_dump_member_array(float, state, scale); trace_dump_member_array(float, state, translate); - + trace_dump_struct_end(); } @@ -189,7 +196,7 @@ void trace_dump_scissor_state(const struct pipe_scissor_state *state) void trace_dump_clip_state(const struct pipe_clip_state *state) { unsigned i; - + if(!state) { trace_dump_null(); return; @@ -222,7 +229,7 @@ void trace_dump_constant_buffer(const struct pipe_constant_buffer *state) trace_dump_struct_begin("pipe_constant_buffer"); - trace_dump_member(ptr, state, buffer); + trace_dump_member(buffer_ptr, state, buffer); trace_dump_struct_end(); } @@ -238,7 +245,7 @@ void trace_dump_shader_state(const struct pipe_shader_state *state) } tgsi_dump_str(state->tokens, 0, str, sizeof(str)); - + trace_dump_struct_begin("pipe_shader_state"); trace_dump_member_begin("tokens"); @@ -252,7 +259,7 @@ void trace_dump_shader_state(const struct pipe_shader_state *state) void trace_dump_depth_stencil_alpha_state(const struct pipe_depth_stencil_alpha_state *state) { unsigned i; - + if(!state) { trace_dump_null(); return; @@ -268,7 +275,7 @@ void trace_dump_depth_stencil_alpha_state(const struct pipe_depth_stencil_alpha_ trace_dump_member(bool, &state->depth, occlusion_count); trace_dump_struct_end(); trace_dump_member_end(); - + trace_dump_member_begin("stencil"); trace_dump_array_begin(); for(i = 0; i < Elements(state->stencil); ++i) { @@ -397,22 +404,47 @@ void trace_dump_surface(const struct pipe_surface *state) trace_dump_struct_begin("pipe_surface"); + trace_dump_reference(&state->reference); + trace_dump_member(format, state, format); trace_dump_member(uint, state, status); trace_dump_member(uint, state, clear_value); trace_dump_member(uint, state, width); trace_dump_member(uint, state, height); + trace_dump_member(uint, state, layout); + trace_dump_member(uint, state, offset); + trace_dump_member(uint, state, usage); + + trace_dump_member(ptr, state, texture); + trace_dump_member(uint, state, face); + trace_dump_member(uint, state, level); + trace_dump_member(uint, state, zslice); + + trace_dump_struct_end(); +} + + +void trace_dump_transfer(const struct pipe_transfer *state) +{ + if(!state) { + trace_dump_null(); + return; + } + + trace_dump_struct_begin("pipe_transfer"); + + trace_dump_member(format, state, format); + trace_dump_member(uint, state, width); + trace_dump_member(uint, state, height); + trace_dump_member_begin("block"); trace_dump_block(&state->block); trace_dump_member_end(); - + trace_dump_member(uint, state, nblocksx); trace_dump_member(uint, state, nblocksy); trace_dump_member(uint, state, stride); - trace_dump_member(uint, state, layout); - trace_dump_member(uint, state, offset); - trace_dump_member(uint, state, refcount); trace_dump_member(uint, state, usage); trace_dump_member(ptr, state, texture); @@ -436,7 +468,7 @@ void trace_dump_vertex_buffer(const struct pipe_vertex_buffer *state) trace_dump_member(uint, state, stride); trace_dump_member(uint, state, max_index); trace_dump_member(uint, state, buffer_offset); - trace_dump_member(ptr, state, buffer); + trace_dump_member(buffer_ptr, state, buffer); trace_dump_struct_end(); } @@ -455,7 +487,7 @@ void trace_dump_vertex_element(const struct pipe_vertex_element *state) trace_dump_member(uint, state, vertex_buffer_index); trace_dump_member(uint, state, nr_components); - + trace_dump_member(format, state, src_format); trace_dump_struct_end(); diff --git a/src/gallium/drivers/trace/tr_state.h b/src/gallium/drivers/trace/tr_state.h index 5ae533dc664..513ed0ac98d 100644 --- a/src/gallium/drivers/trace/tr_state.h +++ b/src/gallium/drivers/trace/tr_state.h @@ -68,6 +68,8 @@ void trace_dump_sampler_state(const struct pipe_sampler_state *state); void trace_dump_surface(const struct pipe_surface *state); +void trace_dump_transfer(const struct pipe_transfer *state); + void trace_dump_vertex_buffer(const struct pipe_vertex_buffer *state); void trace_dump_vertex_element(const struct pipe_vertex_element *state); diff --git a/src/gallium/drivers/trace/tr_texture.c b/src/gallium/drivers/trace/tr_texture.c index 1cc4f0bd436..7b392f07286 100644 --- a/src/gallium/drivers/trace/tr_texture.c +++ b/src/gallium/drivers/trace/tr_texture.c @@ -25,7 +25,6 @@ * **************************************************************************/ -#include "pipe/p_inlines.h" #include "util/u_hash_table.h" #include "util/u_memory.h" @@ -34,26 +33,28 @@ struct pipe_texture * -trace_texture_create(struct trace_screen *tr_scr, +trace_texture_create(struct trace_screen *tr_scr, struct pipe_texture *texture) { struct trace_texture *tr_tex; - + if(!texture) goto error; - + assert(texture->screen == tr_scr->screen); - + tr_tex = CALLOC_STRUCT(trace_texture); if(!tr_tex) goto error; - + memcpy(&tr_tex->base, texture, sizeof(struct pipe_texture)); + + pipe_reference_init(&tr_tex->base.reference, 1); tr_tex->base.screen = &tr_scr->base; tr_tex->texture = texture; - + return &tr_tex->base; - + error: pipe_texture_reference(&texture, NULL); return NULL; @@ -61,38 +62,39 @@ error: void -trace_texture_destroy(struct trace_screen *tr_scr, +trace_texture_destroy(struct trace_screen *tr_scr, struct pipe_texture *texture) { - struct trace_texture *tr_tex = trace_texture(tr_scr, texture); + struct trace_texture *tr_tex = trace_texture(tr_scr, texture); pipe_texture_reference(&tr_tex->texture, NULL); FREE(tr_tex); } struct pipe_surface * -trace_surface_create(struct trace_texture *tr_tex, +trace_surface_create(struct trace_texture *tr_tex, struct pipe_surface *surface) { struct trace_surface *tr_surf; - + if(!surface) goto error; - + assert(surface->texture == tr_tex->texture); - + tr_surf = CALLOC_STRUCT(trace_surface); if(!tr_surf) goto error; - + memcpy(&tr_surf->base, surface, sizeof(struct pipe_surface)); - + + pipe_reference_init(&tr_surf->base.reference, 1); tr_surf->base.texture = NULL; pipe_texture_reference(&tr_surf->base.texture, &tr_tex->base); tr_surf->surface = surface; return &tr_surf->base; - + error: pipe_surface_reference(&surface, NULL); return NULL; @@ -100,7 +102,7 @@ error: void -trace_surface_destroy(struct trace_texture *tr_tex, +trace_surface_destroy(struct trace_texture *tr_tex, struct pipe_surface *surface) { struct trace_surface *tr_surf = trace_surface(tr_tex, surface); @@ -109,3 +111,45 @@ trace_surface_destroy(struct trace_texture *tr_tex, FREE(tr_surf); } + +struct pipe_transfer * +trace_transfer_create(struct trace_texture *tr_tex, + struct pipe_transfer *transfer) +{ + struct trace_transfer *tr_trans; + + if(!transfer) + goto error; + + assert(transfer->texture == tr_tex->texture); + + tr_trans = CALLOC_STRUCT(trace_transfer); + if(!tr_trans) + goto error; + + memcpy(&tr_trans->base, transfer, sizeof(struct pipe_transfer)); + + tr_trans->base.texture = NULL; + pipe_texture_reference(&tr_trans->base.texture, &tr_tex->base); + tr_trans->transfer = transfer; + assert(tr_trans->base.texture == &tr_tex->base); + + return &tr_trans->base; + +error: + transfer->texture->screen->tex_transfer_destroy(transfer); + return NULL; +} + + +void +trace_transfer_destroy(struct trace_texture *tr_tex, + struct pipe_transfer *transfer) +{ + struct trace_transfer *tr_trans = trace_transfer(tr_tex, transfer); + struct pipe_screen *screen = tr_trans->transfer->texture->screen; + pipe_texture_reference(&tr_trans->base.texture, NULL); + screen->tex_transfer_destroy(tr_trans->transfer); + FREE(tr_trans); +} + diff --git a/src/gallium/drivers/trace/tr_texture.h b/src/gallium/drivers/trace/tr_texture.h index 9e72edb8a3c..9c21bc7d276 100644 --- a/src/gallium/drivers/trace/tr_texture.h +++ b/src/gallium/drivers/trace/tr_texture.h @@ -48,48 +48,78 @@ struct trace_surface struct pipe_surface base; struct pipe_surface *surface; - +}; + + +struct trace_transfer +{ + struct pipe_transfer base; + + struct pipe_transfer *transfer; + void *map; }; static INLINE struct trace_texture * -trace_texture(struct trace_screen *tr_scr, +trace_texture(struct trace_screen *tr_scr, struct pipe_texture *texture) { if(!texture) return NULL; + assert(tr_scr); assert(texture->screen == &tr_scr->base); return (struct trace_texture *)texture; } static INLINE struct trace_surface * -trace_surface(struct trace_texture *tr_tex, +trace_surface(struct trace_texture *tr_tex, struct pipe_surface *surface) { if(!surface) return NULL; + assert(tr_tex); assert(surface->texture == &tr_tex->base); return (struct trace_surface *)surface; } +static INLINE struct trace_transfer * +trace_transfer(struct trace_texture *tr_tex, + struct pipe_transfer *transfer) +{ + if(!transfer) + return NULL; + assert(tr_tex); + assert(transfer->texture == &tr_tex->base); + return (struct trace_transfer *)transfer; +} + + struct pipe_texture * -trace_texture_create(struct trace_screen *tr_scr, +trace_texture_create(struct trace_screen *tr_scr, struct pipe_texture *texture); void -trace_texture_destroy(struct trace_screen *tr_scr, +trace_texture_destroy(struct trace_screen *tr_scr, struct pipe_texture *texture); struct pipe_surface * -trace_surface_create(struct trace_texture *tr_tex, +trace_surface_create(struct trace_texture *tr_tex, struct pipe_surface *surface); void trace_surface_destroy(struct trace_texture *tr_tex, struct pipe_surface *surface); +struct pipe_transfer * +trace_transfer_create(struct trace_texture *tr_tex, + struct pipe_transfer *transfer); + +void +trace_transfer_destroy(struct trace_texture *tr_tex, + struct pipe_transfer *transfer); + #endif /* TR_TEXTURE_H_ */ diff --git a/src/gallium/drivers/trace/tr_winsys.c b/src/gallium/drivers/trace/tr_winsys.c deleted file mode 100644 index c4148fe8104..00000000000 --- a/src/gallium/drivers/trace/tr_winsys.c +++ /dev/null @@ -1,450 +0,0 @@ -/************************************************************************** - * - * 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 "util/u_memory.h" -#include "util/u_hash_table.h" - -#include "tr_dump.h" -#include "tr_state.h" -#include "tr_screen.h" -#include "tr_texture.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 pipe_winsys *winsys = tr_ws->winsys; - const char *result; - - trace_dump_call_begin("pipe_winsys", "get_name"); - - trace_dump_arg(ptr, winsys); - - result = winsys->get_name(winsys); - - trace_dump_ret(string, result); - - trace_dump_call_end(); - - 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 pipe_winsys *winsys = tr_ws->winsys; - - assert(surface); - if(surface->texture) { - struct trace_screen *tr_scr = trace_screen(surface->texture->screen); - struct trace_texture *tr_tex = trace_texture(tr_scr, surface->texture); - struct trace_surface *tr_surf = trace_surface(tr_tex, surface); - surface = tr_surf->surface; - } - - trace_dump_call_begin("pipe_winsys", "flush_frontbuffer"); - - trace_dump_arg(ptr, winsys); - trace_dump_arg(ptr, surface); - /* XXX: hide, as there is nothing we can do with this - trace_dump_arg(ptr, context_private); - */ - - winsys->flush_frontbuffer(winsys, surface, context_private); - - trace_dump_call_end(); -} - - -static struct pipe_buffer * -trace_winsys_surface_buffer_create(struct pipe_winsys *_winsys, - unsigned width, unsigned height, - enum pipe_format format, - unsigned usage, - unsigned *pstride) -{ - struct trace_winsys *tr_ws = trace_winsys(_winsys); - struct pipe_winsys *winsys = tr_ws->winsys; - unsigned stride; - struct pipe_buffer *result; - - trace_dump_call_begin("pipe_winsys", "surface_buffer_create"); - - trace_dump_arg(ptr, winsys); - trace_dump_arg(uint, width); - trace_dump_arg(uint, height); - trace_dump_arg(format, format); - trace_dump_arg(uint, usage); - - result = winsys->surface_buffer_create(winsys, - width, height, - format, - usage, - pstride); - - stride = *pstride; - - trace_dump_arg(uint, stride); - - trace_dump_ret(ptr, result); - - trace_dump_call_end(); - - return result; -} - - -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 pipe_winsys *winsys = tr_ws->winsys; - struct pipe_buffer *buffer; - - trace_dump_call_begin("pipe_winsys", "buffer_create"); - - trace_dump_arg(ptr, winsys); - trace_dump_arg(uint, alignment); - trace_dump_arg(uint, usage); - trace_dump_arg(uint, size); - - buffer = winsys->buffer_create(winsys, alignment, usage, size); - - trace_dump_ret(ptr, buffer); - - trace_dump_call_end(); - - /* Zero the buffer to avoid dumping uninitialized memory */ - if(buffer->usage & PIPE_BUFFER_USAGE_CPU_WRITE) { - void *map; - map = winsys->buffer_map(winsys, buffer, PIPE_BUFFER_USAGE_CPU_WRITE); - if(map) { - memset(map, 0, buffer->size); - winsys->buffer_unmap(winsys, buffer); - } - } - - return buffer; -} - - -static struct pipe_buffer * -trace_winsys_user_buffer_create(struct pipe_winsys *_winsys, - void *data, - unsigned size) -{ - struct trace_winsys *tr_ws = trace_winsys(_winsys); - struct pipe_winsys *winsys = tr_ws->winsys; - struct pipe_buffer *result; - - trace_dump_call_begin("pipe_winsys", "user_buffer_create"); - - trace_dump_arg(ptr, winsys); - trace_dump_arg_begin("data"); - trace_dump_bytes(data, size); - trace_dump_arg_end(); - trace_dump_arg(uint, size); - - result = winsys->user_buffer_create(winsys, data, size); - - trace_dump_ret(ptr, result); - - trace_dump_call_end(); - - /* XXX: Mark the user buffers. (we should wrap pipe_buffers, but is is - * impossible to do so while texture-less surfaces are still around */ - if(result) { - assert(!(result->usage & TRACE_BUFFER_USAGE_USER)); - result->usage |= TRACE_BUFFER_USAGE_USER; - } - - return result; -} - - -void -trace_winsys_user_buffer_update(struct pipe_winsys *_winsys, - struct pipe_buffer *buffer) -{ - struct trace_winsys *tr_ws = trace_winsys(_winsys); - struct pipe_winsys *winsys = tr_ws->winsys; - const void *map; - - if(buffer && buffer->usage & TRACE_BUFFER_USAGE_USER) { - map = winsys->buffer_map(winsys, buffer, PIPE_BUFFER_USAGE_CPU_READ); - if(map) { - trace_dump_call_begin("pipe_winsys", "buffer_write"); - - trace_dump_arg(ptr, winsys); - - trace_dump_arg(ptr, buffer); - - trace_dump_arg_begin("data"); - trace_dump_bytes(map, buffer->size); - trace_dump_arg_end(); - - trace_dump_arg_begin("size"); - trace_dump_uint(buffer->size); - trace_dump_arg_end(); - - trace_dump_call_end(); - - winsys->buffer_unmap(winsys, buffer); - } - } -} - - -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 pipe_winsys *winsys = tr_ws->winsys; - void *map; - - map = winsys->buffer_map(winsys, buffer, usage); - if(map) { - if(usage & PIPE_BUFFER_USAGE_CPU_WRITE) { - assert(!hash_table_get(tr_ws->buffer_maps, buffer)); - hash_table_set(tr_ws->buffer_maps, buffer, map); - } - } - - return map; -} - - -static void -trace_winsys_buffer_unmap(struct pipe_winsys *_winsys, - struct pipe_buffer *buffer) -{ - struct trace_winsys *tr_ws = trace_winsys(_winsys); - 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("pipe_winsys", "buffer_write"); - - trace_dump_arg(ptr, winsys); - - trace_dump_arg(ptr, buffer); - - trace_dump_arg_begin("data"); - trace_dump_bytes(map, buffer->size); - trace_dump_arg_end(); - - trace_dump_arg_begin("size"); - trace_dump_uint(buffer->size); - trace_dump_arg_end(); - - trace_dump_call_end(); - - hash_table_remove(tr_ws->buffer_maps, buffer); - } - - winsys->buffer_unmap(winsys, buffer); -} - - -static void -trace_winsys_buffer_destroy(struct pipe_winsys *_winsys, - struct pipe_buffer *buffer) -{ - struct trace_winsys *tr_ws = trace_winsys(_winsys); - struct pipe_winsys *winsys = tr_ws->winsys; - - trace_dump_call_begin("pipe_winsys", "buffer_destroy"); - - trace_dump_arg(ptr, winsys); - trace_dump_arg(ptr, buffer); - - winsys->buffer_destroy(winsys, buffer); - - trace_dump_call_end(); -} - - -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 pipe_winsys *winsys = tr_ws->winsys; - struct pipe_fence_handle *dst = *pdst; - - trace_dump_call_begin("pipe_winsys", "fence_reference"); - - trace_dump_arg(ptr, winsys); - trace_dump_arg(ptr, dst); - trace_dump_arg(ptr, src); - - winsys->fence_reference(winsys, pdst, src); - - trace_dump_call_end(); -} - - -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 pipe_winsys *winsys = tr_ws->winsys; - int result; - - trace_dump_call_begin("pipe_winsys", "fence_signalled"); - - trace_dump_arg(ptr, winsys); - trace_dump_arg(ptr, fence); - trace_dump_arg(uint, flag); - - result = winsys->fence_signalled(winsys, fence, flag); - - trace_dump_ret(int, result); - - trace_dump_call_end(); - - 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 pipe_winsys *winsys = tr_ws->winsys; - int result; - - trace_dump_call_begin("pipe_winsys", "fence_finish"); - - trace_dump_arg(ptr, winsys); - trace_dump_arg(ptr, fence); - trace_dump_arg(uint, flag); - - result = winsys->fence_finish(winsys, fence, flag); - - trace_dump_ret(int, result); - - trace_dump_call_end(); - - return result; -} - - -static void -trace_winsys_destroy(struct pipe_winsys *_winsys) -{ - struct trace_winsys *tr_ws = trace_winsys(_winsys); - struct pipe_winsys *winsys = tr_ws->winsys; - - trace_dump_call_begin("pipe_winsys", "destroy"); - - trace_dump_arg(ptr, winsys); - - /* - winsys->destroy(winsys); - */ - - trace_dump_call_end(); - - hash_table_destroy(tr_ws->buffer_maps); - - FREE(tr_ws); -} - - -struct pipe_winsys * -trace_winsys_create(struct pipe_winsys *winsys) -{ - struct trace_winsys *tr_ws; - - if(!winsys) - goto error1; - - tr_ws = CALLOC_STRUCT(trace_winsys); - if(!tr_ws) - goto error1; - - 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_buffer_create = trace_winsys_surface_buffer_create; - 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->buffer_maps = hash_table_create(trace_buffer_hash, - trace_buffer_compare); - if(!tr_ws->buffer_maps) - goto error2; - - trace_dump_call_begin("", "pipe_winsys_create"); - trace_dump_ret(ptr, winsys); - trace_dump_call_end(); - - return &tr_ws->base; - -error2: - FREE(tr_ws); -error1: - return winsys; -} |